:root {
  color-scheme: dark;
  --ink: #f8f7ff;
  --muted-ink: #bfc8ff;
  --gold: #fff0a8;
  --panel-top: #2028aa;
  --panel-mid: #111a82;
  --panel-bottom: #08104f;
  --panel-deep: #05092e;
  --line: #f8f7ff;
  --line-soft: #95a8ff;
  --shadow: #02020c;
  --accent: #79e2ff;
  font-family: "MS Gothic", "Hiragino Kaku Gothic ProN", "Yu Gothic", monospace;
  background: #030617;
  color: var(--ink);
}

* {
  box-sizing: border-box;
}

html {
  image-rendering: pixelated;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 16% 18%, rgba(255, 255, 255, 0.16) 0 1px, transparent 1px),
    radial-gradient(circle at 78% 22%, rgba(255, 255, 255, 0.12) 0 1px, transparent 1px),
    radial-gradient(circle at 68% 76%, rgba(255, 255, 255, 0.1) 0 1px, transparent 1px),
    linear-gradient(180deg, #07104d 0%, #030617 72%);
  background-size: 44px 44px, 64px 64px, 58px 58px, auto;
  letter-spacing: 0.02em;
}

button {
  position: relative;
  min-height: 38px;
  border: 3px solid var(--line);
  border-radius: 0;
  background: linear-gradient(180deg, #2531bd, #10197c);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.22),
    inset -2px -2px 0 rgba(0, 0, 0, 0.42),
    4px 4px 0 var(--shadow);
  color: var(--ink);
  font: inherit;
  font-weight: 700;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.78);
  cursor: pointer;
}

button:hover:not(:disabled),
button:focus-visible:not(:disabled) {
  color: var(--gold);
  background: linear-gradient(180deg, #3546e0, #17228f);
  outline: none;
}

button:hover:not(:disabled)::before,
button:focus-visible:not(:disabled)::before {
  content: "▶";
  position: absolute;
  left: 8px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--gold);
  font-size: 10px;
}

button:disabled {
  color: #94a0cf;
  opacity: 0.62;
  cursor: not-allowed;
}

.opening-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: grid;
  place-items: center;
  padding: 18px;
  background:
    repeating-linear-gradient(
      0deg,
      rgba(255, 255, 255, 0.03) 0 2px,
      transparent 2px 4px
    ),
    #02020c;
}

.opening-screen.hidden {
  display: none;
}

.opening-window {
  width: min(720px, 100%);
  padding: 24px;
  border: 4px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 22px),
    linear-gradient(180deg, #172391, #08104f);
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.16),
    inset -3px -3px 0 rgba(0, 0, 0, 0.55),
    8px 8px 0 var(--shadow);
}

.opening-title {
  color: var(--gold);
  font-size: 24px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.82);
}

.opening-lines {
  margin: 22px 0;
  display: grid;
  gap: 10px;
  line-height: 1.8;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.78);
}

.opening-lines p {
  margin: 0;
}

.opening-start {
  width: 100%;
}

.opening-help {
  width: 100%;
  margin-bottom: 10px;
}

.opening-difficulty {
  margin: 0 0 16px;
  padding: 12px;
  border: 3px solid var(--line-soft);
  background: rgba(5, 9, 46, 0.52);
}

.opening-difficulty-title {
  margin-bottom: 8px;
  color: var(--gold);
  font-weight: 700;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.72);
}

.opening-difficulty-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.opening-difficulty-btn.selected {
  color: #1d1200;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.3), transparent 22px),
    linear-gradient(180deg, #fff07a, #ffb347 38%, #d66c18);
  text-shadow: none;
}

.opening-difficulty-note {
  margin: 10px 0 0;
  color: var(--muted-ink);
  font-size: 13px;
  line-height: 1.5;
}

.game-shell {
  position: relative;
  width: min(1180px, calc(100% - 24px));
  margin: 0 auto;
  padding: 14px 0;
  display: grid;
  grid-template-columns: 270px 1fr;
  gap: 10px;
}

.dungeon-panel,
.party-panel,
.battle-panel,
.status-dialog {
  position: relative;
  border: 4px solid var(--line);
  border-radius: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.1), transparent 18px),
    linear-gradient(180deg, var(--panel-top), var(--panel-mid) 48%, var(--panel-bottom));
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.18),
    inset -3px -3px 0 rgba(0, 0, 0, 0.5),
    7px 7px 0 var(--shadow);
}

.dungeon-panel,
.party-panel,
.battle-panel {
  padding: 12px;
}

.dungeon-panel {
  align-self: stretch;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.panel-title,
.battle-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.panel-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: end;
}

.party-control-panel {
  justify-content: flex-end;
  margin-bottom: 6px;
}

.party-control-panel .panel-actions {
  max-width: 100%;
}

.panel-title h1,
.battle-header h2,
.dialog-header h2 {
  margin: 0;
  color: var(--gold);
  font-size: 18px;
  line-height: 1.2;
  letter-spacing: 0.08em;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.8);
}

.party-title-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.small-btn {
  min-height: 30px;
  padding: 0 8px;
  font-size: 13px;
}

.small-btn:hover:not(:disabled)::before,
.small-btn:focus-visible:not(:disabled)::before {
  left: 5px;
}

.music-credit {
  margin: 6px 0 0;
  color: var(--muted-ink);
  font-size: 12px;
  text-align: right;
}

.floor-readout {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px;
}

.floor-readout .label,
.party-row-title,
.formation-panel-title,
.formation-zone-title {
  color: var(--gold);
  font-weight: 700;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.72);
}

