:root {
  color-scheme: dark;
  --bg: #110e0b;
  --ink: #f6efe2;
  --muted: #cbbba4;
  --line: rgba(246, 239, 226, 0.14);
  --copper: #e0a15c;
  --serif: "Iowan Old Style", Palatino, "Palatino Linotype", Georgia, serif;
  --sans: "Avenir Next", "Segoe UI", sans-serif;
  --accent: var(--copper);
}

* { box-sizing: border-box; }

html, body, #app { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--ink);
  font-family: var(--sans);
  background:
    radial-gradient(1000px 520px at 8% -10%, rgba(224, 161, 92, 0.18), transparent 55%),
    radial-gradient(800px 480px at 110% 0%, rgba(73, 198, 242, 0.1), transparent 46%),
    var(--bg);
}

button, .screen.play { user-select: none; }

button {
  font: inherit;
  color: var(--ink);
  background: #2a231c;
  border: 1px solid rgba(224, 161, 92, 0.4);
  border-radius: 999px;
  padding: 0.55rem 0.95rem;
  cursor: pointer;
}

button:hover { border-color: var(--copper); }
button:focus-visible { outline: 2px solid var(--copper); outline-offset: 2px; }
button:disabled { opacity: 0.45; cursor: default; }

button.primary {
  background: linear-gradient(#f3d0a0, #c9843a);
  color: #2a160c;
  border-color: transparent;
  font-weight: 700;
}

.screen { height: 100%; min-height: 0; display: flex; flex-direction: column; }
.screen.map, .screen.title { overflow: auto; }
.screen[data-book="earth"] { --accent: #86c56a; }
.screen[data-book="fire"] { --accent: #ff7a45; }
.screen[data-book="air"] { --accent: #ffd056; }
.screen[data-book="water"] { --accent: #49c6f2; }

.kicker, .eyebrow {
  margin: 0;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  font-size: 0.72rem;
  color: var(--muted);
}

.title-wrap {
  margin: auto;
  max-width: 42rem;
  padding: 48px 20px 24px;
  text-align: center;
}

.title-wrap h1 {
  font-family: var(--serif);
  font-weight: 600;
  font-size: clamp(2.7rem, 7vw, 4.6rem);
  line-height: 0.95;
  margin: 0.2rem 0 0.8rem;
}

.lead { font-size: 1.15rem; color: var(--ink); }
.fine { color: var(--muted); font-size: 0.88rem; }
.title-actions { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; margin: 22px 0; }

.also {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px 10px;
  padding: 8px 20px 22px;
}
.also a {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  text-decoration: none;
  font-size: 0.92rem;
  padding: 0.4rem 0.8rem;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(42, 35, 28, 0.55);
}
.also a:hover { color: var(--ink); border-color: rgba(224, 161, 92, 0.55); }
.also a:focus-visible { outline: 2px solid var(--copper); outline-offset: 2px; }
.also img { width: 1.55rem; height: 1.55rem; flex: none; display: block; }

.medallions { display: flex; justify-content: center; gap: 14px; margin-bottom: 8px; }
.med {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  transform: rotate(45deg);
  box-shadow: inset 0 0 0 3px rgba(255, 255, 255, 0.28), 0 10px 24px rgba(0, 0, 0, 0.28);
}
.med.earth { background: radial-gradient(circle at 35% 30%, #e7ffc4, #5ea844 46%, #245018); }
.med.fire { background: radial-gradient(circle at 35% 30%, #ffd2c2, #ff6d45 46%, #8d2a16); }
.med.air { background: radial-gradient(circle at 35% 30%, #fff1c4, #ffd056 46%, #8a6412); }
.med.water { background: radial-gradient(circle at 35% 30%, #d9f6ff, #49c6f2 46%, #14688a); }

.map-head, .top {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 20px 0;
}
.map-head h1, .titles h1 {
  font-family: var(--serif);
  font-size: 1.7rem;
  font-weight: 600;
  margin: 0;
}
.titles { flex: 1; min-width: 0; }
.titles h1 { font-size: 1.35rem; }
.top-actions, .map-head .actions { display: flex; flex-wrap: wrap; gap: 8px; }

.map-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 16px;
  padding: 16px 20px 32px;
}

.book {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
  border-top: 3px solid var(--accent);
  border-radius: 18px;
  padding: 16px;
}
.book h2 { font-family: var(--serif); font-size: 1.25rem; margin: 0 0 0.35rem; }
.book p { color: var(--muted); margin: 0 0 12px; min-height: 3.2em; }

.path { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.path li { display: flex; align-items: center; gap: 8px; }
.node {
  width: 58px;
  flex: none;
  border-radius: 16px;
  padding: 4px 2px 2px;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.node.current { box-shadow: 0 0 0 2px var(--accent); }
.node-name { font-size: 0.86rem; }
.num { font-family: var(--serif); font-size: 1.05rem; line-height: 1; }

.star { width: 11px; height: 11px; fill: #3c342c; }
.star.on { fill: var(--copper); }
.mini { display: flex; gap: 1px; height: 12px; }
.stars { display: flex; gap: 6px; margin: 8px 0 12px; }
.stars .star { width: 28px; height: 28px; }

.tip { margin: 8px 20px 0; color: var(--muted); }
.stage { flex: 1; min-height: 0; display: flex; }
.board-wrap {
  position: relative;
  flex: 1;
  min-width: 0;
  margin: 10px 12px 10px 16px;
  border-radius: 18px;
  overflow: hidden;
  background: #16110e;
  box-shadow: inset 0 0 0 1px rgba(224, 161, 92, 0.22), 0 18px 50px rgba(0, 0, 0, 0.35);
}
#board { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }

aside {
  width: 212px;
  flex: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  padding: 10px 16px 10px 0;
}
.vial {
  width: 26px;
  height: 148px;
  border-radius: 20px;
  border: 1px solid rgba(246, 239, 226, 0.28);
  background: #120e0b;
  position: relative;
  overflow: hidden;
}
.vial-fill {
  position: absolute;
  left: 3px;
  right: 3px;
  bottom: 3px;
  height: 100%;
  border-radius: 14px;
  background: linear-gradient(#f6ffe4, var(--accent));
}
.vial.danger .vial-fill { background: linear-gradient(#ffd2c8, #d64532); }
.time-num { margin: 0; font-variant-numeric: tabular-nums; }
.score-label { margin: 8px 0 0; color: var(--muted); font-size: 0.75rem; letter-spacing: 0.12em; text-transform: uppercase; }
.score-num { margin: 0; font-family: var(--serif); font-size: 1.7rem; }
#minimap { width: 180px; height: 120px; border-radius: 10px; background: #120f0c; }
.caption { margin: 0; color: var(--muted); font-size: 0.75rem; text-align: center; }
.pans { display: flex; gap: 6px; }
.pans[hidden] { display: none; }
.pans button { padding: 0.35rem 0.6rem; }

.powers {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
  padding: 0 16px 14px;
}
.power {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  min-width: 180px;
  border-radius: 16px;
  text-align: left;
  --pip: var(--copper);
}
.power .who { display: flex; flex-direction: column; }
.power small { color: var(--muted); font-size: 0.75rem; }
.pip { width: 16px; height: 16px; border-radius: 5px; }
.meter { flex: 1 0 100%; height: 5px; background: #3a3128; border-radius: 99px; overflow: hidden; }
.meter > span { display: block; height: 100%; width: 0; background: var(--pip); }
.power.ready { box-shadow: 0 0 0 1px var(--pip), 0 0 16px color-mix(in srgb, var(--pip) 50%, transparent); }
.power.armed { background: #3c2e22; }
.power.deny { animation: deny 0.28s linear; }
.none-powers { color: var(--muted); margin: 0; }

@keyframes deny {
  25% { transform: translateX(-3px); }
  75% { transform: translateX(3px); }
}

.toast {
  position: absolute;
  left: 50%;
  bottom: 14px;
  transform: translateX(-50%);
  margin: 0;
  padding: 8px 12px;
  border-radius: 999px;
  background: rgba(18, 14, 11, 0.92);
  border: 1px solid rgba(224, 161, 92, 0.45);
  pointer-events: none;
  max-width: calc(100% - 24px);
  text-align: center;
}

.veil {
  position: fixed;
  inset: 0;
  background: rgba(8, 6, 5, 0.64);
  display: grid;
  place-items: center;
  padding: 20px;
  z-index: 5;
}
.veil[hidden] { display: none; }
.dialog {
  width: min(460px, 100%);
  background: #221c17;
  border: 1px solid rgba(224, 161, 92, 0.4);
  border-radius: 22px;
  padding: 22px;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.45);
}
.dialog h2 { font-family: var(--serif); margin: 0.15rem 0 0.7rem; font-weight: 600; }
.dialog ul { margin: 0 0 1rem; padding-left: 1.15rem; color: var(--muted); }
.dialog li + li { margin-top: 0.4rem; }
.dialog p { margin: 0.25rem 0; }
.actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }

@media (max-width: 980px) {
  .map-grid { grid-template-columns: 1fr 1fr; }
  .book p { min-height: 0; }
}

@media (max-width: 820px) {
  .top { flex-wrap: wrap; align-items: flex-start; }
  .titles { flex: 1 1 auto; }
  .titles h1 { font-size: 1.2rem; }
  .top-actions { flex: 1 1 100%; }
  .stage { flex-direction: column; }
  aside {
    width: auto;
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    padding: 0 12px 8px;
  }
  .vial { height: 88px; }
  #minimap { width: 140px; height: 88px; }
  .board-wrap { margin: 8px 12px; }
  .map-grid { grid-template-columns: 1fr; }
}
