/* VELOCITY — base: type, tokens, controls, the frame, shared motion.
 *
 * The look: a clinical instrument at night. Deep blue-black ground, glass
 * panels, luminous data. Each domain keeps its hue (body mint · tech violet
 * · world blue · money gold · energy orange · people rose); amber warns,
 * red means mortal danger. Motion reports a change of state and eases
 * everywhere; reduced motion (OS or Settings) lands all of it at once.
 */

/* ============ type (bundled, SIL Open Font License) ============ */
@font-face { font-family: "Inter"; src: url("../assets/fonts/inter-latin-wght-normal.woff2") format("woff2"); font-weight: 100 900; font-style: normal; font-display: swap; }
@font-face { font-family: "Space Grotesk"; src: url("../assets/fonts/space-grotesk-latin-wght-normal.woff2") format("woff2"); font-weight: 300 700; font-style: normal; font-display: swap; }
@font-face { font-family: "JetBrains Mono"; src: url("../assets/fonts/jetbrains-mono-latin-wght-normal.woff2") format("woff2"); font-weight: 100 800; font-style: normal; font-display: swap; }

:root {
  color-scheme: dark;

  /* ---- ground & surfaces ---- */
  --bg-0: #03060B;
  --bg-1: #060B13;
  --bg-2: #0A111C;
  --glass: rgba(13, 21, 33, 0.86);
  --glass-2: rgba(19, 29, 45, 0.9);
  --glass-hi: rgba(30, 44, 66, 0.55);
  --well: rgba(4, 9, 16, 0.55);
  --well-2: rgba(120, 170, 230, 0.06);
  --track: rgba(120, 170, 230, 0.12);
  --hover: rgba(120, 180, 255, 0.07);
  --hover-2: rgba(120, 180, 255, 0.12);

  /* ---- lines ---- */
  --line: rgba(130, 175, 230, 0.13);
  --line-strong: rgba(150, 195, 245, 0.24);
  --line-soft: rgba(130, 175, 230, 0.075);
  --edge-hi: rgba(200, 230, 255, 0.07);

  /* ---- type colours ---- */
  --text: #E8F0F9;
  --text-2: #B3C2D4;
  --text-3: #7C8EA4;
  --text-4: #56687E;

  /* ---- the action colour (End Year, focus, primary) ---- */
  --accent: #2FE3CB;
  --accent-2: #19B8A6;
  --accent-ink: #032621;
  --accent-glow: rgba(47, 227, 203, 0.35);

  /* ---- domain hues: fill · ink (text on dark) ---- */
  --c-body: #3DDC97;   --c-body-ink: #6FF0B8;
  --c-tech: #A78BFA;   --c-tech-ink: #C4B2FF;
  --c-world: #5AA9FF;  --c-world-ink: #8EC5FF;
  --c-money: #F7C04A;  --c-money-ink: #FFD67A;
  --c-energy: #FF9446; --c-energy-ink: #FFB27A;
  --c-people: #F472B6; --c-people-ink: #FF9ACB;
  --teal: #2FE3CB;     --teal-ink: #7FF3E2;

  /* ---- states ---- */
  --amber: #F5B544;    --amber-ink: #FFCB6B;
  --orange: #FF8A3D;
  --danger: #FF4D5E;   --danger-ink: #FF7A87;
  --fx-good: #3DDC97;
  --fx-bad: #FF5A67;

  /* organ reserve bands */
  --org-strong: #3DDC97;
  --org-fair: #B5E35B;
  --org-impaired: #F5B544;
  --org-failing: #FF8A3D;
  --org-failed: #FF4D5E;

  /* "deep" hues name the colour used for text and marks on the ground —
     on a dark ground that is the lighter ink (hue references in the JS) */
  --c-body-deep: var(--c-body-ink);
  --c-tech-deep: var(--c-tech-ink);
  --c-world-deep: var(--c-world-ink);
  --c-money-deep: var(--c-money-ink);
  --c-energy-deep: var(--c-energy-ink);
  --c-people-deep: var(--c-people-ink);
  --teal-deep: var(--teal-ink);
  --amber-deep: var(--orange);
  --red-terminal: var(--danger);

  /* card kinds */
  --k-tech_unlock: var(--c-tech);
  --k-world_event: var(--c-world);
  --k-life_event: var(--c-people);
  --k-biomarker_threshold: var(--c-body);
  --k-briefing_template: var(--amber);

  /* ---- depth ---- */
  --shadow-panel: 0 1px 0 rgba(255, 255, 255, 0.03) inset, 0 12px 32px rgba(0, 0, 0, 0.32), 0 2px 6px rgba(0, 0, 0, 0.25);
  --shadow-lift: 0 18px 44px rgba(0, 0, 0, 0.48), 0 4px 12px rgba(0, 0, 0, 0.32);
  --shadow-card: 0 40px 90px rgba(0, 0, 0, 0.62), 0 10px 26px rgba(0, 0, 0, 0.42);
  --dim: rgba(2, 5, 10, 0.7);

  /* ---- type ---- */
  --font-display: "Space Grotesk", "Inter", "Segoe UI", system-ui, sans-serif;
  --font-sans: "Inter", "Segoe UI", system-ui, -apple-system, Helvetica, Arial, sans-serif;
  --font-mono: "JetBrains Mono", "SF Mono", Menlo, Consolas, ui-monospace, monospace;
  --font-serif: Georgia, "Times New Roman", serif;
  --font-prose: var(--font-sans);

  --unit: 8px;
  --page-margin: 28px;
  --panel-pad: 16px;
  --gutter: 14px;
  --card-pad: 40px;
  --r: 9px;
  --r-lg: 16px;

  --ease-out: cubic-bezier(0.22, 1, 0.36, 1);
  --ease-quart: cubic-bezier(0.25, 1, 0.5, 1);
  --ease-in-out: cubic-bezier(0.65, 0, 0.35, 1);
  --ease-spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease-back: cubic-bezier(0.34, 1.3, 0.64, 1);
  --text-scale: 1;
}

