:root {
  color-scheme: dark;
  --ink: #f2f3db;
  --muted: #aeb58e;
  --panel: #22251d;
  --panel-dark: #151713;
  --line: #424833;
  --accent: #f3bd4e;
  --danger: #d86745;
}

* {
  box-sizing: border-box;
}

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

body {
  background: #172017;
  color: var(--ink);
  font-family: "Courier New", Courier, monospace;
  min-height: 100%;
  overflow: hidden;
}

button,
canvas {
  font: inherit;
}

.game-shell {
  display: grid;
  grid-template-rows: auto 1fr;
  height: 100vh;
  position: relative;
  width: 100vw;
}

.game-shell.is-title {
  grid-template-rows: 1fr;
}

.game-shell.is-title .hud {
  display: none;
}

.hud {
  align-items: center;
  background: rgba(34, 37, 29, 0.94);
  border: 0;
  box-shadow: 0 4px 0 #0b0d09;
  display: flex;
  min-height: 48px;
}

.hud {
  gap: 18px;
  justify-content: space-between;
  min-height: 74px;
  padding: 10px 12px;
  z-index: 2;
}

.hud-resources,
.hud-resources div {
  display: grid;
  gap: 3px;
  min-width: 104px;
}

.hud-resources {
  display: flex;
  gap: 18px;
  justify-content: flex-end;
  margin-left: auto;
}

.hud-vitals {
  display: grid;
  gap: 8px;
  min-width: 320px;
  width: min(48vw, 460px);
}

.meter-row {
  align-items: center;
  display: grid;
  gap: 8px;
  grid-template-columns: 108px 1fr;
}

.label {
  color: var(--muted);
  font-size: clamp(16px, 2.2vw, 20px);
  font-weight: 700;
  line-height: 1;
  text-transform: uppercase;
}

.label-health {
  color: #ff5d4f;
}

.label-stamina {
  color: #5df067;
}

.label-cash {
  color: #ffd75a;
}

.label-wood {
  color: #d99a50;
}

.hud strong {
  color: var(--accent);
  font-size: clamp(22px, 3vw, 30px);
  line-height: 1;
  min-width: 84px;
}

.meter {
  background: #11150f;
  border: 2px solid var(--line);
  height: 18px;
  overflow: hidden;
}

.meter span {
  display: block;
  height: 100%;
  transition: width 120ms linear;
  width: 100%;
}

.health-meter span {
  background: #c93f35;
}

.stamina-meter span {
  background: #4fbf48;
}

#game {
  background: #173520;
  display: block;
  height: 100%;
  image-rendering: pixelated;
  min-height: 0;
  width: 100%;
}

.menu-overlay {
  align-items: center;
  background: rgba(12, 15, 10, 0.72);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 20px;
  position: absolute;
  z-index: 5;
}

.menu-overlay[hidden],
.controls-panel[hidden],
.settings-panel[hidden] {
  display: none;
}

.menu-panel {
  background: var(--panel);
  border: 2px solid var(--line);
  box-shadow: 0 8px 0 #0b0d09;
  display: grid;
  gap: 14px;
  max-width: 420px;
  padding: 18px;
  width: min(100%, 420px);
}

.menu-panel h1 {
  color: var(--accent);
  font-size: 24px;
  line-height: 1;
  margin: 0;
}

.title-overlay {
  align-items: stretch;
  background: linear-gradient(rgba(10, 14, 9, 0.18), rgba(10, 14, 9, 0.62));
  justify-content: stretch;
  z-index: 8;
}

.title-brand {
  left: 28px;
  position: absolute;
  top: 24px;
  text-shadow: 3px 3px 0 #0b0d09;
  width: min(560px, calc(100vw - 56px));
}

.title-brand h1 {
  color: var(--accent);
  font-size: clamp(36px, 6vw, 70px);
  line-height: 0.98;
  margin: 0 0 12px;
}

.title-panel {
  bottom: 26px;
  left: 50%;
  position: absolute;
  transform: translateX(-50%);
  max-width: 760px;
  width: min(calc(100vw - 40px), 760px);
}

