/* ─────────────────────────────────────────────────────────────────────────
   Pool Designer — design system (U.GG-grade dark dashboard)

   All visual primitives are token-driven. JS-emitted class names from
   frontend/src/views/* and widgets/* are intentionally preserved here so
   no markup changes are required outside of the additive shell.
   ───────────────────────────────────────────────────────────────────────── */

:root {
  /* Surfaces ─ layered, never pure black */
  --bg:           #0B0F19;
  --surface-1:    #121826;   /* cards */
  --surface-2:    #1A2236;   /* elevated / hover */
  --surface-3:    #222B43;   /* row hover, selected */
  --surface-rail: #0E1422;   /* sidebar/topbar tint */
  --overlay:      rgba(11, 15, 25, 0.72);

  /* Borders / dividers */
  --border-subtle: rgba(255, 255, 255, 0.06);
  --border:        rgba(255, 255, 255, 0.10);
  --border-strong: rgba(255, 255, 255, 0.16);

  /* Text */
  --text:          #E6EAF2;
  --text-muted:    #9AA3B7;
  --text-dim:      #6B7390;
  --text-on-accent:#06231A;

  /* Accent (teal — preserves brand) */
  --accent:        #3DD9A4;
  --accent-strong: #6FE2B5;
  --accent-soft:   rgba(61, 217, 164, 0.14);
  --accent-bar:    rgba(61, 217, 164, 0.28);
  --accent-ring:   rgba(61, 217, 164, 0.45);

  /* Semantic data palette — encodes meaning, do not retheme */
  --c-matchup:     #E6C978;
  --c-synergy:     #7FC0E8;
  --c-blind:       #C9A4D8;
  --c-total:       #6FE2B5;
  --c-pos:         #3DD9A4;
  --c-neg:         #E07B4A;

  /* Radii */
  --r-sm:   6px;
  --r-md:   10px;
  --r-lg:   14px;
  --r-pill: 999px;

  /* Shadows */
  --shadow-sm:   0 1px 0 rgba(255,255,255,0.04) inset, 0 1px 2px rgba(0,0,0,0.4);
  --shadow-md:   0 8px 24px -8px rgba(0,0,0,0.6);
  --shadow-glow: 0 0 0 1px var(--accent-ring), 0 8px 28px -10px rgba(61,217,164,0.35);

  /* Spacing (8px grid) */
  --s-1:  4px;
  --s-2:  8px;
  --s-3: 12px;
  --s-4: 16px;
  --s-5: 20px;
  --s-6: 24px;
  --s-8: 32px;

  /* Typography */
  --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI",
               system-ui, sans-serif;
  --font-num:  "Inter", ui-monospace, "SF Mono", Menlo, monospace;

  --fs-h1: 22px;
  --fs-h2: 16px;
  --fs-h3: 13px;
  --fs-body: 13px;
  --fs-sm: 12px;
  --fs-xs: 11px;

  /* Motion */
  --ease:     cubic-bezier(.2, .7, .2, 1);
  --dur-fast: 120ms;
  --dur:      180ms;

  /* Shell metrics */
  --topbar-h:    56px;
  --sidebar-w:   280px;
  --sidebar-w-collapsed: 64px;
}

/* ── Reset ─────────────────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; height: 100%; }
html, body { overflow-x: hidden; max-width: 100vw; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: var(--fs-body);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  font-feature-settings: "cv11", "ss01";
}
a { color: var(--accent-strong); text-decoration: none; }
a:hover { color: var(--accent); text-decoration: underline; }
button { font-family: inherit; }

/* Custom scrollbars (WebKit + Firefox) */
* { scrollbar-width: thin; scrollbar-color: var(--surface-3) transparent; }
*::-webkit-scrollbar { width: 10px; height: 10px; }
*::-webkit-scrollbar-track { background: transparent; }
*::-webkit-scrollbar-thumb {
  background: var(--surface-3);
  border: 2px solid transparent;
  background-clip: padding-box;
  border-radius: 8px;
}
*::-webkit-scrollbar-thumb:hover { background-color: var(--border-strong); background-clip: padding-box; }

/* Screen-reader-only helper (preserves hidden form-control semantics). */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0);
  white-space: nowrap; border: 0;
}

/* Focus rings (only when the user is keyboarding) */
:focus { outline: none; }
:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--accent-ring);
  border-radius: var(--r-sm);
}

/* ── App shell (grid) ──────────────────────────────────────────────────── */
.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  grid-template-rows: var(--topbar-h) 1fr;
  grid-template-areas:
    "topbar topbar"
    "side   main";
  min-height: 100vh;
  transition: grid-template-columns var(--dur) var(--ease);
}
.app-shell[data-sidebar="collapsed"] {
  /* Collapsed = fully hidden sidebar at every viewport width. The sidebar
     itself is taken out of flow (position: fixed below) and slid off-screen,
     so the grid only needs a single main column. Avoids the previous 64px
     desktop "strip" state that confused users when they widened the window
     while collapsed. */
  grid-template-columns: 1fr;
  grid-template-areas:
    "topbar"
    "main";
}

/* Legacy #app fallback if shell wrapper is not present (defensive). */
#app:not(.app-shell) { display: flex; min-height: 100vh; }

/* ── Topbar ────────────────────────────────────────────────────────────── */
#topbar {
  grid-area: topbar;
  display: flex;
  align-items: center;
  gap: var(--s-4);
  padding: 0 var(--s-4);
  background: rgba(11, 15, 25, 0.78);
  backdrop-filter: saturate(140%) blur(10px);
  -webkit-backdrop-filter: saturate(140%) blur(10px);
  border-bottom: 1px solid var(--border-subtle);
  position: sticky; top: 0; z-index: 50;
}
.topbar-brand {
  display: flex; align-items: center; gap: var(--s-2);
  font-weight: 700; letter-spacing: -0.01em;
  color: var(--text);
  flex-shrink: 0;
}
.topbar-brand .brand-mark {
  width: 28px; height: 28px; border-radius: 8px;
  background: linear-gradient(135deg, var(--accent) 0%, #2BAA85 100%);
  display: grid; place-items: center;
  color: var(--text-on-accent);
  font-weight: 800; font-size: 14px;
  box-shadow: 0 4px 12px -4px rgba(61,217,164,0.5);
}
.topbar-brand .brand-name { font-size: 14px; }
.topbar-brand .brand-name .brand-sub {
  display: block; font-size: 10px; color: var(--text-dim);
  font-weight: 500; letter-spacing: 0.04em; text-transform: uppercase;
  line-height: 1; margin-top: 2px;
}
.topbar-divider {
  width: 1px; height: 24px;
  background: var(--border-subtle);
  margin: 0 var(--s-2);
}
#topbar-title {
  font-size: 14px;
  color: var(--text);
  font-weight: 600;
  letter-spacing: -0.005em;
}
#topbar-title .crumb {
  color: var(--text-dim);
  font-weight: 500;
  margin-right: var(--s-2);
}
.topbar-spacer { flex: 1; }
.topbar-links {
  display: flex; align-items: center; gap: var(--s-3);
  font-size: var(--fs-sm);
  color: var(--text-muted);
}
.topbar-links a {
  color: var(--text-muted);
  padding: 4px 8px;
  border-radius: var(--r-sm);
  transition: color var(--dur-fast), background var(--dur-fast);
}
.topbar-links a:hover { color: var(--text); background: var(--surface-2); text-decoration: none; }
.topbar-links .sep { color: var(--border-strong); }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 32px; height: 32px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  color: var(--text-muted);
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-subtle); }
.icon-btn svg { width: 16px; height: 16px; }

/* ── Sidebar ───────────────────────────────────────────────────────────── */
#sidebar {
  grid-area: side;
  background: var(--surface-rail);
  border-right: 1px solid var(--border-subtle);
  padding: var(--s-4) var(--s-4) var(--s-6);
  overflow-y: auto;
  position: sticky;
  top: var(--topbar-h);
  max-height: calc(100vh - var(--topbar-h));
}

/* ── Dev banner ─────────────────────────────────────────────────────────── */
#dev-banner {
  position: sticky;
  top: 0;
  z-index: 100;
  background: #f1c84b;
  color: #1a1300;
  text-align: center;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.04em;
  padding: 6px 12px;
  border-bottom: 1px solid #b58a1e;
}

