/* Brand palette ported from ~/Developer/Verbull/app/Sources/Theme.swift.
   Dark is the default (matches the app); light follows prefers-color-scheme.
   IP guardrails: tiles are teal/amber, never green/yellow. */
:root {
  --teal: #1db88e;
  --teal-bright: #2bd4a7;
  --teal-ink: #04120d;
  --amber: #dba829;
  --amber-ink: #201700;
  --card-dark: #0f2a24;
  --card-mid: #1a3d30;
  /* Background gradient sampled from the app icon's own backdrop
     (#1d4939 top → #0f2a24 bottom) — smooth, no grid. */
  --bg-top: #1d4939;
  --bg: #143328;
  --bg-deep: #0f2a24;
  --fg: #f2f5f4;
  --fg-secondary: #a9b8b3;
  --line: rgba(169, 184, 179, 0.14);
  --tile-absent: rgba(160, 176, 170, 0.3);
  --tile-border: rgba(160, 176, 170, 0.32);
  --tile-border-filled: rgba(190, 208, 201, 0.6);
  --key-bg: rgba(160, 176, 170, 0.18);
  --key-bg-hover: rgba(160, 176, 170, 0.28);
  /* True icon ink — the backdrop now matches the icon's own gradient, so the
     near-black arm reads exactly as it does on the App Store icon. */
  --logo-ink: #04120d;
  --radius: 12px;
  --font-display: 'Bricolage Grotesque', -apple-system, sans-serif;
  --font-mono: 'IBM Plex Mono', ui-monospace, SFMono-Regular, Menlo, monospace;
  --font-body: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg-top: #fbfdfc;
    --bg: #f4f7f6;
    --bg-deep: #e9efec;
    --fg: #12211c;
    --fg-secondary: #4d5f59;
    --line: rgba(18, 33, 28, 0.14);
    --tile-absent: rgba(18, 33, 28, 0.18);
    --tile-border: rgba(18, 33, 28, 0.22);
    --tile-border-filled: rgba(18, 33, 28, 0.45);
    --key-bg: rgba(18, 33, 28, 0.1);
    --key-bg-hover: rgba(18, 33, 28, 0.16);
    --logo-ink: #04120d;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--fg);
  font-family: var(--font-body);
  display: flex;
  flex-direction: column;
  align-items: center;
  /* Smooth backdrop echoing the app icon: a soft teal glow up top over the
     icon's own green gradient. */
  background-color: var(--bg);
  background-image:
    radial-gradient(ellipse 90% 55% at 50% -12%, rgba(29, 184, 142, 0.12), transparent 70%),
    linear-gradient(165deg, var(--bg-top), var(--bg) 55%, var(--bg-deep));
}

/* ---------- header ---------- */

header {
  width: 100%;
  max-width: 480px;
  padding: 18px 20px 10px;
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}

.wordmark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.45rem;
  letter-spacing: -0.02em;
  display: inline-flex;
  align-items: center;
  gap: 7px;
}

/* Candlehorn V mark: the teal up-candle is baked in; the ink down-candle
   follows the scheme (lighter on dark grounds per the logo spec). */
.logo-mark .ink-body,
.logo-mark .ink-wick { stroke: var(--logo-ink); }

.header-meta {
  display: flex;
  align-items: baseline;
  gap: 12px;
  font-family: var(--font-mono);
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--fg-secondary);
}

/* Streak: teal flame + count, matching the app's streak label (flame.fill
   in accentTeal on the game screen). */
.streak {
  color: var(--teal);
  font-weight: 600;
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.streak:empty { display: none; }

/* ---------- layout ---------- */

main {
  width: 100%;
  max-width: 480px;
  padding: 14px 20px 24px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

/* ---------- first-visit intro ---------- */

#intro {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px 16px 14px;
  position: relative;
  background: linear-gradient(160deg, rgba(29, 184, 142, 0.07), transparent 55%);
}

#intro h1 {
  margin: 0 0 6px;
  font-family: var(--font-display);
  font-weight: 700;
  font-size: 1.35rem;
  letter-spacing: -0.015em;
  line-height: 1.15;
}