.floor-readout strong {
  font-size: 21px;
  line-height: 1;
  color: var(--ink);
  text-shadow: 3px 3px 0 rgba(0, 0, 0, 0.82);
}

.tower-gauge {
  height: 22px;
  margin: 0;
  display: flex;
  align-items: stretch;
  border: 3px solid var(--line);
  border-radius: 0;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.08) 0 16px,
      transparent 16px 18px
    ),
    var(--panel-deep);
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.08),
    inset -3px -3px 0 rgba(0, 0, 0, 0.55);
  overflow: hidden;
}

.tower-progress {
  width: 2%;
  height: 100%;
  background:
    repeating-linear-gradient(
      90deg,
      rgba(255, 255, 255, 0.34) 0 3px,
      transparent 3px 6px
    ),
    linear-gradient(90deg, #fff6c6, #ffd95f 46%, #ff835a);
  transition: width 180ms steps(4);
}

.travel-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}

.travel-actions button {
  min-height: 32px;
}

.side-note {
  flex: 1;
  min-height: 92px;
  padding: 9px;
  border: 3px solid var(--line-soft);
  background: rgba(5, 9, 46, 0.42);
  color: var(--ink);
  overflow: hidden;
}

.side-note-title {
  color: var(--gold);
  font-weight: 700;
  line-height: 1.2;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.72);
}

.side-note-body {
  margin-top: 6px;
  font-size: 12px;
  line-height: 1.55;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.72);
}

.party-grid {
  margin-top: 0;
  display: grid;
  gap: 6px;
}

.party-row {
  display: grid;
  gap: 5px;
}

.party-row-title {
  font-size: 13px;
  letter-spacing: 0.08em;
}

.party-row-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 6px;
}

.empty-slot {
  min-height: 86px;
  display: grid;
  place-items: center;
  border: 3px solid var(--line-soft);
  color: var(--muted-ink);
  background: rgba(4, 8, 40, 0.58);
}

.member-card,
.enemy-card {
  position: relative;
  min-height: 86px;
  padding: 6px;
  border: 3px solid var(--line);
  border-radius: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 18px),
    linear-gradient(180deg, #172391, #0c145d);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.14),
    inset -2px -2px 0 rgba(0, 0, 0, 0.45);
}

.member-card-content {
  position: relative;
  z-index: 1;
}

.member-card.defeated,
.enemy-card.defeated {
  opacity: 0.46;
}

.member-card.substitution-incoming .member-card-content {
  animation: substitute-member-in 640ms cubic-bezier(0.17, 0.84, 0.44, 1) both;
}

.substitution-outgoing-ghost {
  position: absolute;
  inset: 0;
  z-index: 3;
  box-sizing: border-box;
  padding: 10px;
  color: #d9ddff;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.04), transparent 18px),
    linear-gradient(180deg, rgba(8, 12, 58, 0.98), rgba(2, 4, 24, 0.98));
  box-shadow:
    inset 0 0 0 3px rgba(170, 178, 255, 0.5),
    inset 0 0 30px rgba(0, 0, 0, 0.72);
  text-shadow: 2px 2px 0 #000;
  animation: substitute-member-out 640ms ease-in forwards;
}

.substitution-outgoing-ghost .character-portrait,
.substitution-outgoing-ghost .pixel-icon {
  filter: grayscale(0.45) brightness(0.58);
}

.member-card.acting .substitution-outgoing-ghost .name-line,
.member-card.acting .substitution-outgoing-ghost .name-line > span:last-child,
.member-card.acting .substitution-outgoing-ghost .stat-line {
  color: #d9ddff;
  text-shadow: 2px 2px 0 #000;
}

.substitution-ghost-body {
  margin-top: 8px;
}

