:root {
  --ink: #faedb5;
  --muted: rgba(250, 237, 181, 0.74);
  --bronze: #2b2111;
  --bronze-2: #3d2e18;
  --bronze-3: #1a140a;
  --gold: #e8d48a;
  --line: rgba(250, 237, 181, 0.32);
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bronze-3);
  color: var(--ink);
}

body {
  font-family: Manrope, "Segoe UI", Roboto, "Helvetica Neue", sans-serif;
  -webkit-tap-highlight-color: transparent;
}

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

.shell {
  height: 100dvh;
  width: 100%;
  max-width: 560px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  background:
    radial-gradient(880px 420px at 8% -12%, rgba(250, 237, 181, 0.28), transparent 58%),
    radial-gradient(640px 360px at 100% 0%, rgba(232, 212, 138, 0.16), transparent 52%),
    linear-gradient(180deg, #2b2111 0%, #1a140a 100%);
}

.mast {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: calc(8px + var(--safe-t)) 12px 8px;
  border-bottom: 1px solid var(--line);
  min-width: 0;
}

.brand { min-width: 0; }

.eyebrow, .kicker {
  margin: 0;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--gold);
}

.mast h1 {
  margin: 1px 0 0;
  font-size: clamp(16px, 4.8vw, 22px);
  line-height: 1.1;
  letter-spacing: -0.03em;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.sound {
  margin-left: auto;
  flex: 0 0 auto;
  border: 1px solid var(--ink);
  background: transparent;
  border-radius: 999px;
  min-height: 36px;
  padding: 0 12px;
  font-size: 12px;
  font-weight: 800;
}

.sound[aria-pressed="false"] { opacity: 0.5; }

.sigil {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 4px;
  padding: 8px 8px 9px;
  border-bottom: 1px solid var(--line);
}

.sigil button {
  appearance: none;
  border: 1px solid transparent;
  background: rgba(26, 20, 10, 0.35);
  border-radius: 14px;
  min-height: 48px;
  padding: 5px 2px 6px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  min-width: 0;
}

.sigil button i {
  width: 7px;
  height: 7px;
  display: block;
  transform: rotate(45deg);
  border: 1.5px solid var(--gold);
}

.sigil button span {
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: clamp(9px, 2.55vw, 12px);
  font-weight: 800;
  letter-spacing: 0.01em;
}

.sigil button.core {
  border-color: rgba(250, 237, 181, 0.7);
  background:
    radial-gradient(circle at 50% 0%, rgba(250, 237, 181, 0.2), transparent 70%),
    rgba(43, 33, 17, 0.8);
  box-shadow: inset 0 0 0 1px rgba(255, 245, 210, 0.12);
}

.sigil button.is-on {
  background: linear-gradient(#fff 0%, #faedb5 42%, #e8d48a 100%);
  color: #2b2111;
  border-color: #faedb5;
  box-shadow: 0 0 16px rgba(250, 237, 181, 0.45);
}

.sigil button.is-on i {
  background: #2b2111;
  border-color: #2b2111;
}

main {
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
}

.view { display: none; min-height: 0; }
.view.is-on {
  display: flex;
  flex-direction: column;
  height: 100%;
  min-height: 0;
}

.play {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 8px 10px calc(8px + var(--safe-b));
  user-select: none;
}

.hud {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.hud div, .end-stats div {
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 6px 8px;
  background: rgba(26, 20, 10, 0.45);
}

.hud span, .place-line span, .end-stats dt {
  display: block;
  font-size: 10px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--muted);
}

.hud strong, .place-line strong {
  display: block;
  margin-top: 2px;
  font-size: clamp(14px, 4vw, 18px);
  line-height: 1.1;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.lamps { display: flex; gap: 5px; margin-top: 4px; height: 16px; align-items: center; }

.lamps i {
  width: 9px;
  height: 9px;
  border-radius: 50%;
  background: var(--ink);
  box-shadow: 0 0 8px rgba(250, 237, 181, 0.8);
  display: block;
}

.lamps i.off {
  background: transparent;
  box-shadow: none;
  border: 1px solid rgba(250, 237, 181, 0.4);
}

.place-line, .best-line {
  margin: 0;
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
  min-width: 0;
}

.place-line strong { margin-top: 0; }

.best-line {
  font-size: 12px;
  color: var(--muted);
}

.order {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.order b {
  min-width: 0;
  text-align: center;
  border-radius: 999px;
  border: 1px solid var(--line);
  padding: 5px 4px;
  font-size: clamp(10px, 2.8vw, 12px);
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.order b.is-next {
  color: #2b2111;
  border-color: #faedb5;
  background: linear-gradient(#fff, #faedb5 45%, #e8d48a);
}

.order b.is-done {
  color: var(--ink);
  border-color: rgba(250, 237, 181, 0.7);
  background: rgba(250, 237, 181, 0.12);
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  border-radius: 22px;
  overflow: hidden;
  border: 1px solid rgba(250, 237, 181, 0.5);
  box-shadow: inset 0 0 0 1px rgba(255, 245, 210, 0.14), 0 12px 28px rgba(0, 0, 0, 0.35);
  background: #120e08;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.flash {
  position: absolute;
  left: 10px;
  right: 10px;
  top: 12px;
  margin: 0;
  text-align: center;
  font-weight: 800;
  letter-spacing: 0.04em;
  color: var(--ink);
  text-shadow: 0 2px 10px #000;
  pointer-events: none;
  opacity: 0;
}

.flash.show { animation: pop 0.75s ease; }

@keyframes pop {
  0% { opacity: 0; transform: translateY(6px); }
  18% { opacity: 1; transform: none; }
  100% { opacity: 0; }
}

.veil {
  position: absolute;
  inset: 0;
  overflow: hidden;
  padding: 10px 12px 12px;
  background: rgba(18, 14, 8, 0.84);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.veil-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}

.veil[hidden] { display: none !important; }

.veil h2 {
  margin: 0;
  font-size: clamp(20px, 6vw, 30px);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.sheet h2 {
  margin: 0 0 8px;
  font-size: clamp(24px, 7vw, 34px);
  line-height: 1.05;
  letter-spacing: -0.03em;
}

.veil p, .sheet p { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.45; }

.veil ul {
  margin: 0;
  padding-left: 18px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.4;
}

.veil li + li { margin-top: 4px; }

.gold-action, .ghost {
  border-radius: 999px;
  min-height: 44px;
  padding: 0 14px;
  font-weight: 800;
  cursor: pointer;
}

.gold-action {
  flex: 0 0 auto;
  width: 100%;
  border: 2px solid #faedb5;
  background: linear-gradient(#fff 0%, #faedb5 42%, #e8d48a 100%);
  color: #2b2111;
  box-shadow: 0 0 18px rgba(250, 237, 181, 0.4);
}

.play-foot {
  display: flex;
  gap: 8px;
}

.ghost {
  flex: 1 1 0;
  min-width: 0;
  border: 1px solid rgba(250, 237, 181, 0.55);
  background: transparent;
  color: var(--ink);
}

.ghost:disabled { opacity: 0.4; }

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

.end-stats dd {
  margin: 2px 0 0;
  font-size: clamp(16px, 5vw, 22px);
  font-weight: 800;
  color: var(--ink);
}

.sheet {
  flex: 1 1 auto;
  min-height: 0;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 14px 14px calc(20px + var(--safe-b));
  -webkit-overflow-scrolling: touch;
}

.sheet h2 { margin-bottom: 8px; }

.lead { margin-bottom: 12px !important; }

.sheet h3 {
  margin: 14px 0 6px;
  font-size: 16px;
}

.hero-still, .land img {
  width: 100%;
  aspect-ratio: 16 / 10;
  object-fit: cover;
  border-radius: 16px;
  border: 1px solid rgba(250, 237, 181, 0.35);
  display: block;
  margin: 10px 0;
}

.land {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 10px;
  margin: 0 0 12px;
  background: linear-gradient(180deg, rgba(61, 46, 24, 0.72), rgba(26, 20, 10, 0.88));
}

.land img { margin-top: 0; }

.land-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  min-width: 0;
}

.land h3 {
  margin: 0;
  min-width: 0;
  font-size: clamp(16px, 4.5vw, 18px);
}

.seal {
  flex: 0 0 auto;
  border: 1px solid var(--ink);
  border-radius: 999px;
  padding: 3px 8px;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.land.is-open .seal {
  background: linear-gradient(#fff, #faedb5 42%, #e8d48a);
  color: #2b2111;
  border-color: #faedb5;
}

.cuts {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.cuts article, .steps li, #journal article {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 10px 12px;
  background: rgba(26, 20, 10, 0.4);
}

.cuts b {
  display: inline-block;
  margin-bottom: 4px;
  color: var(--gold);
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.cuts h3 { margin: 0 0 4px; }

.cuts p { margin: 0; }

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

.steps b { display: block; margin-bottom: 3px; }

.steps span, #journal span, #journal small {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

#journal {
  display: grid;
  gap: 8px;
  margin: 10px 0 6px;
}

#journal article b { font-size: 16px; }

.empty { margin: 0; }

.colophon {
  margin-top: 16px !important;
  font-size: 12px !important;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

@media (max-width: 340px) {
  .sigil { gap: 3px; padding-left: 6px; padding-right: 6px; }
  .play { padding-left: 8px; padding-right: 8px; }
  .sheet { padding-left: 10px; padding-right: 10px; }
}

@media (min-width: 420px) {
  .cuts { grid-template-columns: 1fr; }
  .hero-still, .land img { max-height: 240px; }
}
