/* TREASURE CHAIN — light parchment by default, night-sea dark via toggle/OS. */
:root {
  --bg: #f6f1e7; --surface: #fffdf8; --surface2: #efe7d6; --ink: #1d1a14; --muted: #6b6355;
  --line: #ddd3c0; --accent: #6d3fd1; --accent-ink: #fff; --teal: #0b8a5f; --gold: #a8781f;
  --sea: #e7eef0; --sea-line: #cfdde1; --isle: #efe2c4; --isle-edge: #b99a5f; --route: #8a7b62;
  --danger: #b42318; --focus: #6d3fd1;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, "Book Antiqua", Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1220; --surface: #121a2b; --surface2: #18223a; --ink: #ece6d8; --muted: #a39a88;
    --line: #26324a; --accent: #a78bfa; --accent-ink: #0b1220; --teal: #34d399; --gold: #e0b252;
    --sea: #0d1830; --sea-line: #1a2847; --isle: #2a2a24; --isle-edge: #8f7a4a; --route: #b8a77f;
    --danger: #f97066; --focus: #a78bfa; color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0b1220; --surface: #121a2b; --surface2: #18223a; --ink: #ece6d8; --muted: #a39a88;
  --line: #26324a; --accent: #a78bfa; --accent-ink: #0b1220; --teal: #34d399; --gold: #e0b252;
  --sea: #0d1830; --sea-line: #1a2847; --isle: #2a2a24; --isle-edge: #8f7a4a; --route: #b8a77f;
  --danger: #f97066; --focus: #a78bfa; color-scheme: dark;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { scroll-behavior: smooth; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.55 var(--sans); }
a { color: var(--accent); }
:focus-visible { outline: 3px solid var(--focus); outline-offset: 2px; border-radius: 4px; }
.skip { position: absolute; left: -999px; top: 8px; background: var(--surface); padding: 8px 12px; z-index: 10; }
.skip:focus { left: 8px; }
.mono { font-family: var(--mono); font-size: .92em; }
.small, .muted { color: var(--muted); }
.small { font-size: .85rem; }
h1, h2, h3 { font-family: var(--serif); line-height: 1.15; letter-spacing: -.01em; }
h1 { font-size: clamp(2rem, 5vw, 3.2rem); margin: .2em 0 .35em; }
h2 { font-size: clamp(1.5rem, 3.2vw, 2rem); margin: 0 0 .6em; }

/* top bar */
.top { position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 16px;
  padding: 10px 16px; background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: 8px; text-decoration: none; color: var(--ink);
  font-weight: 700; letter-spacing: .12em; font-size: .9rem; }
.brand b { color: var(--accent); margin-left: .35em; }
.top nav { display: flex; gap: 4px; margin-left: auto; flex-wrap: wrap; }
.top nav a { color: var(--ink); text-decoration: none; padding: 6px 10px; border-radius: 8px; font-size: .95rem; }
.top nav a:hover { background: var(--surface2); }
.theme { border: 1px solid var(--line); background: var(--surface); color: var(--ink); border-radius: 8px;
  width: 38px; height: 34px; font-size: 1.1rem; cursor: pointer; }

main { max-width: 1120px; margin: 0 auto; padding: 0 16px; }
.panel { padding: 48px 0; border-top: 1px solid var(--line); }

/* hero */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.25fr); gap: 32px; align-items: center; padding: 40px 0 48px; }
.eyebrow { text-transform: uppercase; letter-spacing: .14em; font-size: .78rem; color: var(--muted); margin: 0; }
.pill { display: inline-block; padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line);
  background: var(--surface); color: var(--gold); font-weight: 700; }
.pill.live { color: var(--teal); border-color: var(--teal); }
.lede { font-size: 1.12rem; color: var(--ink); max-width: 46ch; }
.cta-row { display: flex; flex-wrap: wrap; gap: 10px; margin: 20px 0; }
.btn { display: inline-flex; align-items: center; justify-content: center; min-height: 44px; padding: 10px 18px;
  border-radius: 10px; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink);
  font: 600 1rem var(--sans); text-decoration: none; cursor: pointer; }
.btn.ghost { background: transparent; color: var(--accent); }
.btn:disabled { opacity: .6; cursor: wait; }
.linkish { background: none; border: 0; color: var(--accent); text-decoration: underline; cursor: pointer; font: inherit; padding: 0; }
.stats { display: flex; gap: 20px; color: var(--muted); }
.stats b { color: var(--ink); font-size: 1.2rem; }

