:root {
  --ink: #f6ecd4;
  --muted: #e4d2b4;
  --gold: #e4c56a;
  --gold-2: #f3d58a;
  --burgundy: #4a1224;
  --navy: #0c1730;
  --panel: #241018;
  --display: Palatino, "Palatino Linotype", "Iowan Old Style", Georgia, "Times New Roman", serif;
  --ui: "Avenir Next", "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  max-width: 100%;
  overflow-x: hidden;
}

body {
  min-height: 100vh;
  min-height: 100dvh;
  font-family: var(--ui);
  color: var(--ink);
  background:
    radial-gradient(880px 420px at 0% -10%, rgba(176, 36, 58, 0.42), transparent 60%),
    radial-gradient(720px 380px at 100% 0%, rgba(28, 64, 150, 0.5), transparent 58%),
    linear-gradient(180deg, #101c38 0%, #160910 46%, #0c101c 100%);
}

button, input { font: inherit; color: inherit; }

button {
  background: transparent;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button:focus-visible {
  outline: 2px solid var(--gold-2);
  outline-offset: 3px;
}

img { max-width: 100%; display: block; }

p, h1, h2, h3, li, figcaption { overflow-wrap: break-word; }

h1, h2, h3 { font-family: var(--display); font-weight: 500; }

.shell {
  width: min(920px, 100%);
  margin: 0 auto;
  padding: 12px 12px calc(28px + env(safe-area-inset-bottom));
}

.mast {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 2px 12px;
}

.crest {
  width: 52px;
  height: 64px;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  border: 1px solid var(--gold);
  border-radius: 28px 28px 8px 8px;
  background:
    radial-gradient(circle at 50% 28%, rgba(255, 220, 150, 0.45), transparent 56%),
    linear-gradient(#7a1d36, #1a0c14);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.35);
}

.crest span {
  font-family: var(--display);
  color: var(--gold-2);
  font-size: 1.5rem;
  line-height: 1;
}

.mast-copy { flex: 1; min-width: 0; }

.eyebrow {
  margin: 0 0 3px;
  font-size: 0.68rem;
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}

.mast h1 {
  margin: 0;
  font-size: clamp(2rem, 8vw, 3.15rem);
  line-height: 0.88;
  letter-spacing: 0.03em;
}

.quiet {
  flex: 0 0 auto;
  border: 1px solid rgba(228, 197, 106, 0.65);
  border-radius: 999px;
  padding: 8px 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
  background: rgba(8, 10, 20, 0.35);
}

.rail-clip {
  position: sticky;
  top: 0;
  z-index: 6;
  overflow-x: auto;
  overscroll-behavior-x: none;
  scrollbar-width: none;
  margin: 0 -12px;
  padding: 8px 12px 12px;
  background: linear-gradient(180deg, rgba(12, 16, 34, 0.96), rgba(12, 16, 34, 0.88) 70%, transparent);
}

.rail-clip::-webkit-scrollbar { display: none; }

.rail {
  display: flex;
  gap: 8px;
  width: max-content;
  min-width: 100%;
  scroll-snap-type: x proximity;
}

.cartouche {
  flex: 0 0 auto;
  width: max-content;
  min-width: 92px;
  min-height: 58px;
  padding: 8px 12px 10px;
  scroll-snap-align: start;
  border-radius: 8px 8px 16px 16px;
  border: 1px solid rgba(228, 197, 106, 0.48);
  background: linear-gradient(180deg, rgba(255, 236, 200, 0.07), rgba(0, 0, 0, 0.28));
  color: var(--ink);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
}

.cartouche i {
  font-family: var(--display);
  font-style: normal;
  color: var(--gold);
  letter-spacing: 0.16em;
  font-size: 0.74rem;
}

.cartouche span {
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  white-space: nowrap;
}

.cartouche.on {
  background: linear-gradient(180deg, #f6dd9a, #c49245 58%, #a87532);
  color: #3a120c;
  border-color: #f6dd9a;
  box-shadow: 0 10px 18px rgba(150, 24, 40, 0.28);
}

.cartouche.on i { color: #6e1424; }

.panel { display: none; }
.panel.on { display: block; }

.sheet {
  position: relative;
  margin: 0 0 14px;
  padding: 14px;
  border-radius: 18px;
  border: 1px solid rgba(228, 197, 106, 0.5);
  background:
    linear-gradient(180deg, rgba(255, 236, 196, 0.06), transparent 28%),
    linear-gradient(180deg, #3c1424, #1c0c14 58%, #140a12);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.45), 0 16px 30px rgba(0, 0, 0, 0.22);
}

.sheet:before,
.sheet:after {
  content: "";
  position: absolute;
  width: 12px;
  height: 12px;
  border: 1px solid rgba(243, 213, 138, 0.8);
  pointer-events: none;
}

.sheet:before { top: 7px; left: 7px; border-right: 0; border-bottom: 0; }
.sheet:after { right: 7px; bottom: 7px; border-left: 0; border-top: 0; }

.kicker {
  margin: 0 0 4px;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  font-size: 0.68rem;
  color: var(--gold-2);
}

h2 { margin: 0 0 8px; font-size: clamp(1.5rem, 5vw, 2.15rem); line-height: 1.05; }
h3 { margin: 0; font-family: var(--display); font-weight: 500; font-size: 1.28rem; }

.lead, .copy { margin: 0; color: var(--muted); line-height: 1.5; }
.copy + .copy { margin-top: 8px; }

.banner {
  position: relative;
  margin: 0 0 12px;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid rgba(228, 197, 106, 0.42);
}

.banner img, .wide-photo {
  width: 100%;
  height: 168px;
  object-fit: cover;
}

.banner figcaption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  margin: 0;
  padding: 36px 12px 10px;
  background: linear-gradient(transparent, rgba(8, 6, 12, 0.9));
  font-family: var(--display);
  font-size: clamp(1.2rem, 4.5vw, 1.7rem);
}

.meters {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.meter {
  min-width: 0;
  padding: 8px 10px;
  border-radius: 12px;
  border: 1px solid rgba(228, 197, 106, 0.28);
  background: rgba(0, 0, 0, 0.28);
}

.meter span {
  display: block;
  font-size: 0.66rem;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #d9c4a4;
}

.meter strong {
  display: block;
  margin-top: 2px;
  font-family: var(--display);
  font-weight: 500;
  font-size: 1.12rem;
  font-variant-numeric: tabular-nums;
}

.pips { display: flex; gap: 5px; margin-top: 6px; }
.pips i, .diamond {
  display: inline-block;
  width: 8px;
  height: 8px;
  border: 1px solid var(--gold);
}
.pips i { border-radius: 50%; }
.pips i.on { background: var(--gold); }
.diamond { margin: 0 3px; transform: rotate(45deg); }
.diamond.on { background: var(--gold); box-shadow: 0 0 8px rgba(228, 197, 106, 0.75); }
.marks { display: flex; align-items: center; min-height: 16px; }

.picks {
  display: flex;
  gap: 8px;
  overflow-x: auto;
  overscroll-behavior-x: none;
  scrollbar-width: none;
  margin: 12px 0;
  padding-bottom: 2px;
}
.picks::-webkit-scrollbar { display: none; }

.pick {
  flex: 0 0 auto;
  max-width: 100%;
  border: 1px solid rgba(228, 197, 106, 0.48);
  border-radius: 999px;
  padding: 8px 12px;
  color: var(--ink);
  background: rgba(0, 0, 0, 0.2);
  white-space: nowrap;
}
.pick.on { background: var(--gold); color: #3a120c; border-color: var(--gold); }
.pick.is-off { opacity: 0.45; }

.stage { margin-top: 4px; }

.board {
  position: relative;
  display: grid;
  width: min(100%, 520px);
  margin: 0 auto;
  background: #070b16;
  border: 1px solid rgba(228, 197, 106, 0.5);
  border-radius: 12px;
  overflow: hidden;
}

.ray {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  z-index: 2;
  pointer-events: none;
}

.ray-glow, .ray-core {
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.ray-glow { stroke: rgba(255, 214, 120, 0.42); stroke-width: 3.4; }
.ray-core { stroke: #fff6d8; stroke-width: 1.15; }

.cell {
  position: relative;
  z-index: 1;
  display: grid;
  place-items: center;
  aspect-ratio: 1;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  color: var(--gold-2);
  padding: 0;
}

.cell:focus-visible { outline-offset: -3px; }
.board { touch-action: manipulation; }

.wall {
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.06), transparent 20%, transparent 80%, rgba(0, 0, 0, 0.4)),
    linear-gradient(#2a3548, #141b2a);
}
.floor { background: radial-gradient(circle at 30% 20%, rgba(255, 255, 255, 0.05), transparent 42%), #16243d; }
.floor.hot { background: #2a4068; }
.lamp {
  background: radial-gradient(circle at 50% 42%, #ffe7a8, #d4893a 40%, #3a1d12 72%);
}
.lamp:after {
  content: "";
  position: absolute;
  right: 0;
  top: 36%;
  width: 30%;
  height: 28%;
  background: linear-gradient(90deg, rgba(255, 226, 160, 0.95), transparent);
}
.mirror { background: #10192e; }
.mirror i, .sample-bar {
  position: absolute;
  width: 74%;
  height: 14%;
  left: 13%;
  top: 43%;
  border-radius: 99px;
  background: linear-gradient(#fff6d2, #e4c56a 45%, #8d6424);
  box-shadow: 0 0 8px rgba(255, 220, 140, 0.4);
}
.mirror.slash i { transform: rotate(-45deg); }
.mirror.back i { transform: rotate(45deg); }
.dial {
  background: radial-gradient(circle at 50% 50%, #10203f 0 58%, #0c1730 60%);
}
.dial i {
  position: absolute;
  width: 9%;
  height: 34%;
  left: 45.5%;
  top: 16%;
  border-radius: 4px;
  background: linear-gradient(#fff1c4, #d4a84a);
  transform-origin: 50% 100%;
}
.dial.d0 i { transform: rotate(90deg); }
.dial.d1 i { transform: rotate(180deg); }
.dial.d2 i { transform: rotate(270deg); }
.dial.d3 i { transform: rotate(0deg); }
.dial b {
  position: absolute;
  width: 16%;
  height: 16%;
  border-radius: 50%;
  background: var(--gold-2);
}
.mosaic {
  background:
    linear-gradient(115deg, transparent 42%, rgba(8, 4, 8, 0.78) 42% 48%, transparent 48% 58%, rgba(8, 4, 8, 0.78) 58% 64%, transparent 64%),
    conic-gradient(from 20deg, #7a2038, #1c3f86, #e4c56a, #f4ead4, #7a2038);
}
.mosaic.on { box-shadow: inset 0 0 0 2px #f3d58a, 0 0 12px rgba(243, 213, 138, 0.7); }
.relic { background: #161126; }
.relic i {
  width: 30%;
  height: 44%;
  border: 2px solid rgba(228, 197, 106, 0.5);
  border-radius: 50% 50% 46% 46%;
}
.relic.on i {
  background: radial-gradient(circle at 40% 35%, #fff6d0, #e4c56a 46%, #8a6230);
  border-color: #f3d58a;
  box-shadow: 0 0 10px rgba(243, 213, 138, 0.85);
}
.hour { background: #140c18; }
.hour strong {
  font-family: var(--display);
  font-weight: 500;
  font-size: clamp(0.68rem, 2.6vw, 1rem);
  letter-spacing: 0.04em;
  color: rgba(243, 213, 138, 0.5);
}
.hour.on { background: #3d2c12; }
.hour.on strong { color: #fff1c4; }
.door { background: #2a1018; }
.door:before {
  content: "";
  width: 58%;
  height: 74%;
  border: 2px solid var(--gold);
  border-bottom: 0;
  border-radius: 40px 40px 3px 3px;
}
.door.on {
  background: #6a3c16;
  box-shadow: inset 0 0 16px rgba(255, 214, 130, 0.9);
}

.note {
  min-height: 2.8em;
  margin: 10px 0 0;
  text-align: center;
  color: var(--ink);
  line-height: 1.4;
}

.hint { margin: 4px 0 0; text-align: center; color: var(--muted); font-size: 0.92rem; }

.legend {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  margin: 12px 0 0;
  padding: 0;
  list-style: none;
}
.legend li { display: flex; align-items: center; gap: 6px; font-size: 0.78rem; color: var(--muted); }
.swatch { width: 12px; height: 12px; border: 1px solid rgba(228, 197, 106, 0.7); display: inline-block; }
.swatch.mirror { background: linear-gradient(#fff6d2, #8d6424); }
.swatch.dial { border-radius: 50%; background: #10203f; }
.swatch.mosaic { background: conic-gradient(#7a2038, #1c3f86, #e4c56a, #f4ead4); }
.swatch.hour { background: #3d2c12; }
.swatch.door { background: #6a3c16; }
.swatch.relic { border-radius: 50%; background: #e4c56a; }

.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin-top: 12px;
}

.controls button {
  min-height: 64px;
  padding: 8px 4px;
  border-radius: 16px;
  border: 1px solid rgba(228, 197, 106, 0.62);
  background: linear-gradient(180deg, rgba(255, 226, 170, 0.1), rgba(0, 0, 0, 0.28));
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
}

.controls button b {
  font-family: var(--display);
  font-weight: 500;
  font-size: 1rem;
  color: var(--gold-2);
}
.controls button span {
  font-size: 0.68rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.controls button.is-off,
.controls button:disabled { opacity: 0.42; }

.help { margin-top: 12px; border-top: 1px solid rgba(228, 197, 106, 0.22); padding-top: 8px; }
.help summary { cursor: pointer; letter-spacing: 0.06em; }
.help ol { margin: 8px 0 0; padding-left: 1.15rem; color: var(--muted); }
.help li { margin: 6px 0; line-height: 1.4; }

.solid, .ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 48px;
  max-width: 100%;
  padding: 12px 16px;
  border-radius: 999px;
}
.solid {
  color: #fff8ea;
  border: 1px solid var(--gold);
  background: linear-gradient(#ff6868, #b42338 46%, #6e1020);
  box-shadow: inset 0 1px 0 rgba(255, 255, 255, 0.4), 0 8px 16px rgba(110, 12, 24, 0.35);
  letter-spacing: 0.04em;
  font-weight: 700;
}
.ghost {
  border: 1px solid rgba(228, 197, 106, 0.7);
  color: var(--ink);
  background: rgba(0, 0, 0, 0.2);
}

.shade {
  position: fixed;
  inset: 0;
  z-index: 20;
  background: rgba(6, 8, 16, 0.72);
}
.veil {
  position: fixed;
  z-index: 21;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(440px, calc(100% - 28px));
  max-height: calc(100% - 28px);
  overflow: auto;
  margin: 0;
  text-align: center;
}
.veil h2 { margin-top: 4px; }
.veil-actions { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin-top: 14px; }
.shade[hidden], .veil[hidden], [hidden] { display: none !important; }

.wide-photo { border-radius: 14px; margin-bottom: 12px; border: 1px solid rgba(228, 197, 106, 0.35); height: 190px; }

.mech {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  align-items: center;
}
.sample { width: 58px; height: 58px; }
.sample .cell { width: 58px; height: 58px; border-radius: 8px; border: 1px solid rgba(228, 197, 106, 0.35); }

.enfilade { position: relative; display: flex; flex-direction: column; gap: 14px; }
.enfilade:before {
  content: "";
  position: absolute;
  top: 10px;
  bottom: 10px;
  left: 16px;
  width: 1px;
  background: linear-gradient(var(--gold), rgba(228, 197, 106, 0.05));
}
.doorcard {
  margin-left: 34px;
  border-radius: 16px;
  overflow: hidden;
  border: 1px solid rgba(228, 197, 106, 0.48);
  background: linear-gradient(180deg, rgba(255, 236, 196, 0.05), transparent 26%), #2a1018;
  min-width: 0;
}
.doorcard img { width: 100%; height: 128px; object-fit: cover; }
.doorcard .body { padding: 12px; }
.doorcard .body p { margin: 8px 0; color: var(--muted); line-height: 1.45; }
.doorcard .row { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; justify-content: space-between; }
.doorcard.is-locked { opacity: 0.7; }

.tag {
  display: inline-block;
  border: 1px solid rgba(228, 197, 106, 0.55);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 0.66rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}
.tag.done { background: var(--gold); color: #3a120c; border-color: var(--gold); }
.tag.wait { color: var(--gold-2); }

.relics { display: grid; grid-template-columns: 1fr; gap: 12px; }
.relic-card {
  display: grid;
  grid-template-columns: 58px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
  padding: 12px;
  border-radius: 16px;
  border: 1px solid rgba(228, 197, 106, 0.4);
  background: rgba(16, 8, 14, 0.55);
  min-width: 0;
}
.seal {
  width: 58px;
  height: 58px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  border: 1px solid rgba(228, 197, 106, 0.65);
  font-family: var(--display);
  color: var(--gold);
  background: radial-gradient(circle at 40% 35%, rgba(255, 230, 170, 0.2), transparent 60%), #1a0c14;
}
.relic-card.is-found .seal {
  background: radial-gradient(circle at 40% 35%, #fff1c2, #c49245 62%, #6e3d12);
  color: #3a120c;
}
.relic-card h3 { font-size: 1.15rem; }
.relic-card p { margin: 6px 0 0; color: var(--muted); line-height: 1.4; }
.relic-card.is-locked { opacity: 0.78; }

.run {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid rgba(228, 197, 106, 0.18);
}
.run span { color: var(--muted); font-variant-numeric: tabular-nums; }
.ask {
  margin-top: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid rgba(228, 197, 106, 0.35);
  background: rgba(0, 0, 0, 0.25);
}
.ask p { margin: 0 0 10px; }
.ask .veil-actions { margin-top: 0; }

.stats {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}

@media (min-width: 640px) {
  .meters { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .banner img, .wide-photo { height: 220px; }
  .sheet { padding: 18px; }
}

@media (min-width: 760px) {
  .rail { width: 100%; }
  .cartouche { flex: 1 1 0; width: auto; min-width: 0; }
  .enfilade:before { left: 50%; }
  .doorcard { width: calc(50% - 28px); margin-left: 0; }
  .doorcard:nth-child(odd) { margin-right: auto; }
  .doorcard:nth-child(even) { margin-left: auto; }
  .relics { grid-template-columns: 1fr 1fr; }
  .shell { padding-top: 18px; }
}

@media (max-width: 360px) {
  .shell { padding-left: 8px; padding-right: 8px; }
  .rail-clip { margin-left: -8px; margin-right: -8px; padding-left: 8px; padding-right: 8px; }
  .mast h1 { font-size: 1.85rem; }
  .banner img { height: 136px; }
  .controls button { min-height: 56px; }
  .controls button span { letter-spacing: 0.06em; }
  .cartouche { min-width: 84px; min-height: 52px; padding: 7px 10px 8px; }
  .quiet { padding: 8px 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .ray-core { stroke-dasharray: none; }
}
