:root {
  --bg: #f4efe3;
  --panel: #fffaf0;
  --ink: #2a1a3d;
  --mute: #6d5f80;
  --line: #d9ccb4;
  --amber: #c2670a;
  --moss: #1e8a52;
  --blood: #c92a46;
  --violet: #6d3fd1;
  --bar: #e8dcc3;
  box-sizing: border-box;
  padding-top: env(safe-area-inset-top, 0px);
  padding-bottom: env(safe-area-inset-bottom, 0px);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #1a0f2e;
    --panel: #25163f;
    --ink: #f3ead7;
    --mute: #a897c4;
    --line: #3d2a63;
    --amber: #ffb84d;
    --moss: #5fd38d;
    --blood: #ff6b81;
    --violet: #a98bff;
    --bar: #35235a;
  }
}
:root[data-theme="dark"] {
  --bg: #1a0f2e;
  --panel: #25163f;
  --ink: #f3ead7;
  --mute: #a897c4;
  --line: #3d2a63;
  --amber: #ffb84d;
  --moss: #5fd38d;
  --blood: #ff6b81;
  --violet: #a98bff;
  --bar: #35235a;
}
* {
  box-sizing: border-box;
}
html {
  scroll-padding-top: env(safe-area-inset-top, 0px);
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font:
    400 16px/1.5 "Space Grotesk",
    system-ui,
    sans-serif;
}
h1,
h2,
.big {
  font-family: Bungee, Impact, sans-serif;
  font-weight: 400;
  margin: 0;
  letter-spacing: 0.02em;
}
header {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  border-bottom: 2px solid var(--line);
}
.app-nav {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 8px;
  padding: 8px 18px;
  background: rgba(29, 18, 51, 0.96);
  border-bottom: 2px solid var(--line);
}
.app-nav a {
  color: var(--ink);
  text-decoration: none;
  font-weight: 700;
  padding: 6px 12px;
  border: 2px solid var(--line);
  border-radius: 20px;
  background: var(--panel);
}
.app-nav a:hover,
.app-nav a:focus-visible {
  color: #2a1a3d;
  background: var(--amber);
  outline: 2px solid var(--amber);
  outline-offset: 2px;
}
main,
#chat-section,
#heroes {
  scroll-margin-top: 72px;
}
h1 {
  font-size: 26px;
  color: var(--amber);
}
.ctl {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}
input,
button {
  font: inherit;
  color: inherit;
}
input {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 0;
  width: 150px;
}
button {
  background: var(--violet);
  color: #fff;
  border: 0;
  border-radius: 8px;
  padding: 9px 14px;
  font-weight: 700;
  cursor: pointer;
}
button.alt {
  background: var(--panel);
  color: var(--ink);
  border: 2px solid var(--line);
}
button:focus-visible,
input:focus-visible {
  outline: 3px solid var(--amber);
  outline-offset: 2px;
}
#status {
  font-size: 13px;
  color: var(--mute);
}
main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 300px;
  gap: 16px;
  padding: 16px 18px;
  max-width: 1100px;
  margin: 0 auto;
}
@media (max-width: 820px) {
  main {
    grid-template-columns: 1fr;
  }
}
.panel {
  background: var(--panel);
  border: 2px solid var(--line);
  border-radius: 14px;
  padding: 16px;
}
.stats {
  display: flex;
  gap: 14px;
  flex-wrap: wrap;
  margin-bottom: 14px;
  align-items: center;
}
.hp {
  flex: none;
  width: min(260px, 100%);
}
.chip {
  min-width: 92px;
  text-align: center;
}
.hp .track {
  height: 14px;
  background: var(--bar);
  border-radius: 7px;
  overflow: hidden;
}
.hp .fill {
  height: 100%;
  background: var(--moss);
  transition:
    width 0.6s,
    background 0.6s;
}
.chip {
  font-weight: 700;
  padding: 4px 10px;
  border-radius: 20px;
  background: var(--bar);
}
#scene h2 {
  font-size: 28px;
  line-height: 1.15;
  margin-bottom: 6px;
}
#scene p {
  margin: 0 0 14px;
  color: var(--mute);
  max-width: 60ch;
}
.opt {
  position: relative;
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: center;
  border: 2px solid var(--line);
  border-radius: 10px;
  margin-bottom: 8px;
  padding: 12px 14px;
  overflow: hidden;
  background: var(--panel);
}
.opt .bar {
  position: absolute;
  inset: 0 auto 0 0;
  background: var(--bar);
  width: 0;
  transition: width 0.4s;
  z-index: 0;
}
.opt > * {
  position: relative;
  z-index: 1;
}
.opt.win {
  border-color: var(--amber);
}
.opt.blink {
  animation: blinktxt 0.5s steps(2, start) infinite;
}
.opt.blink .bar {
  width: 100% !important;
  animation: blinkbar 0.5s steps(2, start) infinite;
}
@keyframes blinkbar {
  50% {
    background: var(--amber);
  }
}
@keyframes blinktxt {
  50% {
    color: #1a0f2e;
  }
}
.opt.blink small,
.opt.blink b {
  color: inherit;
}
.opt.blink .bar {
  opacity: 0;
}
.opt b {
  font-family: Bungee, sans-serif;
  font-weight: 400;
  color: var(--amber);
  margin-right: 8px;
}
.opt small {
  color: var(--mute);
}
.timer {
  display: flex;
  align-items: center;
  gap: 12px;
  margin-top: 6px;
}
.timer .t {
  height: 8px;
  flex: 1;
  background: var(--bar);
  border-radius: 4px;
  overflow: hidden;
}
.timer .t i {
  display: block;
  height: 100%;
  background: var(--amber);
  width: 100%;
  transition: width 1s linear;
}
#die {
  font-size: 54px;
  color: var(--amber);
  min-width: 90px;
  text-align: center;
}
#result {
  display: none;
  text-align: center;
  padding: 10px 0;
}
#result.show {
  display: block;
}
#result .out {
  font-size: 20px;
  font-weight: 700;
}
.ok {
  color: var(--moss);
}
.bad {
  color: var(--blood);
}
aside .panel {
  margin-bottom: 16px;
}
h2.s {
  font-size: 15px;
  margin-bottom: 8px;
  color: var(--violet);
}
#chat {
  height: 230px;
  overflow-y: auto;
  font-size: 14px;
  overflow-wrap: anywhere;
}
#chat div {
  padding: 2px 0;
}
#chat b {
  color: var(--violet);
}
ol {
  margin: 0;
  padding-left: 22px;
  font-size: 14px;
}
.say {
  display: flex;
  gap: 6px;
  margin-top: 8px;
}
.say input {
  flex: 1;
  width: auto;
}
.hint {
  font-size: 13px;
  color: var(--mute);
  margin-top: 10px;
}
body.overlay {
  background: transparent;
}
body.overlay header,
body.overlay .app-nav,
body.overlay aside,
body.overlay .hint {
  display: none;
}
body.overlay main {
  grid-template-columns: 1fr;
  max-width: 520px;
  margin: 0;
}
body.overlay .panel {
  background: rgba(26, 15, 46, 0.88);
  color: #f3ead7;
  border-color: #ffb84d;
}
body.overlay {
  --ink: #f3ead7;
  --mute: #c9bbe0;
  --bar: #4a3478;
  --amber: #ffb84d;
  --moss: #5fd38d;
  --blood: #ff6b81;
}
@media (prefers-reduced-motion: reduce) {
  * {
    transition: none !important;
  }
  .opt.blink,
  .opt.blink .bar {
    animation: none;
  }
  .opt.blink .bar {
    background: var(--amber);
  }
  .opt.blink {
    color: #1a0f2e;
  }
}
:root,
:root:not([data-theme="light"]),
:root[data-theme="dark"] {
  --bg: #120a1f;
  --panel: #21143a;
  --ink: #f6ecd2;
  --mute: #b9a8d6;
  --line: #8a6428;
  --amber: #ffc24d;
  --moss: #6fe39a;
  --blood: #ff6b7f;
  --violet: #b394ff;
  --bar: #3a2763;
}
body:not(.overlay) {
  background:
    radial-gradient(ellipse at 50% -10%, #4a2a7a 0, transparent 55%),
    repeating-linear-gradient(0deg, #120a1f 0 38px, #170d27 38px 40px), #120a1f;
  background-attachment: fixed;
}
header {
  background: linear-gradient(#3a2260, #241440);
  border-bottom: 4px solid var(--line);
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.5);
}
h1 {
  font-size: 30px;
  text-shadow:
    0 3px 0 #5b3a0c,
    0 0 18px rgba(255, 194, 77, 0.45);
}
.panel {
  border: 3px solid var(--line);
  box-shadow:
    inset 0 0 0 2px #120a1f,
    inset 0 0 40px rgba(0, 0, 0, 0.35),
    0 6px 0 #0b0614;
  background: linear-gradient(#2a1a4a, #1d1233);
}
.panel h2.s {
  color: var(--amber);
}
button {
  box-shadow: 0 4px 0 #3b2290;
}
button:active {
  transform: translateY(3px);
  box-shadow: 0 1px 0 #3b2290;
}
button.alt {
  box-shadow: 0 4px 0 #0b0614;
}
.map {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 0 0 14px;
  position: relative;
  padding: 0 4px;
}
.map:before {
  content: "";
  position: absolute;
  left: 18px;
  right: 18px;
  top: 50%;
  border-top: 4px dashed var(--line);
}
.node {
  position: relative;
  width: 34px;
  height: 34px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--bar);
  border: 3px solid var(--line);
  font:
    400 14px Bungee,
    sans-serif;
  color: var(--mute);
}
.node.done {
  background: var(--amber);
  color: #2a1a3d;
  border-color: #fff1c2;
}
.node.cur {
  background: var(--violet);
  color: #fff;
  border-color: #fff1c2;
  animation: pulse 1.2s ease-in-out infinite;
}
@keyframes pulse {
  50% {
    box-shadow: 0 0 0 8px rgba(179, 148, 255, 0.35);
  }
}
.party {
  display: flex;
  gap: 12px;
  justify-content: center;
  margin: 0 0 14px;
}
.hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  font-size: 12px;
  font-weight: 700;
  color: var(--mute);
}
.face {
  width: 56px;
  height: 56px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  font-size: 30px;
  background: linear-gradient(#4a2f80, #2c1a52);
  border: 3px solid var(--amber);
  box-shadow: 0 4px 0 #0b0614;
}
.hero.down .face {
  filter: grayscale(1);
  border-color: #666;
  opacity: 0.7;
}
.party.cheer .hero:not(.down) .face {
  animation: hop 0.5s ease 2;
}
.party.hurt .hero:not(.down) .face {
  animation: shake 0.12s linear 6;
  border-color: var(--blood);
}
@keyframes hop {
  50% {
    transform: translateY(-12px);
  }
}
@keyframes shake {
  25% {
    transform: translateX(-4px);
  }
  75% {
    transform: translateX(4px);
  }
}
.hp .track {
  height: 18px;
  border: 3px solid var(--line);
  background: #120a1f;
  border-radius: 10px;
}
.hp .fill {
  border-radius: 6px;
}
.chip {
  border: 2px solid var(--line);
  background: #120a1f;
}
.opt {
  border: 3px solid var(--line);
  border-radius: 12px;
  background: linear-gradient(#2d1c4f, #22143d);
  box-shadow: 0 4px 0 #0b0614;
}
.opt b {
  display: inline-grid;
  place-items: center;
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--amber);
  color: #2a1a3d;
  font-size: 15px;
  margin-right: 10px;
}
.opt.blink b {
  background: #1a0f2e;
  color: var(--amber);
}
.opt.win {
  box-shadow:
    0 0 18px rgba(255, 194, 77, 0.6),
    0 4px 0 #0b0614;
}
#scene h2 {
  color: var(--amber);
  text-shadow: 0 2px 0 #5b3a0c;
}
#die {
  display: grid;
  place-items: center;
  width: 110px;
  height: 122px;
  margin: 0 auto 8px;
  background: linear-gradient(#ffd77a, #e19a1c);
  color: #2a1a3d;
  font-size: 42px;
  clip-path: polygon(50% 0, 96% 26%, 96% 74%, 50% 100%, 4% 74%, 4% 26%);
}
#die.roll {
  animation: tumble 0.4s linear infinite;
}
@keyframes tumble {
  to {
    transform: rotate(360deg);
  }
}
#die.crit {
  background: linear-gradient(#b8ffd0, #2fbf6a);
}
#die.fumble {
  background: linear-gradient(#ffb3bd, #d6304a);
}
ol li {
  margin: 4px 0;
}
#lb {
  max-height: 240px;
  overflow-y: auto;
}
.plus {
  color: var(--moss);
  margin-left: 6px;
  display: inline-block;
  font-size: 12px;
  font-weight: 400;
  animation: pop 0.7s ease-out;
}
@keyframes pop {
  from {
    transform: scale(2);
    opacity: 0;
  }
  to {
    transform: scale(1);
    opacity: 1;
  }
}
.hpd {
  min-height: 22px;
  margin-top: 4px;
  font-weight: 700;
  opacity: 0;
}
.hpd.show {
  opacity: 1;
  animation: pop 0.6s ease-out;
}
@media (max-width: 820px) {
  .face {
    width: 48px;
    height: 48px;
  }
  .node {
    width: 30px;
    height: 30px;
  }
}
@media (prefers-reduced-motion: reduce) {
  .node.cur,
  #die.roll,
  .party .face {
    animation: none !important;
  }
}
