* { box-sizing: border-box; }
html, body {
  margin: 0; padding: 0;
  background: #0b0d12;
  color: #e8ecf2;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
#wrap {
  max-width: 980px;
  margin: 0 auto;
  padding: 18px 10px 30px;
}
header {
  display: flex; justify-content: space-between; align-items: flex-end;
  margin-bottom: 10px;
}
h1 {
  font-size: 22px; margin: 0; letter-spacing: 1px;
  color: #f6c453;
  text-transform: uppercase;
}
#hud { display: flex; gap: 14px; }
.hud-item {
  background: #181c25; border: 1px solid #232938; border-radius: 6px;
  padding: 4px 10px;
  display: flex; flex-direction: column; align-items: center;
  min-width: 64px;
}
.lbl { font-size: 10px; color: #7c869c; letter-spacing: 1.5px; text-transform: uppercase; }
.val { font-size: 16px; font-weight: 600; font-variant-numeric: tabular-nums; }

canvas {
  display: block; width: 100%; height: auto;
  background: #0e1422;
  border: 1px solid #232938;
  border-radius: 4px;
  image-rendering: pixelated;
}

#controls {
  margin-top: 12px;
  display: flex; flex-wrap: wrap; gap: 14px;
  font-size: 12px; color: #9aa3b8;
}
kbd {
  background: #1c2230; border: 1px solid #2c3346;
  border-bottom-width: 2px; border-radius: 3px;
  padding: 1px 6px; font-family: inherit; font-size: 11px;
  color: #d8dde8;
}

#overlay {
  position: fixed; inset: 0;
  background: rgba(8, 10, 16, 0.78);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}
#overlay[hidden] { display: none; }
.card {
  background: #161b25; border: 1px solid #2a3145; border-radius: 10px;
  padding: 28px 36px; text-align: center;
  min-width: 300px;
}
.card h2 { margin: 0 0 10px; color: #f6c453; }
.card p { margin: 6px 0; color: #c8cfdb; font-variant-numeric: tabular-nums; }
.card-buttons {
  display: flex; gap: 10px; justify-content: center; margin-top: 14px;
}
.card button {
  background: #f6c453; color: #1a1d24; border: none;
  font-weight: 700; font-size: 14px;
  padding: 9px 22px; border-radius: 5px; cursor: pointer;
  letter-spacing: 0.5px;
  font-family: inherit;
}
.card button:hover { background: #ffd56b; }
#overlay-share {
  background: #2c3346; color: #d8dde8;
}
#overlay-share:hover { background: #3a4360; }

.theme-control {
  display: inline-flex; align-items: center; gap: 6px;
  color: #9aa3b8;
}
#theme-select {
  background: #1c2230; color: #d8dde8;
  border: 1px solid #2c3346; border-radius: 4px;
  padding: 2px 6px; font-size: 12px;
  font-family: inherit; cursor: pointer;
}
#theme-select:hover { border-color: #4a5366; }
#theme-select:focus { outline: 1px solid #f6c453; }

/* Footer pill buttons */
#back-today-btn {
  background: #1c2230; color: #d8dde8;
  border: 1px solid #2c3346; border-radius: 4px;
  padding: 2px 10px; font-size: 12px;
  font-family: inherit; cursor: pointer;
  letter-spacing: 0.3px;
}
#back-today-btn:hover { border-color: #4a5366; color: #ffffff; }
#result-btn {
  background: rgba(246, 196, 83, 0.08);
  border: 1px solid rgba(246, 196, 83, 0.4);
  color: #f6c453;
  border-radius: 4px;
  padding: 2px 10px; font-size: 12px;
  font-family: inherit; cursor: pointer;
  letter-spacing: 0.3px;
}
#result-btn:hover {
  background: rgba(246, 196, 83, 0.14);
  border-color: rgba(246, 196, 83, 0.6);
  color: #ffd56b;
}

