:root {
  color-scheme: dark;
  --deep: #082b2a;
  --deep-2: #103f3c;
  --tile: #8fc4aa;
  --tile-dark: #4e8978;
  --cream: #f6eed5;
  --cream-2: #e4d8b8;
  --ink: #143c39;
  --yellow: #ffd64a;
  --orange: #df704c;
  --danger: #d95848;
  --water: #64d5cf;
  --muted: #a9cbc1;
  --focus: #fff0a1;
  --radius: 14px;
  font-family: "Microsoft YaHei UI", "PingFang SC", "Noto Sans CJK SC", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { min-width: 320px; background: var(--deep); }
body {
  margin: 0;
  min-height: 100vh;
  min-height: 100dvh;
  color: var(--cream);
  background:
    radial-gradient(circle at 50% -10%, rgba(113, 198, 169, .22), transparent 42rem),
    var(--deep);
  overscroll-behavior: none;
}
button, dialog { font: inherit; }
button { -webkit-tap-highlight-color: transparent; }
button:focus-visible, canvas:focus-visible, a:focus-visible {
  outline: 3px solid var(--focus);
  outline-offset: 3px;
}
::selection { color: var(--deep); background: var(--yellow); }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-track { background: #092d2b; }
::-webkit-scrollbar-thumb { background: #4e8e7d; border: 2px solid #092d2b; border-radius: 6px; }

.skip-link {
  position: fixed;
  z-index: 100;
  top: 8px;
  left: 8px;
  padding: 10px 14px;
  color: var(--ink);
  background: var(--focus);
  transform: translateY(-150%);
}
.skip-link:focus { transform: translateY(0); }
.sr-only {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0,0,0,0);
  white-space: nowrap; border: 0;
}
.device-qa-badge {
  position: fixed;
  z-index: 120;
  left: max(8px, env(safe-area-inset-left));
  bottom: max(8px, env(safe-area-inset-bottom));
  max-width: calc(100vw - 16px);
  padding: 8px 11px;
  border: 1px solid rgba(255, 240, 161, .72);
  border-radius: 9px;
  color: var(--cream);
  background: rgba(8, 43, 42, .94);
  box-shadow: 0 5px 18px rgba(0, 20, 19, .34);
  font: 700 10px/1.35 ui-monospace, Consolas, monospace;
}
.boot-failure {
  position: fixed;
  z-index: 200;
  left: 50%;
  top: 50%;
  width: min(560px, calc(100vw - 32px));
  padding: 24px;
  color: var(--ink);
  background: var(--cream);
  border: 2px solid var(--danger);
  border-radius: 14px;
  box-shadow: 0 24px 80px rgba(0, 20, 19, .5);
  transform: translate(-50%, -50%);
}
.boot-failure strong { font-size: 22px; }
.boot-failure p { margin: 10px 0 18px; color: #5e716a; line-height: 1.65; }
.boot-failure div { display: flex; flex-wrap: wrap; gap: 8px; }
.boot-failure button { min-height: 44px; padding: 0 16px; border: 0; border-radius: 9px; color: var(--cream); background: var(--deep-2); font-weight: 800; cursor: pointer; }
.boot-failure button:first-child { color: var(--ink); background: var(--yellow); }
.boot-failure small { display: block; margin-top: 14px; color: #71847c; }
.boot-failure code { padding: 2px 5px; color: var(--ink); background: #e3d8b8; border-radius: 4px; }

.app-shell {
  width: min(100%, 1680px);
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0 auto;
  background: #0d3533;
  box-shadow: 0 28px 90px rgba(0, 15, 14, .44);
}

.topbar {
  min-height: 76px;
  display: grid;
  grid-template-columns: minmax(230px, 1fr) auto minmax(150px, 1fr);
  align-items: center;
  gap: 24px;
  padding: 10px clamp(16px, 3vw, 42px);
  background: #f2e8ca;
  color: var(--ink);
  border-bottom: 5px solid #c89f59;
  box-shadow: 0 8px 28px rgba(3, 28, 27, .24);
  position: relative;
  z-index: 4;
}
.brand-lockup { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-wordmark { width: clamp(170px, 19vw, 270px); height: 52px; object-fit: contain; object-position: left center; }
.build-stamp {
  color: #7d4f2b;
  border: 1px solid #b67c45;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 11px;
  font-weight: 800;
  white-space: nowrap;
}
.resource-ledger { display: flex; align-items: center; gap: 10px; }
.resource-value { display: flex; align-items: center; min-width: 118px; gap: 7px; }
.resource-value + .resource-value { border-left: 1px solid rgba(20, 60, 57, .2); padding-left: 14px; }
.resource-value img { width: 40px; height: 40px; object-fit: contain; }
.resource-value span { display: flex; flex-direction: column; line-height: 1; }
.resource-value strong { font-size: 22px; font-variant-numeric: tabular-nums; letter-spacing: -.025em; }
.resource-value small { margin-top: 5px; color: #54756c; font-size: 11px; font-weight: 700; }
.topbar-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }
.quiet-button, .segmented {
  min-height: 44px;
  border: 0;
  color: var(--ink);
  background: transparent;
  font-weight: 800;
  cursor: pointer;
}
.quiet-button:hover, .segmented:hover { background: rgba(18, 74, 70, .1); }
.quiet-button:disabled { opacity: .45; cursor: not-allowed; }
.icon-button { width: 44px; padding: 10px; border-radius: 50%; }
.icon-button svg { width: 22px; height: 22px; fill: currentColor; }
.icon-button.is-active { color: #fff; background: var(--danger); }

.game-layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 350px;
  min-height: calc(100dvh - 76px);
}
.stage-panel { min-width: 0; display: flex; flex-direction: column; background: #0b302f; }
.stage-toolbar {
  min-height: 56px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 18px;
  padding: 7px clamp(14px, 2.2vw, 30px);
  border-bottom: 1px solid rgba(188, 228, 211, .14);
}
.phase-copy { min-width: 0; display: flex; align-items: center; gap: 9px; }
.phase-copy strong { font-size: 14px; }
.phase-copy > span:last-child { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.status-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--yellow); box-shadow: 0 2px 10px rgba(255, 214, 74, .45); }
.status-dot[data-phase="battle"] { background: var(--danger); box-shadow: 0 2px 12px rgba(217, 88, 72, .5); }
.status-dot[data-phase="paused"] { background: var(--water); }
.status-dot[data-phase="result"] { background: #a9cbc1; box-shadow: none; }
.view-controls { display: flex; background: rgba(3, 30, 29, .48); border-radius: 12px; padding: 3px; }
.segmented { min-height: 36px; padding: 0 12px; border-radius: 9px; color: var(--muted); font-size: 12px; }
.segmented.is-active { color: var(--ink); background: var(--cream); box-shadow: 0 4px 12px rgba(0, 16, 15, .25); }

.canvas-wrap {
  position: relative;
  flex: 1 1 auto;
  min-height: 390px;
  aspect-ratio: 16 / 9;
  overflow: hidden;
  background: #092b2a;
}
#game-canvas { display: block; width: 100%; height: 100%; touch-action: manipulation; }
.selection-prompt {
  position: absolute;
  inset: auto 50% 24px auto;
  transform: translateX(50%);
  width: max-content;
  max-width: calc(100% - 32px);
  padding: 11px 18px;
  display: flex;
  align-items: baseline;
  gap: 9px;
  color: var(--ink);
  background: rgba(255, 240, 161, .94);
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 25, 23, .32);
  pointer-events: none;
}
.selection-prompt strong { font-size: 14px; }
.selection-prompt span { font-size: 12px; color: #55746d; }
.asset-warning {
  position: absolute;
  top: 12px; right: 12px;
  max-width: 340px;
  padding: 10px 12px;
  color: #3b2119;
  background: #ffd3a9;
  border-radius: 10px;
  font-size: 12px;
  font-weight: 700;
}
.danger-strip {
  min-height: 66px;
  padding: 10px clamp(14px, 2.2vw, 30px);
  display: grid;
  grid-template-columns: minmax(220px, 360px) minmax(0, 1fr);
  align-items: center;
  gap: 20px;
  color: var(--cream);
  background: #123f3c;
  border-top: 1px solid rgba(188, 228, 211, .12);
}
.enemy-summary { display: grid; grid-template-columns: auto 1fr; gap: 4px 11px; align-items: center; }
.enemy-name { font-size: 13px; font-weight: 800; }
.enemy-name strong { color: #ffad7b; }
.enemy-bar { height: 8px; overflow: hidden; background: #082825; border-radius: 6px; }
.enemy-bar i { display: block; width: 100%; height: 100%; background: var(--orange); }
.enemy-summary > span:last-child { grid-column: 1 / -1; color: var(--muted); font-size: 11px; }
.danger-strip p { margin: 0; color: #d7e9e2; font-size: 13px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.control-panel {
  padding: 20px 18px 18px;
  color: var(--ink);
  background: #eee5c9;
  border-left: 1px solid #c79d58;
  overflow: auto;
}
.room-heading { display: flex; align-items: end; justify-content: space-between; gap: 16px; }
.room-heading span { display: block; color: #70877e; font-size: 11px; font-weight: 800; }
.room-heading h2 { margin: 3px 0 0; font-size: 22px; letter-spacing: -.025em; }
.door-readout { text-align: right; }
.door-readout strong { display: block; margin-top: 3px; font-size: 13px; font-variant-numeric: tabular-nums; }
.door-health { height: 9px; margin: 13px 0 18px; background: #bdc6ae; border-radius: 8px; overflow: hidden; }
.door-health i { display: block; height: 100%; width: 0; background: #3b9a73; transition: background .2s; }
.door-health i[data-danger="true"] { background: var(--danger); }
.movement-panel { margin: 0 0 12px; padding: 12px; color: var(--cream); background: #123f3c; border: 1px solid rgba(255,216,77,.34); border-radius: 13px; box-shadow: 0 8px 18px rgba(10,44,42,.16); }
.movement-copy span, .movement-copy strong, .movement-copy small { display: block; }
.movement-copy span { color: #ffd84d; font-size: 9px; font-weight: 900; letter-spacing: .08em; }
.movement-copy strong { margin-top: 3px; font-size: 13px; }
.movement-copy small { margin-top: 3px; color: #a9c6bc; font-size: 9.5px; line-height: 1.4; }
.movement-actions { display: grid; grid-template-columns: 112px minmax(0,1fr); align-items: center; gap: 10px; margin-top: 10px; }
.dpad { display: grid; grid-template-columns: repeat(3, 34px); grid-template-rows: repeat(2, 34px); gap: 3px; }
.dpad button { display: grid; place-items: center; padding: 0; color: var(--cream); background: #28615a; border: 1px solid rgba(255,255,255,.13); border-radius: 8px; font-size: 13px; cursor: pointer; touch-action: none; }
.dpad button:hover, .dpad button.is-pressed { color: var(--ink); background: var(--yellow); }
.dpad button:nth-child(1) { grid-column: 2; grid-row: 1; }
.dpad button:nth-child(2) { grid-column: 1; grid-row: 2; }
.dpad button:nth-child(3) { grid-column: 2; grid-row: 2; }
.dpad button:nth-child(4) { grid-column: 3; grid-row: 2; }
.place-bed-button { min-height: 58px; display: flex; align-items: center; justify-content: center; gap: 8px; padding: 8px 10px; color: var(--ink); background: var(--yellow); border: 0; border-radius: 10px; font-size: 11px; font-weight: 900; cursor: pointer; }
.place-bed-button:disabled { color: #70847c; background: #92aaa0; cursor: not-allowed; }
.place-bed-button kbd { display: grid; place-items: center; min-width: 22px; height: 22px; color: inherit; background: rgba(255,255,255,.45); border-radius: 6px; font: 900 10px inherit; }
.cell-context { margin-bottom: 10px; padding: 11px 12px; background: rgba(20,60,57,.08); border: 1px solid rgba(20,60,57,.12); border-radius: 12px; }
.cell-context > span { color: #6a8179; font-size: 10px; font-weight: 900; }
.cell-context h3 { margin: 3px 0 2px; font-size: 14px; }
.cell-context p { margin: 0; color: #5d766e; font-size: 10.5px; line-height: 1.45; }
.build-menu { display: grid; gap: 7px; margin-bottom: 13px; }
.cell-popover { position: fixed; z-index: 80; width: 350px; padding: 12px; overflow-y: auto; overscroll-behavior: contain; color: var(--ink); background: var(--cream); border-radius: var(--radius); box-shadow: 0 12px 36px rgb(0 20 18 / 36%); }
.cell-popover-header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.cell-popover-header h2 { margin: 0; font-size: 16px; line-height: 1.4; }
.cell-popover-header button { flex: 0 0 44px; width: 44px; height: 44px; padding: 10px; border: 0; border-radius: 9px; background: var(--cream-2); color: var(--ink); cursor: pointer; }
.cell-popover-header svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; }
.cell-popover .build-menu, .cell-popover .building-detail { margin-bottom: 0; }
.cell-popover .build-choice { min-height: 72px; }
.cell-popover .build-choice strong, .cell-popover .building-detail-copy strong { font-size: 15px; }
.cell-popover .build-choice small, .cell-popover .building-detail-copy small { font-size: 13px; color: var(--ink); }
.cell-popover .build-choice em { font-size: 13px; }
.cell-popover .build-choice:disabled { opacity: .7; }
.cell-popover .building-detail-actions { grid-template-columns: 1fr; }
.cell-popover .building-detail-actions button { min-height: 44px; font-size: 14px; }
.cell-popover-note { margin: 12px 0 0; font-size: 12px; line-height: 1.5; color: var(--ink); }
.build-choice { min-height: 58px; display: grid; grid-template-columns: 46px minmax(0,1fr) auto; align-items: center; gap: 9px; padding: 6px 9px; color: var(--ink); background: #fff8e8; border: 1px solid rgba(20,60,57,.12); border-radius: 11px; text-align: left; cursor: pointer; }
.build-choice:hover:not(:disabled) { border-color: #d8ad45; transform: translateY(-1px); }
.build-choice:disabled { opacity: .48; cursor: not-allowed; }
.build-choice img { width: 44px; height: 44px; object-fit: contain; }
.build-choice strong, .build-choice small { display: block; }
.build-choice strong { font-size: 12px; }
.build-choice small { margin-top: 3px; color: #668078; font-size: 9.5px; }
.build-choice em { padding: 5px 7px; color: #704b28; background: #efd8aa; border-radius: 8px; font-size: 10px; font-style: normal; font-weight: 900; white-space: nowrap; }
.building-detail { margin-bottom: 13px; padding: 10px; background: #fff8e8; border: 1px solid #d8ad45; border-radius: 12px; }
.building-detail-copy { display: grid; grid-template-columns: 48px 1fr; align-items: center; gap: 9px; }
.building-detail-copy img { width: 46px; height: 46px; object-fit: contain; }
.building-detail-copy strong, .building-detail-copy small { display: block; }
.building-detail-copy strong { font-size: 13px; }
.building-detail-copy small { margin-top: 3px; color: #5e776f; font-size: 10px; line-height: 1.4; }
.building-detail-actions { display: grid; grid-template-columns: 1fr auto; gap: 7px; margin-top: 8px; }
.building-detail-actions .secondary-button, .danger-button { min-height: 36px; padding: 0 11px; border: 0; border-radius: 9px; font-size: 10px; font-weight: 900; cursor: pointer; }
.danger-button { color: #8f3e32; background: #f2d5c9; }
.building-detail-actions button:disabled { opacity: .48; cursor: not-allowed; }
.fixed-actions-label { display: flex; justify-content: space-between; align-items: baseline; margin: 10px 2px 7px; }
.fixed-actions-label span { font-size: 11px; font-weight: 900; }
.fixed-actions-label small { color: #71867f; font-size: 9px; }
.action-list { display: grid; gap: 8px; }
.fixed-action-list { grid-template-columns: 1fr; }
.build-action {
  position: relative;
  min-height: 64px;
  width: 100%;
  display: grid;
  grid-template-columns: 50px minmax(0, 1fr) auto;
  align-items: center;
  gap: 11px;
  padding: 7px 12px 7px 7px;
  color: var(--ink);
  background: #f8f1dd;
  border: 0;
  border-radius: var(--radius);
  box-shadow: 0 5px 14px rgba(53, 54, 34, .12);
  text-align: left;
  cursor: pointer;
  transition: transform .16s ease-out, box-shadow .16s ease-out, background .16s;
}
.build-action:hover:not(:disabled) { transform: translateY(-2px); background: #fff8e8; box-shadow: 0 9px 20px rgba(53, 54, 34, .17); }
.build-action:active:not(:disabled) { transform: translateY(0) scale(.99); }
.build-action:disabled { opacity: .54; cursor: not-allowed; box-shadow: none; }
.art-slot { width: 50px; height: 50px; display: grid; place-items: center; background: #d6e4cf; border-radius: 11px; overflow: hidden; }
.art-slot img { width: 48px; height: 48px; object-fit: contain; }
.action-copy { min-width: 0; }
.action-copy strong { display: block; font-size: 14px; }
.action-copy small { display: block; margin-top: 5px; color: #698078; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-size: 10.5px; font-weight: 700; }
.action-price { padding: 6px 8px; color: #74502b; background: #f0dab1; border-radius: 9px; font-size: 11px; font-weight: 900; white-space: nowrap; }
.build-action kbd { position: absolute; top: 5px; right: 5px; width: 18px; height: 18px; display: grid; place-items: center; color: #6e8279; background: transparent; font: 700 10px inherit; }

.event-log { margin-top: 22px; padding-top: 17px; border-top: 1px solid rgba(20, 60, 57, .17); }
.section-heading { display: flex; align-items: center; justify-content: space-between; }
.section-heading h3 { margin: 0; font-size: 14px; }
.section-heading span { color: #688078; font-size: 11px; font-variant-numeric: tabular-nums; }
.event-log ol { margin: 10px 0 0; padding: 0; list-style: none; }
.event-log li { display: grid; grid-template-columns: 38px 1fr; gap: 7px; padding: 6px 0; color: #49655d; font-size: 11px; line-height: 1.45; }
.event-log li + li { border-top: 1px solid rgba(20, 60, 57, .09); }
.event-log time { color: #81958e; font-variant-numeric: tabular-nums; }
.event-log li[data-severity="danger"] span { color: #9b3f35; font-weight: 800; }
.event-log li[data-severity="success"] span { color: #287557; font-weight: 800; }

dialog {
  padding: 0;
  color: var(--ink);
  background: var(--cream);
  border: 0;
  border-radius: 16px;
  box-shadow: 0 30px 90px rgba(0, 20, 18, .54);
}
dialog::backdrop { background: rgba(3, 25, 24, .76); backdrop-filter: blur(5px); }
.intro-dialog { width: min(900px, calc(100vw - 28px)); overflow: hidden; }
.intro-dialog[open] { display: grid; grid-template-columns: 42% 58%; }
.intro-art { min-height: 520px; position: relative; overflow: hidden; background: #174b47; }
.intro-art::before {
  content: "";
  position: absolute; inset: 0;
  background: url("../../art/bathhouse/runtime/final-three-packages-v001/marketing/portrait/portrait_800x1200_v001.png") center / cover no-repeat;
}
.intro-art::after { content: ""; position: absolute; inset: 54% 0 0; background: linear-gradient(transparent, rgba(10, 39, 37, .9)); }
.intro-logo { display: none; }
.intro-guest { display: none; }
.intro-copy { padding: clamp(30px, 4vw, 56px); align-self: center; }
.intro-copy .premise { margin: 0 0 12px; color: #a24d35; font-size: 14px; font-weight: 900; }
.intro-copy h2 { margin: 0; max-width: 14ch; font-size: clamp(29px, 4vw, 48px); line-height: 1.08; letter-spacing: -.035em; text-wrap: balance; }
.intro-copy > p:not(.premise,.silent-note) { margin: 19px 0; color: #4d6961; line-height: 1.75; font-size: 14px; }
.intro-copy ul { margin: 20px 0 26px; padding: 0; list-style: none; }
.intro-copy li { position: relative; padding: 7px 0 7px 23px; color: #36564e; font-size: 13px; }
.intro-copy li::before { content: ""; position: absolute; left: 1px; top: 12px; width: 9px; height: 9px; border: 3px solid #2f8c70; border-radius: 50%; }
.primary-button, .secondary-button {
  position: relative;
  min-height: 52px;
  padding: 0 22px;
  border: 0;
  border-radius: 13px;
  font-weight: 900;
  cursor: pointer;
  overflow: hidden;
}
.primary-button { min-width: 210px; color: var(--ink); background: var(--yellow); box-shadow: 0 8px 22px rgba(151, 112, 24, .25); }
.primary-button:hover:not(:disabled) { background: #ffe16b; }
.primary-button:disabled { color: #74837d; background: #d5dac7; cursor: wait; box-shadow: none; }
.primary-button i { position: absolute; left: 0; bottom: 0; height: 4px; width: 0; background: #2f8c70; }
.secondary-button { color: var(--cream); background: var(--deep-2); }
.silent-note { margin: 12px 0 0; color: #7a8f87; font-size: 10px; }

.sheet-dialog { width: min(660px, calc(100vw - 28px)); }
.sheet-dialog form { padding: clamp(24px, 5vw, 42px); }
.dialog-close { position: absolute; top: 14px; right: 14px; width: 44px; height: 44px; border: 0; border-radius: 50%; color: var(--ink); background: rgba(20,60,57,.08); font-size: 26px; cursor: pointer; }
.sheet-dialog h2 { margin: 0 0 24px; font-size: 30px; letter-spacing: -.025em; }
.rule-steps { display: grid; grid-template-columns: repeat(2, 1fr); gap: 18px; }
.rule-steps b { display: grid; place-items: center; width: 40px; height: 40px; color: var(--ink); background: var(--yellow); border-radius: 50%; font-size: 19px; }
.rule-steps p { margin: 10px 0 0; color: #4e6961; font-size: 13px; line-height: 1.65; }
.test-disclaimer { margin: 26px 0 22px; padding: 14px 16px; color: #62432b; background: #f2d9ad; border-radius: 12px; font-size: 12px; line-height: 1.6; }

.result-dialog { width: min(680px, calc(100vw - 28px)); overflow: hidden; }
.result-dialog[open] { display: grid; grid-template-columns: 42% 58%; }
.result-visual { min-height: 400px; display: grid; place-items: center; background: #164d48; }
.result-visual img { width: 86%; max-height: 360px; object-fit: contain; filter: drop-shadow(0 15px 20px rgba(0,0,0,.28)); }
.result-copy { padding: 42px 38px; }
.result-copy > span { color: #a25137; font-size: 12px; font-weight: 900; }
.result-copy h2 { margin: 7px 0 10px; font-size: 34px; letter-spacing: -.035em; }
.result-copy p { min-height: 48px; margin: 0; color: #547067; font-size: 13px; line-height: 1.7; }
.result-copy dl { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 24px 0; background: rgba(20,60,57,.12); }
.result-copy dl div { padding: 12px 8px; text-align: center; background: var(--cream); }
.result-copy dt { color: #70867e; font-size: 10px; }
.result-copy dd { margin: 5px 0 0; font-weight: 900; font-variant-numeric: tabular-nums; }

.toast {
  position: fixed;
  z-index: 90;
  left: 50%; bottom: max(18px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: min(520px, calc(100vw - 30px));
  padding: 12px 16px;
  color: #44251f;
  background: #ffd2a7;
  border-radius: 12px;
  box-shadow: 0 12px 30px rgba(0, 20, 18, .34);
  font-size: 13px;
  font-weight: 800;
}

@media (max-width: 1040px) {
  .topbar { grid-template-columns: 1fr auto auto; gap: 12px; }
  .build-stamp { display: none; }
  .game-layout { grid-template-columns: minmax(0, 1fr) 310px; }
  .control-panel { padding-inline: 13px; }
  .build-action { grid-template-columns: 52px minmax(0,1fr); }
  .art-slot { width: 52px; height: 52px; }
  .art-slot img { width: 49px; height: 49px; }
  .action-price { grid-column: 2; justify-self: start; margin-top: -15px; }
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .app-shell { min-height: 100dvh; }
  .topbar {
    min-height: 64px;
    grid-template-columns: minmax(0, 1fr) auto;
    padding: 7px 12px;
    border-bottom-width: 3px;
  }
  .brand-wordmark { width: 180px; height: 45px; }
  .resource-ledger { order: 3; grid-column: 1 / -1; justify-content: center; margin: -2px -12px -7px; padding: 5px 12px; background: #e5d9b8; }
  .resource-value { min-width: 105px; }
  .resource-value img { width: 30px; height: 30px; }
  .resource-value strong { font-size: 18px; }
  .quiet-button:not(.icon-button) { display: none; }
  .game-layout { display: block; min-height: 0; }
  .stage-toolbar { min-height: 52px; padding: 6px 10px; }
  .phase-copy > span:last-child { display: none; }
  .segmented { padding-inline: 10px; }
  .canvas-wrap { min-height: 0; aspect-ratio: 16 / 9; }
  .danger-strip { min-height: 76px; grid-template-columns: 1fr; gap: 5px; padding: 8px 12px; }
  .danger-strip p { font-size: 11px; }
  .control-panel { border-left: 0; border-top: 4px solid #c79d58; padding: 16px 12px calc(18px + env(safe-area-inset-bottom)); overflow: visible; }
  .room-heading h2 { font-size: 19px; }
  .movement-actions { grid-template-columns: 112px minmax(150px,1fr); }
  .action-list { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 7px; }
  .build-action { min-height: 82px; grid-template-columns: 48px minmax(0,1fr); padding: 7px; }
  .art-slot { width: 48px; height: 60px; }
  .art-slot img { width: 46px; height: 54px; }
  .action-copy strong { font-size: 12px; }
  .action-copy small { font-size: 9.5px; }
  .action-price { font-size: 9.5px; padding: 4px 6px; }
  .repair-action { grid-column: 1 / -1; }
  .event-log { margin-top: 16px; }
  .event-log ol { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
  .event-log li:nth-child(n+5) { display: none; }
  .intro-dialog[open] { display: block; }
  .intro-art { min-height: 250px; }
  .intro-art::before { background-position: center 34%; }
  .intro-logo { top: 14px; height: 66px; }
  .intro-copy { padding: 26px 24px 30px; }
  .intro-copy h2 { font-size: 31px; }
  .intro-copy ul { margin-block: 14px 18px; }
  .result-dialog[open] { display: block; }
  .result-visual { min-height: 190px; }
  .result-visual img { width: 54%; max-height: 175px; }
  .result-copy { padding: 26px 24px 30px; }
}

@media (max-width: 440px) {
  .brand-wordmark { width: 150px; }
  .phase-copy { gap: 6px; }
  .phase-copy strong { font-size: 12px; }
  .view-controls .segmented:first-child, .view-controls .segmented:nth-child(2) { font-size: 0; width: 40px; padding: 0; }
  .view-controls .segmented:first-child::after { content: "全"; font-size: 12px; }
  .view-controls .segmented:nth-child(2)::after { content: "房"; font-size: 12px; }
  .selection-prompt { bottom: 10px; padding: 8px 12px; }
  .selection-prompt span { display: none; }
  .rule-steps { grid-template-columns: 1fr; gap: 14px; }
  .rule-steps > div { display: grid; grid-template-columns: 40px 1fr; gap: 12px; align-items: start; }
  .rule-steps p { margin: 0; }
  .result-copy dl { grid-template-columns: 1fr 1fr 1fr; }
}

@media (max-height: 720px) and (min-width: 821px) {
  .topbar { min-height: 64px; }
  .game-layout { min-height: calc(100dvh - 64px); }
  .canvas-wrap { min-height: 320px; }
  .build-action { min-height: 62px; }
  .art-slot { height: 50px; }
  .art-slot img { height: 48px; }
  .event-log li:nth-child(n+4) { display: none; }
}

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

/* Keep the battlefield stable while the construction menu changes height. */
.loot-ledger { margin-top: 20px; padding-block: 14px; border-block: 1px solid #c9bc93; }
.loot-ledger h3 { margin: 0; font-size: 15px; }
.loot-ledger p { margin: 8px 0; font-size: 13px; line-height: 1.5; }
.loot-toolbar { display: flex; gap: 8px; }
.loot-toolbar button, .loot-bag-item button, .loot-pool-link { min-height: 44px; padding: 10px 12px; color: var(--ink); background: #e7d8a7; border: 0; border-radius: 10px; font-size: 14px; font-weight: 700; cursor: pointer; }
.loot-toolbar button { flex: 1; }
.loot-toolbar button[aria-pressed="true"] { background: #173f3d; color: #fff3ce; }
.loot-toolbar button:hover, .loot-bag-item button:hover:not(:disabled), .loot-pool-link:hover { background: #f1d572; color: #173f3d; }
.loot-bag-item button:disabled { opacity: .65; cursor: not-allowed; }
.loot-panel { position: fixed; z-index: 85; right: max(12px, env(safe-area-inset-right)); top: max(12px, env(safe-area-inset-top)); width: min(410px, calc(100% - 24px)); max-height: calc(100dvh - 24px); overflow-y: auto; overscroll-behavior: contain; padding: 16px; background: var(--cream); color: var(--ink); border-radius: 14px; box-shadow: 0 14px 40px rgb(0 20 18 / 38%); }
.loot-panel > .cell-popover-header { position: sticky; top: -16px; z-index: 1; padding-block: 8px; background: var(--cream); }
.loot-disclosure, #loot-panel-status { font-size: 13px; line-height: 1.6; margin: 12px 0; }
.loot-pool-row, .loot-bag-item { padding-block: 14px; border-bottom: 1px solid #c9bc93; }
.loot-pool-row strong, .loot-bag-item strong { font-size: 15px; line-height: 1.5; }
.loot-pool-row p, .loot-bag-item p, #loot-bag-empty, #loot-history { margin: 6px 0; font-size: 14px; line-height: 1.6; }
.loot-item-reason { color: #853c28; }
#loot-history { padding-left: 22px; }
.cell-popover .loot-choice { background: #fae8a5; }
.loot-pool-link { width: 100%; background: transparent; text-decoration: underline; text-underline-offset: 3px; font-size: 13px; }
@media (min-width: 821px) {
  .app-shell { height: 100dvh; display: flex; flex-direction: column; }
  .topbar { flex: 0 0 auto; }
  .game-layout { flex: 1; min-height: 0; overflow: hidden; }
  .stage-panel, .control-panel { min-height: 0; }
  .control-panel { overflow-y: auto; }
  .stage-toolbar, .danger-strip { flex-shrink: 0; }
  .canvas-wrap { min-height: 0; aspect-ratio: auto; }
  #game-canvas { position: absolute; inset: 0; }
  .selection-prompt { bottom: 5px; padding: 6px 12px; }
}
