:root {
  color-scheme: light;
  --ink: #1e2329;
  --muted: #67717c;
  --paper: #fffaf0;
  --panel: #ffffff;
  --line: #d9d1c1;
  --red: #c94f3d;
  --green: #236b4b;
  --blue: #2f6fa3;
  --gold: #b87a20;
  --shadow: 0 18px 40px rgba(35, 30, 22, 0.14);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-width: 320px;
  color: var(--ink);
  background: #efe6d6;
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    sans-serif;
}

button {
  min-height: 40px;
  border: 1px solid #1f2c36;
  border-radius: 8px;
  color: #fff;
  background: #1f2c36;
  font: inherit;
  font-weight: 700;
  cursor: pointer;
}

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

.app {
  width: min(1220px, calc(100vw - 28px));
  margin: 0 auto;
  padding: 22px 0 28px;
}

.topbar,
.toolbar,
.lower {
  display: grid;
  gap: 16px;
}

.topbar {
  grid-template-columns: 1fr auto;
  align-items: end;
  margin-bottom: 16px;
}

.coach {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  align-items: center;
  margin-bottom: 16px;
  padding: 14px 16px;
  border: 1px solid #c9d7df;
  border-radius: 8px;
  background: #f7fbfd;
  box-shadow: var(--shadow);
}

.coach span {
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
}

.coach h2 {
  margin: 4px 0 5px;
  font-size: 18px;
}

.coach p {
  color: #47525c;
  line-height: 1.42;
}

.rule-triangle {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.rule-triangle span {
  min-height: 34px;
  padding: 8px 10px;
  border-radius: 8px;
  color: #fff;
  background: var(--blue);
  font-size: 12px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--blue);
  font-size: 13px;
  font-weight: 800;
  letter-spacing: 0;
}

h1,
h2,
p {
  margin: 0;
}

h1 {
  font-size: clamp(28px, 5vw, 48px);
  line-height: 1.02;
  letter-spacing: 0;
}

h2 {
  margin-bottom: 10px;
  font-size: 16px;
}

.hidden {
  display: none !important;
}

.pack-chip {
  max-width: 300px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  font-size: 13px;
  font-weight: 800;
}

.start-panel,
.map-panel {
  margin-bottom: 16px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.start-panel > div:first-child,
.map-head {
  margin-bottom: 14px;
}

.start-panel p,
.map-head p {
  color: var(--muted);
  line-height: 1.45;
}

.pack-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(210px, 1fr));
  gap: 10px;
}

.pack-card {
  min-height: 188px;
  padding: 14px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffaf0;
  text-align: left;
  box-shadow: 0 10px 22px rgba(35, 30, 22, 0.1);
}

.pack-card span {
  color: var(--blue);
  font-size: 12px;
  font-weight: 900;
}

.pack-card h3 {
  margin: 10px 0 8px;
  font-size: 22px;
}

.pack-card p {
  color: #3c4650;
  font-size: 13px;
}

.map-head {
  display: flex;
  justify-content: space-between;
  gap: 14px;
  align-items: start;
}

#new-run {
  min-width: 80px;
  color: var(--ink);
  background: transparent;
  border-color: var(--line);
}

.map {
  display: grid;
  grid-template-columns: repeat(7, minmax(78px, 1fr));
  gap: 12px;
  align-items: center;
  overflow-x: auto;
  padding: 4px 0;
}

.map-layer {
  display: grid;
  gap: 12px;
  min-width: 78px;
}

.map-node {
  min-height: 58px;
  border: 2px solid var(--line);
  border-radius: 8px;
  color: var(--ink);
  background: #fffaf0;
  text-align: center;
}

.map-node strong,
.map-node small {
  display: block;
}

.map-node strong {
  font-size: 18px;
}

.map-node small {
  margin-top: 3px;
  color: var(--muted);
  font-size: 11px;
}

.map-node.reachable {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 163, 0.14);
}

.map-node.done {
  color: var(--green);
  border-color: rgba(35, 107, 75, 0.45);
  background: #eff7ef;
}

.map-node.current {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}