/* ── App nav (sidebar) ──────────────────────────────────────────────────── */
#app-nav { margin-bottom: var(--s-5); }
#app-nav h1 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 var(--s-3);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
#app-nav .nav-group { margin-bottom: var(--s-2); }
#app-nav .nav-group-trigger {
  display: flex; align-items: center; gap: 6px;
  width: 100%;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 6px 8px;
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  text-align: left;
}
#app-nav .nav-group-trigger:hover { background: var(--surface-2); }
#app-nav .nav-caret {
  display: inline-block;
  transition: transform var(--dur-fast) var(--ease);
  font-size: 10px;
  color: var(--text-muted);
}
#app-nav .nav-group[data-expanded="false"] .nav-caret { transform: rotate(-90deg); }
#app-nav .nav-group[data-expanded="false"] .nav-group-items { display: none; }
#app-nav .nav-group-items {
  display: flex;
  flex-direction: column;
  gap: 1px;
  margin: 2px 0 6px 16px;
  padding-left: 8px;
  border-left: 1px solid var(--border-subtle);
}
#app-nav .nav-item {
  display: block;
  width: 100%;
  text-align: left;
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  padding: 5px 10px;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
}
#app-nav .nav-item:hover { background: var(--surface-2); color: var(--text); }
#app-nav .nav-item.active {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 600;
  box-shadow: inset 2px 0 0 var(--accent);
}
#app-nav .nav-standalone { margin-top: 4px; padding-left: 8px; font-weight: 600; color: var(--text); }

/* Old horizontal tab strip retired in favor of sidebar nav. Kept in DOM
   so existing event handlers / tests don't break, but hidden visually. */
.tabs-top { display: none !important; }

/* ── CPD-only sidebar controls ─────────────────────────────────────────── */
/* Shown only when an active view belongs to the Champion Pool Designer
   group. Toggle is driven by data-view-group on .app-shell. */
#cpd-controls { display: none; }
.app-shell[data-view-group="cpd"] #cpd-controls { display: block; }
#cpd-controls h1 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 var(--s-3);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* ── Topbar rank bracket ───────────────────────────────────────────────── */
.topbar-rank {
  display: flex; align-items: center; gap: 6px;
  margin: 0;
}
.topbar-rank .field-label {
  color: var(--text-dim);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.topbar-rank .rank-trigger { padding: 4px 8px; font-size: 12px; }

/* ── Welcome champion search ───────────────────────────────────────────── */
.welcome-wrap {
  min-height: calc(100vh - var(--topbar-h) - 80px);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
}
.welcome-title {
  margin: 0 0 56px;
  font-size: 84px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--text);
  text-align: center;
  line-height: 1.05;
}
.welcome-search-wrap {
  display: flex; justify-content: center;
  width: 100%; max-width: 560px;
  margin: 0 auto;
  position: relative;
}

.welcome-champ-suggest {
  position: absolute;
  top: calc(100% + 6px);
  left: 0; right: 0;
  margin: 0; padding: 4px 0;
  list-style: none;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: 12px;
  max-height: 320px;
  overflow-y: auto;
  z-index: 50;
  box-shadow: 0 10px 24px rgba(0,0,0,0.35);
  text-align: left;
}
.welcome-champ-suggest li {
  padding: 8px 14px;
  font-size: 14px;
  color: var(--text);
  cursor: pointer;
}
.welcome-champ-suggest li:hover,
.welcome-champ-suggest li.active {
  background: var(--surface-3, rgba(255,255,255,0.06));
}
.welcome-champ-suggest .empty {
  color: var(--text-muted);
  cursor: default;
}
.under-construction a {
  color: var(--accent, #f1c84b);
  text-decoration: underline;
}

/* ── Under-construction placeholder ────────────────────────────────────── */
.under-construction {
  min-height: calc(100vh - var(--topbar-h) - 80px);
  display: flex; flex-direction: column;
  align-items: center; justify-content: center;
  text-align: center;
  color: var(--text-muted);
}
.under-construction h2 {
  color: var(--text);
  margin: 0 0 8px;
  font-size: 22px;
}
.under-construction p {
  margin: 0;
  font-size: 14px;
  letter-spacing: 0.02em;
}
.welcome-champ-search {
  width: 100%;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: 999px;
  padding: 10px 16px;
  font-size: 14px;
  color: var(--text);
  outline: none;
  transition: border-color var(--dur-fast), box-shadow var(--dur-fast);
}
.welcome-champ-search:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(61,217,164,0.15);
}
.welcome-champ-search::placeholder { color: var(--text-dim); }

#sidebar h1 {
  font-size: 13px;
  font-weight: 600;
  margin: 0 0 var(--s-4);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

/* Collapsed-sidebar: slide the sidebar fully off-screen. We keep the
   sidebar in the DOM (and don't toggle display) so its inline form-control
   state survives across collapse/expand cycles. */
.app-shell[data-sidebar="collapsed"] #sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0; bottom: 0;
  width: min(var(--sidebar-w), 86vw);
  z-index: 60;
  transform: translateX(-100%);
  transition: transform var(--dur) var(--ease);
  box-shadow: var(--shadow-md);
}

#sidebar .field { margin-bottom: var(--s-4); color: var(--text); }
#sidebar .field-label {
  display: block;
  margin-bottom: var(--s-2);
  font-size: var(--fs-xs);
  font-weight: 600;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
#sidebar label {
  display: block;
  margin-bottom: var(--s-4);
  color: var(--text);
  font-size: var(--fs-body);
}

/* Slider value-pill convention: <span> right after the slider label.
   For sliders, the pill is upgraded to a floating bubble that tracks the
   thumb (positioned via inline `left` set in main.js). */
#sidebar label > span:not(.hint):not(.info-tip) {
  display: inline-block;
  margin-left: var(--s-1);
  padding: 1px 8px;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-pill);
  font-family: var(--font-num);
  font-variant-numeric: tabular-nums;
  font-size: var(--fs-xs);
  color: var(--text);
}
/* Slider rows: label-text on row 1, floating value bubble above the
   thumb, slider on row 2, hint below. */
#sidebar label:has(> input[type="range"]) { position: relative; }
#sidebar label:has(> input[type="range"]) > input[type="range"] {
  margin-top: 28px;
}
#sidebar label > span.slider-bubble {
  position: absolute;
  top: 20px;
  left: 0;
  margin-left: 0;
  transform: translateX(-50%);
  pointer-events: none;
  z-index: 2;
  background: var(--accent-soft, var(--surface-2));
  border-color: var(--accent);
  color: var(--text);
  transition: none;
  white-space: nowrap;
}

#sidebar select,
#sidebar input[type="text"] {
  width: 100%;
  background: var(--surface-1);
  color: var(--text);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  margin-top: var(--s-1);
  font-size: var(--fs-body);
  font-family: inherit;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
#sidebar select:hover,
#sidebar input[type="text"]:hover { border-color: var(--border); }
#sidebar select:focus,
#sidebar input[type="text"]:focus { border-color: var(--accent); background: var(--surface-2); }

/* Custom range slider */
#sidebar input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  margin-top: var(--s-2);
  cursor: pointer;
}
#sidebar input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; background: var(--surface-3);
  border-radius: var(--r-pill);
}
#sidebar input[type="range"]::-moz-range-track {
  height: 4px; background: var(--surface-3);
  border-radius: var(--r-pill);
}
#sidebar input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; margin-top: -5px;
  background: var(--accent);
  border: 2px solid var(--bg);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--accent), 0 2px 6px rgba(0,0,0,0.5);
  transition: transform var(--dur-fast);
}
#sidebar input[type="range"]::-moz-range-thumb {
  width: 14px; height: 14px;
  background: var(--accent);
  border: 2px solid var(--bg);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--accent), 0 2px 6px rgba(0,0,0,0.5);
}
#sidebar input[type="range"]:hover::-webkit-slider-thumb { transform: scale(1.15); }
#sidebar input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 4px var(--accent-ring); }

/* Custom checkbox */
#sidebar .checkbox-label {
  display: flex; flex-wrap: wrap; align-items: center; gap: var(--s-2);
}
#sidebar .checkbox-label input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 16px; height: 16px;
  background: var(--surface-1);
  border: 1px solid var(--border-strong);
  border-radius: 4px;
  cursor: pointer;
  display: grid; place-items: center;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
#sidebar .checkbox-label input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}
#sidebar .checkbox-label input[type="checkbox"]:checked::after {
  content: ""; width: 9px; height: 5px;
  border-left: 2px solid var(--text-on-accent);
  border-bottom: 2px solid var(--text-on-accent);
  transform: rotate(-45deg) translate(0, -1px);
}

#sidebar .hint {
  display: block;
  color: var(--text-dim);
  font-size: var(--fs-xs);
  line-height: 1.45;
  margin-top: var(--s-1);
  margin-left: 0;
  flex-basis: 100%;
}

#sidebar .weights-box {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--s-3);
  margin: var(--s-2) 0 var(--s-4);
}
#sidebar .weights-box legend {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: 0 var(--s-1);
}
#sidebar .weights-box label { font-size: var(--fs-sm); margin-top: var(--s-2); margin-bottom: var(--s-2); }
#sidebar .weights-box .hint { margin: 0 0 var(--s-2) 0; }

/* ── Info tip ──────────────────────────────────────────────────────────
   <span class="info-tip" data-tip="...">?</span>
   Small "(?)" glyph that reveals a themed tooltip on hover/focus.
   Use this in place of long inline explainer paragraphs. */
