/* ============================================================
   Brain — Editorial Puzzle Suite
   A responsive, mobile-first design system with an NYT-Games feel:
   ink-on-paper minimalism, an editorial serif wordmark, hairline
   rules, a centered column that sits on a subtle field on desktop,
   and proper safe-area / dynamic-viewport handling for phones.
   ============================================================ */

:root {
  /* Palette — light (paper) */
  --paper: #ffffff;
  --paper-2: #f6f7f8;
  --ink: #1a1a1b;
  --ink-soft: #6c6e72;
  --hairline: #d8dade;
  --accent: #6aaa64;        /* signature green — active / correct */
  --accent-ink: #ffffff;
  --highlight: #c9b458;     /* warm gold — secondary */
  --danger: #c0392b;

  /* Per-shape palette (soft, Connections-like) */
  --color-circle:   #7cb342;
  --color-square:   #5b8def;
  --color-triangle: #e6b84b;
  --color-star:     #b07cd6;
  --color-diamond:  #e0735e;

  /* Sequence empty-cell fill */
  --cell-bg: #e8eaee;

  /* Legacy aliases — Shadow-DOM game components reference these.
     They resolve through the base tokens above, so theming the
     base tokens automatically themes the components. */
  --bg-color: var(--paper);
  --text-color: var(--ink);
  --accent-color: var(--accent);

  /* Typography */
  --font-display: Georgia, 'Iowan Old Style', 'Times New Roman', serif;
  --font-ui: ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;

  /* Shape & rhythm */
  --radius: 14px;
  --radius-sm: 10px;
  --maxw: 30rem;            /* ~480px reading column */
  --topbar-h: 3.25rem;
  --shadow-1: 0 1px 2px rgba(20, 20, 30, .05), 0 8px 24px rgba(20, 20, 30, .07);
  --shadow-2: 0 12px 40px rgba(20, 20, 30, .16);
}

[data-theme="dark"] {
  --paper: #161618;
  --paper-2: #202024;
  --ink: #f4f4f5;
  --ink-soft: #9b9ca1;
  --hairline: #36373b;
  --accent: #6aaa64;
  --accent-ink: #0e0e0f;
  --highlight: #c9b458;
  --danger: #e07065;
  --cell-bg: #2b2c31;
}

* { box-sizing: border-box; }

html { height: 100%; }

body {
  margin: 0;
  min-height: 100%;
  font-family: var(--font-ui);
  font-size: 16px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  overscroll-behavior-y: none;
}

/* ---- App shell: a centered column ---- */
.app {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  min-height: 100svh;
  min-height: 100dvh;
  max-width: var(--maxw);
  margin: 0 auto;
  background: var(--paper);
}

/* On desktop the column floats on a subtle field with hairline sides */
@media (min-width: 32rem) {
  body { background: var(--paper-2); }
  .app {
    border-inline: 1px solid var(--hairline);
    box-shadow: var(--shadow-1);
  }
}

/* ---- Top bar ---- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 0.25rem;
  min-height: var(--topbar-h);
  padding: 0 0.5rem;
  padding-top: env(safe-area-inset-top);
  border-bottom: 1px solid var(--hairline);
  background: color-mix(in srgb, var(--paper) 82%, transparent);
  backdrop-filter: saturate(1.4) blur(10px);
  -webkit-backdrop-filter: saturate(1.4) blur(10px);
}
.topbar .title {
  flex: 1;
  text-align: center;
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.3rem;
  letter-spacing: 0.01em;
}
.topbar .dateline {
  flex: 1;
  padding-left: 0.6rem;
  font-size: 0.78rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  color: var(--ink-soft);
  text-transform: uppercase;
}

.icon-btn {
  flex: 0 0 auto;
  width: 2.5rem;
  height: 2.5rem;
  display: grid;
  place-items: center;
  border: none;
  background: none;
  color: var(--ink);
  font-size: 1.3rem;
  line-height: 1;
  border-radius: 50%;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.icon-btn svg {
  width: 1.35rem;
  height: 1.35rem;
  fill: none;
  stroke: currentColor;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn:hover { background: var(--paper-2); }
.icon-btn:active { transform: scale(0.92); }
.icon-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Main screen ---- */
.screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.5rem;
  width: 100%;
  padding: 1.5rem 1.25rem calc(1.75rem + env(safe-area-inset-bottom));
}
.screen.home,
.screen.settings {
  justify-content: flex-start;
  padding-top: 1.75rem;
}
.screen.settings { align-items: stretch; gap: 2.25rem; }