/* Archive button — stylized to stand out */
#archive-btn {
  background: linear-gradient(180deg, rgba(246,196,83,0.18), rgba(246,196,83,0.08));
  border: 1px solid rgba(246, 196, 83, 0.55);
  color: #ffd56b;
  border-radius: 5px;
  padding: 4px 14px; font-size: 12px;
  font-family: inherit; cursor: pointer;
  font-weight: 700;
  letter-spacing: 0.8px;
  text-transform: uppercase;
  box-shadow: 0 0 0 1px rgba(246, 196, 83, 0.06) inset;
}
#archive-btn::before {
  content: '';
  display: inline-block;
  width: 10px; height: 8px;
  margin-right: 6px;
  vertical-align: middle;
  background:
    linear-gradient(#ffd56b, #ffd56b) 0 0/100% 2px no-repeat,
    linear-gradient(#ffd56b, #ffd56b) 0 50%/100% 2px no-repeat,
    linear-gradient(#ffd56b, #ffd56b) 0 100%/100% 2px no-repeat;
}
#archive-btn:hover {
  background: linear-gradient(180deg, rgba(246,196,83,0.28), rgba(246,196,83,0.14));
  border-color: rgba(246, 196, 83, 0.85);
  color: #ffe48a;
}

/* Today stats line (between hero and All Time) */
.stats-today {
  text-align: center;
  margin: 6px 0 2px;
  color: #9aa3b8;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
.stats-today[hidden] { display: none; }
.stats-today .today-label {
  color: #7c869c;
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  margin-right: 2px;
}
.stats-today strong {
  color: #f6c453; font-weight: 700; margin: 0 2px;
}
.stats-today .today-sep { margin: 0 6px; color: #4a5366; }
.stats-today .today-delta {
  margin-left: 6px;
  color: #4ade80;
  font-weight: 700;
  font-size: 12px;
}
.stats-today .today-delta:empty { display: none; }

/* End-of-run stats — hero (this run) + base (all time) */
.stats-hero {
  display: flex; gap: 10px;
  justify-content: center;
  margin: 14px 0 6px;
}
.stats-section-label {
  font-size: 10px;
  color: #7c869c;
  text-transform: uppercase;
  letter-spacing: 1.4px;
  margin: 14px 0 6px;
  text-align: center;
  position: relative;
}
.stats-section-label::before,
.stats-section-label::after {
  content: '';
  position: absolute; top: 50%;
  width: 28%; height: 1px;
  background: #2a3145;
}
.stats-section-label::before { left: 0; }
.stats-section-label::after  { right: 0; }
.stats-row {
  display: flex; flex-wrap: wrap; gap: 8px;
  justify-content: center;
  margin: 0 0 4px;
}
.stat-box {
  background: #1c2230; border: 1px solid #2c3346; border-radius: 6px;
  padding: 10px 6px;
  display: flex; flex-direction: column; align-items: center;
  min-width: 76px; flex: 1; max-width: 96px;
}
.stat-value {
  font-size: 18px; font-weight: 800;
  color: #d8dde8;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stat-label {
  font-size: 10px;
  color: #7c869c;
  text-transform: uppercase;
  letter-spacing: 1px;
  margin-top: 4px;
}
.stat-box-hero {
  background: rgba(246, 196, 83, 0.07);
  border: 1px solid rgba(246, 196, 83, 0.45);
  min-width: 130px; max-width: 160px;
  padding: 14px 10px;
}
.stat-box-hero .stat-value {
  font-size: 30px;
  color: #ffd56b;
}
.stat-box-hero .stat-label {
  color: #d4b06a;
  letter-spacing: 1.5px;
}

/* Archive overlay */
#archive-overlay {
  position: fixed; inset: 0;
  background: rgba(8, 10, 16, 0.78);
  display: flex; align-items: center; justify-content: center;
  z-index: 10;
}
#archive-overlay[hidden] { display: none; }
.archive-card { min-width: 380px; max-width: 480px; }
.archive-card h2 { margin: 0 0 14px; }
#archive-list {
  max-height: 320px; overflow-y: auto;
  margin-bottom: 4px;
  text-align: left;
  border-top: 1px solid #2a3145;
  border-bottom: 1px solid #2a3145;
  padding: 6px 0;
}
.archive-row {
  display: flex; align-items: center; gap: 12px;
  padding: 8px 12px;
  border-radius: 4px;
  font-size: 13px;
  color: #c8cfdb;
}
.archive-row + .archive-row { margin-top: 2px; }
.archive-row:hover { background: rgba(255, 255, 255, 0.04); }
.archive-day {
  flex: 1; color: #d8dde8;
  font-variant-numeric: tabular-nums;
}
.archive-id {
  flex: 1;
  display: flex; flex-direction: column;
  line-height: 1.2;
}
.archive-num {
  font-weight: 700; color: #f6c453;
  font-size: 14px;
  font-variant-numeric: tabular-nums;
}
.archive-date {
  font-size: 10px; color: #7c869c;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.3px;
}
.archive-times {
  display: flex; flex-direction: column; line-height: 1.3;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: #c8cfdb;
}
.archive-times .archive-key {
  color: #7c869c;
  font-size: 9px;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  margin-right: 4px;
}
.archive-delta {
  color: #4ade80; font-weight: 700; margin-left: 4px;
}
.archive-row.archive-today {
  background: rgba(246, 196, 83, 0.05);
  border-left: 2px solid rgba(246, 196, 83, 0.55);
  padding-left: 10px;
}
.archive-todaytag {
  display: inline-block;
  margin-left: 6px;
  padding: 1px 6px;
  background: rgba(246, 196, 83, 0.18);
  color: #f6c453;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  border-radius: 8px;
  vertical-align: 1px;
}
.archive-unplayed {
  color: #5c6478;
  font-style: italic;
}
.archive-unplayed .archive-key {
  color: #5c6478;
  font-style: normal;
}
.archive-play {
  background: #1c2230; color: #d8dde8;
  border: 1px solid #2c3346;
  border-radius: 4px;
  padding: 3px 12px;
  font-size: 11px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
  letter-spacing: 0.4px;
}
.archive-play:hover:not(:disabled) {
  background: #2a3346;
  border-color: #4a5366;
  color: #ffffff;
}
.archive-play:disabled {
  cursor: default;
  background: rgba(246, 196, 83, 0.15);
  border-color: rgba(246, 196, 83, 0.55);
  color: #ffd56b;
  font-weight: 700;
  letter-spacing: 0.7px;
  text-transform: uppercase;
}
.archive-stats {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  min-width: 56px;
  color: #9aa3b8;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
}
.archive-deaths { line-height: 1.2; }
.archive-perfect {
  display: inline-block;
  padding: 1px 8px;
  background: rgba(246, 196, 83, 0.12);
  border: 1px solid rgba(246, 196, 83, 0.4);
  color: #f6c453;
  font-size: 9px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.8px;
  border-radius: 10px;
}
.archive-empty {
  text-align: center;
  color: #7c869c;
  padding: 24px 12px;
  font-size: 13px;
}