.enemy-card.attack-preview {
  border-color: #ff6b6b;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.12), transparent 18px),
    linear-gradient(180deg, #7b1820, #430b10);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.14),
    inset -2px -2px 0 rgba(0, 0, 0, 0.45),
    0 0 0 3px rgba(255, 107, 107, 0.18);
}

.enemy-card.acting {
  border-color: #ff6b6b;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.18), transparent 20px),
    linear-gradient(180deg, #9d1d2a, #5c0b14 62%, #2b0508);
  color: #fff4f4;
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.18),
    inset -2px -2px 0 rgba(0, 0, 0, 0.48),
    0 0 0 3px rgba(255, 107, 107, 0.22),
    0 0 18px rgba(255, 58, 78, 0.42);
  animation: enemy-acting-pulse 500ms ease-in-out infinite alternate;
}

.enemy-card.acting .name-line,
.enemy-card.acting .stat-line {
  color: #fff4f4;
}

.enemy-card.acting .name-line > span:last-child {
  color: #ffd1d6;
}

.member-card.acting {
  border-color: #fff07a;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.3), transparent 22px),
    linear-gradient(180deg, #fff07a, #ffb347 38%, #d66c18);
  color: #1d1200;
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.36),
    inset -2px -2px 0 rgba(0, 0, 0, 0.34),
    0 0 0 3px rgba(255, 240, 122, 0.28),
    0 0 18px rgba(255, 212, 94, 0.38);
}

.member-card.acting .name-line,
.member-card.acting .stat-line {
  color: #1d1200;
  text-shadow: none;
}

.member-card.acting .name-line > span:last-child {
  color: #1d1200;
}

.member-card.acting .member-job-symbol {
  border-color: rgba(29, 18, 0, 0.72);
  color: #1d1200;
  background: rgba(255, 255, 255, 0.32);
  text-shadow: none;
}

.member-card.hit-shake,
.enemy-card.hit-shake {
  animation: hit-shake 320ms steps(2, end);
}

.attack-impact {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: calc(50% - var(--impact-offset, 0px));
  width: 64px;
  height: 64px;
  pointer-events: none;
  transform: translate(-50%, -50%);
}

.attack-impact-slash {
  animation: slash-impact 920ms ease-out forwards;
}

.attack-impact-slash::before,
.attack-impact-slash::after {
  content: "";
  position: absolute;
  left: 5px;
  top: 28px;
  width: 54px;
  height: 8px;
  border-radius: 999px;
  background: linear-gradient(90deg, transparent, #ffffff 18%, #fff0a8 58%, transparent);
  box-shadow:
    0 0 8px rgba(255, 255, 255, 0.82),
    0 0 14px rgba(121, 226, 255, 0.56);
  transform: rotate(-34deg);
}

.attack-impact-slash::after {
  left: 18px;
  top: 34px;
  width: 35px;
  height: 4px;
  opacity: 0.68;
  transform: rotate(-34deg);
}

.attack-impact-fire {
  animation: fire-impact 920ms ease-out forwards;
}

.attack-impact-fire::before,
.attack-impact-fire::after {
  content: "";
  position: absolute;
  left: 14px;
  top: 8px;
  width: 36px;
  height: 48px;
  border-radius: 50% 50% 42% 42%;
  background:
    radial-gradient(circle at 50% 68%, #fff7a8 0 18%, #ffb02e 19% 38%, transparent 39%),
    radial-gradient(circle at 44% 40%, #ffef7a 0 16%, #ff7124 17% 48%, #9b1b16 49% 70%, transparent 71%);
  clip-path: polygon(50% 0, 68% 25%, 86% 45%, 75% 100%, 50% 88%, 25% 100%, 14% 45%, 32% 25%);
  filter:
    drop-shadow(0 0 6px rgba(255, 138, 38, 0.85))
    drop-shadow(0 0 10px rgba(255, 48, 32, 0.46));
}

.attack-impact-fire::after {
  left: 23px;
  top: 24px;
  width: 18px;
  height: 26px;
  background: radial-gradient(circle at 50% 64%, #fff8c8 0 30%, #ffe06c 31% 58%, transparent 59%);
  opacity: 0.88;
}

.damage-popup {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: calc(-12px - var(--damage-offset, 0px));
  color: #ffef7a;
  font-size: 24px;
  font-weight: 700;
  line-height: 1;
  pointer-events: none;
  text-shadow:
    2px 2px 0 #6a120d,
    -2px 2px 0 #6a120d,
    2px -2px 0 #6a120d,
    -2px -2px 0 #6a120d;
  animation: damage-popup 2s ease-out forwards;
}

@keyframes hit-shake {
  0% { transform: translateX(0); }
  20% { transform: translateX(-6px); }
  40% { transform: translateX(6px); }
  60% { transform: translateX(-4px); }
  80% { transform: translateX(4px); }
  100% { transform: translateX(0); }
}

@keyframes enemy-acting-pulse {
  0% {
    filter: brightness(1);
  }
  100% {
    filter: brightness(1.18);
  }
}

@keyframes slash-impact {
  0% {
    opacity: 0;
    transform: translate(-62%, -38%) rotate(-12deg) scale(0.45);
  }
  12% {
    opacity: 1;
    transform: translate(-50%, -50%) rotate(0deg) scale(1.08);
  }
  62% {
    opacity: 0.88;
    transform: translate(-43%, -57%) rotate(6deg) scale(1.14);
  }
  100% {
    opacity: 0;
    transform: translate(-36%, -64%) rotate(12deg) scale(1.2);
  }
}

@keyframes fire-impact {
  0% {
    opacity: 0;
    transform: translate(-50%, -38%) scale(0.42);
  }
  12% {
    opacity: 1;
    transform: translate(-50%, -50%) scale(1.08);
  }
  64% {
    opacity: 0.9;
    transform: translate(-50%, -58%) scale(0.94);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -68%) scale(0.72);
  }
}

@keyframes substitute-member-out {
  0% {
    opacity: 1;
    filter: brightness(0.88);
    transform: translateX(0);
  }
  24% {
    opacity: 1;
    filter: brightness(0.45);
    transform: translateX(0);
  }
  100% {
    opacity: 0;
    filter: brightness(0.22);
    transform: translateX(-46px);
  }
}

@keyframes substitute-member-in {
  0% {
    opacity: 0;
    transform: translateX(42px);
  }
  26% {
    opacity: 0;
    transform: translateX(42px);
  }
  100% {
    opacity: 1;
    transform: translateX(0);
  }
}

@keyframes damage-popup {
  0% {
    opacity: 0;
    transform: translate(-50%, 10px) scale(0.8);
  }
  12% {
    opacity: 1;
    transform: translate(-50%, 0) scale(1.12);
  }
  72% {
    opacity: 1;
    transform: translate(-50%, -18px) scale(1);
  }
  100% {
    opacity: 0;
    transform: translate(-50%, -28px) scale(0.95);
  }
}

.name-line {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  font-weight: 700;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.76);
}

.name-with-icon {
  display: inline-flex;
  align-items: center;
  min-width: 0;
  gap: 8px;
}

.member-card .name-line > span:last-child {
  flex: 0 0 auto;
  color: var(--gold);
  font-size: 12px;
  white-space: nowrap;
}

.member-meta {
  display: inline-flex;
  align-items: center;
  gap: 6px;
}

.member-job-symbol {
  min-width: 20px;
  height: 20px;
  display: inline-grid;
  place-items: center;
  border: 2px solid var(--gold);
  color: var(--gold);
  background: rgba(5, 9, 46, 0.72);
  font-size: 13px;
  line-height: 1;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.78);
}

.pixel-icon {
  width: 48px;
  height: 48px;
  flex: 0 0 auto;
  image-rendering: pixelated;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.7));
}