#intro p {
  margin: 0 0 12px;
  font-size: 0.9rem;
  color: var(--fg-secondary);
  line-height: 1.45;
}

.legend { display: flex; flex-direction: column; gap: 6px; }

.legend-row {
  display: flex;
  align-items: center;
  gap: 10px;
  font-size: 0.82rem;
  color: var(--fg-secondary);
}

.legend-tile {
  width: 26px;
  height: 26px;
  border-radius: 5px;
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 0.8rem;
}

.legend-tile.correct { background: var(--teal); color: var(--teal-ink); }
.legend-tile.present { background: var(--amber); color: var(--amber-ink); }
.legend-tile.absent { background: var(--tile-absent); color: var(--fg); }

#intro-dismiss {
  position: absolute;
  top: 8px;
  right: 8px;
  border: none;
  background: none;
  color: var(--fg-secondary);
  font-size: 1rem;
  line-height: 1;
  padding: 8px;
  cursor: pointer;
  border-radius: 8px;
}

/* ---------- board ---------- */

#board { display: flex; flex-direction: column; gap: 6px; }

.row { display: flex; gap: 6px; justify-content: center; }

.tile {
  width: 52px;
  height: 52px;
  border-radius: 8px;
  border: 2px solid var(--tile-border);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 800;
  font-size: 1.5rem;
  text-transform: uppercase;
  color: var(--fg);
}

.tile.filled { border-color: var(--tile-border-filled); }
.tile.correct { background: var(--teal); border-color: var(--teal); color: var(--teal-ink); }
.tile.present { background: var(--amber); border-color: var(--amber); color: var(--amber-ink); }
.tile.absent { background: var(--tile-absent); border-color: transparent; }

@keyframes tile-pop {
  0% { transform: scale(1); }
  45% { transform: scale(1.1); }
  100% { transform: scale(1); }
}
.tile.pop { animation: tile-pop 0.12s ease-out; }

@keyframes tile-flip {
  0% { transform: rotateX(0); }
  50% { transform: rotateX(-90deg); }
  100% { transform: rotateX(0); }
}
.tile.flip { animation: tile-flip 0.52s ease both; }

@keyframes tile-bounce {
  0%, 100% { transform: translateY(0); }
  40% { transform: translateY(-14px); }
  70% { transform: translateY(3px); }
}
.tile.bounce { animation: tile-bounce 0.55s ease both; }

@keyframes row-shake {
  10%, 90% { transform: translateX(-2px); }
  25%, 75% { transform: translateX(4px); }
  50% { transform: translateX(-5px); }
}
.row.shake { animation: row-shake 0.4s ease; }

/* Narrow phones: keep 7-letter rows inside the viewport. */
@media (max-width: 400px) {
  .tile { width: 44px; height: 44px; font-size: 1.3rem; }
}

#message {
  min-height: 1.3em;
  font-family: var(--font-mono);
  font-size: 0.8rem;
  color: var(--fg-secondary);
}

/* ---------- keyboard ---------- */

#keyboard {
  display: flex;
  flex-direction: column;
  gap: 7px;
  width: 100%;
}

.kb-row { display: flex; gap: 5px; justify-content: center; }

