:root {
  color-scheme: dark;
  --bg: #101110;
  --surface: #191b19;
  --surface-2: #222522;
  --line: #3b403b;
  --line-strong: #5d645d;
  --text: #f2f0e9;
  --muted: #a8ada6;
  --faint: #737a73;
  --hp: #ef6a5b;
  --hp-dark: #7f302b;
  --block: #58b9c4;
  --energy: #f1c45b;
  --gold: #e7b64e;
  --attack: #db6f5c;
  --skill: #65aab2;
  --power: #d0a95b;
  --status: #969b96;
  --good: #74bb83;
  --danger: #e1594b;
  --focus: #f4d67e;
  --max-width: 760px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Microsoft YaHei", sans-serif;
  font-size: 16px;
  letter-spacing: 0;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-width: 280px;
  min-height: 100dvh;
  margin: 0;
  color: var(--text);
  background-color: var(--bg);
  background-image:
    linear-gradient(rgba(255, 255, 255, 0.025) 1px, transparent 1px),
    linear-gradient(90deg, rgba(255, 255, 255, 0.018) 1px, transparent 1px);
  background-size: 24px 24px;
  -webkit-tap-highlight-color: transparent;
}

body.modal-open {
  height: 100dvh;
  overflow: hidden;
}

button,
input,
select {
  font: inherit;
  letter-spacing: 0;
}

button {
  color: inherit;
}

button:focus-visible,
[tabindex]:focus-visible,
summary:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 2px;
}

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

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

.boot-screen {
  display: grid;
  min-height: 100dvh;
  place-content: center;
  justify-items: center;
  gap: 12px;
  color: var(--muted);
}

.app-shell {
  min-height: 100dvh;
}

.app-shell.map-shell {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr);
}

.topbar {
  position: sticky;
  z-index: 20;
  top: 0;
  border-bottom: 1px solid var(--line);
  background: rgba(16, 17, 16, 0.96);
  backdrop-filter: blur(12px);
}

.topbar-inner {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: min(100%, var(--max-width));
  min-height: 58px;
  margin: 0 auto;
  padding: 8px 12px;
  padding-top: max(8px, env(safe-area-inset-top));
}

.brand-button,
.icon-button {
  border: 0;
  background: transparent;
  cursor: pointer;
}

.brand-button {
  display: grid;
  grid-template-columns: 30px minmax(0, 1fr);
  gap: 8px;
  align-items: center;
  min-width: 0;
  min-height: 44px;
  padding: 0;
  text-align: left;
}

.brand-button img {
  width: 30px;
  height: 30px;
}

.brand-copy {
  min-width: 0;
}

