/* DailyGrid — bold dark puzzle aesthetic, matched to the brand logo.
 * Deep navy + vibrant gradient accents. Mobile-first. */

:root {
  --bg: #0a1428;
  --bg-deep: #060d1d;
  --surface: #111f36;
  --surface-2: #182a4a;
  --ink: #f1f5f9;
  --ink-soft: #94a3b8;
  --line: #1e3a5f;
  --accent: #7c6cf6;
  --accent-2: #2dd4bf;
  --accent-grad: linear-gradient(135deg, #7c6cf6, #2dd4bf);
  --accent-soft: rgba(124, 108, 246, 0.16);
  --good: #4ade80;
  --good-soft: rgba(74, 222, 128, 0.14);
  --bad: #f87171;
  --bad-soft: rgba(248, 113, 113, 0.14);
  --warn: #fbbf24;
  --cat-words: #2dd4bf;
  --cat-numbers: #fb923c;
  --cat-logic: #a78bfa;
  --radius: 14px;
  --cell: 30px;
  --shadow: 0 4px 18px rgba(0, 0, 0, 0.35);
}

/* Light theme — same brand, daylight version */
[data-theme="light"] {
  --bg: #f4f6fb;
  --bg-deep: #ffffff;
  --surface: #ffffff;
  --surface-2: #eef1f8;
  --ink: #16233a;
  --ink-soft: #5b6b85;
  --line: #dbe2ef;
  --accent: #5b4fe0;
  --accent-2: #0d9488;
  --accent-grad: linear-gradient(135deg, #5b4fe0, #0d9488);
  --accent-soft: rgba(91, 79, 224, 0.10);
  --good: #15803d;
  --good-soft: rgba(21, 128, 61, 0.10);
  --bad: #b91c1c;
  --bad-soft: rgba(185, 28, 28, 0.08);
  --warn: #b45309;
  --shadow: 0 2px 10px rgba(22, 35, 58, 0.08);
}

[data-theme="light"] body {
  background: var(--bg);
}

[data-theme="light"] .topbar {
  background: rgba(255, 255, 255, 0.9);
}

[data-theme="light"] .brand-name {
  background: linear-gradient(120deg, #5b4fe0, #0d9488);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}

[data-theme="light"] .game-card {
  background: var(--surface);
  box-shadow: var(--shadow);
}

[data-theme="light"] .btn.primary {
  color: #fff;
  box-shadow: 0 4px 14px rgba(91, 79, 224, 0.35);
}

[data-theme="light"] .footbar {
  background: rgba(255, 255, 255, 0.92);
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background:
    radial-gradient(600px 300px at 15% -5%, rgba(124, 108, 246, 0.18), transparent 60%),
    radial-gradient(500px 260px at 90% 0%, rgba(45, 212, 191, 0.12), transparent 60%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(10, 20, 40, 0.82);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 0;
  z-index: 10;
}

.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 1.25rem; letter-spacing: -0.01em; }
.brand-name {
  background: linear-gradient(120deg, #c4b5fd, #5eead4);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-mark { font-size: 1.4rem; }
.brand-logo { width: 32px; height: 32px; border-radius: 8px; }

.topbar-right { display: flex; align-items: center; gap: 10px; }

.date-nav { display: flex; align-items: center; gap: 4px; }
.date-label { font-size: 0.85rem; color: var(--ink-soft); min-width: 86px; text-align: center; font-variant-numeric: tabular-nums; }

.icon-btn {
  border: 1px solid var(--line);
  background: var(--surface);
  color: var(--ink);
  border-radius: 8px;
  width: 34px; height: 34px;
  font-size: 1.2rem; line-height: 1;
  cursor: pointer;
}
.icon-btn:active { background: var(--surface-2); }
.clock {
  font-size: 0.9rem;
  font-weight: 700;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
  padding: 0 2px;
}

/* ---- modal ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 100;
  background: rgba(4, 8, 20, 0.6);
  backdrop-filter: blur(3px);
  display: flex; align-items: flex-start; justify-content: center;
  padding: 8vh 16px 16px;
}
.modal-overlay[hidden] { display: none; }
.modal {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: 100%; max-width: 560px;
  max-height: 80vh; display: flex; flex-direction: column;
}
.modal-head {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 16px; border-bottom: 1px solid var(--line);
}
.modal-head h2 { font-size: 1.15rem; margin: 0; letter-spacing: -0.01em; }
.modal-body { padding: 16px; overflow-y: auto; }

/* ---- stats ---- */
.stat-hero { display: flex; gap: 12px; margin-bottom: 16px; flex-wrap: wrap; }
.stat-tile {
  flex: 1 1 100px; text-align: center;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 6px;
}
.stat-tile .v { font-size: 1.5rem; font-weight: 800; color: var(--ink); }
.stat-tile .l { font-size: 0.72rem; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.04em; }
.stat-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.stat-table th { text-align: left; color: var(--ink-soft); font-weight: 600; font-size: 0.75rem; text-transform: uppercase; letter-spacing: 0.04em; padding: 6px 8px; border-bottom: 1px solid var(--line); }
.stat-table td { padding: 7px 8px; border-bottom: 1px solid var(--line); color: var(--ink); font-variant-numeric: tabular-nums; }
.stat-table tr:last-child td { border-bottom: none; }
.stat-note { font-size: 0.8rem; color: var(--ink-soft); margin-top: 12px; }

/* ---- archive ---- */
.arch-row {
  display: flex; align-items: center; gap: 10px;
  width: 100%; text-align: left;
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 12px; margin-bottom: 8px;
  cursor: pointer; color: var(--ink); font-size: 0.92rem;
}
.arch-row:hover { border-color: var(--accent); }
.arch-row.current { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent); }
.arch-date { font-weight: 700; min-width: 118px; }
.arch-diff { font-size: 0.72rem; font-weight: 800; letter-spacing: 0.05em; padding: 3px 8px; border-radius: 999px; }
.arch-solved { margin-left: auto; color: var(--ink-soft); font-size: 0.85rem; font-variant-numeric: tabular-nums; }

/* ---- newsletter ---- */
.newsletter {
  max-width: 640px; margin: 26px auto 8px; padding: 20px;
  background: var(--surface); border: 1px solid var(--line);
  border-radius: var(--radius); text-align: center;
}
.newsletter h3 { margin: 0 0 6px; font-size: 1.05rem; }
.newsletter p { color: var(--ink-soft); font-size: 0.88rem; margin: 0 0 12px; }
.newsletter-form { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }
.newsletter-form input[type="email"] {
  background: var(--surface-2); border: 1px solid var(--line);
  border-radius: 10px; padding: 10px 14px; font-size: 0.95rem;
  color: var(--ink); min-width: 220px;
}
.newsletter-done { color: var(--good, #22c55e) !important; font-weight: 700; }

/* ---- social links ---- */
.social-links { display: inline-flex; align-items: center; gap: 10px; margin-left: 6px; }
.social-links a {
  display: inline-flex; align-items: center; justify-content: center;
  width: 30px; height: 30px; border-radius: 50%;
  border: 1px solid var(--line); color: var(--ink-soft);
  transition: color 0.15s, border-color 0.15s;
}
.social-links a:hover { color: var(--accent-2); border-color: var(--accent-2); }

/* ---- streak savior banner ---- */
.savior-banner {
  max-width: 640px; margin: 0 auto 14px; padding: 10px 16px;
  background: var(--warn-soft, rgba(180, 83, 9, 0.12));
  border: 1px solid var(--warn, #b45309);
  border-radius: 10px; color: var(--ink);
  font-size: 0.88rem; font-weight: 600; text-align: center;
}

.streak {
  font-weight: 700;
  background: rgba(251, 146, 60, 0.14);
  border: 1px solid rgba(251, 146, 60, 0.45);
  color: #fdba74;
  border-radius: 999px;
  padding: 6px 12px;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* ---------- tabs ---------- */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
  position: sticky;
  top: 55px;
  z-index: 9;
}

.tab {
  flex: 1;
  border: none;
  background: none;
  padding: 12px 4px 10px;
  font-size: 0.95rem;
  font-weight: 600;
  color: var(--ink-soft);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  min-height: 48px;
}
.tab .tick { color: var(--good); font-weight: 800; margin-left: 2px; }
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.tab:active { background: var(--accent-soft); }

/* Homepage: category-grouped game picker (10 games) */
#tabs.home {
  display: block;
  padding: 20px 16px 28px;
  position: static;
  border-bottom: none;
  max-width: 640px;
  margin: 0 auto;
}
#tabs.game-open { display: block; padding: 8px 16px; position: sticky; top: 55px; }
.back-btn {
  border: none; background: none; color: var(--accent-2);
  font-size: 1rem; font-weight: 700; cursor: pointer; padding: 8px 0;
}
.day-progress { display: flex; align-items: center; gap: 16px; margin: 0 auto 22px; justify-content: center; flex-wrap: wrap; }
.day-progress-ring {
  --pct: 0;
  width: 72px; height: 72px; border-radius: 50%;
  display: flex; align-items: center; justify-content: center;
  background: conic-gradient(from 0deg, #7c6cf6, #2dd4bf calc(var(--pct) * 1%), rgba(30, 58, 95, 0.6) 0);
  font-weight: 800;
  box-shadow: 0 0 24px rgba(124, 108, 246, 0.35);
}
.day-progress-ring .day-progress-count {
  background: var(--bg-deep); border-radius: 50%;
  width: 58px; height: 58px; display: flex;
  align-items: center; justify-content: center; font-size: 0.9rem; color: var(--ink);
}
.day-progress-label { font-size: 1.1rem; font-weight: 700; color: var(--ink); letter-spacing: -0.01em; }
.players-pill {
  font-size: 0.82rem; font-weight: 700; color: var(--accent-2);
  background: var(--accent-soft);
  border: 1px solid var(--line);
  border-radius: 999px; padding: 5px 12px; white-space: nowrap;
}
.players-pill:empty { display: none; }
.cat-name {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.14em;
  margin: 22px 0 10px; font-weight: 800;
  display: flex; align-items: center; gap: 8px;
}
.cat-name::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.cat-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.game-card {
  --cat: var(--accent);
  display: flex; align-items: center; gap: 12px;
  background: linear-gradient(160deg, var(--surface-2), var(--surface));
  border: 1px solid var(--line);
  border-top: 2px solid var(--cat);
  border-radius: var(--radius); padding: 14px 12px; cursor: pointer; text-align: left;
  color: var(--ink); min-height: 76px; position: relative;
  box-shadow: var(--shadow);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
.game-card:active { transform: scale(0.97); }
.game-card.done { opacity: 0.72; }
.game-card.done::before {
  content: ""; position: absolute; inset: 0; border-radius: var(--radius);
  background: radial-gradient(circle at 85% 15%, color-mix(in srgb, var(--cat) 18%, transparent), transparent 55%);
  pointer-events: none;
}
.game-card-emoji {
  font-size: 1.9rem; line-height: 1;
  filter: drop-shadow(0 0 10px color-mix(in srgb, var(--cat) 55%, transparent));
}
.game-card-info { display: flex; flex-direction: column; min-width: 0; gap: 2px; }
.game-card-title { font-weight: 800; font-size: 1rem; letter-spacing: -0.01em; }
.game-card-hook { font-size: 0.78rem; color: var(--ink-soft); }
.game-card .tick {
  position: absolute; top: 8px; right: 10px;
  color: var(--good); font-weight: 800; font-size: 1.05rem;
}
.diff-badge {
  position: absolute; bottom: 8px; right: 10px;
  font-size: 0.62rem; font-weight: 800; text-transform: uppercase; letter-spacing: 0.06em;
  padding: 3px 8px; border-radius: 999px; background: rgba(148, 163, 184, 0.14); color: var(--ink-soft);
}
.diff-badge.hard { background: rgba(248, 113, 113, 0.16); color: #fca5a5; }
.diff-badge.medium { background: rgba(251, 191, 36, 0.14); color: #fcd34d; }
.diff-badge.easy { background: rgba(74, 222, 128, 0.14); color: #86efac; }

/* ---------- game area ---------- */
.game-area {
  flex: 1;
  width: 100%;
  max-width: 640px;
  margin: 0 auto;
  padding: 16px 14px 24px;
}

.loading, .error-box { text-align: center; color: var(--ink-soft); padding: 48px 16px; }
.error-box { color: var(--bad); }

.game-head { display: flex; align-items: baseline; justify-content: space-between; margin-bottom: 12px; }
.game-title { font-size: 1.45rem; font-weight: 800; margin: 0; letter-spacing: -0.02em; }
.game-sub { color: var(--ink-soft); font-size: 0.85rem; }
.timer { font-variant-numeric: tabular-nums; font-weight: 700; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 4px 10px; color: var(--accent-2); }

.howto {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 0.9rem;
  color: var(--ink-soft);
  margin-bottom: 14px;
  box-shadow: var(--shadow);
}

.btn {
  border: 1px solid var(--line);
  background: var(--surface-2);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 10px 16px;
  font-size: 0.95rem;
  font-weight: 700;
  cursor: pointer;
  min-height: 44px;
}
.btn:active { transform: translateY(1px); }
.btn.primary {
  background: var(--accent-grad);
  border: none;
  color: #0a1428;
  box-shadow: 0 4px 16px rgba(124, 108, 246, 0.4);
}
.btn.ghost { background: transparent; }

.game-actions { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }

/* win banner */
.win-banner {
  margin-top: 16px;
  background: var(--good-soft);
  border: 1px solid rgba(74, 222, 128, 0.4);
  border-radius: var(--radius);
  padding: 16px;
  text-align: center;
  box-shadow: 0 0 24px rgba(74, 222, 128, 0.12);
}
.win-banner h3 { margin: 0 0 4px; color: var(--good); font-size: 1.2rem; }
.win-banner p { margin: 4px 0 10px; color: var(--ink); }

/* ---------- cipher ---------- */
.cipher-text { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 12px; box-shadow: var(--shadow); margin-bottom: 14px; }
.cipher-word { display: inline-block; white-space: nowrap; margin: 0 7px 8px 0; }
.ctile {
  display: inline-flex; flex-direction: column; align-items: center;
  min-width: 22px; margin: 0 1px; padding: 2px 1px;
  border: 1px solid transparent; border-radius: 6px;
  background: none; cursor: pointer; font-family: inherit;
}
.ctile .c-top { font-size: 0.68rem; color: var(--ink-soft); font-weight: 700; }
.ctile .c-bot { font-size: 1.25rem; font-weight: 800; color: var(--ink); min-height: 1.5em; }
.ctile.sel { border-color: var(--accent); background: var(--accent-soft); }
.ctile.locked .c-bot { color: var(--good); }
.ctile.locked { cursor: default; }
.c-lit { display: inline-block; min-width: 10px; font-size: 1.25rem; font-weight: 800; color: var(--ink-soft); }

.cipher-progress { font-size: 0.85rem; color: var(--ink-soft); margin-bottom: 10px; font-variant-numeric: tabular-nums; }

.plain-keys { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 6px; }
.pkey {
  width: 38px; height: 44px;
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--surface); font-size: 1.05rem; font-weight: 700; color: var(--ink);
  cursor: pointer;
}
.pkey.used { background: var(--bg-deep); color: var(--ink-soft); text-decoration: line-through; }
.pkey:active { background: var(--accent-soft); }

/* ---------- pixel (nonogram) ---------- */
.pix-scroll { overflow-x: auto; padding-bottom: 8px; }
.pix-wrap {
  --n: 15;
  --pcell: 26px;
  display: grid;
  grid-template-columns: auto repeat(var(--n), var(--pcell));
  gap: 1px;
  background: var(--line);
  border: 2px solid var(--ink-soft);
  border-radius: 6px;
  overflow: hidden;
  width: max-content;
  margin: 0 auto 12px;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}
.pix-corner { background: var(--surface); min-width: 44px; }
.pix-clue-col, .pix-clue-row {
  background: var(--surface);
  display: flex; align-items: center; justify-content: center;
  font-size: 0.72rem; font-weight: 700; color: var(--ink-soft);
  line-height: 1.15; text-align: center;
  padding: 2px;
}
.pix-clue-col { flex-direction: column; min-height: 52px; }
.pix-clue-row { flex-direction: row; min-width: 44px; gap: 3px; flex-wrap: wrap; }
.pix-cell {
  width: var(--pcell); height: var(--pcell);
  background: var(--surface);
  border: none; padding: 0; cursor: pointer;
  position: relative;
}
.pix-cell.filled { background: var(--ink); }
.pix-cell.crossed::before, .pix-cell.crossed::after {
  content: ""; position: absolute; left: 15%; right: 15%; top: 50%;
  height: 2px; background: #c9cdd3; border-radius: 1px;
}
.pix-cell.crossed::before { transform: rotate(45deg); }
.pix-cell.crossed::after { transform: rotate(-45deg); }
.pix-toolbar { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; flex-wrap: wrap; }
.mode-btn.active { background: var(--accent); border-color: var(--accent); color: #fff; }

/* ---------- ladder ---------- */
.ladder-chain { display: flex; flex-direction: column; align-items: center; gap: 6px; margin-bottom: 14px; }
.rung {
  font-size: 1.6rem; font-weight: 800; letter-spacing: 0.35em; text-indent: 0.35em;
  background: var(--surface); border: 2px solid var(--line); border-radius: var(--radius);
  padding: 8px 18px; min-width: 200px; text-align: center; text-transform: uppercase;
}
.rung.anchor { border-color: var(--ink); }
.rung.target { border-style: dashed; border-color: var(--ink-soft); color: var(--ink-soft); }
.rung-link { color: var(--ink-soft); font-size: 1.2rem; line-height: 0.6; }
.ladder-status { text-align: center; color: var(--ink-soft); margin-bottom: 12px; font-variant-numeric: tabular-nums; }
.ladder-input-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 8px; }
.ladder-input {
  font-size: 1.4rem; font-weight: 800; letter-spacing: 0.3em; text-indent: 0.3em; text-transform: uppercase;
  text-align: center; width: 190px; padding: 10px;
  border: 2px solid var(--line); border-radius: var(--radius); background: var(--surface); color: var(--ink);
}
.ladder-input:focus { outline: none; border-color: var(--accent); }
.ladder-err { min-height: 1.4em; text-align: center; color: var(--bad); font-size: 0.9rem; margin-bottom: 4px; }

/* ---------- grid (sudoku) ---------- */
.sudoku {
  display: grid;
  grid-template-columns: repeat(9, 1fr);
  max-width: 420px; margin: 0 auto 14px;
  border: 3px solid var(--ink);
  border-radius: 4px; overflow: hidden;
  background: var(--surface);
  touch-action: manipulation;
}
.scell {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  background: var(--surface);
  font-size: 1.35rem; font-weight: 600; color: var(--ink);
  cursor: pointer; padding: 0;
  font-family: inherit;
}
.scell:nth-child(3n):not(:nth-child(9n)) { border-right: 2px solid var(--ink-soft); }
.scell:nth-child(n+19):nth-child(-n+27),
.scell:nth-child(n+46):nth-child(-n+54) { border-bottom: 2px solid var(--ink-soft); }
.scell.given { font-weight: 800; background: var(--surface-2); cursor: default; color: var(--ink); }
.scell.sel { background: var(--accent-soft); box-shadow: inset 0 0 0 2px var(--accent); }
.scell.peer { background: rgba(24, 42, 74, 0.5); }
.scell.same { background: rgba(124, 108, 246, 0.25); font-weight: 800; }
.scell.err { color: var(--bad); background: var(--bad-soft); }

.numpad { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; max-width: 420px; margin: 0 auto; }
.numpad .btn { font-size: 1.25rem; padding: 12px 0; }
.numpad .btn.erase { grid-column: span 1; font-size: 1rem; }

/* ---------- footer / toast ---------- */
.footbar {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  padding: 12px 14px 18px;
  border-top: 1px solid var(--line);
  background: rgba(10, 20, 40, 0.9);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  position: sticky; bottom: 0;
}
.foot-note { font-size: 0.8rem; color: var(--ink-soft); }

.toast {
  position: fixed; left: 50%; bottom: 76px; transform: translateX(-50%) translateY(20px);
  background: var(--surface-2); color: var(--ink);
  border: 1px solid var(--line);
  padding: 10px 18px; border-radius: 999px;
  font-size: 0.9rem; font-weight: 600; opacity: 0; pointer-events: none;
  transition: opacity 0.2s, transform 0.2s;
  z-index: 50; white-space: nowrap;
  box-shadow: var(--shadow);
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

@media (max-width: 520px) {
  .pix-wrap { --pcell: 20px; }
  .pix-clue-row { min-width: 36px; }
  .pix-corner { min-width: 36px; }
  .scell { font-size: 1.15rem; }
  .tab { font-size: 0.85rem; }
  .brand-name { font-size: 1.1rem; }
  .date-label { min-width: 74px; }
}

/* Wide screens: use the horizontal space instead of one narrow column */
@media (min-width: 760px) {
  #tabs.home { max-width: 980px; padding: 28px 24px 36px; }
  .day-progress { margin-bottom: 8px; }
  .cat-grid { grid-template-columns: repeat(4, 1fr); gap: 14px; }
  .game-card {
    flex-direction: column;
    text-align: center;
    justify-content: center;
    gap: 8px;
    min-height: 168px;
    padding: 20px 12px 16px;
  }
  .game-card-emoji { font-size: 2.4rem; }
  .game-card-info { align-items: center; }
  .game-area { max-width: 720px; }
}
