/*
 * Theme axes, keyed off <html data-*> set by theme.js:
 *   data-design  stock | cyber | glass | editorial
 *   data-layout  stock | sidebar | command | split
 *   data-size    default | compact | comfortable | large
 *   data-face    default | mono | sans | serif | rounded
 *   data-case    default | upper | sentence | smallcaps
 * Order matters: text overrides come after designs so they win ties.
 */

:root {
  --stack-rounded: ui-rounded, "SF Pro Rounded", "Nunito", "Varela Round",
    "Quicksand", var(--stack-sans);
  --shadow: rgba(0, 0, 0, 0.55);
  --float-bottom: calc(var(--nav-h) + 14px + env(safe-area-inset-bottom));
  --dock-bottom: calc(var(--nav-h) + 8px + env(safe-area-inset-bottom));
}

/* =====================  DESIGN 1 · CYBER / TERMINAL  ===================== */

html[data-design="cyber"] {
  --r-xs: 0;
  --r-sm: 0;
  --r-md: 0;
  --r-lg: 0;
  --r-pill: 0;
  --r-bar: 0;
  --sans: var(--stack-mono);
  --label: var(--stack-mono);
  --display: var(--stack-mono);
  --glow: 0 0 0 1px color-mix(in srgb, var(--accent) 55%, transparent),
    0 0 16px -3px color-mix(in srgb, var(--accent) 60%, transparent);
}
html[data-design="cyber"] body::before {
  background-size: 100% 100%, 22px 22px, 22px 22px;
}
html[data-design="cyber"] body::after {
  content: "";
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 60;
  background: repeating-linear-gradient(
    180deg,
    color-mix(in srgb, var(--ink) 3.5%, transparent) 0 1px,
    transparent 1px 3px
  );
}
html[data-design="cyber"] :is(.panel, .run, .recent, .tick, .picker, .stat) {
  --c: color-mix(in srgb, var(--accent) 85%, transparent);
  background:
    linear-gradient(var(--c), var(--c)) top left / 9px 1px,
    linear-gradient(var(--c), var(--c)) top left / 1px 9px,
    linear-gradient(var(--c), var(--c)) top right / 9px 1px,
    linear-gradient(var(--c), var(--c)) top right / 1px 9px,
    linear-gradient(var(--c), var(--c)) bottom left / 9px 1px,
    linear-gradient(var(--c), var(--c)) bottom left / 1px 9px,
    linear-gradient(var(--c), var(--c)) bottom right / 9px 1px,
    linear-gradient(var(--c), var(--c)) bottom right / 1px 9px,
    color-mix(in srgb, var(--panel) 94%, transparent);
  background-repeat: no-repeat;
  border: 1px solid var(--line);
  box-shadow: inset 0 0 0 2px var(--bg), inset 0 0 0 3px var(--line-soft);
}
html[data-design="cyber"] .run { border-left: 2px solid var(--accent); }
html[data-design="cyber"] .panel-title { color: var(--accent); }
html[data-design="cyber"] .panel-title::before { content: ">"; color: var(--accent); }
html[data-design="cyber"] .panel-num {
  background: var(--accent);
  border-color: var(--accent);
  color: var(--accent-ink);
}
html[data-design="cyber"] .hero-value {
  color: var(--accent);
  text-shadow: 0 0 20px color-mix(in srgb, var(--accent) 45%, transparent);
}
html[data-design="cyber"] .hero-value::after {
  content: "_";
  margin-left: 0.08em;
  animation: caret 1.1s steps(1) infinite;
}
@keyframes caret { 50% { opacity: 0; } }
html[data-design="cyber"] .bar i,
html[data-design="cyber"] .tick-bar i,
html[data-design="cyber"] .family-progress i {
  box-shadow: 0 0 10px color-mix(in srgb, var(--accent) 70%, transparent);
}
html[data-design="cyber"] .btn:hover:not(:disabled),
html[data-design="cyber"] :is(.fac-card, .tier-card).buyable,
html[data-design="cyber"] .chip[aria-pressed="true"] {
  box-shadow: var(--glow);
}
html[data-design="cyber"] .btn:hover:not(:disabled) {
  background: var(--accent);
  color: var(--accent-ink);
}
html[data-design="cyber"] .row { border-top-style: dotted; }
html[data-design="cyber"] :is(.tab, .rail-item, .mitem)[aria-current="page"],
html[data-design="cyber"] .tab[aria-pressed="true"] {
  color: var(--accent);
  text-shadow: 0 0 10px color-mix(in srgb, var(--accent) 60%, transparent);
}
html[data-design="cyber"] .card { border-color: var(--line); }
html[data-design="cyber"] .avatar { box-shadow: var(--glow); }

