/* =============================================================================
   Equadle – main stylesheet
   ============================================================================= */

:root {
  --correct: #2f9e44;
  --present: #f59f00;
  --absent: #8b949e;
  --danger: #e03131;
  --success: #2f9e44;
  --accent: #3b82f6;
  --accent-2: #7c3aed;
  --tile-gap: 6px;
  --radius: 18px;
  --tile-aspect: 1 / 1;
}

/* ── Colorblind palette override ─────────────────────────────────────────────── */
[data-colorblind="on"] {
  --correct: #0066cc;
  --present: #e87722;
}

[data-colorblind="on"] .settings-item[aria-pressed="true"] {
  color: var(--accent);
}

html[data-theme="dark"] {
  --bg: #0d1117;
  --bg-soft: #111827;
  --surface: #161b22;
  --surface-2: #1f2937;
  --surface-3: #273449;
  --text: #f8fafc;
  --muted: #aeb8c7;
  --border: #303a4c;
  --shadow: rgba(0,0,0,.38);
  --tile-bg: #111827;
  --tile-border: #374151;
  --key-bg: #1f2937;
  --key-bg-hover: #273449;
  --key-text: #f8fafc;
  --panel-gradient: linear-gradient(180deg, rgba(22,27,34,.98), rgba(13,17,23,.99));
  --top-gradient: linear-gradient(180deg, rgba(13,17,23,.98), rgba(13,17,23,.88));
}

html[data-theme="light"] {
  --bg: #f6f8fb;
  --bg-soft: #eef2f7;
  --surface: #ffffff;
  --surface-2: #eef2f7;
  --surface-3: #dfe7f2;
  --text: #172033;
  --muted: #586579;
  --border: #c8d2e0;
  --shadow: rgba(15,23,42,.14);
  --tile-bg: #ffffff;
  --tile-border: #c8d2e0;
  --key-bg: #ffffff;
  --key-bg-hover: #eef2f7;
  --key-text: #172033;
  --panel-gradient: linear-gradient(180deg, rgba(255,255,255,.98), rgba(239,243,248,.99));
  --top-gradient: linear-gradient(180deg, rgba(246,248,251,.98), rgba(246,248,251,.88));
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overflow: hidden;
}

body {
  min-height: 100dvh;
  background:
    radial-gradient(circle at 12% 0%, rgba(59,130,246,.13), transparent 320px),
    radial-gradient(circle at 90% 10%, rgba(124,58,237,.11), transparent 360px),
    var(--bg);
}

button {
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
}

.app {
  height: 100vh;
  height: 100dvh;
  width: 100%;
}

.view {
  height: 100vh;
  height: 100dvh;
  width: 100%;
  display: none;
}

.view.active {
  display: block;
}

/* ── Top controls ─────────────────────────────────────────────────────────── */
.settings-wrap {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  right: 12px;
  z-index: 20;
}

.settings-top {
  /* dimensions come from .theme-button */
}

.settings-menu {
  position: absolute;
  top: calc(100% + 8px);
  right: 0;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: 0 8px 24px var(--shadow);
  min-width: 190px;
  overflow: hidden;
}

.settings-item {
  display: block;
  width: 100%;
  padding: 13px 18px;
  text-align: left;
  font-size: 14px;
  font-weight: 600;
  color: var(--text);
  background: none;
  border: none;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  transition: background 0.12s;
}

.settings-item:last-child { border-bottom: none; }

.settings-item:hover,
.settings-item:focus-visible {
  background: var(--tile-border);
}

.back-top {
  position: fixed;
  top: calc(10px + env(safe-area-inset-top));
  left: 12px;
  z-index: 20;
}

.theme-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 999px;
  min-height: 40px;
  min-width: 40px;
  display: grid;
  place-items: center;
  font-size: 18px;
  font-weight: 950;
  cursor: pointer;
  box-shadow: 0 8px 20px var(--shadow);
}

/* ── Splash / Home screen ─────────────────────────────────────────────────── */
.splash {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(18px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
}

.splash-inner {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
}

.hero {
  text-align: center;
  margin: 8px 52px 16px;
}

h1 {
  margin: 0;
  font-size: clamp(42px, 12vw, 72px);
  line-height: .95;
  letter-spacing: -2.4px;
}

.sigma {
  color: var(--accent);
  display: inline-block;
  transform: translateY(-0.07em) rotate(-6deg);
  margin-right: 0.02em;
}

.small-sigma {
  font-size: 1.08em;
  vertical-align: 0.03em;
  margin-right: 1px;
}

.tagline {
  color: var(--muted);
  font-size: 16px;
  margin-top: 10px;
  font-weight: 700;
}

/* ── Cards ────────────────────────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 24px;
  padding: 16px;
  box-shadow: 0 18px 60px var(--shadow);
  margin-bottom: 14px;
}

.day-card {
  display: grid;
  gap: 4px;
  text-align: center;
}

.game-number {
  font-weight: 950;
  font-size: 28px;
  letter-spacing: -0.5px;
}

.date-big {
  font-weight: 700;
  font-size: 15px;
  color: var(--muted);
}

.new-day {
  color: var(--muted);
  font-weight: 800;
}

.new-day.is-new {
  color: var(--success);
}

.section-title {
  margin: 0 0 12px;
  font-size: 20px;
}

/* ── Mode selection ─────────────────────────────────────────────────────── */
.mode-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 14px;
}