.map-node[disabled]:not(.reachable) {
  opacity: 0.48;
}

.run-strip {
  display: flex;
  gap: 8px;
  align-items: center;
}

.node {
  min-width: 42px;
  padding: 7px 9px;
  border: 1px solid var(--line);
  border-radius: 8px;
  color: var(--muted);
  background: rgba(255, 255, 255, 0.72);
  text-align: center;
  font-size: 12px;
  font-weight: 800;
}

.node.active {
  color: #fff;
  background: var(--red);
  border-color: var(--red);
}

.node.done {
  color: var(--green);
  border-color: rgba(35, 107, 75, 0.45);
}

.arena {
  position: relative;
  overflow: hidden;
  min-height: 392px;
  border: 1px solid #cbbca4;
  border-radius: 8px;
  background: #d6c4a7;
  box-shadow: var(--shadow);
}

.arena-art {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.fighter,
.intent-panel {
  position: absolute;
  display: grid;
  gap: 4px;
  border: 1px solid rgba(255, 255, 255, 0.64);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.9);
  box-shadow: 0 12px 28px rgba(35, 30, 22, 0.18);
  backdrop-filter: blur(8px);
}

.fighter {
  min-width: 168px;
  padding: 13px;
}

.fighter span,
.intent-panel span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.fighter strong {
  font-size: 24px;
}

.meter {
  overflow: hidden;
  height: 8px;
  border-radius: 999px;
  background: rgba(30, 35, 41, 0.12);
}

.meter i {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: inherit;
  background: var(--green);
  transition: width 220ms ease;
}

.enemy .meter i {
  background: var(--red);
}

.fighter small {
  color: var(--muted);
  font-weight: 700;
}

.player {
  left: 26px;
  bottom: 24px;
}

.enemy {
  right: 26px;
  top: 24px;
}

.intent-panel {
  right: 26px;
  bottom: 24px;
  width: min(340px, calc(100% - 52px));
  padding: 14px;
}

.intent-panel strong {
  font-size: 22px;
}

.intent-panel p {
  color: var(--muted);
  line-height: 1.45;
}

#enemy-revealed {
  color: var(--red);
  font-weight: 800;
}

.effect-layer {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 2;
}

.wave-beam {
  position: absolute;
  left: 28%;
  top: 51%;
  width: 44%;
  height: 12px;
  border-radius: 999px;
  background: linear-gradient(90deg, #56b6f0, #fff7b0, #e85d4a);
  box-shadow: 0 0 22px rgba(232, 93, 74, 0.68);
  transform-origin: left center;
  animation: fireWave 520ms ease-out both;
}

.hit-pop {
  position: absolute;
  right: 12%;
  top: 21%;
  padding: 6px 10px;
  border-radius: 8px;
  color: #fff;
  background: var(--red);
  font-weight: 900;
  animation: popHit 680ms ease-out both;
}

.hit-pop.player-hit {
  right: auto;
  left: 12%;
  top: 60%;
  background: var(--blue);
}

.guard-ring {
  position: absolute;
  left: 10%;
  bottom: 16%;
  width: 132px;
  height: 86px;
  border: 4px solid rgba(35, 107, 75, 0.72);
  border-radius: 50%;
  animation: guardPulse 620ms ease-out both;
}

.qi-spark {
  position: absolute;
  left: 17%;
  bottom: 27%;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff3a1;
  box-shadow: 0 0 24px #f0c957;
  animation: sparkUp 700ms ease-out both;
}

.controls {
  margin-top: 16px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.combat-guide {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-bottom: 12px;
}

.combat-guide article {
  min-height: 92px;
  padding: 12px;
  border: 1px solid #d7c8ae;
  border-radius: 8px;
  background: #fffaf0;
}

.combat-guide h2 {
  margin-bottom: 7px;
  font-size: 14px;
}

.combat-guide p {
  color: #3f4b55;
  line-height: 1.44;
}

.toolbar {
  grid-template-columns: 1fr auto;
  align-items: center;
  margin-bottom: 12px;
}

.toolbar div {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar span {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 10px;
  border-radius: 8px;
  color: var(--muted);
  background: #f4efe7;
  font-size: 13px;
  font-weight: 800;
}

#end-turn {
  min-width: 116px;
  background: var(--green);
  border-color: var(--green);
}

.turn-actions {
  display: flex;
  gap: 8px;
}

#recommend-turn {
  min-width: 104px;
  color: var(--ink);
  background: #fffaf0;
  border-color: var(--gold);
}

.hand,
.reward-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 10px;
}