.member-sprite-wrap {
  position: relative;
  min-width: 56px;
  min-height: 56px;
  display: inline-grid;
  place-items: center;
  flex: 0 0 auto;
  overflow: visible;
}

.member-sprite-wrap .pixel-icon,
.member-sprite-wrap .character-portrait {
  grid-area: 1 / 1;
}

.tactic-buff-markers {
  position: absolute;
  z-index: 5;
  left: 50%;
  top: -7px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 1px;
  transform: translateX(-50%);
  pointer-events: auto;
}

.tactic-buff-marker {
  width: 10px;
  height: 10px;
  display: grid;
  place-items: center;
  border: 1px solid rgba(0, 0, 0, 0.82);
  background: rgba(3, 6, 23, 0.72);
  font-size: 11px;
  font-weight: 900;
  line-height: 1;
  text-shadow:
    1px 1px 0 #000,
    -1px 1px 0 #000,
    1px -1px 0 #000,
    -1px -1px 0 #000;
}

.tactic-buff-atk {
  color: #ff5c68;
}

.tactic-buff-pDef {
  color: #62a8ff;
}

.tactic-buff-mDef {
  color: #c37bff;
}

.tactic-buff-agi {
  color: #59e686;
}

.hero-sprite {
  width: 48px;
  height: 72px;
}

.character-portrait {
  width: 56px;
  height: 56px;
  flex: 0 0 auto;
  object-fit: contain;
  image-rendering: auto;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.7));
}

.monster-portrait {
  width: 52px;
  height: 52px;
  flex: 0 0 auto;
  object-fit: contain;
  image-rendering: auto;
  filter: drop-shadow(2px 2px 0 rgba(0, 0, 0, 0.7));
}

.monster-portrait-boss {
  width: 78px;
  height: 78px;
}

.status-table .hero-sprite,
.formation-table .hero-sprite,
.status-table .character-portrait,
.formation-table .character-portrait {
  width: 32px;
  height: 48px;
}

.status-table .member-sprite-wrap,
.formation-table .member-sprite-wrap {
  min-width: 36px;
  min-height: 48px;
}

.monster-sprite {
  width: 40px;
  height: 40px;
}

.stat-line {
  margin-top: 4px;
  color: var(--ink);
  font-size: 13px;
  line-height: 1.32;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.72);
}

.status-badges {
  margin-top: 6px;
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  min-height: 18px;
  padding: 0 5px;
  border: 2px solid rgba(248, 247, 255, 0.78);
  background: rgba(3, 6, 23, 0.58);
  color: var(--ink);
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.82);
}

.status-poison,
.status-venom {
  border-color: #9cff7c;
  color: #d8ffcf;
}

.status-paralysis {
  border-color: #ffe26e;
  color: #fff0a8;
}

.status-stun {
  border-color: #79e2ff;
  color: #d7f8ff;
}

.status-sleep {
  border-color: #d7a8ff;
  color: #efe0ff;
}

.status-cover {
  border-color: #fff0a8;
  color: #fff6c8;
  background: rgba(74, 59, 18, 0.74);
}

.status-cover::before {
  content: "盾";
  margin-right: 3px;
  color: #fff0a8;
}

.status-tactics {
  border-color: #9ff0ff;
  color: #dcfbff;
  background: rgba(22, 68, 82, 0.74);
}

.member-card-body {
  margin-top: 5px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 6px;
  align-items: center;
}

.member-stats .stat-line {
  margin-top: 0;
}

.member-stats .stat-line + .stat-line {
  margin-top: 2px;
}

.bar {
  height: 8px;
  margin-top: 4px;
  border: 2px solid var(--line);
  border-radius: 0;
  background: #05092e;
  overflow: hidden;
}

.bar > span {
  display: block;
  height: 100%;
  width: 100%;
  background: #7cff9a;
}

.bar.mp > span {
  background: #79e2ff;
}

.battle-panel {
  grid-column: 1 / -1;
  min-height: 320px;
}

.gold {
  color: var(--gold);
  font-weight: 700;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.8);
}

.enemy-area {
  min-height: 112px;
  margin-top: 10px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 8px;
}

.town-card {
  grid-column: 1 / -1;
}

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

.building-card {
  min-height: 0;
}

.building-card .shop-buyers {
  grid-template-columns: 1fr;
}

.commander-window {
  display: grid;
  grid-template-columns: 82px minmax(0, 1fr);
  gap: 10px;
  align-items: center;
  min-height: 98px;
}

.commander-portrait-frame {
  width: 82px;
  height: 82px;
  border: 3px solid var(--line);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.14), transparent 22px),
    #070d3f;
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.18),
    inset -2px -2px 0 rgba(0, 0, 0, 0.48);
  overflow: hidden;
}

.commander-portrait {
  width: 100%;
  height: 100%;
  display: block;
  object-fit: cover;
  object-position: 50% 18%;
}

.commander-dialogue {
  min-width: 0;
}

.commander-dialogue p {
  margin: 5px 0 0;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.45;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.72);
}