/* ---- Buttons ---- */
button,
.btn {
  font-family: var(--font-ui);
  font-size: 1rem;
  font-weight: 600;
  padding: 0.85em 1.5em;
  border-radius: 999px;
  border: 1px solid var(--ink);
  background: var(--ink);
  color: var(--paper);
  cursor: pointer;
  transition: transform 0.08s ease, background 0.15s, opacity 0.15s, border-color 0.15s;
  -webkit-tap-highlight-color: transparent;
}
button:hover,
.btn:hover { transform: translateY(-1px); }
button:active,
.btn:active { transform: scale(0.97); }
button:focus-visible,
.btn:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
button:disabled { opacity: 0.5; cursor: default; transform: none; }

.btn-secondary {
  background: transparent;
  color: var(--ink);
  border-color: var(--hairline);
}
.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: color-mix(in srgb, var(--danger) 45%, var(--hairline));
}

/* ---- Landing: hero + game list ---- */
.hero { text-align: center; }
.wordmark {
  margin: 0;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(2.75rem, 14vw, 3.75rem);
  line-height: 0.95;
  letter-spacing: -0.015em;
}
.tagline {
  margin: 0.6rem 0 0;
  color: var(--ink-soft);
  font-size: 0.95rem;
}

.game-list {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  width: 100%;
}
.game-card {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem;
  text-decoration: none;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  transition: transform 0.14s ease, box-shadow 0.2s, border-color 0.2s;
}
.game-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-1);
  border-color: color-mix(in srgb, var(--ink) 22%, var(--hairline));
}
.game-card:active { transform: scale(0.99); }
.game-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }

.game-card .meta { flex: 1; min-width: 0; }
.game-card .meta h2 {
  margin: 0 0 0.1rem;
  font-family: var(--font-display);
  font-size: 1.2rem;
  font-weight: 700;
}
.game-card .meta p {
  margin: 0;
  font-size: 0.84rem;
  line-height: 1.35;
  color: var(--ink-soft);
}
.game-card .chev {
  flex: 0 0 auto;
  color: var(--ink-soft);
  font-size: 1.3rem;
  transition: transform 0.2s;
}
.game-card:hover .chev { transform: translateX(3px); }

/* Completed-today state: green tint + checkmark instead of chevron */
.game-card.done {
  background: color-mix(in srgb, var(--accent) 14%, var(--paper));
  border-color: color-mix(in srgb, var(--accent) 45%, var(--hairline));
}
.game-card .check {
  flex: 0 0 auto;
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  background: var(--accent);
  color: var(--accent-ink);
  display: none;
  place-items: center;
  font-size: 1rem;
  font-weight: 700;
}
.game-card.done .check { display: grid; }
.game-card.done .chev { display: none; }

/* Multiple icon buttons on the right of a top bar */
.topbar-actions {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
}

/* About / prose page */
.screen.prose {
  justify-content: flex-start;
  align-items: stretch;
  text-align: left;
  gap: 0;
  padding-top: 1.5rem;
}
.prose h2,
.prose h3 { font-family: var(--font-display); }
.prose-lead { font-size: 1.35rem; line-height: 1.3; margin: 0 0 1.1rem; }
.prose h3 { font-size: 1.1rem; margin: 1.6rem 0 0.45rem; }
.prose p { margin: 0 0 1rem; line-height: 1.6; }
.prose a { color: var(--accent); font-weight: 600; }
.prose-list { margin: 0 0 1rem; padding-left: 1.2rem; line-height: 1.6; }
.prose-list li { margin-bottom: 0.35rem; }
.prose-note {
  padding: 0.9rem 1rem;
  background: var(--paper-2);
  border-radius: var(--radius-sm);
}
.prose-disclaimer { font-size: 0.82rem; color: var(--ink-soft); }
.screen.prose .btn { align-self: flex-start; margin-top: 0.5rem; text-decoration: none; }

