:root {
  --bg: #f4f1ea;
  --surface: #fffdf8;
  --ink: #1f2430;
  --muted: #6b6f7b;
  --cell: #fffdf8;
  --grid: #e3ddd0;
  --wall: #1f2430;
  --path: #6d5efc;
  --path-tint: #e6e2ff;
  --dot: #1f2430;
  --dot-ink: #ffffff;
  --dot-done: #6d5efc;
  --accent: #6d5efc;
  --accent-ink: #ffffff;
  --win: #18a874;
  --shadow: 0 10px 30px rgba(31, 36, 48, 0.12);
  --easy: #1f9d6b;
  --medium: #d9822b;
  --hard: #d0434f;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme='light']) {
    --bg: #14161c;
    --surface: #1c1f27;
    --ink: #eceef3;
    --muted: #9aa0ad;
    --cell: #1c1f27;
    --grid: #2c303b;
    --wall: #eceef3;
    --path: #8b7fff;
    --path-tint: #2d2a52;
    --dot: #eceef3;
    --dot-ink: #14161c;
    --dot-done: #8b7fff;
    --accent: #8b7fff;
    --accent-ink: #14161c;
    --win: #2fd194;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: 20px 16px 40px;
}

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.logo {
  margin: 0;
  font-size: 1.6rem;
  letter-spacing: -0.02em;
}
.logo span { color: var(--accent); }

.tabs {
  display: flex;
  background: var(--surface);
  border-radius: 999px;
  padding: 4px;
  box-shadow: var(--shadow);
}
.tab {
  border: 0;
  background: transparent;
  color: var(--muted);
  font: inherit;
  font-weight: 600;
  padding: 6px 14px;
  border-radius: 999px;
  cursor: pointer;
}
.tab.active { background: var(--accent); color: var(--accent-ink); }

