@font-face {
  font-family: "DCC Noto";
  src: url("../../assets/fonts/NotoSansCJKsc-Regular.otf") format("opentype");
  font-display: swap;
}

:root {
  --stone-950: #101719;
  --stone-900: #172126;
  --steel-850: #1b2529;
  --steel-800: #253238;
  --steel-750: #303d44;
  --steel-650: #586b70;
  --steel-500: #788a88;
  --bone: #f0e2c3;
  --muted: #a7b7b2;
  --safety: #f2c14e;
  --slime: #6ccb5f;
  --ghost: #61c9d8;
  --danger: #d95d4f;
  --inspection: #4f8cc9;
  --success: #78c98a;
  --wood: #6c4930;
  --wood-hi: #bd7840;
  --scale: 1;
  --safe-top: max(env(safe-area-inset-top), 0px);
  --safe-bottom: max(env(safe-area-inset-bottom), 0px);
  --world-height: clamp(286px, 39.5vh, 350px);
  --nav-height: 58px;
}

* { box-sizing: border-box; }

html,
body {
  margin: 0;
  min-height: 100%;
  background: var(--stone-950);
  color: var(--bone);
  font-family: "DCC Noto", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  letter-spacing: 0;
}

body {
  min-height: 100dvh;
  display: flex;
  justify-content: center;
  overflow: hidden;
}

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

button { touch-action: manipulation; }

.game-shell {
  position: relative;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) calc(var(--nav-height) + var(--safe-bottom));
  width: 100vw;
  max-width: 430px;
  min-height: 100dvh;
  max-height: 100dvh;
  overflow: hidden;
  background: var(--stone-900);
  border-inline: 2px solid #0b1012;
}

.top-bar,
.page-host,
.field-page,
.bottom-nav {
  width: 100%;
  max-width: 100%;
  min-width: 0;
}

.top-bar {
  min-height: calc(70px + var(--safe-top));
  padding: calc(6px + var(--safe-top)) 8px 5px;
  background: var(--steel-850);
  border-bottom: 2px solid #0b1012;
  box-shadow: inset 0 -2px 0 #35474d;
  z-index: 4;
}

.title-row,
.metric-row,
.resource-rail,
.status-line,
.room-rail,
.choice-row,
.segmented,
.row-between,
.row-start,
.modal-actions,
.setting-row,
.facility-cost,
.employee-metrics,
.micro-legend {
  display: flex;
  align-items: center;
}

.title-row,
.row-between,
.setting-row { justify-content: space-between; gap: 8px; }