.info-tip {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 14px; height: 14px;
  margin-left: 4px;
  border-radius: 50%;
  background: var(--surface-2);
  color: var(--text-muted);
  border: 1px solid var(--border);
  font-size: 10px;
  font-weight: 700;
  line-height: 1;
  cursor: help;
  position: relative;
  user-select: none;
  /* `middle` keeps the glyph visually centred against neighbouring text
     of varying heights (slider labels with embedded value spans, checkbox
     rows where the (?) sits next to a checkbox input). `baseline` left
     it floating low against those siblings. */
  vertical-align: middle;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.info-tip:hover,
.info-tip:focus-visible {
  background: var(--accent-soft);
  color: var(--accent);
  border-color: var(--accent-ring);
  outline: none;
}
.info-tip::after {
  /* The floater (see main.js _initInfoTips) handles the actual bubble so
     it can escape clipping containers like the sidebar; we keep nothing
     here. */
  content: none;
}
/* Body-level floater: rendered once, repositioned on hover/focus. */
.tip-floater {
  position: fixed;
  top: 0; left: 0;
  max-width: 280px;
  padding: 8px 10px;
  background: var(--surface-2);
  color: var(--text);
  border: 1px solid var(--border-strong);
  border-radius: var(--r-md);
  font-size: var(--fs-xs);
  line-height: 1.45;
  text-align: left;
  white-space: normal;
  box-shadow: 0 8px 24px rgba(0,0,0,0.5);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--dur-fast);
  z-index: 10000;
}
.tip-floater.visible { opacity: 1; }

/* Buttons */
.btn-sm {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 12px;
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  margin-top: var(--s-2);
  width: 100%;
  transition: background var(--dur-fast), color var(--dur-fast), border-color var(--dur-fast);
}
.btn-sm:hover { background: var(--surface-2); color: var(--text); border-color: var(--border-strong); }
.btn-primary {
  width: 100%;
  background: var(--accent);
  color: var(--text-on-accent);
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  padding: 9px 16px;
  font-size: var(--fs-body);
  font-weight: 700;
  letter-spacing: 0.01em;
  cursor: pointer;
  margin-top: var(--s-2);
  transition: background var(--dur-fast), box-shadow var(--dur-fast), transform var(--dur-fast);
}
.btn-primary:hover { background: var(--accent-strong); box-shadow: var(--shadow-glow); transform: translateY(-1px); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled {
  background: var(--surface-2); border-color: var(--border-subtle);
  color: var(--text-dim); cursor: not-allowed;
  box-shadow: none; transform: none;
}

/* ── Role icon bar (sidebar + coverage sub-tabs) ──────────────────────── */
/* Continuous segmented control: outer track + flush inner segments. */
.role-strip {
  display: flex;
  align-items: stretch;
  gap: 2px;
  padding: 3px;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: 8px;
}
.role-tile {
  flex: 1 1 0;
  min-width: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 4px;
  padding: 7px 0;
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast), box-shadow var(--dur-fast);
}
.role-tile img {
  width: 20px; height: 20px;
  filter: brightness(1.8);
  opacity: 0.6;
  pointer-events: none;
  transition: opacity var(--dur-fast), filter var(--dur-fast);
}
.role-tile:hover { background: var(--surface-2); }
.role-tile:hover img { opacity: 0.95; }
.role-tile.active {
  background: var(--accent-soft);
  box-shadow: inset 0 0 0 1px var(--accent-ring);
}
.role-tile.active img { opacity: 1; filter: brightness(2.2); }

/* Coverage role sub-tabs + meta role tabs share the same compact
   segmented look so the bar is identical across Matchup, Synergy, and
   Playrate by Rank views. */
#role-tabs.role-strip,
.meta-role-tabs.role-strip {
  gap: 4px;
  padding: 3px;
  min-width: 0;
  width: max-content;
  max-width: 100%;
  /* #role-tabs also carries .tabs-sub which sets border-radius:pill;
     re-assert the squared 8px container here so coverage matches meta. */
  border-radius: 8px;
}
#role-tabs .role-tile,
.meta-role-tabs .role-tile {
  padding: 5px 10px;
}
#role-tabs .role-tile img,
.meta-role-tabs .role-tile img { width: 16px; height: 16px; }

/* ── Rank list (sidebar) ──────────────────────────────────────────────── */
.rank-list {
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  overflow: hidden;
}
.rank-row {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  padding: 7px 10px;
  background: transparent;
  border: none;
  border-left: 3px solid transparent;
  color: var(--text);
  font-size: var(--fs-body);
  text-align: left;
  cursor: pointer;
  transition: background var(--dur-fast);
  font-family: inherit;
}
.rank-row + .rank-row { border-top: 1px solid var(--border-subtle); }
.rank-row img {
  width: 22px; height: 22px;
  object-fit: contain;
  flex-shrink: 0;
}
.rank-row .rank-name { flex: 1; font-weight: 500; }
.rank-row:hover { background: var(--surface-2); }
.rank-row.active {
  background: var(--surface-3);
  border-left-color: var(--accent);
  color: var(--text);
}
.rank-row[disabled] { opacity: 0.35; cursor: not-allowed; }

/* ── Rank dropdown (custom select with crests) ────────────────────────── */
.rank-dropdown { position: relative; margin-top: var(--s-1); }
.rank-trigger {
  display: flex;
  align-items: center;
  gap: var(--s-3);
  width: 100%;
  padding: 7px 10px;
  background: var(--surface-1);
  color: var(--text);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  font-size: var(--fs-body);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.rank-trigger:hover { border-color: var(--border); }
.rank-trigger:focus-visible,
.rank-dropdown.open .rank-trigger {
  outline: none;
  border-color: var(--accent);
  background: var(--surface-2);
}
.rank-trigger-icon {
  width: 22px; height: 22px;
  object-fit: contain;
  flex-shrink: 0;
}
.rank-trigger-icon[src=""] { visibility: hidden; }
.rank-trigger-label { flex: 1; font-weight: 500; }
.rank-trigger-caret {
  color: var(--text-muted, var(--text));
  font-size: 12px;
  transition: transform var(--dur-fast);
}
.rank-dropdown.open .rank-trigger-caret { transform: rotate(180deg); }

.rank-menu {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  box-shadow: 0 6px 18px rgba(0,0,0,0.35);
  overflow: hidden;
}
.rank-menu[hidden] { display: none; }
.rank-menu .rank-row { width: 100%; }
.rank-menu .rank-row.active {
  background: var(--surface-3);
  border-left-color: var(--accent);
}

/* ── Pool chip multiselect ────────────────────────────────────────────── */
#pool-input-wrap, .pool-input-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  padding: 4px;
  margin-top: var(--s-1);
  position: relative;
  transition: border-color var(--dur-fast);
}
#pool-input-wrap:focus-within, .pool-input-wrap:focus-within {
  border-color: var(--accent);
}

/* Stacked variant (sidebar Your-pool): chips and add slot render as
   full-width vertical rows instead of pills. */
#pool-input-wrap.pool-stack {
  background: transparent;
  border: none;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.pool-stack #pool-chips {
  display: flex;
  flex-direction: column;
  gap: 4px;
}
.pool-row {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px 4px 4px;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.pool-row:hover { background: var(--surface-2); border-color: var(--border); }
.pool-row img,
.pool-row .champ-icon {
  width: 32px; height: 32px;
  border-radius: 4px;
  flex-shrink: 0;
}
.pool-row-name {
  flex: 1;
  font-size: var(--fs-body);
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.pool-row-x {
  background: transparent;
  border: none;
  color: var(--text-dim);
  font-size: 18px;
  line-height: 1;
  padding: 2px 6px;
  cursor: pointer;
  border-radius: var(--r-sm);
  transition: background var(--dur-fast), color var(--dur-fast);
}
.pool-row-x:hover { background: var(--c-neg); color: var(--text); }

.pool-add-slot {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 4px 6px;
  background: transparent;
  border: 1.5px dashed var(--border);
  border-radius: var(--r-sm);
  min-height: 42px;
  transition: border-color var(--dur-fast), background var(--dur-fast);
  cursor: text;
}
.pool-add-slot:hover,
.pool-add-slot:focus-within {
  border-color: var(--accent);
  border-style: solid;
  background: var(--surface-1);
}
.pool-add-plus {
  width: 32px; height: 32px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  line-height: 1;
  color: var(--text-dim);
  border: 1.5px dashed var(--border);
  border-radius: 4px;
  flex-shrink: 0;
  transition: color var(--dur-fast), border-color var(--dur-fast);
}
.pool-add-slot:hover .pool-add-plus,
.pool-add-slot:focus-within .pool-add-plus {
  color: var(--accent);
  border-color: var(--accent);
  border-style: solid;
}
.pool-stack #pool-search {
  background: transparent !important;
  border: none !important;
  padding: 4px 0 !important;
  flex: 1;
  outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: var(--fs-body);
  min-width: 0;
}

#pool-chips, .pool-chips, #pb-definite-chips, #pb-maybe-chips, #cmp-champ-chip {
  display: flex; flex-wrap: wrap; gap: 4px;
}
#pool-search, #pb-definite-search, #pb-maybe-search, #cmp-champ-search {
  background: transparent !important;
  border: none !important;
  padding: 4px 6px !important;
  flex: 1; min-width: 80px; outline: none;
  color: var(--text);
  font-family: inherit;
  font-size: var(--fs-body);
}
.pool-chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  background: var(--surface-2);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-pill);
  padding: 2px 4px 2px 2px;
  font-size: var(--fs-sm);
  color: var(--text);
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.pool-chip:hover { background: var(--surface-3); border-color: var(--border); }
/* Default champion icon shape (used in tables, heatmap labels, comparer
   tiles, etc.) is a soft-cornered square. Inside pool chips and the
   sidebar role bar the icon is circular to match the rounded chip. */