.enemy-formation {
  grid-column: 1 / -1;
  display: grid;
  gap: 12px;
}

.enemy-row-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 10px;
}

.command-area {
  min-height: 40px;
  margin-top: 10px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.command-area button {
  min-width: 116px;
}

.dungeon-quick-actions {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px 36px;
  padding: 4px;
  border: 3px solid var(--line-soft);
  background: rgba(5, 9, 46, 0.5);
}

.dungeon-primary-actions {
  display: inline-flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
}

.dungeon-quick-actions button {
  min-width: 132px;
}

.dungeon-return-action {
  margin-left: auto;
}

.dungeon-quick-actions span {
  color: var(--muted-ink);
  font-size: 12px;
  white-space: nowrap;
}

.dungeon-choice-actions .dungeon-primary-actions button {
  min-width: 104px;
}

.exploration-standby-card {
  display: grid;
  gap: 4px;
}

.dungeon-map {
  --node-size: 42px;
  margin-top: -2px;
  display: grid;
  grid-template-columns: repeat(var(--floor-count), minmax(38px, 1fr));
  grid-auto-rows: minmax(22px, auto);
  gap: 3px;
  align-items: center;
  overflow-x: auto;
  overflow-y: visible;
  padding: 18px 2px 2px;
}

.dungeon-map-floor {
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  line-height: 1;
  text-align: center;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.76);
}

.dungeon-map-spacer,
.dungeon-map-connector {
  position: relative;
  min-height: var(--node-size);
  display: grid;
  place-items: center;
}

.dungeon-map-connector::before {
  content: "";
  width: 0;
}

.dungeon-map-node {
  position: relative;
  z-index: 1;
  width: 100%;
  min-width: 0;
  min-height: var(--node-size);
  display: grid;
  place-items: center;
  gap: 1px;
  padding: 2px;
  border: 2px solid var(--line-soft);
  background: rgba(5, 9, 46, 0.72);
  color: var(--ink);
  line-height: 1;
  text-align: center;
  text-shadow: 1px 1px 0 rgba(0, 0, 0, 0.82);
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.16),
    inset -1px -1px 0 rgba(0, 0, 0, 0.45);
}

.dungeon-map-node.linked::after {
  content: "";
  position: absolute;
  z-index: 0;
  left: calc(50% + 12px);
  right: -9px;
  top: 50%;
  border-top: 2px solid rgba(248, 247, 255, 0.66);
  transform: translateY(-50%);
}

button.dungeon-map-node {
  min-width: 0;
  min-height: var(--node-size);
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.16),
    inset -1px -1px 0 rgba(0, 0, 0, 0.45);
}

button.dungeon-map-node:hover:not(:disabled)::before,
button.dungeon-map-node:focus-visible:not(:disabled)::before {
  content: none;
}

.dungeon-map-node span {
  position: relative;
  z-index: 1;
  font-size: 14px;
  font-weight: 700;
}

.dungeon-map-node small {
  position: relative;
  z-index: 1;
  color: rgba(248, 247, 255, 0.82);
  font-size: 9px;
}

.dungeon-map-node.has-commander span,
.dungeon-map-node.has-node-marker span,
.dungeon-map-node.has-boss-marker span {
  margin-top: 10px;
}

.dungeon-commander-marker {
  position: absolute;
  z-index: 4;
  left: 50%;
  top: -23px;
  width: 38px;
  height: 38px;
  object-fit: contain;
  pointer-events: none;
  transform: translateX(-50%);
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.76));
}

.dungeon-node-marker {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: -23px;
  width: 38px;
  height: 38px;
  object-fit: contain;
  pointer-events: none;
  transform: translateX(-50%);
  filter: drop-shadow(0 2px 0 rgba(0, 0, 0, 0.76));
}

.node-marker-strong {
  top: -25px;
  width: 40px;
  height: 40px;
}

.node-marker-enemy {
  top: -24px;
  width: 39px;
  height: 39px;
}

.node-marker-chest {
  top: -21px;
  width: 36px;
  height: 36px;
}

.dungeon-boss-marker {
  position: absolute;
  z-index: 3;
  left: 50%;
  top: -25px;
  width: 42px;
  height: 42px;
  object-fit: contain;
  pointer-events: none;
  transform: translateX(-50%);
  filter:
    drop-shadow(0 2px 0 rgba(0, 0, 0, 0.82))
    drop-shadow(0 0 5px rgba(255, 55, 75, 0.42));
}

.dungeon-map-node.has-commander.has-node-marker .dungeon-commander-marker,
.dungeon-map-node.has-commander.has-boss-marker .dungeon-commander-marker {
  left: 27%;
  top: -21px;
  width: 32px;
  height: 32px;
}

.dungeon-map-node.has-commander.has-node-marker .dungeon-node-marker,
.dungeon-map-node.has-commander.has-boss-marker .dungeon-boss-marker {
  left: 68%;
}

.dungeon-map-node.current {
  outline: 2px solid var(--gold);
  outline-offset: 1px;
}

.dungeon-map-node.passed {
  opacity: 0.48;
}

.dungeon-map-node.chosen {
  opacity: 1;
  border-color: var(--gold);
}

.dungeon-map-node.locked-route {
  border-color: var(--gold);
  box-shadow:
    inset 1px 1px 0 rgba(255, 255, 255, 0.16),
    inset -1px -1px 0 rgba(0, 0, 0, 0.45),
    0 0 0 1px rgba(255, 240, 168, 0.72);
}

.dungeon-map-node.locked-out {
  opacity: 0.36;
  filter: grayscale(0.42);
}

