/* AI Precision Recall Lab — every style of the page: the palette tokens (spec 04 §1), the ivan components
   (buttons, chips, panels, the overlay, the banner, the language switcher), the screens, the play screen in its
   three layouts (04 §4.2: desktop, phone landscape, phone portrait), the live panel (matrix, metric bars,
   charts, the formula tooltip) and the sandbox's knobs. Canvas code takes the same colours from art/palette.js. */

:root {
  --bg: #0d1b2a;
  --bg-play: #13263a;
  --belt-a: #1c3348;
  --belt-b: #223d55;
  --panel: rgba(13, 27, 42, 0.95);
  --panel-border: rgba(255, 255, 255, 0.12);
  --chip: rgba(13, 27, 42, 0.82);
  --chip-border: rgba(255, 255, 255, 0.1);
  --text: #eef3f7;
  --muted: #9fb0c3;
  --accent: #ffb300;
  --accent-hover: #ffc233;
  --focus: rgba(255, 213, 79, 0.6);
  --pos: #ff8a3d;
  --neg: #4fc3f7;
  --good: #7bd88f;
  --warn: #ffd54f;
  --bad: #ff6b5e;
  --review: #b39ddb;
  --btn: #33495c;
  --btn-hover: #3f5a71;
  --on-accent: #1b2733;
}

html, body {
  margin: 0;
  padding: 0;
  overflow: hidden;
  width: 100%;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Segoe UI', Arial, sans-serif;
  overscroll-behavior: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
}
body {
  /* a quiet hint of the two classes behind the menu until the attract demo (I06) runs there */
  background:
    radial-gradient(ellipse 60% 45% at 18% 85%, rgba(79, 195, 247, 0.10), transparent 70%),
    radial-gradient(ellipse 60% 45% at 82% 15%, rgba(255, 138, 61, 0.10), transparent 70%),
    var(--bg);
}
html.cursor-hidden, html.cursor-hidden * { cursor: none !important; }
canvas { display: block; touch-action: none; }
button { font-family: inherit; touch-action: manipulation; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }

/* ---------- HUD pieces (the HUD itself comes with the play screen) ---------- */
.chip {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 36px;
  padding: 0 12px;
  border-radius: 18px;
  background: var(--chip);
  border: 1px solid var(--chip-border);
  color: #fff;
  font-size: 15px;
  white-space: nowrap;
  pointer-events: auto;
  box-sizing: border-box;
}
.chip b { font-variant-numeric: tabular-nums; }
button.chip { cursor: pointer; font-size: 15px; }
button.chip:hover { background: rgba(30, 50, 70, 0.92); }
.round {
  width: 38px;
  height: 38px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.15);
  background: var(--chip);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  pointer-events: auto;
  display: flex;
  align-items: center;
  justify-content: center;
}
.round:hover { background: rgba(30, 50, 70, 0.92); }
.round.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }

/* ---------- the banner ---------- */
#banner {
  position: fixed;
  left: 50%;
  bottom: calc(24px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  max-width: 90vw;
  padding: 8px 18px;
  border-radius: 20px;
  background: rgba(13, 27, 42, 0.9);
  border: 1px solid var(--chip-border);
  font-size: 15px;
  text-align: center;
  opacity: 0;
  transition: opacity 0.3s;
  pointer-events: none;
  z-index: 40;
}
#banner.on { opacity: 1; }

/* ---------- the screens ---------- */
#overlay {
  position: fixed;
  inset: 0;
  display: flex;
  padding: calc(16px + env(safe-area-inset-top)) calc(16px + env(safe-area-inset-right))
           calc(16px + env(safe-area-inset-bottom)) calc(16px + env(safe-area-inset-left));
  box-sizing: border-box;
  background: rgba(10, 20, 30, 0.55);
  z-index: 20;
  overflow-y: auto;
}
.panel {
  width: 520px;
  max-width: 100%;
  margin: auto;
  padding: 22px 26px;
  border-radius: 18px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 10px 40px rgba(0, 0, 0, 0.5);
  text-align: center;
  box-sizing: border-box;
}
.panel h1 { margin: 6px 0 10px; font-size: 28px; }
/* the language switcher (04 §8, from ivan): EN · RU · SV with flags, at the top of the start screen, the
   results and the end card */