/* Game glyph badges */
.glyph {
  flex: 0 0 auto;
  width: 3.1rem;
  height: 3.1rem;
  border-radius: 12px;
  display: grid;
  place-items: center;
  background: var(--paper-2);
  font-family: var(--font-display);
  font-size: 1.5rem;
  font-weight: 700;
}
.glyph.seq {
  grid-template-columns: repeat(3, 1fr);
  grid-template-rows: repeat(3, 1fr);
  place-items: stretch;
  gap: 3px;
  padding: 0.6rem;
  background: color-mix(in srgb, var(--color-circle) 16%, var(--paper));
}
.glyph.seq i { background: var(--color-circle); border-radius: 2px; aspect-ratio: 1; }
.glyph.dig {
  color: var(--ink);
  background: color-mix(in srgb, var(--color-triangle) 20%, var(--paper));
}
.glyph.shp {
  color: var(--color-star);
  background: color-mix(in srgb, var(--color-star) 18%, var(--paper));
}

/* ---- Settings ---- */
.settings-group { display: flex; flex-direction: column; }
.danger-group { gap: 0.75rem; }
.row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 0.25rem;
  border-bottom: 1px solid var(--hairline);
}
.row .label { font-weight: 600; }
.row-hint {
  display: block;
  margin-top: 0.15rem;
  max-width: 18rem;
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--ink-soft);
}
.section-title {
  margin: 0 0 0.9rem;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
}

/* iOS-style switch (keeps .toggle/.handle/.on hooks) */
.toggle {
  flex: 0 0 auto;
  width: 52px;
  height: 32px;
  border-radius: 999px;
  border: none;
  background: var(--hairline);
  color: inherit;
  padding: 0;
  position: relative;
  cursor: pointer;
  transition: background 0.2s;
}
.toggle .handle {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35);
  transition: transform 0.2s ease;
}
.toggle.on { background: var(--accent); }
.toggle.on .handle { transform: translateX(20px); }
.toggle:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.toggle:hover,
.toggle:active { transform: none; }

/* ---- Progress calendar ---- */
.month-label {
  margin: 0 0 0.9rem;
  text-align: center;
  font-family: var(--font-display);
  font-size: 1.1rem;
  font-weight: 700;
}
.weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 22rem;
  margin: 0 auto 0.5rem;
}
.weekdays span {
  text-align: center;
  font-size: 0.66rem;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--ink-soft);
}
.calendar {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 6px;
  width: 100%;
  max-width: 22rem;
  margin: 0 auto;
}
.calendar .day {
  /* reset native button styling for interactive day cells */
  appearance: none;
  -webkit-appearance: none;
  margin: 0;
  padding: 0;
  border: none;
  font: inherit;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  border-radius: 9px;
  background: var(--paper-2);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  color: var(--ink-soft);
  cursor: pointer;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: transform 0.08s ease, box-shadow 0.15s, background 0.15s;
}
.calendar .day:hover { transform: translateY(-1px); box-shadow: var(--shadow-1); }
.calendar .day:active { transform: scale(0.94); }
.calendar .day:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.calendar .day.selected { box-shadow: inset 0 0 0 2px var(--ink); }
.calendar .day.blank {
  background: transparent;
  cursor: default;
  pointer-events: none;
}
.calendar .day.today { box-shadow: inset 0 0 0 2px var(--hairline); }
.calendar .day.active {
  background: var(--accent);
  color: var(--accent-ink);
  font-weight: 700;
}
.calendar .day.active.today { box-shadow: inset 0 0 0 2px var(--accent-ink); }
.calendar .day.active.selected { box-shadow: inset 0 0 0 2px var(--ink); }
.calendar .day .num { line-height: 1; }
.calendar .day .count { display: none; }

/* Per-day score detail */
.day-detail {
  width: 100%;
  max-width: 22rem;
  margin: 1.1rem auto 0;
}
.detail-date {
  margin: 0 0 0.6rem;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
}
.detail-list {
  list-style: none;
  margin: 0;
  padding: 0;
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  overflow: hidden;
}
.detail-list li {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0.9rem;
  border-bottom: 1px solid var(--hairline);
}
.detail-list li:last-child { border-bottom: none; }
.detail-list .g-name { font-weight: 600; }
.detail-list .g-score {
  color: var(--ink-soft);
  font-size: 0.9rem;
  font-variant-numeric: tabular-nums;
}
.detail-list .g-score strong { color: var(--accent); font-size: 1.05rem; }
.detail-list li.empty .g-name { color: var(--ink-soft); font-weight: 500; }
.detail-empty {
  margin: 0;
  padding: 0.9rem;
  text-align: center;
  color: var(--ink-soft);
  border: 1px dashed var(--hairline);
  border-radius: var(--radius-sm);
}