.node-mob {
  border-color: #ffdf7e;
  background: linear-gradient(180deg, rgba(132, 91, 24, 0.86), rgba(73, 42, 13, 0.86));
}

.node-strong {
  border-color: #ff8d9d;
  background: linear-gradient(180deg, rgba(142, 31, 56, 0.9), rgba(78, 9, 26, 0.9));
}

.node-empty {
  border-color: #8fd7ff;
  background: linear-gradient(180deg, rgba(21, 72, 94, 0.82), rgba(8, 38, 54, 0.86));
}

.node-start {
  border-color: #c7f7a0;
  background: linear-gradient(180deg, rgba(34, 92, 48, 0.86), rgba(10, 46, 31, 0.9));
}

.node-chest {
  border-color: #ffe38a;
  background: linear-gradient(180deg, rgba(111, 78, 25, 0.9), rgba(43, 67, 35, 0.9));
}

.node-enemy {
  border-color: #f8f7ff;
  background: linear-gradient(180deg, rgba(82, 88, 138, 0.88), rgba(28, 33, 76, 0.9));
}

.shop-buyers,
.enemy-actions,
.member-actions {
  margin-top: 10px;
  display: grid;
  gap: 8px;
}

.shop-buyers,
.member-actions {
  grid-template-columns: 1fr 1fr;
}

.member-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
  height: 28px;
  min-height: 0;
  gap: 4px;
  margin-top: 0;
}

.member-actions.empty-actions {
  visibility: hidden;
}

.enemy-actions {
  grid-template-columns: repeat(auto-fit, minmax(64px, 1fr));
}

.shop-buyers button,
.enemy-actions button {
  min-height: 34px;
  font-size: 13px;
}

.member-actions button {
  height: 28px;
  min-height: 0;
  padding: 0 6px;
  font-size: 12px;
  line-height: 1;
  white-space: nowrap;
}

.party-grid .member-card {
  min-height: 104px;
  padding: 8px;
}

.party-grid .name-line,
.party-grid .name-with-icon {
  gap: 8px;
}

.party-grid .character-portrait {
  width: 64px;
  height: 64px;
}

.party-grid .member-sprite-wrap {
  min-width: 64px;
  min-height: 64px;
}

.party-grid .member-job-symbol {
  min-width: 20px;
  height: 20px;
  font-size: 13px;
}

.party-grid .member-card .name-line > span:last-child {
  font-size: 12px;
}

.party-grid .member-card-body {
  margin-top: 8px;
  grid-template-columns: minmax(0, 1fr) 92px;
  gap: 8px;
}

.party-grid .stat-line {
  font-size: 13px;
  line-height: 1.4;
}

.party-grid .member-stats .stat-line + .stat-line {
  margin-top: 4px;
}

.party-grid .member-actions {
  height: 28px;
}

.party-grid .member-actions button {
  height: 28px;
  padding: 0 6px;
  font-size: 12px;
}

.log {
  height: 150px;
  margin-top: 14px;
  padding: 12px;
  overflow: auto;
  border: 4px solid var(--line);
  border-radius: 0;
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.08), transparent 18px),
    linear-gradient(180deg, #16228b, #0a1255);
  box-shadow:
    inset 3px 3px 0 rgba(255, 255, 255, 0.12),
    inset -3px -3px 0 rgba(0, 0, 0, 0.42);
  color: var(--ink);
  line-height: 1.6;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.74);
}

.log p {
  margin: 0 0 4px;
}

.log p.tower-clear-log {
  margin-bottom: 8px;
  padding: 6px 8px;
  border: 2px solid rgba(255, 240, 168, 0.82);
  color: var(--gold);
  background:
    linear-gradient(90deg, rgba(255, 240, 168, 0.2), rgba(121, 226, 255, 0.08)),
    rgba(5, 9, 46, 0.72);
  font-weight: 700;
}

.status-dialog {
  width: min(1120px, calc(100% - 28px));
  max-height: min(760px, calc(100vh - 28px));
  color: var(--ink);
}

.status-dialog::backdrop {
  background: rgba(0, 0, 0, 0.74);
}

.formation-dialog {
  width: min(1440px, calc(100% - 12px));
  max-height: min(900px, calc(100vh - 20px));
}

.items-dialog {
  width: min(1120px, calc(100% - 20px));
  max-height: min(820px, calc(100vh - 20px));
}

.shop-dialog {
  width: min(1440px, calc(100% - 12px));
  height: min(900px, calc(100vh - 20px));
  max-height: min(900px, calc(100vh - 20px));
}

.help-dialog {
  width: min(980px, calc(100% - 20px));
}

.shop-dialog[open] {
  display: flex;
  flex-direction: column;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
}

.shop-dialog-actions {
  display: flex;
  align-items: center;
  gap: 12px;
}

.status-content {
  overflow: auto;
}

.help-content {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 12px;
  overflow: auto;
}

.help-section {
  padding: 12px;
  border: 3px solid var(--line-soft);
  background: rgba(5, 9, 46, 0.36);
}

.help-section h3 {
  margin: 0 0 8px;
  color: var(--gold);
  font-size: 15px;
  line-height: 1.2;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.72);
}

.help-section p,
.help-section ol,
.help-section ul {
  margin: 0;
  padding-left: 18px;
  color: var(--ink);
  font-size: 14px;
  line-height: 1.65;
  text-shadow: 2px 2px 0 rgba(0, 0, 0, 0.72);
}

.help-section p {
  padding-left: 0;
}