.champ-icon { border-radius: 3px; }
.pool-chip img,
.pool-chip .champ-icon { width: 20px; height: 20px; border-radius: 50%; }
.pool-chip .x {
  cursor: pointer; color: var(--text-dim);
  padding: 0 4px;
  margin-left: 0;
  border-left: none;
  border-radius: var(--r-pill);
  font-size: 14px; line-height: 1;
  transition: color var(--dur-fast), background var(--dur-fast);
}
.pool-chip .x:hover { background: var(--c-neg); color: var(--text); }

#pool-suggestions, .pool-suggestions {
  position: absolute;
  top: 100%; left: 0; right: 0;
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  margin-top: 4px;
  max-height: 240px;
  overflow-y: auto;
  z-index: 1000;
  display: none;
  box-shadow: var(--shadow-md);
}
#pool-suggestions.open, .pool-suggestions.open { display: block; }
.suggestion {
  display: flex;
  align-items: center;
  gap: var(--s-2);
  padding: 6px 10px;
  cursor: pointer;
  color: var(--text);
  border-left: 2px solid transparent;
  transition: background var(--dur-fast), border-color var(--dur-fast);
}
.suggestion img { width: 20px; height: 20px; border-radius: 4px; }
.suggestion:hover, .suggestion.active {
  background: var(--surface-3);
  border-left-color: var(--accent);
}
.suggestion .pr {
  color: var(--text-dim);
  font-size: var(--fs-xs);
  margin-left: auto;
  font-variant-numeric: tabular-nums;
}

/* Status line with live dot */
#status {
  color: var(--text-dim);
  font-size: var(--fs-xs);
  margin-top: var(--s-4);
  min-height: 14px;
  display: flex; align-items: center; gap: var(--s-2);
  font-family: var(--font-num);
}
#status:not(:empty)::before {
  content: ""; width: 6px; height: 6px;
  background: var(--accent);
  border-radius: 50%;
  box-shadow: 0 0 8px var(--accent-ring);
  animation: pulse 1.6s ease-in-out infinite;
  flex-shrink: 0;
}
@keyframes pulse {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.35; }
}

/* ── Main area ────────────────────────────────────────────────────────── */
#main {
  grid-area: main;
  padding: var(--s-5) var(--s-6) var(--s-8);
  overflow-x: auto;
  min-width: 0;
  max-width: 1600px;
  margin: 0 auto;
  width: 100%;
}

/* ── Tabs (segmented pill) ────────────────────────────────────────────── */
.tabs-top, .tabs-sub {
  display: inline-flex;
  flex-wrap: wrap;
  gap: 2px;
  padding: 4px;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-pill);
  margin-bottom: var(--s-5);
  border-bottom: 1px solid var(--border-subtle);
}
.tabs-sub {
  margin-top: 0;
  margin-bottom: var(--s-4);
  padding: 3px;
}
.tab-btn {
  background: transparent;
  color: var(--text-muted);
  border: 1px solid transparent;
  border-radius: var(--r-pill);
  padding: 6px 14px;
  font-size: var(--fs-sm);
  font-weight: 500;
  cursor: pointer;
  transition: background var(--dur-fast), color var(--dur-fast);
  font-family: inherit;
}
.tab-btn:hover { background: var(--surface-2); color: var(--text); }
.tab-btn.active {
  background: var(--accent-soft);
  color: var(--accent-strong);
}
.tabs-sub .tab-btn { font-size: var(--fs-xs); padding: 4px 12px; }

/* ── View transitions ─────────────────────────────────────────────────── */
.view { display: none; }
.view.active {
  display: block;
  animation: viewIn var(--dur) var(--ease);
}
@keyframes viewIn {
  from { opacity: 0; transform: translateY(4px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ── Generic primitives ───────────────────────────────────────────────── */
.section-h {
  color: var(--text);
  font-size: var(--fs-h2);
  font-weight: 700;
  margin: var(--s-6) 0 var(--s-3);
  letter-spacing: -0.01em;
}
.section-h::before {
  content: ""; display: inline-block;
  width: 3px; height: 14px;
  background: var(--accent);
  border-radius: 2px;
  margin-right: var(--s-2);
  vertical-align: -2px;
}

.row-controls {
  display: flex; gap: var(--s-4); flex-wrap: wrap;
  margin-bottom: var(--s-3);
  align-items: flex-end;
}
.row-controls label {
  display: block; min-width: 200px;
  color: var(--text); font-size: var(--fs-body);
}
.row-controls select, .row-controls input[type="text"] {
  background: var(--surface-1);
  color: var(--text);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  padding: 6px 10px;
  margin-top: var(--s-1);
  font-size: var(--fs-body);
  font-family: inherit;
  min-width: 180px;
}
.row-controls select:hover, .row-controls input[type="text"]:hover { border-color: var(--border); }
.row-controls select:focus, .row-controls input[type="text"]:focus { border-color: var(--accent); }
.row-controls .checkbox-label {
  display: flex; align-items: center; gap: var(--s-2);
  font-size: var(--fs-body);
}
.row-controls input[type="range"] {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 22px; background: transparent;
  cursor: pointer; margin-top: var(--s-2);
}
.row-controls input[type="range"]::-webkit-slider-runnable-track {
  height: 4px; background: var(--surface-3); border-radius: var(--r-pill);
}
.row-controls input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 14px; height: 14px; margin-top: -5px;
  background: var(--accent);
  border: 2px solid var(--bg);
  border-radius: 50%;
  box-shadow: 0 0 0 1px var(--accent);
}

/* Card primitive — used by .welcome-tile, .eq-box, .strength-cell etc. */
.card {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-5);
  box-shadow: var(--shadow-sm);
}
.card.is-hoverable {
  transition: transform var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
}
.card.is-hoverable:hover {
  transform: translateY(-2px);
  border-color: var(--border);
  box-shadow: var(--shadow-md);
}

/* Table wrapper — gives every .std-table sticky-header + rounded card frame */
.table-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  overflow: hidden;
  margin-bottom: var(--s-4);
}
.table-wrap > .std-table { margin: 0; }

/* ── Coverage tab: stats banner ───────────────────────────────────────── */
#stats-banner {
  display: flex; flex-wrap: wrap; gap: var(--s-2);
  margin-bottom: var(--s-3);
}
.stat-pill {
  display: inline-flex; align-items: center; gap: var(--s-2);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 14px;
  font-size: var(--fs-sm);
  color: var(--text);
  font-variant-numeric: tabular-nums slashed-zero;
}
.stat-pill.cov         { border-left-color: var(--c-pos); }
.stat-pill.unc         { border-left-color: var(--c-neg); }
.stat-pill.delta-pos   { border-left-color: var(--c-pos); }
.stat-pill.delta-neg   { border-left-color: var(--c-neg); }

/* ── Plotly chart containers ──────────────────────────────────────────── */
#heatmap, #pb-selected-hm, #blind-scatter, #health-redundancy-heatmap {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--s-2);
  margin-bottom: var(--s-3);
}
#health-redundancy-heatmap { margin-top: var(--s-6); }

/* Blindability scatter: clip champion icons to circles and lift the
   hovered icon (scale + glow). JS in views/blind.js raises the hovered
   <image> to the end of its SVG group so it draws on top of neighbors. */
#blind-scatter image {
  /* For SVG <image>, the default clip-path reference box is view-box (the
     full plot area), so `circle(50%)` would be huge and never crop the
     icon. Anchor the clip to the element's own fill-box so it actually
     rounds each champion tile to a circle. */
  clip-path: circle(50% at center) fill-box;
  cursor: pointer;
  transform-box: fill-box;
  transform-origin: center;
  transition: transform var(--dur-base) ease-out,
              filter var(--dur-base) ease-out;
}
#blind-scatter image:hover,
#blind-scatter image.hovered {
  transform: scale(1.8);
  filter: drop-shadow(0 0 8px rgba(61, 217, 164, 0.85));
}