/* ==================  DESIGN 2 · GLASS / NEUMORPHIC  ================== */

html[data-design="glass"] {
  --r-xs: 8px;
  --r-sm: 14px;
  --r-md: 18px;
  --r-lg: 22px;
  --r-bar: 999px;
  --sans: var(--stack-sans);
  --label: var(--stack-sans);
  --display: var(--stack-sans);
  --glass: color-mix(in srgb, var(--panel) 55%, transparent);
  --glass-strong: color-mix(in srgb, var(--panel) 78%, transparent);
  --glass-edge: color-mix(in srgb, var(--ink) 11%, transparent);
  --glass-hi: color-mix(in srgb, #fff 10%, transparent);
  --depth: inset 0 1px 0 var(--glass-hi), 0 14px 34px -16px var(--shadow),
    0 2px 8px -3px var(--shadow);
  /* floating tab bar sits higher (stock layout only; other layouts override) */
  --float-bottom: calc(var(--nav-h) + 24px + env(safe-area-inset-bottom));
  --dock-bottom: calc(var(--nav-h) + 18px + env(safe-area-inset-bottom));
}
html[data-design="glass"] body::before {
  background-image:
    radial-gradient(60% 40% at 8% 4%, color-mix(in srgb, var(--accent) 28%, transparent), transparent 70%),
    radial-gradient(50% 38% at 96% 34%, color-mix(in srgb, var(--accent-2) 24%, transparent), transparent 70%),
    radial-gradient(60% 45% at 40% 102%, color-mix(in srgb, var(--magenta) 18%, transparent), transparent 70%);
  background-size: 100% 100%;
  -webkit-mask-image: none;
  mask-image: none;
}
html[data-design="glass"] :is(.panel, .run, .recent, .stat, .tick, .picker, .topbar:not(.flat)) {
  background: var(--glass);
  border: 1px solid var(--glass-edge);
  -webkit-backdrop-filter: blur(18px) saturate(150%);
  backdrop-filter: blur(18px) saturate(150%);
  box-shadow: var(--depth);
}
html[data-design="glass"] .panel { padding: 12px 14px 8px; }
html[data-design="glass"] .run { border-left: 1px solid var(--glass-edge); }
/* Map cells must stay opaque so the corridor SVG cannot show through them;
   the glass tint is composited over the board colour instead. */
html[data-design="glass"] .map-cell {
  background-color: var(--bg);
  background-image: linear-gradient(
    color-mix(in srgb, var(--panel-2) 60%, transparent),
    color-mix(in srgb, var(--panel-2) 60%, transparent)
  );
}
/* Keep the affordable tint through the glass surface (the rule above would
   otherwise flatten a purchasable cell back to the plain panel tint). */
html[data-design="glass"] .map-cell.afford-cheap {
  background-image: linear-gradient(
    color-mix(in srgb, var(--good, #3ecf7a) 24%, var(--panel-2)),
    color-mix(in srgb, var(--good, #3ecf7a) 24%, var(--panel-2))
  );
}
html[data-design="glass"] .map-cell.afford-pricey {
  background-image: linear-gradient(
    color-mix(in srgb, var(--warn, #e6b33c) 18%, var(--panel-2)),
    color-mix(in srgb, var(--warn, #e6b33c) 18%, var(--panel-2))
  );
}
html[data-design="glass"] :is(.card, .slot, .fac-card, .tier-card, .tag, .chip:not([aria-pressed="true"])) {
  background: color-mix(in srgb, var(--panel-2) 60%, transparent);
  border-color: var(--glass-edge);
}
html[data-design="glass"] :is(.fac-card, .tier-card):disabled :is(.fac-cost, .tier-cost) {
  color: color-mix(in srgb, var(--muted) 72%, var(--ink));
}
html[data-design="glass"] :is(.fac-card, .tier-card).buyable {
  box-shadow: 0 0 0 1px var(--accent) inset, 0 8px 22px -12px var(--accent);
}
html[data-design="glass"] :is(.chip, .tag, .dust) { border-radius: 999px; }
html[data-design="glass"] .btn {
  border-radius: 999px;
  border-color: var(--glass-edge);
  background: var(--glass-strong);
  box-shadow: 0 6px 16px -8px var(--shadow), inset 0 1px 0 var(--glass-hi);
  text-transform: none;
  letter-spacing: 0.02em;
  font-weight: 600;
}
html[data-design="glass"] .btn:active:not(:disabled) {
  box-shadow: inset 0 2px 6px var(--shadow);
}
html[data-design="glass"] .bar,
html[data-design="glass"] .tick-bar {
  height: 7px;
  border: 0;
  border-radius: 999px;
  background: color-mix(in srgb, var(--track) 55%, transparent);
  box-shadow: inset 0 1px 3px var(--shadow);
}
html[data-design="glass"] :is(.bar, .tick-bar) i {
  border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
}
html[data-design="glass"] .hero { border-bottom: 0; }
html[data-design="glass"] .hero-value { font-weight: 250; letter-spacing: -0.045em; }
html[data-design="glass"] .panel-head { border-bottom: 0; }
html[data-design="glass"] .panel-num { border-radius: 999px; padding: 1px 7px; }
html[data-design="glass"] .row { border-top: 1px solid var(--glass-edge); }
html[data-design="glass"] .tabs {
  left: 10px;
  right: 10px;
  bottom: calc(8px + env(safe-area-inset-bottom));
  padding: 6px 8px;
  border: 1px solid var(--glass-edge);
  border-radius: var(--r-lg);
  background: var(--glass-strong);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  backdrop-filter: blur(20px) saturate(160%);
  box-shadow: var(--depth);
}
html[data-design="glass"] .tab[aria-pressed="true"]::after {
  left: 30%;
  right: 30%;
  bottom: 2px;
  border-radius: 99px;
}

/* ==================  DESIGN 3 · CLEAN CORPORATE / EDITORIAL  ================== */

html[data-design="editorial"] {
  --r-xs: 2px;
  --r-sm: 4px;
  --r-md: 6px;
  --r-lg: 8px;
  --r-pill: 4px;
  --r-bar: 0;
  --sans: var(--stack-sans);
  --label: var(--stack-sans);
  --display: var(--stack-serif);
}
html[data-design="editorial"] body::before { display: none; }
html[data-design="editorial"] :is(.panel, .run, .recent, .stat, .tick, .picker, .card, .slot, .fac-card, .tier-card) {
  background: var(--panel);
  border: 1px solid var(--line);
  box-shadow: none;
}
html[data-design="editorial"] .run { border-left: 3px solid var(--accent); }
html[data-design="editorial"] .panel-head { border-bottom: 1.5px solid var(--ink); }
html[data-design="editorial"] :is(.panel-title, .run-head > span:first-child, .recent h2) {
  font-family: var(--stack-serif);
  font-size: calc(14px * var(--fs));
  font-weight: 600;
  letter-spacing: 0.04em;
  font-variant-caps: all-small-caps;
  color: var(--ink);
}
html[data-design="editorial"] .panel-num {
  border: 0;
  padding: 0;
  font-family: var(--stack-serif);
  font-style: italic;
  font-size: calc(12px * var(--fs));
  color: var(--accent);
}
html[data-design="editorial"] .panel-title .icon { display: none; }
html[data-design="editorial"] .hero-value { font-weight: 500; letter-spacing: -0.02em; }
html[data-design="editorial"] :is(.ident h1, .stat .v, .banner-title, .lab-code) {
  font-family: var(--stack-serif);
}
html[data-design="editorial"] .row { border-top: 1px solid var(--line-soft); }
html[data-design="editorial"] .btn {
  text-transform: none;
  letter-spacing: 0.01em;
  font-weight: 600;
  border-color: var(--ink);
  background: transparent;
}
html[data-design="editorial"] .btn:hover:not(:disabled) {
  background: var(--ink);
  color: var(--bg);
  border-color: var(--ink);
}
html[data-design="editorial"] :is(.tab, .rail-label) {
  text-transform: none;
  letter-spacing: 0.01em;
  font-size: calc(11px * var(--fs));
}
html[data-design="editorial"] .tab[aria-pressed="true"]::after { background: var(--ink); }
html[data-design="editorial"] .topbar:not(.flat) {
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
  background: var(--bg);
  border: 0;
  border-bottom: 1px solid var(--line);
  border-radius: 0;
}
html[data-design="editorial"] :is(.avatar, .coin) { box-shadow: none; }
html[data-design="editorial"] .card:hover { transform: none; }
html[data-design="editorial"] .tick-bar { border: 0; background: var(--line-soft); }

/* =====================  TEXT · SIZE / FACE / CASE  ===================== */

html[data-size="compact"] { --fs: 0.9; }
html[data-size="comfortable"] { --fs: 1.08; }
html[data-size="large"] { --fs: 1.2; }

html[data-face="mono"] {
  --sans: var(--stack-mono);
  --label: var(--stack-mono);
  --display: var(--stack-mono);
}
html[data-face="sans"] {
  --sans: var(--stack-sans);
  --label: var(--stack-sans);
  --display: var(--stack-sans);
}
html[data-face="serif"] { --display: var(--stack-serif); }
html[data-face="serif"] :is(.panel-title, .run-head > span:first-child, .recent h2, .ident h1, .stat .v, .banner-title, .lab-code) {
  font-family: var(--stack-serif);
}
html[data-face="rounded"] {
  --sans: var(--stack-rounded);
  --label: var(--stack-rounded);
  --display: var(--stack-rounded);
}

html[data-case="upper"] :is(
  .panel-title > span:last-child, .run-head > span:first-child, .hero-label > span,
  .meter-name > span, .fac-name > span, .eff-label, .tick-head > span:first-child,
  .tab, .rail-label, .family-name > span:last-child, .stat .k, .recent h2,
  .chart-label, .picker-head, .slot-num
) {
  text-transform: uppercase;
  font-variant-caps: normal;
  letter-spacing: 0.14em;
}
html[data-case="sentence"] :is(
  .panel-title > span:last-child, .run-head > span:first-child, .hero-label > span,
  .meter-name > span, .fac-name > span, .eff-label, .tick-head > span:first-child,
  .tab, .rail-label, .family-name > span:last-child, .stat .k, .recent h2,
  .chart-label, .picker-head, .slot-num
) {
  display: inline-block;
  text-transform: lowercase;
  font-variant-caps: normal;
  letter-spacing: 0.01em;
}
html[data-case="sentence"] :is(
  .panel-title > span:last-child, .run-head > span:first-child, .hero-label > span,
  .meter-name > span, .fac-name > span, .eff-label, .tick-head > span:first-child,
  .tab, .rail-label, .family-name > span:last-child, .stat .k, .recent h2,
  .chart-label, .picker-head, .slot-num
)::first-letter {
  text-transform: uppercase;
}
html[data-case="sentence"] :is(.stat .k, .recent h2, .chart-label, .picker-head) {
  display: block;
}
html[data-case="smallcaps"] :is(
  .panel-title > span:last-child, .run-head > span:first-child, .hero-label > span,
  .meter-name > span, .fac-name > span, .eff-label, .tick-head > span:first-child,
  .tab, .rail-label, .family-name > span:last-child, .stat .k, .recent h2,
  .chart-label, .picker-head, .slot-num
) {
  text-transform: none;
  font-variant-caps: all-small-caps;
  letter-spacing: 0.08em;
  font-size: 1.15em;
}

/* =====================  LAYOUT A · CLASSIC SIDEBAR  ===================== */

html[data-layout="sidebar"] {
  --rail-w: 62px;
  --float-bottom: calc(14px + env(safe-area-inset-bottom));
  --dock-bottom: calc(8px + env(safe-area-inset-bottom));
}
html[data-layout="sidebar"] #app {
  max-width: none;
  padding: 0 0 0 var(--rail-w);
}
.rail {
  position: fixed;
  left: 0;
  top: 0;
  bottom: 0;
  z-index: 20;
  width: var(--rail-w);
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: calc(10px + env(safe-area-inset-top)) 6px calc(10px + env(safe-area-inset-bottom));
  background: var(--bg-soft);
  border-right: 1px solid var(--line);
  overflow-y: auto;
  scrollbar-width: none;
}
.rail::-webkit-scrollbar { display: none; }
.rail-mark {
  text-align: center;
  font-size: calc(20px * var(--fs));
  color: var(--accent);
  padding: 4px 0 10px;
}
.rail-item {
  appearance: none;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  padding: 9px 2px 8px;
  border: 0;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--faint);
  cursor: pointer;
}
.rail-item .icon { width: 18px; height: 18px; }
.rail-label {
  font-family: var(--label);
  font-size: calc(8.5px * var(--fs));
  letter-spacing: 0.06em;
  text-transform: uppercase;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.rail-item[aria-current="page"] {
  color: var(--ink);
  background: color-mix(in srgb, var(--accent) 12%, transparent);
}
.rail-item[aria-current="page"]::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 8px;
  bottom: 8px;
  width: 3px;
  background: var(--accent);
  border-radius: 0 2px 2px 0;
}
.banner {
  padding: calc(12px + env(safe-area-inset-top)) 14px 14px;
  background:
    linear-gradient(135deg, color-mix(in srgb, var(--accent) 20%, var(--bg-soft)), var(--bg-soft) 72%);
  border-bottom: 1px solid var(--line);
}
.banner-crumb {
  margin-top: 12px;
  font-family: var(--label);
  font-size: calc(9.5px * var(--fs));
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--muted);
}
.banner-title {
  margin: 2px 0 0;
  font-family: var(--display);
  font-size: calc(24px * var(--fs));
  font-weight: 600;
  letter-spacing: -0.01em;
  color: var(--ink);
}
html[data-layout="sidebar"] .content {
  padding: 14px 12px 24px;
  max-width: var(--content-max);
}

/* topbar reused inside banners / pane heads */
.topbar.flat {
  position: relative;
  margin: 0;
  padding: 0;
  border: 0;
  border-radius: 0;
  background: none;
  -webkit-backdrop-filter: none;
  backdrop-filter: none;
}

/* ==================  LAYOUT B · MODERN COMMAND CENTER  ================== */

html[data-layout="command"] {
  --float-bottom: calc(80px + env(safe-area-inset-bottom));
  --dock-bottom: calc(74px + env(safe-area-inset-bottom));
}
html[data-layout="command"] #app {
  padding: 0 12px calc(92px + env(safe-area-inset-bottom));
}
.cmdbar {
  position: sticky;
  top: 0;
  z-index: 15;
  display: flex;
  align-items: center;
  gap: 10px;
  margin: 0 -12px 12px;
  padding: calc(9px + env(safe-area-inset-top)) 12px 9px;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line-soft);
}
.crumbs {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: center;
  gap: 6px;
  font-family: var(--label);
  font-size: calc(11px * var(--fs));
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
}
.crumbs span { overflow: hidden; text-overflow: ellipsis; }
.crumbs .sep { color: var(--faint); flex: 0 0 auto; }
.crumbs b { color: var(--ink); font-weight: 600; }
/* Phones: the breadcrumb trail crowds out the page title (and runs under the
   level ring), so keep only the current tab name. */
@media (max-width: 430px) {
  .crumbs span { display: none; }
  .crumbs { gap: 0; }
}
.kpis {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 8px;
  margin-bottom: 12px;
}
.kpis .stat .v { font-size: calc(15px * var(--fs)); }
.dash {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(300px, 1fr));
  gap: 12px;
  align-items: start;
}
.dash > * { margin: 0; min-width: 0; }
.dash > :is(.hero, .tick, .eff, .stats, .filters, .family, .hint, .loop-hero, .loop-claim, .loop-tree-card, .loop-ladder, .btn.wide, .run, .recent, .empty, .lab-span) {
  grid-column: 1 / -1;
}
.dock {
  position: fixed;
  left: 50%;
  bottom: calc(12px + env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 25;
  display: flex;
  gap: 2px;
  max-width: calc(100vw - 24px);
  padding: 5px;
  overflow-x: auto;
  scrollbar-width: none;
  border: 1px solid var(--line);
  border-radius: calc(var(--r-lg) + 6px);
  background: color-mix(in srgb, var(--panel) 92%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 14px 32px -12px var(--shadow);
}
.dock::-webkit-scrollbar { display: none; }
.dock-btn,
.cmd-icon {
  appearance: none;
  flex: 0 0 auto;
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: var(--r-lg);
  background: transparent;
  color: var(--faint);
  cursor: pointer;
}
.cmd-icon {
  width: 34px;
  height: 34px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  color: var(--ink);
}
:is(.dock-btn, .cmd-icon) .icon { width: 18px; height: 18px; }
/* all dock icons must fit a phone width: allow each to shrink a little */
.dock-btn {
  flex: 0 1 42px;
  min-width: 34px;
}
.dock-btn[aria-current="page"] { color: var(--accent-ink); background: var(--accent); }
/* Too narrow for the whole row: extra tabs (Inventory) live in the side menu. */
.dock-btn.dock-drop { display: none; }
.scrim {
  position: fixed;
  inset: 0;
  z-index: 40;
  background: rgba(0, 0, 0, 0.45);
  animation: fade 0.16s ease both;
}
@keyframes fade { from { opacity: 0; } }
.drawer {
  position: fixed;
  z-index: 41;
  top: calc(10px + env(safe-area-inset-top));
  bottom: calc(10px + env(safe-area-inset-bottom));
  left: 10px;
  width: min(80vw, 290px);
  display: flex;
  flex-direction: column;
  padding: 12px 10px;
  overflow-y: auto;
  border: 1px solid var(--line);
  border-radius: var(--r-lg);
  background: var(--panel);
  box-shadow: 0 24px 60px -20px var(--shadow);
  animation: slide-in 0.2s ease both;
}
@keyframes slide-in { from { transform: translateX(-24px); opacity: 0; } }
.drawer-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 4px 10px;
  border-bottom: 1px solid var(--line-soft);
  margin-bottom: 6px;
}
.drawer-group {
  margin: 10px 6px 4px;
  font-family: var(--label);
  font-size: calc(9px * var(--fs));
  letter-spacing: 0.2em;
  text-transform: uppercase;
  color: var(--faint);
}

/* shared nav rows (drawer + split master) */
.mitem {
  appearance: none;
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-width: 0;
  padding: 9px 10px;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  background: transparent;
  color: var(--muted);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}
.mitem .icon { width: 16px; height: 16px; }
.mitem-text { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 1px; }
.mitem-label {
  font-size: calc(12.5px * var(--fs));
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mitem-sum {
  font-family: var(--label);
  font-size: calc(9.5px * var(--fs));
  color: var(--faint);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.mitem[aria-current="page"] {
  border-color: color-mix(in srgb, var(--accent) 55%, transparent);
  background: color-mix(in srgb, var(--accent) 10%, transparent);
  color: var(--accent);
}

/* ==================  LAYOUT C · MINIMALIST SPLIT-VIEW  ================== */

html[data-layout="split"] {
  --float-bottom: calc(14px + env(safe-area-inset-bottom));
  --dock-bottom: 0px;
}
html[data-layout="split"] body { overflow: hidden; }
html[data-layout="split"] #app {
  max-width: none;
  padding: 0;
  height: var(--tg-viewport-stable-height, 100dvh);
}
.split {
  display: grid;
  height: 100%;
  grid-template-columns: minmax(0, 1fr);
  grid-template-rows: auto var(--split-h, 150px) 16px minmax(0, 1fr);
}
.split-head {
  padding: calc(9px + env(safe-area-inset-top)) 12px 9px;
  border-bottom: 1px solid var(--line-soft);
}
.split-head .avatar { width: 30px; height: 30px; font-size: calc(13px * var(--fs)); }
.pane-master {
  container-type: inline-size;
  overflow: auto;
  overscroll-behavior: contain;
  padding: 8px 10px;
  min-height: 0;
}
.pane-detail {
  overflow: auto;
  overscroll-behavior: contain;
  padding: 12px 12px calc(18px + env(safe-area-inset-bottom));
  min-height: 0;
  min-width: 0;
}
.mlist {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
  gap: 6px;
}
.pane-master .mitem { border-color: var(--line-soft); background: var(--panel); }
.pane-master .mitem[aria-current="page"] {
  border-color: var(--accent);
  background: color-mix(in srgb, var(--accent) 10%, var(--panel));
}
.split-handle {
  display: grid;
  place-items: center;
  touch-action: none;
  cursor: row-resize;
  background: var(--bg-soft);
  border-top: 1px solid var(--line-soft);
  border-bottom: 1px solid var(--line-soft);
  user-select: none;
  -webkit-user-select: none;
}
.split-handle::before {
  content: "";
  width: 44px;
  height: 4px;
  border-radius: 99px;
  background: var(--line-strong);
}
.split-handle.dragging::before { background: var(--accent); }
@media (min-width: 640px) {
  .split {
    grid-template-columns: var(--split-w, 240px) 12px minmax(0, 1fr);
    grid-template-rows: auto minmax(0, 1fr);
  }
  .split-head { grid-column: 1 / -1; }
  .mlist { grid-template-columns: 1fr; }
  .split-handle {
    cursor: col-resize;
    border-top: 0;
    border-bottom: 0;
    border-left: 1px solid var(--line-soft);
    border-right: 1px solid var(--line-soft);
  }
  .split-handle::before { width: 4px; height: 44px; }
}
@container (max-width: 120px) {
  .mitem-text { display: none; }
  .mitem { justify-content: center; padding: 10px 0; }
  .mlist { grid-template-columns: 1fr; }
}

/* =====================  THEME LAB  ===================== */

.lab-top {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
  padding: 4px 2px 12px;
}
.lab-kicker {
  font-family: var(--label);
  font-size: calc(9.5px * var(--fs));
  letter-spacing: 0.22em;
  color: var(--faint);
  text-transform: uppercase;
}
:is(.hero-value, .stat .v, .lab-code, .banner-title) {
  font-variant-numeric: lining-nums tabular-nums;
}
.lab-code {
  font-family: var(--display);
  font-size: calc(22px * var(--fs));
  letter-spacing: 0.02em;
  color: var(--ink);
  margin-top: 4px;
}
.lab-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.lab-actions .btn { padding: 7px 10px; }
.btn.on { border-color: var(--accent); color: var(--accent); }

.opt-list { display: flex; flex-direction: column; }
.opt {
  appearance: none;
  display: grid;
  grid-template-columns: 16px minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
  width: 100%;
  padding: 9px 0;
  border: 0;
  border-top: 1px dashed var(--line-soft);
  background: transparent;
  color: inherit;
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}
.opt:first-child { border-top: 0; }
.opt-radio {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  border: 1.5px solid var(--line-strong);
}
.opt[aria-checked="true"] .opt-radio {
  border-color: var(--accent);
  background: radial-gradient(circle, var(--accent) 0 40%, transparent 45%);
}
.opt-name { display: block; font-size: calc(12.5px * var(--fs)); color: var(--ink); }
.opt-desc {
  display: block;
  margin-top: 2px;
  font-family: var(--label);
  font-size: calc(10px * var(--fs));
  line-height: 1.4;
  color: var(--faint);
}
.opt-code {
  font-family: var(--stack-mono);
  font-size: calc(10px * var(--fs));
  color: var(--accent);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 1px 5px;
}

.swatches {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(96px, 1fr));
  gap: 7px;
  margin: 8px 0 6px;
}
.swatch {
  appearance: none;
  display: flex;
  flex-direction: column;
  gap: 7px;
  padding: 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  font-family: inherit;
  text-align: left;
  cursor: pointer;
}
.swatch[aria-checked="true"] { outline: 2px solid var(--accent); outline-offset: 1px; }
.swatch-dots { display: flex; gap: 3px; }
.swatch-dots i {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(127, 127, 127, 0.35);
}
.swatch-name { font-size: calc(10.5px * var(--fs)); line-height: 1.2; }
.swatch-code { font-family: var(--stack-mono); font-size: calc(9px * var(--fs)); opacity: 0.65; }

.seg-label {
  margin: 10px 0 6px;
  font-family: var(--label);
  font-size: calc(9.5px * var(--fs));
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
}
.seg { display: flex; flex-wrap: wrap; gap: 6px; padding-bottom: 4px; }

.specimen-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 8px;
  margin: 8px 0;
}
.specimen .hero { padding-bottom: 8px; margin-bottom: 8px; }
.specimen .hero-value { font-size: calc(34px * var(--fs)); }

.inspector {
  position: sticky;
  bottom: var(--dock-bottom);
  z-index: 6;
  margin-top: 12px;
  border: 1px solid var(--accent);
  border-radius: var(--r-sm);
  background: color-mix(in srgb, var(--bg) 94%, transparent);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  box-shadow: 0 -10px 24px -16px var(--shadow);
}
.inspector-head {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 6px 6px 6px 10px;
  border-bottom: 1px solid var(--line-soft);
}
.inspector.closed .inspector-head { border-bottom: 0; }
.inspector-title {
  flex: 1;
  font-family: var(--label);
  font-size: calc(9.5px * var(--fs));
  letter-spacing: 0.18em;
  color: var(--accent);
  text-transform: uppercase;
}
.inspector .chip { padding: 4px 9px; font-size: calc(10.5px * var(--fs)); }
.inspector .icon-btn { width: 28px; height: 28px; }
.inspector textarea {
  display: block;
  width: 100%;
  resize: none;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--ink);
  font-family: var(--stack-mono);
  font-size: calc(10.5px * var(--fs));
  line-height: 1.45;
  padding: 8px 10px;
}

.qbar {
  position: fixed;
  right: 10px;
  bottom: var(--float-bottom);
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
}
.qbar-pill {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 10px;
  border: 1px solid var(--accent);
  border-radius: 999px;
  background: color-mix(in srgb, var(--panel) 94%, transparent);
  color: var(--ink);
  font-family: var(--stack-mono);
  font-size: 10px;
  letter-spacing: 0.04em;
  cursor: pointer;
  box-shadow: 0 10px 26px -12px var(--shadow);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
}
.qbar-pill .icon { color: var(--accent); }
.qbar-card {
  width: min(300px, calc(100vw - 20px));
  padding: 6px 8px 8px;
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  background: color-mix(in srgb, var(--panel) 96%, transparent);
  -webkit-backdrop-filter: blur(14px);
  backdrop-filter: blur(14px);
  box-shadow: 0 18px 40px -16px var(--shadow);
}
.qbar-row {
  display: grid;
  grid-template-columns: 62px 30px minmax(0, 1fr) 30px;
  align-items: center;
  gap: 4px;
  padding: 3px 0;
}
.qbar-axis {
  font-family: var(--stack-mono);
  font-size: 9px;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--faint);
}
.qbar-name {
  font-size: 11.5px;
  text-align: center;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.qbar-step {
  appearance: none;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  background: var(--panel-2);
  color: var(--ink);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
}
.qbar-step:active { border-color: var(--accent); color: var(--accent); }
.qbar-foot {
  display: flex;
  justify-content: space-between;
  gap: 6px;
  margin-top: 6px;
  padding-top: 6px;
  border-top: 1px solid var(--line-soft);
}
.qbar-foot .btn { padding: 6px 9px; }