.help-section li + li {
  margin-top: 4px;
}

.items-content {
  display: grid;
  grid-template-columns: 220px minmax(0, 1fr);
  gap: 12px;
  align-items: start;
}

.item-list-panel,
.item-target-panel {
  display: grid;
  gap: 10px;
}

.item-list {
  display: grid;
  gap: 8px;
}

.item-select {
  min-height: 40px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 0 10px;
}

.item-select.selected {
  color: var(--gold);
  border-color: var(--gold);
}

.item-target-panel {
  min-width: 0;
  overflow: auto;
}

.item-target-table {
  width: 100%;
  min-width: 620px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 12px;
}

.item-target-table th,
.item-target-table td {
  padding: 2px 4px;
  border-bottom: 2px solid rgba(248, 247, 255, 0.5);
  text-align: left;
  vertical-align: middle;
  line-height: 1;
}

.item-target-table th {
  color: var(--gold);
}

.job-symbol-cell {
  color: var(--gold);
  font-weight: 700;
  text-align: center;
}

.item-target-table th:nth-child(2),
.item-target-table td:nth-child(2) {
  width: 42px;
  text-align: center;
}

.item-target-table td:last-child,
.item-target-table th:last-child {
  width: 82px;
}

.item-target-table button {
  width: 100%;
  min-height: 18px;
  padding: 0 4px;
  font-size: 11px;
}

.shop-content {
  flex: 1 1 auto;
  min-height: 0;
  overflow: auto;
}

.shop-bulk-actions {
  position: sticky;
  top: 0;
  z-index: 3;
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 8px;
  padding: 0 0 10px;
  background: #111a82;
}

.shop-bulk-actions button {
  min-height: 34px;
  padding: 0 10px;
  font-size: 13px;
}

.shop-table {
  width: 100%;
  min-width: 920px;
  border-collapse: collapse;
  table-layout: fixed;
  font-size: 13px;
}

.shop-table th,
.shop-table td,
.status-table th,
.status-table td,
.formation-table th,
.formation-table td {
  border-bottom: 2px solid rgba(248, 247, 255, 0.5);
  text-align: left;
  vertical-align: middle;
}

.shop-table th,
.shop-table td {
  padding: 5px 6px;
  white-space: nowrap;
}

.shop-table th {
  position: sticky;
  top: 44px;
  z-index: 2;
  color: var(--gold);
  background: #111a82;
}

.shop-table tbody tr,
.status-table tr,
.formation-table tr {
  background: rgba(5, 9, 46, 0.28);
}

.shop-table tbody tr:hover,
.status-table tbody tr:hover,
.formation-table tbody tr:hover {
  background: rgba(255, 255, 255, 0.1);
}

.shop-table button {
  width: 100%;
  min-height: 28px;
  padding: 0 6px;
  font-size: 12px;
}

.shop-table th:nth-child(1),
.shop-table td:nth-child(1) {
  width: 92px;
}

.shop-table th:nth-child(2),
.shop-table td:nth-child(2) {
  width: 72px;
}

.shop-table th:nth-child(3),
.shop-table td:nth-child(3) {
  width: 42px;
}

.shop-table th:nth-child(4),
.shop-table td:nth-child(4),
.shop-table th:nth-child(5),
.shop-table td:nth-child(5) {
  width: 120px;
}

.shop-table th:nth-child(6),
.shop-table td:nth-child(6),
.shop-table th:nth-child(7),
.shop-table td:nth-child(7),
.shop-table th:nth-child(8),
.shop-table td:nth-child(8) {
  width: 54px;
}

.shop-table th:nth-child(9),
.shop-table td:nth-child(9),
.shop-table th:nth-child(10),
.shop-table td:nth-child(10) {
  width: 108px;
}

.status-table {
  width: max-content;
  min-width: 880px;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}

.status-table th,
.status-table td {
  padding: 7px 6px;
}

.status-table th {
  color: var(--gold);
  font-weight: 700;
}

.status-table th:nth-child(1),
.status-table td:nth-child(1) {
  width: 96px;
}

.status-table th:nth-child(2),
.status-table td:nth-child(2),
.status-table th:nth-child(4),
.status-table td:nth-child(4),
.status-table th:nth-child(5),
.status-table td:nth-child(5),
.status-table th:nth-child(11),
.status-table td:nth-child(11) {
  width: 72px;
}

.status-table th:nth-child(3),
.status-table td:nth-child(3),
.status-table th:nth-child(6),
.status-table td:nth-child(6),
.status-table th:nth-child(7),
.status-table td:nth-child(7),
.status-table th:nth-child(8),
.status-table td:nth-child(8),
.status-table th:nth-child(9),
.status-table td:nth-child(9),
.status-table th:nth-child(10),
.status-table td:nth-child(10) {
  width: 54px;
}

.status-table th:nth-child(12),
.status-table td:nth-child(12),
.status-table th:nth-child(13),
.status-table td:nth-child(13) {
  width: 54px;
}

.status-table th:nth-child(14),
.status-table td:nth-child(14) {
  width: 54px;
}

.status-table th:nth-child(15),
.status-table td:nth-child(15) {
  width: 86px;
}

.status-table th:nth-child(6),
.status-table td:nth-child(6) {
  width: 74px;
}

.formation-content {
  display: grid;
  grid-template-columns: minmax(520px, 1fr) minmax(620px, 1.2fr);
  gap: 12px;
  align-items: start;
}

.formation-party-panel {
  display: grid;
  gap: 10px;
}

.formation-panel-title {
  font-size: 14px;
}