* { margin: 0; padding: 0; box-sizing: border-box; }

html, body {
  height: 100%;
  background: var(--bg-1);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: calc(15px * var(--text-scale));
  line-height: 1.5;
  overflow: hidden;
  font-kerning: normal;
  font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
body {
  background:
    radial-gradient(1200px 700px at 12% -10%, rgba(47, 227, 203, 0.075), transparent 62%),
    radial-gradient(1100px 700px at 100% 0%, rgba(167, 139, 250, 0.07), transparent 60%),
    radial-gradient(1400px 800px at 50% 120%, rgba(90, 169, 255, 0.07), transparent 60%),
    linear-gradient(180deg, var(--bg-1), var(--bg-0));
}

::selection { background: rgba(47, 227, 203, 0.3); color: #fff; }
:focus { outline: none; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 4px; }
button { font: inherit; color: inherit; }
a { color: var(--teal-ink); }

.t1 { font: 700 calc(30px * var(--text-scale))/1.12 var(--font-display); color: var(--text); letter-spacing: -0.02em; }
.t2 { font: 650 calc(21px * var(--text-scale))/1.25 var(--font-display); color: var(--text); letter-spacing: -0.012em; }
.t3 { font: 400 calc(16px * var(--text-scale))/1.62 var(--font-prose); color: var(--text); }
.t4 { font: 400 calc(13.5px * var(--text-scale))/1.5 var(--font-sans); color: var(--text-2); }
.t5 { font: 400 calc(12px * var(--text-scale))/1.45 var(--font-sans); color: var(--text-3); }
.mono { font: 500 calc(15px * var(--text-scale))/1.35 var(--font-mono); color: var(--text); font-variant-numeric: tabular-nums; }
.mono-s { font: 500 calc(12px * var(--text-scale))/1.35 var(--font-mono); color: var(--text); font-variant-numeric: tabular-nums; }

.caps {
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-family: var(--font-sans);
  font-size: calc(10.5px * var(--text-scale));
  font-weight: 650;
  color: var(--text-3);
}
em { font-style: italic; }
strong { font-weight: 650; color: #fff; }

kbd {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 1.7em; height: 1.65em; padding: 0 0.45em;
  font: 600 calc(10px * var(--text-scale))/1 var(--font-mono);
  color: var(--text-3);
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line-strong);
  border-bottom-width: 2px;
  border-radius: 5px;
  margin-left: 6px;
}
.nav-arrow { font-family: var(--font-sans); font-weight: 600; display: inline-block; transition: transform 200ms var(--ease-out); }
.ico { display: inline-block; vertical-align: -2px; flex: none; }
.ico-tint { fill: currentColor; fill-opacity: 0.2; } /* an organ, a flame: a body, not an outline */

/* ============ buttons & controls ============ */
.btn {
  position: relative;
  display: inline-flex; align-items: center; justify-content: center; gap: 7px;
  font: 600 calc(13px * var(--text-scale))/1 var(--font-sans);
  letter-spacing: 0.005em;
  color: var(--text);
  background: linear-gradient(180deg, rgba(255, 255, 255, 0.075), rgba(255, 255, 255, 0.025));
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  padding: 9px 15px;
  cursor: pointer;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.06) inset, 0 2px 8px rgba(0, 0, 0, 0.25);
  transition: background 160ms var(--ease-out), border-color 160ms var(--ease-out), transform 120ms var(--ease-out), box-shadow 200ms var(--ease-out), color 160ms var(--ease-out);
  user-select: none;
  white-space: nowrap;
  -webkit-tap-highlight-color: transparent;
}
.btn:hover { background: linear-gradient(180deg, rgba(255, 255, 255, 0.11), rgba(255, 255, 255, 0.04)); border-color: rgba(170, 210, 255, 0.36); }
.btn:hover .nav-arrow { transform: translateX(3px); }
.btn:active { transform: translateY(1px) scale(0.985); box-shadow: 0 1px 0 rgba(255, 255, 255, 0.04) inset; }
.btn:disabled { opacity: 0.38; pointer-events: none; }
.btn.focused { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-glow); }

