:root {
  color-scheme: dark;
  --basalt: #16110d;
  --basalt-2: #211913;
  --basalt-3: #2b2118;
  --panel: #332719;
  --panel-2: #40301f;
  --hide: #11100e;
  --line: #6d5233;
  --line-soft: #4b3826;
  --sand: #e5d2ad;
  --sand-2: #bda985;
  --paper: #f0dfb9;
  --rust: #b85a2a;
  --rust-2: #7f351f;
  --ochre: #d7a74c;
  --blue: #4fb7c8;
  --blue-2: #2d8291;
  --green: #7fb45b;
  --bad: #d95a43;
  --shadow: 0 18px 48px #00000073;
  --inset: inset 0 1px #ffffff14, inset 0 -12px 24px #00000033;
  --font: "Trebuchet MS", Tahoma, system-ui, sans-serif;
  --display: Georgia, "Times New Roman", serif;
  --mono: "Courier New", ui-monospace, monospace;
}

* { box-sizing: border-box; }

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

body {
  background:
    radial-gradient(circle at 78% 8%, #d8843d2e, transparent 28rem),
    radial-gradient(circle at 16% 12%, #4fb7c824, transparent 26rem),
    linear-gradient(180deg, #101715, #20170f 42%, #32180f);
  color: var(--sand);
  font-family: var(--font);
  overflow-x: hidden;
}

button,
input,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
}

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

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

.skip-link {
  position: fixed;
  z-index: 1000;
  top: 0;
  left: 0;
  padding: 0.65rem 0.85rem;
  color: var(--basalt);
  background: var(--paper);
  transform: translateY(-120%);
}

.skip-link:not(:focus-visible) {
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  border: 0;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  white-space: nowrap;
  overflow: hidden;
}

.skip-link:focus-visible {
  clip: auto;
  clip-path: none;
  width: auto;
  height: auto;
  margin: 0;
  padding: 0.65rem 0.85rem;
  transform: translateY(0);
}

.eyebrow {
  margin: 0;
  color: var(--ochre);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: 1.25rem;
  overflow: hidden;
  background:
    linear-gradient(180deg, #120d0a33, #120d0ae0),
    radial-gradient(circle at 62% 26%, #eaa14c36, transparent 30rem),
    #140f0c;
}

.boot.hide {
  pointer-events: none;
  opacity: 0;
  transition: opacity 360ms ease;
}

.boot-art {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.boot-sun {
  position: absolute;
  top: 9vh;
  right: 16vw;
  width: 4rem;
  height: 4rem;
  border-radius: 50%;
  background: radial-gradient(circle, #fff3ce 0 28%, #efb15f 56%, #e46d3f00 70%);
  box-shadow: 0 0 5rem #e89b4b73;
}

.boot-ridge {
  position: absolute;
  left: -6vw;
  right: -6vw;
  bottom: 0;
  height: 42vh;
  clip-path: polygon(0 64%, 9% 42%, 18% 58%, 31% 30%, 43% 51%, 55% 22%, 71% 54%, 83% 35%, 100% 62%, 100% 100%, 0 100%);
}

.boot-ridge-far { bottom: 18vh; background: #4a2118; opacity: 0.72; }
.boot-ridge-mid { bottom: 8vh; background: #6e2d1d; opacity: 0.88; }
.boot-ridge-near { background: linear-gradient(#9a4727, #522315); }

.boot-panel {
  position: relative;
  width: min(34rem, 100%);
  padding: 2rem;
  border: 1px solid #9f7446;
  background: linear-gradient(180deg, #342619f2, #201711f7);
  box-shadow: var(--shadow), var(--inset);
}

.boot-panel h1 {
  margin: 0.25rem 0 0.6rem;
  color: var(--paper);
  font-family: var(--display);
  font-size: clamp(2.4rem, 8vw, 4.8rem);
  line-height: 0.9;
}

.boot-panel p:not(.eyebrow):not(.boot-status) {
  max-width: 28rem;
  margin: 0 0 1.2rem;
  color: var(--sand-2);
  line-height: 1.55;
}

.boot-status {
  min-height: 1.3em;
  margin: 0.9rem 0 0;
  color: var(--blue);
  font-family: var(--mono);
  font-size: 0.78rem;
}

.primary-action,
.footer-actions button,
.card button,
.map-piece,
.tabs button {
  border: 1px solid var(--line);
  color: var(--paper);
  background: linear-gradient(180deg, #664325, #3b281b);
  box-shadow: var(--inset);
}

.primary-action {
  min-width: 12rem;
  min-height: 3rem;
  padding: 0.8rem 1.2rem;
  border-color: #d19d52;
  background: linear-gradient(180deg, #bd6730, #74311f);
  font-weight: 800;
  text-transform: uppercase;
}

.app-shell {
  width: min(1440px, 100%);
  min-height: 100vh;
  margin: 0 auto;
  display: grid;
  grid-template-rows: auto 1fr auto;
}

.app-shell[aria-hidden="true"] {
  pointer-events: none;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 1rem;
  padding: 0.9rem 1rem;
  border-bottom: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #2a1f18e8, #18120ee8);
}

.brand-block {
  min-width: 17rem;
  display: flex;
  align-items: center;
  gap: 0.9rem;
}

.brand-block h1 {
  margin: 0;
  color: var(--paper);
  font-family: var(--display);
  font-size: 1.45rem;
}

.brand-block p {
  margin: 0.1rem 0 0;
  color: var(--sand-2);
  font-family: var(--mono);
  font-size: 0.75rem;
}

.site-link {
  color: var(--blue);
  font-family: var(--mono);
  font-size: 0.72rem;
  font-weight: 700;
  text-decoration: none;
  text-transform: uppercase;
}

.meter-pack {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-left: auto;
  justify-content: flex-end;
}

.meter,
.sol-card {
  min-width: 10rem;
  padding: 0.55rem 0.65rem;
  border: 1px solid var(--line-soft);
  background: #201711;
}

.sol-card {
  min-width: 5rem;
}

.meter span,
.sol-card span {
  display: block;
  color: var(--sand-2);
  font-family: var(--mono);
  font-size: 0.68rem;
  text-transform: uppercase;
}

.meter b,
.sol-card b {
  color: var(--paper);
}

.meter i {
  display: block;
  height: 0.45rem;
  margin-top: 0.35rem;
  border: 1px solid #59442d;
  background: #120f0c;
  overflow: hidden;
}

.meter em {
  display: block;
  height: 100%;
  width: 100%;
  background: linear-gradient(90deg, var(--blue-2), var(--blue));
}

#powerBar {
  background: linear-gradient(90deg, #9b6b24, var(--ochre));
}

.game-layout {
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(22rem, 27rem);
}

.world-panel {
  min-height: 0;
  padding: 1rem;
  border-right: 1px solid var(--line-soft);
}

.world-head {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.8rem;
}

.world-head h2 {
  margin: 0.1rem 0 0;
  color: var(--paper);
  font-family: var(--display);
  font-size: 1.7rem;
}

.action-readout {
  max-width: 22rem;
  padding: 0.45rem 0.65rem;
  border: 1px solid var(--line-soft);
  color: var(--sand-2);
  background: #1d1510;
  font-family: var(--mono);
  font-size: 0.72rem;
}

.iso-viewport {
  position: relative;
  min-height: clamp(32rem, 68vh, 48rem);
  border: 1px solid var(--line);
  background:
    radial-gradient(circle at 50% 18%, #e7a15a26, transparent 24rem),
    url("./assets/mars-terrain.svg"),
    linear-gradient(180deg, #1c2823, #522415 58%, #251913);
  background-size: auto, 192px 192px, auto;
  overflow: hidden;
  contain: layout paint style;
  box-shadow: var(--shadow), inset 0 0 0 1px #ffffff0d;
}

.iso-viewport::before {
  content: "";
  position: absolute;
  inset: 0;
  opacity: 0.22;
  background-image:
    linear-gradient(30deg, #fff2c60c 1px, transparent 1px),
    linear-gradient(150deg, #00000022 1px, transparent 1px);
  background-size: 64px 64px;
}

.iso-board {
  /* MS-105: --base-scale is the responsive fit, --user-scale/--pan-* are the
     player's pinch and drag. They compose here so JS never fights the media query. */
  --base-scale: 1;
  --user-scale: 1;
  --pan-x: 0px;
  --pan-y: 0px;
  position: absolute;
  left: 50%;
  top: 22%;
  width: 1px;
  height: 1px;
  transform:
    translate(-50%, -50%)
    translate(var(--pan-x), var(--pan-y))
    scale(calc(var(--base-scale) * var(--user-scale)));
}

.iso-viewport {
  touch-action: none;
}

.view-reset {
  position: absolute;
  right: 0.6rem;
  bottom: 0.6rem;
  z-index: 6;
  padding: 0.4rem 0.7rem;
  border: 1px solid var(--line);
  color: var(--sand);
  background: #1d1510e6;
  font-family: var(--mono);
  font-size: 0.68rem;
}

.view-reset[hidden] {
  display: none;
}

.terrain-canvas {
  position: absolute;
  z-index: 0;
  left: -470px;
  top: -86px;
  width: 940px;
  height: 620px;
  pointer-events: none;
  filter: drop-shadow(0 1rem 1.1rem #00000066);
}

.tile {
  position: absolute;
  width: 3.8rem;
  height: 3.8rem;
  transform: translate(-50%, -50%) rotate(45deg) skew(-7deg, -7deg);
  border: 1px solid #8a4a29;
  background: linear-gradient(135deg, #8c3f25, #b85b2d 45%, #6b2e1f);
  box-shadow: 0.6rem 0.6rem 0 #00000024;
  contain: layout paint style;
}

.tile:nth-child(3n) { background: linear-gradient(135deg, #6e3425, #9f4a29 52%, #512317); }
.tile:nth-child(5n) { background: linear-gradient(135deg, #875336, #c16b38 48%, #61311f); }

.map-piece {
  position: absolute;
  z-index: 2;
  width: 4.8rem;
  min-height: 4.1rem;
  padding: 0;
  border: 0;
  background: transparent;
  transform: translate(-50%, -76%);
  contain: layout paint style;
}

.map-piece:focus-visible .label {
  border-color: var(--blue);
  box-shadow: 0 0 0 2px #4fb7c866;
}

.map-piece .label {
  display: block;
  width: max-content;
  max-width: 7.5rem;
  margin: 0.25rem auto 0;
  padding: 0.1rem 0.35rem;
  color: var(--sand);
  background: #15100ccf;
  border: 1px solid #3e2e20;
  box-shadow: 0 2px 0 #00000059;
  font-family: var(--mono);
  font-size: 0.62rem;
  white-space: nowrap;
}

.model {
  position: relative;
  width: 3.4rem;
  height: 3rem;
  margin: 0 auto;
  filter: drop-shadow(0 0.55rem 0.35rem #00000066);
}

.building .model::before {
  content: "";
  position: absolute;
  left: 0.35rem;
  right: 0.35rem;
  bottom: 0.2rem;
  height: 1.65rem;
  border: 1px solid #9f7b55;
  background: linear-gradient(135deg, #d8c39d, #7e654a);
  box-shadow: inset -0.55rem -0.4rem #00000029, inset 0.35rem 0.35rem #fff7cc30;
  clip-path: polygon(0 28%, 50% 0, 100% 28%, 100% 100%, 0 100%);
}

.building .model::after {
  content: "";
  position: absolute;
  left: 1.18rem;
  bottom: 0.48rem;
  width: 1rem;
  height: 0.65rem;
  border: 1px solid #18343a;
  background: linear-gradient(180deg, #8bd9df, #1d5963);
}

.building.ghost .model {
  opacity: 0.42;
  filter: grayscale(0.6) drop-shadow(0 0.55rem 0.35rem #00000066);
}

.building[data-model="array"] .model::before {
  background: linear-gradient(135deg, #285c68, #66b5bf);
  clip-path: polygon(0 25%, 100% 0, 100% 70%, 0 95%);
}

.building[data-model="array"] .model::after {
  left: 0.7rem;
  bottom: 1.05rem;
  width: 2rem;
  height: 0.16rem;
  border: 0;
  background: #16313c;
  box-shadow: 0 0.45rem #16313c, 0.65rem 0.22rem #16313c;
}

.building[data-model="tower"] .model::before {
  background: linear-gradient(135deg, #b8d4d6, #5e7674);
  clip-path: polygon(32% 0, 68% 0, 88% 100%, 12% 100%);
}

.building[data-model="foundry"] .model::before {
  background: linear-gradient(135deg, #a06f49, #463224);
  clip-path: polygon(0 35%, 28% 12%, 30% 35%, 58% 12%, 60% 35%, 100% 24%, 100% 100%, 0 100%);
}

.building[data-model="glass"] .model::before {
  background: linear-gradient(135deg, #b6edda, #4a937b);
  clip-path: ellipse(48% 42% at 50% 60%);
}

.building[data-model="reactor"] .model::before {
  background: linear-gradient(135deg, #d8d4bd, #5d5143);
  box-shadow: 0 0 1rem #63c7e180;
  clip-path: polygon(36% 0, 64% 0, 84% 100%, 16% 100%);
}

.node .model {
  width: 2.8rem;
  height: 2.1rem;
  border: 1px solid #3a2b21;
  border-radius: 44% 56% 50% 50%;
  background:
    radial-gradient(circle at 34% 28%, #fff6d0 0 9%, transparent 10%),
    radial-gradient(circle at 36% 30%, var(--node-color), #39251a 76%);
  box-shadow: inset -0.45rem -0.35rem #00000030, inset 0.3rem 0.2rem #ffffff24;
}

.node.locked .model,
.node.depleted .model {
  opacity: 0.38;
  filter: grayscale(0.7);
}

/* MS-102: node health as a fill bar rather than repeated block glyphs. */
.node .charges {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  color: var(--ochre);
  font-family: var(--mono);
  font-size: 0.62rem;
}

.charge-track {
  flex: 1;
  min-width: 1.6rem;
  height: 0.32rem;
  border: 1px solid #4b3826;
  background: #15100c;
  overflow: hidden;
}

.charge-fill {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--rust), var(--ochre));
  transition: width 260ms ease-out;
}

.charge-fill.mid { background: linear-gradient(90deg, #9b6b24, var(--ochre)); }
.charge-fill.low { background: linear-gradient(90deg, #7a3227, #c25a3a); }

.charge-count {
  flex: none;
  font-variant-numeric: tabular-nums;
}

@media (prefers-reduced-motion: reduce) {
  .charge-fill { transition: none; }
}

.player-marker {
  position: absolute;
  z-index: 4;
  width: 2rem;
  height: 3rem;
  transform: translate(-50%, -95%);
  pointer-events: none;
  filter: drop-shadow(0 0.45rem 0.28rem #0000007a);
}

.player-marker::before {
  content: "";
  position: absolute;
  inset: 0.1rem 0.35rem 0.45rem;
  border: 1px solid #c7d6d9;
  border-radius: 44% 44% 38% 38%;
  background: linear-gradient(180deg, #f1eee0, #9aa3a1);
}

.player-marker::after {
  content: "";
  position: absolute;
  top: 0.34rem;
  left: 0.65rem;
  width: 0.7rem;
  height: 0.48rem;
  border-radius: 45%;
  background: #173a44;
  box-shadow: inset 0 0 0 1px #74cddd;
}

.side-panel {
  min-height: 0;
  display: flex;
  flex-direction: column;
  background: linear-gradient(180deg, #2b2017, #1b1510);
}

.tabs {
  display: grid;
  /* Six tabs in two even rows of three — a 5-column track orphaned the sixth. */
  grid-template-columns: repeat(3, minmax(0, 1fr));
  border-bottom: 1px solid var(--line-soft);
}

.tabs button {
  min-height: 3rem;
  border-width: 0 1px 0 0;
  border-radius: 0;
  color: var(--sand-2);
  background: #241911;
  font-family: var(--mono);
  font-size: 0.68rem;
}

.tabs button[aria-selected="true"] {
  color: var(--paper);
  background: linear-gradient(180deg, #5d3c21, #322219);
}

.tabs button:focus-visible {
  position: relative;
  z-index: 1;
}

.panel-body {
  flex: 1;
  min-height: 0;
  padding: 0.85rem;
  overflow: auto;
  contain: content;
}

.card {
  margin-bottom: 0.7rem;
  padding: 0.75rem;
  border: 1px solid var(--line-soft);
  background: linear-gradient(180deg, #3a2a1c, #241a13);
}

.card h3 {
  margin: 0 0 0.35rem;
  color: var(--paper);
  font-size: 0.95rem;
}

.card p {
  margin: 0.25rem 0 0.65rem;
  color: var(--sand-2);
  font-size: 0.82rem;
  line-height: 1.45;
}

.card button {
  width: 100%;
  min-height: 2.5rem;
  border-color: #8f6539;
  font-family: var(--mono);
  font-size: 0.74rem;
  font-weight: 700;
}

.card button:not(:disabled):hover,
.footer-actions button:not(:disabled):hover,
.primary-action:hover,
.map-piece:hover .model {
  filter: brightness(1.08);
}

.cost-list,
.inventory-grid,
.skill-list {
  display: grid;
  gap: 0.4rem;
}

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

.pill,
.slot,
.skill-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.6rem;
  padding: 0.45rem 0.5rem;
  border: 1px solid var(--line-soft);
  background: #211812;
  color: var(--sand);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.pill.ok { border-color: #4f6b34; color: #a9da82; }
.pill.no { border-color: #773a2f; color: #f0a08f; }

.skill-bar {
  flex: 1;
  height: 0.45rem;
  border: 1px solid #4b3826;
  background: #15100c;
  overflow: hidden;
}

.skill-bar i {
  display: block;
  height: 100%;
  background: linear-gradient(90deg, var(--rust), var(--ochre));
}

/* MS-103: tap-to-expand XP detail under each skill row. */
.skill-row--expandable {
  cursor: pointer;
}

.skill-row--expandable:focus-visible {
  outline: 2px solid var(--ochre);
  outline-offset: 2px;
}

.skill-detail {
  padding: 0.4rem 0.55rem 0.55rem;
  border: 1px solid var(--line-soft);
  border-top: 0;
  background: #1a130e;
  color: var(--sand-2);
  font-family: var(--mono);
  font-size: 0.66rem;
  line-height: 1.5;
}

.skill-detail[hidden] {
  display: none;
}

.command-log {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 1rem;
  padding: 0.75rem 1rem;
  border-top: 1px solid var(--line-soft);
  background: #18120e;
}

#eventLog {
  display: flex;
  flex-direction: column-reverse;
  gap: 0.2rem;
  max-height: 5.6rem;
  overflow: auto;
}

#eventLog p {
  margin: 0;
  color: var(--sand-2);
  font-size: 0.82rem;
}

#eventLog p.good { color: #a9da82; }
#eventLog p.warn { color: #e3be66; }
#eventLog p.bad { color: #f0a08f; }

.footer-actions {
  display: grid;
  grid-template-columns: repeat(2, minmax(7rem, 1fr));
  gap: 0.45rem;
  align-content: center;
}

.footer-actions button {
  min-height: 2.35rem;
  color: var(--sand);
  font-family: var(--mono);
  font-size: 0.72rem;
}

.toast-stack {
  position: fixed;
  z-index: 200;
  top: 5.5rem;
  left: 50%;
  display: grid;
  gap: 0.5rem;
  width: min(28rem, calc(100vw - 2rem));
  pointer-events: none;
  transform: translateX(-50%);
}

.toast {
  padding: 0.75rem 0.9rem;
  border: 1px solid var(--line);
  background: linear-gradient(180deg, #3a2a1c, #1f1711);
  box-shadow: var(--shadow);
}

.toast b {
  display: block;
  margin-bottom: 0.2rem;
  color: var(--paper);
}

@media (max-width: 980px) {
  .topbar,
  .command-log {
    grid-template-columns: 1fr;
    display: grid;
  }

  .meter-pack {
    margin-left: 0;
    justify-content: stretch;
  }

  .meter {
    flex: 1;
  }

  .game-layout {
    grid-template-columns: 1fr;
  }

  .world-panel {
    border-right: 0;
    border-bottom: 1px solid var(--line-soft);
  }

  .iso-viewport {
    min-height: 34rem;
  }

  .side-panel {
    min-height: 28rem;
  }
}

/* MS-101: below 768px the topbar's three stat cards stack instead of squeezing,
   and every control keeps a full-width, thumb-sized hit target so the resource
   and footer buttons stop getting clipped off the edge of the viewport. */
@media (max-width: 768px) {
  .meter-pack {
    display: grid;
    grid-template-columns: 1fr;
    gap: 0.45rem;
    width: 100%;
    margin-left: 0;
  }

  .meter,
  .sol-card {
    min-width: 0;
    width: 100%;
  }

  .world-head {
    flex-wrap: wrap;
    align-items: flex-start;
    gap: 0.5rem;
  }

  .action-readout {
    max-width: none;
    width: 100%;
  }

  .world-panel {
    padding: 0.75rem;
  }

  .tabs button {
    min-height: 2.75rem;
    font-size: 0.66rem;
  }

  .panel-body {
    padding: 0.65rem;
  }

  .footer-actions {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .footer-actions button,
  .card button {
    width: 100%;
    min-height: 2.75rem;
  }

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

@media (max-width: 620px) {
  .boot-panel {
    padding: 1.2rem;
  }

  .brand-block {
    min-width: 0;
    align-items: flex-start;
    flex-direction: column;
    gap: 0.35rem;
  }

  .meter,
  .sol-card {
    min-width: calc(50% - 0.35rem);
  }

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

  .tile {
    width: 3.8rem;
    height: 3.8rem;
  }

  .iso-board {
    top: 26%;
    --base-scale: 0.47;
  }

  .iso-viewport {
    min-height: 28rem;
  }

  .map-piece {
    width: 4.6rem;
  }

  .footer-actions {
    grid-template-columns: 1fr;
  }
}

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