/* Heatmap key */
.hm-key {
  display: flex; flex-wrap: wrap;
  gap: var(--s-4);
  padding: var(--s-2) var(--s-3);
  margin: var(--s-2) 0 var(--s-3);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-sm);
  font-size: var(--fs-xs);
  color: var(--text-muted);
}
.hm-key .key-item { display: inline-flex; align-items: center; gap: 6px; white-space: nowrap; }
.hm-key-swatch {
  display: inline-block; width: 14px; height: 14px; border-radius: 3px;
  border: 1px solid var(--border-subtle); flex: 0 0 14px;
}
.hm-key-swatch.swatch-bold  { background: #6FE2B5; }
.hm-key-swatch.swatch-faint { background: rgba(230,234,242,0.18); }
.hm-key-swatch.swatch-grad  {
  background: linear-gradient(90deg, #E07B4A 0%, #1A2236 50%, #3DD9A4 100%);
  width: 28px; flex: 0 0 28px;
}

/* ── Coverage tab redesign ───────────────────────────────────────────── */
/* Headline answer card: one-sentence summary + filter chips. */
#coverage-headline { margin: var(--s-2) 0 var(--s-3); }
.cov-headline-card {
  display: flex; gap: var(--s-4); align-items: flex-start;
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-left: 4px solid var(--accent);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
}
.cov-headline-main { flex: 1; min-width: 0; }
.cov-headline-big {
  font-size: 18px; line-height: 1.35; color: var(--text);
}
.cov-headline-big strong { color: var(--accent-strong); font-weight: 700; }
.cov-headline-mid {
  margin-top: 6px; font-size: var(--fs-body); color: var(--text-muted);
}
.cov-headline-mid strong { color: var(--text); font-weight: 600; }
.cov-headline-sub { margin-top: 8px; font-size: var(--fs-sm); }
.cov-headline-sub.cov-ok { color: var(--accent-strong); }
.cov-problem-link {
  color: var(--c-neg); text-decoration: none; font-weight: 600;
}
.cov-problem-link:hover { text-decoration: underline; }
.cov-headline-chips {
  display: flex; flex-direction: column; gap: 4px; align-items: flex-end;
  flex: 0 0 auto;
}
.cov-chip {
  font-size: 11px; color: var(--text-muted);
  background: var(--surface-2); border: 1px solid var(--border-subtle);
  border-radius: var(--r-pill); padding: 2px 10px;
  white-space: nowrap;
}

/* Problem matchups list */
#coverage-problems { margin: var(--s-3) 0 var(--s-4); }
.cov-section-h { display: flex; align-items: baseline; gap: 10px; margin: 0 0 var(--s-2); }
.cov-section-sub { font-size: var(--fs-sm); color: var(--text-dim); font-weight: 400; }
.cov-problem-list {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(360px, 100%), 1fr));
  gap: 8px;
}
.cov-problem-row {
  display: flex; align-items: center; gap: var(--s-3);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--c-neg);
  border-radius: var(--r-sm);
  padding: 8px 12px;
}
.cov-problem-row.tone-loss { border-left-color: var(--c-neg); }
.cov-problem-row.tone-even { border-left-color: #c0a050; }
.cov-problem-row.tone-slim { border-left-color: #c0a050; }
.cov-problem-opp { display: flex; align-items: center; gap: 6px; min-width: 120px; }
.cov-problem-opp img { width: 28px; height: 28px; border-radius: 4px; }
.cov-problem-resp { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; font-size: var(--fs-sm); color: var(--text); }
.cov-problem-resp img { width: 22px; height: 22px; border-radius: 4px; }
.cov-problem-label { color: var(--text-dim); }
.cov-problem-verdict { font-weight: 600; }
.cov-problem-verdict.tone-win  { color: var(--c-pos); }
.cov-problem-verdict.tone-slim { color: #e6c978; }
.cov-problem-verdict.tone-even { color: #e6c978; }
.cov-problem-verdict.tone-loss { color: var(--c-neg); }
.cov-problem-pct {
  color: var(--text-dim); font-size: 11px;
  background: var(--surface-2); border-radius: var(--r-pill);
  padding: 1px 8px; border: 1px solid var(--border-subtle);
  cursor: help;
}

/* MVPs / fillers card */
#coverage-mvps { margin-top: var(--s-4); }
.cov-mvp-card {
  display: grid; grid-template-columns: 1fr 1fr; gap: var(--s-4);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
}
.cov-mvp-col { display: flex; flex-direction: column; gap: 8px; min-width: 0; }
.cov-mvp-title {
  font-size: var(--fs-sm); text-transform: uppercase; letter-spacing: 0.06em;
  color: var(--text-muted); font-weight: 600; padding-bottom: 4px;
  border-bottom: 1px solid var(--border-subtle);
}
.cov-mvp-row { display: flex; align-items: center; gap: 10px; }
.cov-mvp-row img { width: 32px; height: 32px; border-radius: 5px; flex: 0 0 32px; }
.cov-mvp-text { display: flex; flex-direction: column; min-width: 0; }
.cov-mvp-text > b { color: var(--text); font-size: var(--fs-body); }
.cov-mvp-sub { color: var(--text-muted); font-size: var(--fs-xs); line-height: 1.3; }
.cov-mvp-row.cov-mvp-filler .cov-mvp-text > b { color: var(--text-muted); }

/* Coverage: uncovered chips */
#uncovered { margin-top: var(--s-4); }
.cov-banner {
  background: var(--accent-soft);
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  padding: 8px 14px;
  font-weight: 600;
  color: var(--accent-strong);
  display: inline-block;
}
.uncov-chip {
  display: inline-flex; align-items: center; gap: 6px;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--c-neg);
  border-radius: var(--r-sm);
  padding: 5px 10px;
  margin: 3px;
  font-size: var(--fs-sm);
  line-height: 1.2;
}
.uncov-chip img { width: 20px; height: 20px; border-radius: 4px; }
.uncov-chip .best { color: var(--text-dim); font-size: 10px; display: block; }
.uncov-header { color: var(--text-muted); font-size: var(--fs-body); margin: 0 0 var(--s-2); }

/* Empty state */
.empty-msg {
  color: var(--text-dim);
  padding: var(--s-8) 0;
  text-align: center;
  font-size: var(--fs-body);
}

/* ── Expand Your Pool tab ─────────────────────────────────────────────── */

/* Weights collapsible (Score weights moved from Pool Health) */
.weights-collapsible {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3);
  margin: 0 0 var(--s-3);
}
.weights-collapsible > summary {
  cursor: pointer;
  color: var(--text-muted);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  padding: var(--s-1) 0;
  user-select: none;
}
.weights-collapsible[open] > summary { margin-bottom: var(--s-2); }
.weights-collapsible .weights-box {
  border: 0;
  padding: 0;
  margin: 0;
  display: grid;
  grid-template-columns: repeat(2, minmax(min(240px, 100%), 1fr));
  gap: var(--s-2) var(--s-4);
}
.weights-collapsible .weights-box label {
  display: flex;
  flex-direction: column;
  font-size: var(--fs-sm);
  gap: 2px;
}
.weights-collapsible .weights-box input[type="range"] { width: 100%; }

/* Top-3 picks cards */
.repl-top-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  gap: var(--s-2);
  margin: 0 0 var(--s-4);
}
.repl-top-card {
  display: grid;
  grid-template-columns: auto auto 1fr;
  align-items: center;
  gap: var(--s-2) var(--s-3);
  text-align: left;
  padding: var(--s-3);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-left: 4px solid var(--border-subtle);
  border-radius: var(--r-md);
  color: inherit;
  cursor: pointer;
  font: inherit;
  transition: transform 80ms, border-color 80ms, background 80ms;
}
.repl-top-card:hover { transform: translateY(-1px); background: var(--surface-2); }
.repl-top-card.tone-win  { border-left-color: var(--c-pos); }
.repl-top-card.tone-slim { border-left-color: var(--accent); }
.repl-top-card.tone-loss { border-left-color: var(--c-neg); }
.repl-top-rank {
  color: var(--text-dim);
  font-weight: 700;
  font-size: var(--fs-sm);
  width: 28px;
  text-align: right;
}
.repl-top-icon img { width: 44px; height: 44px; border-radius: 50%; display: block; }
.repl-top-body { min-width: 0; }
.repl-top-name { font-weight: 700; font-size: var(--fs-body); }
.repl-top-pp {
  margin-top: 2px;
  font-size: var(--fs-body);
  font-weight: 700;
}
.repl-top-card.tone-win  .repl-top-pp { color: var(--c-pos); }
.repl-top-card.tone-slim .repl-top-pp { color: var(--accent-strong); }
.repl-top-card.tone-loss .repl-top-pp { color: var(--c-neg); }
.repl-top-why {
  margin-top: 4px;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  line-height: 1.35;
}

/* Candidates table — pillar pills + overall column */
.repl-table th { white-space: nowrap; }
.repl-table .repl-cand { white-space: nowrap; }
.repl-table .repl-overall {
  text-align: center;
  padding: 4px 10px;
  border-radius: 4px;
  font-size: var(--fs-body);
}
.repl-table .repl-overall.tone-win  { color: var(--c-pos); }
.repl-table .repl-overall.tone-slim { color: var(--accent-strong); }
.repl-table .repl-overall.tone-loss { color: var(--c-neg); }
.repl-table .repl-overall-sub {
  font-size: 10px;
  color: var(--text-dim);
  font-weight: 400;
  margin-top: 1px;
}
.repl-table .repl-pill {
  text-align: center;
  padding: 4px 8px;
  font-weight: 600;
  white-space: nowrap;
}
.repl-table .repl-pill.tone-win     { color: var(--c-pos); }
.repl-table .repl-pill.tone-loss    { color: var(--c-neg); }
.repl-table .repl-pill.tone-neutral { color: var(--text-muted); }
.repl-table .repl-arrow { display: inline-block; margin-right: 4px; font-size: 12px; }
.repl-table .cell-na { color: var(--text-dim); text-align: center; }
.repl-table tr.selected td { background: rgba(111, 226, 181, 0.08); }
.repl-table tbody tr { cursor: pointer; }
.repl-table tbody tr:hover td { background: var(--surface-2); }
.repl-table tbody tr.selected:hover td { background: rgba(111, 226, 181, 0.14); }

/* Equation card */
.eq-box {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-left: 3px solid var(--accent);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-3);
  font-size: var(--fs-body);
  line-height: 1.55;
}
.eq-box .plain {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  margin-top: var(--s-2);
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--s-2);
}

