/*
 * Swarm Leaper - shell styling.
 *
 * The canvas is the game; everything here is chrome that has to stay out of its way and stay
 * legible against a background that runs from near-black forest floor to near-black deep space
 * with a bright blue sky in the middle. That is why every panel is a dark translucent slab with
 * its own backdrop blur rather than a colour picked to match the art: the art does not hold still.
 *
 * Safe-area insets are read from CSS variables that safe-area.js is allowed to zero out when the
 * platform launcher has already inset us - applying them twice pushes the HUD down past its own
 * canvas-drawn counterparts.
 */

:root {
  --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);

  --ink: #f2efe6;
  --dim: #a8a79e;
  --slab: rgba(12, 16, 14, 0.72);
  --slab-hard: rgba(10, 13, 12, 0.92);
  --line: rgba(255, 255, 255, 0.14);
  --moss: #7ec26a;
  --amber: #ffd579;
  --danger: #ff6a5e;

  --ui: "Avenir Next", "Segoe UI Variable Display", "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: #06090a;
  color: var(--ink);
  font-family: var(--ui);
  overscroll-behavior: none;
  user-select: none;
  -webkit-user-select: none;
}

#game {
  position: fixed;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

/* ---------------------------------------------------------------- HUD */
#hud {
  position: fixed;
  top: 0; left: 0; right: 0;
  padding: calc(var(--safe-top) + 10px) calc(var(--safe-right) + 12px) 0 calc(var(--safe-left) + 12px);
  pointer-events: none;
  z-index: 5;
}
#hud[hidden] { display: none; }

.hud-top {
  display: flex;
  align-items: flex-start;
  gap: 10px;
}

.readout {
  display: flex;
  align-items: baseline;
  gap: 3px;
  background: var(--slab);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 6px 11px 7px;
  flex-wrap: wrap;
}
.readout b {
  font-size: clamp(22px, 6.4vw, 34px);
  font-weight: 800;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
  line-height: 1.12;
}
.readout span { font-size: 12px; color: var(--dim); font-weight: 700; }
.readout i {
  display: block;
  width: 100%;
  font-style: normal;
  font-size: 11px;
  color: var(--dim);
  letter-spacing: 0.06em;
  text-transform: uppercase;
  margin-top: 2px;
}
.readout i em { font-style: normal; color: var(--ink); font-variant-numeric: tabular-nums; }