/* ---- Motion ---- */
@keyframes rise {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: none; }
}
.fade-in > * { animation: rise 0.45s ease both; }
.fade-in > *:nth-child(2) { animation-delay: 0.05s; }
.fade-in > *:nth-child(3) { animation-delay: 0.1s; }
.game-list .game-card { animation: rise 0.45s ease both; }
.game-list .game-card:nth-child(1) { animation-delay: 0.08s; }
.game-list .game-card:nth-child(2) { animation-delay: 0.14s; }
.game-list .game-card:nth-child(3) { animation-delay: 0.2s; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
  }
}

/* ============================================================
   Support screen — platform cards, crypto cards, home CTA
   ============================================================ */

/* Intro blurb on the support screen */
.support-intro {
  margin: 0 0 0.25rem;
  color: var(--ink-soft);
  font-size: 0.95rem;
  line-height: 1.55;
}

/* List of platform links */
.support-list {
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  width: 100%;
}

.support-link {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.85rem 1rem;
  text-decoration: none;
  color: var(--ink);
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  transition: transform 0.14s ease, box-shadow 0.2s, border-color 0.2s;
}
.support-link:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-1);
  border-color: color-mix(in srgb, var(--ink) 22%, var(--hairline));
}
.support-link:active { transform: scale(0.99); }
.support-link:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
.support-link.disabled {
  color: var(--ink-soft);
  background: var(--paper-2);
  opacity: 0.55;
  cursor: not-allowed;
}
.support-link.disabled:hover {
  transform: none;
  box-shadow: none;
  border-color: var(--hairline);
}
.support-link.disabled .chev {
  font-size: 0.74rem;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}

.support-name {
  flex: 0 0 auto;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.05rem;
}
.support-blurb {
  flex: 1;
  font-size: 0.84rem;
  color: var(--ink-soft);
  line-height: 1.35;
}

/* Crypto cards */
.crypto-card {
  background: var(--paper-2);
  border: 1px solid var(--hairline);
  border-radius: var(--radius);
  padding: 1rem;
  margin-bottom: 0.85rem;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
}

.crypto-header {
  font-size: 1rem;
  line-height: 1.2;
}
.crypto-symbol {
  font-size: 0.8rem;
  color: var(--ink-soft);
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  margin-left: 0.3rem;
}
.crypto-note {
  font-size: 0.8rem;
  color: var(--ink-soft);
}

.crypto-addr {
  font-family: ui-monospace, 'Cascadia Code', 'Source Code Pro', Menlo, Consolas, monospace;
  font-size: 0.78rem;
  line-height: 1.45;
  color: var(--ink);
  word-break: break-all;
  background: var(--paper);
  border: 1px solid var(--hairline);
  border-radius: var(--radius-sm);
  padding: 0.55rem 0.7rem;
}

.crypto-actions {
  display: flex;
  gap: 0.5rem;
}

.copy-btn {
  font-family: var(--font-ui);
  font-size: 0.78rem;
  font-weight: 600;
  padding: 0.3em 0.9em;
  border-radius: 999px;
  border: 1px solid var(--hairline);
  background: var(--paper);
  color: var(--ink);
  cursor: pointer;
  transition: background 0.15s, transform 0.08s;
  -webkit-tap-highlight-color: transparent;
}
.copy-btn:hover { background: var(--paper-2); }
.copy-btn:active { transform: scale(0.94); }
.copy-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* QR code container — always dark-on-white so the code is scannable */
.qr {
  align-self: center;
  background: #ffffff;
  padding: 0.5rem;
  border-radius: var(--radius-sm);
  max-width: 180px;
  width: 100%;
  line-height: 0; /* collapse any baseline gap around the SVG */
}
.qr svg,
.qr img {
  display: block;
  width: 100%;
  height: auto;
}

/* Home screen CTA card */
.support-card {
  display: block;
  width: 100%;
  padding: 0.85rem 1rem;
  text-align: center;
  text-decoration: none;
  font-size: 0.88rem;
  font-weight: 600;
  color: var(--ink-soft);
  background: color-mix(in srgb, var(--accent) 8%, var(--paper));
  border: 1px solid color-mix(in srgb, var(--accent) 30%, var(--hairline));
  border-radius: var(--radius);
  transition: transform 0.14s ease, box-shadow 0.2s, color 0.15s;
  margin-top: 0.25rem;
}
.support-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-1);
  color: var(--ink);
}
.support-card:active { transform: scale(0.99); }
.support-card:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; }
