/* Tendrils: the field is one full-screen canvas (a microscope slide); over it sits the HUD in the original game's
   style: small white caps for ZONE and POWER LIMIT top left, a thin power bar split by each side's share and TIME
   top right, and a typewriter tip line under them with a blinking caret. Round white-ringed buttons for pause and
   speed. The cards between battles are dark grey panels with a thin light edge. The title screen and the sheets are
   shared/mainmenu.js (menu.css, loaded after this); only their colours are set here (--sg-*). Colours follow
   art.js: green is you and the accent, yellow the pulses and the tip, red, purple and blue the foes, grey neutral. */
:root {
  --bg: #1b1c1e; --bg-hi: #333437; --ink: #f0f0ea; --ink-soft: #b4b6b0; --line: rgba(230, 230, 220, 0.18);
  --accent: #4cc552; --accent-ink: #0a1a0b; --panel: #242527; --panel-edge: rgba(230, 230, 220, 0.28); --gold: #ffd257;
  --yellow: #f3e64a;
  --grey: #a9adb2; --green: #3cb842; --red: #c8343a; --purple: #b23dc4; --blue: #3577d8;
  --sheet: #1f2022; --sheet-ink: #f0f0ea; --sheet-soft: #b4b6b0;
  --hud-font: Verdana, Tahoma, "DejaVu Sans", "Segoe UI", system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
* { touch-action: manipulation; }
html, body { margin: 0; height: 100%; background: var(--bg); }
body {
  font-family: "Baloo 2", ui-rounded, system-ui, sans-serif; color: var(--ink);
  overflow: hidden; overscroll-behavior: none;
}
button { font: inherit; color: inherit; -webkit-tap-highlight-color: transparent; }
.app {
  position: fixed; inset: 0; overflow: hidden;
  -webkit-user-select: none; user-select: none; -webkit-touch-callout: none;
}
#field { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; }

/* ---- the HUD ---- */
.hud {
  position: absolute; left: 0; right: 0; top: 0; z-index: 5;
  padding: var(--sg-corner-top) 10px 0 var(--sg-corner-left); /* the corner's menu button heads the row (shared/menu.css) */
  display: flex; align-items: center; gap: 10px; pointer-events: none;
  font-family: var(--hud-font); text-transform: uppercase;
}
.hud > * { pointer-events: auto; }
/* round, white-ringed, like the original's buttons */
.icon-btn {
  width: 44px; height: 44px; flex: none; display: grid; place-items: center; padding: 0;
  border: 2px solid rgba(240, 240, 232, 0.92); border-radius: 50%; background: rgba(16, 17, 18, 0.72); cursor: pointer;
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35), 0 2px 8px rgba(0, 0, 0, 0.35);
}
.icon-btn svg { width: 20px; height: 20px; stroke: #f0f0ea; stroke-width: 3; stroke-linecap: round; fill: none; }
.icon-btn:active { transform: scale(0.93); }
.speed b { font-family: var(--hud-font); font-size: 13px; font-weight: 700; line-height: 1; text-transform: none; }
.speed[aria-pressed="true"] { border-color: var(--yellow); color: var(--yellow); background: rgba(60, 56, 10, 0.7); }
.hud-zone {
  flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; pointer-events: none;
  font-size: 11.5px; line-height: 1.25; letter-spacing: 0.03em; color: #e6e6e0; white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
.hud-zone b { font-weight: 400; color: #ffffff; }
.hud-right { flex: none; display: grid; justify-items: end; gap: 3px; pointer-events: none; }
.share {
  width: 96px; height: 11px; display: flex; overflow: hidden; background: rgba(0, 0, 0, 0.45);
  border: 1.5px solid rgba(245, 245, 238, 0.95); box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.35);
}
.share i { display: block; height: 100%; background: var(--c, #888); transition: width 0.3s linear; }
.hud-time {
  font-size: 11px; line-height: 1.2; letter-spacing: 0.03em; color: #e6e6e0; white-space: nowrap;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8);
}
.hud-time b { font-weight: 400; color: #fff; font-variant-numeric: tabular-nums; }
.hud-stars { color: var(--gold); letter-spacing: 1px; font-size: 11px; line-height: 1; min-height: 11px; }
.hud-stars i { font-style: normal; }
.hud-stars i.off { color: rgba(255, 255, 255, 0.22); }

/* the typewriter tip, under the HUD: "> IT'S TIME TO ..._" */
.tip {
  position: absolute; left: 12px; right: 12px; top: calc(env(safe-area-inset-top, 0px) + 56px); z-index: 6;
  margin: 0; padding: 0; pointer-events: none; text-align: left;
  font-family: var(--hud-font); font-size: 12px; line-height: 1.4; letter-spacing: 0.03em; text-transform: uppercase;
  color: var(--yellow); text-shadow: 0 1px 2px rgba(0, 0, 0, 0.9), 0 0 6px rgba(0, 0, 0, 0.6);
}
.tip .caret { font-style: normal; animation: caret 1s steps(1) infinite; }
@keyframes caret { 50% { opacity: 0; } }

/* ---- cards between battles (intro, results) ---- */
.card-layer {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: rgba(8, 9, 10, 0.7); overflow-y: auto;
}
.card {
  width: 100%; max-width: 400px; border-radius: 6px; padding: 16px 16px 14px;
  background: rgba(30, 31, 33, 0.96);
  border: 1px solid var(--panel-edge); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.6);
  animation: rise 0.25s ease-out;
}
.card .kicker {
  margin: 0; font-family: var(--hud-font); font-size: 11.5px; font-weight: 400; color: var(--ink-soft);
  letter-spacing: 0.06em; text-transform: uppercase;
}
.card h2 { margin: 2px 0 6px; font-size: 28px; line-height: 1.1; font-weight: 800; color: #fff; }
.card h2.win { color: #7dea7f; }
.card h2.loss { color: #ff8a84; }
.card p { margin: 6px 0; color: var(--ink-soft); font-size: 16px; line-height: 1.35; }
.card .btns { display: flex; gap: 10px; margin-top: 14px; }
.btn {
  flex: 1; min-height: 50px; border-radius: 25px; border: 1.5px solid rgba(240, 240, 232, 0.6); background: rgba(255, 255, 255, 0.05);
  font-weight: 800; font-size: 17px; cursor: pointer; padding: 0 12px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: #e9f7e4; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(76, 197, 82, 0.25); }
.btn:active { transform: scale(0.97); }
.foes { display: flex; gap: 8px; flex-wrap: wrap; margin: 10px 0 2px; }
.foe { display: flex; align-items: center; gap: 8px; padding: 4px 12px 4px 4px; border-radius: 22px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); font-size: 15px; font-weight: 700; }
.foe .face { width: 36px; height: 36px; border-radius: 50%; overflow: hidden; background: #26272a; }
.foe .face svg, .foe .face canvas { width: 100%; height: 100%; display: block; }
.foe small { display: block; color: var(--ink-soft); font-size: 12px; line-height: 1; font-weight: 600; }
.teach { display: flex; gap: 12px; align-items: center; margin: 12px 0 4px; padding: 10px 12px; border-radius: 6px; background: rgba(243, 230, 74, 0.07); border: 1px solid rgba(243, 230, 74, 0.35); }
.teach .ic { width: 40px; height: 40px; flex: none; display: grid; place-items: center; border-radius: 50%; background: #1d1e20; border: 2px solid var(--yellow); }
.teach .ic svg { width: 24px; height: 24px; }
.teach span { font-size: 16px; line-height: 1.3; color: var(--ink); }
.par { display: grid; gap: 4px; margin: 10px 0 0; padding: 0; list-style: none; }
.par li { display: flex; align-items: center; gap: 10px; font-size: 15px; color: var(--ink); }
.par .st { color: var(--gold); letter-spacing: 1px; min-width: 48px; }
.par .st i { font-style: normal; }
.par .st i.off { color: rgba(255, 255, 255, 0.18); }
.bigstars { display: flex; justify-content: center; gap: 8px; margin: 8px 0 4px; }
.bigstars svg { width: 54px; height: 54px; }
.bigstars path { fill: rgba(255, 255, 255, 0.08); stroke: rgba(255, 255, 255, 0.25); stroke-width: 1.2; }
.bigstars .on path { fill: var(--gold); stroke: #fff4c2; }
.bigstars .on { animation: pop 0.4s ease-out both; }
.bigstars .on:nth-child(2) { animation-delay: 0.15s; }
.bigstars .on:nth-child(3) { animation-delay: 0.3s; }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 6px 12px; margin: 10px 0 0; font-size: 15px; }
.stats div { display: flex; justify-content: space-between; gap: 8px; padding: 4px 10px; border-radius: 4px; background: rgba(255, 255, 255, 0.04); }
.stats span { color: var(--ink-soft); }
.stats b { font-variant-numeric: tabular-nums; }
.newlist { margin: 10px 0 0; padding: 0; list-style: none; display: grid; gap: 4px; }
.newlist li { font-size: 15px; color: var(--yellow); font-weight: 700; }

/* ---- Bri's notes: a small lab-notebook sticky note on some zone cards, signed "— Bri" ---- */
.card .bri-note {
  position: relative; display: block; width: fit-content; max-width: min(270px, 100%); margin: 12px 0 4px auto;
  padding: 9px 12px 7px; border-radius: 2px 2px 3px 10px; transform: rotate(-1.2deg);
  background: linear-gradient(180deg, #f6efc9, #efe5b6); color: #3a372f;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.4) inset, 0 6px 14px -6px rgba(0, 0, 0, 0.6);
}
/* a strip of lab tape holding it on */
.card .bri-note::before {
  content: ""; position: absolute; left: 50%; top: -7px; width: 54px; height: 14px; transform: translateX(-50%) rotate(2deg);
  background: rgba(230, 236, 240, 0.55); border-left: 1px dashed rgba(255, 255, 255, 0.5); border-right: 1px dashed rgba(255, 255, 255, 0.5);
}
.card .bri-note .bri-text { margin: 0; font-size: 14.5px; line-height: 1.3; color: #3a372f; }
.card .bri-note .bri-sign { display: block; margin-top: 3px; text-align: right; font-size: 13.5px; font-weight: 800; color: #2f5a94; }

/* ---- sheets: levels, looks, achievements ---- */
.td-world { margin: 4px 0 14px; }
.td-world h3 {
  margin: 0 0 8px; font-family: var(--hud-font); font-size: 12.5px; letter-spacing: 0.05em; text-transform: uppercase;
  color: var(--ink-soft); font-weight: 400; display: flex; justify-content: space-between;
}
.td-world h3 small { font-weight: 400; color: var(--gold); }
.td-levels { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 8px; }
.td-level {
  min-height: 44px; min-width: 0; border-radius: 50%; aspect-ratio: 1; border: 2px solid rgba(240, 240, 232, 0.55); background: rgba(54, 168, 58, 0.16);
  display: grid; place-items: center; align-content: center; gap: 0; padding: 4px 2px; cursor: pointer; max-width: 66px; justify-self: center; width: 100%;
}
.td-level b { font-size: 19px; line-height: 1; }
.td-level .stars { font-size: 10px; letter-spacing: 0; color: rgba(255, 255, 255, 0.2); }
.td-level .stars i { font-style: normal; }
.td-level .stars i.on { color: var(--gold); }
.td-level.locked { opacity: 0.3; background: rgba(140, 140, 140, 0.12); }
.td-level.next { border-color: var(--yellow); box-shadow: 0 0 12px rgba(243, 230, 74, 0.35); }
/* an optional level: off the main path, harder (a dashed purple edge) */
.td-level.side { border: 2px dashed rgba(224, 124, 244, 0.7); background: rgba(178, 61, 196, 0.14); }
.td-level.side.next { border-color: var(--yellow); }
/* the purple stretch's heading */
h3.td-exp {
  margin: 22px 0 10px; padding: 10px 14px; border-radius: 6px; font-size: 17px; font-weight: 800; color: #e07cf4;
  background: rgba(178, 61, 196, 0.1); border: 1px solid rgba(224, 124, 244, 0.4);
  display: grid; gap: 2px; letter-spacing: 0.02em;
}
h3.td-exp small { font-size: 13px; font-weight: 700; color: var(--ink-soft); letter-spacing: 0; }
/* the level card's one line */
.card p.intro { margin: 2px 0 10px; color: var(--ink); opacity: 0.85; }
.td-picks { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: 10px; }
.td-pick { border-radius: 8px; border: 1.5px solid var(--panel-edge); background: rgba(255, 255, 255, 0.04); padding: 8px 6px; display: grid; justify-items: center; gap: 2px; cursor: pointer; min-height: 120px; }
.td-pick .face { width: 64px; height: 64px; border-radius: 50%; overflow: hidden; background: #26272a; }
.td-pick .face svg, .td-pick .face canvas { width: 100%; height: 100%; display: block; }
.td-pick b { font-size: 15px; line-height: 1.1; text-align: center; }
.td-pick small { font-size: 12px; color: var(--ink-soft); text-align: center; }
.td-pick.on { border-color: var(--accent); background: rgba(76, 197, 82, 0.1); }
.td-pick.locked .face { filter: grayscale(1) brightness(0.45); }
.td-note { margin: 0 0 12px; color: var(--ink-soft); font-size: 15px; }
.td-ach { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.td-ach li { display: flex; gap: 10px; align-items: center; padding: 8px 10px; border-radius: 6px; background: rgba(255, 255, 255, 0.04); }
.td-ach li .medal { width: 30px; height: 30px; border-radius: 50%; flex: none; display: grid; place-items: center; background: var(--gold); color: #3a2a00; font-weight: 800; }
.td-ach li.no .medal { background: rgba(255, 255, 255, 0.1); color: transparent; }
.td-ach li b { display: block; }
.td-ach li span { font-size: 14px; color: var(--ink-soft); }
.td-howto p { margin: 0 0 10px; }
.td-form { display: grid; gap: 14px; }
.td-form h3 { margin: 0 0 6px; font-size: 15px; color: var(--ink-soft); font-weight: 700; }
.td-form .btns { display: flex; gap: 10px; }
.seg { display: flex; gap: 6px; flex-wrap: wrap; }
.seg button { flex: 1 0 auto; min-height: 44px; min-width: 44px; padding: 0 10px; border-radius: 22px; border: 1.5px solid var(--panel-edge); background: rgba(255, 255, 255, 0.05); font-weight: 700; cursor: pointer; }
.seg button.on { background: var(--accent); color: var(--accent-ink); border-color: #e9f7e4; }
.td-howto .kinds { display: grid; gap: 8px; margin: 6px 0 10px; }
.td-howto .kinds div { display: flex; gap: 10px; align-items: center; }
.td-howto .kinds svg { flex: none; }

.toast {
  position: absolute; left: 50%; bottom: calc(env(safe-area-inset-bottom, 0px) + 24px); z-index: 30; transform: translate(-50%, 8px);
  margin: 0; padding: 7px 12px; border-radius: 4px; background: rgba(24, 25, 27, 0.94); border: 1px solid var(--panel-edge);
  font-family: var(--hud-font); font-size: 13px; text-transform: uppercase; letter-spacing: 0.03em;
  opacity: 0; transition: opacity 0.2s, transform 0.2s; pointer-events: none; max-width: calc(100% - 24px); text-align: center;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }

/* ---- the title screen's colours (the layout is shared/mainmenu.js) ---- */
#mm {
  --sg-bg: radial-gradient(ellipse 110% 60% at 50% 25%, #35373a, transparent 75%), radial-gradient(ellipse 70% 45% at 85% 88%, rgba(180, 38, 46, 0.14), transparent 70%), radial-gradient(ellipse 70% 45% at 10% 80%, rgba(54, 168, 58, 0.16), transparent 70%), var(--bg);
  --sg-ink: var(--ink); --sg-ink-soft: var(--ink-soft);
  --sg-title: #ffffff; --sg-title-shadow: 0 0 16px rgba(76, 197, 82, 0.7), 0 0 2px #3cb842;
  --sg-accent: var(--accent); --sg-accent-ink: var(--accent-ink);
  --sg-card: #26272a; --sg-card-ink: var(--ink); --sg-line: rgba(230, 230, 220, 0.2);
}
#mm .td-title-art { width: 300px; height: 150px; max-width: 92vw; border-radius: 14px; overflow: hidden; box-shadow: 0 0 0 1.5px rgba(240, 240, 232, 0.35), 0 14px 30px -14px rgba(0, 0, 0, 0.8); }
#mm .td-title-art > * { display: block; width: 100%; height: 100%; object-fit: cover; }
.sg-sheet { --sg-sheet-bg: var(--sheet); --sg-sheet-ink: var(--sheet-ink); --sg-accent: var(--accent); --sg-accent-ink: var(--accent-ink); --sg-ink-soft: var(--sheet-soft); }

@keyframes pop { 0% { transform: scale(0.6); opacity: 0.4; } 55% { transform: scale(1.18); opacity: 1; } 100% { transform: scale(1); } }
@keyframes rise { from { transform: translateY(16px); opacity: 0; } to { transform: none; opacity: 1; } }
@media (max-height: 680px) {
  .card { padding: 12px 14px 12px; }
  .card h2 { font-size: 24px; }
  .bigstars svg { width: 44px; height: 44px; }
}
@media (max-width: 370px) {
  .hud { gap: 8px; padding-right: 8px; } /* (the left stays under the corner) */
  .hud-zone { font-size: 10.5px; }
  .share { width: 84px; }
  .tip { font-size: 11px; }
}
@media (prefers-reduced-motion: reduce) {
  .card .bri-note { transform: none; }
  .card, .bigstars .on { animation: none; }
  .toast, .share i { transition: none; }
  .tip .caret { animation: none; }
}
#mm.sg-scened .td-title-art { border-radius: 0; overflow: visible; box-shadow: none; }