/* ── Tables (.std-table) ──────────────────────────────────────────────── */
.std-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: var(--fs-body);
  font-variant-numeric: tabular-nums slashed-zero;
}
.std-table th {
  color: var(--text-muted);
  text-align: left;
  padding: 9px 12px;
  background: var(--surface-2);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  position: sticky; top: 0; z-index: 2;
}
.std-table td {
  padding: 7px 12px;
  line-height: 1.5;
  border-bottom: 1px solid var(--border-subtle);
}
.std-table tr:last-child td { border-bottom: none; }
.std-table tbody tr {
  transition: background var(--dur-fast);
}
.std-table tbody tr:hover td { background: var(--surface-2); }
.std-table img {
  width: 24px; height: 24px;
  border-radius: 4px;
  vertical-align: middle;
  border: 1px solid var(--border-subtle);
}

.std-table .th-desc {
  display: block;
  color: var(--text-dim);
  font-weight: 400;
  font-size: 10px;
  text-transform: none;
  letter-spacing: 0;
  margin-top: 2px;
}

/* Pool Health → Redundancy table: bigger icon + fonts, slim rank column,
   2px gutter between the champ icon and its neighbours (rank cell & name). */
.redundancy-table { font-size: calc(var(--fs-body) + 1px); }
.redundancy-table th { font-size: calc(var(--fs-xs) + 1px); }
.redundancy-table th.rank-col,
.redundancy-table td.rank-col {
  width: 44px;
  padding-right: 2px;
  text-align: center;
}
.redundancy-table td.rank-col + td { padding-left: 2px; }
.redundancy-table td img.champ-icon {
  width: 28px; height: 28px;
  margin-right: 4px;
}

/* Ban tab legend */
.ban-legend {
  display: flex; flex-wrap: wrap; gap: 6px 18px;
  margin: var(--s-2) 0 var(--s-1);
  color: var(--text-muted);
  font-size: var(--fs-sm);
  line-height: 1.5;
}
.ban-legend b { color: var(--text); font-weight: 600; }

/* Numeric color cells (correlation, blind z, ban score) */
.cell-pos, .cell-neg, .cell-na {
  text-align: center; color: var(--text); font-weight: 700;
  border-radius: var(--r-sm); padding: 5px 10px;
  font-variant-numeric: tabular-nums;
}
.cell-na { color: var(--text-dim); background: transparent; font-weight: 400; }

/* ── Ban Recommender ──────────────────────────────────────────────────── */
#ban-tables-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(260px, 100%), 1fr));
  gap: var(--s-3);
  margin-top: var(--s-3);
}
.ban-table-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-3);
  max-height: 600px;
  overflow-y: auto;
  transition: border-color var(--dur-fast), transform var(--dur-fast);
}
.ban-table-wrap:hover { border-color: var(--border); }
.ban-table-wrap h4 {
  margin: 0 0 var(--s-2);
  color: var(--text);
  font-size: var(--fs-body);
  font-weight: 600;
  letter-spacing: -0.005em;
}
.ban-table { width: 100%; border-collapse: collapse; font-size: var(--fs-sm); font-variant-numeric: tabular-nums; }
.ban-table th {
  color: var(--text-muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  text-align: left;
  padding: 4px 6px;
  border-bottom: 1px solid var(--border-subtle);
  font-weight: 600;
}
.ban-table td {
  padding: 5px 6px;
  border-bottom: 1px solid var(--border-subtle);
  vertical-align: middle;
}
.ban-table tr:hover td { background: var(--surface-2); }
.ban-table img { width: 28px; height: 28px; border-radius: 4px; vertical-align: middle; border: 1px solid var(--border-subtle); }

.ban-top-card {
  background: linear-gradient(135deg, var(--accent-soft), transparent 70%), var(--surface-1);
  border: 1px solid var(--accent);
  border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-5);
  margin-top: var(--s-3);
  display: flex; align-items: center; gap: var(--s-4);
  box-shadow: var(--shadow-glow);
}
.ban-top-card img {
  width: 48px; height: 48px;
  border-radius: var(--r-sm);
  border: 1px solid var(--border);
}
.ban-top-card .label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 600;
}
.ban-top-card .name {
  font-size: 20px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.01em;
  line-height: 1.1;
}
.ban-top-card .meta { font-size: var(--fs-sm); color: var(--text-muted); margin-top: var(--s-1); }

/* ── Pool Builder ─────────────────────────────────────────────────────── */
.builder-grid { display: block; margin-top: var(--s-2); }
.builder-controls {
  display: flex; flex-wrap: wrap; gap: var(--s-3); align-items: flex-end;
  margin-bottom: var(--s-3);
  padding: var(--s-3) var(--s-4);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
}
.builder-controls > label {
  flex: 1 1 280px;
  display: block; margin-bottom: 0;
  color: var(--text); font-size: var(--fs-body);
}
.builder-controls > label.compact-label { flex: 0 0 180px; }
#pb-combo-count {
  padding: 7px 14px;
  border-radius: var(--r-pill);
  background: var(--accent-soft);
  border: 1px solid transparent;
  color: var(--accent-strong);
  font-size: var(--fs-sm);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  flex: 1 1 200px;
  align-self: center;
}
#pb-combo-count.over {
  background: rgba(224, 123, 74, 0.16);
  color: var(--c-neg);
}
#pb-build { flex: 0 0 140px; margin-top: 0; }

/* ── Replacement Finder ───────────────────────────────────────────────── */
#repl-locked-wrap {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  margin: var(--s-2) 0;
}
#repl-locked-wrap label.lock-item {
  display: inline-flex; align-items: center; gap: var(--s-1);
  margin-right: var(--s-4);
  color: var(--text); font-size: var(--fs-sm);
}
#repl-locked-wrap label.lock-item input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 14px; height: 14px;
  background: var(--surface-2);
  border: 1px solid var(--border-strong);
  border-radius: 3px;
  cursor: pointer;
  display: grid; place-items: center;
}
#repl-locked-wrap label.lock-item input[type="checkbox"]:checked {
  background: var(--accent); border-color: var(--accent);
}
#repl-locked-wrap label.lock-item input[type="checkbox"]:checked::after {
  content: ""; width: 7px; height: 4px;
  border-left: 2px solid var(--text-on-accent);
  border-bottom: 2px solid var(--text-on-accent);
  transform: rotate(-45deg) translate(0, -1px);
}
#repl-locked-wrap img { width: 20px; height: 20px; border-radius: 4px; }
#repl-summary { margin: var(--s-3) 0; }

/* ── Welcome / landing tab ────────────────────────────────────────────── */
.welcome-wrap {
  /* Fill the main column. #main already enforces a 1600px max-width and
     centers itself, so further centering here would create a visible left
     margin whenever the sidebar is collapsed and #main expands to fill
     the viewport. */
  max-width: 100%;
  margin: 0;
  padding: var(--s-2) 0 var(--s-6);
  position: relative;
}
.welcome-wrap::before {
  content: "";
  position: absolute;
  inset: -20px -40px auto -40px;
  height: 240px;
  background: radial-gradient(ellipse 600px 200px at 50% 0,
              rgba(61,217,164,0.10), transparent 70%);
  pointer-events: none;
  z-index: -1;
}
.welcome-title {
  color: var(--text);
  margin: 0 0 var(--s-2);
  font-size: 32px;
  font-weight: 800;
  letter-spacing: -0.02em;
  line-height: 1.1;
}
.welcome-lead {
  color: var(--text-muted);
  margin: 0 0 var(--s-3);
  font-size: 15px;
  line-height: 1.5;
}
.welcome-links {
  color: var(--text-dim);
  font-size: var(--fs-sm);
  margin: 0 0 var(--s-6);
  display: flex; align-items: center; flex-wrap: wrap; gap: var(--s-2);
}
.welcome-links a {
  color: var(--accent-strong);
  padding: 4px 10px;
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-pill);
  font-size: var(--fs-sm);
  transition: border-color var(--dur-fast), background var(--dur-fast);
}
.welcome-links a:hover { background: var(--surface-2); border-color: var(--accent); text-decoration: none; }
.welcome-links .sep { display: none; }

