/* ── Tokens ─────────────────────────────────────────── */
:root {
  --bg: #f7f4ee;
  --surface: #ffffff;
  --surface2: #efece4;
  --text: #1a1c2a;
  --text2: #6b7280;
  --border: #e2ddd2;
  --empty: #f2efe8;
  --empty-text: #8a8278;
  --shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
  --shadow-lg: 0 8px 32px rgba(0, 0, 0, 0.14);
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0d0f18;
    --surface: #161926;
    --surface2: #1c2030;
    --text: #e6e8f4;
    --text2: #5a6280;
    --border: #252840;
    --empty: #151828;
    --empty-text: #8a90b0;
    --shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
  }
}
:root[data-theme="dark"] {
  --bg: #0d0f18;
  --surface: #161926;
  --surface2: #1c2030;
  --text: #e6e8f4;
  --text2: #5a6280;
  --border: #252840;
  --empty: #151828;
  --empty-text: #8a90b0;
  --shadow: 0 1px 4px rgba(0, 0, 0, 0.4);
  --shadow-lg: 0 8px 40px rgba(0, 0, 0, 0.6);
}

/* ── Reset & base ──────────────────────────────────── */
*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}
html {
  height: 100%;
}
body {
  font-family: "Nunito", system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  overscroll-behavior: contain;
}

/* ── Header ────────────────────────────────────────── */
header {
  position: sticky;
  top: 0;
  z-index: 20;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow);
}

.app-title {
  font-family: "Fredoka One", cursive;
  font-size: 1.6rem;
  letter-spacing: 0.01em;
  line-height: 1;
  color: var(--text);
}
.app-title span {
  display: inline-block;
  background: linear-gradient(
    135deg,
    #f59e0b 0%,
    #ef4444 50%,
    #a855f7 100%
  );
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.counter-pill {
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--text2);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 4px 14px;
  white-space: nowrap;
  font-variant-numeric: tabular-nums;
}
.counter-pill strong {
  color: var(--text);
  font-weight: 900;
}

/* ── Recent strip ──────────────────────────────────── */
.recent-strip {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  padding: 8px 16px;
  display: flex;
  align-items: center;
  gap: 8px;
  min-height: 56px;
  overflow-x: auto;
  scrollbar-width: none;
}
.recent-strip::-webkit-scrollbar {
  display: none;
}

.recent-label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text2);
  flex-shrink: 0;
  white-space: nowrap;
}

.recent-balls {
  display: flex;
  gap: 6px;
  align-items: center;
}

.recent-ball {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Fredoka One", cursive;
  font-size: 0.9rem;
  color: #fff;
  flex-shrink: 0;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.recent-ball:nth-child(1) {
  opacity: 1;
  transform: scale(1.08);
}
.recent-ball:nth-child(2) {
  opacity: 0.85;
}
.recent-ball:nth-child(3) {
  opacity: 0.7;
}
.recent-ball:nth-child(4) {
  opacity: 0.55;
}
.recent-ball:nth-child(5) {
  opacity: 0.42;
}
.recent-ball:nth-child(6) {
  opacity: 0.3;
}
.recent-ball:nth-child(n + 7) {
  opacity: 0.2;
}

.recent-empty {
  font-size: 0.75rem;
  color: var(--empty-text);
  font-weight: 600;
  font-style: italic;
}

/* ── Grid ──────────────────────────────────────────── */
.grid-wrap {
  padding: 10px 10px 4px;
  flex: 1;
}

.grid {
  display: grid;
  grid-template-columns: repeat(10, 1fr);
  gap: 4px;
}

.ball-btn {
  aspect-ratio: 1;
  width: 100%;
  border: none;
  border-radius: 50%;
  background: var(--empty);
  color: var(--empty-text);
  font-family: "Fredoka One", cursive;
  font-size: clamp(0.6rem, 2.2vw, 0.9rem);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1;
  position: relative;
  outline: none;
  transition:
    transform 0.08s ease,
    background 0.12s ease,
    color 0.12s ease;
}
.ball-btn::before {
  content: "";
  position: absolute;
  inset: -3px;
  border-radius: 50%;
}
.ball-btn:focus-visible {
  box-shadow: 0 0 0 3px var(--text);
}
.ball-btn:active {
  transform: scale(0.82);
}
.ball-btn.called {
  color: #fff;
  box-shadow:
    0 2px 5px rgba(0, 0, 0, 0.25),
    inset 0 1px 0 rgba(255, 255, 255, 0.2);
}
.ball-btn.called::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 50%;
  background: radial-gradient(
    circle at 35% 35%,
    rgba(255, 255, 255, 0.18) 0%,
    transparent 70%
  );
  pointer-events: none;
}

/* ── Footer ────────────────────────────────────────── */
footer {
  padding: 12px 16px 20px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  background: var(--bg);
}

.decade-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
  justify-content: center;
  margin-bottom: 2px;
}
.legend-dot {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 0.62rem;
  font-weight: 700;
  color: var(--text2);
}
.legend-dot i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  display: inline-block;
  flex-shrink: 0;
}

.footer-btns {
  display: flex;
  gap: 10px;
  width: 100%;
  max-width: 360px;
}

