:root {
  color-scheme: dark;
  --night: #07152c;
  --night-2: #0b2343;
  --cloud: #f4eedc;
  --mist: #b9c8d8;
  --amber: #ffbd5d;
  --amber-hot: #ff8b38;
  --mint: #82efcf;
  --danger: #ff6757;
  --glass: rgba(7, 21, 44, 0.82);
  --line: rgba(220, 235, 239, 0.22);
  --shadow: 0 24px 80px rgba(0, 5, 19, 0.48);
  --ease: cubic-bezier(0.16, 1, 0.3, 1);
  font-family: "Avenir Next", Avenir, "Trebuchet MS", sans-serif;
  font-synthesis: none;
}

* { box-sizing: border-box; }

html,
body {
  width: 100%;
  min-width: 18rem;
  min-height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--night);
  color: var(--cloud);
}

body { min-height: 100dvh; }
button, kbd { font: inherit; }
button { touch-action: manipulation; }
[hidden] { display: none !important; }

button:focus-visible,
a:focus-visible {
  outline: 3px solid var(--mint);
  outline-offset: 4px;
}

.skip-link {
  position: fixed;
  z-index: 200;
  top: .75rem;
  left: .75rem;
  padding: .7rem 1rem;
  transform: translateY(-180%);
  border-radius: 999px;
  background: var(--cloud);
  color: var(--night);
  font-weight: 900;
}
.skip-link:focus { transform: none; }

.game-shell {
  position: relative;
  isolation: isolate;
  width: 100%;
  height: 100dvh;
  min-height: 34rem;
  overflow: hidden;
  background: var(--night);
}

#game-stage,
#game-stage canvas {
  position: absolute;
  inset: 0;
  width: 100% !important;
  height: 100% !important;
  display: block;
  touch-action: none;
}

.scene-vignette {
  position: absolute;
  z-index: 2;
  inset: 0;
  pointer-events: none;
  background:
    radial-gradient(circle at 55% 43%, transparent 35%, rgba(2, 9, 26, .24) 78%, rgba(2, 8, 21, .58) 100%),
    linear-gradient(180deg, rgba(4, 13, 32, .34), transparent 28%, rgba(4, 12, 28, .22));
}

.topbar {
  position: absolute;
  z-index: 30;
  top: 0;
  left: 0;
  right: 0;
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: start;
  gap: 1rem;
  padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) 0 max(1rem, env(safe-area-inset-left));
  pointer-events: none;
}

.brand-lockup,
.run-hud,
.utility-nav { pointer-events: auto; }

.brand-lockup {
  display: flex;
  align-items: center;
  gap: .65rem;
  min-height: 3rem;
  text-shadow: 0 2px 20px #05132c;
}
.brand-sun {
  display: grid;
  place-items: center;
  width: 2.65rem;
  height: 2.65rem;
  border: 1px solid rgba(255, 218, 145, .55);
  border-radius: 50%;
  background: rgba(8, 26, 53, .72);
  color: var(--amber);
  box-shadow: inset 0 0 22px rgba(255, 167, 59, .2), 0 0 28px rgba(255, 167, 59, .15);
  font-size: 1.3rem;
}
.brand-lockup div { display: grid; gap: .05rem; }
.brand-lockup span:not(.brand-sun) { color: var(--mist); font-size: .62rem; font-weight: 800; letter-spacing: .16em; text-transform: uppercase; }
.brand-lockup strong { font-family: Georgia, serif; font-size: 1.08rem; letter-spacing: .08em; }
.brand-lockup i { color: var(--amber); font-size: .75em; font-style: normal; }

.utility-nav { display: flex; gap: .45rem; }
.icon-button {
  display: grid;
  place-items: center;
  width: 2.9rem;
  min-width: 44px;
  height: 2.9rem;
  min-height: 44px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: var(--glass);
  color: var(--cloud);
  box-shadow: 0 8px 28px rgba(0, 7, 24, .28);
  cursor: pointer;
  font-weight: 900;
  transition: transform 140ms var(--ease), background 140ms linear;
}
.icon-button:active { transform: scale(.92); }
.icon-button[aria-pressed="true"] { background: var(--amber); color: var(--night); }

