:root {
  --bg: #07080b;
  --bg-2: #101218;
  --ink: #f6f1e4;
  --muted: #b7ad9a;
  --gold: #e4b34a;
  --gold-2: #f6d78a;
  --line: rgba(228, 179, 74, 0.38);
  --green: #14924c;
  --green-2: #2ee58a;
  --danger: #d45b4c;
  --panel: rgba(16, 18, 24, 0.92);
  --dock: 4.6rem;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--ink);
  font-family: "Avenir Next", "Segoe UI", sans-serif;
  overflow: hidden;
}

button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }

.app {
  height: 100dvh;
  max-height: 100dvh;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(120% 70% at 50% -10%, rgba(228, 179, 74, 0.16), transparent 55%),
    var(--bg);
  overflow: hidden;
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 0.7rem;
  padding: calc(0.55rem + var(--safe-t)) 0.9rem 0.55rem;
  border-bottom: 1px solid var(--line);
  background: rgba(7, 8, 11, 0.88);
}
.crest {
  width: 2.4rem;
  height: 2.4rem;
  border-radius: 50%;
  object-fit: cover;
  border: 1px solid var(--gold);
}
.brand { min-width: 0; flex: 1; }
.eyebrow {
  margin: 0;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  font-size: 0.62rem;
  color: var(--gold-2);
}
.brand h1, .sheet h2, .veilCard h2 {
  margin: 0;
  font-family: Palatino, "Palatino Linotype", "Times New Roman", serif;
  font-weight: 600;
  letter-spacing: 0.02em;
}
.brand h1 { font-size: clamp(1.25rem, 4.5vw, 1.7rem); }
.pulse {
  width: 2rem;
  height: 2rem;
  border-radius: 50%;
  border: 1px solid var(--line);
  display: grid;
  place-items: center;
}
.pulse span {
  width: 0.55rem;
  height: 0.55rem;
  border-radius: 50%;
  background: var(--green-2);
  box-shadow: 0 0 10px var(--green-2);
}

.stage {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
}
.panel { display: none; min-height: 100%; position: relative; }
.panel[data-active="true"] { display: block; }

.play {
  min-height: 100%;
  display: flex;
  flex-direction: column;
  gap: 0.45rem;
  padding: 0.55rem 0.75rem 0.7rem;
}
.meters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 0.35rem;
}
.meter, .trace {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 0.7rem;
  padding: 0.35rem 0.4rem 0.4rem;
  min-width: 0;
}
.meter span, .trace span {
  display: block;
  color: var(--muted);
  font-size: 0.62rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
.meter strong, .trace strong {
  display: block;
  font-size: clamp(0.95rem, 3.4vw, 1.2rem);
  color: var(--gold-2);
  overflow: hidden;
  text-overflow: ellipsis;
}

.board {
  flex: 1 1 auto;
  min-height: 11rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
}
#crownCanvas {
  width: min(100%, 28rem);
  height: auto;
  max-height: 100%;
  touch-action: none;
  border-radius: 1rem;
}
.laneHint {
  margin: 0.15rem 0 0;
  text-align: center;
  font-size: 0.68rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--gold);
}