.welcome-group { margin: var(--s-6) 0; }
.welcome-group h3 {
  color: var(--text-muted);
  font-size: var(--fs-xs);
  text-transform: uppercase;
  letter-spacing: 0.1em;
  margin: 0 0 var(--s-3);
  font-weight: 700;
  display: flex; align-items: center; gap: var(--s-2);
}
.welcome-group h3::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--border-subtle);
}

.welcome-tiles {
  display: grid; gap: var(--s-3);
  /* min(N, 100%) lets the column shrink below N on viewports narrower than
     N + container padding, instead of forcing horizontal overflow. */
  grid-template-columns: repeat(auto-fit, minmax(min(320px, 100%), 1fr));
}
.welcome-tile {
  display: flex; flex-direction: column; align-items: flex-start; gap: var(--s-1);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--s-4) var(--s-5);
  color: var(--text); cursor: pointer; text-align: left;
  position: relative;
  overflow: hidden;
  transition: transform var(--dur) var(--ease),
              border-color var(--dur) var(--ease),
              box-shadow var(--dur) var(--ease);
  font-family: inherit;
}
.welcome-tile::after {
  content: "→";
  position: absolute;
  right: var(--s-4); top: var(--s-4);
  color: var(--text-dim);
  font-size: 18px;
  transform: translateX(-4px);
  opacity: 0;
  transition: transform var(--dur) var(--ease), opacity var(--dur) var(--ease), color var(--dur) var(--ease);
}
.welcome-tile:hover {
  background: var(--surface-1);
  border-color: var(--accent);
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}
.welcome-tile:hover::after { transform: translateX(0); opacity: 1; color: var(--accent); }
.welcome-tile .wt-title {
  font-weight: 700;
  font-size: 15px;
  color: var(--text);
  letter-spacing: -0.01em;
  padding-right: var(--s-6);
}
.welcome-tile .wt-desc {
  font-size: var(--fs-sm);
  color: var(--text-muted);
  line-height: 1.55;
}

/* Patch notes */
.welcome-group.patch-notes {
  margin-top: var(--s-8);
  border-top: 1px solid var(--border-subtle);
  padding-top: var(--s-5);
}
.patch-notes-list { list-style: none; padding: 0; margin: 0; }
.patch-notes-list li {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4);
  margin-bottom: var(--s-2);
}
.patch-notes-list li strong { color: var(--c-matchup); font-weight: 700; font-size: var(--fs-body); }
.patch-notes-date {
  display: inline-block;
  color: var(--text-dim);
  font-size: var(--fs-xs);
  margin-left: var(--s-2);
  font-variant-numeric: tabular-nums;
}
.patch-notes-desc {
  display: block;
  color: var(--text-muted);
  font-size: var(--fs-sm);
  line-height: 1.55;
  margin-top: var(--s-1);
}
.patch-notes-desc em { color: var(--text); font-style: normal; font-weight: 600; }

/* ── Playrate by Rank tab ─────────────────────────────────────────────── */
#meta-charts {
  display: flex; flex-direction: column; gap: var(--s-3);
  max-width: 1400px;
}
.meta-controls-row {
  display: flex; align-items: center; justify-content: space-between;
  gap: var(--s-4); flex-wrap: wrap;
}
.meta-show-all-label {
  color: var(--text-muted); font-size: var(--fs-sm);
  cursor: pointer; display: flex; align-items: center; gap: var(--s-1);
}
.meta-show-all-label input { cursor: pointer; accent-color: var(--accent); }

.meta-panel-large {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
  padding: var(--s-2);
}
.meta-svg-large { display: block; width: 100%; height: auto; }

.meta-svg-large path.ribbon { opacity: 0.22; transition: opacity var(--dur-fast); }
.meta-svg-large path.ribbon:not(.meta-dim) { opacity: 0.55; }
.meta-svg-large g.seg.meta-dim rect { opacity: 0.18; transition: opacity var(--dur-fast); }
.meta-svg-large g.seg.meta-dim image { opacity: 0.18; transition: opacity var(--dur-fast); }
.meta-svg-large path.ribbon.meta-dim { opacity: 0.04; }
.meta-svg-large g.seg:not(.meta-dim) rect { stroke: var(--text); stroke-width: 0.7; }
.meta-svg-large g.seg { cursor: default; }
.meta-svg-large g.leader path { transition: opacity var(--dur-fast); }
.meta-svg-large g.leader.meta-dim path { opacity: 0.1; }
.meta-svg-large g.leader.meta-dim image { opacity: 0.25; }
.meta-svg-large g.leader.meta-dim rect { opacity: 0.25; }

.meta-champ-grid-wrap { padding: var(--s-1) 0 var(--s-2); }
.meta-champ-grid-label {
  color: var(--text-muted);
  font-size: var(--fs-sm);
  margin-bottom: var(--s-2);
  display: flex; align-items: center; gap: var(--s-3);
}
.meta-champ-clear, .meta-champ-resync {
  padding: 4px 12px;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  cursor: pointer;
  border-radius: var(--r-pill);
  font-size: var(--fs-xs);
  font-family: inherit;
  transition: background var(--dur-fast), color var(--dur-fast);
}
.meta-champ-clear:hover, .meta-champ-resync:hover {
  color: var(--text); background: var(--surface-2);
}
.meta-champ-grid {
  display: flex; flex-wrap: wrap; gap: 4px; padding: var(--s-2);
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-md);
}
.meta-champ-tile {
  width: 32px; height: 32px;
  border-radius: var(--r-sm);
  border: 2px solid transparent;
  cursor: pointer;
  opacity: 0.4;
  transition: opacity var(--dur-fast), border-color var(--dur-fast), transform var(--dur-fast);
  flex-shrink: 0; overflow: hidden;
}
.meta-champ-tile.selected { opacity: 1; border-color: var(--accent); }
.meta-champ-tile:hover { opacity: 0.85; transform: translateY(-1px); }
.meta-champ-tile.selected:hover { opacity: 1; }
.meta-champ-tile img { width: 100%; height: 100%; display: block; }

/* Hover tooltip */
.meta-tooltip {
  position: fixed; pointer-events: none; z-index: 200; display: none;
  align-items: center; gap: var(--s-2);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-2) var(--s-3);
  font-size: var(--fs-sm);
  box-shadow: var(--shadow-md);
  color: var(--text);
}
.meta-tooltip img { width: 32px; height: 32px; border-radius: var(--r-sm); flex-shrink: 0; }
.meta-tooltip .name { color: var(--text); font-weight: 700; font-size: var(--fs-body); }
.meta-tooltip .meta { color: var(--text-muted); font-size: var(--fs-xs); margin-top: 2px; }

/* ── Selected / in-pool row treatments ───────────────────────────────── */
tr.selected td {
  box-shadow: inset 0 1px 0 var(--accent-bar), inset 0 -1px 0 var(--accent-bar);
}
tr.selected td:first-child {
  box-shadow: inset 4px 0 0 var(--accent),
              inset 0 1px 0 var(--accent-bar),
              inset 0 -1px 0 var(--accent-bar);
}
tr.in-pool-row td { background: var(--accent-soft); }
.std-table tr[data-cand] { cursor: pointer; }
.std-table tr[data-cand]:hover td {
  box-shadow: inset 0 0 0 1px var(--accent-ring);
}

/* Compact table */
.std-table.compact-table {
  width: auto;
  border-spacing: 0;
}
.std-table.compact-table th,
.std-table.compact-table td {
  padding: 5px 10px;
  font-size: var(--fs-sm);
  white-space: nowrap;
}
.std-table.compact-table th { font-size: 10px; }

/* Horizontal scroll for big plots/tables */
#pb-result-table, #pb-selected-hm,
#repl-table, #repl-new-pool-hm,
#heatmap, #health-redundancy-heatmap {
  overflow-x: auto;
  max-width: 100%;
}

/* ── Pool strength summary (top of Pool Health tab) ───────────────────── */
.strength-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(min(220px, 100%), 1fr));
  gap: var(--s-3);
  margin: var(--s-2) 0 var(--s-5);
}
.strength-cell {
  background: var(--surface-1);
  border: 1px solid var(--border-subtle);
  border-radius: var(--r-lg);
  padding: var(--s-4);
  display: flex;
  flex-direction: column;
  gap: var(--s-1);
  transition: border-color var(--dur-fast), transform var(--dur-fast);
}
.strength-cell:hover {
  border-color: var(--border);
  transform: translateY(-1px);
}
.strength-label {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 600;
}
.strength-tier  {
  font-size: 28px;
  font-weight: 800;
  line-height: 1.1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}
