:root {
  color-scheme: dark;
  --black: #020406;
  --panel: rgba(5, 9, 12, .92);
  --gold: #d6a34a;
  --gold-bright: #ffd77f;
  --cream: #fff5dc;
  --muted: #9ba7af;
  --danger: #ff4a68;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
}

* { box-sizing: border-box; }
html, body { width: 100%; height: 100%; margin: 0; overflow: hidden; background: var(--black); }
body { color: var(--cream); font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif; overscroll-behavior: none; }
button, a { -webkit-tap-highlight-color: transparent; }
button:focus-visible, a:focus-visible { outline: 3px solid var(--gold-bright); outline-offset: 3px; }

.game-app {
  width: 100%;
  height: 100vh;
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  padding-left: var(--safe-left);
  padding-right: var(--safe-right);
  background: #020406;
}

.game-bar {
  min-height: calc(58px + var(--safe-top));
  padding: calc(.55rem + var(--safe-top)) .8rem .55rem;
  display: grid;
  grid-template-columns: minmax(72px, 1fr) auto minmax(72px, 1fr);
  align-items: center;
  gap: .6rem;
  border-bottom: 1px solid rgba(255, 215, 127, .18);
  background: rgba(2, 4, 6, .96);
  z-index: 30;
}

.back-link { min-height: 40px; display: inline-flex; align-items: center; color: #bec6cb; font-size: .82rem; font-weight: 750; letter-spacing: .04em; text-decoration: none; text-transform: uppercase; }
.game-brand { min-width: 0; display: flex; align-items: center; justify-content: center; gap: .55rem; text-align: left; }
.brand-mark { width: 36px; height: 36px; position: relative; flex: none; overflow: hidden; border: 1px solid rgba(255, 215, 127, .45); border-radius: 50%; background: #050505; }
.brand-mark img { position: absolute; width: 78px; max-width: none; left: -21px; top: -34px; }
.game-brand strong, .game-brand small { display: block; white-space: nowrap; }
.game-brand strong { color: var(--gold-bright); font-size: .82rem; letter-spacing: .14em; }
.game-brand small { margin-top: .08rem; color: #7e8b93; font-size: .55rem; letter-spacing: .18em; }
.bar-actions { display: flex; justify-content: flex-end; gap: .4rem; }
.icon-button { width: 42px; height: 42px; border: 1px solid rgba(255, 215, 127, .3); border-radius: 50%; background: #090e12; color: var(--gold-bright); font: 800 1rem/1 ui-sans-serif, system-ui, sans-serif; cursor: pointer; }
.graphics-button { font-size: .66rem; letter-spacing: .05em; }
.graphics-button.is-low { border-color: rgba(155, 167, 175, .38); color: #9ba7af; box-shadow: none; }
.audio-button { font-size: .88rem; }
.audio-button.is-muted { border-color: rgba(155, 167, 175, .38); color: #78858d; box-shadow: none; }

.game-stage { position: relative; min-height: 0; overflow: hidden; touch-action: none; user-select: none; -webkit-user-select: none; background: #020406; }
.game-stage.is-underground { background: #010506; }
.game-stage.is-underground .progress-track span { background: linear-gradient(90deg, #3c8f87, #68d4c6, var(--gold-bright)); box-shadow: 0 0 12px #68d4c6; }
.game-stage.is-underground .jump-control,
.game-stage.is-underground .dash-control { border-color: rgba(104, 212, 198, .72); box-shadow: 0 10px 28px rgba(0, 0, 0, .5), inset 0 1px rgba(104, 212, 198, .16); }
#game-canvas { position: absolute; inset: 0; touch-action: none; }
#game-canvas canvas { display: block; width: 100% !important; height: 100% !important; touch-action: none; }

.hud { position: absolute; z-index: 12; inset: .75rem .75rem auto; display: grid; grid-template-columns: repeat(5, 1fr); gap: .38rem; pointer-events: none; }
.hud-stat { display: flex; flex-direction: column; align-items: flex-start; text-shadow: 0 1px 8px #000; }
.hud-center { align-items: center; }
.hud-right { align-items: flex-end; }
.hud-stat span { color: #8e9aa2; font-size: clamp(.52rem, 2vw, .65rem); font-weight: 800; letter-spacing: .16em; }
.hud-stat strong { color: var(--cream); font-size: clamp(.94rem, 4vw, 1.2rem); font-variant-numeric: tabular-nums; letter-spacing: .05em; }
.shield-meter { min-height: 24px; display: flex; align-items: center; justify-content: center; gap: .28rem; }
.shield-badge { width: 24px; height: 26px; display: block; overflow: hidden; background: #fff; clip-path: polygon(50% 0, 92% 16%, 82% 75%, 50% 100%, 18% 75%, 8% 16%); filter: drop-shadow(0 0 6px rgba(104, 212, 198, .68)); }
.shield-badge[hidden] { display: none; }
.shield-badge img { width: 34px; height: 34px; margin-left: -5px; object-fit: cover; object-position: 50% 16%; }
.shield-stat small { color: #68d4c6; font-size: clamp(.42rem, 1.6vw, .53rem); font-weight: 850; letter-spacing: .08em; line-height: 1; text-shadow: 0 1px 8px #000; }
.progress-track { grid-column: 1 / -1; height: 2px; overflow: hidden; background: rgba(255, 255, 255, .12); }
.progress-track span { width: 0; height: 100%; display: block; background: linear-gradient(90deg, var(--gold), var(--gold-bright)); box-shadow: 0 0 12px var(--gold-bright); transition: width .1s linear; }

.mission-callout { position: absolute; z-index: 14; top: 18%; left: 50%; width: min(86vw, 520px); margin: 0; transform: translate(-50%, -8px); opacity: 0; color: var(--gold-bright); font-size: clamp(.78rem, 3vw, 1rem); font-weight: 850; letter-spacing: .14em; text-align: center; text-shadow: 0 2px 12px #000; text-transform: uppercase; pointer-events: none; transition: opacity .18s ease, transform .18s ease; }
.mission-callout.is-visible { opacity: 1; transform: translate(-50%, 0); }

.jump-control,
.dash-control {
  position: absolute;
  z-index: 16;
  bottom: max(1rem, var(--safe-bottom));
  min-width: 112px;
  min-height: 58px;
  display: grid;
  place-content: center;
  gap: .12rem;
  border: 1px solid rgba(255, 215, 127, .72);
  border-radius: 16px;
  background: linear-gradient(145deg, rgba(24, 31, 34, .92), rgba(6, 9, 11, .96));
  box-shadow: 0 10px 28px rgba(0, 0, 0, .42), inset 0 1px rgba(255, 255, 255, .08);
  color: var(--gold-bright);
  cursor: pointer;
  touch-action: manipulation;
  user-select: none;
}
.jump-control { display: none; left: 50%; transform: translateX(-50%); }
.dash-control { right: max(1rem, var(--safe-right)); }
.jump-control span,
.dash-control span { color: #87939a; font-size: .52rem; font-weight: 850; letter-spacing: .18em; }
.jump-control strong,
.dash-control strong { font-size: .78rem; letter-spacing: .12em; }
.jump-control:disabled,
.dash-control:disabled { opacity: .42; cursor: default; }
.jump-control:active { background: var(--gold-bright); color: #050708; box-shadow: 0 0 28px rgba(255, 215, 127, .62); }
.dash-control.is-active { background: var(--gold-bright); color: #050708; box-shadow: 0 0 28px rgba(255, 215, 127, .62); transform: translateX(3px); }

@media (max-width: 900px), (pointer: coarse) {
  .jump-control { display: grid; }
}

.screen-overlay { position: absolute; z-index: 20; inset: 0; display: grid; place-items: center; padding: 1rem; padding-bottom: calc(1rem + var(--safe-bottom)); opacity: 0; visibility: hidden; background: radial-gradient(circle at 50% 43%, rgba(45, 31, 9, .34), rgba(1, 3, 4, .9) 68%); backdrop-filter: blur(4px); transition: opacity .2s ease, visibility .2s ease; }
.screen-overlay.is-visible { opacity: 1; visibility: visible; }
.overlay-panel { width: min(100%, 540px); max-height: 100%; overflow: auto; padding: clamp(1.1rem, 4vw, 2rem); border: 1px solid rgba(255, 215, 127, .34); border-radius: 18px; background: linear-gradient(145deg, rgba(12, 18, 22, .96), rgba(3, 6, 8, .97)); box-shadow: 0 22px 80px rgba(0,0,0,.55), inset 0 1px rgba(255,255,255,.04); text-align: center; }
.overlay-kicker { margin: 0 0 .55rem; color: #aab3b9; font-size: .63rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
h1 { margin: 0; font-size: clamp(2rem, 9vw, 3.9rem); letter-spacing: -.055em; line-height: .96; text-transform: uppercase; }
h1 span { color: var(--gold-bright); }
.overlay-copy { max-width: 42ch; margin: 1rem auto; color: #bcc5ca; font-size: clamp(.86rem, 2.7vw, 1rem); line-height: 1.5; }
.control-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; margin: 1rem 0; }
.control-grid[hidden] { display: none; }
.control-grid div { min-width: 0; padding: .7rem .35rem; border: 1px solid rgba(255,255,255,.09); border-radius: 9px; background: rgba(255,255,255,.025); }
.control-grid b, .control-grid span { display: block; }
.control-grid b { color: var(--gold-bright); font-size: clamp(.66rem, 2.5vw, .8rem); }
.control-grid span { margin-top: .2rem; color: #8d989f; font-size: .67rem; text-transform: uppercase; }
.high-score { margin: .7rem 0; color: #79868e; font-size: .68rem; font-weight: 800; letter-spacing: .14em; }
.overlay-actions { display: flex; gap: .6rem; justify-content: center; }
.primary-button, .secondary-button { min-height: 48px; padding: .75rem 1.1rem; border-radius: 9px; font: 800 .82rem/1 ui-sans-serif, system-ui, sans-serif; letter-spacing: .06em; text-transform: uppercase; cursor: pointer; }
.primary-button { flex: 1; border: 1px solid var(--gold-bright); background: var(--gold-bright); color: #080a0c; }
.secondary-button { border: 1px solid rgba(255,255,255,.22); background: transparent; color: #e9edef; }
.overlay-note { margin: .8rem auto 0; color: #6f7c84; font-size: .62rem; line-height: 1.4; }

.game-footer { min-height: calc(32px + var(--safe-bottom)); padding: .4rem .75rem calc(.4rem + var(--safe-bottom)); display: flex; justify-content: space-between; gap: 1rem; color: #65727a; background: #020406; font-size: .58rem; font-weight: 700; letter-spacing: .08em; text-transform: uppercase; }
#runtime-status { color: #b69250; }

@media (max-width: 520px) {
  .game-bar { grid-template-columns: 54px 1fr 166px; padding-inline: .5rem; }
  .back-link { font-size: .7rem; }
  .brand-mark { display: none; }
  .game-brand strong { font-size: .72rem; }
  .game-brand small { font-size: .49rem; }
  .bar-actions { gap: .25rem; }
  .icon-button { width: 38px; height: 38px; }
  .game-footer span:last-child { display: none; }
  .game-footer { justify-content: center; }
  .jump-control, .dash-control { bottom: max(.65rem, var(--safe-bottom)); min-width: 102px; min-height: 54px; }
  .dash-control { right: max(.65rem, var(--safe-right)); }
}

@media (max-height: 560px) {
  .game-bar { min-height: calc(48px + var(--safe-top)); padding-top: calc(.3rem + var(--safe-top)); padding-bottom: .3rem; }
  .brand-mark { width: 32px; height: 32px; }
  .overlay-panel { padding: .9rem 1.1rem; }
  h1 { font-size: clamp(1.65rem, 7vh, 2.45rem); }
  .overlay-copy { margin: .55rem auto; }
  .control-grid { margin: .55rem 0; }
  .control-grid div { padding: .45rem .25rem; }
  .overlay-note { display: none; }
}

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