:root {
  --ink: #161b2e;
  --muted: #6d768d;
  --panel: #f3dfb1;
  --panel-strong: #ffd86b;
  --field: #202941;
  --field-soft: #303c5f;
  --gold: #f6c453;
  --green: #4fd18b;
  --red: #ff5f6d;
  --blue: #4aa8ff;
  --yellow: #ffd45a;
  --violet: #9c78ff;
  --line: #202033;
  --shadow: 8px 8px 0 rgba(22, 27, 46, 0.22);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  font-family: "Microsoft JhengHei", "Noto Sans TC", system-ui, sans-serif;
  background:
    linear-gradient(180deg, rgba(22, 27, 46, 0.82), rgba(22, 27, 46, 0.58)),
    repeating-linear-gradient(0deg, #273250 0 16px, #202941 16px 32px);
}

button {
  font: inherit;
}

.app {
  width: min(1440px, 100%);
  margin: 0 auto;
  padding: 18px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 16px 18px;
  border: 4px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.eyebrow {
  margin: 0 0 4px;
  color: #8a5417;
  font-size: 13px;
  font-weight: 900;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1,
h2 {
  margin: 0;
  letter-spacing: 0;
}

h1 {
  font-size: clamp(24px, 3vw, 40px);
  text-shadow: 2px 2px 0 #fff3c7;
}

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

.status-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(110px, 1fr));
  gap: 10px;
  min-width: min(540px, 100%);
}

.status-grid div {
  padding: 10px 12px;
  border: 3px solid var(--line);
  border-radius: 2px;
  background: #fff2c2;
  box-shadow: inset 0 -4px 0 #d0a64c;
}

.status-grid span {
  display: block;
  color: var(--muted);
  font-size: 12px;
  font-weight: 900;
}

.status-grid strong {
  display: block;
  margin-top: 2px;
  font-size: 16px;
  line-height: 1.25;
}

.layout {
  display: grid;
  grid-template-columns: 310px 1fr;
  gap: 18px;
  margin-top: 18px;
}

.panel,
.play-area {
  border: 4px solid var(--line);
  border-radius: 2px;
  background: var(--panel);
  box-shadow: var(--shadow);
}

.panel {
  padding: 14px;
}

.stage-list,
.unit-list {
  display: grid;
  gap: 8px;
}

.stage-card,
.unit-card {
  width: 100%;
  padding: 10px;
  border: 3px solid var(--line);
  border-radius: 2px;
  color: var(--ink);
  text-align: left;
  background: #fff2c2;
  box-shadow: inset 0 -4px 0 #c79e49;
}

.stage-card {
  cursor: pointer;
}

.stage-card.active {
  border-color: #0f1426;
  background: var(--panel-strong);
}

.stage-card:disabled,
.unit-card.locked {
  color: #747474;
  background: #b9b0a0;
  box-shadow: inset 0 -4px 0 #8d8373;
}

.stage-card strong,
.unit-card strong {
  display: block;
  font-size: 15px;
}

.stage-card span,
.unit-card span {
  display: block;
  margin-top: 2px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.35;
}

.unit-card {
  display: grid;
  grid-template-columns: 36px 1fr;
  gap: 8px;
  align-items: center;
}

.unit-icon {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border: 3px solid var(--line);
  border-radius: 2px;
  background: #fff2c2;
  font-weight: 900;
  box-shadow: inset 0 -4px 0 rgba(0, 0, 0, 0.18);
}

.unit-icon img {
  width: 30px;
  height: 30px;
  object-fit: contain;
  image-rendering: pixelated;
}

.primary-button,
.ghost-button,
.danger-button {
  width: 100%;
  min-height: 44px;
  margin-top: 12px;
  border: 4px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
  font-weight: 900;
  box-shadow: 4px 4px 0 rgba(22, 27, 46, 0.24);
}

.primary-button {
  color: #161b2e;
  background: var(--gold);
}

.ghost-button {
  color: var(--ink);
  background: #fff2c2;
}

.danger-button {
  color: #fff8d8;
  background: #bf3f3f;
}

.play-area {
  position: relative;
  overflow: hidden;
  min-height: 680px;
}

canvas {
  display: block;
  width: 100%;
  height: auto;
  background: var(--field);
  image-rendering: pixelated;
}

.hud {
  padding: 12px;
  border-top: 4px solid var(--line);
  background: #2a314a;
}

.story-text {
  min-height: 44px;
  padding: 10px 12px;
  border: 3px solid var(--line);
  border-radius: 2px;
  background: #fff2c2;
  font-weight: 900;
  line-height: 1.45;
  box-shadow: inset 0 -4px 0 #c79e49;
}

.unit-buttons {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 10px;
  margin-top: 10px;
}

.summon-button {
  display: grid;
  grid-template-rows: 34px auto auto;
  place-items: center;
  gap: 3px;
  min-height: 76px;
  padding: 8px;
  border: 4px solid var(--line);
  border-radius: 2px;
  cursor: pointer;
  background: #fff2c2;
  color: var(--ink);
  font-weight: 900;
  box-shadow: inset 0 -5px 0 #c79e49;
}

.summon-icon {
  width: 34px;
  height: 34px;
  object-fit: contain;
  image-rendering: pixelated;
}

.summon-button strong {
  display: block;
  max-width: 100%;
  overflow-wrap: anywhere;
  font-size: 13px;
  line-height: 1.1;
}

.summon-button:disabled {
  cursor: default;
  color: #70737c;
  background: #aeb0b8;
  box-shadow: inset 0 -5px 0 #777a85;
}

.summon-button span {
  display: block;
  margin-top: 4px;
  font-size: 12px;
  font-weight: 900;
}

.result-overlay {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  background: rgba(22, 27, 46, 0.62);
}

.result-overlay.hidden {
  display: none;
}

.result-box {
  width: min(420px, calc(100% - 32px));
  padding: 22px;
  border: 4px solid var(--line);
  border-radius: 2px;
  background: #fff2c2;
  box-shadow: var(--shadow);
  text-align: center;
}

.result-box p:not(.eyebrow) {
  color: var(--muted);
  line-height: 1.5;
}

@media (max-width: 980px) {
  .topbar,
  .layout {
    grid-template-columns: 1fr;
  }

  .topbar {
    display: grid;
  }

  .status-grid {
    grid-template-columns: 1fr;
    min-width: 0;
  }

  .unit-buttons {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}