.title-panel > .menu-actions {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.menu-status {
  color: var(--muted);
  margin: 0;
}

.menu-actions {
  display: grid;
  gap: 8px;
}

.menu-actions button {
  background: #38412b;
  border: 2px solid #6d7b48;
  color: var(--ink);
  cursor: pointer;
  min-height: 40px;
  padding: 6px 12px;
  text-align: left;
}

.menu-actions button:focus-visible,
.menu-actions button:hover {
  border-color: var(--accent);
  outline: none;
}

.controls-panel {
  border-bottom: 2px solid var(--line);
  display: grid;
  gap: 8px;
  padding-bottom: 12px;
}

.settings-panel {
  border-bottom: 2px solid var(--line);
  display: grid;
  gap: 8px;
  padding-bottom: 12px;
}

.settings-panel label {
  align-items: center;
  color: var(--muted);
  display: flex;
  justify-content: space-between;
  text-transform: uppercase;
}

.settings-panel input {
  accent-color: var(--accent);
  height: 20px;
  width: 20px;
}

.controls-panel div {
  align-items: baseline;
  display: flex;
  gap: 12px;
  justify-content: space-between;
}

.controls-panel span {
  color: var(--muted);
  text-transform: uppercase;
}

.controls-panel strong {
  color: var(--ink);
  font-size: 14px;
  text-align: right;
}

.shop-panel {
  gap: 10px;
  max-height: calc(100vh - 40px);
  max-width: 900px;
  overflow: auto;
  width: min(100%, 900px);
}

.shop-panel > .menu-actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.bus-panel {
  max-width: 460px;
  width: min(100%, 460px);
}

.dialogue-overlay {
  align-items: flex-end;
  background: transparent;
  justify-content: center;
  padding: 0 24px 28px;
  pointer-events: none;
}

.dialogue-panel {
  background: #f0d6a4;
  border: 4px solid #151713;
  box-shadow: 0 0 0 4px #f6c45e, 0 8px 0 rgba(0, 0, 0, 0.42);
  color: #2a1c15;
  display: grid;
  gap: 10px;
  max-width: 860px;
  min-height: 112px;
  padding: 14px 16px 16px;
  pointer-events: auto;
  width: min(100%, 860px);
}

.dialogue-panel h1 {
  color: #5f341f;
  font-size: 16px;
  line-height: 1;
  margin: 0;
  text-transform: uppercase;
}

.dialogue-panel p {
  color: #21160f;
  font-size: 20px;
  font-weight: 700;
  margin: 0;
  min-height: 26px;
}

.dialogue-actions {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  justify-self: end;
  width: min(100%, 430px);
}

.dialogue-actions button {
  background: #5f341f;
  border: 3px solid #21160f;
  box-shadow: inset 0 0 0 2px #f6c45e;
  color: #f6e5a4;
  cursor: pointer;
  min-height: 40px;
  padding: 6px 12px;
  text-align: left;
}

.dialogue-actions button:focus-visible,
.dialogue-actions button:hover {
  background: #7a4429;
  outline: 3px solid #f6c45e;
  outline-offset: 2px;
}

.bus-end-overlay {
  background: #000;
}

.inventory-panel {
  max-width: 620px;
  width: min(100%, 620px);
}

.shop-summary,
.inventory-summary {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

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

.shop-summary div,
.inventory-summary div {
  background: var(--panel-dark);
  border: 2px solid var(--line);
  display: grid;
  gap: 2px;
  padding: 8px;
}

.shop-summary span,
.inventory-summary span {
  color: var(--muted);
  font-size: 12px;
  text-transform: uppercase;
}

.shop-summary strong,
.inventory-summary strong {
  color: var(--accent);
  font-size: 22px;
}

.shop-grid {
  display: grid;
  gap: 8px;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
}

.shop-item,
.shop-ticket,
.shop-upgrade {
  background: #2c3323;
  border: 2px solid #5e6d3d;
  color: var(--ink);
  cursor: pointer;
  display: grid;
  gap: 4px;
  min-height: 62px;
  padding: 8px 10px;
  text-align: left;
}

.shop-item strong,
.shop-ticket strong,
.shop-upgrade strong {
  color: var(--accent);
}

.shop-item span,
.shop-ticket span,
.shop-upgrade span {
  color: var(--muted);
  font-size: 13px;
}

.shop-item em,
.shop-ticket em,
.shop-upgrade em {
  color: var(--ink);
  font-style: normal;
}

.shop-ticket strong {
  align-items: center;
  display: flex;
  gap: 8px;
}

.ticket-lock {
  display: none;
  height: 14px;
  position: relative;
  width: 14px;
}

.ticket-lock::before {
  border: 2px solid currentColor;
  border-bottom: 0;
  content: "";
  height: 7px;
  left: 2px;
  position: absolute;
  top: 0;
  width: 8px;
}

.ticket-lock::after {
  background: currentColor;
  box-shadow: inset 0 -3px 0 rgba(0, 0, 0, 0.28);
  content: "";
  height: 8px;
  left: 0;
  position: absolute;
  top: 6px;
  width: 14px;
}

.shop-ticket.is-locked .ticket-lock {
  display: inline-block;
}

.shop-item:focus-visible,
.shop-item:hover,
.shop-ticket:focus-visible,
.shop-ticket:hover,
.shop-upgrade:focus-visible,
.shop-upgrade:hover {
  border-color: var(--accent);
  outline: none;
}

.shop-item:disabled,
.shop-ticket:disabled,
.shop-upgrade:disabled,
.menu-actions button:disabled {
  border-color: #3a422c;
  color: #7c8466;
  cursor: default;
}

.shop-item:disabled strong,
.shop-item:disabled span,
.shop-item:disabled em,
.shop-ticket:disabled strong,
.shop-ticket:disabled span,
.shop-ticket:disabled em,
.shop-upgrade:disabled strong,
.shop-upgrade:disabled span,
.shop-upgrade:disabled em {
  color: #7c8466;
}

@media (max-width: 640px) {
  .hud {
    gap: 8px;
    min-height: 70px;
    padding: 8px;
  }

  .hud-resources {
    gap: 8px;
  }

  .hud-resources div {
    min-width: 64px;
  }

  .hud-vitals {
    min-width: 188px;
    width: 50vw;
  }

  .meter-row {
    grid-template-columns: 78px 1fr;
  }

  .hud strong {
    font-size: 18px;
    min-width: 64px;
  }

  .controls-panel div {
    align-items: flex-start;
    display: grid;
    gap: 2px;
  }

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