:root {
  color-scheme: dark;
  --bg: #060605;
  --panel: rgba(15, 13, 10, 0.94);
  --panel-soft: rgba(15, 13, 10, 0.72);
  --line: rgba(255, 226, 178, 0.14);
  --text: #fff7e8;
  --muted: #b9ae9b;
  --amber: #ffbd59;
  --amber-bright: #ffe2a2;
  --ember: #e87935;
  --danger: #e65e55;
  --health: #d96a59;
  --fuel: #e9a847;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: #050504;
  color: var(--text);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-user-select: none;
  user-select: none;
  touch-action: none;
}

body {
  width: 100%;
  height: var(--escapee-vh, 100dvh);
  background:
    radial-gradient(circle at 50% 42%, rgba(74, 50, 22, 0.19), transparent 42%),
    #050504;
}

button { font: inherit; }

#game-shell {
  position: relative;
  width: 100%;
  height: var(--escapee-vh, 100dvh);
  overflow: hidden;
  background: #080704;
  box-shadow: inset 0 0 80px rgba(0, 0, 0, 0.5);
  isolation: isolate;
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
  background: transparent;
}

.hidden { display: none !important; }

#hud {
  position: absolute;
  inset: max(12px, env(safe-area-inset-top)) 12px auto 12px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 10px;
  pointer-events: none;
  z-index: 4;
}

.hud-cluster {
  display: flex;
  flex-wrap: wrap;
  gap: 7px;
}

.chip,
.icon-button {
  border: 1px solid var(--line);
  background: rgba(9, 8, 6, 0.68);
  box-shadow: inset 0 1px 0 rgba(255,255,255,0.03), 0 8px 30px rgba(0,0,0,0.2);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.chip {
  min-width: 74px;
  padding: 7px 10px;
  border-radius: 10px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.09em;
  text-transform: uppercase;
}

.chip strong {
  display: block;
  margin-top: 2px;
  color: var(--text);
  font-size: 15px;
  letter-spacing: 0;
  text-transform: none;
}

#utility-controls {
  display: flex;
  gap: 7px;
  pointer-events: auto;
}

.icon-button {
  display: grid;
  place-items: center;
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 10px;
  color: var(--text);
  cursor: pointer;
  font-weight: 900;
  transition: transform 120ms ease, border-color 120ms ease, background 120ms ease;
}

.icon-button:hover,
.icon-button:focus-visible {
  transform: translateY(-1px);
  border-color: rgba(255, 226, 178, 0.3);
  background: rgba(33, 26, 17, 0.84);
  outline: none;
}

#status-bars {
  position: absolute;
  left: 50%;
  bottom: max(14px, env(safe-area-inset-bottom));
  width: min(410px, calc(100% - 28px));
  transform: translateX(-50%);
  padding: 9px 11px 10px;
  border: 1px solid var(--line);
  border-radius: 12px;
  background: rgba(9, 8, 6, 0.74);
  box-shadow: 0 14px 40px rgba(0,0,0,0.28);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  pointer-events: none;
  z-index: 4;
}

.bar-row + .bar-row { margin-top: 7px; }

.bar-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 4px;
  color: var(--muted);
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.bar-track {
  height: 7px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,0.08);
  box-shadow: inset 0 1px 4px rgba(0,0,0,0.42);
}

.bar-fill {
  height: 100%;
  width: 100%;
  border-radius: inherit;
  transform-origin: left;
  transition: transform 80ms linear;
}

#health-fill { background: linear-gradient(90deg, #9b3937, #e4725f); }
#fuel-fill { background: linear-gradient(90deg, #ad6727, #ffc461); box-shadow: 0 0 12px rgba(255,188,88,0.22); }

.overlay {
  position: absolute;
  inset: 0;
  z-index: 10;
  display: grid;
  place-items: center;
  padding: 22px;
  background: rgba(2, 2, 2, 0.7);
  backdrop-filter: blur(7px);
  -webkit-backdrop-filter: blur(7px);
}

.panel {
  width: min(700px, 100%);
  padding: 26px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background:
    linear-gradient(180deg, rgba(255, 210, 132, 0.035), transparent 30%),
    var(--panel);
  box-shadow: 0 24px 80px rgba(0,0,0,0.54), inset 0 1px 0 rgba(255,255,255,0.035);
  text-align: center;
}

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

h1 {
  margin-bottom: 10px;
  color: #fff2d6;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(38px, 7vw, 68px);
  font-weight: 600;
  line-height: 0.95;
  letter-spacing: -0.045em;
  text-shadow: 0 0 30px rgba(255, 175, 67, 0.19);
}

h2 {
  margin-bottom: 8px;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(27px, 5vw, 42px);
  font-weight: 600;
  letter-spacing: -0.025em;
}

.subtext {
  max-width: 560px;
  margin: 0 auto 20px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.55;
}

.instruction-line {
  color: #e2d5c0;
  font-size: clamp(14px, 2.5vw, 17px);
}

.controls-row {
  display: flex;
  justify-content: center;
  gap: 10px;
  flex-wrap: wrap;
  margin: 18px 0 23px;
}