.card {
  min-height: 178px;
  padding: 12px;
  border: 2px solid #d7c8ae;
  border-radius: 8px;
  color: var(--ink);
  background: var(--paper);
  text-align: left;
  box-shadow: 0 8px 18px rgba(35, 30, 22, 0.1);
}

.card.selected {
  border-color: var(--red);
  background: #fff3e0;
  transform: translateY(-5px);
}

.card[disabled] {
  opacity: 0.48;
}

.card .meta,
.card .cost {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.card .cost {
  justify-content: flex-start;
  color: var(--gold);
}

.card h3 {
  margin: 12px 0 8px;
  font-size: 18px;
  line-height: 1.15;
  letter-spacing: 0;
}

.card p {
  color: #3c4650;
  font-size: 13px;
  line-height: 1.42;
}

.card.charge {
  border-top-color: var(--blue);
}

.card.guard {
  border-top-color: var(--green);
}

.card.wave {
  border-top-color: var(--red);
}

.card.skill {
  border-top-color: var(--gold);
}

.card.recommended {
  border-color: var(--blue);
  box-shadow: 0 0 0 3px rgba(47, 111, 163, 0.16), 0 8px 18px rgba(35, 30, 22, 0.1);
}

.lower {
  grid-template-columns: 360px 1fr;
  margin-top: 16px;
}

.panel {
  min-height: 176px;
  padding: 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.relics {
  display: grid;
  gap: 8px;
}

.relic {
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f7f2ea;
}

.relic strong {
  display: block;
  margin-bottom: 3px;
}

.relic small {
  color: var(--muted);
  line-height: 1.4;
}

.log {
  display: grid;
  gap: 7px;
  max-height: 220px;
  overflow: auto;
  margin: 0;
  padding-left: 22px;
  color: #39424b;
}

.log li {
  line-height: 1.42;
}

dialog {
  width: min(780px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 32px 90px rgba(0, 0, 0, 0.28);
}

dialog::backdrop {
  background: rgba(28, 24, 18, 0.56);
}

dialog form {
  padding: 18px;
  background: #fffaf0;
}

#reward-copy {
  margin-bottom: 14px;
  color: var(--muted);
}

#skip-reward {
  margin-top: 14px;
  color: var(--ink);
  background: transparent;
  border-color: var(--line);
}

@media (max-width: 760px) {
  .topbar,
  .coach,
  .toolbar,
  .combat-guide,
  .lower {
    grid-template-columns: 1fr;
  }

  .rule-triangle {
    justify-content: flex-start;
  }

  .turn-actions {
    width: 100%;
  }

  .turn-actions button {
    flex: 1;
  }

  .arena {
    min-height: 520px;
  }

  .player,
  .enemy,
  .intent-panel {
    left: 16px;
    right: 16px;
    width: auto;
  }

  .player {
    bottom: 20px;
  }

  .enemy {
    top: 20px;
  }

  .intent-panel {
    bottom: 138px;
  }
}

@keyframes fireWave {
  from {
    opacity: 0;
    transform: scaleX(0.05);
  }
  45% {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: scaleX(1);
  }
}

@keyframes popHit {
  from {
    opacity: 0;
    transform: translateY(8px) scale(0.88);
  }
  35% {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
  to {
    opacity: 0;
    transform: translateY(-22px) scale(1.05);
  }
}

@keyframes guardPulse {
  from {
    opacity: 0;
    transform: scale(0.72);
  }
  45% {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: scale(1.18);
  }
}

@keyframes sparkUp {
  from {
    opacity: 0;
    transform: translateY(18px) scale(0.7);
  }
  35% {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translateY(-48px) scale(1.3);
  }
}