.hud-mid { flex: 1; min-width: 0; text-align: center; padding-top: 3px; }
#hudZone {
  font-size: clamp(10px, 3vw, 13px);
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.82);
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.8);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.pips { display: flex; gap: 5px; justify-content: center; margin-top: 6px; flex-wrap: wrap; }
.pip {
  font-style: normal;
  font-size: 13px;
  line-height: 1;
  padding: 4px 7px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--slab);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  display: inline-flex;
  align-items: center;
  gap: 3px;
}
.pip b { font-size: 10px; font-weight: 800; }
.pip.shield { color: #8ed7ff; border-color: rgba(142, 215, 255, 0.45); }
.pip.net    { color: #dbe8ff; border-color: rgba(219, 232, 255, 0.4); }
.pip.wings  { color: #fff2b0; border-color: rgba(255, 242, 176, 0.45); }
.pip.slow   { color: #b9f0d6; border-color: rgba(185, 240, 214, 0.45); }

.hud-btns { display: flex; gap: 6px; pointer-events: auto; }
.icon {
  width: 38px; height: 38px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: var(--slab);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  color: var(--ink);
  font-size: 17px;
  line-height: 1;
  cursor: pointer;
  display: grid;
  place-items: center;
}
.icon:active { transform: scale(0.94); }

/* the band progress bar - the thing you watch when you are not watching the swarm */
.bar {
  position: relative;
  margin: 9px auto 0;
  max-width: min(560px, 100%);
  height: 22px;
  border-radius: 11px;
  border: 1px solid var(--line);
  background: var(--slab);
  backdrop-filter: blur(9px);
  -webkit-backdrop-filter: blur(9px);
  overflow: hidden;
}
.bar i {
  position: absolute;
  inset: 0 auto 0 0;
  width: 0;
  background: linear-gradient(90deg, rgba(120, 200, 255, 0.35), rgba(150, 226, 255, 0.85));
  /* NO TRANSITION HERE ON PURPOSE. The width is rewritten every frame, so a 120ms transition is
     restarted every frame and one is therefore ALWAYS in flight - the element never stops
     animating. It buys nothing visually (the value is already per-frame smooth) and it makes the
     page permanently unstable, which is how it hung a screenshot for thirty seconds in the
     platform's QA browser. Same reasoning applies to #hudGap below. */
}
.bar[data-big="1"] i {
  background: linear-gradient(90deg, rgba(255, 190, 90, 0.35), rgba(255, 216, 120, 0.92));
}
.bar span {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  text-shadow: 0 1px 4px rgba(0, 0, 0, 0.85);
}

#hudGap {
  position: fixed;
  left: 0; right: 0;
  bottom: calc(var(--safe-bottom) + 20px);
  text-align: center;
  font-size: clamp(13px, 4vw, 18px);
  font-weight: 900;
  letter-spacing: 0.28em;
  color: var(--danger);
  text-shadow: 0 2px 14px rgba(0, 0, 0, 0.9);
  opacity: 0;
  pointer-events: none;
}

/* ------------------------------------------------------------- screens */
.screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: calc(var(--safe-top) + 16px) calc(var(--safe-right) + 16px) calc(var(--safe-bottom) + 16px) calc(var(--safe-left) + 16px);
  pointer-events: none;
}
.screen[hidden] { display: none; }

.card {
  pointer-events: auto;
  width: min(420px, 100%);
  background: var(--slab-hard);
  backdrop-filter: blur(16px) saturate(1.2);
  -webkit-backdrop-filter: blur(16px) saturate(1.2);
  border: 1px solid var(--line);
  border-radius: 22px;
  padding: 22px 20px 18px;
  text-align: center;
  box-shadow: 0 24px 70px rgba(0, 0, 0, 0.6);
  max-height: 100%;
  overflow: auto;
}

h1 {
  margin: 0 0 2px;
  font-size: clamp(34px, 11vw, 54px);
  font-weight: 900;
  letter-spacing: -0.035em;
  line-height: 1.02;
  text-transform: uppercase;
}
h1 span {
  display: block;
  color: var(--moss);
  text-shadow: 0 0 26px rgba(126, 194, 106, 0.4);
}
.tag { margin: 8px 0 18px; color: var(--dim); font-size: 14px; line-height: 1.45; }

.big {
  pointer-events: auto;
  width: 100%;
  border: none;
  border-radius: 15px;
  padding: 15px 18px;
  font: inherit;
  font-size: 17px;
  font-weight: 800;
  letter-spacing: 0.05em;
  text-transform: uppercase;
  color: #0c1a0e;
  background: linear-gradient(180deg, #9ada84, #6bb257);
  box-shadow: 0 8px 0 #3d6b32, 0 14px 26px rgba(0, 0, 0, 0.42);
  cursor: pointer;
}
.big:active { transform: translateY(4px); box-shadow: 0 4px 0 #3d6b32, 0 8px 16px rgba(0, 0, 0, 0.4); }

.link {
  margin-top: 12px;
  background: none;
  border: none;
  color: var(--dim);
  font: inherit;
  font-size: 13px;
  text-decoration: underline;
  text-underline-offset: 3px;
  cursor: pointer;
  pointer-events: auto;
}

.stats { display: flex; gap: 10px; margin: 16px 0 4px; }
.stats.slim { justify-content: center; }
.stats div {
  flex: 1;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  border-radius: 13px;
  padding: 9px 6px;
}
.stats b {
  display: block;
  font-size: 21px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  line-height: 1.1;
}
.stats span {
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
}

.bigscore { display: flex; align-items: baseline; justify-content: center; gap: 6px; }
.bigscore b {
  font-size: clamp(46px, 15vw, 72px);
  font-weight: 900;
  letter-spacing: -0.045em;
  font-variant-numeric: tabular-nums;
  /* The platform's viewport-fit check measures the font's INTRINSIC text box against the element
     box, and this face's default line box is ~1.33em - so any line-height below that reports the
     number as vertically clipped no matter how it looks. 1.4 clears it with room. */
  line-height: 1.4;
}
.bigscore span { font-size: 15px; color: var(--dim); font-weight: 700; }
.zone { margin: 4px 0 0; font-size: 13px; color: var(--dim); }
.zone em { font-style: normal; color: var(--ink); }
.note { margin: 12px 0 0; font-size: 14px; color: var(--ink); opacity: 0.86; }
.newbest {
  display: inline-block;
  margin-bottom: 10px;
  padding: 4px 12px;
  border-radius: 99px;
  background: var(--amber);
  color: #2a1c00;
  font-size: 11px;
  font-weight: 900;
  letter-spacing: 0.16em;
}

.board {
  pointer-events: auto;
  width: min(420px, 100%);
  background: var(--slab);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 12px 14px 14px;
}
.board h3 {
  margin: 0 0 8px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
}
.brow {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 5px 0;
  border-top: 1px solid rgba(255, 255, 255, 0.07);
  font-size: 14px;
}
.brow b { width: 18px; color: var(--dim); font-weight: 700; }
.brow span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.brow em { font-style: normal; font-weight: 800; font-variant-numeric: tabular-nums; }

/* -------------------------------------------------------------- sheets */
.sheet {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(var(--safe-top) + 12px) calc(var(--safe-right) + 12px) calc(var(--safe-bottom) + 12px) calc(var(--safe-left) + 12px);
  background: rgba(4, 7, 6, 0.66);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
}
.sheet[hidden] { display: none; }
.sheetcard {
  width: min(480px, 100%);
  max-height: 100%;
  overflow: auto;
  background: var(--slab-hard);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 20px 18px 18px;
  -webkit-overflow-scrolling: touch;
}
.sheet.wide .sheetcard { width: min(760px, 100%); }
.sheetcard h2 { margin: 0 0 4px; font-size: 22px; font-weight: 900; letter-spacing: -0.02em; }
.sheetcard h3 {
  margin: 18px 0 8px;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--dim);
}
.sheetcard p { font-size: 14px; line-height: 1.5; color: rgba(242, 239, 230, 0.86); margin: 8px 0; }
.sheetcard p.dim { color: var(--dim); font-size: 12.5px; }
.sheetcard .big { margin-top: 16px; }

.rule { display: flex; gap: 10px; padding: 7px 0; border-top: 1px solid rgba(255, 255, 255, 0.07); }
.rule b { flex: 0 0 88px; font-size: 13px; font-weight: 800; }
.rule span { flex: 1; font-size: 13px; line-height: 1.4; color: rgba(242, 239, 230, 0.8); }
.sw-crumble { color: #c9ab84; }
.sw-spring  { color: #4fd6a6; }
.sw-rocket  { color: #ffab4d; }
.sw-goo     { color: #b6d84a; }
.sw-slick   { color: #a8e2ff; }
.sw-mover   { color: #c0a9e8; }
.sw-nest    { color: #ff8a7e; }

/* ----------------------------------------------------------- the tuner */
#debugBody { margin-top: 10px; }
.dhead {
  font-size: 11px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  margin: 14px 0 6px;
}
.dhead b { color: var(--ink); }
#debugBody table { width: 100%; border-collapse: collapse; font-size: 11.5px; }
#debugBody th {
  text-align: left;
  font-size: 10px;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: var(--dim);
  padding-bottom: 4px;
  font-weight: 700;
}
#debugBody td { padding: 3px 6px 3px 0; border-top: 1px solid rgba(255, 255, 255, 0.06); vertical-align: top; }
#debugBody tr.live td { background: rgba(126, 194, 106, 0.09); }
#debugBody td i { font-style: normal; color: var(--moss); font-size: 9.5px; letter-spacing: 0.08em; }
#debugBody .arms span {
  display: inline-block;
  padding: 1px 5px;
  margin: 1px 3px 1px 0;
  border-radius: 6px;
  background: rgba(255, 255, 255, 0.05);
  color: var(--dim);
}
#debugBody .arms span.on { background: rgba(126, 194, 106, 0.22); color: var(--ink); font-weight: 700; }
#debugBody .arms em { font-style: normal; opacity: 0.66; font-size: 10px; }
#debugBody pre {
  font-size: 10.5px;
  line-height: 1.45;
  color: var(--dim);
  white-space: pre-wrap;
  margin: 0;
  max-height: 180px;
  overflow: auto;
}

/* Landscape phones: the title card has to fit in very little height. */
@media (max-height: 460px) {
  .card { padding: 14px 16px 12px; }
  h1 { font-size: clamp(24px, 7vh, 34px); }
  .tag { margin: 6px 0 10px; font-size: 12px; }
  .stats { margin: 10px 0 2px; }
  .stats b { font-size: 17px; }
  .big { padding: 11px 16px; font-size: 15px; }
  .board { display: none; }
}


/* results card: a secondary way out beside the primary one */
.btnrow { display: flex; gap: 8px; align-items: stretch; }
.btnrow .big { flex: 1; }
.ghost {
  flex: 0 0 auto;
  padding: 15px 16px;
  border-radius: 15px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06);
  color: var(--ink);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  cursor: pointer;
}
.ghost:active { transform: translateY(2px); }
