:root {
  color-scheme: dark;
  --ink: #eefbff;
  --muted: #9cb9c2;
  --deep: #05141e;
  --panel: rgba(7, 29, 40, .86);
  --line: rgba(170, 232, 238, .2);
  --cyan: #68e7f3;
  --amber: #ffbe5c;
  --coral: #ff6b63;
  --safe-top: env(safe-area-inset-top, 0px);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--deep);
}

* { box-sizing: border-box; }
html, body { width: 100%; min-height: 100%; margin: 0; background: #061720; }
html { overflow-x: hidden; }
body { overflow-x: hidden; }
body { color: var(--ink); }
button, a { -webkit-tap-highlight-color: transparent; }
button { font: inherit; }
button:focus-visible, a:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }

.brand-bar {
  position: fixed; inset: 0 0 auto; z-index: 20; height: calc(68px + var(--safe-top));
  padding: var(--safe-top) clamp(14px, 3vw, 38px) 0;
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  background: rgba(244, 242, 233, .96); color: #203a38; border-bottom: 1px solid #ccd6cf;
  backdrop-filter: blur(12px);
}
.brand { display: flex; min-height: 44px; align-items: center; }
.brand img { display: block; width: 145px; height: 38px; object-fit: contain; }
.nav-actions { display: flex; gap: 8px; }
.quiet-button, .icon-button {
  min-height: 42px; padding: 0 14px; border: 1px solid #aebdb5; border-radius: 8px;
  color: #203a38; background: #fffdf5; font-size: 12px; font-weight: 750; cursor: pointer;
}
.quiet-button:hover, .icon-button:hover { background: #e5ece5; }

.game-shell { position: relative; width: 100%; height: calc(100dvh - 68px - var(--safe-top)); margin-top: calc(68px + var(--safe-top)); isolation: isolate; background: #071e2a; }
#gameCanvas { display: block; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }

.hud {
  position: absolute; z-index: 5; left: clamp(12px, 2.3vw, 34px); right: clamp(12px, 2.3vw, 34px); top: 16px;
  display: grid; grid-template-columns: 170px 130px 110px minmax(230px, 1fr); align-items: stretch;
  max-width: 1080px; margin: auto; border: 1px solid var(--line); border-radius: 13px; overflow: hidden;
  background: rgba(3, 20, 29, .77); box-shadow: 0 12px 35px rgba(0,0,0,.25); backdrop-filter: blur(14px);
  pointer-events: none;
}
.hud > div { padding: 12px 16px; border-right: 1px solid var(--line); min-width: 0; }
.hud > div:last-child { border: 0; }
.micro-label { display: block; color: #9bc0c8; font: 700 9px/1.3 "Courier New", monospace; letter-spacing: 1.3px; }
.hud strong { display: block; margin-top: 3px; font-size: 23px; line-height: 1; font-variant-numeric: tabular-nums; }
.hud-primary strong { color: var(--amber); font-size: 32px; }
.hud small { font-size: 11px; color: var(--muted); }
.bar-label { display: flex; justify-content: space-between; color: #c6dce1; font-size: 10px; }
.meter { height: 5px; margin: 7px 0 8px; border-radius: 6px; overflow: hidden; background: rgba(255,255,255,.12); }
.meter i { display: block; width: 100%; height: 100%; background: linear-gradient(90deg, #ff665f, #ffd071 42%, #72ebce 75%); transform-origin: left; }
.inventory { display: flex; gap: 7px; flex-wrap: wrap; }
.resource { padding: 3px 6px; border-radius: 5px; font-size: 9px; font-weight: 700; background: rgba(255,255,255,.07); }
.oxygen { color: #8ce7ff; } .substrate { color: #ffd074; } .adp { color: #73f1d0; }

.ability-status, .announcement {
  position: absolute; z-index: 6; left: 50%; transform: translateX(-50%); pointer-events: none;
  text-align: center; font-weight: 850; letter-spacing: .06em; text-transform: uppercase;
}
.ability-status { bottom: 26px; min-width: 220px; color: #8ffff2; font-size: 11px; text-shadow: 0 0 18px #38d9df; }
.announcement { top: 118px; opacity: 0; color: #fff; font-size: clamp(18px, 3vw, 30px); text-shadow: 0 2px 22px #031017; transition: opacity .18s, transform .18s; }
.announcement.show { opacity: 1; transform: translate(-50%, 4px); }
.touch-hint { position: absolute; z-index: 4; right: 18px; bottom: 18px; color: rgba(213,240,242,.62); font: 700 9px/1.2 "Courier New", monospace; letter-spacing: .8px; pointer-events: none; }
.touch-hint span { display: inline-block; width: 19px; height: 19px; border: 1px solid currentColor; border-radius: 50%; vertical-align: middle; margin-right: 6px; }

.overlay { position: absolute; z-index: 12; inset: 0; background: #061720; }
.overlay[hidden] { display: none !important; }
.start-screen { display: grid; grid-template-columns: minmax(0, 1.38fr) minmax(360px, .82fr); }
.cover-panel { position: relative; overflow: hidden; min-height: 0; }
.cover-panel img { width: 100%; height: 100%; object-fit: cover; object-position: 52% center; display: block; }
.cover-shade { position: absolute; inset: 0; background: linear-gradient(90deg, transparent 58%, rgba(6,23,32,.9)), linear-gradient(0deg, rgba(3,13,20,.5), transparent 35%); }
.cover-tag { position: absolute; left: 28px; bottom: 20px; margin: 0; font: 700 9px/1.4 "Courier New", monospace; letter-spacing: 1.5px; color: rgba(255,255,255,.84); }
.start-copy { display: flex; flex-direction: column; justify-content: center; padding: clamp(32px, 5vw, 72px); background: radial-gradient(circle at 0 40%, rgba(45,129,143,.25), transparent 45%), #061720; }
.eyebrow { margin: 0 0 13px; color: #7de5e6; font: 700 10px/1.4 "Courier New", monospace; letter-spacing: 2px; }
h1, h2 { margin: 0; font-family: Georgia, "Times New Roman", serif; font-weight: 400; letter-spacing: -.045em; }
h1 { font-size: clamp(50px, 5.15vw, 78px); line-height: .86; }
h1 em { color: var(--amber); font-weight: 400; }
h2 { font-size: clamp(35px, 5vw, 55px); line-height: 1; }
.lede { max-width: 510px; margin: 26px 0 20px; color: #afc7ce; font-size: clamp(14px, 1.5vw, 17px); line-height: 1.65; }
.start-facts { display: flex; gap: 9px; margin-bottom: 25px; flex-wrap: wrap; }
.start-facts span { min-width: 91px; padding: 9px 11px; border: 1px solid var(--line); border-radius: 8px; color: #9eb9c0; font-size: 10px; }
.start-facts b { display: block; color: #f5fbfd; font-size: 17px; }
.primary-button {
  display: flex; align-items: center; justify-content: space-between; gap: 20px; width: 100%; min-height: 52px;
  padding: 0 18px; border: 1px solid #e5aa4c; border-radius: 8px; background: #e9ad50; color: #142a2d;
  font-weight: 850; cursor: pointer; box-shadow: 0 10px 35px rgba(233,173,80,.12);
}
.primary-button:hover { background: #ffc769; }
.text-button { align-self: center; border: 0; padding: 13px; color: #a5c2c9; background: transparent; font-size: 12px; text-decoration: underline; cursor: pointer; }

.compact-overlay { display: grid; place-items: center; padding: 16px; background: rgba(1, 12, 18, .78); backdrop-filter: blur(10px); }
.modal-card { width: min(520px, 100%); max-height: calc(100dvh - 30px); overflow: auto; padding: clamp(28px, 5vw, 54px); border: 1px solid var(--line); border-radius: 18px; background: #092633; box-shadow: 0 30px 100px #0008; }
.modal-card > p:not(.eyebrow) { color: #aac4cb; line-height: 1.7; }
.final-score { display: block; margin-top: 22px; color: var(--amber); font-size: clamp(64px, 15vw, 104px); line-height: .9; letter-spacing: -.07em; }
.score-caption { color: #97b5bd; font: 700 9px/1.4 "Courier New", monospace; letter-spacing: 1.5px; }
.result-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin: 26px 0; border: 1px solid var(--line); background: var(--line); }
.result-grid div { padding: 13px 8px; text-align: center; background: #092633; }
.result-grid b, .result-grid span { display: block; }
.result-grid b { font-size: 16px; }
.result-grid span { margin-top: 4px; color: #8da9b1; font-size: 9px; text-transform: uppercase; }
.marsnut-return { display: block; margin-top: 16px; color: #9fd4dc; text-align: center; font-size: 12px; }

dialog { width: min(690px, calc(100% - 24px)); max-height: calc(100dvh - 26px); padding: clamp(25px, 4vw, 46px); overflow: auto; border: 1px solid #47717c; border-radius: 18px; color: var(--ink); background: #092530; box-shadow: 0 30px 100px #0009; }
dialog::backdrop { background: rgba(1, 10, 16, .83); backdrop-filter: blur(8px); }
dialog h2 { margin-bottom: 23px; }
dialog p, dialog li { color: #b8cdd2; font-size: 13px; line-height: 1.72; }
dialog li { margin: 7px 0; }
dialog strong { color: #fff; }
.dialog-close { position: absolute; right: 11px; top: 9px; width: 42px; height: 42px; border: 0; color: #bdd3d8; background: transparent; font-size: 27px; cursor: pointer; }
.dialog-brand { display: inline-flex; margin-bottom: 26px; padding: 5px 10px; border-radius: 7px; background: #f4f2e9; }
.dialog-brand img { display: block; width: 125px; height: 32px; object-fit: contain; }
.science-note { margin: 22px 0; padding-top: 17px; border-top: 1px solid var(--line); font-size: 11px !important; }

.marsnut-about, .marsnut-footer { color: #262b24; background: #f5f2e9; font-family: Arial, Helvetica, sans-serif; }
.marsnut-bottom-wrap { width: min(1280px, calc(100% - 96px)); margin: auto; }
.marsnut-about-inner { display: flex; align-items: center; gap: 23px; padding: 33px 0; border-bottom: 1px solid #d8d9ce; }
.marsnut-about-star { color: #d84c2a; font-size: 46px; }
.marsnut-about p { margin: 0; color: #63685e; font-size: 13px; line-height: 1.8; }
.marsnut-about strong { color: #262b24; }
.marsnut-device-note { margin-left: auto; color: #63685e; font: 700 9px/2 "Courier New", monospace; letter-spacing: .8px; text-align: right; }
.marsnut-device-note b { font: 400 12px/2 Arial, Helvetica, sans-serif; letter-spacing: 0; }
.marsnut-footer-inner { display: flex; align-items: center; gap: 25px; min-height: 99px; color: #63685e; font-size: 11px; }
.marsnut-footer a { display: inline-flex; align-items: center; flex-shrink: 0; }
.marsnut-footer img { display: block; width: 134px; height: 35px; }
.marsnut-footer-inner > span:last-child { margin-left: auto; }
.marsnut-footer-dot { color: #d84c2a; margin: 0 13px; }
.marsnut-footer a:focus-visible { outline-color: #d84c2a; }

@media (max-width: 860px) {
  .marsnut-bottom-wrap { width: calc(100% - 48px); }
  .hud { grid-template-columns: repeat(3, 1fr); }
  .hud-status { grid-column: 1 / -1; border-top: 1px solid var(--line); }
  .start-screen { grid-template-columns: 1fr; grid-template-rows: minmax(200px, 42vh) 1fr; overflow: auto; }
  .cover-shade { background: linear-gradient(0deg, #061720 0%, transparent 55%); }
  .start-copy { padding: 25px clamp(22px, 7vw, 60px) 38px; justify-content: flex-start; }
  h1 { font-size: clamp(49px, 12vw, 74px); }
  .lede { margin: 18px 0 14px; }
  .start-facts { margin-bottom: 17px; }
}

@media (max-width: 520px) {
  .brand-bar { height: calc(62px + var(--safe-top)); }
  .game-shell { height: calc(100dvh - 62px - var(--safe-top)); margin-top: calc(62px + var(--safe-top)); }
  .marsnut-bottom-wrap { width: calc(100% - 36px); }
  .marsnut-about-inner { gap: 15px; flex-wrap: wrap; padding: 27px 0; }
  .marsnut-about-star { font-size: 33px; }
  .marsnut-about p { flex: 1 1 calc(100% - 55px); font-size: 12px; }
  .marsnut-about p br { display: none; }
  .marsnut-device-note { flex-basis: calc(100% - 48px); margin-left: 48px; text-align: left; }
  .marsnut-footer-inner { min-height: 110px; flex-wrap: wrap; gap: 12px; padding: 23px 0; }
  .marsnut-footer-inner > span:nth-child(2) { margin-left: auto; }
  .marsnut-footer-inner > span:last-child { width: 100%; margin-left: 0; font-size: 10px; }
  .brand img { width: 120px; height: 34px; }
  .quiet-button, .icon-button { min-height: 38px; padding: 0 10px; font-size: 10px; }
  .hud { top: 8px; left: 7px; right: 7px; grid-template-columns: 1.15fr 1fr 1fr; }
  .hud > div { padding: 8px 9px; }
  .hud strong { font-size: 17px; }
  .hud-primary strong { font-size: 23px; }
  .micro-label { font-size: 7px; letter-spacing: .7px; }
  .inventory { gap: 4px; }
  .resource { font-size: 8px; }
  .announcement { top: 105px; }
  .touch-hint { display: none; }
  .start-screen { grid-template-rows: minmax(180px, 34vh) 1fr; }
  .cover-tag { left: 16px; bottom: 11px; font-size: 7px; }
  .start-copy { padding-top: 12px; }
  .start-copy .eyebrow { margin-bottom: 8px; }
  h1 { font-size: 48px; }
  .lede { font-size: 12px; line-height: 1.5; }
  .start-facts span { flex: 1; min-width: 0; padding: 7px; }
  .start-facts b { font-size: 14px; }
  .primary-button { min-height: 48px; }
  dialog { padding: 25px 22px; }
  dialog ol { padding-left: 19px; }
}

@media (max-height: 560px) and (orientation: landscape) {
  .brand-bar { height: calc(54px + var(--safe-top)); }
  .game-shell { height: calc(100dvh - 54px - var(--safe-top)); margin-top: calc(54px + var(--safe-top)); }
  .brand img { width: 112px; height: 30px; }
  .quiet-button, .icon-button { min-height: 34px; }
  .start-screen { grid-template-columns: 1.2fr .8fr; grid-template-rows: 1fr; }
  .start-copy { padding: 18px 28px; }
  h1 { font-size: 48px; }
  .lede { margin: 10px 0; font-size: 11px; line-height: 1.4; }
  .start-facts { margin-bottom: 10px; }
  .start-facts span { padding: 5px 7px; }
  .hud { top: 7px; }
}

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