:root {
  --bg: #0a0a0a;
  --card: #141414;
  --ink: #f5f5f1;
  --muted: #a3a3a3;
  --red: #e50914;
  --brass: rgba(196, 165, 116, 0.45);
  --display: "Anton", "Arial Narrow", Impact, sans-serif;
  --sans: "Outfit", Roboto, "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  overflow: hidden;
  max-width: 100%;
}

body {
  font-family: var(--sans);
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

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

#app {
  height: 100vh;
  height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(229, 9, 20, 0.2), transparent 52%),
    radial-gradient(70% 40% at 100% 100%, rgba(110, 0, 16, 0.28), transparent 46%),
    var(--bg);
  overflow: hidden;
}

.column {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 14px 8px;
  background: linear-gradient(var(--red), var(--red)) top / 100% 2px no-repeat;
}

.brand { display: flex; align-items: center; gap: 8px; min-width: 0; }

.pip {
  width: 12px;
  height: 12px;
  flex: 0 0 auto;
  border: 2px solid var(--red);
  box-shadow: 0 0 8px rgba(229, 9, 20, 0.85);
}

.word {
  font-family: var(--display);
  font-size: 22px;
  letter-spacing: 0.08em;
  line-height: 1;
  text-transform: uppercase;
}

.kicker {
  margin: 0;
  max-width: 48%;
  text-align: right;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  line-height: 1.3;
}

#stage {
  flex: 1;
  min-width: 0;
  min-height: 0;
  display: flex;
  flex-direction: column;
  position: relative;
}

.view { flex: 1; min-width: 0; min-height: 0; }

.view.scroll {
  overflow-x: hidden;
  overflow-y: auto;
  overscroll-behavior: contain;
}

.wrap {
  width: min(640px, 100%);
  margin: 0 auto;
  padding-bottom: 18px;
}