.key {
  min-width: 40px;
  padding: 8px 10px;
  border: 1px solid rgba(255,235,202,0.18);
  border-bottom-width: 3px;
  border-radius: 8px;
  background: rgba(255,255,255,0.045);
  color: #eadcc4;
  font-size: 13px;
  font-weight: 900;
}

.button-row {
  display: flex;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px;
}

.button {
  appearance: none;
  border: 1px solid rgba(255,234,198,0.16);
  border-radius: 11px;
  padding: 12px 18px;
  background: #211a12;
  color: var(--text);
  cursor: pointer;
  font-weight: 850;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.button:hover,
.button:focus-visible {
  transform: translateY(-2px);
  background: #302318;
  border-color: rgba(255,226,178,0.32);
  outline: none;
}

.button.primary {
  border-color: transparent;
  background: var(--amber);
  color: #1a1005;
  box-shadow: 0 8px 30px rgba(255,171,57,0.15);
}

.button.primary:hover,
.button.primary:focus-visible { background: #ffd07c; }

#upgrade-cards {
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 12px;
  margin-top: 21px;
}

.upgrade-card {
  min-height: 162px;
  padding: 17px 14px;
  border: 1px solid rgba(255,230,190,0.12);
  border-radius: 13px;
  background: rgba(255,255,255,0.035);
  color: var(--text);
  cursor: pointer;
  text-align: left;
  transition: transform 120ms ease, background 120ms ease, border-color 120ms ease;
}

.upgrade-card:hover,
.upgrade-card:focus-visible {
  transform: translateY(-3px);
  border-color: rgba(255,190,91,0.38);
  background: rgba(255,187,86,0.075);
  outline: none;
}

.upgrade-number {
  display: inline-grid;
  place-items: center;
  width: 27px;
  height: 27px;
  margin-bottom: 17px;
  border-radius: 8px;
  background: rgba(255,185,82,0.11);
  color: var(--amber);
  font-size: 11px;
  font-weight: 900;
}

.upgrade-card strong {
  display: block;
  margin-bottom: 7px;
  color: #fff0d3;
  font-size: 17px;
}

.upgrade-card .description {
  display: block;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.4;
}

.upgrade-card .current {
  display: block;
  margin-top: 11px;
  color: #d9a85f;
  font-size: 10px;
  font-weight: 800;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

#toast {
  position: absolute;
  top: 78px;
  left: 50%;
  z-index: 5;
  transform: translate(-50%, -8px);
  padding: 8px 13px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(9,8,6,0.86);
  color: #fff0d4;
  opacity: 0;
  pointer-events: none;
  font-size: 12px;
  font-weight: 850;
  transition: opacity 180ms ease, transform 180ms ease;
}

#toast.show { opacity: 1; transform: translate(-50%, 0); }

#touch-stick {
  position: absolute;
  left: max(18px, env(safe-area-inset-left));
  bottom: max(91px, calc(env(safe-area-inset-bottom) + 78px));
  z-index: 6;
  display: none;
  width: 112px;
  height: 112px;
  border: 1px solid rgba(255,230,190,0.12);
  border-radius: 50%;
  background: rgba(10,9,7,0.3);
  box-shadow: inset 0 0 30px rgba(0,0,0,0.24);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  touch-action: none;
}

#touch-knob {
  position: absolute;
  left: 50%;
  top: 50%;
  width: 46px;
  height: 46px;
  transform: translate(-50%, -50%);
  border: 1px solid rgba(255,233,199,0.22);
  border-radius: 50%;
  background: rgba(255,187,82,0.16);
  box-shadow: 0 5px 18px rgba(0,0,0,0.28), inset 0 1px 0 rgba(255,255,255,0.08);
}

@media (pointer: coarse), (max-width: 760px) {
  #touch-stick { display: block; }
  #status-bars { bottom: max(10px, env(safe-area-inset-bottom)); }
  #upgrade-cards { grid-template-columns: 1fr; }
  .upgrade-card { min-height: 0; }
  .panel { max-height: 92dvh; overflow-y: auto; padding: 22px 18px; }
  .chip { min-width: 62px; padding: 6px 8px; font-size: 9px; }
  .chip strong { font-size: 13px; }
  #toast { top: 68px; }
}

@media (max-width: 430px) {
  #hud { inset-inline: 8px; }
  .hud-cluster { gap: 5px; }
  .chip { min-width: 55px; }
  .overlay { padding: 13px; }
}

@media (pointer: coarse) and (orientation: landscape) and (max-height: 500px) {
  #touch-stick {
    width: 92px;
    height: 92px;
    left: max(12px, env(safe-area-inset-left));
    bottom: max(12px, env(safe-area-inset-bottom));
  }
  #touch-knob { width: 40px; height: 40px; }
  #status-bars {
    width: min(360px, calc(100% - 230px));
    bottom: max(8px, env(safe-area-inset-bottom));
  }
  #hud { inset-block-start: max(8px, env(safe-area-inset-top)); }
  .panel { max-height: calc(var(--escapee-vh, 100dvh) - 18px); }
}

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