/* TardiBots: the whole UI look (owner: shell).
   The TardiGREATS clubhouse style: cream sticker panels with 3px ink borders and
   chunky ink drop shadows, Bricolage Grotesque titles over Nunito Sans text,
   section colours (Body blue, Look purple, Brain orange, Try it green, Jobs coral,
   Notebook yellow), springy presses, soft glass over the 3D scene.
   Other owners add their own css/brain.css, css/mission.css, css/coop.css and can
   use the tokens below. Layout works at 1024x768, 1280x800, 1366x1024, 1440x900
   and 820x1180 portrait. */

/* ------------------------------------------------------------------ tokens */
:root {
  --cream: #FBF7F0;
  --cream-2: #F3ECDF;
  --cream-3: #E9DFCD;
  --paper: #FFFDF8;
  --ink: #16223A;
  --ink-2: #34466B;
  --muted: #5D6A86;
  --line: rgba(22, 34, 58, 0.14);

  --blue: #2E8BC9;
  --purple: #8A4FD1;
  --orange: #FF8A3D;
  --green: #2F9E5B;
  --coral: #F0525F;
  --yellow: #F2C14E;
  --teal: #0F9D8A;

  --blue-soft: #DDEFFB;
  --purple-soft: #EEE3FB;
  --orange-soft: #FFE9DA;
  --green-soft: #DDF3E5;
  --coral-soft: #FDE1E3;
  --yellow-soft: #FCF1D2;
  --teal-soft: #D5F2EE;
  --ink-soft: #E3E6EE;

  --font-title: 'Bricolage Grotesque', ui-rounded, 'SF Pro Rounded', 'Avenir Next', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-text: 'Nunito Sans', ui-rounded, 'Avenir Next', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;

  --r-xl: 28px;
  --r-lg: 24px;
  --r-md: 18px;
  --r-sm: 12px;
  --border: 3px solid var(--ink);
  --pop: 0 4px 0 var(--ink);
  --pop-sm: 0 3px 0 var(--ink);
  --pop-down: 0 1px 0 var(--ink);
  --float: 0 4px 0 var(--ink), 0 16px 34px rgba(22, 34, 58, 0.18);
  --spring: cubic-bezier(0.34, 1.56, 0.64, 1);
  --ease: cubic-bezier(0.22, 1, 0.36, 1);

  --safe-t: env(safe-area-inset-top, 0px);
  --safe-r: env(safe-area-inset-right, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-l: env(safe-area-inset-left, 0px);
  --gap: 12px;
  --hud-h: 56px;
  --top: calc(var(--safe-t) + var(--hud-h) + 22px);      /* first free line under the top bar */
  --dock-h: 88px;
  --bottom: calc(var(--safe-b) + var(--dock-h) + 22px);  /* first free line above the dock */
  --side-l: calc(var(--safe-l) + var(--gap));
  --side-r: calc(var(--safe-r) + var(--gap));
}

/* Section colours as a reusable "tone": any element with data-tone gets --tone. */
[data-tone="blue"] { --tone: var(--blue); --tone-soft: var(--blue-soft); --tone-ink: #fff; }
[data-tone="purple"] { --tone: var(--purple); --tone-soft: var(--purple-soft); --tone-ink: #fff; }
[data-tone="orange"] { --tone: var(--orange); --tone-soft: var(--orange-soft); --tone-ink: var(--ink); }
[data-tone="green"] { --tone: var(--green); --tone-soft: var(--green-soft); --tone-ink: #fff; }
[data-tone="coral"] { --tone: var(--coral); --tone-soft: var(--coral-soft); --tone-ink: #fff; }
[data-tone="yellow"] { --tone: var(--yellow); --tone-soft: var(--yellow-soft); --tone-ink: var(--ink); }
[data-tone="teal"] { --tone: var(--teal); --tone-soft: var(--teal-soft); --tone-ink: #fff; }
[data-tone="ink"] { --tone: var(--ink); --tone-soft: var(--ink-soft); --tone-ink: #fff; }

/* ------------------------------------------------------------------- base */
*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  font-family: var(--font-text);
  font-size: 16px;
  line-height: 1.35;
  color: var(--ink);
  background:
    radial-gradient(120% 80% at 50% 0%, #FFF4E0 0%, rgba(255, 244, 224, 0) 60%),
    linear-gradient(180deg, #F6E9D3 0%, #EAD6B8 62%, #C99B6B 62.2%, #B98652 100%);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
}

input, textarea { -webkit-user-select: text; user-select: text; }

button { font: inherit; color: inherit; }

h1, h2, h3, h4 { margin: 0; font-family: var(--font-title); font-weight: 800; letter-spacing: -0.01em; }
p { margin: 0; }

.ic { display: block; flex: none; }
.ic-wrap { display: inline-flex; align-items: center; justify-content: center; line-height: 0; flex: none; }

.is-hidden { display: none !important; }
.muted { color: var(--muted); }

.title-md { font-family: var(--font-title); font-weight: 800; font-size: 26px; line-height: 1.1; }

.section-label {
  font-family: var(--font-text);
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
  margin: 0 0 8px;
}

/* The 3D canvas fills the window under the UI (ARCHITECTURE 13: touch rules). */
#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  outline: none;
  touch-action: none;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  z-index: 0;
}

body.no-3d #stage { visibility: hidden; }
/* Without 3D, a cosy pegboard wall and a wooden bench stand in for the workshop. */
body.no-3d {
  background:
    radial-gradient(circle, rgba(22, 34, 58, 0.13) 0 2.2px, transparent 2.8px) 0 0 / 34px 34px,
    radial-gradient(90% 70% at 50% 30%, #FFF6E6 0%, rgba(255, 246, 230, 0) 70%),
    linear-gradient(180deg, #F3E3C6 0%, #E9D2AE 66%, #B98652 66.2%, #A9763F 100%);
}

/* The UI layer: transparent to the 3D except where there is something to touch. */
#ui {
  position: fixed;
  inset: 0;
  z-index: 10;
  pointer-events: none;
}
#ui .panel, #ui .btn, #ui button, #ui input, #ui select, #ui textarea, #ui label, #ui a,
#ui .chip, #ui .sheet, #ui .scrim, #ui .toast, #ui .coach-card,
#ui .room > *, #ui .mission-layer > *, #ui > .tb-coop {
  pointer-events: auto;
}

.screen { position: absolute; inset: 0; z-index: 1; pointer-events: none; }
.room { position: absolute; inset: 0; pointer-events: none; }
.mission-layer { position: absolute; inset: 0; z-index: 30; pointer-events: none; }
.mission-layer:not(.is-active):empty { display: none; }
.layer { position: absolute; inset: 0; pointer-events: none; }
.layer-coach { z-index: 40; }
.layer-sheets { z-index: 50; }
.layer-toasts { z-index: 60; }

/* ----------------------------------------------------------------- panels */
.panel {
  background: var(--cream);
  border: var(--border);
  border-radius: var(--r-lg);
  box-shadow: var(--float);
}

.panel-glass {
  background: rgba(251, 247, 240, 0.86);
  -webkit-backdrop-filter: blur(14px) saturate(1.25);
  backdrop-filter: blur(14px) saturate(1.25);
  border: 2px solid rgba(22, 34, 58, 0.16);
  border-radius: var(--r-md);
  box-shadow: 0 8px 24px rgba(22, 34, 58, 0.14);
}

/* ---------------------------------------------------------------- buttons */
.btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  min-width: 48px;
  padding: 0 18px;
  border: var(--border);
  border-radius: 16px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--pop);
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 17px;
  line-height: 1;
  white-space: nowrap;
  cursor: pointer;
  touch-action: manipulation;
  transition: transform 0.16s var(--spring), box-shadow 0.16s var(--ease), background-color 0.18s, color 0.18s, opacity 0.2s;
}
.btn .btn-label { display: inline-block; }
.btn.is-down, .btn:active:not(:disabled) {
  transform: translateY(3px) scale(0.96);
  box-shadow: var(--pop-down);
}
.btn:focus-visible, .chip:focus-visible, .dock-btn:focus-visible, .part-card:focus-visible,
.swatch:focus-visible, .finish:focus-visible, .hud-name:focus-visible {
  outline: 3px solid var(--blue);
  outline-offset: 3px;
}
.btn:disabled {
  opacity: 0.42;
  cursor: default;
  box-shadow: var(--pop-sm);
  transform: none;
}

.btn-solid { background: var(--tone, var(--blue)); color: var(--tone-ink, #fff); }
.btn-soft { background: var(--tone-soft, var(--paper)); color: var(--ink); }
.btn-soft:not([data-tone]) { background: var(--paper); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; }
.btn-ghost.is-down, .btn-ghost:active:not(:disabled) { box-shadow: none; background: rgba(22, 34, 58, 0.06); }
.btn-icon { width: 48px; padding: 0; }
.btn-small { min-height: 44px; padding: 0 14px; font-size: 15px; border-radius: 14px; }
.btn-wide { width: 100%; }
.btn-hero {
  min-height: 76px;
  padding: 0 48px;
  font-size: 30px;
  border-radius: var(--r-lg);
  box-shadow: 0 6px 0 var(--ink), 0 18px 34px rgba(22, 34, 58, 0.25);
}
.btn-hero .ic { width: 34px; height: 34px; }
.btn-hero.is-down, .btn-hero:active { transform: translateY(5px) scale(0.97); box-shadow: 0 1px 0 var(--ink); }
.btn-chip {
  min-height: 44px;
  padding: 0 12px;
  border-radius: 999px;
  font-size: 14px;
  box-shadow: var(--pop-sm);
}
.btn-name {
  min-height: 56px;
  font-size: 20px;
  background: var(--paper);
  border-radius: var(--r-md);
}
.btn[aria-pressed="true"], .btn.is-on {
  background: var(--tone, var(--blue));
  color: var(--tone-ink, #fff);
}
.btn-badge {
  position: absolute;
  top: -8px;
  right: -8px;
  min-width: 22px;
  height: 22px;
  padding: 0 6px;
  border-radius: 999px;
  border: 2px solid var(--ink);
  background: var(--coral);
  color: #fff;
  font-size: 12px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

/* A soft fade at the bottom of a scrolling panel while there is more below. */
.has-more {
  -webkit-mask-image: linear-gradient(180deg, #000 calc(100% - 34px), rgba(0, 0, 0, 0.12) 100%);
  mask-image: linear-gradient(180deg, #000 calc(100% - 34px), rgba(0, 0, 0, 0.12) 100%);
}

/* ------------------------------------------------------------------ chips */
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 44px;
  min-width: 44px;
  padding: 0 14px;
  border: var(--border);
  border-radius: 999px;
  background: var(--paper);
  color: var(--ink);
  box-shadow: var(--pop-sm);
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 15px;
  cursor: pointer;
  transition: transform 0.16s var(--spring), box-shadow 0.16s, background-color 0.18s;
}
.chip.is-down, .chip:active { transform: translateY(2px) scale(0.96); box-shadow: var(--pop-down); }
.chip.is-on { background: var(--ink); color: #fff; }
.chip.is-on .chip-swatch { box-shadow: 0 0 0 2px #fff; }
.chip.is-locked { opacity: 0.45; }
.chip-swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--ink); flex: none; }
.chips-swatch .chip { padding: 0 10px; }
.chips-big .chip { min-height: 56px; padding: 0 18px; font-size: 17px; }

/* ------------------------------------------------------------ text input */
.text-input {
  width: 100%;
  min-height: 56px;
  padding: 0 18px;
  border: var(--border);
  border-radius: var(--r-md);
  background: #fff;
  color: var(--ink);
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 22px;
  box-shadow: inset 0 3px 0 rgba(22, 34, 58, 0.08);
  outline: none;
}
.text-input::placeholder { color: #9AA3B8; font-weight: 600; }
.text-input:focus { border-color: var(--blue); box-shadow: 0 0 0 4px rgba(46, 139, 201, 0.25); }

/* -------------------------------------------------------------- boot card */
.boot {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    radial-gradient(circle, rgba(22, 34, 58, 0.1) 0 2px, transparent 2.6px) 0 0 / 30px 30px,
    radial-gradient(80% 60% at 50% 40%, #FFF6E6 0%, #F5E4C6 70%, #EBD3AC 100%);
  transition: opacity 0.5s var(--ease), visibility 0.5s;
}
.boot.is-done { opacity: 0; visibility: hidden; pointer-events: none; }
.boot-card {
  width: min(380px, calc(100vw - 40px));
  padding: 26px 28px 30px;
  border: var(--border);
  border-radius: var(--r-xl);
  background: var(--cream);
  box-shadow: 0 6px 0 var(--ink), 0 26px 50px rgba(22, 34, 58, 0.22);
  text-align: center;
  /* Visible from the very first paint (no fade from 0): only a little settle. */
  animation: boot-in 0.6s var(--spring) both;
}
.boot-bot { display: flex; justify-content: center; margin-bottom: 4px; }
.boot-bot svg { overflow: visible; }
.boot-body { animation: bot-bob 1.4s ease-in-out infinite; transform-origin: 60px 100px; }
.boot-shadow { fill: rgba(22, 34, 58, 0.16); animation: bot-shadow 1.4s ease-in-out infinite; transform-origin: 60px 108px; }
.boot-eyes { animation: bot-blink 3.2s infinite; transform-origin: 60px 50px; }
.boot-bulb { animation: bulb-glow 1.2s ease-in-out infinite alternate; }
.boot-title {
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 44px;
  line-height: 1;
  letter-spacing: -0.02em;
  color: var(--ink);
}
.boot-step { margin: 10px 0 16px; font-weight: 700; color: var(--muted); min-height: 1.35em; }
.boot-bar {
  height: 22px;
  border: var(--border);
  border-radius: 999px;
  background: var(--paper);
  overflow: hidden;
  box-shadow: inset 0 3px 0 rgba(22, 34, 58, 0.08);
}
.boot-bar > span {
  position: relative;
  display: block;
  height: 100%;
  width: 4%;
  border-right: 3px solid var(--ink);
  border-radius: 999px;
  overflow: hidden;
  background: linear-gradient(90deg, var(--blue), var(--green));
  transition: width 0.45s var(--ease);
}
/* The stripes slide with a transform, which the compositor keeps moving even
   while the page is busy loading (a background-position animation would freeze). */
.boot-bar > span::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: -32px;
  width: calc(100% + 64px);
  min-width: 420px;
  background: repeating-linear-gradient(-45deg, rgba(255, 255, 255, 0.35) 0 8px, rgba(255, 255, 255, 0) 8px 16px);
  background-size: 22.6px 22.6px;
  animation: bar-slide 0.8s linear infinite;
  will-change: transform;
}
.boot.is-stuck .boot-body, .boot.is-stuck .boot-bar > span::after { animation: none; }
.boot.is-stuck .boot-step { color: var(--ink); }

/* ------------------------------------------------------------------ HUD top */
.hud-top {
  position: absolute;
  z-index: 20;
  top: calc(var(--safe-t) + 10px);
  left: var(--side-l);
  right: var(--side-r);
  height: var(--hud-h);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--gap);
  pointer-events: none;
  transition: transform 0.35s var(--ease), opacity 0.3s;
}
.hud-top.is-hidden { display: flex !important; transform: translateY(calc(-100% - 30px)); opacity: 0; visibility: hidden; }
.hud-left, .hud-right { display: flex; align-items: center; gap: 10px; min-width: 0; }
.hud-left > *, .hud-right > * { pointer-events: auto; }
.hud-group {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px;
  border: var(--border);
  border-radius: 18px;
  background: var(--cream);
  box-shadow: var(--pop);
}
.hud-group .btn { border-color: transparent; box-shadow: none; background: transparent; border-radius: 13px; }
.hud-group .btn.is-down, .hud-group .btn:active:not(:disabled) { background: var(--cream-3); transform: scale(0.92); box-shadow: none; }
.hud-group .btn:disabled { opacity: 0.32; }
.hud-group .btn[aria-pressed="true"] { background: transparent; color: var(--ink); }
.hud-group .btn[aria-pressed="false"] { color: var(--muted); }
.hud-music.is-off { color: var(--muted); }
.hud-music.is-off .ic { opacity: 0.55; }
.hud-home { background: var(--cream); }

.hud-name {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 50px;
  max-width: 280px;
  padding: 0 14px 0 18px;
  border: var(--border);
  border-radius: 18px;
  background: var(--cream);
  box-shadow: var(--pop);
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 21px;
  cursor: pointer;
  transition: transform 0.16s var(--spring), box-shadow 0.16s;
}
.hud-name .ic { color: var(--blue); }
.hud-name-text { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hud-name:active { transform: translateY(3px) scale(0.97); box-shadow: var(--pop-down); }

.hud-chip {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  height: 44px;
  padding: 0 14px 0 10px;
  border: var(--border);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: var(--pop-sm);
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 18px;
  white-space: nowrap;
}
.hud-sparks .ic { color: #D9A521; }
.hud-bolts .ic { color: var(--ink-2); }
.hud-bolts-bar {
  display: none;
  width: 54px;
  height: 10px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--cream-2);
  overflow: hidden;
}
.hud-bolts-bar > span { display: block; height: 100%; width: 0; background: var(--blue); transition: width 0.4s var(--ease); }
.hud-bolts.has-budget .hud-bolts-bar { display: block; }
.hud-bolts.is-over { background: var(--orange-soft); }
.hud-bolts.is-over .hud-bolts-bar > span {
  background: repeating-linear-gradient(-45deg, var(--orange) 0 5px, #FFB27D 5px 10px);
}
.hud-sparks.is-pop { animation: pop 0.6s var(--spring); }
.hud-plus {
  position: absolute;
  left: 50%;
  top: 0;
  padding: 2px 8px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  font-size: 15px;
  pointer-events: none;
  animation: float-up 1.2s var(--ease) forwards;
}

.hud-top.is-mini .hud-sparks,
.hud-top.is-mini .hud-bolts,
.hud-top.is-mini .hud-right .hud-group:first-child { display: none; }

/* ------------------------------------------------------------------- dock */
.dock {
  position: absolute;
  z-index: 20;
  left: 50%;
  bottom: calc(var(--safe-b) + 10px);
  transform: translateX(-50%);
  max-width: calc(100vw - var(--safe-l) - var(--safe-r) - 16px);
  transition: transform 0.35s var(--ease), opacity 0.3s;
}
.dock.is-hidden { display: block !important; transform: translate(-50%, calc(100% + 30px)); opacity: 0; visibility: hidden; }
.dock-inner {
  display: flex;
  align-items: stretch;
  gap: 4px;
  padding: 6px;
  border: var(--border);
  border-radius: var(--r-lg);
  background: var(--cream);
  box-shadow: var(--float);
  pointer-events: auto;
  overflow-x: auto;
  scrollbar-width: none;
}
.dock-inner::-webkit-scrollbar { display: none; }
.dock-btn {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  width: 78px;
  min-height: 68px;
  padding: 6px 2px 5px;
  border: 0;
  border-radius: 18px;
  background: transparent;
  cursor: pointer;
  transition: transform 0.18s var(--spring), background-color 0.2s;
  flex: none;
}
.dock-ic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 40px;
  border: 3px solid var(--ink);
  border-radius: 14px;
  background: var(--tone-soft, var(--paper));
  color: var(--ink);
  box-shadow: var(--pop-sm);
  transition: transform 0.18s var(--spring), background-color 0.2s, color 0.2s, box-shadow 0.18s;
}
.dock-label {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 13px;
  line-height: 1.1;
  white-space: nowrap;
  color: var(--ink);
}
.dock-btn.is-down { transform: scale(0.93); }
.dock-btn.is-down .dock-ic { transform: translateY(2px); box-shadow: var(--pop-down); }
.dock-btn.is-on { background: var(--tone-soft, var(--cream-2)); }
.dock-btn.is-on .dock-ic { background: var(--tone, var(--blue)); color: var(--tone-ink, #fff); transform: translateY(-3px) scale(1.06); }
.dock-btn.is-on .dock-label { font-weight: 800; }
.dock-btn.is-on::after {
  content: '';
  position: absolute;
  bottom: 2px;
  width: 22px;
  height: 4px;
  border-radius: 4px;
  background: var(--ink);
}
.dock-dot {
  position: absolute;
  top: 3px;
  right: 12px;
  width: 14px;
  height: 14px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--coral);
  transform: scale(0);
  transition: transform 0.3s var(--spring);
}
.dock-btn.has-dot .dock-dot { transform: scale(1); }
.dock-btn.is-wiggle .dock-ic { animation: wiggle 0.45s var(--ease); }
/* While the first-minutes coach runs: the dock steps away, the hub card hides,
   and only the sound buttons stay live in the top bar (the coach's own buttons
   and Skip are the way on). */
body.is-coaching .dock { transform: translate(-50%, calc(100% + 30px)); opacity: 0; visibility: hidden; pointer-events: none; }
body.is-coaching .dock .dock-inner { pointer-events: none; }
body.is-coaching #ui .hub { opacity: 0; visibility: hidden; transition: opacity 0.25s, visibility 0.25s; }
body.is-coaching #ui .hub * { pointer-events: none; }
body.is-coaching #ui .hud-top .hud-home,
body.is-coaching #ui .hud-top .hud-name,
body.is-coaching #ui .hud-top .hud-group .btn:not(.hud-sound):not(.hud-music) { pointer-events: none; opacity: 0.5; }
body.is-coaching #ui .test-ui .btn, body.is-coaching #ui .test-ui .panel { pointer-events: none; }
body.is-coaching #ui .test-ui .transport, body.is-coaching #ui .test-ui .test-remote { opacity: 0.5; }

/* Photo mode (render/photo.js toggles html.tb-photo): the chrome steps aside. */
html.tb-photo .hud-top, html.tb-photo .dock, html.tb-photo .layer-coach { opacity: 0; visibility: hidden; }

/* ------------------------------------------------------------------ sheets */
.scrim {
  position: absolute;
  inset: 0;
  background: rgba(22, 34, 58, 0.34);
  -webkit-backdrop-filter: blur(2px);
  backdrop-filter: blur(2px);
  animation: fade-in 0.22s var(--ease) both;
}
.scrim.is-leaving { animation: fade-out 0.2s var(--ease) both; }
.sheet {
  position: absolute;
  display: flex;
  flex-direction: column;
  max-height: calc(100% - var(--safe-t) - var(--safe-b) - 32px);
  background: var(--cream);
  border: var(--border);
  border-radius: var(--r-xl);
  box-shadow: 0 6px 0 var(--ink), 0 26px 60px rgba(22, 34, 58, 0.3);
  overflow: hidden;
}
.sheet-center {
  left: 50%;
  top: 50%;
  width: min(520px, calc(100vw - 32px));
  transform: translate(-50%, -50%);
  animation: sheet-pop 0.38s var(--spring) both;
}
.sheet-center.is-wide { width: min(780px, calc(100vw - 32px)); }
.sheet-center.is-leaving { animation: sheet-pop-out 0.2s var(--ease) both; }
.sheet-right {
  top: calc(var(--safe-t) + 16px);
  bottom: calc(var(--safe-b) + 16px);
  right: calc(var(--safe-r) + 16px);
  width: min(430px, calc(100vw - 32px));
  max-height: none;
  animation: slide-left 0.36s var(--ease) both;
}
.sheet-right.is-wide { width: min(560px, calc(100vw - 32px)); }
.sheet-right.is-leaving { animation: slide-left-out 0.2s var(--ease) both; }
.sheet-left {
  top: calc(var(--safe-t) + 16px);
  bottom: calc(var(--safe-b) + 16px);
  left: calc(var(--safe-l) + 16px);
  width: min(430px, calc(100vw - 32px));
  max-height: none;
  animation: slide-right 0.36s var(--ease) both;
}
.sheet-left.is-leaving { animation: slide-right-out 0.2s var(--ease) both; }
.sheet-bottom {
  left: 50%;
  bottom: calc(var(--safe-b) + 16px);
  width: min(720px, calc(100vw - 32px));
  transform: translateX(-50%);
  max-height: 72%;
  animation: slide-up 0.36s var(--ease) both;
}
.sheet-bottom.is-leaving { animation: slide-down-out 0.2s var(--ease) both; }
.sheet-head {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px 14px 10px 18px;
}
.sheet-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 48px;
  height: 48px;
  border: var(--border);
  border-radius: 16px;
  background: var(--tone, var(--blue));
  color: var(--tone-ink, #fff);
  box-shadow: var(--pop-sm);
  flex: none;
}
.sheet-title { font-size: 25px; line-height: 1.1; flex: 1; min-width: 0; }
.sheet-x { margin-left: auto; }
.sheet-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 6px 20px 20px;
  -webkit-user-select: none;
  user-select: none;
}
.sheet-text { font-size: 18px; line-height: 1.45; }
.sheet-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
  padding: 14px 20px 20px;
  border-top: 2px dashed var(--line);
}
.sheet-confirm .sheet-body { padding-top: 0; }
.sheet-confirm .sheet-actions { border-top: 0; padding-top: 4px; }
.sheet-photo .sheet-body { display: flex; justify-content: center; }

/* ------------------------------------------------------------------ toasts */
.layer-toasts {
  inset: auto;
  top: calc(var(--top) + 4px);
  left: 50%;
  transform: translateX(-50%);
  width: min(560px, calc(100vw - 32px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
}
.toast {
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: 100%;
  padding: 8px 18px 8px 8px;
  border: var(--border);
  border-radius: 999px;
  background: var(--paper);
  box-shadow: var(--float);
  font-weight: 800;
  font-size: 17px;
  animation: toast-in 0.42s var(--spring) both;
  cursor: pointer;
}
.toast.is-leaving { animation: toast-out 0.25s var(--ease) both; }
.toast-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--tone, var(--ink));
  color: var(--tone-ink, #fff);
  flex: none;
}
.toast-text { min-width: 0; }

/* ------------------------------------------------- "this room is being built" */
.room-building {
  position: absolute;
  inset: var(--top) var(--side-r) var(--bottom) var(--side-l);
  display: flex;
  align-items: center;
  justify-content: center;
  pointer-events: none;
}
.brain-panel .room-building, .test-ui .room-building { inset: 0; padding: 16px; }
.building-card {
  width: min(440px, 100%);
  padding: 28px 28px 26px;
  text-align: center;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  animation: card-in 0.5s var(--spring) both;
}
.building-card p { font-size: 17px; line-height: 1.45; color: var(--ink-2); }
.building-card .btn { margin-top: 6px; }
.building-art {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 104px;
  height: 104px;
  border: var(--border);
  border-radius: 50%;
  background:
    radial-gradient(circle at 50% 50%, var(--cream) 0 34px, transparent 35px),
    repeating-linear-gradient(-45deg, var(--yellow) 0 10px, var(--ink) 10px 20px);
  box-shadow: var(--pop);
  color: var(--ink);
  animation: tool-tap 2.4s ease-in-out infinite;
}

/* -------------------------------------------------------------- title screen */
.title-screen {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  justify-content: center;
  padding: calc(var(--safe-t) + 24px) 24px calc(var(--safe-b) + 24px) max(6vw, calc(var(--safe-l) + 24px));
  pointer-events: none;
  background: linear-gradient(90deg, rgba(251, 247, 240, 0.42) 0%, rgba(251, 247, 240, 0) 46%);
}
.title-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 18px;
  max-width: min(540px, 46vw);
  text-align: left;
  pointer-events: none;
  animation: title-in 0.7s var(--spring) both;
}
.title-card > * { pointer-events: auto; }
.title-card.is-leaving { animation: title-out 0.26s var(--ease) both; }
.title-card .hello {
  font-size: clamp(44px, 6.2vw, 84px);
  line-height: 1;
  color: #fff;
  letter-spacing: -0.02em;
  paint-order: stroke fill;
  -webkit-text-stroke: 8px var(--ink);
  text-shadow: 0 6px 0 var(--ink);
  padding: 0 4px;
  overflow-wrap: anywhere;
}
.title-card .hello + .btn-hero { margin-top: 8px; }
.title-card .logo {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 8px 18px 8px 10px;
  border: var(--border);
  border-radius: 999px;
  background: var(--cream);
  box-shadow: var(--pop);
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 24px;
}
.title-card .logo .ic-wrap {
  width: 48px;
  height: 48px;
  border: var(--border);
  border-radius: 50%;
  background: var(--blue);
  color: #fff;
}
.title-card .logo .ic { width: 30px; height: 30px; }
.title-form {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 12px;
  width: min(440px, calc(100vw - 48px));
  padding: 20px 20px 22px;
  border: var(--border);
  border-radius: var(--r-xl);
  background: var(--cream);
  box-shadow: var(--float);
}
.name-label { font-family: var(--font-title); font-weight: 800; font-size: 20px; }
.name-input { text-align: center; }
.title-form .btn-hero { width: 100%; }

/* ------------------------------------------------------------------- hub */
.hub {
  position: absolute;
  left: var(--side-l);
  top: var(--top);
  bottom: var(--bottom);
  display: flex;
  align-items: center;
  pointer-events: none;
}
.hub-card {
  width: min(330px, calc(100vw - 32px));
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: slide-right 0.45s var(--spring) both;
}
.hub-head { display: flex; align-items: center; gap: 12px; }
.hub-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 54px;
  height: 54px;
  border: var(--border);
  border-radius: 18px;
  background: var(--blue);
  color: #fff;
  box-shadow: var(--pop-sm);
  flex: none;
}
.hub-name { font-family: var(--font-title); font-weight: 800; font-size: 26px; line-height: 1.05; overflow-wrap: anywhere; }
.hub-sub { color: var(--muted); font-weight: 700; font-size: 15px; margin-top: 2px; }
.hub-title { font-family: var(--font-title); font-weight: 800; font-size: 22px; }
.hub-actions { display: grid; grid-template-columns: 1fr; gap: 10px; }
.hub-actions .btn { justify-content: flex-start; min-height: 56px; font-size: 19px; }
.hub-card > .btn-wide { white-space: normal; text-align: left; justify-content: flex-start; line-height: 1.15; padding: 10px 16px; }

/* ------------------------------------------------------------ body (build) */
.build-ui { position: absolute; inset: 0; pointer-events: none; }

.drawer {
  position: absolute;
  top: var(--top);
  bottom: var(--bottom);
  left: var(--side-l);
  width: clamp(250px, 24vw, 312px);
  display: flex;
  flex-direction: column;
  padding: 10px;
  gap: 10px;
  animation: slide-right 0.4s var(--ease) both;
}
.fam-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  flex: none;
}
.btn.fam {
  flex-direction: column;
  gap: 2px;
  min-height: 56px;
  min-width: 0;
  padding: 5px 2px 4px;
  border-width: 2px;
  border-radius: 14px;
  box-shadow: 0 2px 0 var(--ink);
  font-size: 12px;
  background: var(--paper);
}
.btn.fam .ic { width: 22px; height: 22px; }
/* Long names (Greek, French) wrap at their soft hyphens onto two lines, and
   shrink a step when one word is still wider than the button (dom.js fitLabels). */
.btn.fam .btn-label, .btn.tab .btn-label {
  display: block;
  max-width: 100%;
  white-space: normal;
  hyphens: manual;
  -webkit-hyphens: manual;
  overflow-wrap: normal;
  text-align: center;
  line-height: 1.05;
}
.btn.fam .btn-label.is-tight, .btn.tab .btn-label.is-tight { font-size: 11px; letter-spacing: -0.02em; }
.btn.fam .btn-label.is-tighter, .btn.tab .btn-label.is-tighter { font-size: 10px; letter-spacing: -0.03em; overflow-wrap: anywhere; }
.btn.fam.is-on { background: var(--blue); color: #fff; }
.part-grid {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: min-content;
  gap: 10px;
  padding: 4px 2px 8px;
  margin: 0 -2px;
}
.part-empty { grid-column: 1 / -1; padding: 16px 6px; text-align: center; }
.part-card {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 132px;
  padding: 8px 6px 8px;
  border: var(--border);
  border-radius: var(--r-md);
  background: var(--paper);
  box-shadow: var(--pop-sm);
  cursor: grab;
  touch-action: none;
  transition: transform 0.16s var(--spring), box-shadow 0.16s, background-color 0.2s;
}
.part-card.is-down { transform: translateY(2px) scale(0.96); box-shadow: var(--pop-down); }
.part-card.is-on { background: var(--blue-soft); box-shadow: 0 0 0 3px var(--blue), var(--pop-sm); transform: translateY(-2px); }
.part-card.is-locked { background: var(--cream-2); cursor: pointer; }
.part-card.is-locked .part-thumb { filter: grayscale(0.85) opacity(0.6); }
.part-thumb {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 84px;
  height: 72px;
  border-radius: 14px;
  background: radial-gradient(60% 60% at 50% 40%, #fff 0%, var(--cream-2) 100%);
  color: var(--ink-2);
  overflow: hidden;
  pointer-events: none;
}
.part-thumb img { width: 100%; height: 100%; object-fit: contain; -webkit-user-drag: none; }
.part-thumb.has-img { background: radial-gradient(60% 60% at 50% 42%, #fff 0%, #F1E9DA 100%); }
.part-name {
  font-family: var(--font-title);
  font-weight: 700;
  font-size: 14px;
  line-height: 1.1;
  text-align: center;
  min-height: 2.2em;
  display: flex;
  align-items: center;
}
.part-cost {
  position: absolute;
  top: 6px;
  left: 6px;
  display: inline-flex;
  align-items: center;
  gap: 1px;
  padding: 1px 6px 1px 3px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: #fff;
  font-weight: 800;
  font-size: 12px;
  line-height: 16px;
}
.part-lock, .part-pair {
  position: absolute;
  display: flex;
  align-items: center;
  justify-content: center;
  border: 2px solid var(--ink);
  border-radius: 50%;
}
.part-lock { top: 5px; right: 5px; width: 30px; height: 30px; background: var(--yellow); }
.part-pair { top: 6px; right: 6px; width: 24px; height: 24px; background: var(--blue-soft); color: var(--blue); }
.part-card.is-locked .part-pair { display: none; }
.shop-btn { flex: none; width: 100%; }
.shop-btn .ic { color: #D9A521; }

.tool-rail {
  position: absolute;
  left: 50%;
  bottom: var(--bottom);
  transform: translateX(-50%);
  display: flex;
  gap: 8px;
  padding: 8px;
  border-radius: 22px;
  animation: rise-in 0.4s var(--ease) both;
}
.btn.tool {
  flex-direction: column;
  gap: 3px;
  min-width: 76px;
  min-height: 62px;
  padding: 6px 8px;
  font-size: 13px;
  border-radius: 16px;
  background: var(--paper);
}
.btn.tool .ic { width: 26px; height: 26px; }
.btn.tool[aria-pressed="true"] { background: var(--tone, var(--blue)); color: var(--tone-ink, #fff); }
.btn.tool.is-spin .ic { animation: spin-once 0.4s var(--ease); }
.brush-dot {
  position: absolute;
  top: 6px;
  right: 8px;
  width: 16px;
  height: 16px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--blue);
}
.quick-swatches {
  position: absolute;
  left: 50%;
  bottom: calc(var(--bottom) + 92px);
  transform: translate(-50%, 16px) scale(0.96);
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  max-width: min(560px, calc(100vw - 40px));
  padding: 10px 12px;
  border-radius: 999px;
  opacity: 0;
  visibility: hidden;
  transition: transform 0.3s var(--spring), opacity 0.2s, visibility 0.2s;
}
.quick-swatches.is-open { opacity: 1; visibility: visible; transform: translate(-50%, 0) scale(1); }

.view-btns {
  position: absolute;
  top: var(--top);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  gap: 6px;
  padding: 5px;
  border: 2px solid rgba(22, 34, 58, 0.16);
  border-radius: 999px;
  background: rgba(251, 247, 240, 0.8);
  -webkit-backdrop-filter: blur(12px);
  backdrop-filter: blur(12px);
  pointer-events: auto;
}
.view-btns .btn-chip { border-width: 2px; box-shadow: 0 2px 0 var(--ink); font-size: 13px; padding: 0 12px 0 10px; gap: 6px; }
.view-btns .btn-chip .ic { width: 18px; height: 18px; }

.build-hint, .look-hint {
  position: absolute;
  bottom: calc(var(--bottom) + 96px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  max-width: min(520px, calc(100vw - 2 * 330px));
  padding: 10px 16px 10px 12px;
  font-weight: 800;
  font-size: 16px;
  line-height: 1.25;
  pointer-events: none;
  animation: fade-in 0.35s var(--ease) both;
}
.build-hint .ic-wrap, .look-hint .ic-wrap { color: var(--blue); }
.look-hint { bottom: var(--bottom); max-width: min(480px, calc(100vw - 2 * 420px)); }
.build-ui:has(.part-info.is-open) .build-hint,
.build-ui:has(.quick-swatches.is-open) .build-hint { opacity: 0; }
.look-hint .ic-wrap { color: var(--purple); }

.ghost-badge {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 25;
  display: none;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: var(--border);
  border-radius: 50%;
  box-shadow: var(--pop-sm);
  color: #fff;
  pointer-events: none;
}
.ghost-badge.is-shown { display: flex; }
.ghost-badge.is-ok { background: var(--blue); }
.ghost-badge.is-no { background: var(--orange); color: var(--ink); border-radius: 12px; }
.ghost-badge.is-shown .ic-wrap { animation: pop 0.3s var(--spring); }

.drag-chip {
  position: fixed;
  left: 0;
  top: 0;
  z-index: 26;
  display: none;
  width: 72px;
  height: 72px;
  pointer-events: none;
  border: var(--border);
  border-radius: 20px;
  background: var(--paper);
  box-shadow: 0 10px 24px rgba(22, 34, 58, 0.3);
  overflow: hidden;
  transition: opacity 0.15s, border-radius 0.2s;
}
.drag-chip.is-shown { display: block; }
.drag-chip.is-over { opacity: 0.55; border-radius: 50%; }
.drag-chip .part-thumb { width: 100%; height: 100%; border-radius: 0; }

/* The part card opens beside the robot, over the systems panel's corner, so the
   part being looked at stays in view. */
.part-info {
  position: absolute;
  z-index: 3;
  top: var(--top);
  right: var(--side-r);
  width: clamp(250px, 24vw, 320px);
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
  transform: translateX(24px) scale(0.96);
  transform-origin: top right;
  opacity: 0;
  visibility: hidden;
  transition: transform 0.32s var(--spring), opacity 0.2s, visibility 0.2s;
}
.part-info.is-open { transform: none; opacity: 1; visibility: visible; }
.info-actions .btn { flex: 1 1 auto; }
.info-head { display: flex; gap: 12px; align-items: flex-start; }
.info-ic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 46px;
  height: 46px;
  border: var(--border);
  border-radius: 14px;
  background: var(--blue-soft);
  color: var(--blue);
  flex: none;
}
.info-name { font-family: var(--font-title); font-weight: 800; font-size: 20px; }
.info-blurb { color: var(--ink-2); font-size: 15px; margin-top: 2px; }
.info-stats { display: flex; gap: 8px; flex-wrap: wrap; }
.info-stats .hud-chip { height: 34px; font-size: 15px; box-shadow: none; border-width: 2px; }
.info-actions { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* The systems panel: what the robot IS (mass, balance, battery, speed, bolts). */
.systems {
  position: absolute;
  top: var(--top);
  right: var(--side-r);
  width: clamp(236px, 22vw, 292px);
  max-height: calc(100% - var(--top) - var(--bottom));
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 12px 12px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  animation: slide-left 0.4s var(--ease) both;
}
.systems.is-empty .sys-row { opacity: 0.55; }
.sys-head { display: flex; flex-direction: column; gap: 4px; }
.sys-head .section-label { margin: 2px 2px 0; }
.sys-delta { min-height: 0; }
.delta-pop {
  display: inline-block;
  padding: 6px 10px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--yellow-soft);
  font-weight: 800;
  font-size: 14px;
  line-height: 1.25;
  transition: opacity 0.4s, transform 0.4s var(--ease);
}
.delta-pop.is-in { animation: delta-in 0.5s var(--spring) both; }
.delta-pop.is-out { opacity: 0; transform: translateY(-4px); }
.sys-row {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 8px;
  border: 2px solid transparent;
  border-radius: 16px;
  transition: background-color 0.3s, border-color 0.3s;
}
.sys-row.is-tappable { cursor: pointer; border-color: var(--line); background: var(--paper); pointer-events: auto; }
.sys-row.is-tappable:active { transform: scale(0.98); }
.sys-row.is-on { border-color: var(--blue); background: var(--blue-soft); }
.sys-row.is-changed { animation: row-flash 0.9s var(--ease); }
.sys-ic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: var(--cream-2);
  flex: none;
}
.sys-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 5px; }
/* A long value (Greek, French) drops under its label instead of running off the panel. */
.sys-top { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: 2px 8px; }
.sys-label { font-weight: 800; font-size: 14px; color: var(--muted); }
.sys-val {
  display: inline-flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  align-items: center;
  gap: 4px;
  margin-left: auto;
  max-width: 100%;
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 16px;
  text-align: right;
}
.sys-sub { font-size: 12px; color: var(--muted); font-weight: 700; }
.sys-sub:empty { display: none; }
.meter {
  height: 12px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--cream-2);
  overflow: hidden;
}
.meter > span { display: block; height: 100%; width: 0; border-radius: 999px; background: var(--blue); transition: width 0.5s var(--ease); }
.sys-row[data-k="mass"] .meter > span { background: var(--ink-2); }
.sys-row[data-k="speed"] .meter > span { background: var(--green); }
.sys-row[data-k="bolts"] .meter > span { background: #D9A521; }
.sys-row[data-k="bolts"].is-over .meter > span { background: repeating-linear-gradient(-45deg, var(--orange) 0 5px, #FFB27D 5px 10px); }
.sys-row[data-k="bolts"].is-over .sys-val { color: #B4521A; }
.marble-wrap { height: 30px; color: var(--ink); }
.marble { display: block; }
.marble-ball { fill: var(--blue); stroke: var(--ink); stroke-width: 2.5; transition: cx 0.5s var(--spring), cy 0.5s var(--spring); }
.sys-row[data-state="wobbly"] .marble-ball { fill: var(--yellow); }
.sys-row[data-state="tippy"] .marble-ball { fill: var(--orange); }
.sys-row[data-state="tippy"] .sys-val { color: #B4521A; }
.tank {
  position: relative;
  height: 18px;
  margin-right: 6px;
  border: 2px solid var(--ink);
  border-radius: 6px;
  background: var(--cream-2);
}
.tank-fill {
  position: absolute;
  left: 2px;
  top: 2px;
  bottom: 2px;
  width: 0;
  max-width: calc(100% - 4px);
  border-radius: 3px;
  background: var(--green);
  transition: width 0.6s var(--ease), background-color 0.3s;
}
.tank-cap { position: absolute; right: -7px; top: 4px; width: 5px; height: 6px; border: 2px solid var(--ink); border-left: 0; border-radius: 0 3px 3px 0; background: var(--cream-2); }
.sys-row[data-level="mid"] .tank-fill { background: var(--yellow); }
.sys-row[data-level="low"] .tank-fill { background: repeating-linear-gradient(-45deg, var(--orange) 0 4px, #FFB27D 4px 8px); }
.sys-warnings {
  position: sticky;
  bottom: -10px;
  z-index: 1;
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 2px -4px -10px;
  padding: 6px 4px 10px;
  background: var(--cream);
  box-shadow: 0 -12px 12px -8px var(--cream);
}
.sys-warnings:empty { display: none; }
.sys-warn {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  min-height: 44px;
  padding: 8px 10px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--orange-soft);
  text-align: left;
  font-weight: 700;
  font-size: 14px;
  line-height: 1.3;
  cursor: pointer;
}
.sys-warn .ic-wrap { color: #B4521A; margin-top: 1px; }

/* Parts Shop + locked part */
.shop { display: flex; flex-direction: column; gap: 14px; }
.shop-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-weight: 700; }
.shop-head .hud-chip { box-shadow: none; }
.shop-head .hud-chip .ic { color: #D9A521; }
.shop-list { display: flex; flex-direction: column; gap: 10px; }
.shop-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px;
  border: 2px solid var(--ink);
  border-radius: var(--r-md);
  background: var(--paper);
}
.shop-row.is-focus { box-shadow: 0 0 0 4px var(--yellow); }
.shop-row .part-thumb { width: 64px; height: 56px; flex: none; }
.shop-section { margin: 6px 2px -4px; }
.shop-art { display: flex; align-items: center; justify-content: center; }
.lock-art { display: flex; justify-content: center; margin: 4px 0 12px; }
.lock-art canvas, .lock-art .finish-swatch { border-radius: 16px; }
.lock-art .finish-swatch { width: 72px; height: 72px; border-radius: 50%; }
.lock-have { margin-top: 10px; font-weight: 700; }
.shop-text { flex: 1; min-width: 0; }
.shop-name { font-family: var(--font-title); font-weight: 800; font-size: 17px; }
.shop-blurb { font-size: 14px; color: var(--ink-2); }
.lock-note {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  padding: 12px 14px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--yellow-soft);
  font-weight: 800;
}

/* ------------------------------------------------------------------- look */
.look-ui { position: absolute; inset: 0; pointer-events: none; }
.look-panel {
  position: absolute;
  top: var(--top);
  bottom: var(--bottom);
  right: var(--side-r);
  width: clamp(300px, 30vw, 380px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slide-left 0.4s var(--ease) both;
}
.tabbar {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 4px;
  padding: 8px;
  border-bottom: 2px dashed var(--line);
  flex: none;
}
.btn.tab {
  flex-direction: column;
  gap: 2px;
  min-width: 0;
  min-height: 56px;
  padding: 5px 2px;
  border: 0;
  box-shadow: none;
  background: transparent;
  border-radius: 14px;
  font-size: 12px;
}
.btn.tab .ic { width: 24px; height: 24px; }
.btn.tab.is-on { background: var(--purple); color: #fff; box-shadow: 0 3px 0 var(--ink); }
.btn.tab.is-down { transform: scale(0.94); box-shadow: none; }
.look-body {
  flex: 1;
  min-height: 0;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 16px;
}
.look-section { display: flex; flex-direction: column; min-width: 0; }
.look-row { display: flex; flex-wrap: wrap; gap: 12px 18px; }
.look-foot {
  flex: none;
  display: flex;
  gap: 8px;
  padding: 10px 14px 14px;
  border-top: 2px dashed var(--line);
}
.look-foot:empty { display: none; }
.look-foot .btn { flex: 1 1 auto; white-space: normal; text-align: center; line-height: 1.1; }
.look-lead { font-weight: 700; font-size: 16px; color: var(--ink-2); }
.palette { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 6px; }
.swatch {
  position: relative;
  width: 44px;
  height: 44px;
  justify-self: center;
  padding: 0;
  border: var(--border);
  border-radius: 50%;
  background:
    radial-gradient(circle at 34% 30%, rgba(255, 255, 255, 0.55) 0 14%, rgba(255, 255, 255, 0) 38%),
    var(--c);
  box-shadow: var(--pop-sm);
  cursor: pointer;
  transition: transform 0.18s var(--spring), box-shadow 0.18s;
}
.swatch:active { transform: scale(0.9); }
.swatch.is-on { transform: translateY(-2px) scale(1.08); box-shadow: 0 0 0 3px var(--paper), 0 0 0 6px var(--ink); }
.swatch.is-pop { animation: pop 0.4s var(--spring); }
.swatch-check {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transform: scale(0.4);
  transition: opacity 0.15s, transform 0.25s var(--spring);
}
.swatch-check .ic-wrap {
  width: 24px;
  height: 24px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
}
.swatch-check .ic { width: 14px; height: 14px; stroke-width: 3; }
.swatch.is-on .swatch-check { opacity: 1; transform: scale(1); }
.swatch-mine {
  position: absolute;
  top: -7px;
  right: -7px;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 20px;
  height: 20px;
  border: 2px solid var(--ink);
  border-radius: 50%;
  background: var(--coral);
  color: #fff;
}
.swatch-mine .ic { width: 11px; height: 11px; stroke-width: 3; }
.swatch-sm { width: 40px; height: 40px; }
.finish-row { display: grid; grid-template-columns: repeat(auto-fill, minmax(64px, 1fr)); gap: 6px; }
.finish {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-height: 78px;
  padding: 8px 2px 6px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 2px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.16s var(--spring), box-shadow 0.16s, background-color 0.2s;
}
.finish:active { transform: scale(0.95); }
.finish.is-on { background: var(--purple-soft); box-shadow: 0 0 0 3px var(--purple), 0 2px 0 var(--ink); }
.finish.is-locked { opacity: 0.6; }
.finish-name { font-family: var(--font-title); font-weight: 700; font-size: 12px; line-height: 1.05; text-align: center; max-width: 100%; }
.finish-name.is-tight { font-size: 11px; letter-spacing: -0.02em; }
.finish-name.is-tighter { font-size: 10px; letter-spacing: -0.03em; overflow-wrap: anywhere; }
.finish-lock { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; display: flex; align-items: center; justify-content: center; border: 2px solid var(--ink); border-radius: 50%; background: var(--yellow); }
/* Live finish swatches: each one paints the brush colour (--c) in its material. */
.finish-swatch {
  --c: var(--blue);
  width: 38px;
  height: 38px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: var(--c);
}
.finish-swatch[data-finish="candy"] {
  background:
    radial-gradient(circle at 33% 27%, rgba(255, 255, 255, 0.95) 0 9%, rgba(255, 255, 255, 0) 26%),
    radial-gradient(circle at 70% 82%, rgba(0, 0, 0, 0.3), rgba(0, 0, 0, 0) 58%),
    radial-gradient(circle at 40% 40%, rgba(255, 255, 255, 0.25), rgba(255, 255, 255, 0) 60%),
    var(--c);
}
.finish-swatch[data-finish="matte"] {
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.22), rgba(0, 0, 0, 0.16) 90%), var(--c);
}
.finish-swatch[data-finish="metal"] {
  background:
    repeating-linear-gradient(90deg, rgba(255, 255, 255, 0.14) 0 1px, rgba(0, 0, 0, 0.05) 1px 3px),
    linear-gradient(135deg, rgba(255, 255, 255, 0.55) 0%, rgba(255, 255, 255, 0) 45%, rgba(0, 0, 0, 0.32) 100%),
    var(--c);
}
.finish-swatch[data-finish="chrome"] {
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.95) 0%, rgba(255, 255, 255, 0.2) 38%, rgba(22, 34, 58, 0.75) 50%, rgba(255, 255, 255, 0.15) 64%, rgba(255, 255, 255, 0.85) 100%),
    var(--c);
}
.finish-swatch[data-finish="glitter"] {
  background:
    radial-gradient(circle, rgba(255, 255, 255, 0.95) 0 1px, rgba(255, 255, 255, 0) 1.6px) 0 0 / 7px 7px,
    radial-gradient(circle, rgba(255, 255, 255, 0.7) 0 1px, rgba(255, 255, 255, 0) 1.6px) 3px 4px / 9px 9px,
    radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.4), rgba(0, 0, 0, 0.2) 85%),
    var(--c);
}
.finish-swatch[data-finish="pearl"] {
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.95) 0 8%, rgba(255, 255, 255, 0) 30%),
    conic-gradient(from 210deg, rgba(255, 196, 232, 0.5), rgba(182, 230, 255, 0.5), rgba(255, 240, 190, 0.5), rgba(255, 196, 232, 0.5)),
    var(--c);
}
.finish-swatch[data-finish="glow"] {
  background: radial-gradient(circle at 50% 50%, rgba(255, 255, 255, 0.85) 0 18%, rgba(255, 255, 255, 0) 62%), var(--c);
  box-shadow: 0 0 12px 3px var(--c);
}
.finish-swatch[data-finish="rubber"] {
  background: radial-gradient(circle at 35% 30%, rgba(255, 255, 255, 0.1), rgba(0, 0, 0, 0.42) 95%), var(--c);
}
.finish-swatch[data-finish="wood"] {
  background:
    repeating-radial-gradient(ellipse at 20% 120%, rgba(95, 52, 20, 0.28) 0 2px, rgba(95, 52, 20, 0) 2px 6px),
    linear-gradient(135deg, rgba(255, 220, 170, 0.35), rgba(80, 40, 10, 0.25)),
    var(--c);
}
.finish-swatch[data-finish="glass"] {
  background:
    radial-gradient(circle at 32% 26%, rgba(255, 255, 255, 0.95) 0 8%, rgba(255, 255, 255, 0) 26%),
    linear-gradient(135deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.08)),
    repeating-conic-gradient(rgba(22, 34, 58, 0.12) 0 25%, rgba(255, 255, 255, 0.4) 0 50%) 0 0 / 12px 12px;
  background-color: var(--c);
  opacity: 0.85;
}
.sticker-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); gap: 6px; }
.sticker-btn {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 54px;
  padding: 5px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background:
    repeating-conic-gradient(#EFE7D8 0 25%, #F8F3EA 0 50%) 0 0 / 16px 16px;
  box-shadow: 0 2px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.16s var(--spring);
}
.sticker-btn:active { transform: scale(0.94); }
.sticker-btn.is-on { box-shadow: 0 0 0 3px var(--purple), 0 2px 0 var(--ink); transform: translateY(-2px); }
.sticker-btn.is-locked canvas { filter: grayscale(1) opacity(0.5); }
.sticker-btn .finish-lock { top: -6px; right: -6px; width: 22px; height: 22px; }
.sticker-btn .finish-lock .ic { width: 12px; height: 12px; }
.face-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 10px; }
.face-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 8px 6px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: var(--paper);
  box-shadow: 0 2px 0 var(--ink);
  cursor: pointer;
  transition: transform 0.16s var(--spring);
}
.face-btn canvas { border-radius: 12px; border: 2px solid var(--ink); }
.face-btn:active { transform: scale(0.95); }
.face-btn.is-on { background: var(--purple-soft); box-shadow: 0 0 0 3px var(--purple), 0 2px 0 var(--ink); }
.face-name { font-family: var(--font-title); font-weight: 700; font-size: 13px; }
.name-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 16px;
  border: var(--border);
  border-radius: var(--r-md);
  background: var(--paper);
  box-shadow: var(--pop-sm);
}
.name-card .ic-wrap { color: var(--purple); }
.name-big { font-family: var(--font-title); font-weight: 800; font-size: 30px; line-height: 1.05; overflow-wrap: anywhere; }

/* Rename sheet */
.name-current { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; font-family: var(--font-title); font-weight: 800; font-size: 22px; color: var(--ink-2); }
.name-current .ic-wrap { color: var(--blue); }
.name-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 10px; margin-bottom: 12px; }
.name-form { display: flex; gap: 10px; margin-top: 16px; padding-top: 16px; border-top: 2px dashed var(--line); }
.name-form .text-input { flex: 1; min-width: 0; font-size: 19px; }

/* Settings */
.set-list { display: flex; flex-direction: column; gap: 6px; }
.set-row { display: flex; flex-direction: column; gap: 8px; padding: 12px 2px 14px; border-bottom: 2px dashed var(--line); }
.set-label { display: flex; align-items: center; gap: 10px; font-family: var(--font-title); font-weight: 800; font-size: 18px; }
.set-ic { display: flex; align-items: center; justify-content: center; width: 34px; height: 34px; border: 2px solid var(--ink); border-radius: 10px; background: var(--cream-2); }
.set-hint { font-size: 14px; color: var(--muted); font-weight: 700; }
.set-danger { border-bottom: 0; padding-top: 18px; align-items: flex-start; }

/* -------------------------------------------------------------- brain screen */
.brain-screen { position: absolute; inset: 0; pointer-events: none; }
.brain-left {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  right: calc(min(58vw, 780px) + var(--side-r) + 12px);
  pointer-events: none;
}
.brain-panel {
  position: absolute;
  top: var(--top);
  bottom: var(--bottom);
  right: var(--side-r);
  width: min(58vw, 780px);
  display: flex;
  flex-direction: column;
  overflow: hidden;
  animation: slide-left 0.42s var(--ease) both;
}
.brain-panel.is-empty { background: var(--orange-soft); }
/* Same-screen co-op: the build area stays live on the left half. */
.brain-left .build-ui.is-compact .drawer { width: clamp(220px, 20vw, 260px); }
.brain-left .build-ui.is-compact .tool-rail { left: calc(var(--side-l) + clamp(220px, 20vw, 260px) + 12px); transform: none; bottom: var(--bottom); flex-direction: column; animation-name: rise-in-plain; }
.brain-left .build-ui.is-compact .btn.fam .btn-label { font-size: 11px; }
.brain-left .build-ui.is-compact .build-hint { display: none; }

/* -------------------------------------------------------------------- test */
.test-ui { position: absolute; inset: 0; pointer-events: none; }
.test-top {
  position: absolute;
  top: var(--top);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 8px 16px;
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 16px;
  white-space: nowrap;
  pointer-events: none;
}
.test-top > span { display: inline-flex; align-items: center; gap: 6px; }
.test-arena .ic-wrap { color: var(--green); }
.test-time { min-width: 3.4em; font-variant-numeric: tabular-nums; }
.mini-meter { display: inline-block; width: 64px; height: 12px; border: 2px solid var(--ink); border-radius: 999px; background: var(--cream-2); overflow: hidden; }
.mini-meter > span { display: block; height: 100%; width: 100%; background: var(--green); transition: width 0.3s linear; }
.test-battery[data-level="mid"] .mini-meter > span { background: var(--yellow); }
.test-battery[data-level="low"] .mini-meter > span { background: repeating-linear-gradient(-45deg, var(--orange) 0 4px, #FFB27D 4px 8px); }
.transport {
  position: absolute;
  left: 50%;
  bottom: var(--bottom);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px;
  border-radius: 26px;
  animation: rise-in 0.4s var(--ease) both;
}
.btn.tbtn {
  flex-direction: column;
  gap: 3px;
  min-width: 70px;
  min-height: 62px;
  padding: 6px 8px;
  font-size: 13px;
  background: var(--paper);
}
.btn.tbtn .ic { width: 26px; height: 26px; }
.btn.tbtn[aria-pressed="true"] { background: var(--blue); color: #fff; }
.btn.tbtn-play {
  min-width: 112px;
  min-height: 76px;
  font-size: 18px;
  border-radius: 22px;
  background: var(--green);
  color: #fff;
}
.btn.tbtn-play .ic { width: 32px; height: 32px; }
.btn.tbtn-play.is-pulse { animation: play-pulse 1.8s ease-in-out infinite; }
.test-remote {
  position: absolute;
  right: var(--side-r);
  bottom: var(--bottom);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.btn.remote-btn {
  width: 76px;
  height: 76px;
  flex-direction: column;
  gap: 2px;
  padding: 0;
  border-radius: 50%;
  font-size: 13px;
  background: var(--tone, var(--blue));
  color: var(--tone-ink, #fff);
}
.btn.remote-letter { font-size: 30px; }
.btn.remote-btn .btn-label { max-width: 100%; padding: 0 4px; text-align: center; }
.btn.remote-btn.is-long { font-size: 11px; letter-spacing: -0.02em; }
.btn.tbtn.speed-btn { min-width: 76px; }
.btn.remote-btn.is-pop { animation: pop 0.4s var(--spring); }
.test-brain {
  position: absolute;
  top: var(--top);
  left: var(--side-l);
  width: clamp(260px, 26vw, 340px);
  max-height: calc(100% - var(--top) - var(--bottom) - 90px);
  overflow: auto;
  padding: 8px;
  animation: slide-right 0.4s var(--ease) both;
}
.test-status {
  position: absolute;
  left: 50%;
  bottom: calc(var(--bottom) + 104px);
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px 10px 12px;
  font-family: var(--font-title);
  font-weight: 800;
  font-size: 19px;
  white-space: nowrap;
  pointer-events: none;
  animation: fade-in 0.3s var(--ease) both;
}
.test-status .ic-wrap { color: var(--green); }
.test-ui[data-phase="missing"] .test-brain { display: none; }
/* While a report is up, the run controls step aside (they peeked out under it). */
.test-ui .transport, .test-ui .test-remote { transition: opacity 0.25s, visibility 0.25s; }
.test-ui[data-report] .transport, .test-ui[data-report] .test-remote, .test-ui[data-report] .test-status { opacity: 0; visibility: hidden; }
.test-report-layer { position: absolute; inset: 0; pointer-events: none; z-index: 2; }
.test-report-layer:empty { display: none; }
.test-report-layer > * { pointer-events: auto; }
.result-host { position: absolute; inset: 0; }
.report-card {
  position: absolute;
  left: 50%;
  top: 50%;
  width: min(540px, calc(100vw - 32px));
  max-height: calc(100% - var(--top) - 24px);
  overflow-y: auto;
  transform: translate(-50%, -50%);
  padding: 20px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  animation: sheet-pop 0.45s var(--spring) both;
}
.report-head { display: flex; align-items: center; gap: 14px; }
.report-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 60px;
  height: 60px;
  border: var(--border);
  border-radius: 20px;
  background: var(--yellow);
  box-shadow: var(--pop-sm);
  flex: none;
  animation: badge-bounce 0.8s var(--spring) 0.15s both;
}
.report-sub { color: var(--muted); font-weight: 700; margin-top: 4px; }
.report-stats { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.report-stat {
  display: grid;
  grid-template-columns: auto 1fr;
  grid-template-rows: auto auto;
  column-gap: 10px;
  align-items: center;
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: 16px;
  background: var(--paper);
}
.report-stat .ic-wrap { grid-row: 1 / 3; color: var(--blue); }
.report-label { font-size: 13px; font-weight: 800; color: var(--muted); }
.report-val { font-family: var(--font-title); font-weight: 800; font-size: 20px; }
.report-discoveries { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 8px; }
.report-discoveries li {
  display: flex;
  gap: 10px;
  align-items: flex-start;
  padding: 10px 12px;
  border: 2px solid var(--ink);
  border-radius: 14px;
  background: var(--yellow-soft);
  font-weight: 700;
  line-height: 1.3;
}
.report-discoveries .ic-wrap { color: #B98A10; margin-top: 1px; }
.report-sparks {
  display: inline-flex;
  align-self: flex-start;
  align-items: center;
  gap: 8px;
  padding: 6px 14px 6px 8px;
  border: 2px solid var(--ink);
  border-radius: 999px;
  background: var(--yellow);
  font-family: var(--font-title);
  font-weight: 800;
}
.report-lead { font-family: var(--font-title); font-weight: 800; font-size: 19px; }
.report-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.report-actions .btn { flex: 1 1 140px; }

/* ------------------------------------------------------------------- photo */
.photo-ui { position: absolute; inset: 0; pointer-events: none; }
.photo-bar {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 16px);
  transform: translateX(-50%);
  width: min(720px, calc(100vw - 32px));
  padding: 12px 14px 14px;
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-areas: 'top top' 'faces snap' 'angles snap';
  gap: 10px 14px;
  align-items: center;
  animation: rise-in 0.4s var(--ease) both;
  transition: transform 0.35s var(--ease), opacity 0.25s;
}
.photo-top { grid-area: top; display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.photo-title { display: inline-flex; align-items: center; gap: 8px; font-family: var(--font-title); font-weight: 800; font-size: 20px; }
.photo-top-btns { display: flex; gap: 8px; }
.photo-group { display: flex; align-items: center; gap: 10px; min-width: 0; }
.photo-group:nth-of-type(2) { grid-area: faces; }
.photo-group:nth-of-type(3) { grid-area: angles; }
.photo-group .section-label { margin: 0; flex: none; width: 54px; }
.photo-faces, .photo-angles { display: flex; gap: 6px; overflow-x: auto; scrollbar-width: none; padding: 2px 2px 4px; }
.photo-faces { flex-wrap: wrap; overflow: visible; }
.photo-faces::-webkit-scrollbar, .photo-angles::-webkit-scrollbar { display: none; }
.photo-face {
  flex: none;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 46px;
  padding: 0;
  border: 2px solid var(--ink);
  border-radius: 12px;
  background: #0B1020;
  box-shadow: 0 2px 0 var(--ink);
  cursor: pointer;
  overflow: hidden;
}
.photo-face.is-on { box-shadow: 0 0 0 3px var(--yellow), 0 2px 0 var(--ink); transform: translateY(-2px); }
.btn.btn-snap {
  grid-area: snap;
  flex-direction: column;
  width: 104px;
  height: 104px;
  padding: 0;
  border-radius: 50%;
  font-size: 15px;
  box-shadow: 0 0 0 5px var(--cream), 0 0 0 8px var(--ink), 0 6px 0 8px var(--ink);
}
.btn.btn-snap .ic { width: 36px; height: 36px; }
.btn.btn-snap.is-down, .btn.btn-snap:active { transform: scale(0.94); box-shadow: 0 0 0 5px var(--cream), 0 0 0 8px var(--ink); }
.photo-show { position: absolute; top: calc(var(--safe-t) + 14px); right: var(--side-r); opacity: 0; visibility: hidden; }
.photo-ui.is-bare .photo-bar { transform: translate(-50%, calc(100% + 40px)); opacity: 0; visibility: hidden; }
.photo-ui.is-bare .photo-show { opacity: 1; visibility: visible; }
.photo-flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.photo-flash.is-on { animation: flash-white 0.45s var(--ease); }
.photo-preview { display: block; max-width: 100%; max-height: 56vh; border: var(--border); border-radius: var(--r-md); box-shadow: var(--pop-sm); background: var(--cream-2); }

/* ------------------------------------------------------- onboarding (coach) */
.coach-card {
  position: absolute;
  left: 50%;
  width: min(580px, calc(100vw - 32px));
  padding: 18px 18px 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
  transform: translateX(-50%);
  animation: coach-in 0.45s var(--spring) both;
}
.coach-card.is-bottom { bottom: calc(var(--safe-b) + 28px); }
.coach-card.is-top { top: calc(var(--top) + 6px); }
.coach-card.is-leaving { animation: fade-out 0.2s var(--ease) both; }
.coach-head { display: flex; gap: 14px; align-items: center; }
.coach-text { flex: 1; min-width: 0; }
.coach-badge {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 56px;
  height: 56px;
  border: var(--border);
  border-radius: 18px;
  background: var(--yellow);
  box-shadow: var(--pop-sm);
  flex: none;
  animation: badge-bounce 0.8s var(--spring) both;
}
.coach-title { font-size: 26px; line-height: 1.1; }
.coach-sub { margin-top: 4px; font-weight: 700; font-size: 17px; color: var(--ink-2); }
.coach-names { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.coach-names > .btn-soft { grid-column: 1 / -1; }
.coach-actions { display: flex; flex-wrap: wrap; gap: 10px; }
.coach-actions .btn { flex: 1 1 180px; min-height: 56px; font-size: 19px; }
.coach-skip { flex: none; align-self: flex-start; margin: -6px -6px 0 0; font-size: 14px; color: var(--muted); }
.coach-parts { display: flex; justify-content: center; }
.coach-part-wrap { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.coach-part-name { font-family: var(--font-title); font-weight: 800; font-size: 17px; }
.coach-part {
  position: relative;
  width: 96px;
  height: 96px;
  padding: 6px;
  border: var(--border);
  border-radius: 22px;
  background: var(--paper);
  box-shadow: var(--pop);
  cursor: grab;
  touch-action: none;
  animation: nudge 1.8s ease-in-out infinite;
}
.coach-part .part-thumb { width: 100%; height: 100%; }
.coach-part.is-dragging { animation: none; z-index: 5; box-shadow: 0 16px 30px rgba(22, 34, 58, 0.3); transition: none; }
.coach-ring {
  position: fixed;
  left: -40px;
  top: -40px;
  width: 80px;
  height: 80px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  pointer-events: auto;
  cursor: pointer;
}
.coach-ring::before, .coach-ring::after {
  content: '';
  position: absolute;
  inset: 0;
  border: 4px solid var(--blue);
  border-radius: 50%;
  animation: ring-pulse 1.6s ease-out infinite;
}
.coach-ring::after { animation-delay: 0.8s; }
.coach-ring-core {
  position: absolute;
  inset: 24px;
  border: 3px solid var(--ink);
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #BFE3FF, var(--blue));
  box-shadow: 0 0 22px 8px rgba(46, 139, 201, 0.55);
}
.coach-ring.is-hot .coach-ring-core { box-shadow: 0 0 30px 14px rgba(46, 139, 201, 0.75); }
.coach-ring.is-done { animation: pop-out 0.4s var(--ease) forwards; }
.coach-hand {
  position: fixed;
  left: -6px;
  top: -6px;
  z-index: 2;
  display: none;
  color: var(--ink);
  pointer-events: none;
  filter: drop-shadow(0 4px 0 rgba(22, 34, 58, 0.25));
}
.coach-hand .ic-wrap {
  width: 54px;
  height: 54px;
  border: var(--border);
  border-radius: 50%;
  background: #fff;
}
.coach-hand.is-show { display: block; animation: show-me 1.5s var(--ease) both; }
.ob-strip { display: flex; gap: 0; margin-bottom: 12px; }
.ob-slot {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 60px;
  padding: 8px 14px;
  border: var(--border);
  background: var(--paper);
  font-family: var(--font-title);
  font-weight: 800;
}
.ob-when { border-radius: 30px 8px 8px 30px; background: var(--orange-soft); }
.ob-do { border-radius: 8px 18px 18px 8px; margin-left: -3px; background: var(--blue-soft); clip-path: polygon(0 0, 100% 0, 100% 100%, 0 100%, 0 64%, 10px 50%, 0 36%); padding-left: 22px; }
.ob-slot-k { font-size: 14px; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); }
.ob-slot-v {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-width: 96px;
  min-height: 40px;
  padding: 0 10px;
  border: 2px dashed rgba(22, 34, 58, 0.35);
  border-radius: 12px;
  font-size: 18px;
}
.ob-slot.is-filled .ob-slot-v { border: 2px solid var(--ink); background: #fff; animation: pop 0.4s var(--spring); }
.ob-tiles { display: flex; gap: 12px; justify-content: center; }
.btn.ob-tile { min-height: 64px; padding: 0 22px; font-size: 20px; background: var(--tone, var(--blue)); color: var(--tone-ink, #fff); border-radius: 18px; }
.btn.ob-tile.is-pulse { animation: play-pulse 1.4s ease-in-out infinite; }
.btn.ob-tile.is-used { opacity: 0.35; }

/* ------------------------------------------------------- rooms of others */
/* The job board, the notebook and the Together room sit between the top bar and
   the dock, like every other panel (their titles, tabs and close buttons stay
   clear of the HUD). */
.room-map, .room-notebook, .room-coop {
  z-index: 2;
  top: calc(var(--top) - 8px);
  bottom: calc(var(--bottom) - 8px);
  left: var(--side-l);
  right: var(--side-r);
}
.room-map, .room-notebook {
  border-radius: var(--r-xl);
  overflow: hidden;
  box-shadow: var(--float);
}

/* ------------------------------------------------------------- animations */
@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes fade-out { from { opacity: 1; } to { opacity: 0; } }
@keyframes card-in { from { opacity: 0; transform: translateY(18px) scale(0.92); } to { opacity: 1; transform: none; } }
@keyframes boot-in { from { transform: translateY(10px) scale(0.97); } to { transform: none; } }
@keyframes bar-slide { from { transform: translateX(0); } to { transform: translateX(22.6px); } }
@keyframes title-in { from { opacity: 0; transform: translateY(40px) scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes title-out { to { opacity: 0; transform: translateY(30px) scale(0.94); } }
@keyframes sheet-pop { from { opacity: 0; transform: translate(-50%, -46%) scale(0.9); } to { opacity: 1; transform: translate(-50%, -50%) scale(1); } }
@keyframes sheet-pop-out { to { opacity: 0; transform: translate(-50%, -48%) scale(0.95); } }
@keyframes slide-left { from { opacity: 0; transform: translateX(40px); } to { opacity: 1; transform: none; } }
@keyframes slide-left-out { to { opacity: 0; transform: translateX(40px); } }
@keyframes slide-right { from { opacity: 0; transform: translateX(-40px); } to { opacity: 1; transform: none; } }
@keyframes slide-right-out { to { opacity: 0; transform: translateX(-40px); } }
@keyframes slide-up { from { opacity: 0; transform: translate(-50%, 40px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes slide-down-out { to { opacity: 0; transform: translate(-50%, 40px); } }
@keyframes rise-in { from { opacity: 0; transform: translate(-50%, 30px); } to { opacity: 1; transform: translate(-50%, 0); } }
@keyframes coach-in { from { opacity: 0; transform: translate(-50%, 24px) scale(0.94); } to { opacity: 1; transform: translate(-50%, 0) scale(1); } }
@keyframes toast-in { from { opacity: 0; transform: translateY(-14px) scale(0.7); } to { opacity: 1; transform: none; } }
@keyframes toast-out { to { opacity: 0; transform: translateY(-10px) scale(0.9); } }
@keyframes pop { 0% { transform: scale(1); } 40% { transform: scale(1.22); } 100% { transform: scale(1); } }
@keyframes pop-out { to { opacity: 0; transform: scale(1.6); } }
@keyframes float-up { from { opacity: 1; transform: translate(-50%, 0); } to { opacity: 0; transform: translate(-50%, -36px); } }
@keyframes wiggle { 0%, 100% { transform: rotate(0); } 25% { transform: rotate(-9deg); } 50% { transform: rotate(8deg); } 75% { transform: rotate(-4deg); } }
@keyframes spin-once { from { transform: rotate(0); } to { transform: rotate(90deg); } }
@keyframes row-flash { 0% { background-color: var(--yellow-soft); } 100% { background-color: transparent; } }
@keyframes delta-in { from { opacity: 0; transform: translateY(8px) scale(0.9); } to { opacity: 1; transform: none; } }
@keyframes play-pulse { 0%, 100% { box-shadow: var(--pop), 0 0 0 0 rgba(47, 158, 91, 0.5); } 50% { box-shadow: var(--pop), 0 0 0 10px rgba(47, 158, 91, 0); } }
@keyframes badge-bounce { from { transform: scale(0.4) rotate(-12deg); } to { transform: none; } }
@keyframes ring-pulse { from { transform: scale(0.55); opacity: 1; } to { transform: scale(1.35); opacity: 0; } }
@keyframes nudge { 0%, 100% { transform: translateY(0); } 50% { transform: translateY(-6px); } }
@keyframes show-me {
  0% { opacity: 0; transform: translate(var(--fx), var(--fy)) scale(0.8); }
  15% { opacity: 1; transform: translate(var(--fx), var(--fy)) scale(0.92); }
  75% { opacity: 1; transform: translate(var(--tx), var(--ty)) scale(0.92); }
  100% { opacity: 0; transform: translate(var(--tx), var(--ty)) scale(0.8); }
}
@keyframes flash-white { 0% { opacity: 0.9; } 100% { opacity: 0; } }
@keyframes tool-tap { 0%, 100% { transform: rotate(0); } 10% { transform: rotate(-14deg); } 20% { transform: rotate(6deg); } 30% { transform: rotate(0); } }
@keyframes bot-bob { 0%, 100% { transform: translateY(0) scale(1, 1); } 45% { transform: translateY(-8px) scale(0.98, 1.03); } 55% { transform: translateY(-8px) scale(0.98, 1.03); } 90% { transform: translateY(0) scale(1.04, 0.96); } }
@keyframes bot-shadow { 0%, 100% { transform: scale(1); opacity: 1; } 50% { transform: scale(0.8); opacity: 0.6; } }
@keyframes bot-blink { 0%, 92%, 100% { transform: scaleY(1); } 95% { transform: scaleY(0.1); } }
@keyframes bulb-glow { from { fill: #F2C14E; } to { fill: #FFE9A8; } }
@keyframes bar-stripes { from { background-position: 0 0, 0 0; } to { background-position: 22.6px 0, 0 0; } }

/* ---------------------------------------------------------- reduced motion */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: 0.01ms !important; animation-iteration-count: 1 !important; transition-duration: 0.01ms !important; }
}
html.reduce-motion *, html.reduce-motion *::before, html.reduce-motion *::after {
  animation-duration: 0.01ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: 0.01ms !important;
}

/* ------------------------------------------------------------- responsive */
/* Laptop and iPad landscape (1024-1280 wide): tighter side panels. */
@media (max-width: 1180px) {
  :root { --gap: 10px; }
  .hud-name { max-width: 200px; font-size: 19px; }
  .dock-btn { width: 72px; }
  .build-hint, .look-hint { max-width: min(420px, calc(100vw - 2 * 300px)); font-size: 15px; }
}

/* Short screens (1024x768, 1280x720): a slimmer dock and top bar. */
@media (max-height: 800px) {
  :root { --hud-h: 52px; --dock-h: 80px; }
  .dock-btn { min-height: 62px; }
  .dock-ic { height: 36px; }
  .part-card { min-height: 120px; }
  .part-thumb { height: 64px; }
  .btn.tool, .btn.tbtn { min-height: 56px; }
  .btn.tbtn-play { min-height: 68px; }
  .btn.remote-btn { width: 68px; height: 68px; }
}

@media (max-width: 1060px) {
  .hud-music { display: none; }
  .hud-bolts-bar { width: 40px; }
}

/* Portrait tablets (820x1180) and narrow windows: side panels become bottom
   drawers so the robot keeps the middle of the screen. */
@media (max-width: 900px), (max-aspect-ratio: 4/5) {
  :root { --dock-h: 84px; }
  .hud-name { max-width: 150px; }
  .hud-chip { padding: 0 10px 0 8px; font-size: 16px; }
  .dock-btn { width: 68px; }
  .dock-label { font-size: 12px; }

  /* The Body drawer becomes a bottom drawer (the compact same-screen drawer on
     the Brain screen stays a column: see below). */
  .build-ui:not(.is-compact) .drawer {
    top: auto;
    bottom: var(--bottom);
    right: var(--side-r);
    width: auto;
    height: min(270px, 30vh);
    flex-direction: row;
    animation-name: rise-in-plain;
  }
  .build-ui:not(.is-compact) .fam-bar { grid-template-columns: repeat(2, 64px); grid-auto-rows: 1fr; overflow-y: auto; }
  .btn.fam { min-height: 48px; }
  .build-ui:not(.is-compact) .part-grid {
    grid-template-columns: none;
    grid-auto-flow: column;
    grid-auto-columns: 104px;
    grid-template-rows: repeat(2, minmax(0, 1fr));
    overflow-x: auto;
    overflow-y: hidden;
  }
  .part-card { min-height: 0; padding: 6px 4px; gap: 2px; }
  .part-thumb { width: 72px; height: 54px; }
  .part-name { font-size: 13px; min-height: 0; }
  .part-empty { grid-row: 1 / -1; }
  .shop-btn { width: auto; align-self: center; flex-direction: column; min-width: 84px; min-height: 96px; white-space: normal; text-align: center; font-size: 13px; }
  .tool-rail {
    left: var(--side-l);
    bottom: calc(var(--bottom) + min(270px, 30vh) + 12px);
    transform: none;
    flex-direction: column;
    animation-name: fade-in;
  }
  .quick-swatches {
    left: calc(var(--side-l) + 110px);
    right: var(--side-r);
    bottom: calc(var(--bottom) + min(270px, 30vh) + 12px);
    max-width: none;
    transform: translateY(16px) scale(0.96);
    border-radius: 24px;
  }
  .quick-swatches.is-open { transform: none; }
  .part-info { width: clamp(220px, 34vw, 280px); }
  .systems {
    width: clamp(220px, 34vw, 280px);
    max-height: calc(100% - var(--top) - var(--bottom) - min(270px, 30vh) - 100px);
  }
  .view-btns { left: var(--side-l); transform: none; flex-direction: column; border-radius: 22px; }
  .build-hint { bottom: auto; top: var(--top); left: calc(var(--side-l) + 120px); right: calc(var(--side-r) + clamp(220px, 34vw, 280px) + 12px); transform: none; max-width: none; }
  .look-hint { bottom: auto; top: var(--top); max-width: calc(100vw - 40px); }

  .look-panel { top: auto; left: var(--side-l); width: auto; height: min(46vh, 520px); animation-name: rise-in-plain; }

  /* Brain: the robot keeps a real strip above the card board (it wiggles there). */
  .brain-panel { left: var(--side-l); width: auto; top: calc(var(--top) + 30vh); }
  .brain-left { right: 0; bottom: auto; height: calc(var(--top) + 30vh); }
  /* Two kids, one screen: the builder's half on top, the brain board below. */
  .brain-screen.is-same .brain-panel { top: 50%; }
  .brain-screen.is-same .brain-left { height: 50%; }
  .brain-left .build-ui.is-compact .drawer { top: var(--top); bottom: 12px; height: auto; width: clamp(200px, 30vw, 240px); }
  .brain-left .build-ui.is-compact .tool-rail { left: calc(var(--side-l) + clamp(200px, 30vw, 240px) + 12px); bottom: 12px; }

  /* The arena name pill sits right of the brain strip, never under it. */
  .test-top {
    left: calc(var(--side-l) + min(300px, 44vw) + 12px);
    right: var(--side-r);
    width: fit-content;
    max-width: calc(100% - var(--side-l) - min(300px, 44vw) - 12px - var(--side-r));
    margin: 0 auto;
    transform: none;
    flex-wrap: wrap;
    justify-content: center;
    white-space: normal;
  }
  .test-brain { width: min(300px, 44vw); }
  .transport { gap: 6px; padding: 6px 8px; }
  .btn.tbtn { min-width: 60px; padding: 6px 4px; }
  .btn.tbtn-play { min-width: 96px; }

  .hub { top: auto; bottom: var(--bottom); right: var(--side-r); justify-content: center; }
  .hub-card { width: min(520px, 100%); margin: 0 auto; }
  .hub-actions { grid-template-columns: repeat(3, 1fr); }
  .hub-actions .btn { flex-direction: column; justify-content: center; min-height: 72px; font-size: 16px; white-space: normal; text-align: center; }

  .title-screen { align-items: center; justify-content: flex-end; padding: calc(var(--safe-t) + 24px) 24px calc(var(--safe-b) + 6vh); background: linear-gradient(180deg, rgba(251, 247, 240, 0) 55%, rgba(251, 247, 240, 0.4) 100%); }
  .title-card { align-items: center; text-align: center; max-width: none; }

  .photo-bar { grid-template-columns: 1fr; grid-template-areas: 'top' 'faces' 'angles' 'snap'; justify-items: center; }
  .photo-group { width: 100%; }
  .btn.btn-snap { width: 88px; height: 88px; }
}
@keyframes rise-in-plain { from { opacity: 0; transform: translateY(30px); } to { opacity: 1; transform: none; } }

/* Phones and very small windows: still usable (the game targets tablets and up). */
@media (max-width: 600px) {
  .hud-sparks, .hud-bolts { display: none; }
  .dock-btn { width: 58px; }
  .dock-label { font-size: 11px; }
  .systems { display: none; }
  .test-remote { gap: 8px; }
  .btn.remote-btn { width: 60px; height: 60px; }
  .coach-names { grid-template-columns: 1fr 1fr; }
}
