:root {
  color-scheme: light;
  --bg: #f5efe7;
  --panel: #ebe5db;
  --panel-2: #ddd4c8;
  --line: #ccc0b3;
  --text: #17201d;
  --muted: #66726b;
  --gold: #d9b660;
  --jade: #3f7f4d;
  --water: #1d6f8f;
  --fire: #b54635;
  --dream: #9a78bd;
  --metal: #5d6a65;
  --shadow: rgba(42, 35, 24, 0.14);
}

html.dark-theme {
  color-scheme: dark;
  --bg: #0e1111;
  --panel: #171b1a;
  --panel-2: #202321;
  --line: #3a413b;
  --text: #f3efe2;
  --muted: #b8b19f;
  --gold: #d9b660;
  --jade: #74b78a;
  --water: #63a8c6;
  --fire: #d86b50;
  --dream: #b58bd8;
  --metal: #c7c2b6;
  --shadow: rgba(0, 0, 0, 0.38);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    radial-gradient(circle at 20% 10%, rgba(63, 127, 77, 0.12), transparent 28rem),
    radial-gradient(circle at 85% 20%, rgba(154, 120, 189, 0.1), transparent 24rem),
    linear-gradient(160deg, #f5efe7 0%, #e8e0d8 46%, #f0e8e0 100%);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
}

html.dark-theme body {
  background:
    radial-gradient(circle at 20% 10%, rgba(116, 183, 138, 0.16), transparent 28rem),
    radial-gradient(circle at 85% 20%, rgba(181, 139, 216, 0.14), transparent 24rem),
    linear-gradient(160deg, #0b0d0d 0%, #141714 46%, #101414 100%);
}

button,
select {
  font: inherit;
}

.site-nav {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 16px 0 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  min-width: max-content;
  color: var(--text);
  font-size: 1.1rem;
  font-weight: 950;
  text-decoration: none;
}
.brand-mark img {
  width: 38px;
  height: 38px;
  object-fit: contain;
}

.nav-links {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.nav-links a {
  min-height: 38px;
  display: inline-flex;
  align-items: center;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: rgba(32, 35, 33, 0.86);
  color: var(--text);
  padding: 0 12px;
  font-weight: 800;
  text-decoration: none;
}

.nav-links a:hover,
.nav-links a[aria-current="page"] {
  border-color: var(--gold);
  box-shadow: 0 0 0 3px rgba(217, 182, 96, 0.18);
}

.shell {
  width: min(1180px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 12px 0 20px;
}

.arena {
  border: 1px solid rgba(217, 182, 96, 0.28);
  background: rgba(13, 16, 15, 0.88);
  box-shadow: 0 24px 70px var(--shadow);
  min-height: calc(100vh - 40px);
  padding: 18px;
}

.topbar,
.panel-heading,
.score-strip,
.action-row,
.skill-select,
.monster-title {
  display: flex;
  align-items: center;
}

.topbar {
  justify-content: space-between;
  gap: 18px;
  border-bottom: 1px solid var(--line);
  padding-bottom: 14px;
}

.eyebrow {
  color: var(--gold);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  margin: 0 0 5px;
  text-transform: uppercase;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  font-size: clamp(2rem, 5vw, 4.25rem);
  line-height: 0.95;
  margin: 0;
  letter-spacing: 0;
}

.score-strip {
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.score-strip span {
  border: 1px solid var(--line);
  background: #141716;
  color: var(--muted);
  padding: 8px 10px;
}

.score-strip strong {
  color: var(--text);
}

.combat-grid {
  display: grid;
  grid-template-columns: minmax(220px, 0.95fr) minmax(280px, 1.25fr) minmax(220px, 0.95fr);
  gap: 14px;
  margin-top: 16px;
}

.lower-grid {
  display: grid;
  grid-template-columns: minmax(270px, 0.9fr) minmax(320px, 1.4fr);
  gap: 14px;
  margin-top: 14px;
}

.panel {
  border: 1px solid var(--line);
  background: linear-gradient(180deg, rgba(32, 35, 33, 0.96), rgba(18, 21, 20, 0.96));
  border-radius: 8px;
}

summary {
  display: none;
}

.stat-panel,
.command-panel,
.log-panel {
  padding: 14px;
}

.panel-heading {
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 0.88rem;
  margin-bottom: 14px;
}

.panel-heading strong {
  color: var(--gold);
}

.bars {
  display: grid;
  gap: 10px;
}

.bar-row {
  display: grid;
  grid-template-columns: 34px 1fr 74px;
  align-items: center;
  gap: 8px;
  color: var(--muted);
  font-size: 0.82rem;
}

.bar-row b {
  color: var(--text);
  font-size: 0.8rem;
  text-align: right;
}

.bar {
  height: 10px;
  border: 1px solid #4a5148;
  background: #0c0f0e;
  overflow: hidden;
}

.bar i {
  display: block;
  width: 100%;
  height: 100%;
  background: linear-gradient(90deg, var(--fire), #e6a166);
  transition: width 180ms ease;
}

.bar.essence i {
  background: linear-gradient(90deg, var(--water), var(--dream));
}

.bar.xp i {
  background: linear-gradient(90deg, var(--jade), var(--gold));
}

.bar.danger i {
  background: linear-gradient(90deg, #9d3530, var(--fire));
}

.stats {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin: 14px 0;
}

.stats div {
  border: 1px solid rgba(255, 255, 255, 0.08);
  background: rgba(0, 0, 0, 0.18);
  padding: 9px;
}

dt {
  color: var(--muted);
  font-size: 0.72rem;
}

dd {
  margin: 3px 0 0;
  color: var(--text);
  font-weight: 700;
}

.passives,
.intent,
.resonance {
  border-top: 1px solid var(--line);
  margin-top: 12px;
  padding-top: 12px;
}

.passives span,
.intent span,
.resonance span,
.skill-select span {
  color: var(--gold);
  display: block;
  font-size: 0.76rem;
  margin-bottom: 5px;
  text-transform: uppercase;
}

.passives p,
.intent p,
.resonance p,
.skill-info {
  color: var(--muted);
  margin: 0;
  line-height: 1.45;
}

.essence-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  min-height: 27px;
}

.essence-chip {
  border: 1px solid currentColor;
  background: rgba(0, 0, 0, 0.22);
  color: var(--text);
  display: inline-flex;
  align-items: center;
  min-height: 25px;
  padding: 3px 8px;
  font-size: 0.76rem;
  font-weight: 700;
}

.skill-detail {
  display: grid;
  gap: 7px;
}

.skill-detail strong {
  color: var(--text);
}

.skill-essences {
  min-height: 0;
}

.beast-panel .resonance {
  margin-top: 12px;
}

#saturationText {
  display: grid;
  gap: 7px;
}

.saturation-name {
  color: var(--muted);
}

.saturation-essences {
  min-height: 0;
}

.beast-stage {
  min-height: 390px;
  overflow: hidden;
  position: relative;
  display: grid;
  place-items: center;
  padding: 20px;
}

.domain-map {
  position: absolute;
  inset: 0;
  opacity: 0.46;
  background:
    linear-gradient(90deg, transparent 49%, rgba(217, 182, 96, 0.18) 50%, transparent 51%),
    linear-gradient(0deg, transparent 49%, rgba(116, 183, 138, 0.12) 50%, transparent 51%);
  background-size: 72px 72px;
}

.domain-map span {
  position: absolute;
  border: 1px solid rgba(217, 182, 96, 0.22);
  transform: rotate(45deg);
}

.domain-map span:nth-child(1) { width: 160px; height: 160px; left: 8%; top: 8%; }
.domain-map span:nth-child(2) { width: 220px; height: 220px; right: -8%; top: 18%; }
.domain-map span:nth-child(3) { width: 130px; height: 130px; left: 20%; bottom: -6%; }
.domain-map span:nth-child(4) { width: 90px; height: 90px; right: 22%; bottom: 12%; }

.monster-card {
  width: min(290px, 76vw);
  aspect-ratio: 1;
  border: 1px solid rgba(217, 182, 96, 0.35);
  background: #f0ead4;
  position: relative;
  display: grid;
  place-items: center;
  box-shadow: 0 16px 34px rgba(0, 0, 0, 0.34);
}

.profile-band {
  position: absolute;
  inset: 0 0 auto;
  height: 12px;
  background: var(--jade);
  z-index: 2;
}

.monster-card img {
  width: 72%;
  image-rendering: pixelated;
  position: relative;
  z-index: 1;
}

.stage-monster-health {
  position: absolute;
  left: 12px;
  right: 12px;
  bottom: 12px;
  z-index: 3;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 8px;
  border: 1px solid rgba(217, 182, 96, 0.38);
  background: rgba(12, 15, 14, 0.84);
  color: var(--muted);
  padding: 7px 8px;
  font-size: 0.72rem;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

.stage-monster-health b {
  color: var(--text);
  font-size: 0.72rem;
  white-space: nowrap;
}

.monster-tint {
  position: absolute;
  inset: 0;
  mix-blend-mode: multiply;
  pointer-events: none;
  opacity: 0.16;
}

.monster-card.hit {
  animation: beast-hit 260ms linear;
}

.shell.hit {
  animation: hero-hit 300ms linear;
}

@keyframes beast-hit {
  0%, 100% { transform: translateX(0); filter: brightness(1); }
  25% { transform: translateX(-8px); filter: brightness(1.7); }
  50% { transform: translateX(8px); }
  75% { transform: translateX(-5px); }
}

@keyframes hero-hit {
  0%, 100% { box-shadow: none; }
  40% { box-shadow: inset 0 0 0 999px rgba(216, 66, 54, 0.17); }
}

.monster-title {
  position: absolute;
  left: 18px;
  right: 18px;
  bottom: 16px;
  justify-content: space-between;
  gap: 12px;
}

.monster-title p {
  color: var(--muted);
  margin: 0;
  font-size: 0.8rem;
}

.monster-title h2 {
  color: var(--text);
  font-size: clamp(1.1rem, 2.8vw, 1.55rem);
  margin: 0;
  text-align: right;
}

.command-panel {
  display: grid;
  gap: 12px;
}

.action-row {
  gap: 8px;
  flex-wrap: wrap;
}

.quick-vitals {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
}

.quick-vital {
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 6px 8px;
  align-items: center;
  border: 1px solid var(--line);
  background: rgba(0, 0, 0, 0.18);
  padding: 9px;
}

.quick-vital span {
  color: var(--gold);
  font-size: 0.72rem;
  font-weight: 800;
  text-transform: uppercase;
}

.quick-vital .bar {
  min-width: 54px;
}

.quick-vital b {
  grid-column: 1 / -1;
  color: var(--text);
  font-size: 0.86rem;
}

button {
  border: 1px solid rgba(217, 182, 96, 0.42);
  background: #26342b;
  color: var(--text);
  cursor: pointer;
  min-height: 42px;
  padding: 0 14px;
}

button:hover:not(:disabled),
button:focus-visible {
  background: #34533c;
  outline: 2px solid rgba(217, 182, 96, 0.45);
  outline-offset: 2px;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

button.quiet {
  background: #1a1d1c;
  border-color: var(--line);
}

.log-restart {
  width: 100%;
  margin: -2px 0 12px;
}

.skill-select {
  align-items: stretch;
  flex-direction: column;
  gap: 6px;
}

select {
  width: 100%;
  min-height: 42px;
  background: #101312;
  border: 1px solid var(--line);
  color: var(--text);
  padding: 0 10px;
}

.battle-log {
  height: 180px;
  overflow-y: auto;
  color: #e7dfca;
  font-family: Consolas, "Courier New", monospace;
  font-size: 0.9rem;
  line-height: 1.45;
  padding-right: 8px;
}

.battle-log p {
  margin: 0 0 8px;
}

.modal {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.68);
  z-index: 10;
}

.modal.hidden {
  display: none;
}

.modal-card {
  width: min(620px, 100%);
  border: 1px solid rgba(217, 182, 96, 0.42);
  background: #171b1a;
  box-shadow: 0 24px 80px rgba(0, 0, 0, 0.55);
  padding: 18px;
}

.modal-card h2 {
  margin-bottom: 8px;
}

.modal-card p {
  color: var(--muted);
  line-height: 1.45;
}

.choice-options {
  display: grid;
  gap: 10px;
  margin-top: 14px;
}

.choice-options button {
  text-align: left;
  min-height: 58px;
  padding: 10px 12px;
}

@media (max-width: 880px) {
  .combat-grid,
  .lower-grid {
    grid-template-columns: 1fr;
  }

  .site-nav {
    align-items: flex-start;
    flex-direction: column;
    padding: 12px 0 0;
  }

  .nav-links {
    justify-content: flex-start;
  }

  .beast-stage {
    min-height: 330px;
    order: -1;
  }

  .hero-panel {
    order: 1;
  }

  .beast-panel {
    order: 2;
  }

  .lower-grid {
    margin-top: 10px;
  }

  .command-panel {
    position: sticky;
    bottom: 0;
    z-index: 4;
    box-shadow: 0 -10px 28px rgba(0, 0, 0, 0.3);
  }

  .topbar,
  .monster-title {
    align-items: flex-start;
    flex-direction: column;
  }

  .score-strip {
    justify-content: flex-start;
  }

  .monster-title h2 {
    text-align: left;
  }

  summary {
    min-height: 46px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    color: var(--gold);
    cursor: pointer;
    font-weight: 900;
    list-style: none;
  }

  summary::-webkit-details-marker {
    display: none;
  }

  summary::after {
    content: "+";
    color: var(--muted);
    font-size: 1.25rem;
  }

  details[open] summary {
    border-bottom: 1px solid var(--line);
    margin-bottom: 14px;
  }

  details[open] summary::after {
    content: "-";
  }
}

@media (max-width: 520px) {
  .site-nav {
    width: calc(100vw - 18px);
  }

  .nav-links {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr 1fr;
  }

  .nav-links a {
    justify-content: center;
    min-width: 0;
    text-align: center;
  }

  .shell {
    width: 100%;
    padding: 0;
  }

  .arena {
    border-left: 0;
    border-right: 0;
    min-height: 100vh;
    padding: 12px;
  }

  .topbar {
    gap: 12px;
  }

  h1 {
    font-size: clamp(2.35rem, 14vw, 3.6rem);
  }

  .score-strip {
    display: grid;
    width: 100%;
    grid-template-columns: repeat(3, 1fr);
  }

  .score-strip span {
    display: grid;
    gap: 2px;
    padding: 7px;
    text-align: center;
  }

  .beast-stage {
    min-height: 300px;
    padding: 14px;
  }

  .monster-card {
    width: min(235px, 72vw);
  }

  .monster-title {
    left: 14px;
    right: 14px;
    bottom: 12px;
  }

  .stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .bar-row {
    grid-template-columns: 32px 1fr;
  }

  .bar-row b {
    grid-column: 2;
    text-align: left;
  }

  button {
    flex: 1 1 112px;
  }

  .battle-log {
    height: 150px;
  }
}

@media (max-width: 380px) {
  .nav-links {
    grid-template-columns: 1fr;
  }

  .stats {
    grid-template-columns: 1fr;
  }
}
