:root {
  --night: #14061f;
  --plum: #2a1044;
  --panel: #1b0a2e;
  --gold: #f3c15b;
  --gold-deep: #a8741a;
  --cream: #fff6df;
  --muted: #d9c7a2;
  --line: rgba(243, 193, 91, 0.38);
  --ruby: #e23d4a;
  --sapphire: #3c7dff;
  --emerald: #1fbf6a;
  --amethyst: #c06bff;
  --amber: #ffb020;
  --ink: #2a1604;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; }
body {
  font-family: Outfit, "Avenir Next", "Segoe UI", sans-serif;
  color: var(--cream);
  background: #100418 url("shrine.png") center/cover no-repeat;
}
button, input { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; display: block; }
h1, h2, h3, p { overflow-wrap: break-word; }
h1, h2, h3 { font-family: Cinzel, Palatino, "Times New Roman", serif; font-weight: 700; }
p { margin: 0; }

.hall {
  width: min(480px, 100%);
  height: 100%;
  height: 100dvh;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: rgba(16, 4, 24, 0.94);
  box-shadow: 0 0 0 1px var(--line);
  position: relative;
}

.mast {
  display: flex;
  align-items: center;
  gap: 12px;
  min-height: 64px;
  padding: 10px 14px;
  background:
    linear-gradient(100deg, rgba(16, 4, 24, 0.94), rgba(42, 16, 68, 0.72)),
    url("shrine.png") center 30%/cover no-repeat;
  border-bottom: 1px solid var(--line);
}
.mast-copy { min-width: 0; flex: 1; }
.eyebrow {
  margin: 0 0 2px;
  color: var(--gold);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
.mast h1 {
  margin: 0;
  font-size: clamp(18px, 5vw, 24px);
  line-height: 1.05;
  color: var(--cream);
}
.sound {
  width: 44px;
  height: 44px;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(20, 6, 31, 0.7);
  display: grid;
  grid-auto-flow: column;
  align-items: end;
  justify-content: center;
  gap: 3px;
  padding: 12px 10px;
  flex: 0 0 auto;
}
.sound i {
  width: 3px;
  height: 8px;
  border-radius: 2px;
  background: var(--muted);
  display: block;
}
.sound i:nth-child(2) { height: 14px; }
.sound i:nth-child(3) { height: 10px; }
.sound.is-on { border-color: var(--gold); }
.sound.is-on i { background: var(--gold); }

.stage { flex: 1; min-height: 0; position: relative; }
.screen { display: none; height: 100%; min-height: 0; }
.screen.is-open { display: flex; flex-direction: column; position: relative; }

.vein, .play { display: none; min-height: 0; }
.vein.is-on, .play.is-on { display: flex; flex-direction: column; flex: 1; }
.vein { overflow: auto; padding: 14px 14px 18px; }
.play { overflow: hidden; padding: 8px 10px 14px; gap: 8px; }

.vein-head, .play-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}
.vein-head h2, .play-head h2, .sheet h2 {
  margin: 0;
  font-size: clamp(20px, 5.4vw, 28px);
  line-height: 1.1;
}
.vein-stats { text-align: right; flex: 0 0 auto; }
.vein-stats strong, .vein-stats span { display: block; }
.vein-stats span, .quiet, .lead { color: var(--muted); }
.lead { margin: 10px 0 12px; line-height: 1.45; }
.vein-list { display: flex; flex-direction: column; gap: 8px; position: relative; }
.vein-list::before {
  content: "";
  position: absolute;
  left: 27px;
  top: 18px;
  bottom: 18px;
  width: 2px;
  background: linear-gradient(var(--gold), #6a3a12);
}
.node {
  position: relative;
  display: grid;
  grid-template-columns: 28px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  text-align: left;
  min-height: 64px;
  padding: 8px 10px;
  border-radius: 16px;
  border: 1px solid var(--line);
  background: rgba(32, 12, 52, 0.9);
}
.node:disabled { opacity: 0.48; }
.node.is-done { border-color: var(--gold); }
.node strong { display: block; font-size: 15px; }
.node em {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-style: normal;
  font-size: 12px;
  line-height: 1.3;
}
.node b { color: var(--gold); font-size: 12px; font-weight: 650; white-space: nowrap; }
.dot {
  width: 16px;
  height: 16px;
  margin-left: 5px;
  border-radius: 4px;
  transform: rotate(45deg);
  background: #5c4a32;
  box-shadow: 0 0 0 4px #1b0a2e;
}
.node.is-done .dot { background: var(--gold); }
.node:not(:disabled) .dot { background: #f0d48a; }

.play-head h2 {
  flex: 1;
  min-width: 0;
  text-align: center;
  font-size: clamp(16px, 4.4vw, 22px);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.text-btn, .ghost, .solid, .cut-actions button {
  border-radius: 14px;
  min-height: 44px;
}
.text-btn {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--gold);
  padding: 0 12px;
}
.cuts-left {
  min-width: 52px;
  text-align: center;
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 4px 8px 5px;
  background: rgba(243, 193, 91, 0.08);
}
.cuts-left b { display: block; font-size: 16px; line-height: 1; color: var(--gold); }
.cuts-left small { color: var(--muted); font-size: 9px; letter-spacing: 0.12em; text-transform: uppercase; }

.goals { display: flex; flex-wrap: wrap; gap: 6px; }
.goal {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  max-width: 100%;
  padding: 4px 8px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px;
  line-height: 1.2;
}
.goal.is-done { background: var(--gold); color: var(--ink); border-color: var(--gold); }
.pip { width: 8px; height: 8px; border-radius: 2px; transform: rotate(45deg); flex: 0 0 auto; }
.pip.ruby { background: var(--ruby); }
.pip.sapphire { background: var(--sapphire); }
.pip.emerald { background: var(--emerald); }
.pip.amethyst { background: var(--amethyst); }
.pip.amber { background: var(--amber); }
.pip.clasp { background: var(--gold); border-radius: 50%; transform: none; }

.board-wrap {
  flex: 1;
  min-height: 0;
  container-type: size;
  display: grid;
  place-items: center;
}
.sizer {
  width: min(100cqi, 100cqh, 440px);
  height: min(100cqi, 100cqh, 440px);
  position: relative;
}
.board {
  width: 100%;
  height: 100%;
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  grid-template-rows: repeat(6, 1fr);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.05), transparent 28%),
    #1a0830;
  border: 0;
  border-radius: 18px;
  box-shadow: inset 0 0 0 2px #e3b34a, 0 10px 24px rgba(0, 0, 0, 0.28);
  touch-action: none;
  user-select: none;
  overflow: hidden;
}
.frame {
  position: absolute;
  left: calc(var(--fx, 2) * 100% / 6);
  top: calc(var(--fy, 2) * 100% / 6);
  width: calc(100% / 3);
  height: calc(100% / 3);
  border: 2px solid var(--gold);
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgba(90, 48, 8, 0.8), 0 0 16px rgba(243, 193, 91, 0.28);
  pointer-events: none;
  z-index: 3;
  transition: left 0.12s ease, top 0.12s ease;
}
.cell {
  border: 0;
  padding: 0;
  background: transparent;
  display: grid;
  place-items: center;
  position: relative;
  box-shadow: inset 0 0 0 1px rgba(243, 193, 91, 0.08);
}
.cell.is-locked::after {
  content: "";
  position: absolute;
  width: 22%;
  height: 22%;
  top: 7%;
  right: 7%;
  border: 2px solid var(--gold);
  border-radius: 50%;
  box-shadow: inset 0 0 0 2px rgba(20, 6, 31, 0.65);
  z-index: 2;
}
.gem {
  width: 72%;
  height: 72%;
  display: block;
  clip-path: polygon(50% 0%, 96% 30%, 78% 100%, 22% 100%, 4% 30%);
  filter: drop-shadow(0 3px 2px rgba(0, 0, 0, 0.35));
  position: relative;
}
.gem::after {
  content: "";
  position: absolute;
  left: 24%;
  right: 24%;
  top: 16%;
  height: 24%;
  background: rgba(255, 255, 255, 0.62);
  clip-path: polygon(50% 0, 100% 100%, 0 100%);
}
.gem.ruby { background: linear-gradient(160deg, #ffd5d8, #e23d4a 42%, #7a1020); }
.gem.sapphire { background: linear-gradient(160deg, #d7e6ff, #3c7dff 42%, #16368f); }
.gem.emerald { background: linear-gradient(160deg, #d8ffe9, #1fbf6a 42%, #0c6a38); }
.gem.amethyst { background: linear-gradient(160deg, #f3defe, #c06bff 42%, #5b188f); }
.gem.amber { background: linear-gradient(160deg, #fff0c8, #ffb020 42%, #a15d08); }
.gem.garuda {
  background: linear-gradient(160deg, #fff6d2, #e3b34a 40%, #8a5a10);
  clip-path: polygon(50% 0, 82% 16%, 100% 48%, 72% 100%, 28% 100%, 0 48%, 18% 16%);
}
.board.is-burst { animation: burst 0.17s ease; }
.board.is-dull { animation: dull 0.17s ease; }
@keyframes burst { 50% { filter: brightness(1.25); } }
@keyframes dull { 40% { transform: translateX(-2px); } 70% { transform: translateX(2px); } }

.note {
  margin: 0;
  min-height: 1.2em;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.score-line { font-size: 13px; color: var(--muted); }
.score-line strong { color: var(--cream); font-variant-numeric: tabular-nums; }
.cut-actions { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.cut-actions button, .solid, .ghost {
  border: 1px solid var(--gold);
  background: transparent;
  color: var(--gold);
  font-weight: 700;
  padding: 0 12px;
}
.solid, .cut-actions .solid {
  background: linear-gradient(180deg, #ffe7a4, var(--gold) 45%, #c48a22);
  color: var(--ink);
  border-color: #ffe7a4;
}
button:active { transform: translateY(1px); }
button:focus-visible { outline: 2px solid var(--cream); outline-offset: 2px; }

.veil {
  display: none;
  position: absolute;
  inset: 0;
  z-index: 5;
  place-items: center;
  padding: 18px;
  background: rgba(10, 3, 18, 0.72);
}
.veil.is-on { display: grid; }
.veil-card {
  width: min(100%, 360px);
  padding: 16px;
  border-radius: 22px;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #341456, #160820);
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 10px;
  align-items: center;
}
.veil-card img { width: 96px; height: 96px; object-fit: cover; border-radius: 18px; }
.veil-card h2 { margin: 0; font-size: 24px; }
.veil-card p { color: var(--muted); line-height: 1.4; }
.veil-card button { width: 100%; }

.sheet {
  height: 100%;
  overflow: auto;
  padding: 16px 16px 22px;
}
.sheet h3 { margin: 18px 0 6px; font-size: 18px; }
.sheet p { line-height: 1.5; margin-bottom: 10px; }
.plate {
  width: 100%;
  max-height: 210px;
  object-fit: cover;
  border-radius: 18px;
  margin: 12px 0;
  border: 1px solid var(--line);
}
.portrait {
  width: min(220px, 70%);
  margin: 8px auto 12px;
  border-radius: 20px;
  border: 1px solid var(--line);
}
.rules { margin: 8px 0 14px; padding-left: 18px; }
.rules li { margin: 0 0 8px; line-height: 1.4; }
.swatches, .vault-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}
.vault-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.swatches figure, .stone {
  margin: 0;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: #1a0830;
  overflow: hidden;
}
.swatches img, .stone img { width: 100%; aspect-ratio: 1; object-fit: cover; }
.swatches figcaption, .stone h3, .stone p { padding: 0 8px; }
.swatches figcaption { padding-bottom: 8px; font-size: 11px; color: var(--gold); }
.stone { padding-bottom: 10px; }
.stone h3 { margin: 8px 0 4px; font-size: 15px; }
.stone p { margin: 0; padding: 0 8px; color: var(--muted); font-size: 12px; line-height: 1.35; }
.stone.is-sealed img, .stone.is-sealed .cluster { filter: grayscale(1) brightness(0.45); }
.cluster {
  height: 120px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 4px;
  background: #12061d;
}
.cluster .gem { width: 36px; height: 48px; }

.trace-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
  margin: 12px 0;
}
.trace-grid div {
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: 10px 8px;
  background: #1a0830;
}
.trace-grid span { display: block; color: var(--muted); font-size: 11px; }
.trace-grid strong { font-size: 18px; font-variant-numeric: tabular-nums; }
.runs { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.runs li {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 2px 8px;
  padding: 10px 12px;
  border-radius: 14px;
  border: 1px solid var(--line);
}
.runs em { grid-column: 1; color: var(--muted); font-style: normal; font-size: 12px; }
.runs strong { grid-row: 1 / span 2; align-self: center; color: var(--gold); }
.quiet { font-size: 13px; line-height: 1.4; }
#clearArchive { width: 100%; margin-top: 8px; }

.rail {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  align-items: end;
  gap: 2px;
  padding: 6px 6px 8px;
  border-top: 1px solid var(--line);
  background:
    radial-gradient(60px 28px at 50% 0, rgba(243, 193, 91, 0.18), transparent 70%),
    linear-gradient(180deg, #3a1860, #12051c);
}
.rail button {
  min-width: 0;
  min-height: 58px;
  border: 0;
  background: transparent;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 4px;
  padding: 4px 0 2px;
}
.rail span {
  font-size: 10px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.rail .is-on span { color: var(--gold); }
.stone {
  width: 18px;
  height: 22px;
  display: block;
  clip-path: polygon(50% 0, 100% 32%, 78% 100%, 22% 100%, 0 32%);
}
.stone.sapphire { background: linear-gradient(160deg, #d7e6ff, var(--sapphire)); }
.stone.emerald { background: linear-gradient(160deg, #d8ffe9, var(--emerald)); }
.stone.amethyst { background: linear-gradient(160deg, #f3defe, var(--amethyst)); }
.stone.amber { background: linear-gradient(160deg, #fff0c8, var(--amber)); }
.rail .quest { transform: translateY(-10px); }
.rail .quest .stone {
  width: 42px;
  height: 42px;
  clip-path: polygon(50% 0, 100% 50%, 50% 100%, 0 50%);
  background: radial-gradient(circle at 35% 30%, #fff6d4, var(--gold) 46%, #8a5a12);
  box-shadow: 0 6px 16px rgba(243, 193, 91, 0.28);
}
.rail .is-on .stone { filter: drop-shadow(0 0 6px rgba(243, 193, 91, 0.8)); }

@supports not (width: 1cqi) {
  .sizer { width: min(100%, 70vw, 440px); height: auto; aspect-ratio: 1; max-height: 100%; }
}

@media (max-width: 359px) {
  .mast h1 { font-size: 16px; }
  .rail span { letter-spacing: 0.04em; }
  .swatches { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .node b { font-size: 11px; }
}

@media (min-width: 520px) {
  body { display: grid; place-items: center; }
  .hall { height: min(100dvh, 920px); border-radius: 28px; overflow: hidden; }
}

@media (prefers-reduced-motion: reduce) {
  .frame, .board.is-burst, .board.is-dull { animation: none; transition: none; }
}