.contract-block { min-width: 0; }
.contract-name {
  margin: 0;
  font-size: calc(16px * var(--scale));
  line-height: 1.05;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.objective {
  margin-top: 2px;
  color: var(--muted);
  font-size: calc(10px * var(--scale));
  line-height: 1.15;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-chip,
.tag,
.mini-state,
.count-badge,
.source-badge {
  border: 1px solid var(--steel-650);
  background: #172329;
  color: var(--muted);
  padding: 3px 6px;
  border-radius: 2px;
  font-size: calc(10px * var(--scale));
  line-height: 1.1;
  white-space: nowrap;
}

.status-chip.warning,
.tag.warning { border-color: var(--safety); color: var(--safety); }
.status-chip.danger,
.tag.danger { border-color: var(--danger); color: #f29b91; }
.status-chip.success,
.tag.success { border-color: var(--success); color: var(--success); }
.status-chip.info,
.tag.info { border-color: var(--ghost); color: var(--ghost); }

.metric-row {
  margin-top: 5px;
  gap: 0;
  min-width: 0;
}

.resource-rail {
  flex: 1;
  justify-content: space-around;
  min-width: 0;
}

.metric {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 2px;
  min-width: 0;
  color: var(--muted);
  font-size: calc(10px * var(--scale));
  line-height: 1;
}

.metric b { font-weight: 700; color: var(--bone); }
.metric.scrap b { color: var(--safety); }
.metric.parts b { color: var(--ghost); }
.metric.organics b { color: var(--slime); }
.metric.focus b { color: var(--ghost); }

.icon {
  width: 20px;
  height: 20px;
  flex: 0 0 20px;
  display: inline-block;
  background-image: url("../../assets/art/ui/ui_icons.png");
  background-size: 80px 80px;
  image-rendering: pixelated;
}

.i-scrap { background-position: 0 0; }
.i-parts { background-position: -20px 0; }
.i-organics { background-position: -40px 0; }
.i-momentum { background-position: -60px 0; }
.i-streak { background-position: 0 -20px; }
.i-field { background-position: -20px -20px; }
.i-crew { background-position: -40px -20px; }
.i-base { background-position: -60px -20px; }
.i-archive { background-position: 0 -40px; }
.i-settings { background-position: -20px -40px; }
.i-safe { background-position: -40px -40px; }
.i-fast { background-position: -60px -40px; }
.i-investigate { background-position: 0 -60px; }
.i-all_hands { background-position: -20px -60px; }
.i-locked { background-position: -40px -60px; }
.i-inspected { background-position: -60px -60px; }

.page-host {
  min-height: 0;
  overflow: hidden;
  background: var(--stone-900);
}

.page-scroll {
  height: 100%;
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 8px 8px 18px;
  scrollbar-color: var(--steel-650) var(--stone-900);
}

.field-page {
  height: 100%;
  display: grid;
  grid-template-rows: var(--world-height) 58px minmax(0, 1fr);
  gap: 5px;
  padding: 6px;
  overflow: hidden;
}

.world-stage {
  position: relative;
  overflow: hidden;
  min-height: 0;
  border: 3px solid var(--safety);
  background: #182126;
  box-shadow:
    inset 0 0 0 2px #0d1214,
    inset 0 0 0 4px #53666a;
  image-rendering: pixelated;
}

.world-stage::before,
.world-stage::after,
.pixel-panel::before,
.pixel-panel::after,
.selected::before,
.selected::after {
  content: "";
  position: absolute;
  width: 6px;
  height: 6px;
  border-color: var(--safety);
  pointer-events: none;
  z-index: 8;
}

.world-stage::before,
.pixel-panel::before,
.selected::before { left: 2px; top: 2px; border-left: 2px solid; border-top: 2px solid; }
.world-stage::after,
.pixel-panel::after,
.selected::after { right: 2px; bottom: 2px; border-right: 2px solid; border-bottom: 2px solid; }

.stage-head {
  position: absolute;
  inset: 0 0 auto 0;
  z-index: 6;
  min-height: 30px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 4px 8px;
  background: #183f43;
  border-bottom: 2px solid #0d1214;
  font-size: calc(13px * var(--scale));
}

.stage-head strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stage-state { color: var(--ghost); font-size: calc(11px * var(--scale)); white-space: nowrap; }
.stage-state.danger { color: #f29b91; }
.stage-state.success { color: var(--success); }

.room-scene {
  position: absolute;
  inset: 30px 0 0;
  background-image: url("../../assets/art/chapter_01/rust_gate_rooms.png");
  background-repeat: no-repeat;
  background-size: 200% 200%;
  background-position: 0 0;
  image-rendering: pixelated;
}

.room-scene[data-room="loaded_vat"] { background-position: 100% 0; }
.room-scene[data-room="pump_station"] { background-position: 0 100%; }
.room-scene[data-room="drain_shaft"] { background-position: 100% 100%; }

.service-ceiling {
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 42%;
  border-bottom: 7px solid #4a5558;
  background: #182126;
  opacity: .44;
}

.service-ceiling::before {
  content: "";
  position: absolute;
  left: 7%;
  right: 7%;
  top: 18px;
  height: 8px;
  border: 3px solid #5c6868;
  border-inline-color: transparent;
}

.stage-object {
  position: absolute;
  z-index: 3;
  left: 23%;
  bottom: 19px;
  width: 128px;
  height: 128px;
  object-fit: contain;
  image-rendering: pixelated;
  transform-origin: 50% 100%;
  transition: opacity 150ms steps(2, end), transform 150ms steps(2, end);
}

.stage-object.cleaning { opacity: .68; transform: scale(.75); }
.stage-object.cleared { opacity: 0; transform: scale(.5); }
.stage-object.hit { animation: object-hit 160ms steps(2, end); }

@keyframes object-hit {
  0% { transform: translateX(0); }
  33% { transform: translateX(-6px); }
  66% { transform: translateX(6px); }
  100% { transform: translateX(0); }
}

.crew-sprite {
  position: absolute;
  z-index: 4;
  right: 17%;
  bottom: 38px;
  width: 48px;
  height: 48px;
  background-image: url("../../assets/art/chapter_01/crew_actions.png");
  background-size: 240px 288px;
  image-rendering: pixelated;
  transform: scale(2);
  transform-origin: 50% 100%;
}

.crew-pip { --crew-row: 0px; }
.crew-glob { --crew-row: -48px; }
.crew-rattle { --crew-row: -96px; }
.crew-tick { --crew-row: -144px; }
.crew-sparks { --crew-row: -192px; }
.crew-mori { --crew-row: -240px; }
.crew-idle { background-position: 0 var(--crew-row); }
.crew-walk { background-position: -48px var(--crew-row); }
.crew-work { background-position: -96px var(--crew-row); animation: crew-work 650ms steps(2, end) infinite; }
.crew-react { background-position: -144px var(--crew-row); }
.crew-complete { background-position: -192px var(--crew-row); }

@keyframes crew-work {
  0%, 100% { margin-bottom: 0; }
  50% { margin-bottom: 4px; }
}

.work-zone {
  position: absolute;
  z-index: 2;
  left: 12%;
  right: 10%;
  bottom: 20px;
  height: 52px;
  border-top: 6px dashed var(--safety);
  opacity: 0;
}
.working .work-zone,
.failure .work-zone,
.recovery .work-zone { opacity: 1; }

.flood-line {
  position: absolute;
  z-index: 2;
  left: 0;
  right: 0;
  bottom: 0;
  height: var(--flood-height, 14%);
  background: #326b73;
  border-top: 4px solid var(--ghost);
  opacity: .68;
  transition: height 240ms steps(4, end);
}

.risk-marker {
  position: absolute;
  z-index: 5;
  right: 7px;
  top: 38px;
  min-width: 82px;
  padding: 4px 6px;
  color: var(--safety);
  background: #251b18;
  border: 2px solid var(--danger);
  font-size: calc(10px * var(--scale));
  text-align: center;
}

.completion-plate {
  position: absolute;
  z-index: 5;
  right: 22px;
  bottom: 54px;
  width: 56px;
  height: 56px;
  display: grid;
  place-items: center;
  background: var(--inspection);
  border: 4px solid #173e59;
  color: white;
  font-size: 34px;
  font-weight: 800;
}

.stage-footer {
  position: absolute;
  z-index: 7;
  left: 6px;
  right: 6px;
  bottom: 5px;
}

.progress-track,
.meter-track {
  height: 8px;
  background: #101719;
  border: 1px solid var(--steel-650);
  overflow: hidden;
}

.progress-fill,
.meter-fill {
  height: 100%;
  background: var(--inspection);
  transition: width 200ms steps(5, end);
}

.stage-facts {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-bottom: 3px;
  color: var(--bone);
  font-size: calc(9px * var(--scale));
  text-shadow: 1px 1px #000;
}

.room-rail {
  gap: 4px;
  width: 100%;
  min-width: 0;
  overflow: hidden;
}

.room-node {
  position: relative;
  flex: 1;
  min-width: 0;
  height: 56px;
  padding: 3px;
  border: 2px solid #35474d;
  background: #11191c;
  color: var(--muted);
  overflow: hidden;
}

.room-node[aria-current="true"] { border-color: var(--safety); color: var(--bone); }
.room-node.locked { opacity: .58; }
.room-thumb {
  position: absolute;
  inset: 3px;
  background-image: url("../../assets/art/chapter_01/rust_gate_rooms.png");
  background-size: 200% 200%;
  background-position: 0 0;
  opacity: .6;
  image-rendering: pixelated;
}
.room-node:nth-child(2) .room-thumb { background-position: 100% 0; }
.room-node:nth-child(3) .room-thumb { background-position: 0 100%; }
.room-node:nth-child(4) .room-thumb { background-position: 100% 100%; }
.room-node span:last-child {
  position: relative;
  z-index: 2;
  display: block;
  margin-top: 27px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: calc(9px * var(--scale));
  line-height: 1;
  text-shadow: 1px 1px #000;
}

.decision-band {
  min-height: 0;
  overflow-y: auto;
  padding: 8px 8px 70px;
  border: 2px solid #35474d;
  background: var(--steel-800);
}

.decision-band h2,
.section-title,
.modal-title {
  margin: 0;
  color: var(--bone);
  font-size: calc(15px * var(--scale));
  line-height: 1.15;
}

.decision-band p,
.modal-copy,
.page-copy,
.card-copy {
  margin: 4px 0;
  color: var(--muted);
  font-size: calc(12px * var(--scale));
  line-height: 1.35;
}

.status-line {
  justify-content: space-between;
  gap: 8px;
  margin: 6px 0;
  font-size: calc(11px * var(--scale));
}

.status-line .danger { color: #f29b91; }
.status-line .info { color: var(--ghost); }
.status-line .success { color: var(--success); }

.choice-row { gap: 5px; margin-top: 7px; }
.choice-row > * { flex: 1; min-width: 0; }

.pixel-button,
.nav-button,
.segment,
.icon-button {
  position: relative;
  border: 2px solid var(--steel-650);
  border-radius: 2px;
  background: #273139;
  color: var(--bone);
  min-height: 46px;
  padding: 7px 8px;
  cursor: pointer;
  box-shadow: inset 2px 2px 0 #53666a, inset -2px -2px 0 #11181b;
}

.pixel-button:hover,
.pixel-button:focus-visible,
.nav-button:hover,
.segment:hover { border-color: var(--safety); outline: 0; }
.pixel-button:active,
.nav-button:active,
.segment:active { transform: translateY(2px); box-shadow: inset 2px 2px 0 #11181b; }

.pixel-button.primary {
  width: auto;
  display: block;
  min-height: 52px;
  margin-top: 8px;
  background: #c99232;
  color: #1b1915;
  border-color: #1b1915;
  border-top: 5px dashed #f6d26d;
  font-weight: 800;
}

.pixel-button.danger { border-color: var(--danger); color: #f6b3ab; }
.pixel-button.success { border-color: var(--success); color: var(--success); }
.pixel-button.selected,
.segment.active,
.nav-button.active { border-color: var(--safety); background: #183f43; color: #fff0a3; }

.pixel-button:disabled,
.pixel-button.locked,
.nav-button:disabled {
  cursor: not-allowed;
  color: #777e86;
  border-color: #343940;
  background: #202329;
  box-shadow: inset 2px 2px 0 #343940;
  transform: none;
}

.button-label {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 5px;
  overflow-wrap: anywhere;
}

.button-sub {
  display: block;
  margin-top: 2px;
  color: currentColor;
  opacity: .78;
  font-size: calc(9px * var(--scale));
  line-height: 1.15;
}

.bottom-nav {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 2px;
  min-height: calc(var(--nav-height) + var(--safe-bottom));
  padding: 2px 3px var(--safe-bottom);
  background: var(--steel-850);
  border-top: 2px solid #0b1012;
  overflow: hidden;
  z-index: 9;
}

.nav-button {
  min-width: 0;
  min-height: 54px;
  padding: 3px 1px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1px;
  font-size: calc(9px * var(--scale));
}

.nav-button .icon { width: 20px; height: 20px; }

.page-heading {
  margin: 0 0 8px;
  font-size: calc(18px * var(--scale));
}

.section-block {
  position: relative;
  padding: 10px 0 12px;
  border-bottom: 2px solid #35474d;
}
.section-block:last-child { border-bottom: 0; }

.employee-list,
.facility-list,
.archive-list { display: grid; gap: 8px; }

.employee-card,
.facility-card,
.archive-entry {
  position: relative;
  display: grid;
  grid-template-columns: auto minmax(0, 1fr) auto;
  align-items: center;
  gap: 8px;
  padding: 8px;
  border: 2px solid #35474d;
  background: #202b30;
}

.employee-card.selected,
.facility-card.selected { border-color: var(--safety); }
.facility-card { grid-template-columns: minmax(0, 1fr) auto; }
.archive-entry { grid-template-columns: minmax(0, 1fr) auto; }

.sprite-portrait {
  position: relative;
  width: 58px;
  height: 58px;
  overflow: hidden;
  border: 2px solid var(--steel-650);
  background: #172126;
}
.sprite-portrait .crew-sprite { right: 5px; bottom: 3px; transform: scale(1); }

.employee-name,
.facility-name { font-size: calc(14px * var(--scale)); font-weight: 700; }
.employee-role,
.facility-effect,
.archive-meta { color: var(--muted); font-size: calc(10px * var(--scale)); line-height: 1.3; }
.employee-metrics { gap: 8px; margin-top: 4px; font-size: calc(10px * var(--scale)); }
.employee-metrics .positive { color: var(--success); }

.segmented {
  gap: 3px;
  margin: 0 0 10px;
}
.segment { flex: 1; min-width: 0; min-height: 44px; padding: 5px 4px; font-size: calc(11px * var(--scale)); }

.rule-grid { display: grid; gap: 10px; }
.rule-group { padding-bottom: 8px; border-bottom: 1px solid #35474d; }
.rule-group legend { padding: 0; margin-bottom: 5px; color: var(--muted); font-size: calc(11px * var(--scale)); }
.rule-group fieldset { border: 0; padding: 0; margin: 0; }

.toggle {
  width: 48px;
  height: 28px;
  padding: 3px;
  border: 2px solid var(--steel-650);
  background: #202329;
  cursor: pointer;
}
.toggle::before {
  content: "";
  display: block;
  width: 18px;
  height: 18px;
  background: #777e86;
  transition: transform 120ms steps(2, end);
}
.toggle[aria-pressed="true"] { border-color: var(--success); }
.toggle[aria-pressed="true"]::before { background: var(--success); transform: translateX(20px); }

.setting-row {
  min-height: 54px;
  padding: 8px 0;
  border-bottom: 1px solid #35474d;
}
.setting-copy strong { display: block; font-size: calc(13px * var(--scale)); }
.setting-copy span { display: block; color: var(--muted); font-size: calc(10px * var(--scale)); }

.select-control,
.range-control {
  min-height: 44px;
  background: #202b30;
  color: var(--bone);
  border: 2px solid var(--steel-650);
}
.select-control { min-width: 118px; padding: 5px; }
.range-control { width: 126px; accent-color: var(--safety); }

.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: grid;
  place-items: end center;
  padding: max(12px, env(safe-area-inset-top)) 6px max(8px, env(safe-area-inset-bottom));
  background: rgb(7 11 13 / 76%);
}

.modal {
  position: relative;
  width: min(100%, 420px);
  max-height: min(82dvh, 680px);
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  border: 3px solid var(--safety);
  background: var(--steel-800);
  box-shadow: inset 0 0 0 2px #0d1214;
}
.modal.danger { border-color: var(--danger); }
.modal.success { border-color: var(--success); }

.modal-head { padding: 12px 12px 8px; border-bottom: 2px solid #35474d; }
.modal-body { min-height: 0; overflow-y: auto; padding: 10px 12px; }
.modal-actions { gap: 6px; padding: 8px 10px 10px; border-top: 2px solid #35474d; }
.modal-actions .pixel-button { flex: 1; }

.compare-grid { display: grid; gap: 7px; }
.compare-option {
  position: relative;
  padding: 8px;
  border: 2px solid #35474d;
  background: #1b2529;
}
.compare-option.selected { border-color: var(--safety); }
.compare-option h3 { margin: 0 0 4px; font-size: calc(14px * var(--scale)); }
.compare-facts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 8px; font-size: calc(10px * var(--scale)); }
.compare-facts span:nth-child(odd) { color: var(--muted); }

.reset-report { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }
.reset-column { padding: 8px; border: 2px solid #35474d; background: #172126; }
.reset-column.keep { border-color: var(--success); }
.reset-column.reset { border-color: var(--danger); }
.reset-column h3 { margin: 0 0 5px; font-size: calc(12px * var(--scale)); }
.reset-column ul { margin: 0; padding-left: 17px; color: var(--muted); font-size: calc(10px * var(--scale)); }

.toast {
  position: fixed;
  z-index: 50;
  top: calc(68px + env(safe-area-inset-top));
  left: 50%;
  width: min(330px, calc(100% - 24px));
  padding: 8px 10px;
  transform: translate(-50%, -14px);
  opacity: 0;
  pointer-events: none;
  text-align: center;
  background: #303740;
  border: 2px solid var(--ghost);
  color: var(--bone);
  transition: opacity 120ms steps(2, end), transform 120ms steps(2, end);
  font-size: calc(11px * var(--scale));
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }

.hidden { display: none !important; }
.muted { color: var(--muted); }
.danger-text { color: #f29b91; }
.success-text { color: var(--success); }
.info-text { color: var(--ghost); }
.safety-text { color: var(--safety); }
.small { font-size: calc(10px * var(--scale)); }
.mono { font-variant-numeric: tabular-nums; }

body[data-reduced-motion="true"] *,
body[data-low-power="true"] * {
  animation: none !important;
  transition: none !important;
}

body[data-reduced-flashes="true"] .risk-marker { color: var(--bone); border-color: var(--steel-650); }

@media (max-width: 374px) {
  :root { --world-height: clamp(278px, 38.5vh, 304px); }
  .top-bar { min-height: calc(72px + var(--safe-top)); padding-inline: 5px; }
  .field-page { padding: 5px; }
  .decision-band { padding-inline: 6px; }
  .stage-object { left: 17%; }
  .crew-sprite { right: 15%; }
  .button-sub { display: none; }
}

@media (min-width: 420px) and (min-height: 900px) {
  :root { --world-height: 350px; }
  .decision-band { padding-top: 10px; }
}

@media (orientation: landscape) {
  body::before {
    content: "Portrait layout required";
    position: fixed;
    inset: 0;
    z-index: 100;
    display: grid;
    place-items: center;
    background: var(--stone-950);
    color: var(--bone);
  }
}