.key {
  min-width: 30px;
  flex: 1;
  max-width: 42px;
  height: 52px;
  border: none;
  border-radius: 8px;
  background: var(--key-bg);
  color: var(--fg);
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.12s ease, transform 0.05s ease;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.key:active { transform: scale(0.94); }
@media (hover: hover) { .key:hover { background: var(--key-bg-hover); } }

.key.wide { max-width: 60px; flex: 1.5; font-size: 0.68rem; }
.key.correct { background: var(--teal); color: var(--teal-ink); }
.key.present { background: var(--amber); color: var(--amber-ink); }
.key.absent { background: var(--key-bg); opacity: 0.35; }

/* ---------- result panel ---------- */

#result-panel { display: none; width: 100%; flex-direction: column; gap: 12px; }

@keyframes panel-rise {
  from { opacity: 0; transform: translateY(14px); }
  to { opacity: 1; transform: translateY(0); }
}
#result-panel.rise { animation: panel-rise 0.4s ease both; }

/* The reveal card reads like a term sheet: mono category eyebrow,
   the answer as the "ticker", the definition as the quote. */
.reveal-card {
  background: linear-gradient(150deg, var(--card-mid), var(--card-dark) 70%);
  border: 1px solid rgba(29, 184, 142, 0.25);
  color: #f2f5f4;
  border-radius: 16px;
  padding: 18px;
}

.reveal-card .category {
  font-family: var(--font-mono);
  font-size: 0.68rem;
  font-weight: 600;
  letter-spacing: 0.14em;
  color: var(--teal-bright);
  text-transform: uppercase;
}

.reveal-card .answer {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.7rem;
  letter-spacing: 0.02em;
  margin-top: 4px;
  text-transform: uppercase;
}

.reveal-card .definition {
  margin-top: 8px;
  font-size: 0.95rem;
  line-height: 1.5;
  color: rgba(242, 245, 244, 0.88);
}

.stats-row {
  display: flex;
  justify-content: center;
  gap: 20px;
  font-family: var(--font-mono);
  font-size: 0.75rem;
  color: var(--fg-secondary);
}
.stats-row strong { color: var(--fg); font-weight: 600; }

button.primary {
  background: var(--teal);
  color: var(--teal-ink);
  border: none;
  border-radius: 14px;
  padding: 15px;
  font-family: var(--font-body);
  font-weight: 700;
  font-size: 1rem;
  cursor: pointer;
  width: 100%;
  transition: background 0.12s ease, transform 0.05s ease;
}
button.primary:active { transform: scale(0.98); }
@media (hover: hover) { button.primary:hover { background: var(--teal-bright); } }

.cta-card {
  display: flex;
  gap: 14px;
  align-items: center;
  background: rgba(29, 184, 142, 0.1);
  border: 1px solid rgba(29, 184, 142, 0.2);
  border-radius: 16px;
  padding: 14px;
}
.cta-card img { width: 56px; height: 56px; border-radius: 13px; flex: none; }
.cta-card .cta-title { font-weight: 700; font-size: 0.95rem; }
.cta-card .cta-copy { font-size: 0.85rem; color: var(--fg-secondary); margin-top: 2px; line-height: 1.4; }
.cta-card a { color: var(--teal); font-weight: 700; text-decoration: none; white-space: nowrap; }

/* Yesterday's answer — a one-line mono footnote in the term-sheet voice
   (label styled like the reveal card's category eyebrow). */
#yesterday {
  width: 100%;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  line-height: 1.6;
  color: var(--fg-secondary);
  text-align: center;
}
#yesterday .y-label {
  color: var(--teal);
  font-weight: 600;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}
#yesterday .y-answer { color: var(--fg); font-weight: 600; }

/* ---------- banner / footer / toast ---------- */

#new-puzzle-banner {
  display: none;
  width: 100%;
  max-width: 480px;
  padding: 10px 20px;
  text-align: center;
  font-size: 0.85rem;
  background: rgba(219, 168, 41, 0.14);
  border-bottom: 1px solid rgba(219, 168, 41, 0.25);
}
#new-puzzle-banner button {
  background: none;
  border: none;
  color: var(--teal);
  font-weight: 700;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 2px 4px;
}

footer {
  margin-top: auto;
  padding: 16px 20px calc(24px + env(safe-area-inset-bottom));
  font-size: 0.8rem;
  color: var(--fg-secondary);
  text-align: center;
}
footer a { color: var(--teal); font-weight: 600; text-decoration: none; }

#toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--fg);
  color: var(--bg);
  padding: 9px 18px;
  border-radius: 999px;
  font-size: 0.85rem;
  font-weight: 600;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  max-width: min(90vw, 420px);
}
#toast.visible { opacity: 1; }

/* ---------- a11y ---------- */

:is(button, a):focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}

@media (prefers-reduced-motion: reduce) {
  .tile.pop, .tile.flip, .tile.bounce, .row.shake, #result-panel.rise {
    animation: none;
  }
  .key, button.primary { transition: none; }
}
