:root {
  --bg: #061011;
  --panel: #0d1718;
  --panel-2: #132022;
  --line: #5e7470;
  --gold: #d8b35f;
  --ember: #d0603d;
  --blood: #b33a34;
  --text: #efe7d2;
  --muted: #aeb8b1;
  --green: #73b56b;
  --blue: #76b8d6;
  --violet: #9d7cc5;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
}

body {
  color: var(--text);
  background: #102024;
  font-family: "PingFang TC", "Microsoft JhengHei", "Noto Sans TC", sans-serif;
}

button {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: 4px;
  color: var(--text);
  background: #1a242d;
  font: inherit;
  cursor: pointer;
}

button:hover,
button:focus-visible {
  border-color: var(--gold);
  background: #24323d;
  outline: none;
}

.game-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
  width: 100vw;
  height: 100vh;
  padding: 4px;
  gap: 4px;
  background: var(--bg);
}

.topbar,
.command-panel,
.dungeon-stage,
.encounter-panel {
  border: 1px solid var(--line);
  border-radius: 4px;
  background: var(--panel);
}

.topbar {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
  min-height: 46px;
  padding: 6px 10px;
}

.eyebrow {
  margin: 0 0 4px;
  color: var(--gold);
  font-size: 0.75rem;
  letter-spacing: 0;
}

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

h1 {
  margin-bottom: 0;
  font-size: 1.45rem;
}

h2 {
  margin-bottom: 8px;
  font-size: 1rem;
}

.run-meta {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 8px;
}

.run-meta span {
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 8px;
  color: var(--gold);
  background: #0e1317;
  white-space: nowrap;
}

.settings-button {
  min-height: 32px;
  padding: 5px 10px;
  color: var(--text);
  background: #263841;
}

.play-layout {
  display: grid;
  grid-template-columns: minmax(0, 5fr) 280px;
  gap: 4px;
  min-height: 0;
}

.dungeon-stage {
  position: relative;
  display: grid;
  min-width: 0;
  min-height: 0;
  padding: 3px;
  background: #071011;
}

canvas {
  width: 100%;
  height: 100%;
  display: block;
  border: 1px solid #314149;
  background: #14272c;
  image-rendering: auto;
}

canvas:focus-visible {
  outline: 1px solid var(--gold);
  outline-offset: 2px;
}

.card-choice-overlay {
  position: absolute;
  left: 4%;
  right: 4%;
  top: 10%;
  bottom: 8%;
  z-index: 4;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  gap: 12px;
  border: 2px solid var(--gold);
  border-radius: 4px;
  padding: 18px;
  background: rgba(10, 18, 20, 0.94);
  pointer-events: none;
}

.card-choice-overlay.hidden {
  display: none;
}

.card-choice-title {
  display: grid;
  gap: 5px;
  text-align: center;
}

.card-choice-title strong {
  color: var(--text);
  font-size: clamp(1.4rem, 2.2vw, 2.4rem);
}

.card-choice-title span {
  color: var(--muted);
  font-size: clamp(0.86rem, 1.2vw, 1.1rem);
  line-height: 1.45;
}

.card-choice-list {
  display: grid;
  grid-template-columns: repeat(var(--card-count), minmax(0, 1fr));
  gap: 14px;
  min-height: 0;
  align-items: stretch;
}

.choice-card {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  gap: 10px;
  min-width: 0;
  border: 2px solid #52696b;
  border-radius: 4px;
  padding: 14px;
  background: #18292d;
}

.choice-card.selected {
  border-color: #ffd37a;
  background: #243b40;
  transform: translateY(-8px);
}

.choice-card-index {
  justify-self: center;
  display: grid;
  place-items: center;
  width: 54px;
  height: 54px;
  border: 2px solid currentColor;
  color: var(--gold);
  font-weight: 800;
  font-size: 1.45rem;
}

.choice-card-title {
  color: var(--text);
  font-weight: 800;
  font-size: clamp(1.05rem, 1.45vw, 1.45rem);
  text-align: center;
  line-height: 1.25;
}

.choice-card-effect {
  color: var(--muted);
  font-size: clamp(0.82rem, 1.05vw, 1rem);
  line-height: 1.45;
  text-align: center;
}

.choice-card-state {
  color: #ffd37a;
  font-weight: 700;
  text-align: center;
}

.card-choice-help {
  color: var(--gold);
  font-weight: 800;
  font-size: clamp(0.95rem, 1.2vw, 1.15rem);
  text-align: center;
}

.settings-menu {
  position: fixed;
  inset: 0;
  display: none;
  place-items: center;
  background: #102429;
  z-index: 10;
}

.settings-menu.open {
  display: grid;
}

.settings-dialog {
  width: min(320px, calc(100vw - 32px));
  display: grid;
  gap: 8px;
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 14px;
  background: #16282d;
}

