:root {
  --ink: #e8eef6;
  --dim: #8d9aab;
  --cold: #bcd8ff;
  --amber: #ffb547;
  --red: #ff5a4a;
  --green: #7fe69a;
  --glass: rgba(6, 10, 16, 0.7);
  --line: rgba(255, 255, 255, 0.1);
  --sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; background: #05070b; color: var(--ink); font-family: var(--sans); }
body { -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
canvas { position: fixed; inset: 0; width: 100%; height: 100%; display: block; }
#ov { touch-action: none; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
svg { fill: currentColor; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
#loading { position: fixed; inset: 0; display: grid; place-items: center; color: var(--dim); letter-spacing: 0.1em; text-transform: uppercase; font-size: 13px; }

/* HUD */
#hud {
  position: fixed; left: 0; right: 0; top: 0; padding: calc(env(safe-area-inset-top) + 10px) calc(env(safe-area-inset-right) + 14px) 10px calc(env(safe-area-inset-left) + 14px);
  display: grid; gap: 8px; pointer-events: none; background: linear-gradient(rgba(2, 4, 8, 0.8), rgba(2, 4, 8, 0));
}
#hud button { pointer-events: auto; }
.row { display: flex; align-items: center; gap: 12px; }
.stage { font-size: 13px; letter-spacing: 0.12em; text-transform: uppercase; color: var(--cold); }
.scrapbox { margin-left: auto; display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; font-size: 17px; }
.gear { width: 14px; height: 14px; border-radius: 50%; border: 3px dotted var(--amber); }
.round { width: 34px; height: 34px; border-radius: 50%; border: 1px solid var(--line); background: var(--glass); display: grid; place-items: center; padding: 0; }
.round svg { width: 14px; height: 14px; stroke: none; }
#btnSound svg { width: 16px; height: 16px; stroke: currentColor; }
#btnSound .mute, #btnSound.off .wave { display: none; }
#btnSound.off .mute { display: inline; }
#btnSound.off { color: var(--dim); }
.wall { display: grid; grid-template-columns: auto 1fr auto; gap: 8px; align-items: center; font-size: 11px; color: var(--dim); letter-spacing: 0.08em; text-transform: uppercase; }
.track { height: 6px; border-radius: 3px; background: var(--line); overflow: hidden; }
.track i { display: block; height: 100%; background: linear-gradient(90deg, #7fa6d9, var(--cold)); transition: width 0.25s; }
.track i.low { background: var(--red); animation: blink 0.8s infinite alternate; }
@keyframes blink { to { opacity: 0.5; } }
.wall small { font-variant-numeric: tabular-nums; }
.walls { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; font-size: 10px; color: var(--dim); }
.walls span { display: flex; align-items: center; gap: 5px; pointer-events: auto; }
.walls .track { flex: 1; height: 4px; }
.track i.down { width: 100% !important; background: var(--red); opacity: 0.35; }

#coach {
  position: fixed; left: calc(50% + (env(safe-area-inset-left) - env(safe-area-inset-right)) / 2); bottom: calc(env(safe-area-inset-bottom) + 86px); transform: translateX(-50%);
  width: min(360px, calc(100% - 32px - env(safe-area-inset-left) - env(safe-area-inset-right))); padding: 12px 14px; border-radius: 12px; background: var(--glass); border: 1px solid var(--line);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); font-size: 14px; line-height: 1.4; pointer-events: none;
}

#dock { position: fixed; left: 0; right: 0; bottom: 0; padding: 10px calc(env(safe-area-inset-right) + 16px) calc(env(safe-area-inset-bottom) + 16px) calc(env(safe-area-inset-left) + 16px); display: flex; justify-content: center; pointer-events: none; }
#dock button {
  pointer-events: auto; display: flex; align-items: center; gap: 8px; padding: 12px 18px; border-radius: 999px;
  border: 1px solid rgba(255, 181, 71, 0.4); background: var(--glass); color: var(--amber); font-weight: 700; font-size: 15px;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
}
#dock button svg { width: 22px; height: 22px; }
#dock button:disabled { color: var(--dim); border-color: var(--line); }
#dock { flex-wrap: wrap; gap: 10px; }
#btnLens { color: var(--cold) !important; border-color: rgba(188, 216, 255, 0.4) !important; }
.lensdot { width: 12px; height: 12px; border-radius: 50%; background: var(--cold); box-shadow: 0 0 8px currentColor; }
.heat { flex-basis: 100%; height: 5px; max-width: 260px; border-radius: 3px; background: var(--line); overflow: hidden; pointer-events: none; }
.heat i { display: block; height: 100%; width: 0; background: linear-gradient(90deg, #ffb547, #ff5a4a); }
.charge { flex-basis: 100%; height: 4px; max-width: 260px; border-radius: 3px; background: var(--line); overflow: hidden; pointer-events: none; }
.charge i { display: block; height: 100%; width: 100%; background: linear-gradient(90deg, #7fb8ff, #bcd8ff); transition: width 0.3s linear; }
.charge i.low { background: linear-gradient(90deg, #ff9a4a, #ffd27a); }
.heat i.hot { animation: blink 0.25s infinite alternate; }
.heat { transition: height 0.2s; }
.heat.strain { height: 9px; box-shadow: 0 0 10px rgba(255, 90, 74, 0.6); }
@media (prefers-reduced-motion: no-preference) { .heat.strain { animation: strain-shake 0.14s infinite alternate; } }
@keyframes strain-shake { from { transform: translateX(-1.5px); } to { transform: translateX(1.5px); } }
#btnFlare.armed { background: rgba(255, 90, 74, 0.25); border-color: var(--red); color: #fff; }

/* CARDS: centred, or a drawer along the bottom while building (the camera lifts the base above it) */
#modal { position: fixed; inset: 0; display: grid; place-items: center; padding: 16px calc(env(safe-area-inset-right) + 16px) 16px calc(env(safe-area-inset-left) + 16px); background: rgba(2, 4, 8, 0.45); }
#modal.sheet { place-items: end center; padding: 0 env(safe-area-inset-right) 0 env(safe-area-inset-left); background: none; pointer-events: none; }
#modal.sheet .card { pointer-events: auto; width: min(480px, 100%); max-height: 60%; border-radius: 16px 16px 0 0; border-bottom: none; }
/* THE BUILD BAR: four shop buttons in a row, then Start; the sheets opened from it or from a tap on the map are lists of short rows */
.shopbar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin: 2px 0 8px; }
.chip { display: grid; justify-items: center; gap: 2px; padding: 9px 4px; min-height: 52px; border-radius: 12px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); color: var(--ink); }
.chip b { font-size: 14px; } .chip small { font-size: 11px; color: var(--dim); white-space: nowrap; }
.chip:disabled { opacity: 0.45; }
.walls span[data-side] { cursor: pointer; padding: 4px 0; }
#modal.sheet .shop { max-height: 38vh; overflow: auto; align-content: start; }
@media (min-width: 720px) { #modal.sheet .card { width: min(560px, 100%); } }
.fold { padding: 4px 10px; border-radius: 999px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); font-size: 12px; color: var(--dim); }
.head-right { display: grid; justify-items: end; gap: 6px; }
.card {
  width: min(420px, 100%); max-height: calc(100% - 20px); overflow: auto; padding: 20px; border-radius: 16px;
  background: rgba(6, 10, 16, 0.86); border: 1px solid var(--line); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.55);
}
.card h1 { margin: 4px 0 10px; font-size: 40px; letter-spacing: 0.02em; color: var(--cold); text-shadow: 0 0 26px rgba(188, 216, 255, 0.45); }
.card h2 { margin: 2px 0 8px; font-size: 24px; display: flex; align-items: center; gap: 10px; }
.kicker { margin: 0; color: var(--dim); font-size: 11px; letter-spacing: 0.16em; text-transform: uppercase; }
.lede { color: #c4cfdc; line-height: 1.5; margin: 0 0 16px; }
.lede.small { font-size: 13px; }
.fine { color: var(--dim); font-size: 12px; margin: 12px 0 0; }
.fine.links a { color: var(--dim); }
.hint { color: var(--dim); font-size: 12px; margin: 10px 0; }
.sheet-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 10px; }
.scrap { margin: 4px 0 0; color: var(--amber); font-size: 13px; }
.scrap b { font-size: 20px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; margin: 4px 0 12px; }
.chips span { padding: 3px 9px; border-radius: 999px; font-size: 12px; color: var(--cold); border: 1px solid rgba(188, 216, 255, 0.25); }
.chips span.boss { color: var(--red); border-color: rgba(255, 90, 74, 0.5); }
.chips span.event { color: var(--amber); border-color: rgba(255, 181, 71, 0.5); }
.chips span.ally { color: var(--green); border-color: rgba(120, 230, 150, 0.45); }
.shop { display: grid; gap: 6px; }
.shop .kicker.sect { margin: 10px 0 0; }
.shop .row { flex-wrap: wrap; justify-content: space-between; padding: 9px 10px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.03); }
.shop .row > div:first-child { display: grid; gap: 2px; min-width: 0; }
.shop b { font-size: 14px; display: flex; align-items: center; gap: 8px; }
.shop small { color: var(--dim); font-size: 12px; line-height: 1.3; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.btns { display: flex; gap: 6px; }
.buy { display: grid; justify-items: center; min-width: 74px; padding: 7px 10px; border-radius: 9px; border: 1px solid rgba(255, 181, 71, 0.45); background: rgba(255, 181, 71, 0.1); color: var(--amber); font-weight: 700; font-size: 13px; }
.buy small { color: inherit; opacity: 0.8; font-size: 11px; }
.buy:disabled { opacity: 0.35; cursor: default; }
.pips { display: inline-flex; gap: 3px; }
.pips i { width: 7px; height: 7px; border-radius: 50%; background: rgba(255, 255, 255, 0.15); }
.pips i.on { background: var(--amber); }
.actions { display: grid; gap: 8px; margin-top: 12px; }
.actions button { padding: 12px; border-radius: 11px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.05); font-weight: 700; }
.actions button.primary { background: var(--cold); color: #08111f; border-color: var(--cold); }
.tally { display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; margin: 0 0 14px; }
.tally dt { color: var(--dim); }
.tally dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
/* While building, the start button stays in reach however far the shop scrolls. */
#modal.sheet .card { padding-bottom: 0; }
#modal.sheet .actions { position: sticky; bottom: 0; margin: 12px -20px 0; padding: 12px 20px calc(env(safe-area-inset-bottom) + 16px); background: linear-gradient(rgba(6, 10, 16, 0), rgba(6, 10, 16, 0.96) 30%); }

/* THE TITLE SCREEN: the intro art fills the screen (tall art on a phone held upright, wide art otherwise); the title sits in the dark sky and the card along the bottom */
#intro { position: fixed; inset: 0; background: #05080d url('../assets/intro-tall.webp') center / cover no-repeat; }
@media (min-aspect-ratio: 1/1) { #intro { background-image: url('../assets/intro-wide.webp'); } }
#intro::after { content: ''; position: absolute; inset: 0; background: linear-gradient(rgba(5, 8, 13, 0.35), rgba(5, 8, 13, 0) 28%, rgba(5, 8, 13, 0) 52%, rgba(5, 8, 13, 0.88) 100%); }
.intro-title { position: absolute; z-index: 1; left: 0; right: 0; top: max(10%, calc(env(safe-area-inset-top) + 28px)); text-align: center; padding: 0 16px; }
.intro-title p { margin: 0 0 4px; color: #c4cfdc; font-size: 12px; letter-spacing: 0.32em; text-transform: uppercase; }
.intro-title h1 { margin: 0; font-size: clamp(44px, 11vw, 92px); line-height: 1; letter-spacing: 0.04em; text-transform: uppercase; color: var(--cold); text-shadow: 0 0 34px rgba(188, 216, 255, 0.55), 0 3px 18px rgba(0, 0, 0, 0.8); }
#modal.title { place-items: end center; background: none; padding: 0 calc(env(safe-area-inset-right) + 16px) 0 calc(env(safe-area-inset-left) + 16px); z-index: 2; }
.card.title { background: none; border: none; box-shadow: none; backdrop-filter: none; -webkit-backdrop-filter: none; text-align: center; padding: 0 0 calc(env(safe-area-inset-bottom) + 20px); overflow: visible; }
.card.title .lede { text-shadow: 0 1px 10px rgba(0, 0, 0, 0.9); }
.card.title .actions button { background: rgba(8, 14, 22, 0.78); border-color: rgba(188, 216, 255, 0.35); }
.card.title .actions button.primary { background: var(--cold); border-color: var(--cold); }
@media (min-aspect-ratio: 1/1) { .intro-title { top: max(4%, calc(env(safe-area-inset-top) + 16px)); } .intro-title h1 { font-size: clamp(44px, 8vw, 84px); } }
@media (max-height: 520px) { .intro-title { top: 6%; } .intro-title h1 { font-size: 40px; } .card.title .lede { display: none; } }

/* THE STORY: the squad's picture with one line at a time. On a phone the picture fills the screen and the line sits on a gradient along the bottom; on a wide screen the picture takes the left and the lines the right. */
#story { position: fixed; inset: 0; z-index: 6; background: #05080d; overflow: hidden; cursor: pointer; }
#storyArt { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; object-position: 50% 40%; --zoom: 1; transform: scale(var(--zoom)); transition: transform 7s ease-out, transform-origin 1.2s ease; }
#story::after { content: ''; position: absolute; inset: 0; background: linear-gradient(rgba(5, 8, 13, 0) 40%, rgba(5, 8, 13, 0.92) 78%); pointer-events: none; }
.story-text { position: absolute; z-index: 1; left: 0; right: 0; bottom: 0; padding: 0 calc(env(safe-area-inset-right) + 20px) calc(env(safe-area-inset-bottom) + 20px) calc(env(safe-area-inset-left) + 20px); text-align: center; }
.story-text p { margin: 0 auto 16px; max-width: 34em; min-height: 4.8em; font-size: clamp(17px, 4.6vw, 22px); line-height: 1.45; text-shadow: 0 1px 12px rgba(0, 0, 0, 0.95); }
.story-text .actions { justify-content: center; }
@media (prefers-reduced-motion: no-preference) { #story .in { animation: story-in 0.9s ease both; } }
@keyframes story-in { from { opacity: 0; transform: translateY(6px); } }
@media (prefers-reduced-motion: reduce) { #storyArt { transition: none; } }
@media (min-aspect-ratio: 1/1) {
  #storyArt { right: auto; width: 46%; transform: scale(calc(1 + (var(--zoom) - 1) * 0.45)); }
  #story::after { background: linear-gradient(90deg, rgba(5, 8, 13, 0) 30%, #05080d 46%); }
  .story-text { left: 46%; top: 0; display: flex; flex-direction: column; justify-content: center; text-align: left; padding: 0 calc(env(safe-area-inset-right) + 6vw) 0 4vw; }
  .story-text p { margin-left: 0; font-size: clamp(20px, 2.4vw, 30px); min-height: 6.5em; }
  .story-text .actions { justify-content: flex-start; }
}

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

/* THE DIFFICULTY CARD: three big choices, each a name and a line under it */
.actions.choices button { display: grid; gap: 3px; text-align: left; padding: 12px 14px; }
.actions.choices button b { font-size: 16px; } .actions.choices button .sub { font-size: 12px; font-weight: 400; opacity: 0.8; }
.actions.choices button:disabled { opacity: 0.5; }

/* The title card's opt-out for the anonymous usage counts (shown only where counting is on) */
.switch { display: flex; align-items: center; justify-content: center; gap: 8px; margin: 8px 0 4px; font-size: 12px; color: var(--dim); cursor: pointer; }
.switch input { accent-color: var(--cold); width: 16px; height: 16px; margin: 0; }

/* A shop button that wants a tap (the Flares chip when you are nearly out) */
.chip.nudge:not(:disabled) { border-color: rgba(255, 181, 71, 0.7); box-shadow: 0 0 0 0 rgba(255, 181, 71, 0.5); animation: nudge 1.6s infinite; }
@keyframes nudge { 70% { box-shadow: 0 0 0 8px rgba(255, 181, 71, 0); } 100% { box-shadow: 0 0 0 0 rgba(255, 181, 71, 0); } }
@media (prefers-reduced-motion: reduce) { .chip.nudge:not(:disabled) { animation: none; } }