.difficulty {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 12px;
}
.diff {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--grid);
  background: var(--surface);
  color: var(--muted);
  padding: 8px 0;
  border-radius: 10px;
  cursor: pointer;
}
.diff:hover:not(:disabled) { border-color: var(--accent); }
.diff:disabled { cursor: not-allowed; }
.diff:disabled:not(.active) { opacity: 0.45; }
.size-select:disabled { opacity: 0.6; cursor: not-allowed; }
.daily-info { margin-bottom: 12px; }
.week {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  margin-bottom: 8px;
}
.wk {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 5px 0 4px;
  border-radius: 8px;
  background: var(--surface);
  border: 2px solid transparent;
  font-size: 0.72rem;
  line-height: 1.25;
  opacity: 0.55;
}
.wk-day { font-weight: 700; color: var(--ink); }
.wk-diff { font-weight: 600; }
.wk-easy .wk-diff { color: var(--easy); }
.wk-medium .wk-diff { color: var(--medium); }
.wk-hard .wk-diff { color: var(--hard); }
.wk.today { opacity: 1; box-shadow: var(--shadow); }
.wk-easy.today { border-color: var(--easy); }
.wk-medium.today { border-color: var(--medium); }
.wk-hard.today { border-color: var(--hard); }
.countdown-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  flex-wrap: wrap;
  gap: 4px 12px;
  font-size: 0.9rem;
  margin-bottom: 6px;
}
.countdown { font-variant-numeric: tabular-nums; color: var(--accent); }
.muted { color: var(--muted); font-size: 0.8rem; }
.new-daily {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  margin-bottom: 12px;
  border-radius: 12px;
  background: var(--path-tint);
  font-weight: 600;
}
.new-daily .btn { padding: 6px 14px; }
.mode-note {
  margin: 0;
  font-size: 0.85rem;
  color: var(--muted);
  text-align: center;
}
.mode-note b { color: var(--ink); }
.diff.active[data-diff='easy'] { background: var(--easy); border-color: var(--easy); color: #fff; }
.diff.active[data-diff='medium'] { background: var(--medium); border-color: var(--medium); color: #fff; }
.diff.active[data-diff='hard'] { background: var(--hard); border-color: var(--hard); color: #fff; }

.bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.bar-left { display: flex; align-items: center; gap: 10px; }
.label { font-weight: 600; color: var(--muted); }
.size-select {
  font: inherit;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--grid);
  border-radius: 8px;
  padding: 4px 8px;
}
.timer {
  font-variant-numeric: tabular-nums;
  font-weight: 700;
  font-size: 1.1rem;
}

.board-wrap { position: relative; }

.board {
  display: block;
  width: 100%;
  aspect-ratio: 1 / 1;
  background: var(--surface);
  border-radius: 16px;
  box-shadow: var(--shadow);
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  cursor: pointer;
}

.board .cell { fill: var(--cell); transition: fill 120ms ease; }
.board .cell.on { fill: var(--path-tint); }
.board .gridline { stroke: var(--grid); stroke-width: 0.025; }
.board .frame { fill: none; stroke: var(--wall); stroke-width: 0.08; }
.board .wall { stroke: var(--wall); stroke-width: 0.14; stroke-linecap: round; }
.board .path {
  fill: none;
  stroke: var(--path);
  stroke-width: 0.5;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.board .head { fill: var(--path); }
.board .dot { fill: var(--dot); transition: fill 120ms ease; }
.board .dot.done { fill: var(--dot-done); }
.board .dot-text {
  fill: var(--dot-ink);
  font-weight: 700;
  font-size: 0.34px;
  font-variant-numeric: tabular-nums;
  text-anchor: middle;
  pointer-events: none;
}
.board .dot.done + .dot-text { fill: #fff; }
.board.solved .path { stroke: var(--win); }
.board.solved .head { fill: var(--win); }
.board.solved .dot.done { fill: var(--dot); }
.board.solved .dot.done + .dot-text { fill: var(--dot-ink); }
.board.solved .cell.on { animation: pulse 900ms ease; }
.board.shake { animation: shake 260ms ease; }

@keyframes pulse {
  0% { fill: var(--path-tint); }
  50% { fill: var(--win); }
  100% { fill: var(--path-tint); }
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-5px); }
  75% { transform: translateX(5px); }
}

.loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  border-radius: 16px;
  background: var(--surface);
  color: var(--muted);
  font-weight: 600;
}

.controls {
  display: flex;
  gap: 8px;
  justify-content: center;
  margin-top: 16px;
  flex-wrap: wrap;
}
.btn {
  font: inherit;
  font-weight: 600;
  border: 1px solid var(--grid);
  background: var(--surface);
  color: var(--ink);
  padding: 9px 16px;
  border-radius: 999px;
  cursor: pointer;
}
.btn:hover { border-color: var(--accent); }
.btn:disabled { opacity: 0.45; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.status {
  min-height: 1.4em;
  text-align: center;
  color: var(--muted);
  margin: 12px 0 4px;
}

.howto {
  margin-top: 12px;
  background: var(--surface);
  border-radius: 12px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.howto summary { cursor: pointer; font-weight: 600; }
.howto ul { padding-left: 18px; color: var(--muted); line-height: 1.55; }
.howto b { color: var(--ink); }

.modal {
  position: fixed;
  inset: 0;
  background: rgba(10, 12, 18, 0.5);
  display: grid;
  place-items: center;
  padding: 16px;
  z-index: 10;
}
.card {
  background: var(--surface);
  border-radius: 18px;
  padding: 24px;
  width: 100%;
  max-width: 360px;
  text-align: center;
  box-shadow: var(--shadow);
  animation: pop 220ms ease;
}
.card h2 { margin: 0 0 16px; color: var(--win); }
.stats { display: flex; justify-content: space-around; gap: 8px; }
.stats div { display: flex; flex-direction: column; }
.stats span { font-size: 1.6rem; font-weight: 800; font-variant-numeric: tabular-nums; }
.stats small { color: var(--muted); }
.note { color: var(--muted); min-height: 1em; }
.card-actions { display: flex; gap: 8px; justify-content: center; }

@keyframes pop {
  from { transform: scale(0.92); opacity: 0; }
  to { transform: scale(1); opacity: 1; }
}

.hidden { display: none !important; }

/* ---------- Accounts ---------- */
body.booting .app { visibility: hidden; }
body.booting .modal { background: var(--bg); }

.top { flex-wrap: wrap; }
.top-right { display: flex; align-items: center; gap: 10px; margin-left: auto; }
.user { position: relative; }
.greeting {
  font: inherit;
  font-size: 0.95rem;
  color: var(--muted);
  background: transparent;
  border: 1px solid transparent;
  border-radius: 999px;
  padding: 6px 10px;
  cursor: pointer;
  max-width: 180px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.greeting b { color: var(--ink); }
.greeting:hover, .greeting[aria-expanded='true'] { border-color: var(--grid); background: var(--surface); }
.caret { font-size: 0.7em; }
.user-menu {
  position: absolute;
  right: 0;
  top: calc(100% + 6px);
  z-index: 5;
  min-width: 190px;
  background: var(--surface);
  border: 1px solid var(--grid);
  border-radius: 12px;
  padding: 12px;
  box-shadow: var(--shadow);
}
.menu-who { margin: 0 0 10px; font-size: 0.85rem; color: var(--muted); overflow-wrap: anywhere; }
.menu-who b { color: var(--ink); }
.user-menu .btn { width: 100%; }

.modal.auth { background: var(--bg); }
.auth-card, .reveal-card { text-align: left; max-width: 380px; }
.auth-card h2, .reveal-card h2 { color: var(--ink); text-align: center; margin-bottom: 6px; }
.auth-card h2 span { color: var(--accent); }
.auth-card .note, .reveal-card .note { text-align: center; margin: 0 0 16px; }
.auth-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  background: var(--bg);
  border-radius: 999px;
  padding: 4px;
  margin-bottom: 16px;
}
.auth-tab {
  font: inherit;
  font-weight: 600;
  border: 0;
  border-radius: 999px;
  padding: 7px 0;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}
.auth-tab.active { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(0, 0, 0, 0.12); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; font-weight: 600; font-size: 0.9rem; }
.field input {
  font: inherit;
  font-weight: 500;
  font-size: 1rem;
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--grid);
  background: var(--bg);
  color: var(--ink);
}
.field input:focus { outline: 2px solid var(--accent); outline-offset: 1px; border-color: transparent; }
.code-input { font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace !important; letter-spacing: 0.08em; text-transform: uppercase; }
.auth-error { min-height: 1.2em; margin: 0 0 10px; color: var(--hard); font-size: 0.88rem; }
.btn.wide { width: 100%; padding: 11px 16px; }

.code-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  background: var(--bg);
  border: 2px dashed var(--accent);
  border-radius: 12px;
  padding: 12px 12px 12px 16px;
  margin-bottom: 14px;
}
.code-box code {
  font-family: ui-monospace, 'Cascadia Mono', Consolas, monospace;
  font-size: 1.45rem;
  font-weight: 700;
  letter-spacing: 0.1em;
  user-select: all;
}
.warning {
  background: color-mix(in srgb, var(--medium) 14%, transparent);
  border-left: 4px solid var(--medium);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 0.88rem;
  line-height: 1.45;
  margin-bottom: 14px;
}
.ack { display: flex; align-items: center; gap: 8px; margin-bottom: 14px; font-size: 0.92rem; cursor: pointer; }
.ack input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- Footer, cookie banner, policy pages ---------- */
.site-footer {
  margin-top: 28px;
  padding-top: 16px;
  border-top: 1px solid var(--grid);
  text-align: center;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}
.footer-links { display: flex; justify-content: center; flex-wrap: wrap; gap: 4px 16px; margin-bottom: 8px; }
.footer-links a, .linklike {
  color: var(--ink);
  font: inherit;
  font-weight: 600;
  text-decoration: none;
}
.footer-links a:hover, .linklike:hover { color: var(--accent); text-decoration: underline; }
.linklike { background: none; border: 0; padding: 0; cursor: pointer; }
.footer-note { margin: 4px auto; max-width: 440px; }
body.has-cookie-banner { padding-bottom: 150px; }

.cookie-banner {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 16px;
  margin: 0 auto;
  z-index: 30;
  width: min(640px, calc(100% - 32px));
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 14px 16px;
  background: var(--surface);
  color: var(--ink);
  border: 1px solid var(--grid);
  border-radius: 14px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
  animation: pop 220ms ease;
}
.cookie-text { flex: 1; font-size: 0.85rem; line-height: 1.45; }
.cookie-text p { margin: 4px 0 0; color: var(--muted); }
.cookie-text a { color: var(--accent); }
.cookie-actions { display: flex; gap: 8px; flex-shrink: 0; }
.cookie-actions .btn { padding: 8px 14px; white-space: nowrap; }
@media (max-width: 560px) {
  .cookie-banner { flex-direction: column; align-items: stretch; gap: 10px; }
  .cookie-actions .btn { flex: 1; }
  body.has-cookie-banner { padding-bottom: 230px; }
}

.auth-legal { margin: 12px 0 0; font-size: 0.75rem; color: var(--muted); line-height: 1.45; text-align: center; }
.auth-legal a, .auth-footer a { color: var(--accent); }
.auth-footer { margin: 14px 0 0; padding-top: 12px; border-top: 1px solid var(--grid); text-align: center; font-size: 0.75rem; color: var(--muted); }

.menu-danger {
  width: 100%;
  margin-top: 8px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 600;
  color: var(--hard);
  background: none;
  border: 0;
  padding: 6px;
  border-radius: 8px;
  cursor: pointer;
}
.menu-danger:hover { background: color-mix(in srgb, var(--hard) 12%, transparent); }

/* Policy pages */
.legal { max-width: 720px; margin: 0 auto; padding: 24px 16px 40px; line-height: 1.6; }
.legal-top { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 8px; }
.legal-top a { text-decoration: none; color: inherit; }
.legal-back { font-weight: 600; color: var(--accent) !important; }
.legal h1 { font-size: 1.9rem; margin: 18px 0 4px; letter-spacing: -0.02em; }
.legal h2 { font-size: 1.15rem; margin: 28px 0 6px; }
.legal .updated { color: var(--muted); margin-top: 0; }
.legal p, .legal li { color: var(--ink); }
.legal a { color: var(--accent); }
.legal .callout {
  background: var(--surface);
  border-left: 4px solid var(--accent);
  border-radius: 8px;
  padding: 12px 16px;
  box-shadow: var(--shadow);
}
.legal table { width: 100%; border-collapse: collapse; font-size: 0.9rem; margin: 8px 0; }
.legal th, .legal td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--grid); vertical-align: top; }
.legal th { background: var(--surface); }
.legal code { font-size: 0.85em; background: var(--surface); padding: 1px 5px; border-radius: 4px; }
.table-wrap { overflow-x: auto; }
.legal-top .logo { font-size: 1.4rem; font-weight: 800; color: var(--ink); }
.turnstile-box { margin: 4px 0 6px; min-height: 0; }
.turnstile-box:empty { display: none; }
.user-menu .btn + .btn { margin-top: 6px; }
