/* Two Halves: warm paper and ink, with one color per half.
   Tile colors are only used inside the grid, never for UI chrome. */

:root {
  --paper: #F4EFE6;
  --paper-2: #EBE4D7;
  --card: #FBF8F2;
  --ink: #1D1A15;
  --ink-2: #5B554A;
  --ink-3: #8C8577;
  --line: #DDD4C4;
  --sun: #C46A1F;
  --sun-soft: #F6E3CF;
  --moon: #3F4A8A;
  --moon-soft: #DFE2F3;
  --good: #2D7A4F;
  --bad: #B0392E;

  --tile-red: #D2453B;
  --tile-blue: #2F68C9;
  --tile-green: #2C9064;
  --tile-yellow: #E0A812;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 1px 0 rgba(29, 26, 21, 0.06), 0 6px 18px -10px rgba(29, 26, 21, 0.25);
  --display: "Fraunces", ui-serif, Georgia, serif;
  --body: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --ease: cubic-bezier(0.2, 0.7, 0.2, 1);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --paper: #16140F;
    --paper-2: #1F1C16;
    --card: #221F19;
    --ink: #F1EBDF;
    --ink-2: #BDB5A6;
    --ink-3: #8A8375;
    --line: #36312A;
    --sun: #EE9A4C;
    --sun-soft: #3A2A1B;
    --moon: #9DA8EC;
    --moon-soft: #252942;
    --good: #6BC793;
    --bad: #F07A6E;
    --tile-red: #E5574C;
    --tile-blue: #4F86E6;
    --tile-green: #3DAF7C;
    --tile-yellow: #EDB92A;
    --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 8px 22px -12px rgba(0, 0, 0, 0.6);
    color-scheme: dark;
  }
}

:root[data-theme="dark"] {
  --paper: #16140F;
  --paper-2: #1F1C16;
  --card: #221F19;
  --ink: #F1EBDF;
  --ink-2: #BDB5A6;
  --ink-3: #8A8375;
  --line: #36312A;
  --sun: #EE9A4C;
  --sun-soft: #3A2A1B;
  --moon: #9DA8EC;
  --moon-soft: #252942;
  --good: #6BC793;
  --bad: #F07A6E;
  --tile-red: #E5574C;
  --tile-blue: #4F86E6;
  --tile-green: #3DAF7C;
  --tile-yellow: #EDB92A;
  --shadow: 0 1px 0 rgba(0, 0, 0, 0.3), 0 8px 22px -12px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body { margin: 0; }

body {
  background: var(--paper);
  color: var(--ink);
  font: 400 16px/1.5 var(--body);
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
}

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

.app {
  max-width: 460px;
  margin: 0 auto;
  padding-block: 20px 32px;
  padding-left: max(16px, env(safe-area-inset-left, 0px));
  padding-right: max(16px, env(safe-area-inset-right, 0px));
}

.noscript { text-align: center; padding: 40px 16px; }

/* --- Type ----------------------------------------------------------------- */

h1, h2, h3 { font-family: var(--display); font-weight: 650; letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 40px; line-height: 1.05; }
h2 { font-size: 26px; line-height: 1.15; }
h3 { font-size: 15px; font-family: var(--body); font-weight: 600; letter-spacing: 0; }
p { margin: 0; }
.muted { color: var(--ink-2); }
.small { font-size: 14px; }
.eyebrow { font-size: 13px; font-weight: 600; letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-3); }

/* --- Top bar -------------------------------------------------------------- */

.bar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  margin-bottom: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; color: inherit; text-decoration: none; }
.brand-name { font-family: var(--display); font-weight: 650; font-size: 19px; }
.emblem { width: 28px; height: 28px; flex: none; }
.emblem-sun { fill: var(--sun); }
.emblem-moon { fill: var(--moon); }

.half-badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 5px 11px; border-radius: 999px; font-size: 14px; font-weight: 600;
}
.glyph-svg { width: 1em; height: 1em; display: block; }
.half-badge .glyph-svg { width: 15px; height: 15px; }
.half-badge.sun { background: var(--sun-soft); color: var(--sun); }
.half-badge.moon { background: var(--moon-soft); color: var(--moon); }