.btn-primary {
  color: var(--accent-ink);
  background: linear-gradient(180deg, #5FF5DE 0%, var(--accent) 45%, var(--accent-2) 100%);
  border-color: rgba(120, 255, 235, 0.7);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.55) inset, 0 -2px 0 rgba(0, 60, 50, 0.25) inset, 0 6px 22px rgba(47, 227, 203, 0.28), 0 2px 6px rgba(0, 0, 0, 0.35);
  text-shadow: 0 1px 0 rgba(255, 255, 255, 0.25);
}
.btn-primary:hover {
  background: linear-gradient(180deg, #86FFEC 0%, #45F0D8 45%, #22C9B5 100%);
  border-color: rgba(160, 255, 240, 0.9);
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.6) inset, 0 -2px 0 rgba(0, 60, 50, 0.25) inset, 0 8px 30px rgba(47, 227, 203, 0.42), 0 2px 6px rgba(0, 0, 0, 0.35);
}
.btn-primary:active { background: linear-gradient(180deg, #2FE3CB, #17A696); }
.btn-primary.focused { box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.5), 0 8px 30px rgba(47, 227, 203, 0.42); border-color: #fff; }

.btn-sm { padding: 6px 11px; font-size: calc(12.5px * var(--text-scale)); border-radius: 8px; }
.btn-lg { padding: 13px 24px; font-size: calc(15px * var(--text-scale)); border-radius: 11px; }
.btn-quiet { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-quiet:hover { background: var(--hover); border-color: transparent; color: var(--text); }
/* the routine's way in: the one button on the dashboard after End the year that asks to be pressed */
.btn-edit { gap: 7px; font-weight: 650; color: var(--teal-ink); background: linear-gradient(180deg, rgba(47, 227, 203, 0.24), rgba(47, 227, 203, 0.09)); border-color: rgba(47, 227, 203, 0.6); box-shadow: 0 0 16px rgba(47, 227, 203, 0.2), 0 1px 0 rgba(255, 255, 255, 0.12) inset; }
.btn-edit:hover { color: #fff; background: linear-gradient(180deg, rgba(47, 227, 203, 0.36), rgba(47, 227, 203, 0.16)); border-color: rgba(127, 243, 226, 0.9); box-shadow: 0 0 22px rgba(47, 227, 203, 0.34), 0 1px 0 rgba(255, 255, 255, 0.16) inset; }
.btn-edit.focused { border-color: #fff; box-shadow: 0 0 0 3px var(--accent-glow), 0 0 22px rgba(47, 227, 203, 0.34); }
.btn-edit .ico { color: currentColor; }
.btn-danger-quiet { color: var(--text-2); }
.btn-danger-quiet:hover { color: var(--danger-ink); border-color: rgba(255, 77, 94, 0.45); background: rgba(255, 77, 94, 0.08); }
.btn-row { display: flex; gap: 10px; margin-top: 22px; flex-wrap: wrap; }
.btn.nudge { animation: nudge 380ms var(--ease-out); }
@keyframes nudge { 0%, 100% { transform: none; } 20% { transform: translateX(-5px); } 45% { transform: translateX(4px); } 70% { transform: translateX(-2px); } }

.step-btn { width: 32px; height: 30px; padding: 0; font-size: calc(16px * var(--text-scale)); font-weight: 500; border-radius: 8px; }

/* dropdown */
.diet-select {
  font: 600 calc(13px * var(--text-scale))/1.2 var(--font-sans);
  color: var(--text);
  background-color: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line-strong);
  border-radius: var(--r);
  padding: 8px 32px 8px 12px;
  cursor: pointer;
  appearance: none;
  background-image: url("data:image/svg+xml;charset=utf-8,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' fill='none' stroke='%23B3C2D4' stroke-width='1.6' stroke-linecap='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  text-transform: capitalize;
  transition: border-color 160ms var(--ease-out), background-color 160ms var(--ease-out);
}
.diet-select:hover { background-color: rgba(255, 255, 255, 0.08); border-color: rgba(170, 210, 255, 0.36); }
.diet-select:focus { border-color: var(--accent); }
.diet-select option { background: #0D1520; color: var(--text); }
.diet-select.home-select { text-transform: none; } /* homes are named in sentence case */

/* segmented control */
.seg { display: inline-flex; background: var(--well); border: 1px solid var(--line); border-radius: 10px; padding: 3px; gap: 2px; }
.seg-opt {
  appearance: none; border: 1px solid transparent; background: none; cursor: pointer;
  font: 600 calc(12px * var(--text-scale))/1 var(--font-sans); color: var(--text-3);
  padding: 8px 13px; border-radius: 7px;
  transition: background 160ms var(--ease-out), color 160ms var(--ease-out), box-shadow 160ms var(--ease-out);
}
.seg-opt:hover { color: var(--text); }
.seg-opt.on { background: linear-gradient(180deg, rgba(47, 227, 203, 0.24), rgba(47, 227, 203, 0.12)); color: var(--teal-ink); border-color: rgba(47, 227, 203, 0.4); box-shadow: 0 0 14px rgba(47, 227, 203, 0.18); }
.seg-opt.focused { border-color: var(--accent); }

/* switch */
.switch {
  appearance: none; cursor: pointer; flex: none;
  width: 44px; height: 25px; border-radius: 13px;
  background: var(--well); border: 1px solid var(--line-strong);
  position: relative; transition: background 200ms var(--ease-out), border-color 200ms var(--ease-out), box-shadow 200ms var(--ease-out);
}
.switch .knob {
  position: absolute; top: 2px; left: 2px; width: 19px; height: 19px; border-radius: 50%;
  background: linear-gradient(180deg, #F4F8FC, #B9C7D6); box-shadow: 0 2px 5px rgba(0, 0, 0, 0.4);
  transition: transform 260ms var(--ease-spring);
}
.switch.on { background: rgba(47, 227, 203, 0.35); border-color: var(--accent); box-shadow: 0 0 14px rgba(47, 227, 203, 0.25); }
.switch.on .knob { transform: translateX(19px); background: linear-gradient(180deg, #FFFFFF, #CFFBF4); }
.switch.focused { box-shadow: 0 0 0 3px var(--accent-glow); }

/* range */
.vol { display: inline-flex; align-items: center; gap: 12px; }
.vol-v { min-width: 40px; text-align: right; color: var(--text-3); }
.range { appearance: none; -webkit-appearance: none; width: 160px; height: 20px; background: transparent; cursor: pointer; }
.range::-webkit-slider-runnable-track {
  height: 6px; border-radius: 3px;
  background: linear-gradient(90deg, var(--accent-2), var(--accent) var(--v, 50%), var(--track) var(--v, 50%));
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.25) inset;
}
.range::-moz-range-track { height: 6px; border-radius: 3px; background: var(--track); }
.range::-moz-range-progress { height: 6px; border-radius: 3px; background: var(--accent); }
.range::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px; margin-top: -6px; border-radius: 50%;
  background: linear-gradient(180deg, #FFFFFF, #C7D3E0); border: none;
  box-shadow: 0 0 0 3px rgba(47, 227, 203, 0.25), 0 2px 6px rgba(0, 0, 0, 0.5);
  transition: box-shadow 160ms var(--ease-out), transform 160ms var(--ease-out);
}
.range:hover::-webkit-slider-thumb { box-shadow: 0 0 0 5px rgba(47, 227, 203, 0.28), 0 2px 6px rgba(0, 0, 0, 0.5); }
.range:active::-webkit-slider-thumb { transform: scale(1.12); }
.range::-moz-range-thumb { width: 18px; height: 18px; border-radius: 50%; background: #F0F5FA; border: none; box-shadow: 0 0 0 3px rgba(47, 227, 203, 0.25); }

/* ============ app frame ============ */
#fx-bg { position: fixed; inset: 0; width: 100%; height: 100%; z-index: 0; pointer-events: none; display: block; }
.fx-vignette { position: fixed; inset: 0; z-index: 1; pointer-events: none; background: radial-gradient(130% 110% at 50% 45%, transparent 55%, rgba(0, 0, 0, 0.55) 100%); }
.app { position: relative; z-index: 2; width: 100%; height: 100%; transition: opacity 1100ms var(--ease-in-out), filter 1100ms var(--ease-in-out), transform 1100ms var(--ease-in-out); }
.app.ending-fade { opacity: 0; filter: blur(6px) brightness(0.6); transform: scale(1.02); pointer-events: none; }
body.ending-dark { background: #000; transition: background-color 900ms var(--ease-in-out); }
.screen { position: absolute; inset: 0; overflow: hidden; }
.screen > * { position: relative; }

/* screen transitions (js/ui/fx.js: V.fx.swapScreen) */
.screen.scr-in { animation: scr-in 620ms var(--ease-out) backwards; }
.screen.scr-out { animation: scr-out 420ms var(--ease-in-out) both; pointer-events: none; z-index: 3; }
@keyframes scr-in { from { opacity: 0; transform: scale(1.02); filter: blur(4px); } to { opacity: 1; transform: none; filter: none; } }
@keyframes scr-out { to { opacity: 0; transform: scale(0.985); } }
.scr-wipe { position: fixed; inset: 0; z-index: 80; pointer-events: none; overflow: hidden; }
.scr-wipe::before {
  content: ''; position: absolute; left: 0; right: 0; height: 38vh; top: -40vh;
  background: linear-gradient(180deg, transparent, rgba(47, 227, 203, 0.05) 60%, rgba(127, 243, 226, 0.22) 97%, rgba(210, 255, 248, 0.6) 99.5%, transparent);
  animation: wipe 760ms var(--ease-in-out) forwards;
}
@keyframes wipe { to { transform: translateY(142vh); } }

/* scroll areas say so: a fade at whichever edge has more */
.fade-b { -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(180deg, #000 calc(100% - 28px), transparent); }
.fade-t { -webkit-mask-image: linear-gradient(0deg, #000 calc(100% - 22px), transparent); mask-image: linear-gradient(0deg, #000 calc(100% - 22px), transparent); }
.fade-t.fade-b { -webkit-mask-image: linear-gradient(180deg, transparent, #000 22px, #000 calc(100% - 28px), transparent); mask-image: linear-gradient(180deg, transparent, #000 22px, #000 calc(100% - 28px), transparent); }

/* thin scrollbars, tinted */
* { scrollbar-width: thin; scrollbar-color: rgba(150, 195, 245, 0.18) transparent; }
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(150, 195, 245, 0.16); border-radius: 4px; border: 2px solid transparent; background-clip: padding-box; }
::-webkit-scrollbar-thumb:hover { background-color: rgba(150, 195, 245, 0.3); }
::-webkit-scrollbar-track { background: transparent; }

/* ============ tooltips / popovers ============ */
#tip-layer { position: fixed; inset: 0; pointer-events: none; z-index: 60; }
.tipbox {
  position: absolute;
  pointer-events: none; /* a hover tip never blocks the pointer; a pinned one (tapped) can hold a link */
  background: linear-gradient(180deg, rgba(24, 36, 54, 0.97), rgba(14, 22, 34, 0.97));
  border: 1px solid var(--line-strong);
  border-radius: 12px;
  box-shadow: var(--shadow-lift), 0 0 0 1px rgba(0, 0, 0, 0.3);
  padding: 12px 14px 12px;
  max-width: min(310px, calc(100vw - 24px));
  animation: tip-in 180ms var(--ease-out);
  transform-origin: 50% 100%;
}
.tipbox.sticky { pointer-events: auto; }
.tipbox.below { transform-origin: 50% 0; }
@supports (backdrop-filter: blur(1px)) { .tipbox { background: linear-gradient(180deg, rgba(24, 36, 54, 0.9), rgba(14, 22, 34, 0.92)); backdrop-filter: blur(12px); } }
.tipbox::before {
  content: '';
  position: absolute; top: -1px; left: 14px; right: 14px; height: 2px;
  border-radius: 0 0 2px 2px;
  background: var(--tip-hue);
  box-shadow: 0 0 12px var(--tip-hue);
}
@keyframes tip-in { from { opacity: 0; transform: translateY(5px) scale(0.97); } to { opacity: 1; transform: none; } }
.tip-title { font: 650 calc(13px * var(--text-scale))/1.35 var(--font-sans); color: #fff; margin: 3px 0 2px; }
.tip-meta { font: 500 calc(10.5px * var(--text-scale))/1.5 var(--font-mono); color: var(--text-3); margin-bottom: 5px; }
.tip-body { font: 400 calc(12.5px * var(--text-scale))/1.55 var(--font-sans); color: var(--text-2); }
.tip-node { margin-top: 7px; }
.tip-meta + .tip-node, .tip-title + .tip-node { margin-top: 2px; }
.pace-parts { display: grid; gap: 4px; min-width: 200px; }
.pp-row { display: flex; justify-content: space-between; gap: 16px; font: 450 calc(12px * var(--text-scale))/1.4 var(--font-sans); color: var(--text-2); }
.pp-row b { color: var(--c-people-ink); font-weight: 600; }
.tip-link {
  display: inline-flex; align-items: center; gap: 4px; margin-top: 10px;
  font: 650 calc(11.5px * var(--text-scale))/1 var(--font-sans);
  color: var(--accent-ink); background: var(--accent); border-radius: 14px; padding: 7px 12px; text-decoration: none;
  box-shadow: 0 4px 14px rgba(47, 227, 203, 0.3);
}
.tip-link:hover { background: #6BF7E2; }
.tip-arrow {
  position: absolute; bottom: -6px;
  width: 11px; height: 11px;
  background: rgba(14, 22, 34, 0.97);
  border-right: 1px solid var(--line-strong);
  border-bottom: 1px solid var(--line-strong);
  transform: rotate(45deg);
}
.tipbox.below .tip-arrow { bottom: auto; top: -6px; border-right: none; border-bottom: none; border-left: 1px solid var(--line-strong); border-top: 1px solid var(--line-strong); background: rgba(24, 36, 54, 0.97); }
.has-tip { -webkit-touch-callout: none; }
body.m .has-tip { -webkit-user-select: none; user-select: none; }

/* ============ modal + card layers ============ */
.modal-layer {
  position: fixed; inset: 0;
  display: flex; align-items: center; justify-content: center;
  pointer-events: none;
  z-index: 40;
  background: transparent;
  transition: background-color 280ms var(--ease-out);
}
#ui-modal-layer { z-index: 50; }
/* a dim, not a blur: a blurred backdrop is redrawn whenever anything above it moves */
.modal-layer.active { pointer-events: auto; background: var(--dim); }
.modal-layer.leaving { background: transparent; }

.modal {
  position: relative;
  background: linear-gradient(180deg, rgba(22, 33, 50, 0.97), rgba(11, 18, 29, 0.98));
  border: 1px solid var(--line-strong);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-card), 0 1px 0 rgba(255, 255, 255, 0.06) inset;
  --mpx: 30px; --mpb: 26px; /* the side and bottom padding, for footers that reach the edge */
  padding: 26px var(--mpx) var(--mpb);
  pointer-events: auto;
  max-height: 88vh;
  min-width: 340px;
  overflow-y: auto;
  scrollbar-width: none;
  animation: modal-in 340ms var(--ease-out) backwards;
}
.modal::-webkit-scrollbar { display: none; }
.modal::after { /* a hairline of light along the top edge */
  content: ''; position: absolute; left: 24px; right: 24px; top: 0; height: 1px; pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(127, 243, 226, 0.5), transparent);
}
.modal.leaving { animation: modal-out 200ms var(--ease-in-out) both; }
@keyframes modal-in { from { opacity: 0; transform: translateY(16px) scale(0.965); } to { opacity: 1; transform: none; } }
@keyframes modal-out { to { opacity: 0; transform: translateY(10px) scale(0.975); } }
.modal-head { margin-bottom: 16px; }
/* the title on the left, Close on the right */
.modal-head.mh-row { display: flex; align-items: flex-start; gap: 12px; }
.mh-row .mh-text { flex: 1 1 auto; min-width: 0; }
.mh-row > .btn { flex: none; }
.mh-count { margin-left: 12px; font: 500 calc(13px * var(--text-scale))/1 var(--font-mono); color: var(--text-3); letter-spacing: 0; }
.modal-close { gap: 6px; }
.dim-left .col-body { opacity: 0.35; transition: opacity 200ms var(--ease-out); }

.modal-sm { min-width: 320px; }
.modal-md { width: min(560px, 92vw); }
.modal-lg { min-width: 460px; max-width: 640px; }
.modal-cap { max-width: 480px; }
.modal-wide { width: min(720px, 70vw); }
.modal-routine { width: min(700px, 94vw); }

/* toast */
.toast {
  position: fixed; bottom: 28px; left: 50%;
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--line-strong);
  background: linear-gradient(180deg, rgba(26, 40, 60, 0.96), rgba(15, 24, 37, 0.96));
  border-radius: 999px;
  box-shadow: var(--shadow-lift), 0 0 30px rgba(47, 227, 203, 0.12);
  padding: 11px 20px 11px 13px;
  font: 550 calc(13px * var(--text-scale))/1.35 var(--font-sans);
  color: var(--text);
  z-index: 70;
  opacity: 0; pointer-events: none;
  transform: translate(-50%, 18px) scale(0.96);
  transition: opacity 240ms var(--ease-out), transform 360ms var(--ease-spring);
}
.toast .ico { color: var(--accent); flex: none; width: 22px; height: 22px; padding: 4px; border-radius: 50%; background: rgba(47, 227, 203, 0.14); }
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }

/* form fields */
.field { display: grid; grid-template-columns: minmax(0, 1fr) minmax(110px, 170px) auto; align-items: center; gap: 6px 16px; border-bottom: 1px solid var(--line-soft); padding: 11px 0; }
.field-label { display: inline-flex; align-items: center; gap: 8px; justify-self: start; font: 550 calc(14.5px * var(--text-scale))/1.4 var(--font-sans); color: var(--text); }
.field-label .ico { color: var(--text-3); width: calc(20px * var(--text-scale)); height: calc(20px * var(--text-scale)); }
.field-bar { display: block; }
/* what a setting does, drawn: a row of effect chips under it (none when it does nothing);
   a chip new since the last step pops in. A setting's label opens its diagram. */
.field > .set-fx { grid-column: 1 / -1; }
.set-fx { display: flex; flex-wrap: wrap; align-items: center; gap: 5px; }
.set-fx .chip.sfx { font-size: calc(11px * var(--text-scale)); padding: 2px 9px; gap: 5px; }
.set-fx .chip.sfx.sfx-ico { padding: 2px 7px 2px 6px; gap: 3px; } /* an organ or a marker: its icon, then the chevrons */
.set-fx.fx-link { cursor: pointer; }
.set-fx.fx-link:hover .chip.sfx { filter: brightness(1.18); }
.sfx-arrows { font-weight: 700; letter-spacing: -0.1em; }
.sfx-tag { font: 650 calc(9.5px * var(--text-scale))/1 var(--font-sans); letter-spacing: 0.14em; text-transform: uppercase; color: var(--text-3); margin-right: 3px; }
.chip.h-body.t-neutral { background: var(--well-2); color: var(--text-2); box-shadow: inset 0 0 0 1px var(--line); }
.chip.h-note { background: var(--well-2); color: var(--text-2); font-family: var(--font-sans); white-space: normal; }
.chip.h-note.t-mortal { color: var(--danger-ink); box-shadow: inset 0 0 0 1px rgba(255, 77, 94, 0.4); }
.set-fx .chip.h-chance { border: 0; }
.chip.h-chance.t-bad { color: var(--amber-ink); }
.chip.h-chance.t-good { color: var(--c-body-ink); }
.chip.sfx-pop { animation: sfx-pop 420ms var(--ease-out); }
@keyframes sfx-pop { 0% { transform: scale(0.82); opacity: 0; } 60% { transform: scale(1.06); opacity: 1; } 100% { transform: none; } }
button.field-label.fl-link { background: none; border: 0; padding: 0; margin: 0; text-align: left; cursor: pointer; }
.fl-link .ico { transition: color 160ms var(--ease-out); }
.fl-link:hover .ico, .fl-link.focused .ico { color: var(--accent); }
.fl-link.focused { text-decoration: underline; text-decoration-color: var(--accent); text-underline-offset: 4px; }
.stepper { display: flex; align-items: center; gap: 6px; justify-self: end; }
.stepper .val { font: 600 calc(14px * var(--text-scale))/1.3 var(--font-mono); color: #fff; min-width: 84px; text-align: center; font-variant-numeric: tabular-nums; }

/* ============ shared keyframes, fx ============ */
@keyframes rise-in { from { opacity: 0; transform: translateY(14px); } to { opacity: 1; transform: none; } }
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { to { opacity: 0; } }
@keyframes pop-in { from { opacity: 0; transform: scale(0.6); } to { opacity: 1; transform: none; } }
@keyframes flash-num { 0% { color: inherit; } 30% { color: #fff; text-shadow: 0 0 14px currentColor; transform: scale(1.2); } 100% { transform: none; } }
@keyframes shimmer { from { background-position: -200% 0; } to { background-position: 200% 0; } }
@keyframes glow-pulse { 0%, 100% { opacity: var(--gp-lo, 0.3); } 50% { opacity: var(--gp-hi, 0.75); } }
.fx-roll { display: inline-block; overflow: hidden; vertical-align: bottom; height: 1em; line-height: 1; }
.fx-roll-inner { display: flex; flex-direction: column; animation: roll 760ms var(--ease-out) both; }
.fx-roll-inner > span { display: block; height: 1em; line-height: 1; }
@keyframes roll { 0% { transform: translateY(0); filter: blur(0); } 40% { filter: blur(1.2px); } 100% { transform: translateY(-50%); filter: none; } }
.fx-flash { animation: flash-num 900ms var(--ease-out); display: inline-block; }

/* floating number: "+18", "−$12k" rising off a value */
.fx-float {
  position: fixed; z-index: 75; pointer-events: none;
  font: 700 calc(13px * var(--text-scale))/1 var(--font-mono);
  text-shadow: 0 0 12px currentColor, 0 1px 2px rgba(0, 0, 0, 0.8);
  animation: fx-float 1100ms var(--ease-out) forwards;
}
@keyframes fx-float { 0% { opacity: 0; transform: translate(-50%, 4px) scale(0.8); } 18% { opacity: 1; transform: translate(-50%, -4px) scale(1.08); } 100% { opacity: 0; transform: translate(-50%, -30px) scale(1); } }
/* a queued action flies to the queue */
.fx-ghost {
  position: fixed; z-index: 74; pointer-events: none;
  display: flex; align-items: center; gap: 8px;
  padding: 6px 12px; border-radius: 999px;
  font: 600 calc(12px * var(--text-scale))/1.2 var(--font-sans); color: #fff;
  background: linear-gradient(180deg, rgba(47, 227, 203, 0.4), rgba(47, 227, 203, 0.2));
  border: 1px solid rgba(127, 243, 226, 0.7);
  box-shadow: 0 0 24px rgba(47, 227, 203, 0.45);
  white-space: nowrap; max-width: 360px; overflow: hidden; text-overflow: ellipsis;
}
.fx-ripple-wrap { position: absolute; inset: 0; border-radius: inherit; overflow: hidden; pointer-events: none; }
.fx-ripple { position: absolute; border-radius: 50%; pointer-events: none; background: radial-gradient(circle, rgba(255, 255, 255, 0.35), rgba(255, 255, 255, 0) 70%); transform: scale(0); animation: ripple 560ms var(--ease-out) forwards; }
@keyframes ripple { to { transform: scale(1); opacity: 0; } }

/* Reduced motion: the OS setting or Settings → Motion. */
body.reduce-motion *, body.reduce-motion *::before, body.reduce-motion *::after {
  animation-duration: 1ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important;
  transition-duration: 1ms !important; transition-delay: 0ms !important;
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 1ms !important; animation-delay: 0ms !important; animation-iteration-count: 1 !important; transition-duration: 1ms !important; }
}

/* fatal content-error screen */
.fatal { padding: 10vh var(--page-margin); max-width: 900px; margin: 0 auto; overflow: auto; height: 100%; }
.fatal pre { font: 400 12px/1.7 var(--font-mono); color: var(--text-2); white-space: pre-wrap; margin-top: 24px; background: var(--well); border: 1px solid var(--line); border-radius: 12px; padding: 16px; }

html { -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
html, body { overscroll-behavior: none; }
.modal.leaving { position: absolute; }

/* A device that can't keep up (Auto motion, V.fx): no backdrop blurs. */
body.lite .tipbox, body.lite .summary-body { -webkit-backdrop-filter: none; backdrop-filter: none; }
/* While a modal or the year's cards cover the instrument, it holds still. */
.ov-held, .ov-held::before, .ov-held::after { animation-play-state: paused !important; }
/* danger reddens the room's edges (V.atmosphere sets --danger-k 0…1; --danger itself is the colour) */
:root { --danger-k: 0; }
.fx-vignette { background: radial-gradient(130% 110% at 50% 45%, transparent 55%, color-mix(in srgb, rgba(0, 0, 0, 0.55), rgba(120, 10, 20, 0.6) calc(var(--danger-k) * 100%)) 100%); transition: background 2s var(--ease-in-out); }