.btn-history {
  font-family: "Nunito", sans-serif;
  font-size: 0.8rem;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text2);
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 11px 0;
  cursor: pointer;
  transition:
    color 0.15s,
    border-color 0.15s,
    transform 0.1s;
  flex: 1;
}
.btn-history:hover {
  color: var(--text);
  border-color: var(--text);
}
.btn-history:active {
  transform: scale(0.95);
}

.btn-newgame {
  font-family: "Nunito", sans-serif;
  font-size: 0.8rem;
  font-weight: 900;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: #fff;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  border: none;
  border-radius: 14px;
  padding: 11px 0;
  cursor: pointer;
  flex: 2;
  box-shadow: 0 3px 10px rgba(239, 68, 68, 0.3);
  transition:
    opacity 0.15s,
    transform 0.1s,
    box-shadow 0.15s;
}
.btn-newgame:hover {
  opacity: 0.9;
  box-shadow: 0 5px 16px rgba(239, 68, 68, 0.4);
}
.btn-newgame:active {
  transform: scale(0.95);
}
.btn-newgame.confirm {
  background: linear-gradient(135deg, #16a34a, #059669);
  box-shadow: 0 3px 10px rgba(22, 163, 74, 0.35);
  animation: pulse-green 0.7s ease infinite alternate;
}

.btn-reset-link {
  font-size: 0.7rem;
  font-weight: 700;
  color: var(--text2);
  background: none;
  border: none;
  cursor: pointer;
  padding: 2px 8px;
  opacity: 0.6;
  letter-spacing: 0.03em;
  transition: opacity 0.15s;
}
.btn-reset-link:hover {
  opacity: 1;
}

@keyframes pulse-green {
  from {
    box-shadow: 0 3px 10px rgba(22, 163, 74, 0.2);
  }
  to {
    box-shadow: 0 5px 18px rgba(22, 163, 74, 0.5);
  }
}

/* ── History panel (bottom sheet) ─────────────────── */
.panel-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.22s ease;
  backdrop-filter: blur(2px);
  -webkit-backdrop-filter: blur(2px);
}
.panel-overlay.open {
  opacity: 1;
  pointer-events: all;
}

.panel {
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  width: 100%;
  max-height: 82dvh;
  display: flex;
  flex-direction: column;
  transform: translateY(100%);
  transition: transform 0.3s cubic-bezier(0.32, 1.1, 0.6, 1);
  box-shadow: var(--shadow-lg);
}
.panel-overlay.open .panel {
  transform: translateY(0);
}

.panel-handle {
  width: 40px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  margin: 12px auto 0;
  flex-shrink: 0;
}

.panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 12px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.panel-title {
  font-family: "Fredoka One", cursive;
  font-size: 1.2rem;
  color: var(--text);
}
.panel-close {
  background: var(--surface2);
  border: none;
  border-radius: 50%;
  width: 32px;
  height: 32px;
  cursor: pointer;
  color: var(--text2);
  font-size: 1rem;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}
.panel-close:hover {
  background: var(--border);
}

.panel-body {
  overflow-y: auto;
  flex: 1;
  padding: 8px 0 20px;
}

.panel-empty {
  text-align: center;
  color: var(--text2);
  font-size: 0.9rem;
  font-style: italic;
  padding: 40px 20px;
  font-weight: 600;
}

/* ── Game items ────────────────────────────────────── */
.game-item {
  border-bottom: 1px solid var(--border);
  overflow: hidden;
}
.game-item:last-child {
  border-bottom: none;
}

.game-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px;
  cursor: pointer;
  gap: 12px;
  transition: background 0.12s;
}
.game-header:hover {
  background: var(--surface2);
}
.game-header:active {
  background: var(--border);
}

.game-meta {
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.game-date {
  font-size: 0.8rem;
  font-weight: 700;
  color: var(--text);
}
.game-date-sub {
  font-size: 0.72rem;
  color: var(--text2);
  font-weight: 600;
}

.game-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}
.game-count-badge {
  font-family: "Fredoka One", cursive;
  font-size: 1.05rem;
  color: var(--text);
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 2px 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}
.game-chevron {
  color: var(--text2);
  font-size: 0.8rem;
  transition: transform 0.2s;
  flex-shrink: 0;
}
.game-item.expanded .game-chevron {
  transform: rotate(90deg);
}

.game-detail {
  display: none;
  padding: 0 20px 16px;
  flex-direction: column;
  gap: 10px;
}
.game-item.expanded .game-detail {
  display: flex;
}

.game-detail-label {
  font-size: 0.65rem;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--text2);
}

.game-sequence {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.mini-ball {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  font-family: "Fredoka One", cursive;
  font-size: 0.7rem;
  color: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.2);
  flex-shrink: 0;
  position: relative;
}

.mini-ball .order-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 999px;
  font-family: "Nunito", sans-serif;
  font-size: 0.45rem;
  font-weight: 900;
  color: var(--text2);
  padding: 0 2px;
  min-width: 13px;
  text-align: center;
  line-height: 13px;
}

/* ── Reduced motion ────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  .ball-btn,
  .recent-ball,
  .btn-newgame,
  .btn-history {
    transition: none;
  }
  .ball-btn:active {
    transform: none;
  }
  .btn-newgame.confirm {
    animation: none;
  }
  .panel,
  .panel-overlay {
    transition: none;
  }
}