/* chart */
.chart-wrap { margin: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--sea); }
.chart-wrap.has-map { background: url(/art/map.webp) center/cover; }
.chart-wrap.has-map .sea { opacity: .25; }
.chart { display: block; width: 100%; height: auto; }
.sea { fill: var(--sea); }
.gridline { stroke: var(--sea-line); stroke-width: 1; }
.isle { fill: var(--isle); stroke: var(--isle-edge); stroke-width: 2.5; }
.isle-name { font: 700 13px var(--sans); letter-spacing: .14em; fill: var(--muted); }
.route { fill: none; stroke: var(--route); stroke-width: 2; opacity: .55; stroke-dasharray: 1 8; stroke-linecap: round; stroke-linejoin: round; }
.route-done { fill: none; stroke: var(--teal); stroke-width: 4; stroke-linecap: round; stroke-linejoin: round; }
.xmark path { stroke: var(--danger); stroke-width: 6; stroke-linecap: round; }
.wp circle { fill: var(--surface); stroke: var(--route); stroke-width: 2.5; transition: transform .2s; }
.wp text { font: 700 14px var(--sans); fill: var(--ink); pointer-events: none; }
.wp:hover circle, .wp:focus circle { stroke: var(--accent); stroke-width: 4; }
.wp.got circle { fill: var(--gold); stroke: var(--gold); }
.wp.got text { fill: #1d1a14; }
.wp.next circle { fill: var(--accent); stroke: var(--accent); animation: pulse 1.6s ease-in-out infinite; transform-box: fill-box; transform-origin: center; }
.wp.next text { fill: var(--accent-ink); }
@keyframes pulse { 50% { transform: scale(1.18); } }
@media (prefers-reduced-motion: reduce) { .wp.next circle { animation: none; } html { scroll-behavior: auto; } }
.rose circle { fill: none; stroke: var(--route); }
.rose path { fill: var(--route); opacity: .7; }
.rose text { font: 700 13px var(--sans); fill: var(--muted); }

/* game */
.game { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 24px; }
.join { display: grid; gap: 14px; max-width: 520px; }
.join label { display: grid; gap: 6px; font-weight: 600; }
.opt { font-weight: 400; color: var(--muted); font-size: .9rem; }
input { font: 1rem var(--sans); padding: 11px 12px; border-radius: 10px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); min-height: 44px; width: 100%; }
.msg { min-height: 1.4em; margin: 0; color: var(--danger); }
.msg.ok { color: var(--teal); }
.bearing { display: grid; grid-template-columns: auto 1fr; gap: 20px; align-items: start; }
.bearing .art { width: 140px; }
.bearing h3 { margin: 0 0 6px; font-size: 1.5rem; }
.bearing .where { font-size: 1.08rem; }
.answer { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 12px; }
.answer input { flex: 1 1 220px; width: auto; }
.progress { height: 10px; border-radius: 99px; background: var(--surface2); overflow: hidden; margin: 6px 0 18px; }
.progress span { display: block; height: 100%; background: linear-gradient(90deg, #9945FF, #14F195); }
.lesson { border-left: 4px solid var(--teal); background: var(--surface2); padding: 12px 16px; border-radius: 0 10px 10px 0; margin: 16px 0; }
.lesson b { color: var(--teal); }
.meta-row { display: flex; flex-wrap: wrap; gap: 8px 24px; color: var(--muted); font-size: .92rem; margin-top: 20px; padding-top: 14px; border-top: 1px solid var(--line); }
.code { font-family: var(--mono); background: var(--surface2); padding: 2px 6px; border-radius: 6px; word-break: break-all; }
.log { list-style: none; padding: 0; margin: 12px 0 0; display: grid; gap: 8px; }
.log li { background: var(--surface2); border-radius: 10px; padding: 10px 14px; }
.log summary { cursor: pointer; font-weight: 600; }

/* piece art + medallion */
.art { display: block; width: 100%; height: auto; aspect-ratio: 1; border-radius: 12px; border: 1px solid var(--line); object-fit: cover; }
.medal { display: grid; place-content: center; text-align: center; gap: 6px; padding: 12px;
  background: var(--surface2); box-shadow: inset 0 0 0 6px var(--surface2), inset 0 0 0 7px var(--gold); }
.medal-n { font: 700 clamp(1.8rem, 6vw, 3.4rem) var(--serif); color: var(--gold); line-height: 1; }
.medal-name { font: 600 .82rem var(--sans); letter-spacing: .08em; text-transform: uppercase; color: var(--muted); }

/* cards */
.cards { list-style: none; padding: 0; margin: 24px 0 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); gap: 14px; }
.card a { display: grid; gap: 4px; text-decoration: none; color: var(--ink); background: var(--surface);
  border: 1px solid var(--line); border-radius: 14px; padding: 10px; height: 100%; }
.card a:hover { border-color: var(--accent); }
.card-n { font: 600 .78rem var(--mono); color: var(--muted); margin-top: 6px; }
.card-name { font: 700 1.02rem var(--serif); }
.card-host { font-size: .85rem; color: var(--muted); }
.card-state { font-size: .85rem; font-weight: 700; color: var(--teal); min-height: 1.2em; }
.card.locked .art { filter: grayscale(.85) opacity(.55); }
.card.got a { border-color: var(--gold); }

.steps, .rules { padding-left: 1.3em; max-width: 70ch; }
.steps li, .rules li { margin: 0 0 10px; }
.hosts { list-style: none; padding: 0; display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.host { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 16px 18px; }
.host h3 { margin: 0 0 4px; font-size: 1.2rem; }
.host .isle { color: var(--gold); font-weight: 600; margin: 0 0 8px; }
.finishers { padding-left: 1.4em; }
.finishers li { margin: 0 0 6px; }

/* piece page */
.crumbs { padding: 20px 0 0; color: var(--muted); font-size: .92rem; }
.piece { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 36px; padding: 24px 0 40px; align-items: start; }
.facts { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin: 20px 0; }
.facts div { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; }
.facts dt { font-size: .78rem; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.facts dd { margin: 2px 0 0; font-weight: 600; }
.piece-mine { font-weight: 700; color: var(--teal); min-height: 1.4em; }
.pager { display: flex; justify-content: space-between; gap: 12px; padding: 20px 0 40px; border-top: 1px solid var(--line); }

.foot { border-top: 1px solid var(--line); padding: 28px 16px 40px; text-align: center; color: var(--muted); }
.foot p { margin: 6px auto; max-width: 70ch; }

@media (max-width: 820px) {
  .hero, .piece { grid-template-columns: 1fr; }
  .top nav a { padding: 6px 7px; font-size: .9rem; }
  .bearing { grid-template-columns: 1fr; }
  .bearing .art { width: 120px; }
}
@media (max-width: 420px) {
  .brand span { display: none; }
  .facts { grid-template-columns: 1fr; }
  .game { padding: 16px; }
}