.timer { font-variant-numeric: tabular-nums; font-weight: 600; color: var(--ink-2); font-size: 15px; }

/* --- Home ----------------------------------------------------------------- */

.hero { padding: 28px 0 8px; }
.hero .emblem { width: 72px; height: 72px; margin-bottom: 22px; }
.hero h1 { margin: 6px 0 12px; }
.hero .lede { font-size: 18px; color: var(--ink-2); max-width: 30ch; }

.steps { list-style: none; padding: 0; margin: 28px 0; display: grid; gap: 14px; }
.steps li { display: grid; grid-template-columns: 28px 1fr; gap: 12px; align-items: start; }
.steps .n {
  width: 28px; height: 28px; border-radius: 50%; display: grid; place-items: center;
  border: 1.5px solid var(--line); font-size: 13px; font-weight: 600; color: var(--ink-2);
}

.pick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.pick-btn {
  appearance: none; border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  border-radius: var(--radius); padding: 18px 14px 16px; text-align: left; cursor: pointer;
  font: inherit; display: grid; gap: 6px; box-shadow: var(--shadow);
  transition: transform 160ms var(--ease), border-color 160ms var(--ease);
}
.pick-btn:hover { transform: translateY(-1px); }
.pick-btn.sun:hover { border-color: var(--sun); }
.pick-btn.moon:hover { border-color: var(--moon); }
.pick-btn .glyph { font-size: 26px; line-height: 1; }
.pick-btn.sun .glyph { color: var(--sun); }
.pick-btn.moon .glyph { color: var(--moon); }
.pick-btn strong { font-size: 17px; }
.pick-btn span.sub { font-size: 13.5px; color: var(--ink-2); }

.footnote { margin-top: 26px; font-size: 14px; color: var(--ink-3); text-align: center; }

/* --- Buttons -------------------------------------------------------------- */

.btn {
  appearance: none; border: 0; border-radius: 12px; font: inherit; font-weight: 600;
  min-height: 48px; padding: 0 20px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  transition: transform 120ms var(--ease), opacity 120ms var(--ease), background 160ms var(--ease);
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--ink); color: var(--paper); }
.btn-primary:disabled { opacity: 0.35; cursor: not-allowed; transform: none; }
.btn-quiet { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn-text { background: none; color: var(--ink-2); min-height: 44px; padding: 0 8px; font-weight: 500; text-decoration: underline; text-underline-offset: 3px; }
.btn-block { width: 100%; }
.row { display: flex; gap: 10px; }
.row > .btn { flex: 1; }

:focus-visible { outline: 2.5px solid var(--moon); outline-offset: 2px; border-radius: 8px; }

/* --- Invite --------------------------------------------------------------- */

.panel {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.stack { display: grid; gap: 14px; }
.stack-lg { display: grid; gap: 22px; }
.link-box {
  display: flex; align-items: center; gap: 8px; padding: 12px 14px; border-radius: var(--radius-sm);
  background: var(--paper-2); font-size: 14px; color: var(--ink-2); overflow: hidden;
}
.link-box code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: ui-monospace, "SF Mono", Consolas, monospace; font-size: 13px; }

/* --- Play ----------------------------------------------------------------- */

.play { display: grid; gap: 18px; }
.partner-note { font-size: 14.5px; color: var(--ink-2); }
.partner-note button { font-size: 14.5px; }

.board {
  display: grid;
  grid-template-columns: 20px repeat(4, 1fr);
  grid-template-rows: 20px repeat(4, auto);
  gap: 7px;
  user-select: none;
}
.axis { display: grid; place-items: center; font-size: 12.5px; font-weight: 600; color: var(--ink-3); }

.tile {
  appearance: none; position: relative; aspect-ratio: 1; border-radius: var(--radius-sm);
  border: 1.5px solid var(--line); background: var(--card); color: var(--ink);
  display: grid; place-items: center; padding: 0; cursor: pointer; font: inherit;
  transition: transform 120ms var(--ease), border-color 160ms var(--ease), background 160ms var(--ease);
}
.tile:hover { border-color: var(--ink-3); }
.tile:active { transform: scale(0.96); }
.tile svg { width: 62%; height: 62%; }
.tile .num { font-family: var(--display); font-size: clamp(26px, 8vw, 34px); font-weight: 650; line-height: 1; }
.tile .label { position: absolute; bottom: 4px; left: 0; right: 0; font-size: 10.5px; color: var(--ink-2); text-align: center; }
.tile.picked { border-color: var(--ink); background: var(--paper-2); }
.tile .pos {
  position: absolute; top: -7px; right: -7px; min-width: 22px; height: 22px; border-radius: 11px;
  background: var(--ink); color: var(--paper); font-size: 12px; font-weight: 600;
  display: grid; place-items: center; padding: 0 6px;
}
.shape-red { fill: var(--tile-red); }
.shape-blue { fill: var(--tile-blue); }
.shape-green { fill: var(--tile-green); }
.shape-yellow { fill: var(--tile-yellow); }

.code { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; }
.slot {
  appearance: none; font: inherit; color: var(--ink); cursor: pointer;
  border: 1.5px dashed var(--line); background: transparent; border-radius: var(--radius-sm);
  min-height: 56px; display: grid; place-items: center; gap: 0; padding: 6px 4px;
}
.slot .ord { font-size: 11.5px; color: var(--ink-3); font-weight: 600; }
.slot .val { font-weight: 650; font-family: var(--display); font-size: 19px; line-height: 1.1; }
.slot.filled { border-style: solid; border-color: var(--ink); background: var(--card); }
.slot.next { border-color: var(--ink-3); }

.feedback { min-height: 22px; font-size: 15px; font-weight: 500; text-align: center; }
.feedback.bad { color: var(--bad); }

.shake { animation: shake 360ms var(--ease); }
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-6px); }
  50% { transform: translateX(5px); }
  75% { transform: translateX(-3px); }
}