.controls {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 0.35rem;
}
.ringRow {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.15rem;
  background: #16130e;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 0.15rem;
  min-width: 0;
}
.ringRow span {
  font-size: 0.72rem;
  color: var(--gold-2);
  white-space: nowrap;
}
.ringRow button, .ghost {
  border: 0;
  background: transparent;
  min-width: 2rem;
  min-height: 2.4rem;
  border-radius: 999px;
  color: var(--gold-2);
}
.ringRow button { font-size: 1.35rem; line-height: 1; }
.boom {
  grid-column: 1 / -1;
  border: 0;
  border-radius: 999px;
  min-height: 2.9rem;
  background: linear-gradient(180deg, #2ee58a, #128a48);
  color: #062214;
  font-weight: 700;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  box-shadow: 0 8px 24px rgba(20, 146, 76, 0.35);
}
.boom:active { transform: translateY(1px); }
.statusLine {
  margin: 0;
  text-align: center;
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.35;
  min-height: 2.2em;
}

.veil {
  position: absolute;
  inset: 0;
  background: rgba(5, 6, 8, 0.82);
  display: grid;
  place-items: center;
  padding: 1rem;
  z-index: 5;
}
.veil[data-hidden="true"] { display: none; }
.veilCard {
  width: min(100%, 24rem);
  background: #121016;
  border: 1px solid var(--line);
  border-radius: 1.2rem;
  padding: 1rem;
  text-align: center;
}
.veilCard img {
  width: min(58%, 10rem);
  margin: 0 auto 0.6rem;
  border-radius: 0.8rem;
}
.veilCard h2 { font-size: 1.55rem; }
.veilCard p { color: var(--muted); line-height: 1.45; font-size: 0.92rem; }

.sheet {
  width: min(100%, 40rem);
  margin: 0 auto;
  padding: 1rem 1rem 1.4rem;
}
.sheet h2 { font-size: clamp(1.6rem, 6vw, 2.2rem); margin-bottom: 0.7rem; }
.sheet h3 {
  margin: 1.1rem 0 0.3rem;
  font-size: 1.05rem;
  color: var(--gold-2);
}
.sheet p, .rules { color: #ddd4c4; line-height: 1.55; }
.wide, .relic {
  width: 100%;
  border-radius: 1rem;
  border: 1px solid var(--line);
  margin: 0.4rem 0 0.8rem;
  object-fit: cover;
  max-height: 14rem;
}
.relic { max-height: 16rem; object-fit: contain; background: #050505; }
.rules { padding-left: 1.1rem; }
.rules li { margin: 0.35rem 0; }
.gemKey {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.35rem;
  margin-top: 0.8rem;
}
.gemKey figure { margin: 0; text-align: center; min-width: 0; }
.gemKey img {
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 0.7rem;
  background: #050505;
}
.gemKey figcaption {
  margin-top: 0.25rem;
  font-size: clamp(0.55rem, 2.4vw, 0.72rem);
  color: var(--muted);
  line-height: 1.2;
}

.traceGrid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.45rem;
}
.runs { margin: 0.8rem 0; padding-left: 1.2rem; }
.runs li { margin: 0.35rem 0; color: #ddd4c4; }
.quiet { color: var(--muted); }
.ghost {
  border: 1px solid var(--line);
  padding: 0.55rem 0.9rem;
  color: var(--gold-2);
}
.facts { margin: 0.6rem 0 0; }
.facts div {
  display: grid;
  grid-template-columns: 6.2rem minmax(0, 1fr);
  gap: 0.4rem;
  padding: 0.45rem 0;
  border-top: 1px solid rgba(228, 179, 74, 0.18);
}
.facts dt { color: var(--gold); }
.facts dd { margin: 0; }

.dock {
  flex: 0 0 auto;
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 0.15rem;
  padding: 0.35rem 0.35rem calc(0.35rem + var(--safe-b));
  background:
    linear-gradient(180deg, rgba(228, 179, 74, 0.18), rgba(228, 179, 74, 0.05) 28%, #0c0d11 28%);
  border-top: 1px solid var(--line);
}
.dock button {
  border: 0;
  background: transparent;
  min-width: 0;
  min-height: 3.3rem;
  padding: 0.2rem 0.1rem 0.15rem;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.12rem;
  color: var(--muted);
}
.dock img {
  width: 1.7rem;
  height: 1.7rem;
  border-radius: 50%;
  object-fit: cover;
  background: #050505;
  border: 1px solid transparent;
}
.dock span {
  font-size: clamp(0.58rem, 2.5vw, 0.72rem);
  letter-spacing: 0.04em;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.dock button[aria-current="page"] { color: var(--gold-2); }
.dock button[aria-current="page"] img {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(228, 179, 74, 0.18);
}

@media (max-width: 340px) {
  .gemKey { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .facts div { grid-template-columns: 1fr; gap: 0.1rem; }
  .ringRow span { font-size: 0.64rem; }
}

@media (min-width: 700px) {
  .app { width: min(100%, 520px); margin: 0 auto; border-left: 1px solid var(--line); border-right: 1px solid var(--line); }
  .board { min-height: 18rem; }
}