.mode-card {
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 24px;
  padding: 0;
  text-align: left;
  cursor: pointer;
  box-shadow: 0 8px 28px var(--shadow);
  overflow: hidden;
  display: block;
  width: 100%;
  font: inherit;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  transition: transform .18s, box-shadow .18s, border-color .2s;
}

.mode-card[data-state="unstarted"]:hover,
.mode-card[data-state="in-progress"]:hover {
  transform: translateY(-2px);
  box-shadow: 0 22px 56px var(--shadow);
}

.mode-card[data-state="unstarted"]:active,
.mode-card[data-state="in-progress"]:active {
  transform: translateY(1px);
}

/* ── Hero zone ── */
.mode-hero {
  padding: 20px 20px 18px;
  position: relative;
  overflow: hidden;
  min-height: 96px;
  display: flex;
  align-items: center;
}

/* Decorative bubble */
.mode-hero::before {
  content: "";
  position: absolute;
  width: 160px;
  height: 160px;
  border-radius: 50%;
  background: rgba(255,255,255,.09);
  right: -35px;
  top: -42px;
  pointer-events: none;
}

/* Easy: emerald → sky */
.mode-card[data-start-mode="easy"] .mode-hero {
  background: linear-gradient(140deg, #059669 0%, #0ea5e9 100%);
}

/* Hard: violet → rose */
.mode-card[data-start-mode="hard"] .mode-hero {
  background: linear-gradient(140deg, #7c3aed 0%, #db2777 100%);
}

/* State overlays via layered gradients */
.mode-card[data-start-mode="easy"][data-state="won"] .mode-hero {
  background: linear-gradient(rgba(0,0,0,.22),rgba(0,0,0,.22)),
              linear-gradient(140deg, #059669 0%, #0ea5e9 100%);
}
.mode-card[data-start-mode="easy"][data-state="failed"] .mode-hero {
  background: linear-gradient(rgba(0,0,0,.50),rgba(0,0,0,.50)),
              linear-gradient(140deg, #059669 0%, #0ea5e9 100%);
}
.mode-card[data-start-mode="easy"][data-state="in-progress"] .mode-hero {
  background: linear-gradient(rgba(245,158,11,.15),rgba(245,158,11,.15)),
              linear-gradient(140deg, #059669 0%, #0ea5e9 100%);
}
.mode-card[data-start-mode="hard"][data-state="won"] .mode-hero {
  background: linear-gradient(rgba(0,0,0,.22),rgba(0,0,0,.22)),
              linear-gradient(140deg, #7c3aed 0%, #db2777 100%);
}
.mode-card[data-start-mode="hard"][data-state="failed"] .mode-hero {
  background: linear-gradient(rgba(0,0,0,.50),rgba(0,0,0,.50)),
              linear-gradient(140deg, #7c3aed 0%, #db2777 100%);
}
.mode-card[data-start-mode="hard"][data-state="in-progress"] .mode-hero {
  background: linear-gradient(rgba(245,158,11,.15),rgba(245,158,11,.15)),
              linear-gradient(140deg, #7c3aed 0%, #db2777 100%);
}

.mode-hero-bottom {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  position: relative;
  z-index: 1;
}

.mode-name {
  font-size: 34px;
  font-weight: 950;
  color: rgba(255,255,255,.95);
  letter-spacing: -0.5px;
  line-height: 1;
  text-shadow: 0 2px 10px rgba(0,0,0,.18);
}

.mode-hero-score {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
}

.mode-hero-score:empty {
  display: none;
}

.hero-score-value {
  font-size: 30px;
  font-weight: 950;
  color: rgba(255,255,255,.95);
  line-height: 1;
  letter-spacing: -0.5px;
  text-shadow: 0 2px 10px rgba(0,0,0,.18);
}

.hero-score-label {
  font-size: 10px;
  font-weight: 900;
  color: rgba(255,255,255,.65);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 3px;
}

/* ── Details zone ── */
.mode-details {
  padding: 14px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 9px;
}

.mode-spec {
  font-size: 11px;
  color: var(--muted);
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  text-align: center;
}

/* ── Guess track ── */
.guess-track {
  display: flex;
  gap: 5px;
  flex-wrap: nowrap;
}

.guess-dot {
  width: 10px;
  height: 10px;
  border-radius: 3px;
  background: var(--surface-2);
  border: 1px solid var(--border);
  flex-shrink: 0;
  transition: background .2s, border-color .2s, opacity .2s;
}

.guess-dot.used {
  border-color: transparent;
}

/* ── Status text ── */
.mode-status {
  font-size: 14px;
  font-weight: 900;
  line-height: 1.5;
  color: var(--muted);
}

/* ── Call to action ── */
.mode-cta {
  background: var(--accent);
  color: white;
  border-radius: 14px;
  padding: 13px 16px;
  font-weight: 950;
  font-size: 15px;
  text-align: center;
  transition: background .2s, box-shadow .2s, color .2s;
  box-shadow: 0 5px 16px rgba(59,130,246,.30);
}

/* ── State: unstarted ── */
.mode-card[data-state="unstarted"] .mode-status {
  color: var(--accent);
}

/* ── State: in-progress ── */
.mode-card[data-state="in-progress"] {
  border-color: color-mix(in srgb, var(--present) 55%, var(--border));
}

.mode-card[data-state="in-progress"] .mode-status { color: var(--present); }

.mode-card[data-state="in-progress"] .mode-cta {
  background: var(--present);
  box-shadow: 0 5px 16px rgba(245,159,0,.30);
}

.mode-card[data-state="in-progress"] .guess-dot.used { background: var(--present); }

/* ── State: won ── */
.mode-card[data-state="won"] {
  border-color: color-mix(in srgb, var(--correct) 55%, var(--border));
}

.mode-card[data-state="won"] .mode-status { color: var(--correct); }

.mode-card[data-state="won"] .mode-cta {
  background: var(--correct);
  box-shadow: 0 5px 16px rgba(47,158,68,.28);
}

.mode-card[data-state="won"] .guess-dot.used        { background: var(--correct); }
.mode-card[data-state="won"] .guess-dot:not(.used)  { opacity: 0.22; }

/* ── State: failed ── */
.mode-card[data-state="failed"] {
  border-color: color-mix(in srgb, var(--absent) 40%, var(--border));
}

.mode-card[data-state="failed"] .mode-status { color: var(--muted); }

.mode-card[data-state="failed"] .mode-cta {
  background: var(--surface-3);
  color: var(--muted);
  box-shadow: none;
}

.mode-card[data-state="failed"] .guess-dot.used {
  background: var(--absent);
  opacity: 0.60;
}

/* ── Score span ── */
.splash-score {
  font-size: 14px;
  font-weight: 900;
  letter-spacing: 0.02em;
}

.mode-card[data-state="won"]    .splash-score { color: var(--correct); }
.mode-card[data-state="failed"] .splash-score { color: var(--muted); }

/* ── Support section ──────────────────────────────────────────────────────── */
.equadle-coffee-wrap-desc {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: center;
  margin-bottom: 14px;
}

.equadle-coffee-wrap-desc h2 {
  margin-top: 5px;
  margin-bottom: 5px;
}

.equadle-coffee-wrap-desc h3 {
  margin-top: 5px;
  margin-bottom: 5px;
}

.equadle-coffee-wrap {
  display: flex;
  justify-content: center;
  align-items: center;
  margin-bottom: 14px;
  min-height: 56px;
}

/* ── How to play ─────────────────────────────────────────────────────────── */
.how-title {
  margin: 0 0 10px;
  font-size: 20px;
}

.how-list {
  margin: 0;
  padding-left: 20px;
  color: var(--muted);
  line-height: 1.6;
  font-weight: 650;
}

.how-list li {
  margin-bottom: 4px;
}

.how-legend {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 10px;
  align-items: center;
  margin-top: 12px;
}

.legend-tile {
  width: 28px;
  height: 28px;
  border-radius: 6px;
  display: grid;
  place-items: center;
  font-weight: 950;
  font-size: 14px;
  color: white;
}

.legend-tile.correct  { background: var(--correct); }
.legend-tile.present  { background: var(--present); }
.legend-tile.absent   { background: var(--absent); }

.legend-text {
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

.example-frame {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 14px;
  margin-top: 14px;
}

.example-board {
  display: grid;
  gap: 8px;
  max-width: 240px;
  width: 100%;
  margin: 0 auto;
}

.example-caption {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  font-weight: 800;
  margin-top: 8px;
}

/* ── Game view ────────────────────────────────────────────────────────────── */
.game-shell {
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
}

.game-header {
  padding: calc(8px + env(safe-area-inset-top)) 12px 8px;
  background: var(--top-gradient);
  border-bottom: 1px solid var(--border);
  z-index: 3;
}

.game-header-top {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  max-width: 760px;
  min-height: 45px;
  margin: 0 auto;
  padding: 0 68px; /* clear the fixed home & settings buttons */
}

.game-nav-arrow {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 12px;
  min-height: 42px;
  min-width: 42px;
  display: grid;
  place-items: center;
  font-size: 14px;
  cursor: pointer;
  flex-shrink: 0;
  transition: opacity 0.15s;
}

.game-nav-arrow:disabled {
  opacity: 0.25;
  cursor: not-allowed;
}

.game-title {
  flex: 1;
  text-align: center;
  font-weight: 950;
  font-size: 18px;
  min-width: 0;
}

.status-strip {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 7px;
  max-width: 760px;
  margin: 8px auto 0;
}

.stat {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 8px 6px;
  min-width: 0;
  text-align: center;
}

.stat span {
  display: block;
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: .07em;
  margin-bottom: 2px;
  font-weight: 900;
}

.stat strong {
  display: block;
  color: var(--text);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  font-weight: 950;
}

/* ── Board & tiles ────────────────────────────────────────────────────────── */
.game-scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: 12px;
  min-height: 0;
}

.game-inner {
  width: 100%;
  max-width: 760px;
  margin: 0 auto;
}

.board {
  display: grid;
  gap: 8px;
  padding-bottom: 10px;
  width: 100%;
}

.row.active-row .tile {
  border-color: var(--accent);
  box-shadow: 0 0 0 2px rgba(59,130,246,.16), inset 0 -2px 0 rgba(0,0,0,.08);
}

.row,
.answer-row,
.entry-row,
.example-row {
  display: grid;
  grid-template-columns: repeat(var(--cols), minmax(0, 1fr));
  gap: var(--tile-gap);
  width: 100%;
}

.example-row {
  --cols: 5;
  --tile-aspect: 1 / 1;
}

.tile {
  width: 100%;
  aspect-ratio: var(--tile-aspect, 1 / 1);
  min-width: 0;
  border: 2px solid var(--tile-border);
  border-radius: clamp(5px, 1.8vw, 12px);
  display: grid;
  place-items: center;
  font-weight: 950;
  font-size: clamp(10px, calc(44vw / var(--cols)), 28px);
  line-height: 1;
  background: var(--tile-bg);
  color: var(--text);
  user-select: none;
  box-shadow: inset 0 -2px 0 rgba(0,0,0,.08);
  position: relative;
}

/* Colorblind tile patterns - diagonal stripes on present, crosshatch on correct */
[data-colorblind="on"] .tile.present,
[data-colorblind="on"] .legend-tile.present,
[data-colorblind="on"] .history-mini-tile.present {
  background-image: repeating-linear-gradient(
    45deg,
    transparent 0px,
    transparent 5px,
    rgba(255,255,255,0.28) 5px,
    rgba(255,255,255,0.28) 8px
  );
}

[data-colorblind="on"] .tile.correct,
[data-colorblind="on"] .legend-tile.correct,
[data-colorblind="on"] .history-mini-tile.correct {
  background-image: repeating-linear-gradient(
    45deg,
    transparent 0px,
    transparent 6px,
    rgba(255,255,255,0.18) 6px,
    rgba(255,255,255,0.18) 8px
  ),
  repeating-linear-gradient(
    -45deg,
    transparent 0px,
    transparent 6px,
    rgba(255,255,255,0.18) 6px,
    rgba(255,255,255,0.18) 8px
  );
}

.tile.correct {
  background: var(--correct);
  border-color: var(--correct);
  color: white;
}

.tile.present {
  background: var(--present);
  border-color: var(--present);
  color: white;
}

.tile.absent {
  background: var(--absent);
  border-color: var(--absent);
  color: white;
}

/* ── Tile flip animation ─────────────────────────────────────────────────── */
.row {
  perspective: 600px;
}

@keyframes tileFlip {
  0%   { transform: rotateY(0deg);  }
  50%  { transform: rotateY(90deg); }
  100% { transform: rotateY(0deg);  }
}

.tile.flipping {
  animation: tileFlip 0.5s ease-in-out var(--flip-delay, 0s) both;
}

@media (prefers-reduced-motion: reduce) {
  .tile.flipping { animation: none; }
}

/* ── Win celebration ──────────────────────────────────────────────────────── */
@keyframes tileBounce {
  0%, 100% { transform: translateY(0)     scale(1);    }
  30%       { transform: translateY(-18px) scale(1.08); }
  60%       { transform: translateY(-6px)  scale(1.02); }
}

.tile.bounce {
  animation: tileBounce 0.5s ease-in-out var(--bounce-delay, 0s);
}

@media (prefers-reduced-motion: reduce) {
  .tile.bounce { animation: none; }
}

/* ── Confetti ─────────────────────────────────────────────────────────────── */
.confetti-wrap {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 9999;
  overflow: hidden;
}

.confetti-piece {
  position: absolute;
  top: -14px;
  animation: confettiFall linear forwards;
  will-change: transform, opacity;
}

@keyframes confettiFall {
  from {
    transform: translate(0, 0) rotate(0deg);
    opacity: 1;
  }
  85% { opacity: 1; }
  to {
    transform: translate(var(--drift), 105vh) rotate(var(--spin));
    opacity: 0;
  }
}

/* ── Answer section ───────────────────────────────────────────────────────── */
.answer-section {
  display: none;
  margin-bottom: 12px;
  padding: 12px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  box-shadow: 0 10px 24px var(--shadow);
}

.answer-section.visible { display: block; }

.answer-label {
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 8px;
  text-align: center;
  font-weight: 950;
}

.answer-row.win .tile {
  background: var(--correct);
  border-color: var(--correct);
  color: white;
}

.answer-row.loss .tile {
  background: var(--tile-bg);
  border-color: var(--tile-border);
  color: var(--text);
}

/* ── Bottom panel / entry ─────────────────────────────────────────────────── */
.bottom-panel {
  background: var(--panel-gradient);
  border-top: 1px solid var(--border);
  box-shadow: 0 -18px 50px var(--shadow);
  padding: 10px 12px calc(10px + env(safe-area-inset-bottom));
  z-index: 5;
}

.bottom-inner {
  max-width: 520px;
  margin: 0 auto;
}

.entry-control {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: stretch;
  margin-bottom: 8px;
}

/* Long equations: stack entry tiles above the guess button */
.entry-control.stacked {
  grid-template-columns: 1fr;
}

.entry-control.stacked .entry-guess-button {
  min-height: 44px;
  border-radius: 14px;
  width: 100%;
}

.entry-control.stacked .entry-invalid-msg {
  min-height: 44px;
  border-radius: 14px;
  width: 100%;
}

.entry-row-wrap {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 9px;
  min-width: 0;
  position: relative;
}

/* ── Entry validity / invalid state ───────────────────────────────────────────── */
.entry-action {
  display: flex;
  align-items: stretch;
}

.entry-invalid-msg {
  display: none;
  min-width: 76px;
  padding: 0 12px;
  border: 2px solid #e03131;
  border-radius: 18px;
  color: #e03131;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  align-items: center;
  justify-content: center;
  line-height: 1.3;
}

.entry-row-wrap.invalid {
  border-color: #e03131;
  box-shadow: 0 0 0 2px rgba(224, 49, 49, 0.15);
  transition: border-color 0.15s, box-shadow 0.15s;
}

@keyframes shake {
  0%, 100% { transform: translateX(0);    }
  15%       { transform: translateX(-6px); }
  30%       { transform: translateX(6px);  }
  45%       { transform: translateX(-5px); }
  60%       { transform: translateX(5px);  }
  75%       { transform: translateX(-3px); }
  90%       { transform: translateX(3px);  }
}

.entry-row-wrap.shake {
  animation: shake 0.45s ease-in-out;
}

@media (prefers-reduced-motion: reduce) {
  .entry-row-wrap.shake { animation: none; }
}

.entry-guess-button {
  border: 2px solid var(--accent);
  border-radius: 18px;
  background: var(--accent);
  color: white;
  min-width: 76px;
  padding: 0 12px;
  font-size: 16px;
  font-weight: 950;
  cursor: pointer;
  box-shadow: 0 6px 14px var(--shadow);
}

.entry-guess-button:active {
  transform: translateY(1px);
  box-shadow: 0 3px 8px var(--shadow);
}

.entry-guess-button:disabled,
.calc-btn:disabled {
  opacity: .55;
  cursor: not-allowed;
  transform: none;
}

.entry-tile {
  width: 100%;
  aspect-ratio: var(--tile-aspect, 1 / 1);
  min-width: 0;
  border: 2px solid var(--tile-border);
  border-radius: clamp(5px, 1.8vw, 11px);
  display: grid;
  place-items: center;
  background: var(--tile-bg);
  color: var(--text);
  font-size: clamp(10px, calc(40vw / var(--cols)), 24px);
  font-weight: 950;
  line-height: 1;
}

.entry-tile.filled {
  border-color: var(--accent);
  background: var(--surface-2);
}

.entry-tile.cursor {
  border-color: var(--present);
  box-shadow: 0 0 0 3px rgba(245,159,0,.18);
}

/* ── Message ──────────────────────────────────────────────────────────────── */
.message {
  min-height: 22px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.3;
  text-align: center;
  margin: 0 0 8px;
  font-weight: 800;
}

.message.bad  { color: var(--danger); }
.message.good { color: var(--success); }

/* ── Calculator ───────────────────────────────────────────────────────────── */
.calculator {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
}

.calc-btn {
  border: 2px solid var(--border);
  border-radius: 16px;
  min-height: 52px;
  background: var(--key-bg);
  color: var(--key-text);
  font-size: 22px;
  font-weight: 950;
  cursor: pointer;
  box-shadow: 0 6px 14px var(--shadow);
  position: relative;
}

.calc-btn:active {
  transform: translateY(1px);
  background: var(--key-bg-hover);
  box-shadow: 0 3px 8px var(--shadow);
}

.calc-btn.num,
.calc-btn.op,
.calc-btn.equals,
.calc-btn.control {
  background: var(--key-bg);
  color: var(--key-text);
}

.calc-btn.op,
.calc-btn.equals {
  color: var(--accent);
}

.calc-btn.control {
  color: var(--muted);
  font-size: 18px;
}

.calc-btn.danger {
  background: var(--surface-2);
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 38%, var(--border));
  font-size: 18px;
}

.calc-btn.wide {
  grid-column: span 3;
}

.calc-btn.delete-wide {
  grid-column: span 3;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 42%, var(--border));
  font-size: 18px;
}

.calc-btn.known-correct,
.calc-btn.known-present,
.calc-btn.known-absent {
  background: var(--key-bg);
  color: var(--key-text);
  border-width: 3px;
}

.calc-btn.known-correct {
  border-color: var(--correct);
  box-shadow: 0 0 0 2px rgba(47,158,68,.18), 0 6px 14px var(--shadow);
}

.calc-btn.known-present {
  border-color: var(--present);
  box-shadow: 0 0 0 2px rgba(245,159,0,.18), 0 6px 14px var(--shadow);
}

.calc-btn.known-absent {
  border-color: var(--absent);
  color: var(--muted);
  box-shadow: 0 0 0 2px rgba(134,142,150,.14), 0 6px 14px var(--shadow);
}

.calc-btn.known-correct::before,
.calc-btn.known-present::before,
.calc-btn.known-absent::before {
  content: "";
  position: absolute;
  right: 7px;
  top: 7px;
  width: 9px;
  height: 9px;
  border-radius: 99px;
  z-index: 1;
}

.calc-btn.known-correct::before { background: var(--correct); }
.calc-btn.known-present::before  { background: var(--present); }
.calc-btn.known-absent::before   { background: var(--absent); }

.calc-btn.wide-equals {
  grid-column: span 4;
  color: var(--accent);
  font-weight: 900;
}

.calc-btn.decimal {
  color: var(--muted);
  font-size: 24px;
  font-weight: 900;
}

/* ── Score section ────────────────────────────────────────────────────────── */
.score-section {
  text-align: center;
  padding: 14px 0 6px;
}

.score-label {
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
  margin-bottom: 4px;
}

.score-total {
  font-size: 46px;
  font-weight: 900;
  line-height: 1;
  color: var(--text);
}

.score-pts {
  font-size: 16px;
  font-weight: 600;
  color: var(--muted);
  margin-left: 2px;
}

.score-breakdown {
  display: flex;
  gap: 10px;
  justify-content: center;
  flex-wrap: wrap;
  margin-top: 8px;
}

.score-pill {
  font-size: 13px;
  font-weight: 700;
  padding: 3px 10px;
  border-radius: 99px;
  border: 2px solid;
}

.score-pill.correct {
  color: var(--correct);
  border-color: var(--correct);
  background: color-mix(in srgb, var(--correct) 12%, transparent);
}

.score-pill.present {
  color: var(--present);
  border-color: var(--present);
  background: color-mix(in srgb, var(--present) 12%, transparent);
}

.score-pill.absent {
  color: var(--absent);
  border-color: var(--absent);
  background: color-mix(in srgb, var(--absent) 10%, transparent);
}

.share-button {
  display: block;
  width: 100%;
  margin-top: 14px;
  padding: 11px 0;
  border: none;
  border-radius: 999px;
  background: var(--accent);
  color: white;
  font-size: 15px;
  font-weight: 700;
  cursor: pointer;
  letter-spacing: 0.02em;
  transition: opacity 0.15s, transform 0.1s;
}

.share-button:active {
  opacity: 0.8;
  transform: scale(0.97);
}

.score-pill.speed {
  color: var(--accent);
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}

/* ── Footer controls ──────────────────────────────────────────────────────── */
.mini-rules {
  color: var(--muted);
  font-size: 11px;
  text-align: center;
  margin-top: 8px;
  line-height: 1.35;
  font-weight: 750;
}

.reset-row {
  margin-top: 9px;
  display: flex;
  justify-content: center;
}

/* When a game is complete, hide everything except the reset button so the
   board, answer and score fill the screen without the keyboard in the way. */
.bottom-panel.game-done .entry-control,
.bottom-panel.game-done .message,
.bottom-panel.game-done .calculator,
.bottom-panel.game-done .mini-rules { display: none; }

.bottom-panel.game-done {
  padding-top: 6px;
  padding-bottom: calc(6px + env(safe-area-inset-bottom));
  box-shadow: none;
  border-top-color: transparent;
}

.bottom-panel.game-done .reset-row { margin-top: 0; }

.reset-button {
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  min-height: 36px;
  padding: 0 13px;
  border-radius: 999px;
  font-weight: 900;
  cursor: pointer;
}

/* ── Loading / Error screens ─────────────────────────────────────────────── */
.loading-shell {
  height: 100vh;
  height: 100dvh;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.loading-inner {
  padding: 24px;
}

.loading-msg {
  color: var(--muted);
  font-size: 17px;
  font-weight: 700;
  margin-top: 18px;
}

.error-msg {
  color: var(--danger);
  font-size: 16px;
  font-weight: 700;
  margin-top: 18px;
  line-height: 1.6;
}

.retry-button {
  margin-top: 22px;
  border: 2px solid var(--accent);
  border-radius: 999px;
  background: var(--accent);
  color: white;
  padding: 11px 26px;
  font-size: 16px;
  font-weight: 950;
  cursor: pointer;
  box-shadow: 0 6px 14px rgba(59,130,246,.3);
}

.retry-button:active {
  transform: translateY(1px);
}

/* ── History nav button (on splash screen) ────────────────────────────────── */
.history-nav-btn {
  display: flex;
  align-items: center;
  justify-content: space-between;
  width: 100%;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  border-radius: 18px;
  padding: 15px 18px;
  font-size: 15px;
  font-weight: 900;
  cursor: pointer;
  margin-top: 14px;
  margin-bottom: 14px;
  box-shadow: 0 4px 16px var(--shadow);
  transition: transform .18s, box-shadow .18s;
  text-align: left;
}

.history-nav-btn:hover {
  transform: translateY(-1px);
  box-shadow: 0 10px 28px var(--shadow);
}

.history-nav-btn:active {
  transform: translateY(1px);
}

.history-nav-arrow {
  font-size: 20px;
  color: var(--muted);
  line-height: 1;
  flex-shrink: 0;
}

/* ── History view ─────────────────────────────────────────────────────────── */
.history-view {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  padding: calc(62px + env(safe-area-inset-top)) 16px calc(20px + env(safe-area-inset-bottom));
}

.history-inner {
  width: 100%;
  max-width: 780px;
  margin: 0 auto;
}

.history-heading {
  text-align: center;
  margin-bottom: 20px;
}

.history-title {
  margin: 0;
  font-size: 26px;
  font-weight: 950;
  letter-spacing: -0.5px;
}

/* ── History / Stats tabs ───────────────────────────────────────────────────── */
.history-tabs {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-bottom: 24px;
}

.history-tab {
  flex: 1;
  max-width: 160px;
  padding: 9px 0;
  border: 2px solid var(--border);
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: background 0.15s, color 0.15s, border-color 0.15s;
}

.history-tab.active {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}

/* ── Streak grid ── */
.streak-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 24px;
}

.streak-card {
  border-radius: 22px;
  padding: 18px 16px 14px;
  position: relative;
  overflow: hidden;
  box-shadow: 0 10px 32px var(--shadow);
}

.streak-card::before {
  content: "";
  position: absolute;
  width: 120px;
  height: 120px;
  border-radius: 50%;
  background: rgba(255,255,255,.08);
  right: -28px;
  bottom: -36px;
  pointer-events: none;
}

.streak-card.easy { background: linear-gradient(140deg, #059669 0%, #0ea5e9 100%); }
.streak-card.hard { background: linear-gradient(140deg, #7c3aed 0%, #db2777 100%); }

.streak-mode-name {
  font-size: 12px;
  font-weight: 900;
  color: rgba(255,255,255,.72);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
  position: relative;
  z-index: 1;
}

.streak-stats {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 10px;
  position: relative;
  z-index: 1;
}

.streak-stat {
  display: flex;
  flex-direction: column;
  align-items: center;
}

.streak-num {
  font-size: 30px;
  font-weight: 950;
  color: rgba(255,255,255,.96);
  line-height: 1;
  letter-spacing: -1px;
}

.streak-label {
  font-size: 9px;
  font-weight: 900;
  color: rgba(255,255,255,.62);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-top: 3px;
}

.streak-sep {
  width: 1px;
  height: 32px;
  background: rgba(255,255,255,.22);
  flex-shrink: 0;
}

.streak-played {
  font-size: 11px;
  font-weight: 800;
  color: rgba(255,255,255,.55);
  position: relative;
  z-index: 1;
}

/* ── Guess distribution chart ───────────────────────────────────────────────── */
.distro-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
  margin-bottom: 24px;
}

@media (max-width: 420px) {
  .distro-grid { grid-template-columns: 1fr; }
}

.distro-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 18px;
  padding: 14px 14px 12px;
}

.distro-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  margin-bottom: 10px;
}

.distro-chart {
  display: flex;
  flex-direction: column;
  gap: 5px;
}

.distro-row {
  display: flex;
  align-items: center;
  gap: 7px;
}

.distro-label {
  width: 16px;
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-align: right;
  flex-shrink: 0;
}

.distro-label.unsolved { color: var(--absent); }

.distro-bar-wrap {
  display: flex;
  align-items: center;
  flex: 1;
  gap: 5px;
  min-width: 0;
}

.distro-bar {
  height: 20px;
  border-radius: 4px;
  background: var(--absent);
  min-width: 2px;
  transition: width 0.35s ease;
  flex-shrink: 0;
}

.distro-bar.highlight { background: var(--correct); }

.distro-count {
  font-size: 12px;
  font-weight: 700;
  color: var(--text);
  flex-shrink: 0;
}

/* ── History list ── */
.history-day {
  margin-bottom: 22px;
}

.history-day-header {
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding-bottom: 8px;
  border-bottom: 1px solid var(--border);
  margin-bottom: 10px;
}

.history-day-primary {
  font-size: 15px;
  font-weight: 950;
}

.history-day-secondary {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
}

.history-day-entries {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

/* ── History entry card ── */
.history-entry {
  background: var(--surface);
  border: 1.5px solid var(--border);
  border-radius: 18px;
  overflow: hidden;
  box-shadow: 0 4px 14px var(--shadow);
  transition: border-color .2s;
}

.history-entry.easy.open { border-color: color-mix(in srgb, #059669 50%, var(--border)); }
.history-entry.hard.open { border-color: color-mix(in srgb, #7c3aed 50%, var(--border)); }

.history-entry-toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  background: none;
  border: none;
  padding: 12px 14px;
  cursor: pointer;
  text-align: left;
  font: inherit;
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
  transition: background .15s;
}

.history-entry-toggle:hover { background: var(--surface-2); }

.history-mode-badge {
  font-size: 10px;
  font-weight: 900;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 3px 9px;
  border-radius: 99px;
  flex-shrink: 0;
  color: white;
}

.history-mode-badge.easy { background: #059669; }
.history-mode-badge.hard { background: #7c3aed; }

.history-result {
  font-size: 14px;
  font-weight: 800;
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-result.won    { color: var(--correct); }
.history-result.failed { color: var(--muted); }

.history-score-val {
  font-size: 13px;
  font-weight: 900;
  color: var(--muted);
  flex-shrink: 0;
  white-space: nowrap;
}

.history-chevron {
  font-size: 18px;
  font-weight: 700;
  color: var(--muted);
  flex-shrink: 0;
  transition: transform .2s;
  line-height: 1;
}

.history-entry.open .history-chevron { transform: rotate(90deg); }

/* ── Entry body (expanded) ── */
.history-entry-body {
  padding: 0 14px 14px;
  border-top: 1px solid var(--border);
}

/* ── Mini tile board ── */
.history-mini-board {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding-top: 12px;
}

.history-mini-row {
  display: grid;
  grid-template-columns: repeat(var(--hcols, 9), minmax(0, 1fr));
  gap: 3px;
  /* max-width: calc(var(--hcols, 9) * 34px + (var(--hcols, 9) - 1) * 3px); */
}

.history-mini-tile {
  width: 100%;
  aspect-ratio: 1 / 1;
  min-width: 0;
  border-radius: 5px;
  display: grid;
  place-items: center;
  font-size: clamp(7px, calc(26vw / var(--hcols, 9)), 15px);
  font-weight: 950;
  line-height: 1;
  border: 1.5px solid var(--tile-border);
  background: var(--tile-bg);
  color: var(--text);
}

.history-mini-tile.correct { background: var(--correct); border-color: var(--correct); color: white; }
.history-mini-tile.present { background: var(--present); border-color: var(--present); color: white; }
.history-mini-tile.absent  { background: var(--absent);  border-color: var(--absent);  color: white; }

.history-answer-label {
  font-size: 12px;
  font-weight: 800;
  color: var(--muted);
  margin-top: 10px;
  text-align: center;
}

.history-empty {
  text-align: center;
  color: var(--muted);
  font-size: 15px;
  font-weight: 700;
  padding: 32px 16px;
}

.history-note {
  color: var(--muted);
  font-size: 13px;
  text-align: center;
  padding: 8px 0 0;
  margin: 0;
}

/* ── Archive Picker ──────────────────────────────────────────────────────── */
.archive-section {
  margin-top: 28px;
  padding-top: 20px;
  border-top: 1px solid var(--tile-border);
}

.archive-heading {
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 14px;
}

.archive-empty {
  font-size: 14px;
  color: var(--muted);
  text-align: center;
  padding: 12px 0;
  margin: 0;
}

.archive-day {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--tile-border);
}

.archive-day:last-child { border-bottom: none; }

.archive-day-label {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.archive-day-primary {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
}

.archive-day-secondary {
  font-size: 12px;
  color: var(--muted);
}

.archive-day-buttons {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.archive-play-btn {
  padding: 6px 16px;
  font-size: 13px;
  font-weight: 600;
  background: var(--accent);
  color: white;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: opacity 0.15s;
}

.archive-play-btn:hover,
.archive-play-btn:focus-visible {
  opacity: 0.85;
}

/* ── Responsive ───────────────────────────────────────────────────────────── */

/* Two-column mode grid on wider screens */
@media (min-width: 540px) {
  .mode-grid {
    grid-template-columns: 1fr 1fr;
  }
}

/* Compact layout for short screens */
@media (max-height: 720px) {
  .game-header          { padding-top: calc(6px + env(safe-area-inset-top)); }
  .game-title           { font-size: 16px; }
  .status-strip         { margin-top: 6px; }
  .stat                 { padding: 6px 5px; }
  .bottom-panel         { padding-top: 8px; }
  .entry-row-wrap       { padding: 7px; }
  .entry-control        { margin-bottom: 6px; }
  .entry-guess-button   { min-width: 68px; border-radius: 15px; }
  .calc-btn             { min-height: 45px; border-radius: 14px; }
  .mini-rules           { display: none; }
}

/* Small phones */
@media (max-width: 360px) {
  :root                 { --tile-gap: 5px; }
  .calc-btn             { min-height: 46px; font-size: 20px; border-radius: 14px; }
  .status-strip         { gap: 5px; }
  .stat                 { padding: 7px 5px; }
  .stat strong          { font-size: 12px; }
  .mode-name            { font-size: 28px; }
}