.strength-plot  { height: 110px; }
.strength-meta  {
  font-size: var(--fs-xs);
  color: var(--text-muted);
  margin-top: var(--s-1);
  font-variant-numeric: tabular-nums;
}
.strength-meta b { color: var(--text); }

/* ── Skeleton loader ──────────────────────────────────────────────────── */
.skeleton {
  background: linear-gradient(90deg,
              var(--surface-1) 0%,
              var(--surface-2) 50%,
              var(--surface-1) 100%);
  background-size: 200% 100%;
  animation: shimmer 1.2s linear infinite;
  border-radius: var(--r-sm);
  min-height: 16px;
}
@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

/* ── Responsive ───────────────────────────────────────────────────────── */
@media (max-width: 1100px) {
  #main { padding: var(--s-4) var(--s-4) var(--s-6); }
}
/* Mobile-overlay layout kicks in for narrow viewports OR for any touch
   device up through 1200px. Touch devices include phones-in-landscape,
   tablets, and 2-in-1s where the CSS viewport may report 1024+ but the
   physical screen is small. */
@media (max-width: 1100px), (pointer: coarse) and (max-width: 1200px) {
  .app-shell,
  .app-shell[data-sidebar="expanded"],
  .app-shell[data-sidebar="collapsed"] {
    grid-template-columns: 1fr;
    grid-template-areas: "topbar" "main";
  }
  #sidebar {
    position: fixed;
    top: var(--topbar-h);
    left: 0; bottom: 0;
    width: min(var(--sidebar-w), 86vw);
    z-index: 60;
    transform: translateX(-100%);
    transition: transform var(--dur) var(--ease);
    box-shadow: var(--shadow-md);
  }
  .app-shell[data-sidebar="expanded"] #sidebar { transform: translateX(0); }
  .app-shell[data-sidebar="expanded"]::after {
    content: "";
    position: fixed;
    inset: var(--topbar-h) 0 0 0;
    background: var(--overlay);
    z-index: 55;
  }
  #main {
    padding: var(--s-3) var(--s-3) var(--s-5);
    min-width: 0;
    max-width: 100vw;
    overflow-x: hidden;
    box-sizing: border-box;
  }
  .tabs-top { width: 100%; overflow-x: auto; }
  .topbar-brand .brand-name .brand-sub { display: none; }
  .welcome-title { font-size: 26px; }
  /* Topbar fits in 56px height with no wrap. On narrow viewports the brand,
     divider, view-crumb and full author-link row don't fit — progressively
     hide non-essentials so the hamburger + brand remain. */
  .topbar-divider { display: none; }
  #topbar-title { display: none; }
  .topbar-links { font-size: var(--fs-xs); gap: var(--s-2); }
  .topbar-links a { padding: 4px 6px; }
  .topbar-links .sep { display: none; }
  /* Sidebar form controls were sized for a fixed 280px column; on the
     mobile overlay they're fine, but shrink min-widths so nothing forces
     horizontal overflow if any of them escape into #main. */
  .row-controls label,
  .row-controls select,
  .row-controls input[type="text"] { min-width: 0; }
  /* Plotly charts: make them obey their container width. */
  #heatmap, #blind-scatter, #health-redundancy-heatmap,
  #heatmap .plot-container, #blind-scatter .plot-container { max-width: 100%; }
  /* Welcome tile grids stay single-column. */
  .welcome-tile-row { grid-template-columns: 1fr !important; }
}
@media (max-width: 700px) {
  /* Tighter spacing on small phones. */
  #main { padding: var(--s-2) var(--s-3) var(--s-5); }
  .welcome-title { font-size: 22px; }
  /* Below 700px we drop the author-links from the topbar entirely — they
     are duplicated inside the welcome page "chip" links so nothing is lost. */
  .topbar-links { display: none; }
  /* And shrink the brand to just its mark; full "Pool Designer" wordmark
     is still discoverable via the hamburger/sidebar. */
  .topbar-brand .brand-name { display: none; }
  /* Tabs row: smaller padding so 2 tab buttons fit per row at 375px. */
  .tabs-top button, .tabs-top .pill { padding: 6px 10px; font-size: var(--fs-sm); }
}

/* ── Motion preferences ───────────────────────────────────────────────── */
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}

/* ── Print ────────────────────────────────────────────────────────────── */
@media print {
  #sidebar, #topbar { display: none !important; }
  .app-shell { display: block; }
  #main { padding: 0; max-width: none; }
  body { background: white; color: black; }
}

/* -- Pool Health tab ---------------------------------------------------- */
.health-headline {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: var(--s-4);
  margin: 0 0 var(--s-6);
}
.health-stat {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-4) var(--s-5);
  box-shadow: var(--shadow-sm);
}
.health-stat-label { font-size: var(--fs-sm); font-weight: 600; letter-spacing: .03em; text-transform: uppercase; }
.health-stat-value { font-size: 32px; font-weight: 700; color: var(--text); margin: 4px 0 2px; line-height: 1; }
.health-stat-value .pct { font-size: 18px; color: var(--text-dim); font-weight: 600; margin-left: 2px; }
.health-stat-sub { font-size: var(--fs-sm); color: var(--text-dim); }
.health-stat-sub .muted { color: var(--text-muted); }

.health-cov-cell { display: flex; align-items: center; gap: 10px; min-width: 160px; }
.health-cov-bar {
  flex: 1; height: 8px; background: var(--surface-3);
  border-radius: 4px; overflow: hidden; min-width: 60px;
}
.health-cov-bar > div { height: 100%; border-radius: 4px; transition: width .25s ease; }
.health-cov-text { font-size: var(--fs-sm); white-space: nowrap; }
.health-cov-text .muted { color: var(--text-muted); margin-left: 4px; }

.th-desc { display: block; font-weight: 400; font-size: 10px; color: var(--text-muted); margin-top: 2px; }
.cell-na { text-align: center; color: var(--text-muted); }

.redundancy-table td { vertical-align: middle; }

/* -- Build From Scratch tab --------------------------------------------- */
.builder-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: var(--s-5);
  margin: var(--s-4) 0;
}
@media (max-width: 900px) { .builder-grid { grid-template-columns: 1fr; } }
.builder-col {
  background: var(--surface-1);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: var(--s-3) var(--s-4) var(--s-4);
}
.builder-col .section-h { margin-top: 0; }
.pb-pool-stack {
  position: relative;
  display: flex; flex-direction: column; gap: var(--s-2);
}
.pb-pool-stack .pool-add-slot { position: relative; }
.pb-pool-stack input[type='text'] {
  width: 100%; padding: 6px 10px; border-radius: var(--r-sm);
  background: var(--surface-0); color: var(--text);
  border: 1px solid var(--border);
}
.pb-pool-stack input[type='text']:focus {
  outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft, rgba(111,226,181,0.15));
}

.builder-controls {
  display: flex; flex-wrap: wrap; gap: var(--s-4);
  align-items: center; padding: var(--s-3) 0 var(--s-5);
}
.builder-target { display: flex; flex-direction: column; gap: 4px; min-width: 200px; }
.builder-target input[type='range'] { width: 200px; }

.pb-combo-count {
  flex: 1;
  padding: 6px 12px;
  border-radius: var(--r-sm);
  background: var(--surface-2);
  color: var(--text-dim);
  font-size: var(--fs-sm);
  border: 1px solid var(--border);
}
.pb-combo-count.ok { color: var(--text); border-color: var(--accent-soft, transparent); }
.pb-combo-count.warn,
.pb-combo-count.over { color: #e69458; border-color: rgba(217,122,74,0.4); background: rgba(217,122,74,0.08); }
.pb-combo-count b { color: var(--text); }

.pb-pool-icon { width: 18px; height: 18px; border-radius: 2px; vertical-align: middle; margin: 0 1px; }
.pb-pool-cell { line-height: 1.0; white-space: nowrap; }

.pb-selected-row {
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
  padding: var(--s-3) var(--s-4); margin-top: var(--s-3);
  background: var(--surface-1); border: 1px solid var(--border);
  border-radius: var(--r-md); font-size: var(--fs-body);
}
.pb-selected-label { font-weight: 600; color: var(--text); margin-right: 6px; }
.pb-sep { color: var(--text-muted); margin: 0 4px; }

.pb-preview-head {
  display: flex; align-items: baseline; gap: var(--s-4);
  margin-top: var(--s-5);
}
.pb-view-label {
  font-size: var(--fs-sm); color: var(--text-dim);
  display: flex; align-items: center; gap: 6px;
}

#pb-result-table tr.selected td {
  background: var(--accent-soft, rgba(111,226,181,0.12)) !important;
  box-shadow: inset 3px 0 0 var(--accent);
}