.formation-drop-row {
  padding: 10px;
  border: 3px solid var(--line-soft);
  background: rgba(5, 9, 46, 0.36);
}

.formation-drop-row.drag-over,
.formation-zone.drag-over {
  border-color: var(--gold);
  background: rgba(255, 240, 168, 0.12);
}

.member-card.drag-over {
  border-color: var(--gold);
  box-shadow:
    inset 2px 2px 0 rgba(255, 255, 255, 0.18),
    inset -2px -2px 0 rgba(0, 0, 0, 0.45),
    0 0 0 3px rgba(255, 240, 168, 0.3);
}

.formation-card-actions {
  margin-top: 8px;
  display: flex;
  justify-content: flex-end;
}

.formation-card-actions button {
  min-height: 28px;
  min-width: 76px;
  padding: 0 8px;
  font-size: 12px;
}

.formation-zone {
  min-height: 180px;
  padding: 10px;
  border: 3px solid var(--line-soft);
  background: rgba(5, 9, 46, 0.36);
  overflow-x: auto;
}

.bench-drop-target {
  margin-bottom: 8px;
  padding: 8px 10px;
  border: 3px dashed var(--line-soft);
  color: var(--muted-ink);
  background: rgba(5, 9, 46, 0.42);
  font-size: 12px;
  text-align: center;
}

.bench-drop-target.drag-over {
  border-color: var(--gold);
  color: var(--gold);
  background: rgba(255, 240, 168, 0.12);
}

.formation-zone-title {
  margin-bottom: 10px;
  font-size: 14px;
}

.formation-table {
  width: 100%;
  min-width: 720px;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
}

.formation-table th,
.formation-table td {
  padding: 8px 6px;
}

.bench-zone .formation-zone-title {
  margin-bottom: 6px;
}

.bench-zone .formation-table {
  font-size: 12px;
  min-width: 650px;
}

.bench-zone .formation-table th,
.bench-zone .formation-table td {
  padding: 3px 6px;
  line-height: 1.2;
}

.formation-table th {
  color: var(--gold);
  font-weight: 700;
}

.formation-table tr {
  cursor: grab;
}

.formation-table tr.in-party {
  background: rgba(255, 240, 168, 0.12);
}

.formation-table tr.bench-back-row {
  background: rgba(18, 94, 74, 0.52);
}

.formation-table tr.bench-back-row:hover {
  background: rgba(30, 126, 96, 0.64);
}

.formation-table tr.bench-both-row {
  background: rgba(84, 74, 178, 0.5);
}

.formation-table tr.bench-both-row:hover {
  background: rgba(108, 96, 214, 0.62);
}

.formation-table tr.bench-ap-empty {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.68) 0 50%, rgba(5, 9, 46, 0.28) 50% 100%);
  color: rgba(248, 247, 255, 0.72);
}

.formation-table tr.bench-hp-empty {
  background: #03040d;
  color: rgba(248, 247, 255, 0.42);
}

.formation-table tr.bench-ap-empty:hover {
  background:
    linear-gradient(90deg, rgba(0, 0, 0, 0.78) 0 50%, rgba(255, 255, 255, 0.08) 50% 100%);
}

.formation-table tr.bench-hp-empty:hover {
  background: #080914;
}

.formation-table tr:active {
  cursor: grabbing;
}

.formation-table tr.drag-over {
  background: rgba(255, 240, 168, 0.18);
  box-shadow: inset 0 0 0 3px var(--gold);
}

.formation-table th:nth-child(1),
.formation-table td:nth-child(1) {
  width: 18%;
}

.formation-table th:nth-child(2),
.formation-table td:nth-child(2) {
  width: 5%;
}

.formation-job-symbol {
  color: var(--gold);
  font-weight: 700;
  text-align: center;
}

.formation-table th:nth-child(3),
.formation-table td:nth-child(3),
.formation-table th:nth-child(4),
.formation-table td:nth-child(4) {
  width: 9%;
}

.formation-table th:nth-child(5),
.formation-table td:nth-child(5),
.formation-table th:nth-child(6),
.formation-table td:nth-child(6),
.formation-table th:nth-child(7),
.formation-table td:nth-child(7),
.formation-table th:nth-child(8),
.formation-table td:nth-child(8),
.formation-table th:nth-child(9),
.formation-table td:nth-child(9),
.formation-table th:nth-child(10),
.formation-table td:nth-child(10),
.formation-table th:nth-child(11),
.formation-table td:nth-child(11) {
  width: 7%;
}

.empty-table-cell {
  height: 48px;
  color: var(--muted-ink);
  text-align: center;
}

@media (max-width: 1160px) {
  .formation-content {
    grid-template-columns: 1fr;
  }
}

@media (max-width: 760px) {
  .game-shell {
    grid-template-columns: 1fr;
  }

  .party-row-grid,
  .enemy-area {
    grid-template-columns: 1fr 1fr;
  }

  .formation-content {
    grid-template-columns: 1fr;
  }

  .items-content {
    grid-template-columns: 1fr;
  }

  .help-content {
    grid-template-columns: 1fr;
  }

  .battle-panel {
    grid-column: auto;
  }
}

@media (max-width: 520px) {
  .party-row-grid,
  .enemy-area,
  .building-grid,
  .travel-actions,
  .formation-content {
    grid-template-columns: 1fr;
  }

  .commander-window {
    grid-template-columns: 72px minmax(0, 1fr);
  }

  .commander-portrait-frame {
    width: 72px;
    height: 72px;
  }
}