.settings-dialog h2 {
  margin-bottom: 4px;
  color: var(--gold);
}

.command-panel {
  display: grid;
  grid-auto-rows: max-content;
  align-content: start;
  gap: 6px;
  min-height: 0;
  padding: 8px;
  overflow: auto;
  background: #0f1c20;
}

.command-panel section {
  min-width: 0;
}

.encounter-panel {
  display: grid;
  gap: 6px;
  padding: 8px;
  background: var(--panel-2);
}

.encounter-copy p {
  margin-bottom: 0;
  line-height: 1.55;
  white-space: pre-line;
}

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

.stat {
  border: 1px solid #3b4b51;
  border-radius: 4px;
  padding: 7px;
  background: #0d1216;
}

.stat strong {
  display: block;
  color: var(--gold);
  font-size: 0.78rem;
}

.stat small {
  display: block;
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.68rem;
  line-height: 1.25;
  overflow-wrap: anywhere;
}

.key-list {
  display: grid;
  gap: 5px;
  color: var(--muted);
  font-size: 0.84rem;
}

.key-list span {
  display: flex;
  gap: 6px;
  align-items: center;
  min-width: 0;
  overflow-wrap: anywhere;
}

.key-list b {
  min-width: 42px;
  border: 1px solid #3b4b51;
  border-radius: 3px;
  padding: 2px 4px;
  color: var(--gold);
  background: #0d1216;
  text-align: center;
}

.persona-bars {
  display: grid;
  gap: 7px;
  margin-top: 6px;
}

.bar-row {
  display: grid;
  grid-template-columns: 72px 1fr 22px;
  gap: 6px;
  align-items: center;
  font-size: 0.85rem;
}

.bar-track {
  height: 8px;
  border: 1px solid #3b4b51;
  background: #0b0f13;
}

.bar-fill {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--ember), var(--gold));
}

.persona-row {
  display: grid;
  gap: 2px;
}

.persona-row p {
  margin: 0;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.25;
}

.small-copy {
  margin-bottom: 0;
  color: var(--muted);
  line-height: 1.55;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.legacy-panel {
  border-top: 1px solid #2f444c;
  padding-top: 8px;
}

.legacy-panel .small-copy {
  display: block;
  min-height: 1.6em;
  max-height: 4.8em;
  overflow: auto;
}

.legend-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  color: var(--muted);
  font-size: 0.86rem;
}

.legend-list span {
  display: flex;
  gap: 7px;
  align-items: center;
  min-width: 0;
}

.legend-swatch {
  display: inline-block;
  width: 13px;
  height: 13px;
  flex: 0 0 auto;
  border: 1px solid #0a0d10;
}

.legend-swatch.hero {
  background: #d8b35f;
}

.legend-swatch.interact {
  background: #76b8d6;
}

.legend-swatch.enemy {
  background: #b33a34;
}

.legend-swatch.stairs {
  background: #9d7cc5;
}

.choice-list {
  display: grid;
  gap: 8px;
  align-content: start;
}

.choice-list:empty {
  display: none;
}

.choice-list button {
  padding: 8px 10px;
  text-align: left;
}

.choice-list button strong,
.choice-list button small {
  display: block;
}

.choice-list button small {
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.choice-list.explore-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.choice-list.explore-actions button {
  text-align: center;
}

.choice-list.explore-actions button:nth-child(1) {
  grid-column: 2;
  grid-row: 1;
}

.choice-list.explore-actions button:nth-child(2) {
  grid-column: 1;
  grid-row: 2;
}

.choice-list.explore-actions button:nth-child(3) {
  grid-column: 2;
  grid-row: 2;
}

.choice-list.explore-actions button:nth-child(4) {
  grid-column: 3;
  grid-row: 2;
}

.choice-list.explore-actions button:nth-child(5) {
  grid-column: 2;
  grid-row: 3;
}

.choice-list.explore-actions button:nth-child(6) {
  grid-column: 1 / -1;
  grid-row: 4;
}

.log-panel {
  min-height: 0;
  padding: 8px;
}

.log-panel ol {
  display: grid;
  gap: 6px;
  max-height: 100%;
  margin: 0;
  padding-left: 20px;
  overflow: auto;
  color: var(--muted);
  font-size: 0.88rem;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.log-panel li {
  min-width: 0;
  line-height: 1.35;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.danger {
  color: #ff8b78;
}

.good {
  color: #b8df9d;
}

@media (max-width: 900px) {
  body {
    overflow: auto;
  }

  .game-shell {
    height: auto;
    min-height: 100vh;
  }

  .play-layout {
    grid-template-columns: 1fr;
  }

  .dungeon-stage {
    height: 62vh;
  }

  .command-panel {
    overflow: visible;
  }
}