.brand-title,
.brand-subtitle {
  display: block;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.brand-title {
  font-size: 0.92rem;
  font-weight: 760;
}

.brand-subtitle {
  margin-top: 2px;
  color: var(--muted);
  font-size: 0.72rem;
}

.top-stats {
  display: flex;
  gap: 5px;
  align-items: stretch;
}

.potion-stat {
  min-width: 48px;
  min-height: 44px;
  padding: 4px 6px;
  border: 1px solid #59715e;
  border-radius: 6px;
  background: #18251b;
  color: var(--good);
  cursor: pointer;
  font-size: 0.72rem;
  font-weight: 760;
}

.mini-stat {
  display: grid;
  min-width: 48px;
  min-height: 40px;
  padding: 4px 6px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  place-content: center;
  text-align: center;
}

.mini-stat-label {
  color: var(--muted);
  font-size: 0.62rem;
  line-height: 1;
}

.mini-stat-value {
  margin-top: 3px;
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
  line-height: 1;
}

.mini-stat.hp .mini-stat-value {
  color: var(--hp);
}

.mini-stat.gold .mini-stat-value {
  color: var(--gold);
}

.screen {
  width: min(100%, var(--max-width));
  min-height: calc(100dvh - 59px);
  margin: 0 auto;
  padding: 18px 14px calc(28px + env(safe-area-inset-bottom));
}

.screen.battle-screen {
  padding-bottom: calc(104px + env(safe-area-inset-bottom));
}

.screen-header {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  justify-content: space-between;
  margin-bottom: 18px;
}

.screen-title {
  margin: 0;
  font-size: 1.28rem;
  line-height: 1.2;
}

.screen-kicker {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.section-label {
  margin: 22px 0 9px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
  text-transform: uppercase;
}

.event-description {
  margin: 6px 0 20px;
  padding: 14px 0;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  color: var(--muted);
  line-height: 1.6;
}

.event-outcome {
  margin: 12px 0 18px;
  padding: 12px;
  border-left: 3px solid var(--good);
  background: var(--surface);
}

.event-outcome p { margin: 6px 0 0; color: var(--muted); line-height: 1.45; }

.primary-button,
.secondary-button,
.danger-button,
.quiet-button {
  display: inline-flex;
  min-height: 46px;
  border-radius: 6px;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  font-weight: 720;
}

.primary-button {
  padding: 10px 18px;
  border: 1px solid #d9b04f;
  background: var(--energy);
  color: #211b0e;
}

.secondary-button {
  padding: 10px 16px;
  border: 1px solid var(--line-strong);
  background: var(--surface-2);
}

.danger-button {
  padding: 10px 16px;
  border: 1px solid #99443b;
  background: #522a27;
}

.quiet-button {
  min-width: 44px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
}

.button-row {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}

.button-row > button {
  flex: 1 1 150px;
}

.start-screen {
  display: grid;
  min-height: calc(100dvh - 96px);
  align-content: center;
}

.start-mark {
  width: 70px;
  height: 70px;
  margin-bottom: 22px;
}

.start-title {
  margin: 0;
  font-size: 2.1rem;
  line-height: 1.05;
}

.start-meta {
  margin: 10px 0 20px;
  color: var(--muted);
  font-size: 0.86rem;
}

.character-picker {
  width: min(100%, 560px);
  margin: 0 0 14px;
  padding: 0;
  border: 0;
}

.character-picker legend {
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 0.72rem;
  font-weight: 700;
}

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

.character-button {
  display: grid;
  min-width: 0;
  min-height: 54px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  align-content: center;
  text-align: left;
  cursor: pointer;
}

.character-button.selected {
  border-color: var(--energy);
  background: #2a261b;
}

.character-name,
.character-stats {
  display: block;
  overflow-wrap: anywhere;
}

.character-name {
  font-size: 0.8rem;
  font-weight: 740;
}

.character-stats {
  margin-top: 3px;
  color: var(--muted);
  font-size: 0.66rem;
}

.selected-character-copy,
.load-error {
  width: min(100%, 560px);
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 0.74rem;
  line-height: 1.45;
  white-space: pre-line;
}

.load-error {
  color: var(--hp);
}

.start-actions {
  display: grid;
  gap: 10px;
  width: min(100%, 380px);
}

.map-screen {
  display: grid;
  width: min(100%, var(--max-width));
  height: 100%;
  min-width: 0;
  min-height: 0;
  margin: 0 auto;
  grid-template-rows: auto minmax(360px, 1fr) auto;
  gap: 8px;
  padding-block: 10px max(10px, env(safe-area-inset-bottom));
}

.map-screen .screen-header {
  margin: 0;
}

.route-map {
  position: relative;
  width: min(100%, 560px);
  height: 100%;
  min-height: 360px;
  max-height: 590px;
  margin-inline: auto;
  border-block: 1px solid var(--line);
  background: rgba(16, 17, 16, 0.42);
  overflow: hidden;
}

.route-links {
  position: absolute;
  z-index: 0;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.route-links line { stroke: var(--line); stroke-width: 1.5; vector-effect: non-scaling-stroke; }
.route-links line.active { stroke: #82703c; stroke-width: 3; }

.route-floor {
  position: absolute;
  z-index: 1;
  left: 5px;
  width: 16px;
  transform: translateY(-50%);
  color: var(--faint);
  font-size: 0.62rem;
  font-variant-numeric: tabular-nums;
  text-align: right;
  pointer-events: none;
}

.route-node {
  position: absolute;
  z-index: 2;
  display: grid;
  width: 30px;
  height: 30px;
  padding: 0;
  border: 0;
  background: transparent;
  color: var(--muted);
  place-items: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
  font-weight: 780;
}

.route-node:disabled {
  opacity: 1;
}

.route-node-mark,
.route-start {
  display: grid;
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: var(--surface);
  place-items: center;
  font-size: 0.72rem;
}

.route-node.available {
  z-index: 4;
  width: 46px;
  height: 46px;
  color: var(--text);
  cursor: pointer;
  pointer-events: auto;
}

.route-node.available .route-node-mark {
  border: 2px solid var(--energy);
  box-shadow: 0 0 0 3px rgba(241, 196, 91, 0.2);
}

.route-node.visited .route-node-mark {
  border-color: #477a51;
  background: #17221a;
  color: var(--good);
}

.route-node.event { color: #d6c9ed; }
.route-node.elite { color: var(--hp); }
.route-node.shop { color: var(--gold); }
.route-node.camp { color: #e58b68; }
.route-node.treasure { color: var(--block); }
.route-node.boss { color: var(--hp); }
.route-node.boss .route-node-mark {
  border-color: #9b4941;
  font-size: 0.64rem;
}

.route-start {
  position: absolute;
  z-index: 1;
  width: 24px;
  height: 24px;
  transform: translate(-50%, -50%);
  color: var(--faint);
  font-size: 0.62rem;
  pointer-events: none;
}

.route-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 4px 10px;
  margin: 0;
  color: var(--muted);
  font-size: 0.64rem;
  justify-content: center;
}

.choice-list,
.enemy-list,
.reward-list,
.deck-list,
.shop-list,
.log-list {
  display: grid;
  gap: 9px;
}

.choice-button,
.reward-button,
.shop-button {
  width: 100%;
  min-height: 72px;
  padding: 12px 13px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.choice-button:hover,
.reward-button:hover,
.shop-button:hover,
.card-button:not(:disabled):hover,
.enemy-panel.selectable:hover {
  border-color: var(--line-strong);
  background: var(--surface-2);
}

.choice-button.fatal-choice {
  border-color: color-mix(in srgb, var(--danger) 62%, var(--line));
}

.choice-button.fatal-choice .choice-name {
  color: var(--danger);
}

.effect-choice.selected,
.event-card-choice.selected {
  border-color: var(--focus);
  background: #2b281d;
  box-shadow: inset 0 0 0 1px var(--focus);
}

.selection-count {
  display: grid;
  min-width: 52px;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
  color: var(--energy);
  place-content: center;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.selection-actions {
  position: sticky;
  bottom: 0;
  display: grid;
  grid-template-columns: minmax(96px, 0.45fr) minmax(140px, 1fr);
  gap: 9px;
  margin: 16px -14px -28px;
  padding: 10px 14px max(10px, env(safe-area-inset-bottom));
  border-top: 1px solid var(--line);
  background: rgba(16, 17, 16, 0.97);
}

.event-selection-screen {
  padding-bottom: calc(92px + env(safe-area-inset-bottom));
}

.event-selection-actions {
  grid-template-columns: minmax(0, 1fr);
}

.choice-main,
.reward-main,
.shop-main {
  display: flex;
  gap: 10px;
  align-items: baseline;
  justify-content: space-between;
}

.choice-name,
.reward-name,
.shop-name {
  font-size: 1rem;
  font-weight: 760;
}

.choice-value,
.reward-rarity,
.shop-price {
  flex: 0 0 auto;
  color: var(--gold);
  font-size: 0.8rem;
  font-variant-numeric: tabular-nums;
}

.choice-detail,
.reward-detail,
.shop-detail {
  margin-top: 6px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.42;
}

.battle-meta {
  display: flex;
  gap: 8px;
  align-items: center;
  margin-bottom: 10px;
  color: var(--muted);
  font-size: 0.75rem;
}

.battle-meta strong {
  color: var(--text);
}

.enemy-list {
  margin-bottom: 14px;
}

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

.enemy-list.group .enemy-panel {
  min-height: 108px;
  padding: 10px;
}

.enemy-list.group .health-track {
  margin-top: 7px;
  margin-bottom: 7px;
}

.enemy-list.group .intent-box {
  min-height: 40px;
  padding-top: 5px;
  padding-bottom: 5px;
}

.enemy-list.group .enemy-bottomline {
  margin-top: 7px;
}

.enemy-panel {
  position: relative;
  min-height: 126px;
  padding: 12px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 7px;
  background: var(--surface);
}

button.enemy-panel {
  width: 100%;
  text-align: left;
  cursor: pointer;
}

.enemy-panel.selected {
  border-color: var(--focus);
  box-shadow: inset 0 0 0 1px var(--focus);
}

.enemy-panel.dead {
  min-height: 72px;
  opacity: 0.48;
}

.enemy-panel.dead.reviving {
  border-style: dashed;
  opacity: 0.76;
}

.enemy-topline,
.enemy-bottomline,
.player-strip,
.hand-toolbar,
.dock-inner {
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
}

.enemy-name {
  min-width: 0;
  overflow-wrap: anywhere;
  font-size: 1rem;
  font-weight: 760;
}

.enemy-hp,
.player-hp {
  flex: 0 0 auto;
  color: var(--hp);
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.health-track {
  height: 5px;
  margin: 9px 0 10px;
  overflow: hidden;
  border-radius: 2px;
  background: #3b2421;
}

.health-fill {
  height: 100%;
  background: var(--hp);
  transition: width 180ms ease;
}

.intent-box {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 8px;
  align-items: center;
  min-height: 44px;
  padding: 7px 9px;
  border-left: 3px solid var(--attack);
  background: #24201e;
}

.intent-box.buff {
  border-left-color: var(--power);
}

.intent-name {
  overflow-wrap: anywhere;
  font-size: 0.8rem;
  font-weight: 690;
}

.intent-value {
  color: var(--hp);
  font-size: 1.08rem;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.intent-value.non-attack {
  color: var(--power);
  font-size: 0.78rem;
}

.enemy-bottomline {
  margin-top: 10px;
  justify-content: flex-start;
}

.status-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.status-pill {
  display: inline-flex;
  min-height: 24px;
  padding: 3px 7px;
  border: 1px solid var(--line);
  border-radius: 4px;
  align-items: center;
  background: #151615;
  color: var(--muted);
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
}

.status-pill.positive {
  color: var(--good);
}

.status-pill.negative {
  color: var(--hp);
}

.status-pill.block {
  color: var(--block);
}

.player-strip {
  position: sticky;
  z-index: 8;
  top: 59px;
  min-height: 54px;
  margin: 0 -14px 12px;
  padding: 8px 14px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
  background: rgba(25, 27, 25, 0.97);
}

.potion-strip {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 7px;
  margin-bottom: 10px;
}

.potion-slot {
  display: grid;
  min-width: 0;
  min-height: 46px;
  padding: 6px 8px;
  border: 1px solid #59715e;
  border-radius: 6px;
  background: #18251b;
  color: var(--text);
  cursor: pointer;
  text-align: left;
}

.potion-slot span {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 0.75rem;
  font-weight: 720;
}

.potion-slot small { color: var(--muted); font-size: 0.62rem; }
.potion-slot.empty { border-style: dashed; color: var(--faint); place-content: center; text-align: center; }
.potion-slot.uncommon { border-color: #4f8b82; }
.potion-slot.rare { border-color: var(--energy); }
.potion-slot.selected { outline: 3px solid var(--focus); outline-offset: 1px; }

.potion-modal-list { display: grid; gap: 9px; }
.potion-modal-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  padding: 10px;
  border-bottom: 1px solid var(--line);
  align-items: center;
}
.potion-modal-row strong,
.potion-modal-row small { display: block; overflow-wrap: anywhere; }
.potion-modal-row small { margin-top: 4px; color: var(--muted); font-size: 0.7rem; line-height: 1.35; }
.potion-actions { display: flex; gap: 6px; }
.potion-actions button { min-height: 44px; padding: 7px 10px; }

.player-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  font-size: 0.84rem;
}

.player-block {
  color: var(--block);
  font-variant-numeric: tabular-nums;
  font-weight: 760;
}

.resource-stack {
  display: flex;
  flex: 0 0 auto;
  gap: 5px;
  align-items: center;
}

.star-orb,
.osty-orb,
.orb-count {
  display: grid;
  min-width: 42px;
  height: 42px;
  padding: 0 6px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: var(--bg);
  color: var(--muted);
  place-content: center;
  font-size: 0.68rem;
  font-variant-numeric: tabular-nums;
  font-weight: 760;
  white-space: nowrap;
}

.star-orb {
  border-color: #9c8242;
  color: var(--energy);
}

.osty-orb {
  color: #cba0ba;
}

.orb-count {
  color: var(--block);
}

.energy-orb {
  display: grid;
  width: 42px;
  height: 42px;
  flex: 0 0 42px;
  border: 2px solid #d4a42e;
  border-radius: 50%;
  background: #392f16;
  color: var(--energy);
  place-content: center;
  font-size: 0.92rem;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.hand-toolbar {
  min-height: 44px;
  margin-bottom: 8px;
}

.hand-title {
  margin: 0;
  font-size: 0.88rem;
}

.pile-buttons {
  display: flex;
  gap: 6px;
}

.pile-button {
  min-width: 64px;
  min-height: 44px;
  padding: 6px 8px;
  border: 1px solid var(--line);
  border-radius: 5px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 0.7rem;
}

.hand-list {
  display: grid;
  gap: 7px;
}

.card-button {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) auto;
  gap: 10px;
  align-items: center;
  width: 100%;
  min-height: 66px;
  padding: 8px 10px;
  border: 1px solid var(--line);
  border-left: 4px solid var(--attack);
  border-radius: 6px;
  background: var(--surface);
  text-align: left;
  cursor: pointer;
}

.card-button.skill {
  border-left-color: var(--skill);
}

.card-button.power {
  border-left-color: var(--power);
}

.card-button.status,
.card-button.curse {
  border-left-color: var(--status);
}

.card-button.selected {
  border-color: var(--focus);
  border-left-color: var(--focus);
  background: #2b281d;
}

.card-cost {
  display: grid;
  width: 38px;
  height: 38px;
  border: 1px solid #846b2f;
  border-radius: 50%;
  background: #332a14;
  color: var(--energy);
  place-content: center;
  font-size: 0.95rem;
  font-variant-numeric: tabular-nums;
  font-weight: 800;
}

.card-copy {
  min-width: 0;
}

.card-name {
  display: block;
  overflow-wrap: anywhere;
  font-size: 0.88rem;
  font-weight: 760;
}

.card-description {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.card-number {
  min-width: 36px;
  color: var(--attack);
  font-size: 1.12rem;
  font-variant-numeric: tabular-nums;
  font-weight: 820;
  text-align: right;
}

.card-button.skill .card-number {
  color: var(--block);
}

.card-button.power .card-number {
  color: var(--power);
}

.card-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  margin-top: 4px;
}

.card-tag {
  color: var(--faint);
  font-size: 0.62rem;
}

.empty-state {
  display: grid;
  min-height: 120px;
  border: 1px dashed var(--line);
  border-radius: 6px;
  color: var(--muted);
  place-content: center;
  font-size: 0.8rem;
}

.turn-dock {
  position: fixed;
  z-index: 30;
  right: 0;
  bottom: 0;
  left: 0;
  border-top: 1px solid var(--line);
  background: rgba(16, 17, 16, 0.97);
  backdrop-filter: blur(12px);
}

.dock-inner {
  width: min(100%, var(--max-width));
  min-height: 76px;
  margin: 0 auto;
  padding: 10px 14px;
  padding-bottom: max(10px, env(safe-area-inset-bottom));
}

.dock-message {
  min-width: 0;
  color: var(--muted);
  font-size: 0.72rem;
  line-height: 1.35;
}

.end-turn-button {
  min-width: 118px;
  min-height: 50px;
  padding: 10px 16px;
  border: 1px solid #b84237;
  border-radius: 6px;
  background: #8c342d;
  cursor: pointer;
  font-weight: 780;
}

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

.summary-stat {
  min-height: 76px;
  padding: 10px 8px;
  border-top: 2px solid var(--line-strong);
  background: var(--surface);
  text-align: center;
}

.summary-stat span {
  display: block;
  color: var(--muted);
  font-size: 0.68rem;
}

.summary-stat strong {
  display: block;
  margin-top: 7px;
  font-size: 1.12rem;
  font-variant-numeric: tabular-nums;
}

.reward-relic {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 4px 10px;
  min-height: 58px;
  padding: 10px 12px;
  border-left: 3px solid var(--good);
  background: var(--surface);
  align-items: center;
}

.reward-relic span,
.reward-relic small {
  color: var(--muted);
  font-size: 0.68rem;
}

.reward-relic strong {
  grid-row: 2;
  font-size: 0.86rem;
}

.reward-relic small {
  grid-row: 1 / span 2;
  grid-column: 2;
}

.reward-relic-actions {
  margin-top: 8px;
}

.treasure-screen {
  display: grid;
  min-height: calc(100dvh - 59px);
  align-content: center;
}

.treasure-screen .screen-header {
  width: 100%;
}

.treasure-closed {
  display: grid;
  width: 132px;
  aspect-ratio: 1.28;
  margin: 36px auto 26px;
  border: 2px solid #8e7840;
  border-top-width: 10px;
  border-radius: 6px;
  background: #272318;
  box-shadow: inset 0 0 0 1px #3d3521;
  place-items: center;
}

.treasure-closed span {
  display: grid;
  width: 34px;
  height: 34px;
  border: 1px solid #b99743;
  border-radius: 4px;
  color: var(--gold);
  place-items: center;
  font-weight: 820;
}

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

.treasure-relic {
  margin-top: 12px;
}

.treasure-actions {
  margin-top: 18px;
}

.deck-row,
.log-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  min-height: 46px;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  align-items: center;
}

.deck-row-name {
  font-size: 0.82rem;
  font-weight: 690;
}

.deck-row-detail,
.log-row {
  color: var(--muted);
  font-size: 0.72rem;
}

.deck-row-value {
  color: var(--energy);
  font-size: 0.72rem;
}

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

.modal {
  width: min(100%, 560px);
  max-height: min(82dvh, 720px);
  overflow: auto;
  border: 1px solid var(--line-strong);
  border-radius: 8px;
  background: var(--surface);
  box-shadow: 0 18px 70px rgba(0, 0, 0, 0.45);
}

.modal-header {
  position: sticky;
  z-index: 2;
  top: 0;
  display: flex;
  gap: 10px;
  align-items: center;
  justify-content: space-between;
  min-height: 58px;
  padding: 10px 12px;
  border-bottom: 1px solid var(--line);
  background: var(--surface);
}

.modal-title {
  margin: 0;
  font-size: 1rem;
}

.modal-body {
  padding: 12px;
}

.catalog-tabs {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 6px;
  margin-bottom: 12px;
}

.catalog-tabs button {
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
}

.catalog-tabs button.selected {
  border-color: var(--energy);
  background: #2a261b;
  color: var(--text);
}

.catalog-controls {
  display: grid;
  grid-template-columns: minmax(0, 1fr) repeat(2, minmax(92px, 0.35fr));
  gap: 8px;
  margin-bottom: 9px;
}

.catalog-field {
  display: grid;
  gap: 4px;
  min-width: 0;
  color: var(--muted);
  font-size: 0.66rem;
}

.catalog-field input,
.catalog-field select {
  width: 100%;
  min-height: 44px;
  padding: 8px 9px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--bg);
  color: var(--text);
}

.catalog-count {
  margin: 6px 0 10px;
  color: var(--muted);
  font-size: 0.7rem;
}

.catalog-list {
  display: grid;
  border-top: 1px solid var(--line);
}

.catalog-row {
  min-width: 0;
  padding: 10px 2px;
  border-bottom: 1px solid var(--line);
}

.catalog-row-head {
  display: flex;
  gap: 8px;
  justify-content: space-between;
  min-width: 0;
  font-size: 0.78rem;
}

.catalog-row-head strong {
  overflow-wrap: anywhere;
}

.catalog-row-head span,
.catalog-row code {
  flex: 0 0 auto;
  color: var(--faint);
  font-size: 0.64rem;
}

.catalog-row p {
  margin: 5px 0;
  color: var(--muted);
  font-size: 0.7rem;
  line-height: 1.45;
}

.catalog-more {
  width: 100%;
  margin-top: 10px;
}

.about-copy {
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.65;
}

.about-copy strong {
  color: var(--text);
}

.about-copy a {
  color: var(--block);
}

.toast {
  position: fixed;
  z-index: 120;
  right: 14px;
  bottom: calc(90px + env(safe-area-inset-bottom));
  left: 14px;
  width: fit-content;
  max-width: min(calc(100% - 28px), 520px);
  min-height: 42px;
  margin: 0 auto;
  padding: 10px 14px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #292c29;
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.36);
  font-size: 0.78rem;
  line-height: 1.35;
}

.toast.error {
  border-color: #a94940;
}

.separator {
  height: 1px;
  margin: 18px 0;
  border: 0;
  background: var(--line);
}

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

.fake-merchant-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
  margin-top: 18px;
}

.crystal-sphere-screen {
  display: grid;
  justify-items: stretch;
}

.crystal-toolbar {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  width: min(100%, 320px);
  margin: 0 auto 14px;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: var(--surface);
}

.crystal-toolbar button {
  min-height: 40px;
  border: 0;
  border-radius: 4px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-weight: 720;
}

.crystal-toolbar button.active {
  background: #35504b;
  color: var(--text);
}

.crystal-board {
  display: grid;
  grid-template-columns: repeat(11, minmax(0, 1fr));
  gap: 2px;
  width: min(100%, 560px);
  aspect-ratio: 1;
  margin: 0 auto;
  padding: 4px;
  border: 1px solid var(--line-strong);
  border-radius: 6px;
  background: #0c0f0e;
}

.crystal-cell {
  min-width: 0;
  min-height: 0;
  aspect-ratio: 1;
  padding: 0;
  border: 1px solid #343b38;
  border-radius: 2px;
  background: #171b19;
  color: var(--text);
  font-size: 0.78rem;
  font-weight: 800;
  line-height: 1;
  font-variant-numeric: tabular-nums;
}

.crystal-cell.is-hidden {
  border-color: #50645e;
  background: #2d403b;
  cursor: crosshair;
}

.crystal-cell.is-hidden:hover {
  border-color: #91b8ad;
  background: #3b554e;
}

.crystal-cell:disabled {
  cursor: default;
  opacity: 1;
}

.crystal-cell.has-item {
  border-color: #777d78;
  background: #292d2a;
}

.crystal-cell.item-relic,
.legend-relic {
  color: #f0cc70;
}

.crystal-cell.item-potion,
.legend-potion {
  color: #76c2ce;
}

.crystal-cell.item-card,
.legend-card {
  color: #d7d1c2;
}

.crystal-cell.item-gold,
.legend-gold {
  color: var(--gold);
}

.crystal-cell.item-curse,
.legend-curse {
  color: #d28bbb;
}

.crystal-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 6px 14px;
  justify-content: center;
  margin-top: 12px;
  color: var(--muted);
  font-size: 0.72rem;
}

.crystal-legend span {
  display: inline-flex;
  gap: 5px;
  align-items: center;
}

.crystal-legend b {
  display: grid;
  width: 22px;
  height: 22px;
  border: 1px solid var(--line);
  border-radius: 3px;
  background: var(--surface);
  place-content: center;
}

@media (max-width: 520px) {
  .topbar-inner {
    grid-template-columns: minmax(0, 1fr) auto;
    padding-right: 8px;
    padding-left: 8px;
  }

  .brand-button {
    grid-template-columns: 26px minmax(0, 1fr);
    gap: 6px;
  }

  .brand-button img {
    width: 26px;
    height: 26px;
  }

  .mini-stat {
    min-width: 44px;
    padding-right: 4px;
    padding-left: 4px;
  }

  .mini-stat.gold {
    display: none;
  }

  .screen {
    padding-right: 10px;
    padding-left: 10px;
  }

  .player-strip {
    margin-right: -10px;
    margin-left: -10px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .card-button {
    grid-template-columns: 38px minmax(0, 1fr) auto;
    gap: 8px;
    padding-right: 8px;
    padding-left: 8px;
  }

  .card-cost {
    width: 35px;
    height: 35px;
  }

  .dock-inner {
    padding-right: 10px;
    padding-left: 10px;
  }

  .selection-actions {
    margin-right: -10px;
    margin-left: -10px;
    padding-right: 10px;
    padding-left: 10px;
  }

  .catalog-controls {
    grid-template-columns: 1fr 1fr;
  }

  .catalog-field:first-child {
    grid-column: 1 / -1;
  }

  .fake-merchant-stock {
    grid-template-columns: minmax(0, 1fr);
  }

  .crystal-board {
    gap: 1px;
    padding: 3px;
  }
}

@media (max-width: 340px) {
  .brand-subtitle,
  .mini-stat.floor,
  .dock-message {
    display: none;
  }

  .top-stats {
    gap: 3px;
  }

  .mini-stat {
    min-width: 41px;
  }

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

  .card-number {
    min-width: 30px;
    font-size: 1rem;
  }

  .end-turn-button {
    width: 100%;
  }

  .character-grid,
  .catalog-controls {
    grid-template-columns: 1fr;
  }

  .catalog-field:first-child {
    grid-column: auto;
  }
}

@media (max-height: 650px) {
  .topbar-inner {
    min-height: 52px;
    padding-top: max(4px, env(safe-area-inset-top));
    padding-bottom: 4px;
  }

  .map-screen {
    grid-template-rows: auto minmax(280px, 1fr) auto;
    gap: 5px;
    padding-block: 6px max(6px, env(safe-area-inset-bottom));
  }

  .map-screen .screen-title {
    font-size: 1rem;
  }

  .map-screen .screen-kicker {
    margin-top: 2px;
    font-size: 0.68rem;
  }

  .route-map {
    min-height: 280px;
  }

  .route-node-mark,
  .route-start {
    width: 18px;
    height: 18px;
    font-size: 0.58rem;
  }

  .route-node.boss .route-node-mark {
    font-size: 0.5rem;
  }

  .route-legend {
    gap: 2px 7px;
    font-size: 0.58rem;
  }
}

@media (max-height: 520px) {
  .topbar-inner {
    min-height: 44px;
    padding-top: max(2px, env(safe-area-inset-top));
    padding-bottom: 2px;
  }

  .map-screen {
    grid-template-rows: auto minmax(230px, 1fr) auto;
    gap: 3px;
    padding-block: 3px max(3px, env(safe-area-inset-bottom));
  }

  .map-screen .screen-header {
    align-items: center;
  }

  .map-screen .screen-title {
    font-size: 0.9rem;
  }

  .map-screen .screen-kicker {
    font-size: 0.6rem;
  }

  .route-map {
    min-height: 230px;
  }

  .route-floor {
    font-size: 0.54rem;
  }

  .route-node-mark,
  .route-start {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    font-size: 0.46rem;
  }

  .route-node.boss .route-node-mark {
    font-size: 0.42rem;
  }

  .route-legend {
    gap: 1px 6px;
    font-size: 0.54rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