.run-hud {
  justify-self: center;
  display: grid;
  grid-template-columns: auto minmax(12rem, 22rem) auto;
  align-items: center;
  gap: clamp(.65rem, 2vw, 1.65rem);
  min-height: 4.25rem;
  padding: .5rem 1rem;
  border: 1px solid var(--line);
  border-radius: 1.35rem;
  background: var(--glass);
  box-shadow: var(--shadow), inset 0 1px rgba(255, 255, 255, .06);
  backdrop-filter: blur(16px) saturate(1.2);
}
.timer { display: grid; grid-template-columns: auto auto; align-items: baseline; column-gap: .2rem; }
.timer span { grid-column: 1 / -1; color: var(--amber); font-size: .58rem; font-weight: 900; letter-spacing: .13em; text-transform: uppercase; }
.timer strong { min-width: 2ch; font-family: Georgia, serif; font-size: 2.25rem; line-height: .95; font-variant-numeric: tabular-nums; }
.hud-meters { display: grid; grid-template-columns: 3.4rem 1fr; align-items: center; gap: .28rem .45rem; }
.hud-meters label { color: var(--mist); font-size: .58rem; font-weight: 900; letter-spacing: .1em; }
.hud-meters label span { float: right; color: var(--cloud); }
.meter { height: .48rem; overflow: hidden; border: 1px solid rgba(255,255,255,.18); border-radius: 999px; background: rgba(1, 8, 22, .65); }
.meter i { display: block; width: 100%; height: 100%; transform-origin: left; border-radius: inherit; background: linear-gradient(90deg, var(--amber-hot), var(--amber)); box-shadow: 0 0 14px rgba(255, 166, 53, .5); }
.signal-meter i { width: 0; background: linear-gradient(90deg, #4bd9c4, var(--mint)); box-shadow: 0 0 14px rgba(81, 229, 203, .45); }
.run-totals { display: grid; gap: .15rem; color: var(--mist); font-size: .64rem; letter-spacing: .07em; text-transform: uppercase; }
.run-totals b { color: var(--cloud); font-variant-numeric: tabular-nums; }

.town-screen {
  position: absolute;
  z-index: 10;
  inset: 0;
  display: grid;
  grid-template-columns: minmax(20rem, .92fr) minmax(22rem, .58fr);
  align-items: end;
  gap: clamp(1rem, 7vw, 8rem);
  padding: clamp(5.8rem, 12vh, 8rem) clamp(1rem, 4vw, 4.5rem) max(1.2rem, env(safe-area-inset-bottom));
  pointer-events: none;
}
.town-screen::before {
  content: "";
  position: absolute;
  z-index: -1;
  inset: 0;
  background: linear-gradient(90deg, rgba(3, 12, 31, .88) 0, rgba(3, 12, 31, .5) 31%, transparent 60%), linear-gradient(0deg, rgba(3, 11, 28, .8), transparent 52%);
}
.town-copy,
.repair-dock { pointer-events: auto; }

.town-copy { max-width: 45rem; padding-bottom: clamp(.5rem, 3vh, 2rem); text-shadow: 0 3px 24px rgba(0, 5, 22, .7); }
.kicker { margin: 0 0 .7rem; color: var(--amber); font-size: .66rem; font-weight: 950; letter-spacing: .18em; text-transform: uppercase; }
h1, h2, p { margin-top: 0; }
h1 {
  margin-bottom: 1rem;
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(3.8rem, 8.2vw, 8.6rem);
  font-weight: 700;
  line-height: .83;
  letter-spacing: -.065em;
}
h1 em { color: var(--amber); font-weight: 400; }
.lede { max-width: 40rem; margin-bottom: 1rem; color: #d7e0e5; font-family: Georgia, serif; font-size: clamp(.95rem, 1.5vw, 1.16rem); line-height: 1.5; }
.control-note { display: flex; flex-wrap: wrap; gap: .45rem 1rem; color: var(--mist); font-size: .69rem; font-weight: 800; letter-spacing: .05em; text-transform: uppercase; }
.control-note span { display: flex; align-items: center; gap: .3rem; }
.control-note span + span::before { content: "✦"; margin-right: .45rem; color: var(--amber); font-size: .7rem; }
kbd { padding: .14rem .32rem; border: 1px solid rgba(255,255,255,.28); border-radius: .32rem; background: rgba(5, 15, 36, .68); color: var(--cloud); font-size: .64rem; box-shadow: inset 0 -2px rgba(255,255,255,.09); }
.start-row { display: flex; align-items: center; gap: 1.2rem; margin-top: 1.35rem; }
.start-row > p { margin: 0; color: var(--mist); font-size: .66rem; font-weight: 800; letter-spacing: .09em; line-height: 1.55; text-transform: uppercase; }
.start-row strong { color: var(--amber); font-size: .95rem; }

.primary-button,
.secondary-button,
.text-button,
.repair-button,
.upgrade-card,
.reset-button { min-height: 44px; cursor: pointer; }
.primary-button {
  display: inline-flex;
  align-items: center;
  gap: 2rem;
  min-height: 3.55rem;
  padding: .8rem .75rem .8rem 1.25rem;
  border: 1px solid rgba(255,255,255,.46);
  border-radius: 999px;
  background: linear-gradient(135deg, #ffd47a, var(--amber-hot));
  color: #1e1830;
  box-shadow: 0 12px 34px rgba(255, 121, 35, .25), inset 0 1px rgba(255,255,255,.55);
  font-size: .76rem;
  font-weight: 950;
  letter-spacing: .09em;
  text-transform: uppercase;
  transition: transform 150ms var(--ease), box-shadow 150ms var(--ease);
}
.primary-button b { display: grid; place-items: center; width: 2.1rem; height: 2.1rem; border-radius: 50%; background: rgba(19, 20, 43, .18); font-size: 1rem; }
.primary-button:active { transform: translateY(2px) scale(.98); box-shadow: 0 5px 16px rgba(255, 121, 35, .2); }

.repair-dock {
  justify-self: end;
  width: min(100%, 34rem);
  max-height: min(72vh, 43rem);
  padding: 1.1rem;
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 1.6rem;
  background: rgba(6, 20, 43, .84);
  box-shadow: var(--shadow), inset 0 1px rgba(255,255,255,.08);
  backdrop-filter: blur(18px) saturate(1.2);
}
.repair-head { display: flex; justify-content: space-between; gap: 1rem; padding: .2rem .15rem .85rem; border-bottom: 1px solid var(--line); }
.repair-head span { color: var(--amber); font-size: .56rem; font-weight: 900; letter-spacing: .16em; }
.repair-head h2 { margin: .2rem 0 0; font-family: Georgia, serif; font-size: clamp(1.4rem, 2.6vw, 2.1rem); }
.repair-head > p { display: grid; justify-items: end; margin: 0; }
.repair-head small { color: var(--mist); font-size: .54rem; letter-spacing: .12em; text-transform: uppercase; }
.repair-head strong { color: var(--amber); font-family: Georgia, serif; font-size: 1.35rem; }
.repair-note { margin: .65rem .15rem; color: var(--mist); font-family: Georgia, serif; font-size: .78rem; line-height: 1.4; }
.building-list { display: grid; gap: .52rem; }
.building-row {
  display: grid;
  grid-template-columns: 4.2rem 1fr auto;
  align-items: center;
  gap: .75rem;
  min-height: 4.45rem;
  padding: .38rem .38rem .38rem .25rem;
  border: 1px solid rgba(218, 230, 238, .13);
  border-radius: 1rem;
  background: rgba(18, 45, 76, .52);
}
.building-thumb { width: 4rem; height: 3.7rem; object-fit: cover; border-radius: .7rem; filter: saturate(.72) brightness(.75); transition: filter 300ms var(--ease); }
.building-row[data-level="1"] .building-thumb { filter: saturate(.9) brightness(.9); }
.building-row[data-level="2"] .building-thumb { filter: saturate(1.05) brightness(1.05); }
.building-row[data-level="3"] .building-thumb { filter: saturate(1.12) brightness(1.18) drop-shadow(0 0 12px rgba(255,183,81,.35)); }
.building-info { min-width: 0; }
.building-info strong { display: block; font-family: Georgia, serif; font-size: .88rem; }
.building-info span { display: block; margin-top: .16rem; color: var(--mist); font-size: .58rem; line-height: 1.25; letter-spacing: .04em; }
.repair-pips { display: flex; gap: .2rem; margin-top: .32rem; }
.repair-pips i { width: .9rem; height: .22rem; border-radius: 99px; background: rgba(255,255,255,.14); }
.repair-pips i.on { background: var(--amber); box-shadow: 0 0 8px rgba(255,185,82,.45); }
.repair-button { min-width: 5.4rem; padding: .55rem .65rem; border: 1px solid rgba(255,205,126,.46); border-radius: 999px; background: rgba(255,173,69,.13); color: var(--amber); font-size: .58rem; font-weight: 950; letter-spacing: .07em; text-transform: uppercase; }
.repair-button:not(:disabled):hover { background: var(--amber); color: var(--night); }
.repair-button:disabled { cursor: not-allowed; border-color: var(--line); color: var(--mist); opacity: .55; }
.reset-button { margin: .7rem 0 0; padding: .35rem .45rem; border: 0; background: transparent; color: #8294a7; font-size: .58rem; letter-spacing: .08em; text-decoration: underline; text-underline-offset: .22rem; text-transform: uppercase; }

.screen-overlay {
  position: absolute;
  z-index: 60;
  inset: 0;
  display: grid;
  place-items: center;
  padding: clamp(5rem, 10vh, 7rem) clamp(.8rem, 3vw, 2rem) max(1rem, env(safe-area-inset-bottom));
  overflow: auto;
  background: rgba(3, 11, 28, .82);
  backdrop-filter: blur(12px) saturate(.8);
}
.upgrade-wrap { width: min(100%, 66rem); text-align: center; }
.upgrade-wrap h2,
.dialog-card h2 { margin: .2rem 0 .55rem; font-family: Georgia, serif; font-size: clamp(2.4rem, 6vw, 4.6rem); line-height: .95; letter-spacing: -.04em; }
.overlay-note { color: var(--mist); font-family: Georgia, serif; font-size: .85rem; }
.upgrade-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: clamp(.7rem, 2vw, 1.25rem); margin-top: 1.35rem; }
.upgrade-card {
  position: relative;
  display: grid;
  grid-template-rows: 8.2rem auto 1fr auto;
  min-height: 21rem;
  padding: .7rem .8rem 1rem;
  overflow: hidden;
  border: 1px solid rgba(255,225,173,.35);
  border-radius: 1.35rem;
  background: linear-gradient(180deg, rgba(23,52,83,.96), rgba(7,23,48,.98));
  color: var(--cloud);
  box-shadow: 0 18px 48px rgba(0,4,18,.45), inset 0 1px rgba(255,255,255,.07);
  text-align: left;
  transition: transform 180ms var(--ease), border-color 180ms linear;
}
.upgrade-card img { justify-self: center; width: 9.2rem; height: 9.2rem; margin-top: -1rem; object-fit: contain; filter: drop-shadow(0 10px 20px rgba(0,0,0,.35)); }
.upgrade-card small { position: absolute; top: .75rem; right: .8rem; display: grid; place-items: center; width: 1.7rem; height: 1.7rem; border: 1px solid rgba(255,255,255,.26); border-radius: 50%; color: var(--amber); font-weight: 900; }
.upgrade-card h3 { margin: .4rem 0 .25rem; font-family: Georgia, serif; font-size: 1.3rem; }
.upgrade-card p { margin: 0; color: var(--mist); font-size: .76rem; line-height: 1.45; }
.upgrade-card b { align-self: end; margin-top: .8rem; padding-top: .65rem; border-top: 1px solid var(--line); color: var(--amber); font-size: .58rem; letter-spacing: .12em; text-transform: uppercase; }

.dialog-card {
  width: min(100%, 36rem);
  padding: clamp(1.25rem, 4vw, 2.4rem);
  border: 1px solid rgba(255,224,172,.32);
  border-radius: 1.8rem;
  background: rgba(8, 27, 55, .96);
  box-shadow: var(--shadow), inset 0 1px rgba(255,255,255,.08);
}
.dialog-card > p:not(.kicker) { color: var(--mist); font-family: Georgia, serif; }
.dialog-card .primary-button { margin-top: 1rem; }
.secondary-button { display: block; min-width: 12rem; margin-top: .65rem; padding: .7rem 1rem; border: 1px solid var(--line); border-radius: 999px; background: rgba(255,255,255,.04); color: var(--cloud); font-size: .67rem; font-weight: 900; letter-spacing: .08em; text-transform: uppercase; }
.text-button { display: block; margin-top: .35rem; padding: .6rem .4rem; border: 0; background: transparent; color: var(--mist); font-size: .65rem; text-decoration: underline; text-underline-offset: .22rem; }
.result-ledger { display: grid; grid-template-columns: repeat(3, 1fr); margin: 1.2rem 0 .35rem; border-block: 1px solid var(--line); }
.result-ledger span { display: grid; gap: .22rem; padding: .9rem .55rem; border-right: 1px solid var(--line); }
.result-ledger span:last-child { border-right: 0; }
.result-ledger small { color: var(--mist); font-size: .55rem; letter-spacing: .1em; text-transform: uppercase; }
.result-ledger strong { color: var(--amber); font-family: Georgia, serif; font-size: 1.2rem; }

.boss-alert {
  position: absolute;
  z-index: 50;
  top: 19%;
  left: 50%;
  width: min(90%, 34rem);
  padding: .85rem 1rem;
  transform: translateX(-50%);
  border: 1px solid rgba(255,119,87,.58);
  border-radius: 1rem;
  background: rgba(44, 10, 21, .9);
  color: var(--cloud);
  box-shadow: 0 14px 40px rgba(34,0,10,.45);
  text-align: center;
  animation: alert-in .45s var(--ease) both;
}
.boss-alert span { display: block; color: var(--danger); font-size: .58rem; font-weight: 950; letter-spacing: .18em; }
.boss-alert strong { display: block; margin-top: .22rem; font-family: Georgia, serif; font-size: 1rem; }

.toast {
  position: absolute;
  z-index: 90;
  left: 50%;
  bottom: max(1rem, env(safe-area-inset-bottom));
  max-width: min(90%, 32rem);
  padding: .65rem .95rem;
  transform: translateX(-50%);
  border: 1px solid rgba(255,219,151,.36);
  border-radius: 999px;
  background: rgba(5, 18, 40, .94);
  color: var(--cloud);
  box-shadow: 0 12px 34px rgba(0,3,18,.42);
  font-size: .65rem;
  font-weight: 850;
  letter-spacing: .06em;
  text-align: center;
  text-transform: uppercase;
}

.touch-pad {
  position: absolute;
  z-index: 40;
  left: max(1rem, env(safe-area-inset-left));
  bottom: max(1rem, env(safe-area-inset-bottom));
  width: 7.4rem;
  height: 7.4rem;
  border: 1px solid rgba(209,231,239,.28);
  border-radius: 50%;
  background: radial-gradient(circle, rgba(28,60,89,.55), rgba(5,19,42,.68));
  box-shadow: inset 0 0 28px rgba(0,0,0,.28), 0 12px 35px rgba(0,4,18,.28);
  touch-action: none;
}
.touch-pad::before,
.touch-pad::after { content: ""; position: absolute; inset: 50% 15% auto; height: 1px; background: rgba(255,255,255,.18); }
.touch-pad::after { inset: 15% auto 15% 50%; width: 1px; height: auto; }
.touch-knob { position: absolute; left: 50%; top: 50%; width: 3.35rem; height: 3.35rem; transform: translate(-50%,-50%); border: 2px solid rgba(255,228,174,.7); border-radius: 50%; background: radial-gradient(circle at 35% 30%, #ffd27a, #b85f2b); box-shadow: 0 5px 20px rgba(0,0,0,.35), inset 0 0 0 .38rem rgba(6,20,43,.46); }

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); white-space: nowrap; border: 0; }

@keyframes alert-in { from { opacity: 0; transform: translate(-50%,-1rem) scale(.96); } to { opacity: 1; transform: translate(-50%,0) scale(1); } }

@media (hover: hover) {
  .icon-button:hover { transform: translateY(-2px); background: rgba(30,61,91,.92); }
  .primary-button:hover { transform: translateY(-3px); box-shadow: 0 17px 40px rgba(255,121,35,.32); }
  .upgrade-card:hover { transform: translateY(-.45rem); border-color: var(--amber); }
}

@media (max-width: 62rem) {
  .town-screen { grid-template-columns: minmax(18rem,.9fr) minmax(20rem,.6fr); gap: 1rem; padding-inline: 1.25rem; }
  .run-hud { grid-template-columns: auto minmax(10rem,18rem); }
  .run-totals { display: none; }
  .building-row { grid-template-columns: 3.6rem 1fr; }
  .building-thumb { width: 3.45rem; height: 3.3rem; }
  .repair-button { grid-column: 2; width: 100%; }
}

@media (max-width: 47rem) {
  .game-shell { min-height: 32rem; }
  .topbar { grid-template-columns: 1fr auto; padding-inline: .7rem; }
  .brand-lockup { display: none; }
  .run-hud { justify-self: start; width: calc(100vw - 7.1rem); grid-template-columns: auto 1fr; min-height: 3.6rem; padding: .4rem .7rem; border-radius: 1rem; }
  .timer strong { font-size: 1.8rem; }
  .town-screen { display: block; padding: 4.6rem .8rem max(.8rem, env(safe-area-inset-bottom)); overflow: auto; }
  .town-screen::before { background: linear-gradient(0deg, rgba(3,11,28,.94) 0 44%, rgba(3,11,28,.24) 82%, transparent); }
  .town-copy { min-height: 68vh; display: flex; flex-direction: column; justify-content: flex-end; padding-bottom: 1.4rem; }
  h1 { font-size: clamp(4rem, 20vw, 6.8rem); }
  .lede { max-width: 31rem; font-size: .92rem; }
  .repair-dock { width: 100%; max-height: none; }
  .upgrade-grid { grid-template-columns: 1fr; }
  .upgrade-card { grid-template-columns: 7rem 1fr; grid-template-rows: auto 1fr auto; min-height: 10.5rem; }
  .upgrade-card img { grid-row: 1 / 4; width: 7.5rem; height: 8rem; margin: -.6rem 0 0 -.8rem; }
  .upgrade-card h3, .upgrade-card p, .upgrade-card b { grid-column: 2; }
  .result-ledger { grid-template-columns: 1fr; }
  .result-ledger span { grid-template-columns: 1fr auto; align-items: center; border-right: 0; border-bottom: 1px solid var(--line); }
  .result-ledger span:last-child { border-bottom: 0; }
}

@media (max-width: 31rem) {
  .control-note { display: grid; }
  .control-note span + span::before { display: none; }
  .start-row { display: grid; }
  .primary-button { width: 100%; justify-content: space-between; }
  .repair-head h2 { font-size: 1.35rem; }
  .touch-pad { width: 6.6rem; height: 6.6rem; }
}

@media (max-height: 41rem) and (orientation: landscape) {
  .town-screen { grid-template-columns: 1fr 27rem; align-items: start; padding-top: 4.5rem; }
  .town-copy { padding: 0; }
  h1 { font-size: 4.1rem; }
  .lede { margin-bottom: .55rem; font-size: .82rem; }
  .start-row { margin-top: .7rem; }
  .repair-dock { max-height: calc(100vh - 5.2rem); }
  .building-row { min-height: 3.6rem; }
  .screen-overlay { align-items: start; padding-top: 4.5rem; }
  .upgrade-card { grid-template-rows: 5rem auto 1fr auto; min-height: 14rem; }
  .upgrade-card img { width: 6.7rem; height: 6.7rem; }
}

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