.rail {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 2px;
  padding: 12px 6px calc(10px + env(safe-area-inset-bottom));
  background:
    radial-gradient(circle at 8px 5px, #0a0a0a 2.4px, transparent 2.7px) 0 0 / 16px 12px repeat-x,
    radial-gradient(circle at 8px calc(100% - 5px), #0a0a0a 2.4px, transparent 2.7px) 0 100% / 16px 12px repeat-x,
    linear-gradient(#161616, #0c0c0c);
  border-top: 1px solid rgba(229, 9, 20, 0.75);
  box-shadow: inset 0 1px 0 var(--brass);
}

.rail button {
  min-width: 0;
  min-height: 48px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  color: #8d8d8d;
  font-size: 10px;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.frame-mark {
  width: 22px;
  height: 14px;
  border: 1px solid currentColor;
  background:
    radial-gradient(circle at 3px 50%, #0a0a0a 1.3px, transparent 1.5px),
    radial-gradient(circle at calc(100% - 3px) 50%, #0a0a0a 1.3px, transparent 1.5px),
    #141414;
}

.rail button[aria-current="page"] { color: #fff; }

.rail button[aria-current="page"] .frame-mark {
  border-color: var(--red);
  box-shadow: 0 0 10px rgba(229, 9, 20, 0.85);
  background-color: #3a0a0e;
}

.hero {
  position: relative;
  height: clamp(168px, 36dvh, 390px);
  margin: 12px 12px 0;
  overflow: hidden;
  background: #12080a url("hero-gate.png") center / cover no-repeat;
  border: 1px solid rgba(229, 9, 20, 0.7);
  box-shadow: inset 0 0 0 1px var(--brass);
}

.hero .veil {
  position: absolute;
  inset: 0;
  background: linear-gradient(to top, rgba(10, 10, 10, 0.94) 0%, rgba(10, 10, 10, 0.15) 52%, rgba(10, 10, 10, 0.4) 100%);
}

.hero .sweep {
  position: absolute;
  inset: 0;
  background: linear-gradient(110deg, transparent 36%, rgba(229, 9, 20, 0.16) 50%, transparent 64%);
  transform: translateX(-70%);
  animation: sweep 8s ease-in-out infinite;
  pointer-events: none;
}

.corner {
  position: absolute;
  width: 16px;
  height: 16px;
  border: 2px solid var(--red);
  z-index: 2;
}

.corner.tl { top: 8px; left: 8px; border-right: 0; border-bottom: 0; }
.corner.tr { top: 8px; right: 8px; border-left: 0; border-bottom: 0; }
.corner.bl { bottom: 8px; left: 8px; border-right: 0; border-top: 0; }
.corner.br { bottom: 8px; right: 8px; border-left: 0; border-top: 0; }

.hero .copy {
  position: absolute;
  left: 14px;
  right: 14px;
  bottom: 12px;
  z-index: 2;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--red);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.18em;
  text-transform: uppercase;
}

.hero h1 {
  margin: 0;
  font-family: var(--display);
  font-size: clamp(40px, 12vw, 68px);
  font-weight: 400;
  letter-spacing: 0.04em;
  line-height: 0.9;
  text-transform: uppercase;
}

.deck {
  margin: 8px 0 0;
  max-width: 36em;
  color: #ececec;
  font-size: 14.5px;
  line-height: 1.45;
}

.h {
  margin: 18px 14px 8px;
  color: var(--red);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

.btn {
  display: block;
  width: calc(100% - 24px);
  margin: 10px 12px 0;
  min-height: 48px;
  padding: 11px 14px;
  background: var(--red);
  color: #fff;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 2px;
}

.btn small {
  display: block;
  margin-top: 2px;
  font-size: 12px;
  font-weight: 500;
  letter-spacing: 0;
  color: #ffe4e6;
}

.btn.ghost {
  background: transparent;
  color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(229, 9, 20, 0.85);
}

.btn.ghost small { color: var(--muted); }

.btn:active { transform: translateY(1px); }

.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; }

.steps {
  list-style: none;
  display: grid;
  gap: 8px;
  margin: 0 12px;
  padding: 0;
}

.steps li {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  padding: 8px;
  background: var(--card);
  border: 1px solid rgba(229, 9, 20, 0.45);
  box-shadow: inset 0 0 0 1px var(--brass);
}

.steps b {
  font-family: var(--display);
  color: var(--red);
  font-size: 22px;
  font-weight: 400;
  letter-spacing: 0.04em;
}

.steps p { margin: 0; font-size: 13.5px; line-height: 1.4; color: #e7e7e7; }

.row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  max-width: 100%;
  padding: 0 12px 8px;
}

.row::-webkit-scrollbar { display: none; }

.tile {
  position: relative;
  flex: 0 0 142px;
  width: 142px;
  aspect-ratio: 2 / 3;
  scroll-snap-align: start;
  overflow: hidden;
  border: 1px solid rgba(229, 9, 20, 0.5);
  background: #12080a;
  text-align: left;
}

.tile img { width: 100%; height: 100%; object-fit: cover; }

.tile span {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 22px 8px 8px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.9));
  font-size: 12px;
  font-weight: 700;
}

.tile.locked img { filter: grayscale(1) brightness(0.45); }

.tile.locked span { color: #c8c8c8; }

.panel {
  margin: 0 12px 10px;
  padding: 10px;
  background: var(--card);
  border: 1px solid rgba(229, 9, 20, 0.5);
  box-shadow: inset 0 0 0 1px var(--brass);
}

.card {
  width: calc(100% - 24px);
  margin: 0 12px 10px;
  display: grid;
  grid-template-columns: 86px minmax(0, 1fr);
  gap: 10px;
  padding: 8px;
  text-align: left;
  background: var(--card);
  border: 1px solid rgba(229, 9, 20, 0.45);
  box-shadow: inset 0 0 0 1px var(--brass);
}

.card img {
  width: 86px;
  height: 120px;
  object-fit: cover;
  background: #12080a;
}

.card.open { border-color: var(--red); }

.card h2, .sheet h2, .essay h2, .head h1 {
  margin: 0;
  font-size: 18px;
  line-height: 1.15;
  letter-spacing: 0.01em;
}

.act {
  margin: 3px 0 0;
  color: var(--red);
  font-size: 11px;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.about, .essay p, .sheet p, .note {
  margin: 6px 0 0;
  color: #dedede;
  font-size: 14px;
  line-height: 1.5;
}

.modes { display: grid; gap: 8px; margin-top: 10px; }

.mode {
  width: 100%;
  min-height: 48px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 8px 10px;
  text-align: left;
  background: #0e0e0e;
  box-shadow: inset 0 0 0 1px rgba(229, 9, 20, 0.4);
}

.mode b { display: block; font-size: 14px; }
.mode small { color: var(--muted); font-size: 12px; }
.mode:disabled { opacity: 0.5; }

.marks { display: inline-flex; gap: 4px; flex: 0 0 auto; }

.marks i {
  width: 14px;
  height: 8px;
  background: #2a2a2a;
  box-shadow: inset 0 0 0 1px rgba(229, 9, 20, 0.5);
}

.marks i.on { background: var(--red); box-shadow: none; }

.essay { margin: 0 12px 12px; padding: 12px; background: var(--card); border-top: 2px solid var(--red); }

.demo {
  display: flex;
  gap: 6px;
  margin-top: 10px;
}

.demo-cell {
  position: relative;
  width: 64px;
  height: 84px;
  background: #1a090c;
  box-shadow: inset 0 0 0 1px rgba(229, 9, 20, 0.6);
}

.switch {
  width: calc(100% - 24px);
  margin: 0 12px 8px;
  min-height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 12px;
  text-align: left;
  background: var(--card);
  border: 1px solid rgba(229, 9, 20, 0.4);
}

.switch b { display: block; font-size: 15px; }
.switch small { display: block; margin-top: 2px; color: var(--muted); font-size: 12px; line-height: 1.35; }

.knob {
  width: 42px;
  height: 24px;
  flex: 0 0 auto;
  border-radius: 99px;
  background: #2a2a2a;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(229, 9, 20, 0.45);
}

.knob::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #8d8d8d;
}

.switch[aria-pressed="true"] .knob { background: #5a0c12; }
.switch[aria-pressed="true"] .knob::after { left: 21px; background: var(--red); }

.bench {
  height: 100%;
  min-width: 0;
  max-width: 100%;
  min-height: 0;
  display: grid;
  grid-template-rows: auto auto auto minmax(0, 1fr) auto auto;
  gap: 8px;
  padding: 10px 12px 12px;
}

.head { min-width: 0; }
.head h1 { font-size: clamp(20px, 5vw, 28px); }
.head p { margin: 2px 0 0; color: var(--red); font-size: 12px; letter-spacing: 0.14em; text-transform: uppercase; font-weight: 700; }

.hint, .hold {
  margin: 0;
  color: #d8d8d8;
  font-size: 13px;
  line-height: 1.35;
}

.stats {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.04em;
  font-variant-numeric: tabular-nums;
}

.stats span { min-width: 0; }

.board-well {
  min-width: 0;
  min-height: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

#board {
  position: relative;
  display: grid;
  gap: 2px;
  background: #050505;
  box-shadow:
    0 0 0 1px var(--brass),
    0 0 0 4px #0a0a0a,
    0 0 0 5px rgba(229, 9, 20, 0.9);
}

#flash {
  position: absolute;
  inset: 0;
  z-index: 4;
  background-repeat: no-repeat;
  background-size: 100% 100%;
  background-position: center;
}

.slot, .piece { position: relative; overflow: hidden; min-width: 0; min-height: 0; }

.slot { background: #101010; }

.face {
  position: absolute;
  inset: 0;
  background-image: var(--art);
  background-repeat: no-repeat;
  background-size: calc(var(--cols) * 100%) calc(var(--rows) * 100%);
  background-position:
    calc(var(--c) / (var(--cols) - 1) * 100%)
    calc(var(--r) / (var(--rows) - 1) * 100%);
}

.slot .face { opacity: 0; }
.slot.filled .face { opacity: 1; }

.brackets {
  position: absolute;
  inset: 3px;
  border: 1px solid rgba(229, 9, 20, 0.28);
  pointer-events: none;
}

.slot.filled .brackets { display: none; }

.tick {
  position: absolute;
  z-index: 2;
  display: none;
  background: var(--tick);
  pointer-events: none;
}

.tick.live { display: block; }
.tick.n { top: 0; left: 14%; right: 14%; height: 3px; }
.tick.s { bottom: 0; left: 14%; right: 14%; height: 3px; }
.tick.w { left: 0; top: 14%; bottom: 14%; width: 3px; }
.tick.e { right: 0; top: 14%; bottom: 14%; width: 3px; }

.mode-open .tick, .mode-grow .piece .tick, .mode-grow .slot .tick { display: none; }
.mode-fog .tick.live { display: block; }

.back {
  position: absolute;
  inset: 0;
  background:
    repeating-linear-gradient(90deg, transparent 0 8px, rgba(229, 9, 20, 0.28) 8px 9px),
    #14080a;
}

.mode-open .back, .mode-fog .back, .mode-grow .back { display: none; }

.mode-fog .piece .face { opacity: 0.28; }
.mode-fog .piece.on .face { opacity: 0.82; }

.tray {
  min-width: 0;
  height: 84px;
  display: flex;
  gap: 8px;
  align-items: center;
  overflow-x: auto;
  overflow-y: hidden;
  overscroll-behavior-x: contain;
  scroll-snap-type: x mandatory;
  padding: 4px 2px;
}

.tray.held { visibility: hidden; }

.piece {
  flex: 0 0 auto;
  height: 68px;
  width: calc(68px * var(--cell-aspect, 0.67));
  scroll-snap-align: start;
  background: #14080a;
  box-shadow: inset 0 0 0 1px rgba(229, 9, 20, 0.35);
}

.piece.on { box-shadow: inset 0 0 0 2px var(--red), 0 0 10px rgba(229, 9, 20, 0.45); }

.mode-grow .slot.cold { opacity: 0.38; }
.mode-grow .slot.warm:not(.filled) { box-shadow: inset 0 0 0 1px rgba(229, 9, 20, 0.7); }
.mode-fog .slot.clash:not(.filled) { opacity: 0.35; }
.mode-fog .slot.agree:not(.filled) { box-shadow: inset 0 0 0 1px #f4f0e6; }

.slot.shake { animation: shake 0.28s linear; }
.slot.just { box-shadow: inset 0 0 0 2px var(--red); }

.actions {
  display: flex;
  gap: 8px;
}

.actions .btn { flex: 1; width: auto; margin: 0; min-height: 46px; font-size: 14px; }

.card .btn { width: 100%; margin: 10px 0 0; }

#overlay {
  position: fixed;
  inset: 0;
  z-index: 40;
  display: grid;
  place-items: center;
  padding: 16px;
  background: rgba(0, 0, 0, 0.78);
}

#overlay[hidden] { display: none; }

#overlay article {
  width: min(100%, 440px);
  max-height: calc(100dvh - 28px);
  overflow: auto;
  padding: 18px 16px;
  background: #141414;
  border: 1px solid var(--red);
  box-shadow: inset 0 0 0 1px var(--brass), 0 16px 50px rgba(0, 0, 0, 0.45);
}

#overlay h2 {
  font-family: var(--display);
  font-size: 32px;
  font-weight: 400;
  letter-spacing: 0.03em;
  text-transform: uppercase;
  line-height: 0.95;
}

#overlay .btn { width: 100%; margin: 10px 0 0; }

.toast {
  position: fixed;
  left: 12px;
  right: 12px;
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 30;
  padding: 10px 12px;
  text-align: center;
  font-size: 13px;
  line-height: 1.35;
  background: #141414;
  border: 1px solid var(--red);
}

.toast[hidden] { display: none; }

.sr {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
}

:focus-visible { outline: 2px solid #fff; outline-offset: 2px; }

::selection { background: var(--red); color: #fff; }

@keyframes sweep {
  0%, 58% { transform: translateX(-70%); }
  82%, 100% { transform: translateX(70%); }
}

@keyframes shake {
  0%, 100% { transform: translateX(0); }
  30% { transform: translateX(-4px); }
  70% { transform: translateX(4px); }
}

@media (max-width: 340px) {
  .rail button { letter-spacing: 0.06em; font-size: 9px; }
  .tile { flex-basis: 124px; width: 124px; }
  .card { grid-template-columns: 72px minmax(0, 1fr); }
  .card img { width: 72px; height: 104px; }
}

@media (min-width: 640px) {
  .steps { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .steps li { grid-template-columns: 1fr; align-items: start; }
}

@media (min-width: 720px), ((orientation: landscape) and (max-height: 540px)) {
  #app { flex-direction: row; }
  .rail {
    order: -1;
    width: 92px;
    grid-template-columns: 1fr;
    grid-template-rows: repeat(4, minmax(0, 1fr));
    border-top: 0;
    border-right: 1px solid rgba(229, 9, 20, 0.75);
    padding: 12px 6px 12px calc(6px + env(safe-area-inset-left));
    background:
      radial-gradient(circle at 5px 8px, #0a0a0a 2.4px, transparent 2.7px) 0 0 / 12px 16px repeat-y,
      radial-gradient(circle at calc(100% - 5px) 8px, #0a0a0a 2.4px, transparent 2.7px) 100% 0 / 12px 16px repeat-y,
      linear-gradient(#161616, #0c0c0c);
  }
  #app.side-rail .toast, .toast { left: 104px; right: 12px; bottom: 16px; }
}

@media (max-height: 540px) {
  .topbar { padding-top: calc(6px + env(safe-area-inset-top)); padding-bottom: 4px; }
  .word { font-size: 18px; }
  .hero { height: 150px; }
  .view.bench { overflow-x: hidden; overflow-y: auto; }
  .bench {
    height: auto;
    min-height: 100%;
    display: flex;
    flex-direction: column;
  }
  .board-well { height: 220px; flex: none; }
  .hint { display: none; }
  .tray { height: 72px; }
  .piece { height: 60px; width: calc(60px * var(--cell-aspect, 0.67)); }
}

@media (prefers-reduced-motion: reduce) {
  .hero .sweep, .slot.shake { animation: none; }
}