.langPick {
  display: flex;
  width: max-content;
  gap: 4px;
  margin: 0 auto 4px;
  padding: 4px;
  border-radius: 22px;
  background: var(--chip);
  border: 1px solid var(--chip-border);
}
.langPick button {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 16px;
  background: none;
  color: var(--muted);
  font: 600 12px 'Segoe UI', Arial, sans-serif;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.langPick button:hover { background: rgba(255, 255, 255, 0.08); color: var(--text); }
.langPick button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.16); color: var(--text); }
.langPick button:focus-visible { outline: 2px solid var(--focus); outline-offset: 1px; }
.langPick img {
  width: 21px;
  height: 14px;
  border-radius: 2px;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15);
  opacity: 0.6;
}
.langPick button:hover img,
.langPick button[aria-pressed="true"] img { opacity: 1; }
.logoImg { display: block; width: 88px; height: 88px; margin: 6px auto 4px; }
.panel h1.logo {
  font-size: clamp(28px, 6.5vw, 42px);
  font-weight: 900;
  line-height: 1.1;
  background: linear-gradient(100deg, var(--neg) 0%, #fff 48%, var(--pos) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.tagline { color: #c8d6e3; margin: 0 0 16px; line-height: 1.45; }
.label { margin: 14px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 1px; color: #8296a8; }
.fine { font-size: 12px; color: #8fa3b6; margin: 6px 0; line-height: 1.4; min-height: 2.8em; }
.btnRow { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; margin-top: 10px; align-items: center; }
.btnCol { display: flex; flex-direction: column; gap: 8px; max-width: 280px; margin: 0 auto; }
.btn {
  min-height: 44px;
  padding: 0 20px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  border-radius: 22px;
  background: var(--btn);
  color: #fff;
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover, .btn:focus-visible { background: var(--btn-hover); outline: none; }
.btn:focus-visible { box-shadow: 0 0 0 3px var(--focus); }
.btn.default { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.default:hover, .btn.default:focus-visible { background: var(--accent-hover); }
.btn.secondary { background: transparent; }
.btn.secondary:hover, .btn.secondary:focus-visible { background: rgba(255, 255, 255, 0.08); }
.btn.big { min-height: 48px; font-size: 18px; padding: 0 36px; }
.btn.toggle { min-height: 36px; padding: 0 16px; font-size: 13px; background: transparent; }
.btn.toggle.on { background: var(--accent); border-color: var(--accent); color: var(--on-accent); }
.btn.small { min-height: 36px; padding: 0 14px; font-size: 13px; }

/* the start screen's account row: the cloud copy of the campaign (core/cloud.js) */
.account { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 6px 10px; margin: 14px auto 0; max-width: 420px; }
.account .fine { flex-basis: 100%; margin: 0; min-height: 0; text-align: center; overflow-wrap: anywhere; }
.btn.cloudIn { display: inline-flex; align-items: center; gap: 8px; }
.gLogo { width: 16px; height: 16px; flex: none; }
.cloudState { display: inline-flex; align-items: center; gap: 7px; color: #c3d1de; font-size: 13px; }
.cloudState::before { content: ''; width: 8px; height: 8px; border-radius: 50%; background: #6f8193; flex: none; }
.cloudState.synced::before { background: #7de08a; }
.cloudState.syncing::before { background: #9fb3c6; }
.cloudState.error::before, .cloudState.signedOut::before { background: #f0c36a; }
#help { text-align: left; font-size: 14px; line-height: 1.5; color: #c8d6e3; margin-top: 10px; }
#help p { margin: 8px 0; }

/* the language switcher (from I07): the same pill as the ivan gallery's */
.langPick {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  border-radius: 22px;
  background: rgba(13, 27, 42, 0.85);
  border: 1px solid rgba(255, 255, 255, 0.08);
}
.langPick button {
  display: flex;
  align-items: center;
  gap: 6px;
  height: 32px;
  padding: 0 10px;
  border: 0;
  border-radius: 16px;
  background: none;
  color: var(--muted);
  font: 600 12px 'Segoe UI', Arial, sans-serif;
  letter-spacing: 0.04em;
  cursor: pointer;
}
.langPick button:hover { background: rgba(255, 255, 255, 0.08); color: #e8eef5; }
.langPick button[aria-pressed="true"] { background: rgba(255, 255, 255, 0.16); color: #e8eef5; }
.langPick img { width: 21px; height: 14px; border-radius: 2px; box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15); opacity: 0.6; }
.langPick button:hover img,
.langPick button[aria-pressed="true"] img { opacity: 1; }

/* ---------- the play screen (04 §4): HUD, the belt canvas, the live panel, the sandbox's knobs ---------- */
#play {
  position: fixed;
  inset: 0;
  display: grid;
  gap: 8px;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
  box-sizing: border-box;
  background: var(--bg);
  z-index: 10;
}
#play.desktop {
  grid-template: "hud hud" auto "stage side" 60fr "live side" 40fr / minmax(0, 1fr) auto;
  padding-bottom: calc(8px + env(safe-area-inset-bottom));
}
#play.landscape { grid-template: "hud hud" auto "stage live" minmax(0, 1fr) / 62fr 38fr; gap: 6px; }
#play.portrait { grid-template: "hud" auto "stage" 45fr "live" 55fr / minmax(0, 1fr); gap: 6px; }
#hud {
  grid-area: hud;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  padding: 6px 10px 0;
  min-width: 0;
}
.hudLeft, .hudRight { display: flex; gap: 6px; align-items: center; min-width: 0; }
.hudLeft .chip { overflow: hidden; text-overflow: ellipsis; }
#stage { grid-area: stage; position: relative; min-height: 0; min-width: 0; }
#beltCanvas { width: 100%; height: 100%; }
#tSlider { position: absolute; right: 0; width: 60px; height: 36px; pointer-events: none; }
#live {
  grid-area: live;
  min-height: 0;
  min-width: 0;
  display: flex;
  gap: 10px;
  padding: 0 10px;
  box-sizing: border-box;
}
.liveBox {
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 14px;
  padding: 8px 10px;
  box-sizing: border-box;
  min-width: 0;
  min-height: 0;
}
.boxTitle {
  font-size: 12px;
  font-weight: 700;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.6px;
  margin-bottom: 6px;
  white-space: nowrap;
}
.boxTitle .fine { text-transform: none; letter-spacing: 0; font-weight: 400; min-height: 0; margin: 0; }
#liveSwap { display: none; }

/* the confusion matrix: rows = what the model said, columns = the truth; the outcome code of 04 §1 */
#matrixBox { flex: 0 0 auto; }
#matrix { border-collapse: separate; border-spacing: 4px; margin: -4px; }
#matrix th { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 4px; text-align: center; }
#matrix tr > th:first-child { text-align: right; }
#matrix th.corner { font-size: 10px; font-weight: 400; color: #7d8fa2; line-height: 1.2; }
#matrix th.pos { color: var(--pos); }
#matrix th.neg { color: var(--neg); }
#matrix td {
  width: 84px;
  height: 62px;
  border-radius: 10px;
  text-align: center;
  vertical-align: middle;
  padding: 2px 4px;
  box-sizing: border-box;
  border: 2px solid transparent;
  transition: opacity 0.15s, border-color 0.15s;
  line-height: 1.15;
}
#matrix td b { display: block; font-size: 22px; font-variant-numeric: tabular-nums; }
#matrix td small { display: block; font-size: 10px; opacity: 0.8; font-variant-numeric: tabular-nums; }
#matrix td .cName { display: block; font-size: 11px; font-weight: 700; }
#matrix td[data-cell="TP"] { background: var(--pos); color: #2a1406; }
#matrix td[data-cell="TN"] { background: var(--neg); color: #062130; }
#matrix td[data-cell="FN"] { background: repeating-linear-gradient(-45deg, rgba(255, 138, 61, 0.55) 0 3px, #1a2633 3px 8px); color: #ffd2b5; }
#matrix td[data-cell="FP"] { background: repeating-linear-gradient(-45deg, rgba(79, 195, 247, 0.5) 0 3px, #1a2633 3px 8px); color: #c7ecfc; }
#matrix td[data-cell="FN"] b, #matrix td[data-cell="FP"] b { color: #fff; }
#matrix td.hlNum { border-color: #fff; box-shadow: 0 0 0 2px var(--accent); }
#matrix td.hlDen { border-color: #fff; border-style: dashed; }
#matrix td.hlDim { opacity: 0.25; }
#matrix td.pulse { animation: cellPulse 0.45s ease-out; }
@keyframes cellPulse { 0% { transform: scale(1.12); filter: brightness(1.5); } 100% { transform: scale(1); filter: none; } }

/* the metric bars: 0–1, the value; "—" when the denominator is empty */
#barsBox { flex: 0 1 300px; display: flex; flex-direction: column; justify-content: space-around; gap: 2px; overflow-y: auto; }
.bar {
  display: grid;
  grid-template-columns: 72px 1fr 40px;
  align-items: center;
  gap: 8px;
  padding: 3px 6px;
  border-radius: 8px;
  cursor: pointer;
  outline: none;
}
.bar:hover, .bar.on { background: rgba(255, 255, 255, 0.07); }
.bar.on { box-shadow: inset 0 0 0 1px rgba(255, 179, 0, 0.6); }
.bName { font-size: 13px; font-weight: 600; white-space: nowrap; }
.bTrack { position: relative; height: 10px; border-radius: 5px; background: rgba(255, 255, 255, 0.09); overflow: hidden; }
.bFill { position: absolute; left: 0; top: 0; bottom: 0; width: 0; border-radius: 5px; background: var(--accent); transition: width 0.15s ease-out; }
.bVal { font-size: 14px; font-weight: 700; text-align: right; font-variant-numeric: tabular-nums; }
.bFormula { display: none; grid-column: 1 / -1; font-size: 11px; color: #c8d6e3; margin-top: -2px; font-variant-numeric: tabular-nums; }
#barsBox.formulas .bFormula { display: block; }
.oTP { color: var(--pos); font-weight: 700; }
.oFN { color: var(--pos); font-weight: 700; text-decoration: underline dashed; }
.oTN { color: var(--neg); font-weight: 700; }
.oFP { color: var(--neg); font-weight: 700; text-decoration: underline dashed; }

/* the formula tooltip */
#tip {
  position: fixed;
  z-index: 30;
  max-width: min(360px, calc(100vw - 16px));
  padding: 10px 12px;
  border-radius: 12px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  box-shadow: 0 8px 28px rgba(0, 0, 0, 0.5);
  font-size: 13px;
  line-height: 1.45;
  pointer-events: none;
  box-sizing: border-box;
}
.tipF { font-variant-numeric: tabular-nums; }
.tipAsk { color: #c8d6e3; margin-top: 4px; }
#tip .fine { min-height: 0; margin: 4px 0 0; }
#tip.pinned { pointer-events: auto; cursor: pointer; }
#tip .tipHint:empty { display: none; }
#tip .tipHint { color: var(--accent); }

/* the charts: in one row on a wide panel, one at a time under tabs otherwise */
#chartsBox { flex: 1 1 0; display: flex; flex-direction: column; }
.chartTabs { display: none; gap: 6px; margin-bottom: 6px; }
.chartTabs .btn.toggle { min-height: 30px; padding: 0 12px; }
.charts { flex: 1 1 auto; display: flex; gap: 8px; min-height: 0; }
.chart { flex: 1 1 0; min-width: 0; min-height: 0; position: relative; }
.chart canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
#play.tabbed .chartTabs { display: flex; }
#play.tabbed .chart { display: none; }
#play.tabbed .chart.on { display: block; }

/* phone portrait: matrix and bars side by side, one chart under them */
#play.portrait #live {
  display: grid;
  grid-template: "matrix bars" auto "charts charts" minmax(0, 1fr) / auto minmax(0, 1fr);
  gap: 6px;
  padding: 0 6px 6px;
}
#play.portrait #matrixBox { grid-area: matrix; }
#play.portrait #barsBox { grid-area: bars; }
#play.portrait #chartsBox { grid-area: charts; }
/* phone landscape: one column on the right; "Charts" swaps the numbers for the charts */
#play.landscape #live { flex-direction: column; padding: 0 6px 6px 0; gap: 6px; }
#play.landscape #liveSwap { display: block; min-height: 30px; align-self: flex-end; }
#play.landscape #barsBox { flex: 1 1 auto; }
#play.landscape #chartsBox { display: none; flex: 1 1 auto; }
#play.landscape #live.showCharts #chartsBox { display: flex; }
#play.landscape #live.showCharts #matrixBox,
#play.landscape #live.showCharts #barsBox { display: none; }
#play.landscape #matrixBox { align-self: center; }

/* ---------- the sandbox's knobs: docked on desktops, a drawer on phones ---------- */
#sandboxPanel {
  grid-area: side;
  width: 270px;
  overflow-x: hidden;
  overflow-y: auto;
  padding: 10px 14px 16px;
  box-sizing: border-box;
  background: rgba(255, 255, 255, 0.03);
  border-left: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 13px;
}
#play.landscape #sandboxPanel, #play.portrait #sandboxPanel {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  width: min(300px, 86vw);
  z-index: 15;
  background: var(--panel);
  box-shadow: -10px 0 40px rgba(0, 0, 0, 0.5);
  padding-top: calc(10px + env(safe-area-inset-top));
  padding-right: calc(14px + env(safe-area-inset-right));
  padding-bottom: calc(16px + env(safe-area-inset-bottom));
}
.sbTop { display: flex; justify-content: space-between; align-items: center; }
.sbTop h2 { margin: 0; font-size: 18px; }
#sandboxPanel .label { margin: 12px 0 6px; text-align: left; }
#sandboxPanel .btnRow { justify-content: flex-start; margin-top: 8px; }
#sandboxPanel .btn { min-height: 36px; padding: 0 14px; font-size: 13px; }
.sbNote { min-height: 0; margin: 4px 0; text-align: left; }
.sbScen { display: grid; grid-template-columns: minmax(0, 1fr); gap: 4px; }   /* one column: long RU / SV names fit */
.sbScenBtn.btn.toggle {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 6px;
  min-height: 36px;
  min-width: 0;
  text-align: left;
  border-radius: 12px;
  font-size: 11px;
  line-height: 1.1;
}
.sbScenBtn canvas { flex: 0 0 auto; }
.sbScenBtn span { min-width: 0; overflow-wrap: anywhere; }
.sbSlider { display: block; margin-top: 12px; }
.sbHead2 { display: flex; justify-content: space-between; gap: 8px; font-size: 12px; color: var(--muted); }
.sbHead2 b { color: var(--text); font-variant-numeric: tabular-nums; }
.sbSlider input { width: 100%; margin: 6px 0 0; accent-color: var(--accent); touch-action: manipulation; }
.sbToggles { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 12px; }
.sbPrices { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.sbPrice { display: flex; flex-direction: column; align-items: center; gap: 2px; font-size: 12px; }
.sbPrice input {
  width: 100%;
  box-sizing: border-box;
  min-height: 32px;
  border-radius: 8px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  text-align: center;
  font: inherit;
  font-size: 14px;
}

/* ---------- small screens ---------- */
@media (max-width: 700px), (max-height: 500px) {
  .chip { height: 32px; padding: 0 9px; font-size: 13px; gap: 4px; }
  button.chip { font-size: 13px; }
  .round { width: 34px; height: 34px; font-size: 16px; }
  .panel { padding: 16px; }
  .panel h1 { font-size: 24px; }
}
/* a phone held sideways: a smaller logo keeps the buttons in view */
@media (max-height: 500px) {
  .logoImg { width: 56px; height: 56px; margin-top: 0; }
  .panel { width: 600px; }
  .panel h1.logo { font-size: 28px; margin: 2px 0 6px; }
  .tagline { margin-bottom: 10px; font-size: 14px; }
  .btn.big { min-height: 44px; font-size: 16px; }
  .label { margin-top: 10px; }
}
/* phones: smaller matrix cells and bars */
@media (max-width: 700px), (max-height: 500px) {
  #matrix td { width: 60px; height: 50px; }
  #matrix td b { font-size: 17px; }
  #matrix td .cName { font-size: 10px; }
  #matrix th { font-size: 11px; padding: 0 2px; }
  #matrix th.corner { font-size: 9px; }
  .liveBox { padding: 6px 8px; border-radius: 12px; }
  .boxTitle { font-size: 11px; margin-bottom: 4px; }
  .bar { grid-template-columns: 62px 1fr 34px; gap: 6px; padding: 2px 4px; }
  .bName { font-size: 12px; }
  .bVal { font-size: 13px; }
  #hud { padding: 4px 6px 0; }
}
@media (max-width: 400px) {
  #matrix td { width: 52px; }
  #play.portrait .bar { grid-template-columns: 54px 1fr 32px; gap: 4px; }
}
@media (prefers-reduced-motion: reduce) {
  #banner { transition: none; }
  #matrix td.pulse { animation: none; }
  .bFill { transition: none; }
}

/* ---------- the campaign (I04): HUD chips, the map, the briefing, the results, the cheat sheet, coach marks ---------- */
.chip.good { color: var(--good); }
.chip.bad { color: var(--bad); }
.chip.warn { color: var(--warn); }
.goalChip { border-width: 2px; }
.goalChip.grace { color: var(--muted); }
.goalChip.met { border-color: var(--good); color: var(--good); }
.goalChip.close { border-color: var(--warn); color: var(--warn); }
.goalChip.broken { border-color: var(--bad); color: var(--bad); }
.tag {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 10px;
  background: rgba(255, 107, 94, 0.18);
  color: var(--bad);
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.good { color: var(--good); }
.bad { color: var(--bad); }
.zero { color: var(--muted); }
.badge {
  display: inline-block;
  margin: 6px 4px 0;
  padding: 3px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 700;
  background: rgba(123, 216, 143, 0.16);
}
.panel.wide { width: 900px; text-align: left; }
.panel.wide .btnRow { justify-content: center; }
.panel.wide > .label, .panel.wide > .fine { text-align: center; }
.panel h2 { font-size: 13px; text-transform: uppercase; letter-spacing: 0.8px; color: var(--muted); margin: 14px 0 8px; }
canvas.avatar { flex: 0 0 auto; border-radius: 50%; }

/* the goal's bar: a tick at the target; red while the window is below it */
.bTick { position: absolute; top: -2px; bottom: -2px; width: 2px; margin-left: -1px; background: #fff; border-radius: 1px; }
.bTrack { overflow: visible; }
.bar.broken .bFill { background: var(--bad); }
.bar.goal .bName::after { content: ""; display: inline-block; width: 6px; height: 6px; margin-left: 5px; border-radius: 50%; background: var(--accent); vertical-align: middle; }

/* the stars: lit or not; on the results screen they light up one by one */
.stars { display: inline-flex; gap: 1px; font-size: 13px; }
.starOn { color: var(--accent); }
.starOff { color: rgba(255, 255, 255, 0.18); }
.resStars { font-size: 34px; display: flex; gap: 6px; margin-top: 4px; }
.resStars .starOn { animation: starIn 0.4s ease-out both; }
@keyframes starIn { 0% { transform: scale(0.2); opacity: 0; } 70% { transform: scale(1.25); } 100% { transform: scale(1); opacity: 1; } }

/* the map */
.mapTop { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; }
.mapTop h1 { margin: 0; }
.mapMoney { display: flex; align-items: center; gap: 8px; }
.mapNote { text-align: left !important; min-height: 0; }
.mapAct h2 { margin-top: 12px; }
.mapRow { display: grid; grid-template-columns: repeat(auto-fill, minmax(196px, 1fr)); gap: 8px; }
.btn.mapCard {
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
  padding: 10px 12px;
  border-radius: 14px;
  text-align: left;
  font-weight: 400;
  min-height: 0;
}
.btn.mapCard.locked { opacity: 0.45; cursor: default; }
.btn.mapCard.default { color: var(--on-accent); }
.btn.mapCard.default .mcClient, .btn.mapCard.default .mcIdea { color: #3b3220; }
.btn.mapCard.default .starOff { color: rgba(0, 0, 0, 0.25); }
.btn.mapCard.default .starOn { color: #7a4b00; }
.mcHead { display: flex; align-items: center; gap: 10px; }
.mcNames { display: flex; flex-direction: column; min-width: 0; line-height: 1.2; }
.mcId { font-size: 11px; font-weight: 700; opacity: 0.75; }
.mcName { font-size: 15px; font-weight: 700; }
.mcClient { font-size: 12px; color: var(--muted); }
.mcIdea { font-size: 12px; color: #c8d6e3; line-height: 1.3; }
.mcLevels { display: flex; justify-content: space-between; gap: 6px; }
.mcLevel { display: flex; align-items: center; gap: 3px; }
.mcLetter { font-size: 11px; font-weight: 700; opacity: 0.7; }

/* the briefing and the results share these boxes */
.brHead, .resHead { display: flex; align-items: center; gap: 14px; }
.brWho h1 { margin: 2px 0; }
.brId { font-size: 12px; font-weight: 700; color: var(--muted); letter-spacing: 0.5px; }
.brClient { font-size: 13px; color: #c8d6e3; }
.resHead.failed h1 { color: var(--bad); }
.brMsg {
  margin: 12px 0 4px;
  padding: 10px 14px;
  border-left: 3px solid var(--accent);
  background: rgba(255, 255, 255, 0.04);
  border-radius: 0 10px 10px 0;
  font-style: italic;
  color: #dfe8f0;
  line-height: 1.45;
}
.brCols { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); gap: 18px; }
.brBox { min-width: 0; }
.termList { display: flex; flex-direction: column; gap: 4px; font-size: 13px; }
.termRow { display: grid; grid-template-columns: 96px minmax(0, 1fr); gap: 8px; align-items: baseline; line-height: 1.35; }
.termName { color: var(--muted); }
.termRow.total { border-top: 1px solid rgba(255, 255, 255, 0.12); padding-top: 4px; font-weight: 700; }
.resMoney .termRow, .resMetrics .termRow { grid-template-columns: minmax(0, 1fr) auto; }
.resMoney .termVal, .resMetrics .termVal { text-align: right; }
.starRules { display: flex; flex-direction: column; gap: 2px; }
.priceTable { border-collapse: separate; border-spacing: 4px; margin: -4px 0 8px -4px; }
.priceTable th { font-size: 12px; font-weight: 600; color: var(--muted); padding: 0 4px; text-align: center; }
.priceTable tr > th:first-child { text-align: right; }
.priceTable th.corner { font-size: 10px; font-weight: 400; }
.priceTable th.pos { color: var(--pos); }
.priceTable th.neg { color: var(--neg); }
.priceTable td { min-width: 86px; height: 46px; border-radius: 10px; text-align: center; padding: 2px 6px; line-height: 1.2; }
.priceTable td b { display: block; font-size: 16px; }
.priceTable td .cName { display: block; font-size: 11px; font-weight: 700; }
.cellTP { background: var(--pos); color: #2a1406; }
.cellTN { background: var(--neg); color: #062130; }
.cellFN { background: repeating-linear-gradient(-45deg, rgba(255, 138, 61, 0.55) 0 3px, #1a2633 3px 8px); color: #fff; }
.cellFP { background: repeating-linear-gradient(-45deg, rgba(79, 195, 247, 0.5) 0 3px, #1a2633 3px 8px); color: #fff; }
.quiz { margin-top: 6px; }
.quizQ { margin: 0 0 8px; line-height: 1.4; }
.quizOpts { display: flex; flex-wrap: wrap; gap: 6px; }
.btn.toggle.quizOpt { font-size: 13px; }
.btn.quizOpt:disabled { cursor: default; opacity: 0.55; }
.btn.quizOpt.right { opacity: 1; background: rgba(123, 216, 143, 0.2); border-color: var(--good); color: var(--good); }
.btn.quizOpt.wrong { opacity: 1; background: rgba(255, 107, 94, 0.16); border-color: var(--bad); color: var(--bad); }
.quizNote { min-height: 0; text-align: left !important; }
.quizNote.good { color: var(--good); }
.quizNote.bad { color: #ffb3aa; }
.resGoal { font-weight: 700; margin: 10px 0 4px; }
.resBest { font-size: 13px; line-height: 1.45; margin: 6px 0; }
.resNums { display: flex; gap: 14px; align-items: flex-start; flex-wrap: wrap; }
.resNums .resMetrics { flex: 1 1 140px; }
canvas.resChart { width: 100%; height: 130px; display: block; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; min-height: 0; }
.lgYou::before, .lgBest::before { content: ""; display: inline-block; width: 16px; height: 0; margin-right: 5px; vertical-align: middle; border-top: 2px solid var(--accent); }
.lgBest::before { border-top: 2px dashed var(--good); }
.lesson { margin-top: 12px; padding: 10px 14px; border-radius: 12px; background: rgba(255, 179, 0, 0.08); border: 1px solid rgba(255, 179, 0, 0.25); }
.lesson h2 { margin-top: 0; color: var(--accent); }
.lesson p { margin: 0 0 8px; line-height: 1.45; }
.lesson .btn { min-height: 36px; font-size: 13px; }
.seed { text-align: right !important; min-height: 0; opacity: 0.6; }

/* the cheat sheet */
.glTop { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 10px; }
.glTop h1 { margin: 0; }
#glSearch {
  flex: 0 1 260px;
  min-height: 38px;
  padding: 0 14px;
  border-radius: 19px;
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: rgba(0, 0, 0, 0.25);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  -webkit-user-select: text;
  user-select: text;
}
#glGrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 8px; }
.btn.glItem { display: flex; flex-direction: column; align-items: flex-start; gap: 4px; padding: 10px 14px; border-radius: 14px; text-align: left; min-height: 0; font-weight: 400; }
.btn.glItem.which { background: rgba(255, 179, 0, 0.12); border-color: rgba(255, 179, 0, 0.4); }
.glName { font-size: 15px; font-weight: 700; }
.glLine { font-size: 12px; color: #c8d6e3; line-height: 1.35; }
.panel h2.glTitle { font-size: 22px; text-transform: none; letter-spacing: 0; color: var(--text); margin: 4px 0 8px; }
.glFormula { font-size: 16px; padding: 8px 12px; border-radius: 10px; background: rgba(255, 255, 255, 0.05); font-variant-numeric: tabular-nums; line-height: 1.5; }
.glBody { display: flex; gap: 18px; align-items: flex-start; margin-top: 8px; }
.glText { flex: 1 1 auto; min-width: 0; }
.glSec h3 { margin: 10px 0 2px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.6px; color: var(--muted); }
.glSec p { margin: 0; line-height: 1.5; font-size: 14px; }
.glFig { flex: 0 0 auto; margin: 10px 0 0; width: 280px; }
.glFig canvas { display: block; border-radius: 10px; background: var(--bg-play); }
.glFig figcaption { min-height: 0; }
.glLinks { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 12px; }
.glLinks .label { margin: 0 6px 0 0; }
.whichFlow { display: flex; flex-direction: column; gap: 6px; margin-top: 10px; }
.whichRow { display: grid; grid-template-columns: minmax(0, 250px) 18px minmax(0, 1fr); gap: 8px; align-items: center; font-size: 14px; }
.whichArrow { color: var(--accent); }
.whichA { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; }
.whichA .btn.toggle { min-height: 30px; padding: 0 10px; font-size: 12px; }

/* coach marks: a bubble over the play screen with an arrow at its target */
#coach {
  position: fixed;
  z-index: 18;
  width: min(330px, calc(100vw - 16px));
  padding: 12px 14px 10px;
  border-radius: 14px;
  background: #fff7e0;
  color: #1b2733;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
  font-size: 14px;
  line-height: 1.45;
  box-sizing: border-box;
}
#coach .coachRow { display: flex; justify-content: flex-end; margin-top: 8px; }
#coach .btn { min-height: 36px; font-size: 14px; }
.coachArrow { position: absolute; bottom: -7px; width: 14px; height: 14px; margin-left: -7px; background: #fff7e0; transform: rotate(45deg); }
#coach.below .coachArrow { bottom: auto; top: -7px; }

@media (max-width: 700px) {
  .panel.wide { padding: 14px; }
  .brCols { grid-template-columns: minmax(0, 1fr); gap: 4px; }
  .glBody { flex-direction: column; }
  .glFig { align-self: center; }
  .mapRow { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .btn.mapCard { padding: 8px; }
  .mcName { font-size: 13px; }
  .mcLevels { flex-wrap: wrap; gap: 2px 6px; justify-content: flex-start; }
  .mcLevels .stars { font-size: 10px; }
  .whichRow { grid-template-columns: minmax(0, 1fr); gap: 2px; }
  .whichArrow { display: none; }
  #play.contract .hudLeft #hudTitle { display: none; }
}
@media (max-width: 380px) {
  .mapRow { grid-template-columns: minmax(0, 1fr); }
}
@media (prefers-reduced-motion: reduce) {
  .resStars .starOn { animation: none; }
}

/* ---------- I05: the Lab, the review desk, incidents and the drift monitor ---------- */
.psiChip { display: flex; align-items: center; gap: 6px; }
.psiChip canvas { flex: 0 0 auto; }
.psiChip.good { border-color: rgba(123, 216, 143, 0.4); }
.psiChip.warn { border-color: var(--warn); }
.psiChip.bad { border-color: var(--bad); }
.incidentChip { border: 2px solid var(--review); color: var(--review); font-weight: 700; }
#hudDesk { border-color: rgba(179, 157, 219, 0.5); }
.retrainBtn { pointer-events: auto; font-weight: 700; }
.retrainBtn:disabled { opacity: 0.55; cursor: default; }
.retrainBtn.alert { border: 2px solid var(--bad); color: var(--bad); animation: retrainPulse 1.2s ease-in-out infinite; }
@keyframes retrainPulse { 50% { background: rgba(255, 107, 94, 0.22); } }

#labFamilies { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 8px; margin: 8px 0 14px; }
.labFamily { display: flex; gap: 10px; align-items: center; padding: 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.1); }
.labRoc { flex: 0 0 auto; border-radius: 8px; background: var(--bg-play); }
.labFamInfo { min-width: 0; flex: 1 1 auto; }
.labFamInfo h2 { margin: 0 0 4px; }
.labFamInfo .fine { min-height: 0; margin: 4px 0 0; }
.labScen { display: flex; justify-content: space-between; gap: 8px; font-size: 13px; }
.labScen b { white-space: nowrap; }
.labFamInfo .labScen { flex-wrap: wrap; column-gap: 8px; row-gap: 0; }
.labAuc { margin-left: auto; display: inline-grid; }
.labAuc > span { grid-area: 1 / 1; justify-self: end; }
.labAuc .labNext, .labAuc.good .labNow { visibility: hidden; }
.labAuc.good .labNext { visibility: visible; }
#labUpgrades { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 8px; }
.labUpgrade { display: flex; flex-direction: column; gap: 4px; padding: 10px 12px; border-radius: 14px; background: rgba(255, 255, 255, 0.04); border: 1px solid rgba(255, 255, 255, 0.1); }
.labUpgrade.bought { border-color: rgba(123, 216, 143, 0.45); }
.labUpgrade.locked { opacity: 0.55; }
.labUpHead { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.labPrice { color: var(--accent); font-weight: 700; }
.labEffect { margin: 0; font-size: 13px; line-height: 1.4; }
.labWhy { min-height: 0; margin: 0 0 4px; }
.labUpgrade .btn { min-height: 36px; font-size: 13px; margin-top: auto; }
.labUpgrade.bought .btn { color: var(--good); }
.labUpgrade:not(.bought) { cursor: pointer; }
.labUpgrade.trying { border-color: var(--accent); background: rgba(255, 179, 0, 0.07); }
.labGain:empty { display: none; }
.labGain { margin: 2px 0 4px; }
.labGain .labScen b { color: var(--good); }

.resIncident { margin-top: 10px; }
.resAround td { min-width: 0; height: auto; padding: 2px 8px; background: rgba(255, 255, 255, 0.05); font-size: 13px; }
canvas.resChart.resSquare { height: 200px; max-width: 260px; }
/* a crowded HUD (goal, PSI, desk, Retrain): the right buttons keep their size, on a phone held upright the chips wrap */
.hudRight { flex-shrink: 0; }
#play.portrait #hud { align-items: flex-start; }
#play.portrait .hudLeft { flex-wrap: wrap; row-gap: 4px; }

/* ---------- Act 3 (I06): the attract demo behind the start screen, the end card and its fireworks ---------- */
/* the demo: the play screen dimmed under the start panel, no HUD, no input (01 §9) */
#play.demo { pointer-events: none; filter: saturate(0.85); opacity: 0.45; }
#play.demo #hud, #play.demo #liveSwap, #play.demo .chartTabs { visibility: hidden; }
#fx { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 60; }
#endCard { text-align: center; }
#endCard .logo { margin-top: 4px; }
.endStars { font-size: 22px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; margin: 6px 0 10px; }
.endTitles { display: flex; flex-wrap: wrap; justify-content: center; gap: 10px; margin: 6px 0 10px; }
.endTitle { display: flex; flex-direction: column; gap: 2px; padding: 10px 14px; border-radius: 14px; max-width: 240px;
  background: rgba(255, 179, 0, 0.1); border: 1px solid rgba(255, 179, 0, 0.45); }
.endTitle b { color: var(--accent); }
.resRing { font-weight: 600; }
.resRing.good { color: var(--good); }
.resRing.bad { color: var(--bad); }