.clues { display: grid; gap: 10px; }
.clue-card {
  background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; display: grid; gap: 4px;
}
.clue-card header { display: flex; justify-content: space-between; align-items: baseline; }
.clue-card .ord { font-weight: 600; font-size: 14px; }
.clue-card .chosen { font-size: 13px; color: var(--ink-3); }
.clue-card ul { margin: 0; padding: 0 0 0 18px; }
.clue-card li { font-size: 15px; }
.clue-card .other { font-size: 13px; color: var(--ink-3); }

details.how { font-size: 14.5px; color: var(--ink-2); }
details.how summary { cursor: pointer; font-weight: 600; color: var(--ink); min-height: 44px; display: flex; align-items: center; }
details.how p + p { margin-top: 8px; }

.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--ink-2); cursor: pointer; min-height: 44px; }
.toggle input { width: 18px; height: 18px; accent-color: var(--ink); }

/* --- Done ----------------------------------------------------------------- */

.done { text-align: center; padding-top: 18px; }
.done .emblem { width: 84px; height: 84px; margin: 0 auto 18px; display: block; }
.done .emblem path { transition: transform 600ms var(--ease); }
.done .emblem .emblem-sun { transform: translateX(-3px); }
.done .emblem .emblem-moon { transform: translateX(3px); }
.done.joined .emblem .emblem-sun, .done.joined .emblem .emblem-moon { transform: translateX(0); }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin: 22px 0; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius-sm); padding: 12px 6px; }
.stat b { display: block; font-family: var(--display); font-size: 26px; font-weight: 650; font-variant-numeric: tabular-nums; }
.stat span { font-size: 12.5px; color: var(--ink-3); }
.done .row { margin-top: 6px; }
.next-up { margin-top: 22px; font-size: 14.5px; color: var(--ink-2); }

.toast {
  position: fixed; left: 50%; bottom: max(24px, env(safe-area-inset-bottom)); transform: translateX(-50%);
  background: var(--ink); color: var(--paper); padding: 10px 16px; border-radius: 999px; font-size: 14px;
  box-shadow: var(--shadow); animation: rise 200ms var(--ease);
}
@keyframes rise { from { opacity: 0; transform: translate(-50%, 8px); } }

/* --- Wider screens: clues sit beside the board ---------------------------- */

@media (min-width: 860px) {
  .app.wide { max-width: 900px; }
  .play-cols { display: grid; grid-template-columns: 1fr 340px; gap: 28px; align-items: start; }
}
.play-main { display: grid; gap: 14px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
