/* Element Tycoon: UI styles. Effects live in css/effects.css. */

:root {
  --cat-alkali-metal: #ffb4a2;
  --cat-alkaline-earth: #ffd6a5;
  --cat-transition-metal: #bdd5ff;
  --cat-post-transition: #b9f2d0;
  --cat-metalloid: #a0e7e5;
  --cat-nonmetal: #fdffb6;
  --cat-halogen: #ffc6e0;
  --cat-noble-gas: #d9c2ff;
  --cat-lanthanide: #ffcfd2;
  --cat-actinide: #f9c6a8;
  --cat-unknown: #e3e3e3;

  --bg-top: #fff7ea;
  --bg-bottom: #e2f1ff;
  --ink: #26324a;
  --ink-soft: #56637d;
  --ink-faint: #8a95aa;
  --panel: rgba(255, 255, 255, 0.82);
  --panel-solid: #ffffff;
  --line: #e2e7f0;
  --locked: #eceef2;
  --locked-ink: #9aa3b4;

  --bench: #5b9dff;
  --sell: #f0a92c;
  --buy: #34b77c;
  --info: #9b7cf0;
  --mode: var(--bench);

  --good: #2f9e6a;
  --warn: #d2683a;
  --close: #7a5bd6;

  /* Spacing scale (DESIGN.md 11.12). Every gap, padding and margin uses these steps. */
  --sp-1: 4px;
  --sp-2: 8px;
  --sp-3: 12px;
  --sp-4: 16px;
  --sp-5: 24px;
  --sp-6: 32px;

  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 2px 6px rgba(38, 50, 74, 0.08), 0 8px 24px rgba(38, 50, 74, 0.08);
  --shadow-lift: 0 4px 10px rgba(38, 50, 74, 0.12), 0 12px 28px rgba(38, 50, 74, 0.12);
  --focus: 0 0 0 3px #ffffff, 0 0 0 5px #3d7cf0;

  --font-head: "Fredoka", "Baloo 2", "Trebuchet MS", "Segoe UI", system-ui, sans-serif;
  --font-body: "Nunito", "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;

  --cell-h: 48px;
  --cell-gap: 3px;
  --tap: 40px;
}

body.mode-sell { --mode: var(--sell); }
body.mode-buy { --mode: var(--buy); }
body.mode-info { --mode: var(--info); }

* { box-sizing: border-box; }

[hidden] { display: none !important; }

/* No double-tap zoom: a double-tap buys (DESIGN.md 11.8 and 11.10). */
html { min-height: 100%; touch-action: manipulation; -webkit-text-size-adjust: 100%; text-size-adjust: 100%; }
button, input, select, label, [data-item] { touch-action: manipulation; }

body {
  margin: 0;
  min-height: 100vh;
  overflow-x: hidden; /* screen shake must not flash a horizontal scrollbar */
  color: var(--ink);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.4;
  background: linear-gradient(170deg, var(--bg-top) 0%, #f6f6f0 40%, var(--bg-bottom) 100%) fixed;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  /* A long press opens the info sheet. The browser must not also select text or show its copy or image menu. */
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}
img { -webkit-touch-callout: none; -webkit-user-drag: none; }
/* Typing still needs selection. */
input, textarea, [contenteditable="true"] { -webkit-user-select: text; user-select: text; -webkit-touch-callout: default; }
/* With a mouse, reading text in dialogs stays selectable for copying. */
@media (hover: hover) and (pointer: fine) {
  .ui-modal-body p, .ui-modal-body li { -webkit-user-select: text; user-select: text; }
}

h1, h2, h3, h4 { font-family: var(--font-head); font-weight: 600; margin: 0; }

button, select, input { font: inherit; color: inherit; }

button { cursor: pointer; }

:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); }

/* ---------------------------------------------------------------- bubbles */

.bubbles {
  position: fixed;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
  z-index: 0;
}
.bubbles span {
  position: absolute;
  bottom: -60px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: radial-gradient(circle at 30% 30%, rgba(255, 255, 255, 0.9), rgba(160, 205, 255, 0.25) 60%, rgba(160, 205, 255, 0.08));
  border: 1px solid rgba(140, 190, 240, 0.25);
  opacity: 0.55;
  animation: bubble-rise 26s linear infinite;
}
.bubbles span:nth-child(1) { left: 4%; animation-delay: 0s; transform: scale(0.8); }
.bubbles span:nth-child(2) { left: 13%; animation-delay: -6s; animation-duration: 31s; width: 34px; height: 34px; }
.bubbles span:nth-child(3) { left: 22%; animation-delay: -14s; width: 14px; height: 14px; }
.bubbles span:nth-child(4) { left: 31%; animation-delay: -3s; animation-duration: 36s; width: 28px; height: 28px; }
.bubbles span:nth-child(5) { left: 42%; animation-delay: -19s; width: 18px; height: 18px; }
.bubbles span:nth-child(6) { left: 52%; animation-delay: -9s; animation-duration: 29s; width: 40px; height: 40px; }
.bubbles span:nth-child(7) { left: 61%; animation-delay: -23s; width: 16px; height: 16px; }
.bubbles span:nth-child(8) { left: 70%; animation-delay: -12s; animation-duration: 34s; }
.bubbles span:nth-child(9) { left: 78%; animation-delay: -2s; width: 30px; height: 30px; }
.bubbles span:nth-child(10) { left: 86%; animation-delay: -17s; animation-duration: 27s; width: 12px; height: 12px; }
.bubbles span:nth-child(11) { left: 93%; animation-delay: -8s; width: 26px; height: 26px; }
.bubbles span:nth-child(12) { left: 47%; animation-delay: -27s; animation-duration: 40s; width: 20px; height: 20px; }

@keyframes bubble-rise {
  0% { transform: translate(0, 0); }
  25% { transform: translate(14px, -28vh); }
  50% { transform: translate(-10px, -56vh); }
  75% { transform: translate(12px, -84vh); }
  100% { transform: translate(0, -115vh); }
}

body.reduced .bubbles span { animation: none; display: none; }

/* ---------------------------------------------------------------- top bar */

.topbar {
  position: relative;
  z-index: 6;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-5);
  padding-top: max(var(--sp-2), env(safe-area-inset-top));
  background: rgba(255, 255, 255, 0.7);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid rgba(38, 50, 74, 0.06);
  box-shadow: 0 2px 10px rgba(38, 50, 74, 0.05);
}

.brand { display: flex; align-items: center; gap: var(--sp-2); flex: 1 1 auto; min-width: 0; }
.brand h1 { overflow: hidden; text-overflow: ellipsis; }
.brand-logo { width: 34px; height: 34px; flex: none; }
.brand h1 { font-size: 24px; font-weight: 700; letter-spacing: 0.2px; white-space: nowrap; color: #2c3b5c; }

.coins {
  display: flex;
  align-items: baseline;
  gap: var(--sp-2);
  padding: 6px var(--sp-4);
  border-radius: 999px;
  background: linear-gradient(180deg, #fff6d8, #ffe9a8);
  box-shadow: inset 0 -2px 0 rgba(200, 140, 0, 0.15), var(--shadow);
  font-family: var(--font-head);
  white-space: nowrap;
}
.coins-icon { font-size: 20px; align-self: center; }
.coins-value { font-size: 22px; font-weight: 700; color: #7a5200; min-width: 2ch; font-variant-numeric: tabular-nums; }
.coins-label { font-size: 14px; color: #9a7420; }
.coins.pop .coins-value { display: inline-block; animation: coin-pop 0.35s ease; }
@keyframes coin-pop { 50% { transform: scale(1.12); } }
.coins.bounce { animation: coin-bounce 0.5s ease; }
@keyframes coin-bounce {
  0%, 100% { transform: translateY(0) scale(1); }
  30% { transform: translateY(-6px) scale(1.08); }
  60% { transform: translateY(2px) scale(0.97); }
}
body.reduced .coins.bounce { animation-duration: 0.2s; }

.top-actions { display: flex; gap: var(--sp-2); flex: 1 1 auto; justify-content: flex-end; }

.top-btn {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: var(--tap);
  padding: var(--sp-2) var(--sp-3);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-solid);
  box-shadow: 0 1px 3px rgba(38, 50, 74, 0.08);
  font-weight: 700;
  font-size: 14px;
  white-space: nowrap;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
@media (hover: hover) {
  .top-btn:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
}
.nb-badge {
  position: absolute;
  top: -7px;
  right: -7px;
  min-width: 19px;
  height: 19px;
  padding: 0 5px;
  border-radius: 999px;
  background: #ef6b5b;
  color: #fff;
  font-size: 11.5px;
  font-weight: 800;
  line-height: 19px;
  text-align: center;
  box-shadow: 0 0 0 2px #fff;
  animation: nb-pulse 1.6s ease-in-out infinite;
}
@keyframes nb-pulse {
  0%, 100% { transform: scale(1); box-shadow: 0 0 0 2px #fff, 0 0 0 2px rgba(239, 107, 91, 0.5); }
  50% { transform: scale(1.12); box-shadow: 0 0 0 2px #fff, 0 0 0 7px rgba(239, 107, 91, 0); }
}
body.reduced .nb-badge { animation: none; }
/* A small dot on the Encyclopedia button while a relevant Chemistry 101 lesson is unread (DESIGN.md 11.13). */
.ency-dot {
  position: absolute;
  top: -4px;
  right: -4px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: #7a5bd6;
  box-shadow: 0 0 0 2px #fff;
}
.top-btn > span:first-child { font-size: 17px; }
.hint-price {
  display: inline-block;
  margin-left: var(--sp-1);
  padding: 0 6px;
  border-radius: 999px;
  background: #fff1c2;
  color: #7a5200;
  font-size: 12px;
}
.hint-price::after { content: " 🪙"; }

/* ---------------------------------------------------------------- main + controls */

/* #app holds the top bar and the game. Screen shake moves #app only. Modals, tooltips and the effects overlay sit outside it. */
#app {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

/* Two columns on desktop: the periodic table and the shelf on the left, the lab table and the known reactions on the right.
   The table and the lab stay on screen together. Drag and drop needs both. */
.main {
  --lab-col: clamp(440px, 39vw, 740px);
  --chrome-x: 150px;
  --chrome-y: 430px;
  --cell-h: clamp(30px, min(calc((100vw - var(--lab-col) - var(--chrome-x)) / 18 * 1.12), calc((100vh - var(--chrome-y)) / 9)), 60px);
  position: relative;
  flex: 1 1 auto;
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--lab-col);
  grid-template-rows: auto minmax(0, 1fr);
  gap: var(--sp-4);
  width: 100%;
  max-width: 1880px;
  min-height: 0;
  margin: 0 auto;
  padding: var(--sp-4) var(--sp-5) var(--sp-4);
}

.controls {
  grid-column: 1 / -1;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-3) var(--sp-4);
}

.col {
  display: flex;
  flex-direction: column;
  gap: var(--sp-4);
  min-width: 0;
  min-height: 0;
}

.seg-group {
  display: inline-flex;
  align-items: center;
  gap: var(--sp-1);
  padding: var(--sp-1);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.75);
  box-shadow: var(--shadow);
}
.seg-label {
  padding: 0 var(--sp-2);
  font-size: 12px;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.6px;
  color: var(--ink-faint);
}
.seg {
  min-height: 32px;
  padding: 5px var(--sp-3);
  border: 0;
  border-radius: 10px;
  background: transparent;
  font-weight: 700;
  font-size: 14px;
  color: var(--ink-soft);
  white-space: nowrap;
  transition: background 0.15s ease, color 0.15s ease, transform 0.15s ease;
}
@media (hover: hover) {
  .seg:hover { background: #f0f4fb; color: var(--ink); }
}
.seg[aria-pressed="true"] {
  background: var(--mode);
  color: #fff;
  box-shadow: 0 2px 6px rgba(38, 50, 74, 0.2);
  text-shadow: 0 1px 1px rgba(0, 0, 0, 0.15);
}
.qty-btn { min-width: 44px; }
/* Phones swap the three Qty buttons for one button that cycles 1, 10 and Max. */
.qty-cycle { display: none; }

.mode-hint {
  margin: 0;
  flex: 1 1 260px;
  font-size: 13.5px;
  color: var(--ink-soft);
}
.mode-hint b { color: var(--ink); }

/* ---------------------------------------------------------------- periodic table */

.table-area {
  padding: var(--sp-3) var(--sp-4);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.55);
  box-shadow: var(--shadow);
  min-width: 0;
}

/* Scroll boxes clip anything outside their padding. 6 px of padding with a matching negative margin leaves room for the 5 px focus and selection rings. */
.table-scroll { overflow-x: auto; overflow-y: hidden; padding: 6px; margin: -2px -6px; }

.ptable {
  display: grid;
  grid-template-columns: repeat(18, minmax(0, 1fr));
  grid-template-rows: repeat(7, var(--cell-h)) var(--sp-2) repeat(2, var(--cell-h));
  gap: var(--cell-gap);
  min-width: 600px;
  margin: 0 auto;
}

/* "My elements" and its toggle only exist on phones (see the phone section). */
.myel, .el-view { display: none; }

.pt-cell {
  --c: var(--cat-unknown);
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-width: 0;
  padding: calc(var(--cell-h) * 0.16) 0 0;
  border: 1px solid rgba(38, 50, 74, 0.08);
  border-radius: 9px;
  background: var(--c);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.45), rgba(255, 255, 255, 0) 60%);
  box-shadow: 0 1px 2px rgba(38, 50, 74, 0.1);
  cursor: pointer;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
@media (hover: hover) {
  .pt-cell:hover {
    transform: translateY(-2px) scale(1.06);
    z-index: 3;
    box-shadow: 0 0 0 2px var(--mode), var(--shadow-lift);
  }
  .pt-cell.is-locked:hover { box-shadow: 0 0 0 2px #c5ccd8; transform: translateY(-1px); }
  body.mode-sell .pt-cell.unsellable:hover { box-shadow: 0 0 0 2px #c5ccd8; transform: translateY(-1px); }
}
.pt-cell:active { transform: translateY(0) scale(0.97); }

.pt-z {
  position: absolute;
  top: 2px;
  left: 4px;
  font-size: clamp(8px, calc(var(--cell-h) * 0.2), 11px);
  line-height: 1;
  font-weight: 700;
  color: rgba(38, 50, 74, 0.6);
}
.pt-sym {
  font-family: var(--font-head);
  font-size: clamp(14px, calc(var(--cell-h) * 0.4), 22px);
  font-weight: 600;
  line-height: 1;
  margin-top: 2px;
}
.pt-count {
  margin-top: 1px;
  min-height: 11px;
  font-size: clamp(10px, calc(var(--cell-h) * 0.24), 12.5px);
  font-weight: 800;
  line-height: 1;
  color: rgba(38, 50, 74, 0.75);
  font-variant-numeric: tabular-nums;
}
.pt-count.zero { color: rgba(38, 50, 74, 0.32); }

.pt-cell.is-locked {
  background: var(--locked);
  background-image: none;
  border-style: dashed;
  border-color: rgba(38, 50, 74, 0.1);
  box-shadow: none;
}
.pt-cell.is-locked .pt-sym { opacity: 0.35; }
.pt-cell.is-locked .pt-z { color: rgba(38, 50, 74, 0.35); }
.pt-cell.is-locked .pt-count { visibility: hidden; }

.pt-placeholder {
  display: flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  border: 1px dashed rgba(38, 50, 74, 0.14);
  font-size: 10px;
  font-weight: 700;
  color: var(--ink-faint);
  text-align: center;
  line-height: 1.1;
}

/* generator progress ring */
.pt-ring {
  position: absolute;
  top: 3px;
  right: 3px;
  width: 12px;
  height: 12px;
  transform: rotate(-90deg);
  display: none;
}
.pt-cell.has-gen .pt-ring { display: block; }
.pt-ring circle { fill: none; stroke-width: 3; }
.pt-ring .ring-bg { stroke: rgba(38, 50, 74, 0.12); }
.pt-ring .ring-fg {
  stroke: #3d8bfd;
  stroke-linecap: round;
  stroke-dasharray: 25.13;
  stroke-dashoffset: 25.13;
}
.ptable.rings-run .pt-ring .ring-fg { animation: ring-fill 10s linear forwards; }
@keyframes ring-fill { from { stroke-dashoffset: 25.13; } to { stroke-dashoffset: 0; } }

/* Unsellable cells look disabled in Sell mode (DESIGN.md 11.1). */
body.mode-sell .pt-cell.unsellable:not(.is-locked),
body.mode-sell .my-tile.unsellable {
  filter: grayscale(0.85);
  opacity: 0.55;
  background-image: repeating-linear-gradient(135deg, rgba(38, 50, 74, 0.07) 0 4px, transparent 4px 9px);
  cursor: not-allowed;
}
.pt-cell.bought, .my-tile.bought { animation: cell-bought 0.6s ease; }
@keyframes cell-bought {
  0% { transform: scale(1); }
  35% { transform: scale(1.14); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.95), 0 0 16px 5px rgba(52, 183, 124, 0.6); }
  100% { transform: scale(1); }
}
.pt-cell.bump, .my-tile.bump { animation: cell-bump 0.45s ease; }
@keyframes cell-bump {
  0% { transform: scale(1); }
  35% { transform: scale(1.12); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9), 0 0 14px 4px rgba(120, 200, 255, 0.55); }
  100% { transform: scale(1); }
}
.pt-cell.just-found, .my-tile.just-found { animation: cell-found 1.6s ease 2; }
@keyframes cell-found {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255, 210, 90, 0); }
  50% { box-shadow: 0 0 0 4px rgba(255, 210, 90, 0.9), 0 0 18px 6px rgba(255, 210, 90, 0.6); }
}
body.reduced .pt-cell.bump, body.reduced .my-tile.bump { animation-duration: 0.2s; }
body.reduced .pt-cell.just-found, body.reduced .my-tile.just-found { animation: none; box-shadow: 0 0 0 3px rgba(255, 200, 70, 0.9); }

/* spotlight in the empty top middle of the table */
.pt-spot {
  grid-column: 3 / 13;
  grid-row: 1 / 4;
  display: flex;
  align-items: center;
  gap: var(--sp-4);
  padding: var(--sp-2) var(--sp-4);
  margin: 0 var(--sp-2) var(--sp-2);
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.6);
  border: 1px solid rgba(38, 50, 74, 0.06);
  min-width: 0;
  overflow: hidden;
}
.spot-tile {
  flex: none;
  width: clamp(60px, calc(var(--cell-h) * 1.9), 96px);
  height: clamp(60px, calc(var(--cell-h) * 1.9), 96px);
  border-radius: 14px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--c, var(--cat-unknown));
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 70%);
  box-shadow: var(--shadow);
  position: relative;
}
.spot-tile .z { position: absolute; top: 5px; left: 8px; font-size: 12px; font-weight: 800; color: rgba(38, 50, 74, 0.6); }
.spot-tile .sym { font-family: var(--font-head); font-size: clamp(26px, calc(var(--cell-h) * 0.8), 40px); font-weight: 600; line-height: 1; }
.spot-tile .nm { font-size: 11px; font-weight: 700; color: rgba(38, 50, 74, 0.7); margin-top: 2px; }
.spot-text { min-width: 0; flex: 1 1 auto; }
.spot-text h3 { font-size: 20px; line-height: 1.15; }
.spot-text h3 .spot-sub { margin-left: var(--sp-2); font-family: var(--font-body); }
.spot-text .spot-sub { font-size: 13px; color: var(--ink-soft); font-weight: 700; }
.spot-props { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1) var(--sp-2); margin-top: var(--sp-2); }
.spot-props .tt-badge, .chem-box .tt-badge { background: rgba(38, 50, 74, 0.07); color: var(--ink); font-size: 11.5px; }
.spot-en { margin-top: 0; flex: 1 1 170px; max-width: 260px; color: var(--ink); }
.spot-en .en-label, .chem-box .en-label { color: var(--ink-soft); }
.spot-en .en-meter, .chem-box .en-meter { background: rgba(38, 50, 74, 0.1); }
.spot-en .en-none { color: var(--ink-faint); }
.spot-chem {
  margin-top: var(--sp-2);
  font-size: 13px;
  line-height: 1.4;
  color: var(--ink);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}
.pt-spot { container-type: size; }
@container (max-height: 135px) {
  .spot-chem { -webkit-line-clamp: 1; }
}
@container (max-height: 110px) {
  .spot-chem { display: none; }
}
.chem-box { margin: var(--sp-3) 0; padding: var(--sp-3) var(--sp-4); border-radius: 12px; background: #f4f7fd; }
.chem-box p { margin: var(--sp-2) 0 0; font-size: 14px; }
.chem-box > p:first-child { margin-top: 0; }
.chem-box .spot-en { max-width: none; margin-top: var(--sp-2); }
.spot-text .spot-line { font-size: 13px; color: var(--ink-soft); margin-top: var(--sp-1); line-height: 1.45; }
.spot-text .spot-line b { color: var(--ink); }
.spot-intro h3 { font-size: clamp(15px, calc(var(--cell-h) * 0.42), 19px); }
.spot-intro p { margin: var(--sp-1) 0 0; font-size: clamp(11.5px, calc(var(--cell-h) * 0.3), 13px); line-height: 1.35; color: var(--ink-soft); }

.spot-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 2px var(--sp-3);
  margin-top: var(--sp-2);
  font-size: clamp(10.5px, calc(var(--cell-h) * 0.26), 11.5px);
  line-height: 1.4;
  color: var(--ink-soft);
}
.legend-item { display: inline-flex; align-items: center; gap: 5px; font-weight: 700; }
.legend-swatch {
  width: 11px;
  height: 11px;
  border-radius: 4px;
  background: var(--c);
  border: 1px solid rgba(38, 50, 74, 0.12);
}

/* ---------------------------------------------------------------- panels */

.panel {
  padding: var(--sp-4);
  border-radius: 16px;
  background: var(--panel);
  box-shadow: var(--shadow);
  min-width: 0;
}
.panel-title { font-size: 18px; color: #33415f; white-space: nowrap; }
.panel-sub { font-family: var(--font-body); font-size: 12.5px; font-weight: 700; color: var(--ink-faint); margin-left: var(--sp-1); }

/* Panel header: the title on the left, the search and filters on the right. */
.panel-head {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  margin-bottom: var(--sp-3);
}
.panel-head .panel-title { flex: 0 1 auto; margin-right: auto; }
.panel-tools {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2);
  flex: 1 1 260px;
  justify-content: flex-end;
  min-width: 0;
}

.panel-filters {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  margin: calc(var(--sp-1) * -1) 0 var(--sp-3);
}
.panel-filters .small-select { flex: 0 1 auto; }

.ui-search {
  flex: 1 1 140px;
  min-width: 0;
  max-width: 260px;
  height: 34px;
  padding: 0 var(--sp-3) 0 32px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 20 20'%3E%3Ccircle cx='8.5' cy='8.5' r='5.5' fill='none' stroke='%238a95aa' stroke-width='2'/%3E%3Cpath d='M13 13l4 4' stroke='%238a95aa' stroke-width='2' stroke-linecap='round'/%3E%3C/svg%3E") no-repeat 10px 50% / 15px 15px;
  font-size: 14px;
  font-weight: 600;
}
.ui-search::placeholder { color: var(--ink-faint); font-weight: 600; }
.ui-search:focus-visible { border-color: #3d7cf0; box-shadow: 0 0 0 3px rgba(61, 124, 240, 0.25); }
.small-select { height: 34px; padding: 0 var(--sp-2); font-size: 13.5px; max-width: 190px; }
.small-toggle { min-height: 34px; padding: 0 var(--sp-1); }

/* Category filter chips with discovered and total counts (DESIGN.md 11.11). One scrolling row. */
.cat-chips {
  display: flex;
  gap: var(--sp-2);
  overflow-x: auto;
  margin: -4px -6px var(--sp-2);
  padding: 6px;
  scrollbar-width: thin;
}
.cat-chip {
  flex: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  min-height: 30px;
  padding: 0 var(--sp-3);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-size: 13px;
  font-weight: 800;
  color: var(--ink-soft);
  white-space: nowrap;
}
.cat-chip[aria-pressed="true"] { background: #2f3d5c; border-color: #2f3d5c; color: #fff; }
.cat-count {
  padding: 0 6px;
  border-radius: 999px;
  background: rgba(38, 50, 74, 0.08);
  font-size: 11.5px;
  font-weight: 800;
  font-variant-numeric: tabular-nums;
}
.cat-chip[aria-pressed="true"] .cat-count { background: rgba(255, 255, 255, 0.2); }

/* The shelf and the known reactions fill the rest of their column and scroll inside. */
.shelf-panel, .known-panel {
  flex: 1 1 auto;
  display: flex;
  flex-direction: column;
  min-height: 150px;
}

.empty-note { margin: var(--sp-1) 0; font-size: 13.5px; color: var(--ink-faint); }

/* shelf chips */
.shelf {
  flex: 1 1 0;
  display: flex;
  flex-wrap: wrap;
  align-content: flex-start;
  gap: var(--sp-2);
  min-height: 0;
  overflow-y: auto;
  padding: 6px 6px var(--sp-1);
  margin: -4px -6px 0;
}
.shelf .empty-note { flex: 1 1 100%; }
.cchip {
  --c: #e6f0ff;
  display: inline-flex;
  align-items: center;
  gap: var(--sp-2);
  min-height: 34px;
  padding: var(--sp-1) var(--sp-3) var(--sp-1) var(--sp-2);
  border: 1px solid rgba(38, 50, 74, 0.1);
  border-radius: 999px;
  background: var(--panel-solid);
  box-shadow: 0 1px 2px rgba(38, 50, 74, 0.08);
  font-weight: 700;
  font-size: 14px;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
@media (hover: hover) {
  .cchip:hover { transform: translateY(-2px); box-shadow: 0 0 0 2px var(--mode), var(--shadow); }
}
.cchip-dot {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: var(--c);
  border: 1px solid rgba(38, 50, 74, 0.18);
  box-shadow: inset 0 -2px 0 rgba(0, 0, 0, 0.06);
  flex: none;
}
.cchip-formula { font-family: var(--font-head); font-weight: 600; font-size: 15px; }
.cchip-count { color: var(--ink-soft); font-size: 12.5px; font-variant-numeric: tabular-nums; }
.cchip.zero { opacity: 0.5; }
.cchip.bump { animation: cell-bump 0.45s ease; }

/* lab table (the scene itself is styled by css/lab.css) */
.lab-panel {
  flex: none;
  padding: var(--sp-2);
  display: flex;
  flex-direction: column;
}
#lab { position: relative; }
.lab-missing {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 100%;
  min-height: 300px;
  border-radius: 12px;
  border: 2px dashed #d3dbe8;
  color: var(--ink-faint);
  font-weight: 700;
  text-align: center;
  padding: var(--sp-5);
}

/* Phone tab bar. Hidden until the phone layout shows it. */
.ptabs { display: none; }

.soft-btn {
  min-height: 36px;
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: var(--panel-solid);
  font-weight: 700;
  transition: transform 0.12s ease, box-shadow 0.12s ease;
}
@media (hover: hover) {
  .soft-btn:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
}
.soft-btn:disabled, .soft-btn[aria-disabled="true"] { opacity: 0.45; cursor: not-allowed; transform: none; box-shadow: none; }
.soft-btn.primary { background: var(--bench); border-color: transparent; color: #fff; }
.soft-btn.buy { background: var(--buy); border-color: transparent; color: #fff; }
.soft-btn.sell { background: var(--sell); border-color: transparent; color: #fff; }
.soft-btn.danger { background: #ef6b5b; border-color: transparent; color: #fff; }

/* known reactions */
.known { flex: 1 1 0; display: flex; flex-direction: column; gap: var(--sp-2); min-height: 0; overflow-y: auto; padding: 2px; }
.kr-more { flex: none; height: 1px; }
.kr {
  position: relative;
  overflow: hidden;
  flex: none;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--sp-2) var(--sp-3);
  padding: var(--sp-2) var(--sp-3);
  border-radius: 12px;
  background: var(--panel-solid);
  border: 1px solid var(--line);
}
.kr.cannot .eq { opacity: 0.6; }
/* A running job (DESIGN.md 11.2): a smooth bar along the bottom of the row and a countdown. */
.kr-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  height: 5px;
  background: rgba(91, 157, 255, 0.12);
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
}
.kr.running .kr-bar { opacity: 1; }
.kr-fill {
  display: block;
  height: 100%;
  width: 100%;
  transform: scaleX(0);
  transform-origin: left center;
  background: linear-gradient(90deg, #8fd3ff, #5b9dff, #b49bff);
}
@keyframes kr-fill { from { transform: scaleX(0); } to { transform: scaleX(1); } }
.kr.running { border-color: #b9d3ff; background: #f6faff; }
.kr.running .kr-max { color: #2d6fd6; font-variant-numeric: tabular-nums; }
.kr.done-flash { animation: kr-done 0.9s ease; }
@keyframes kr-done {
  0% { box-shadow: 0 0 0 0 rgba(47, 158, 106, 0); }
  30% { box-shadow: 0 0 0 3px rgba(47, 158, 106, 0.45); }
  100% { box-shadow: 0 0 0 0 rgba(47, 158, 106, 0); }
}
.cchip.job-pop { animation: chip-pop 0.7s cubic-bezier(0.3, 1.6, 0.5, 1); }
@keyframes chip-pop {
  0% { transform: scale(1); }
  35% { transform: scale(1.25); box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.9), 0 0 16px 6px rgba(120, 220, 160, 0.7); }
  100% { transform: scale(1); }
}
body.reduced .cchip.job-pop, body.reduced .kr.done-flash { animation-duration: 0.2s; }
/* A narrow panel always puts the controls on their own line. A running row then keeps its height. */
.kr-buttons { display: flex; gap: var(--sp-2); margin-left: auto; flex-wrap: wrap; align-items: center; flex: 1 1 100%; justify-content: flex-end; }
.kr-btn {
  min-height: 30px;
  padding: 2px var(--sp-3);
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #f5f8ff;
  font-size: 12.5px;
  font-weight: 800;
  color: var(--ink);
}
@media (hover: hover) {
  .kr-btn:hover:not(:disabled) { background: #e5eeff; }
}
.kr-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.kr-max { font-size: 11.5px; color: var(--ink-faint); font-weight: 700; align-self: center; margin: 0 var(--sp-1); }
/* The cancel button of a running batch (DESIGN.md 11.18). Hidden on idle rows. */
.kr-cancel { display: none; min-width: 30px; padding: 2px var(--sp-2); color: #c0453a; background: #fff4f2; border-color: #f3c9c3; }
.kr.running .kr-cancel { display: inline-flex; align-items: center; justify-content: center; }
@media (hover: hover) {
  .kr-btn.kr-cancel:hover { background: #ffe3de; }
}
/* While a batch runs the ×1, ×10 and Max buttons give their place to the counter and the ✕. "→ bench" stays. */
.kr.running .kr-run { display: none; }

/* equations */
.eq { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-1); font-size: 14.5px; }
.eq-term { display: inline-flex; align-items: baseline; gap: 2px; padding: 2px 7px; border-radius: 7px; background: var(--c, #f1f4fa); }
.eq-term .q { font-size: 12.5px; color: var(--ink-soft); font-weight: 800; }
.eq-term .l { font-family: var(--font-head); font-weight: 600; }
.eq-plus { color: var(--ink-faint); font-weight: 800; }
/* A clean arrow (DESIGN.md 11.6): a CSS shaft and head. Condition, catalyst and medium icons sit above its middle. */
.eq-arrow {
  display: inline-flex;
  flex-direction: column;
  align-items: stretch;
  justify-content: center;
  align-self: center;
  min-width: 34px;
  padding: 0 3px;
  margin: 0 2px;
  line-height: 1;
  border-radius: 6px;
  cursor: help;
}
.eq-arrow:hover .eq-shaft, .eq-arrow:focus-visible .eq-shaft { background: var(--ink); }
.eq-arrow:hover .eq-shaft::after, .eq-arrow:focus-visible .eq-shaft::after { border-color: var(--ink); }
.eq-over {
  display: flex;
  justify-content: center;
  align-items: flex-end;
  gap: 2px;
  min-height: 14px;
  padding: 0 4px 2px 0;
  font-size: 12.5px;
  white-space: nowrap;
}
.eq-cat {
  padding: 0 4px;
  border-radius: 5px;
  background: var(--c, #eef2f8);
  border: 1px solid rgba(38, 50, 74, 0.14);
  font-family: var(--font-head);
  font-size: 10.5px;
  font-weight: 600;
  line-height: 13px;
}
.eq-shaft {
  position: relative;
  display: block;
  height: 2px;
  margin: 3px 3px 3px 0;
  border-radius: 2px;
  background: var(--ink-soft);
}
/* An invisible twin of .eq-over below the shaft keeps the shaft level with the middle of the terms. */
.eq-arrow::after { content: ""; display: block; height: 16px; }
.eq-shaft::after {
  content: "";
  position: absolute;
  right: -2px;
  top: 50%;
  width: 6px;
  height: 6px;
  border-top: 2px solid var(--ink-soft);
  border-right: 2px solid var(--ink-soft);
  border-radius: 1px;
  transform: translateY(-50%) rotate(45deg);
}

/* ---------------------------------------------------------------- tooltip + fallback toasts */

.ui-tip {
  position: fixed;
  z-index: 1000;
  max-width: 280px;
  padding: var(--sp-2) var(--sp-3);
  border-radius: 10px;
  background: rgba(38, 50, 74, 0.94);
  color: #fff;
  font-size: 13px;
  font-weight: 700;
  pointer-events: none;
  box-shadow: 0 6px 18px rgba(0, 0, 0, 0.2);
}
.ui-tip .tip-sub { display: block; font-weight: 600; font-size: 12px; color: #c9d4ea; margin-top: 2px; }

/* Rich tooltips (DESIGN.md 11.3) */
.ui-tip.rich { max-width: 300px; padding: var(--sp-3) var(--sp-3) var(--sp-3); font-weight: 600; line-height: 1.4; }
.tt-head { display: flex; align-items: center; gap: var(--sp-3); }
.tt-title-block { flex: 1 1 auto; min-width: 0; }
.tt-tile {
  flex: none;
  min-width: 44px;
  height: 44px;
  padding: 0 5px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c, var(--cat-unknown));
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 70%);
  color: var(--ink);
  font-family: var(--font-head);
  font-size: 19px;
  font-weight: 600;
}
.tt-tile.formula { font-size: 15px; }
.tt-tile.locked { background: #5a6884; color: rgba(255, 255, 255, 0.5); }
.tt-name { font-family: var(--font-head); font-size: 16px; font-weight: 600; }
.tt-cat { font-size: 12px; color: #c9d4ea; font-weight: 700; }
.tt-props { display: flex; flex-wrap: wrap; gap: var(--sp-1); margin-top: var(--sp-2); }
.tt-badge {
  padding: 1px 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.14);
  font-size: 11.5px;
  font-weight: 800;
  white-space: nowrap;
}
.tt-badge.cat { background: rgba(255, 214, 120, 0.25); }
.tt-badge.fam { background: rgba(180, 155, 255, 0.35); }
.tt-badge.tag-acid { background: rgba(255, 140, 170, 0.32); }
.tt-badge.tag-base { background: rgba(120, 170, 255, 0.35); }
.tt-badge.tag-catalyst { background: rgba(255, 214, 120, 0.3); }
/* Kind badges for mixtures, alloys, devices and materials (DESIGN.md 11.14). Pastel with dark ink on light and dark tips. */
.tt-badge.kind, .tag.kind { color: #26324a; }
.kind-mixture { background: #ffd6e8 !important; }
.kind-alloy { background: #d6e4ff !important; }
.kind-device { background: #fff1b8 !important; }
.kind-material { background: #c9f2df !important; }
.tt-made { margin-top: var(--sp-2); font-size: 12.5px; font-weight: 700; color: #e6ecf8; line-height: 1.35; }
.tt-made.is-formula { font-family: var(--font-head); font-size: 15px; font-weight: 600; overflow-wrap: anywhere; }
.tt-en, .spot-en { display: flex; align-items: center; gap: var(--sp-2); margin-top: var(--sp-2); font-size: 11.5px; font-weight: 800; }
.en-label { color: #c9d4ea; white-space: nowrap; }
.en-meter {
  position: relative;
  flex: 1 1 auto;
  min-width: 50px;
  height: 7px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.16);
  overflow: hidden;
}
.en-meter i {
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  border-radius: 999px;
  background: linear-gradient(90deg, #ffb4a2, #fdffb6 45%, #9ad0ff 75%, #b49bff);
}
.en-val { font-variant-numeric: tabular-nums; }
.en-none { color: #c9d4ea; font-weight: 700; }
.tt-chem { margin: var(--sp-2) 0 0; font-size: 12.5px; font-weight: 600; color: #e8eef9; }
.tt-stock { margin-top: var(--sp-2); font-size: 11.5px; color: #c9d4ea; font-weight: 700; }
.tt-action { margin-top: var(--sp-2); padding-top: var(--sp-2); border-top: 1px solid rgba(255, 255, 255, 0.14); font-size: 12.5px; font-weight: 800; }
.tt-action.bench { color: #a9cbff; }
.tt-action.sell { color: #ffd98a; }
.tt-action.buy { color: #9ff0c7; }
.tt-action.info { color: #d4c5ff; }
.tt-action.muted { color: #c9d4ea; }
.tt-title { font-weight: 700; }
/* Picture thumbnail (DESIGN.md 11.16). It ends the head row and mirrors the symbol tile: same height, same corners.
   The frame is a pale wash of the item colour so the tile and the picture read as a pair. */
.tt-thumb {
  flex: none;
  width: 44px;
  height: 44px;
  padding: 2px;
  box-sizing: border-box;
  border-radius: 10px;
  background: linear-gradient(rgba(255, 248, 238, 0.82), rgba(255, 248, 238, 0.82)), var(--c, #fff8ee);
}

/* Fallback stack, used only when js/effects.js is missing. It sits where the CG.Effects stack sits. */
.ui-toasts {
  position: fixed;
  z-index: 900;
  left: var(--sp-4);
  bottom: var(--sp-4);
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: var(--sp-2);
  pointer-events: none;
}
.ui-toast {
  padding: var(--sp-3) var(--sp-4);
  border-radius: 12px;
  background: #fff;
  box-shadow: var(--shadow-lift);
  font-weight: 700;
  font-size: 14px;
  animation: toast-in 0.25s ease;
}
.ui-toast.good { border-left: 5px solid var(--good); }
.ui-toast.warn { border-left: 5px solid var(--warn); }
.ui-toast.info { border-left: 5px solid var(--bench); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

/* ---------------------------------------------------------------- modals */

.ui-backdrop {
  position: fixed;
  inset: 0;
  z-index: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: rgba(40, 52, 80, 0.35);
  backdrop-filter: blur(2px);
  animation: fade-in 0.18s ease;
}
@keyframes fade-in { from { opacity: 0; } }

.ui-modal {
  position: relative;
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  max-height: min(88vh, 860px);
  border-radius: 20px;
  background: #fffdf8;
  box-shadow: 0 20px 60px rgba(30, 40, 70, 0.3);
  animation: modal-in 0.22s ease;
}
.ui-modal.wide { width: min(1080px, 100%); }
.ui-modal.small { width: min(480px, 100%); }
@keyframes modal-in { from { opacity: 0; transform: translateY(12px) scale(0.98); } }
body.reduced .ui-modal, body.reduced .ui-backdrop { animation: none; }

.ui-modal-head {
  display: flex;
  align-items: center;
  gap: var(--sp-3);
  padding: var(--sp-4) var(--sp-5) var(--sp-3);
  border-bottom: 1px solid #f0ece2;
}
.ui-modal-head h2 { flex: 1; min-width: 0; font-size: 22px; }
.ui-close {
  flex: none;
  width: var(--tap);
  height: var(--tap);
  border: 0;
  border-radius: 50%;
  background: #f1f3f8;
  font-size: 18px;
  font-weight: 800;
  color: var(--ink-soft);
}
.ui-close:hover { background: #e4e8f1; }
.ui-modal-body { padding: var(--sp-4) var(--sp-5) var(--sp-5); overflow-y: auto; overscroll-behavior: contain; }

.tabs { display: flex; gap: var(--sp-2); margin-bottom: var(--sp-4); flex-wrap: wrap; }
.tab {
  min-height: 36px;
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: #fff;
  font-weight: 800;
  font-size: 14px;
  color: var(--ink-soft);
}
.tab[aria-selected="true"] { background: #2f3d5c; color: #fff; border-color: #2f3d5c; }

/* info sheet (touch long-press, DESIGN.md 11.10): the rich tooltip on a light card plus actions */
.sheet-tip {
  padding: var(--sp-4);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
  line-height: 1.45;
}
.sheet-tip .tt-name { font-size: 20px; }
.sheet-tip .tt-tile { min-width: 52px; height: 52px; font-size: 24px; border-radius: 12px; border: 1px solid rgba(38, 50, 74, 0.1); }
.sheet-tip .tt-tile.formula { font-size: 18px; }
.sheet-tip .tt-tile.locked { background: var(--locked); color: var(--locked-ink); }
.sheet-tip .tt-cat, .sheet-tip .tt-stock, .sheet-tip .en-label, .sheet-tip .en-none { color: var(--ink-soft); }
.sheet-tip .tt-badge { background: rgba(38, 50, 74, 0.07); color: var(--ink); font-size: 12px; padding: 2px var(--sp-2); }
.sheet-tip .tt-badge.fam { background: #ece4ff; }
.sheet-tip .tt-badge.tag-acid { background: #ffe0ea; }
.sheet-tip .tt-badge.tag-base { background: #dfeaff; }
.sheet-tip .tt-badge.cat, .sheet-tip .tt-badge.tag-catalyst { background: #fff1c9; }
.sheet-tip .tt-made { color: var(--ink); }
.sheet-tip .en-meter { background: rgba(38, 50, 74, 0.1); }
.sheet-tip .tt-chem { color: var(--ink); font-size: 15px; margin-top: var(--sp-3); }
.sheet-tip .tt-stock { font-size: 13.5px; margin-top: var(--sp-3); }
.sheet-tip .tt-props { margin-top: var(--sp-3); gap: var(--sp-2); }
.sheet-tip .tt-en { margin-top: var(--sp-3); font-size: 12.5px; }
.sheet-tip .tt-thumb { width: 52px; height: 52px; border-radius: 12px; border: 1px solid rgba(38, 50, 74, 0.1); }
.sheet-actions { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: var(--sp-2); margin-top: var(--sp-4); }
.sheet-actions .soft-btn { min-height: 44px; }
.sheet-qty { margin-top: var(--sp-4); box-shadow: none; background: #f1f3f8; }
.sheet-qty .seg { min-width: 56px; min-height: 36px; }

/* encyclopedia */
.ency { display: grid; grid-template-columns: minmax(0, 1.25fr) minmax(0, 1fr); gap: var(--sp-5); align-items: start; }
.ency-card { position: sticky; top: 0; min-width: 0; }
.ency-list { min-width: 0; }
.ency-count { margin: 0 0 var(--sp-3); }
.mini-scroll { overflow-x: auto; padding: 6px; margin: -6px; }
.mini-table {
  display: grid;
  grid-template-columns: repeat(18, minmax(0, 1fr));
  grid-template-rows: repeat(7, 26px) 6px repeat(2, 26px);
  gap: 2px;
  min-width: 470px;
}
.mini {
  --c: var(--cat-unknown);
  padding: 0;
  border: 1px solid rgba(38, 50, 74, 0.08);
  border-radius: 5px;
  background: var(--c);
  font-family: var(--font-head);
  font-size: 11px;
  font-weight: 600;
  min-width: 0;
}
.mini.is-locked { background: var(--locked); color: rgba(38, 50, 74, 0.3); border-style: dashed; }
.mini[aria-current="true"] { box-shadow: 0 0 0 2px #2f3d5c; position: relative; z-index: 1; }
.mini:hover { filter: brightness(0.96); }

.ency-tools { display: flex; flex-wrap: wrap; align-items: center; gap: var(--sp-2) var(--sp-3); margin-bottom: var(--sp-3); }
.ency-tools .ui-search { max-width: 320px; }
.ency-group { margin-bottom: var(--sp-4); }
.ency-group-head {
  display: flex;
  align-items: center;
  gap: var(--sp-2);
  margin-bottom: var(--sp-2);
  font-size: 16px;
  color: #33415f;
}
.ency-group-head .cat-count { margin-left: var(--sp-1); }
.comp-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); gap: var(--sp-2); }
.comp-tile {
  --c: #eef2f8;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  height: 60px;
  padding: var(--sp-1);
  border: 1px solid rgba(38, 50, 74, 0.1);
  border-radius: 10px;
  background: var(--c);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0.1));
  min-width: 0;
}
.comp-tile .f { font-family: var(--font-head); font-weight: 600; font-size: 15px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comp-tile .n { font-size: 10.5px; font-weight: 700; color: var(--ink-soft); max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.comp-tile.fam::after {
  content: "";
  position: absolute;
  top: 5px;
  right: 5px;
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #9b7cf0;
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
}
.comp-tile.is-locked { background: var(--locked); color: var(--locked-ink); border-style: dashed; }
.comp-tile[aria-current="true"], .comp-sil[aria-current="true"] { box-shadow: 0 0 0 2px #2f3d5c; }
/* Undiscovered compounds: compact silhouettes. */
.comp-sils { display: flex; flex-wrap: wrap; gap: var(--sp-1); margin-top: var(--sp-2); }
.comp-sil {
  width: 26px;
  height: 26px;
  padding: 0;
  border: 1px dashed rgba(38, 50, 74, 0.16);
  border-radius: 7px;
  background: var(--locked);
  color: rgba(38, 50, 74, 0.28);
  font-family: var(--font-head);
  font-size: 12px;
  font-weight: 600;
}

.card {
  padding: var(--sp-5);
  border-radius: 16px;
  background: #fff;
  box-shadow: var(--shadow);
}
.card-head { display: flex; gap: var(--sp-4); align-items: center; margin-bottom: var(--sp-3); }
.big-tile {
  --c: var(--cat-unknown);
  flex: none;
  position: relative;
  min-width: 96px;
  height: 96px;
  padding: 0 var(--sp-3);
  box-sizing: border-box;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: var(--c);
  background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.55), rgba(255, 255, 255, 0) 70%);
  border: 1px solid rgba(38, 50, 74, 0.1);
}
.big-tile .z { position: absolute; top: 6px; left: 9px; font-size: 13px; font-weight: 800; color: rgba(38, 50, 74, 0.6); }
.big-tile .sym { font-family: var(--font-head); font-size: 42px; font-weight: 600; line-height: 1; }
/* Formula tiles grow wider for long formulas. The picture beside them keeps its fixed size. */
.big-tile .sym.formula { font-size: var(--fs, 26px); white-space: nowrap; text-align: center; }
.big-tile .mass { font-size: 11px; font-weight: 700; color: rgba(38, 50, 74, 0.65); margin-top: 3px; }
.big-tile.is-locked { background: var(--locked); color: var(--locked-ink); }
.card-title { min-width: 0; }
/* Encyclopedia picture (DESIGN.md 11.16). The tile and the picture form a pair of equal height with the same corners.
   The picture frame is a pale wash of the item colour, like the tooltip thumbnail. The title sits below the pair. */
.card-head.has-art { flex-wrap: wrap; row-gap: var(--sp-3); }
.card-head.has-art .card-title { flex: 1 1 100%; }
.art-frame {
  --c: #ffe3c4;
  flex: none;
  width: 96px;
  height: 96px;
  padding: 4px;
  box-sizing: border-box;
  border-radius: 16px;
  background: linear-gradient(rgba(255, 248, 238, 0.82), rgba(255, 248, 238, 0.82)), var(--c);
  border: 1px solid rgba(38, 50, 74, 0.1);
}
.art-frame img { display: block; width: 100%; height: 100%; -webkit-user-drag: none; }
@media (hover: hover) and (prefers-reduced-motion: no-preference) {
  .art-frame:hover img { animation: art-wobble 0.7s ease-in-out; }
  body.reduced .art-frame:hover img { animation: none; }
}
@keyframes art-wobble {
  0%, 100% { transform: rotate(0deg) scale(1); }
  25% { transform: rotate(-4deg) scale(1.03); }
  55% { transform: rotate(3deg) scale(1.03); }
  80% { transform: rotate(-1.5deg) scale(1.01); }
}
.card h3 { font-size: 24px; }
.card .sub { font-size: 13.5px; font-weight: 700; color: var(--ink-soft); }
.card p { margin: var(--sp-3) 0; line-height: 1.5; }
.card p.made-of { padding: var(--sp-2) var(--sp-3); border-radius: 10px; background: #f4f7fd; font-size: 14px; }
.card p.made-of b { color: var(--ink-soft); }
.fact { padding: var(--sp-3) var(--sp-4); border-radius: 12px; background: #fff7e0; font-size: 14px; line-height: 1.5; }
.fact::before { content: "💡 "; }
.tags { display: flex; gap: var(--sp-1); flex-wrap: wrap; margin-top: var(--sp-2); }
.tag { padding: 2px var(--sp-2); border-radius: 999px; background: #eef2fa; font-size: 12px; font-weight: 800; color: var(--ink-soft); }
.tag.cat { background: #e7f3ff; }
.tag.fam { background: #ece4ff; color: #5b45a8; }
.stat-row { display: flex; flex-wrap: wrap; gap: var(--sp-2) var(--sp-4); margin-top: var(--sp-3); font-size: 13.5px; color: var(--ink-soft); }
.stat-row b { color: var(--ink); }
.recipe-box { margin-top: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: 12px; background: #f4f7fd; }
.recipe-box .eq + .eq { margin-top: var(--sp-2); }
.recipe-box .label { font-size: 12px; font-weight: 800; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: var(--sp-2); }

.notebook { display: flex; flex-direction: column; gap: var(--sp-3); }
.note {
  display: flex;
  gap: var(--sp-3);
  align-items: flex-start;
  padding: var(--sp-4);
  border-radius: 14px;
  background: #fffbea;
  border: 1px solid #f3e6b5;
  font-size: 14.5px;
  line-height: 1.5;
}
.note.done { background: #eef9f1; border-color: #cfeedb; color: var(--ink-soft); }
.note.fresh { box-shadow: 0 0 0 3px rgba(255, 200, 70, 0.6); }
.note-icon { font-size: 18px; flex: none; width: 22px; text-align: center; }
.note.done .note-icon { color: var(--good); font-weight: 800; }
.note:focus { outline: none; box-shadow: 0 0 0 3px rgba(61, 124, 240, 0.4); }
.note.fresh:focus { box-shadow: 0 0 0 3px rgba(255, 200, 70, 0.7); }
.note-main { flex: 1 1 auto; min-width: 0; }
.note-clue { color: var(--ink); }
.note.done .note-clue { color: var(--ink-soft); font-size: 13.5px; }
.note-new {
  float: right;
  margin-left: var(--sp-2);
  padding: 1px 7px;
  border-radius: 999px;
  background: #ef6b5b;
  color: #fff;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.note-why { margin-top: var(--sp-2); color: var(--ink); font-size: 14px; }
.note-why b { color: var(--good); }
.note .eq { margin-top: var(--sp-2); }
.note-exact { margin-top: var(--sp-3); padding: var(--sp-3) var(--sp-4); border-radius: 12px; background: #fff; border: 1px dashed #e8d48a; font-size: 14px; }
.note-steps { margin: var(--sp-2) 0 0; padding-left: 20px; font-size: 13.5px; color: var(--ink-soft); }
.note-steps li { margin: var(--sp-1) 0; }
.soft-btn.small { margin-top: var(--sp-3); min-height: 32px; padding: var(--sp-1) var(--sp-3); font-size: 13px; border-radius: 10px; }
.soft-btn.reveal { background: #fff3c4; border-color: #f0dc8a; }
.labnotes { margin-bottom: var(--sp-4); padding: var(--sp-4); border-radius: 14px; background: #fff; box-shadow: var(--shadow); }
.labnotes-title { font-weight: 800; margin-bottom: var(--sp-2); }
.bar { height: 14px; border-radius: 999px; background: #edf0f6; overflow: hidden; }
.bar > span { display: block; height: 100%; border-radius: 999px; background: linear-gradient(90deg, #9ad0ff, #b49bff); transition: width 0.4s ease; }

/* Chemistry 101 lessons (DESIGN.md 11.13) */
.lessons { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: var(--sp-3); }
.lesson-item {
  position: relative;
  display: grid;
  grid-template-columns: 44px minmax(0, 1fr);
  gap: var(--sp-3);
  align-items: center;
  min-height: 72px;
  padding: var(--sp-3) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: 14px;
  background: #fff;
  text-align: left;
  box-shadow: 0 1px 3px rgba(38, 50, 74, 0.06);
}
@media (hover: hover) {
  .lesson-item:hover { transform: translateY(-1px); box-shadow: var(--shadow); }
}
.lesson-icon {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  background: linear-gradient(180deg, #eef4ff, #dfe9ff);
  font-size: 22px;
}
.lesson-item.read .lesson-icon { background: linear-gradient(180deg, #eaf8ef, #d4f1df); }
.lesson-title { display: block; font-family: var(--font-head); font-weight: 600; font-size: 15.5px; line-height: 1.25; }
.lesson-sum { display: block; margin-top: 2px; font-size: 12.5px; color: var(--ink-soft); line-height: 1.35; }
.lesson-num { color: var(--ink-faint); font-weight: 800; margin-right: var(--sp-1); }
.lesson-check { color: var(--good); font-weight: 800; margin-left: var(--sp-1); }
.lesson-new {
  position: absolute;
  top: var(--sp-2);
  right: var(--sp-2);
  padding: 1px 7px;
  border-radius: 999px;
  background: #7a5bd6;
  color: #fff;
  font-size: 10.5px;
  font-weight: 800;
  letter-spacing: 0.5px;
}
.lesson-intro { margin: 0 0 var(--sp-4); color: var(--ink-soft); font-size: 14px; }
.lesson-view { max-width: 720px; margin: 0 auto; }
.lesson-back { margin-bottom: var(--sp-4); }
.lesson-head { display: flex; align-items: center; gap: var(--sp-3); margin-bottom: var(--sp-4); }
.lesson-head .lesson-icon { width: 56px; height: 56px; font-size: 28px; border-radius: 16px; flex: none; }
.lesson-head h3 { font-size: 24px; line-height: 1.2; }
.lesson-head .sub { font-size: 13px; font-weight: 700; color: var(--ink-faint); }
.lesson-diagram {
  display: flex;
  justify-content: center;
  margin: 0 0 var(--sp-4);
  padding: var(--sp-4);
  border-radius: 16px;
  background: #f4f8ff;
  color: #3a4a66;
}
.lesson-diagram svg { display: block; width: 100%; max-width: 420px; height: auto; max-height: 260px; }
.lesson-body p { margin: 0 0 var(--sp-3); font-size: 16px; line-height: 1.6; }
.lesson-body b { color: #2c3b5c; }
.lchip {
  display: inline-flex;
  align-items: baseline;
  gap: 3px;
  padding: 0 7px;
  border: 1px solid rgba(38, 50, 74, 0.14);
  border-radius: 7px;
  background: var(--c, #eef2f8);
  font-family: var(--font-head);
  font-weight: 600;
  font-size: 0.95em;
  line-height: 1.5;
  vertical-align: baseline;
}
button.lchip { cursor: pointer; }
.lchip small { font-family: var(--font-body); font-size: 0.78em; font-weight: 700; color: var(--ink-soft); }
.lchip.locked { background: var(--locked); color: var(--locked-ink); border-style: dashed; cursor: default; }
.lesson-ingame {
  margin: var(--sp-4) 0;
  padding: var(--sp-4);
  border-radius: 14px;
  background: #e9f6ff;
  border-left: 5px solid var(--bench);
  font-size: 15px;
  line-height: 1.55;
}
.lesson-ingame b { display: block; margin-bottom: var(--sp-1); font-family: var(--font-head); font-weight: 600; color: #2d6fd6; }
.lesson-example { margin: var(--sp-4) 0; padding: var(--sp-3) var(--sp-4); border-radius: 14px; background: #f4f7fd; }
.lesson-example .label { font-size: 12px; font-weight: 800; color: var(--ink-faint); text-transform: uppercase; letter-spacing: 0.5px; margin-bottom: var(--sp-2); }
.lesson-quiz { margin: var(--sp-4) 0; padding: var(--sp-4); border-radius: 14px; background: #fffbea; border: 1px solid #f3e6b5; }
.lesson-quiz .q { font-weight: 800; margin-bottom: var(--sp-3); }
.quiz-options { display: grid; gap: var(--sp-2); }
.quiz-opt {
  min-height: var(--tap);
  padding: var(--sp-2) var(--sp-4);
  border: 1px solid var(--line);
  border-radius: 12px;
  background: #fff;
  font-weight: 700;
  text-align: left;
}
.quiz-opt.right { background: #e2f7ea; border-color: #8fd7ad; }
.quiz-opt.wrong { background: #ffe9e4; border-color: #f2b2a4; }
.quiz-opt:disabled { cursor: default; opacity: 1; }
.quiz-explain { margin-top: var(--sp-3); font-size: 14.5px; line-height: 1.5; }
.lesson-nav { display: flex; justify-content: space-between; gap: var(--sp-2); margin-top: var(--sp-5); }
.lesson-nav .soft-btn { flex: 0 1 auto; min-height: 44px; max-width: 48%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* achievements */
.ach-summary { margin-bottom: var(--sp-3); font-weight: 800; color: var(--ink-soft); }
.ach-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--sp-3); }
.ach {
  display: flex;
  gap: var(--sp-3);
  padding: var(--sp-3);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
}
.ach-icon {
  flex: none;
  width: 44px;
  height: 44px;
  border-radius: 12px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 24px;
  background: linear-gradient(180deg, #fff3c4, #ffd77a);
}
.ach-name { font-family: var(--font-head); font-weight: 600; font-size: 15.5px; }
.ach-desc { font-size: 12.5px; color: var(--ink-soft); margin-top: 2px; }
.ach-reward { font-size: 12px; font-weight: 800; color: #9a7420; margin-top: var(--sp-1); }
.ach.locked { background: #f5f6f9; box-shadow: none; border: 1px dashed #d9dee8; }
.ach.locked .ach-icon { background: #e6e9ef; filter: grayscale(1); opacity: 0.6; }
.ach.locked .ach-name { color: var(--ink-faint); }

/* shop */
.shop-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: var(--sp-3); }
.shop-card {
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  padding: var(--sp-4);
  border-radius: 14px;
  background: #fff;
  box-shadow: var(--shadow);
}
.shop-card .icon { font-size: 30px; }
.shop-card h4 { font-size: 17px; }
.shop-card p { margin: 0; font-size: 13.5px; color: var(--ink-soft); flex: 1; }
.shop-card .owned { font-weight: 800; color: var(--good); }
.price::after { content: " 🪙"; }

.gen-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.gen-row {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) auto;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-3);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(38, 50, 74, 0.08);
}
.gen-tile {
  --c: var(--cat-unknown);
  width: 46px;
  height: 46px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--c);
  font-family: var(--font-head);
  font-size: 20px;
  font-weight: 600;
  border: 1px solid rgba(38, 50, 74, 0.1);
}
.gen-tile.is-locked { background: var(--locked); color: var(--locked-ink); }
.gen-name { font-weight: 800; }
.gen-info { font-size: 13px; color: var(--ink-soft); }
.gen-row.locked { background: #f6f7fa; box-shadow: none; }

.assist-top { display: flex; align-items: center; justify-content: space-between; gap: var(--sp-3); flex-wrap: wrap; margin-bottom: var(--sp-3); }
.assist-list { display: flex; flex-direction: column; gap: var(--sp-2); }
.assist {
  display: grid;
  grid-template-columns: 40px minmax(0, 1fr) auto;
  gap: var(--sp-3);
  align-items: center;
  padding: var(--sp-3);
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(38, 50, 74, 0.08);
}
.assist-face { font-size: 28px; text-align: center; }
.assist-status { font-size: 12px; font-weight: 700; color: var(--ink-faint); margin-top: var(--sp-1); }
.assist-status.ran { color: var(--good); }
.assist-status.waiting { color: var(--warn); }
.ui-select { max-width: 100%; min-height: 34px; padding: 0 var(--sp-2); border: 1px solid var(--line); border-radius: 10px; background: #fff; font-weight: 700; }
.toggle { display: inline-flex; align-items: center; gap: var(--sp-2); font-size: 13px; font-weight: 800; color: var(--ink-soft); white-space: nowrap; cursor: pointer; }
.toggle input { width: 18px; height: 18px; margin: 0; accent-color: var(--buy); }

/* settings, welcome, away */
.setting-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--sp-3);
  padding: var(--sp-3) 0;
  border-bottom: 1px solid #f0ece2;
}
.setting-row:last-child { border-bottom: 0; }
.setting-row .desc { font-size: 13px; color: var(--ink-soft); }
.chat-seg { flex: none; box-shadow: none; background: #f1f3f8; }
.chat-seg .seg { padding: 5px 9px; font-size: 13px; }
.chat-seg .seg[aria-pressed="true"] { background: var(--bench); }
.danger-zone { margin-top: var(--sp-3); padding: var(--sp-4); border-radius: 12px; background: #fff1ee; }
.danger-zone p { margin: 0 0 var(--sp-3); font-size: 13.5px; }
.btn-row { display: flex; gap: var(--sp-2); flex-wrap: wrap; justify-content: flex-end; margin-top: var(--sp-4); }

.welcome-sub { margin: var(--sp-2) 0 var(--sp-3); font-size: 14px; }
.welcome-lab { list-style: none; margin: 0 0 var(--sp-3); padding: 0; display: grid; gap: var(--sp-2); }
.welcome-lab li { display: grid; grid-template-columns: 118px 1fr; gap: var(--sp-3); align-items: baseline; padding: var(--sp-2) var(--sp-3); border-radius: 10px; background: #fff; box-shadow: 0 1px 3px rgba(38, 50, 74, 0.08); font-size: 13.5px; }
.welcome-lab b { font-family: var(--font-head); font-size: 15px; font-weight: 600; white-space: nowrap; }
.welcome-modes { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: var(--sp-2); margin: 0 0 var(--sp-3); }
.welcome-mode { padding: var(--sp-2) var(--sp-3); border-radius: 10px; background: #f6f8fc; font-size: 12.5px; color: var(--ink-soft); }
.welcome-mode b { display: block; font-family: var(--font-head); font-size: 14.5px; font-weight: 600; color: var(--ink); }
.welcome-tip { padding: var(--sp-3) var(--sp-4); border-radius: 12px; background: #e9f6ff; font-size: 14.5px; }
.welcome-how { margin-top: var(--sp-1); font-weight: 800; color: #2d6fd6; }
.lead { font-size: 15.5px; margin: 0 0 var(--sp-2); }

.away-gains { display: flex; flex-wrap: wrap; gap: var(--sp-2); margin: var(--sp-2) 0 var(--sp-3); }
.away-big { font-family: var(--font-head); font-size: 20px; margin-bottom: var(--sp-2); }

/* ---------------------------------------------------------------- responsive */

/* Desktop: the game fills the window. The shelf and the known reactions scroll inside their panels. */
@media (min-width: 1180px) and (min-height: 600px) {
  #app { height: 100vh; }
  .main { flex: 1 1 0; }
}

/* The narrowest two-column windows have a small spotlight box. The legend stays and the intro line goes. */
@media (min-width: 1180px) and (max-width: 1259px) {
  .spot-intro p { display: none; }
}
/* Short desktop windows: the legend is enough in the spotlight box. */
@media (min-width: 1180px) and (max-height: 800px) {
  .spot-intro p { display: none; }
  .mode-hint { font-size: 13px; }
}

/* Icon-only top buttons once their labels would squeeze the title. */
@media (max-width: 1279px) {
  .top-btn-text { display: none; }
  .top-btn { min-width: var(--tap); }
  #btnHint .top-btn-text { display: inline; font-size: 0; }
  #btnHint .top-btn-text .hint-price { font-size: 12px; }
}
@media (max-width: 1179px) {
  .topbar { padding-left: var(--sp-4); padding-right: var(--sp-4); }
}
@media (max-width: 900px) {
  .coins-label { display: none; }
}

@media (max-width: 1100px) {
  .top-btn-text { display: none; }
  .top-btn { min-width: var(--tap); }
  #btnHint .top-btn-text { display: inline; font-size: 0; }
  #btnHint .top-btn-text .hint-price { font-size: 12px; }
  .ency { grid-template-columns: 1fr; gap: var(--sp-4); }
  .ency-card { position: static; order: -1; }
}

/* Tablets and narrow windows: one column. The table comes first and the lab right below it. */
@media (max-width: 1179px) {
  .main {
    --cell-h: clamp(30px, calc((100vw - 90px) / 18), 52px);
    display: flex;
    flex-direction: column;
    gap: var(--sp-4);
    padding: var(--sp-4);
  }
  .col { display: contents; }
  .controls { order: 1; }
  .table-area { order: 2; }
  .lab-panel { order: 3; }
  .shelf-panel { order: 4; }
  .known-panel { order: 5; }
  .shelf-panel, .known-panel { flex: none; }
  .shelf, .known { flex: none; max-height: 320px; }
}

@media (max-width: 1179px) and (min-width: 700px) {
  /* Shelf and known reactions side by side under the lab. */
  .main { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); }
  .controls, .table-area, .lab-panel { grid-column: 1 / -1; }
  .lab-panel #lab { max-width: 760px; margin: 0 auto; width: 100%; }
}

/* Small landscape screens such as a 1024 x 768 laptop.
   The table spans the full width with short cells. The lab sits right under it. The flask stays on screen.
   The shelf and the known reactions stack beside the lab. */
@media (max-width: 1179px) and (min-width: 700px) and (orientation: landscape) {
  .main {
    --cell-h: clamp(30px, calc((100vh - 480px) / 9), 46px);
    grid-template-columns: minmax(0, 1.2fr) minmax(0, 1fr);
    grid-template-areas: "controls controls" "table table" "lab shelf" "lab known";
    align-items: start;
  }
  .controls { grid-area: controls; }
  .table-area { grid-area: table; }
  .lab-panel { grid-area: lab; }
  .shelf-panel { grid-area: shelf; }
  .known-panel { grid-area: known; }
  .shelf { max-height: 150px; }
  .known { max-height: 320px; }
}

/* ---------------------------------------------------------------- touch lab (DESIGN.md 11.17, js/touchlab.js) */

/* Tube and beaker pickers: a compact bottom sheet on every touch device. */
.ui-backdrop:has(> .ui-modal.picker) { align-items: flex-end; padding-bottom: 0; }
.ui-modal.small.picker {
  width: min(560px, 100%);
  height: auto;
  max-height: min(80vh, 660px);
  border-radius: 24px 24px 0 0;
  animation: picker-in 0.28s cubic-bezier(0.2, 0.9, 0.3, 1.15);
}
.ui-modal.picker::before {
  content: "";
  position: absolute;
  top: 7px;
  left: 50%;
  width: 44px;
  height: 5px;
  margin-left: -22px;
  border-radius: 999px;
  background: rgba(38, 50, 74, 0.16);
}
@keyframes picker-in { from { opacity: 0.4; transform: translateY(45%); } }
body.reduced .ui-modal.picker { animation: none; }
.ui-modal.picker .ui-modal-head { padding: var(--sp-5) var(--sp-4) var(--sp-2); padding-top: 22px; border-bottom: 0; }
.ui-modal.picker .ui-modal-head h2 { font-size: 20px; }
.ui-modal-body.pk-body { padding: var(--sp-1) var(--sp-4) calc(var(--sp-5) + env(safe-area-inset-bottom)); }
.pk-intro { margin: 0 0 var(--sp-3); color: var(--ink-soft); font-size: 14.5px; line-height: 1.4; }
.pk-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(76px, 1fr)); gap: var(--sp-2); }
.pk-tile {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-width: 0;
  padding: var(--sp-2) 2px var(--sp-2);
  border: 2px solid transparent;
  border-radius: 16px;
  background: #fff;
  box-shadow: 0 1px 3px rgba(38, 50, 74, 0.12), 0 4px 12px rgba(38, 50, 74, 0.06);
  font: inherit;
  color: var(--ink);
  transition: transform 0.12s ease, box-shadow 0.12s ease;
  -webkit-touch-callout: none;
  user-select: none;
}
.pk-tile:active { transform: scale(0.95); }
.pk-tile:focus-visible { outline: 3px solid #3d7cf0; outline-offset: 2px; }
.pk-pic {
  display: flex;
  align-items: center;
  justify-content: center;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: radial-gradient(circle at 34% 30%, #fff 0, var(--c) 72%);
  box-shadow: inset 0 0 0 2px rgba(58, 74, 102, 0.16);
  overflow: hidden;
}
.pk-art { width: 42px; height: 42px; }
.pk-sym { font-family: var(--font-head); font-size: 22px; font-weight: 600; color: #26324a; }
.pk-sym.is-long { font-size: 15px; }
.pk-label { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pk-label { margin-top: 2px; font-family: var(--font-head); font-size: 14px; font-weight: 600; }
/* Long names wrap to two centred lines. Every name keeps room for two lines. The counts then line up across a row. */
.pk-name {
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  line-clamp: 2;
  max-width: 100%;
  min-height: 2.4em;
  margin-bottom: 3px;
  overflow: hidden;
  overflow-wrap: break-word;
  font-size: 10.5px;
  font-weight: 700;
  line-height: 1.2;
  text-align: center;
  color: var(--ink-soft);
}
.pk-count { margin-top: auto; padding: 0 var(--sp-2); border-radius: 999px; background: #eef2f8; font-size: 12px; font-weight: 800; font-variant-numeric: tabular-nums; white-space: nowrap; }
.pk-tile.is-in { border-color: #3d7cf0; background: #f3f7ff; box-shadow: 0 0 0 4px rgba(61, 124, 240, 0.14), 0 4px 12px rgba(38, 50, 74, 0.08); }
.pk-tile.is-in .pk-count { background: #3d7cf0; color: #fff; }
.pk-tile.is-out { opacity: 0.45; box-shadow: none; }
/* Beaker tiles: the picture sits in a little pool of the medium colour. Pink for acids, blue for bases. */
.pk-acid { --liq: #ff9cc4; }
.pk-base { --liq: #8fc2ff; }
.pk-tile.is-acid .pk-pic, .pk-tile.is-base .pk-pic {
  border-radius: 10px 10px 20px 20px;
  background: linear-gradient(180deg, #fffdf8 0 50%, var(--liq) 50% 100%);
}
.pk-section + .pk-section { margin-top: var(--sp-4); }
.pk-head { display: flex; align-items: center; gap: var(--sp-2); margin: 0 0 var(--sp-2); font-size: 16px; }
.pk-drop { width: 14px; height: 14px; border-radius: 50% 50% 50% 0; transform: rotate(-45deg); background: var(--liq); box-shadow: inset 0 0 0 2px rgba(58, 74, 102, 0.2); }
.pk-note { margin: var(--sp-1) 0 0; color: var(--ink-soft); font-size: 14px; }
.pk-actions { display: flex; flex-wrap: wrap; align-items: center; justify-content: center; gap: var(--sp-2); margin-top: var(--sp-4); }
.pk-actions .soft-btn { flex: 1 1 auto; min-height: 44px; }
.pk-emptystate { padding: var(--sp-2) var(--sp-2) var(--sp-1); text-align: center; }
.pk-empty-icon { display: inline-block; font-size: 44px; line-height: 1.1; animation: pk-bob 2.6s ease-in-out infinite; }
.pk-empty-title { margin: var(--sp-2) 0 var(--sp-1); font-family: var(--font-head); font-size: 18px; font-weight: 600; }
.pk-empty-text { margin: 0; color: var(--ink-soft); line-height: 1.45; }
@keyframes pk-bob { 0%, 100% { transform: translateY(0) rotate(-4deg); } 50% { transform: translateY(-5px) rotate(4deg); } }
body.reduced .pk-empty-icon { animation: none; }
@media (prefers-reduced-motion: reduce) {
  .ui-modal.picker, .pk-empty-icon { animation: none; }
}

/* The quick tray shows on phones only. */
.qtray { display: none; }

/* ---------------------------------------------------------------- phones (DESIGN.md 11.10) */

/* The lab is pinned at the top. A sticky tab bar under it switches between Elements, Shelf and Reactions.
   The page itself never scrolls: .main is the scroll box and the lab plus the tab bar stick to its top. */
@media (max-width: 699px) {
  body { font-size: 15px; }
  #app { height: 100vh; height: 100dvh; min-height: 0; overflow: hidden; }

  /* Top bar: icons only. */
  .topbar { flex-wrap: nowrap; gap: var(--sp-2); padding: var(--sp-2) var(--sp-3); padding-top: max(var(--sp-2), env(safe-area-inset-top)); }
  .brand { flex: none; }
  .brand h1 { display: none; }
  .brand-logo { width: 30px; height: 30px; }
  .coins { flex: none; padding: var(--sp-1) var(--sp-3); gap: var(--sp-1); }
  .coins-label { display: none; }
  .coins-icon { font-size: 17px; }
  .coins-value { font-size: 18px; }
  .top-actions { flex: 1 1 auto; gap: var(--sp-2); justify-content: flex-end; min-width: 0; }
  .top-btn { width: var(--tap); height: var(--tap); min-width: var(--tap); padding: 0; flex: none; }
  .top-btn-text, #btnHint .top-btn-text { display: none; }
  .top-btn > span:first-child { font-size: 18px; }

  .main {
    flex: 1 1 0;
    display: flex;
    flex-direction: column;
    gap: var(--sp-3);
    min-height: 0;
    overflow-x: hidden;
    overflow-y: auto;
    overscroll-behavior: contain;
    -webkit-overflow-scrolling: touch;
    padding: 0 var(--sp-3) calc(var(--sp-6) + env(safe-area-inset-bottom));
  }
  .col { display: contents; }
  /* Children of the scroll box keep their height. Without this, boxes with their own overflow shrink to nothing. */
  .main > *, .col > * { flex-shrink: 0; }

  /* The pinned lab and the tab bar. */
  .lab-panel {
    order: 1;
    position: sticky;
    top: 0;
    z-index: 5;
    margin: 0 calc(var(--sp-3) * -1);
    padding: var(--sp-2) var(--sp-2) 0;
    border-radius: 0 0 18px 18px;
    background: linear-gradient(180deg, #fbf7ef, #f3f6fb);
    box-shadow: 0 6px 16px rgba(38, 50, 74, 0.12);
  }
  .lab-panel #lab { max-height: 42vh; max-height: 42svh; }
  .ptabs {
    display: flex;
    gap: var(--sp-1);
    padding: var(--sp-2) var(--sp-1);
  }
  .ptab {
    flex: 1 1 0;
    min-width: 0;
    overflow: hidden;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    min-height: var(--tap);
    padding: 0 var(--sp-2);
    border: 0;
    border-radius: 12px;
    background: transparent;
    font-family: var(--font-head);
    font-size: 15px;
    font-weight: 600;
    color: var(--ink-soft);
    white-space: nowrap;
  }
  .ptab[aria-selected="true"] { background: #2f3d5c; color: #fff; box-shadow: 0 2px 6px rgba(38, 50, 74, 0.2); }
  .ptab-count:not(:empty) {
    padding: 0 6px;
    border-radius: 999px;
    background: rgba(38, 50, 74, 0.1);
    font-family: var(--font-body);
    font-size: 11.5px;
    font-weight: 800;
  }
  .ptab[aria-selected="true"] .ptab-count:not(:empty) { background: rgba(255, 255, 255, 0.22); }

  /* Quick tray (DESIGN.md 11.17): up to 8 recently used items between the lab and the tab bar. */
  .qtray:not([hidden]) { display: block; padding: 6px 0 0; }
  .qtray:not([hidden]) + .ptabs { padding-top: var(--sp-1); }
  .qtray-list {
    display: flex;
    justify-content: flex-start;
    justify-content: safe center;
    gap: var(--sp-1);
    padding: 2px 6px 2px 2px;
    overflow-x: auto;
    overscroll-behavior-x: contain;
    scrollbar-width: none;
  }
  .qtray-list::-webkit-scrollbar { display: none; }
  .qt-ball {
    position: relative;
    flex: none;
    width: var(--tap);
    height: var(--tap);
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: radial-gradient(circle at 34% 30%, #fff 0, var(--c) 70%);
    box-shadow: inset 0 0 0 2px rgba(58, 74, 102, 0.32), 0 2px 4px rgba(38, 50, 74, 0.16);
    transition: opacity 0.25s ease, transform 0.12s ease;
    -webkit-touch-callout: none;
    user-select: none;
  }
  .qt-ball:active { transform: scale(0.88); }
  .qt-face { position: absolute; inset: 3px; display: flex; align-items: center; justify-content: center; border-radius: 50%; overflow: hidden; }
  .qt-label { font-family: var(--font-head); font-size: 17px; font-weight: 600; line-height: 1; color: #26324a; white-space: nowrap; }
  .qt-label.is-mid { font-size: 12.5px; }
  .qt-label.is-long { font-size: 9.5px; }
  .qt-art { width: 30px; height: 30px; }
  .qt-count {
    position: absolute;
    right: -4px;
    bottom: -3px;
    min-width: 18px;
    height: 16px;
    padding: 0 4px;
    border-radius: 999px;
    background: #2f3d5c;
    color: #fff;
    font-size: 10.5px;
    font-weight: 800;
    line-height: 16px;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }
  .qt-ball.is-empty { opacity: 0.4; box-shadow: inset 0 0 0 2px rgba(58, 74, 102, 0.2); }
  .qt-ball.is-empty .qt-count { background: #8e98ad; }
  .qt-bump { animation: qt-bump 0.32s ease-out; }
  @keyframes qt-bump { 40% { transform: scale(1.16); } 70% { transform: scale(0.95); } }
  body.reduced .qt-bump { animation: none; }

  /* Content under the tabs. */
  .controls { order: 2; gap: var(--sp-2); flex-wrap: nowrap; overflow-x: auto; margin: 0 calc(var(--sp-3) * -1); padding: var(--sp-1) var(--sp-3); scrollbar-width: none; }
  .controls::-webkit-scrollbar { display: none; }
  .controls .seg-group { flex: none; }
  .controls .seg { min-height: var(--tap); padding: 0 var(--sp-3); }
  .controls .seg-label { display: none; }
  .controls .mode-btn > span[aria-hidden] { display: none; }
  .controls .seg-group:first-child { flex: 1 1 auto; }
  .controls .mode-btn { flex: 1 1 0; padding: 0 var(--sp-2); }
  .controls .qty-btn { display: none; }
  .controls .qty-cycle { display: inline-flex; align-items: center; justify-content: center; min-width: 60px; background: #2f3d5c; color: #fff; }
  .controls { overflow-x: visible; }
  .mode-hint { display: none; }
  .table-area { order: 3; padding: var(--sp-3); }
  .shelf-panel { order: 4; }
  .known-panel { order: 5; }
  .shelf-panel, .known-panel { flex: none; min-height: 0; padding: var(--sp-3); }
  .shelf, .known { flex: none; max-height: none; overflow: visible; }

  .main[data-ptab="elements"] .shelf-panel,
  .main[data-ptab="elements"] .known-panel,
  .main[data-ptab="shelf"] .table-area,
  .main[data-ptab="shelf"] .known-panel,
  .main[data-ptab="reactions"] .table-area,
  .main[data-ptab="reactions"] .shelf-panel,
  .main[data-ptab="reactions"] .controls { display: none; }

  /* Elements tab: "My elements" big tiles, or the full table in its own horizontal scroll box. */
  .el-view { display: flex; width: 100%; margin-bottom: var(--sp-3); box-shadow: none; background: #eef2f8; }
  .el-view .seg { flex: 1 1 0; min-height: var(--tap); }
  .el-view .seg[aria-pressed="true"] { background: #2f3d5c; }
  .table-area[data-view="mine"] .table-scroll { display: none; }
  .table-area[data-view="mine"] .myel { display: grid; }
  .myel { grid-template-columns: repeat(auto-fill, minmax(86px, 1fr)); gap: var(--sp-2); }
  .my-tile {
    --c: var(--cat-unknown);
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 2px;
    min-width: 0;
    height: 92px;
    padding: var(--sp-3) var(--sp-1) var(--sp-2);
    border: 1px solid rgba(38, 50, 74, 0.1);
    border-radius: 14px;
    background: var(--c);
    background-image: linear-gradient(180deg, rgba(255, 255, 255, 0.5), rgba(255, 255, 255, 0) 65%);
    box-shadow: 0 1px 3px rgba(38, 50, 74, 0.12);
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
  }
  .my-tile:active { transform: scale(0.96); }
  .my-z { position: absolute; top: 5px; left: 8px; font-size: 11px; font-weight: 800; color: rgba(38, 50, 74, 0.55); }
  .my-sym { font-family: var(--font-head); font-size: 28px; font-weight: 600; line-height: 1; }
  .my-name { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 11.5px; font-weight: 700; color: rgba(38, 50, 74, 0.75); }
  .my-count { font-size: 13px; font-weight: 800; font-variant-numeric: tabular-nums; }
  .my-tile.zero .my-count { color: rgba(38, 50, 74, 0.4); }

  .table-scroll { margin: 0 calc(var(--sp-3) * -1); padding: var(--sp-1) var(--sp-3) var(--sp-2); overscroll-behavior-x: contain; }
  .main { --cell-h: 40px; }
  .ptable {
    --cell-gap: 3px;
    grid-template-columns: repeat(18, 40px);
    width: max-content;
    min-width: 0;
  }
  .pt-spot { display: none; }

  /* Shelf and reactions tabs. */
  .panel-head { margin-bottom: var(--sp-3); }
  .panel-tools { flex: 1 1 100%; justify-content: flex-start; }
  /* Shelf: "Hide empty" moves up beside the title. The search box gets its own row. */
  .shelf-panel .panel-tools { display: contents; }
  .shelf-panel .panel-head .small-toggle { order: 1; }
  .shelf-panel .panel-head .ui-search { order: 2; }
  .ui-search { flex: 1 1 100%; max-width: none; height: var(--tap); font-size: 16px; }
  .small-select, .panel-filters .small-select { flex: 1 1 40%; height: var(--tap); max-width: none; font-size: 14px; }
  .panel-filters { margin-top: 0; }
  .small-toggle { min-height: var(--tap); }
  .cat-chips { margin: 0 calc(var(--sp-3) * -1) var(--sp-3); padding: 2px var(--sp-3) var(--sp-1); scrollbar-width: none; }
  .cat-chips::-webkit-scrollbar { display: none; }
  .cat-chip { min-height: 36px; }
  .cchip { min-height: var(--tap); padding: var(--sp-1) var(--sp-3) var(--sp-1) var(--sp-2); }
  .kr { padding: var(--sp-3); }
  /* One line of controls under the equation, idle or running. The row height stays the same. */
  .kr-buttons { margin-left: 0; width: 100%; flex-wrap: nowrap; }
  .kr-btn { flex: none; min-height: var(--tap); min-width: 44px; padding: 2px var(--sp-2); font-size: 13.5px; }
  .kr-btn.bench { margin-left: auto; }
  .kr-max {
    flex: 1 1 0;
    min-width: 0;
    margin: 0;
    line-height: 1.25;
    overflow: hidden;
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
  }

  /* Modals become full-screen sheets. */
  .ui-backdrop { padding: 0; align-items: stretch; }
  .ui-modal, .ui-modal.wide, .ui-modal.small {
    width: 100%;
    max-height: none;
    height: 100%;
    border-radius: 0;
  }
  .ui-modal-head { padding: var(--sp-3) var(--sp-4); padding-top: max(var(--sp-3), env(safe-area-inset-top)); }
  .ui-modal-head h2 { font-size: 20px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .ui-modal-body { flex: 1 1 auto; padding: var(--sp-4) var(--sp-4) calc(var(--sp-6) + env(safe-area-inset-bottom)); }
  .tab { min-height: var(--tap); }
  .tabs { flex-wrap: nowrap; overflow-x: auto; margin: 0 calc(var(--sp-4) * -1) var(--sp-4); padding: 0 var(--sp-4); scrollbar-width: none; }
  .tabs::-webkit-scrollbar { display: none; }
  .tab { flex: none; }
  .soft-btn { min-height: var(--tap); }
  .card { padding: var(--sp-4); }
  .card-head { gap: var(--sp-3); }
  .big-tile { min-width: 76px; height: 76px; padding: 0 var(--sp-2); }
  .big-tile .sym { font-size: 34px; }
  .big-tile .sym.formula { font-size: calc(var(--fs, 26px) * 0.8); }
  .art-frame { width: 76px; height: 76px; padding: 3px; }
  .card h3 { font-size: 21px; }
  .mini-table { grid-template-rows: repeat(7, 32px) 6px repeat(2, 32px); min-width: 620px; gap: 3px; }
  .mini { font-size: 12.5px; }
  .comp-grid { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
  .comp-sil { width: 32px; height: 32px; }
  .ach-grid, .shop-grid { grid-template-columns: 1fr; }
  .gen-row { grid-template-columns: 40px minmax(0, 1fr); }
  .gen-row > :last-child { grid-column: 1 / -1; }
  .gen-tile { width: 40px; height: 40px; }
  .assist { grid-template-columns: 36px minmax(0, 1fr); }
  .assist > .toggle { grid-column: 1 / -1; min-height: var(--tap); }
  .setting-row { flex-wrap: wrap; }
  .welcome-modes { grid-template-columns: 1fr 1fr; }
  .welcome-lab li { grid-template-columns: 1fr; gap: 0; }
  .lessons { grid-template-columns: 1fr; }
  .lesson-head h3 { font-size: 21px; }
  .lesson-body p { font-size: 15.5px; }
}

/* The narrowest phones: six 40 px buttons and the coins only just fit. The logo makes room. */
@media (max-width: 400px) {
  .ptab { gap: var(--sp-1); font-size: 14.5px; }
  .ptab > span[aria-hidden] { display: none; }
  .brand { display: none; }
  .topbar { gap: var(--sp-2); padding-left: var(--sp-2); padding-right: var(--sp-2); }
  .coins { padding: var(--sp-1) var(--sp-2); }
  /* Six 40 px buttons with 8 px gaps overflow onto the coins at 375 px. 4 px gaps fit beside a five digit count. */
  .top-actions { gap: var(--sp-1); }
}
@media (max-width: 370px) {
  .top-actions { gap: var(--sp-1); }
  .coins-icon { display: none; }
}

/* Very short phones in landscape: the pinned lab gets smaller still. */
@media (max-width: 699px) and (max-height: 480px) {
  .lab-panel #lab { max-height: 36vh; }
}

/* Known Reactions density (round 3). A wide panel fits the equation and its buttons on one line.
   A narrow panel or a phone keeps two lines: the equation first, then the buttons. */
.known { container-type: inline-size; container-name: known; }
@container known (min-width: 520px) {
  .kr { flex-wrap: nowrap; }
  .kr > .eq { flex: 1 1 auto; min-width: 0; }
  .kr-buttons { flex: 0 0 auto; flex-wrap: nowrap; width: auto; margin-left: auto; }
  .kr-max { flex: none; order: 0; margin: 0 var(--sp-1); white-space: nowrap; }
  .kr-btn.bench { margin-left: 0; }
}

/* Round 6 (DESIGN.md 11.19). The bench takes one unit per tap. The quantity picker only matters for selling and buying. */
body.mode-bench .qty-group,
body.mode-info .qty-group { display: none; }
.mixbar { display: none; }

/* Round 6 phone density. The pinned lab is the star. The lists below it shrink so more items fit on screen. */
@media (max-width: 699px) {
  .main { gap: var(--sp-2); padding: 0 var(--sp-2) calc(var(--sp-4) + env(safe-area-inset-bottom)); }
  .lab-panel { margin: 0 calc(var(--sp-2) * -1); padding: var(--sp-1) var(--sp-1) 0; }
  .ptabs { padding: var(--sp-1) var(--sp-1) 6px; }
  .ptab { min-height: 36px; font-size: 14.5px; }

  /* Mode and quantity row. */
  .controls { margin: 0 calc(var(--sp-2) * -1); padding: 2px var(--sp-2); }
  .controls .seg { min-height: 36px; }
  .controls .qty-cycle { min-width: 56px; }

  /* Sell and Buy modes tint the lists, so a tap that spends or earns coins never comes as a surprise. */
  body.mode-sell .table-area, body.mode-sell .shelf-panel,
  body.mode-buy .table-area, body.mode-buy .shelf-panel { box-shadow: 0 0 0 2px var(--mode), var(--shadow); }

  /* Elements tab: small tiles in five columns at 390 px. */
  .table-area { padding: var(--sp-2); }
  .el-view { margin-bottom: var(--sp-2); }
  .el-view .seg { min-height: 32px; font-size: 13.5px; }
  .myel { grid-template-columns: repeat(auto-fill, minmax(60px, 1fr)); gap: 6px; }
  .my-tile { height: 64px; padding: 8px 2px 3px; gap: 2px; border-radius: 11px; }
  .my-z { top: 3px; left: 5px; font-size: 9px; }
  .my-sym { font-size: 21px; }
  .my-name { font-size: 9px; line-height: 1.15; }
  .my-count { font-size: 11.5px; line-height: 1.15; }

  /* Shelf and Reactions tabs: the tab already names the list. The search box and the filters share one row. */
  .shelf-panel, .known-panel { padding: var(--sp-2); }
  .shelf-panel .panel-title, .known-panel .panel-title { display: none; }
  .panel-head { margin-bottom: var(--sp-2); flex-wrap: nowrap; gap: var(--sp-2); }
  .shelf-panel .panel-head .ui-search, .known-panel .panel-head .ui-search { order: 1; flex: 1 1 0; min-width: 0; }
  .shelf-panel .panel-head .small-toggle, .known-panel .panel-head .small-toggle { order: 2; flex: none; font-size: 13px; }
  .known-panel .panel-tools { flex-wrap: nowrap; }
  .ui-search { height: 36px; font-size: 16px; }
  .small-toggle { min-height: 36px; }
  .cat-chips { margin: 0 calc(var(--sp-2) * -1) var(--sp-2); padding: 2px var(--sp-2) 2px; }
  .cat-chip { min-height: 30px; font-size: 13px; }
  .shelf { gap: 6px; }
  .cchip { min-height: 36px; padding: 2px var(--sp-2) 2px 6px; gap: 5px; }
  .cchip-dot { width: 14px; height: 14px; }
  .cchip-formula { font-size: 14px; }
  .cchip-count { font-size: 12px; }

  .known-panel .panel-head { margin-bottom: var(--sp-1); }
  .small-select, .panel-filters .small-select { flex: 1 1 0; min-width: 0; height: 36px; padding-left: var(--sp-2); font-size: 13px; }
  .panel-filters { flex-wrap: nowrap; gap: 6px; margin-bottom: var(--sp-2); }
  .known { gap: 6px; }
  .kr { padding: var(--sp-2); gap: 6px; }
  .eq { font-size: 13.5px; }
  .kr-btn { min-height: 36px; min-width: 42px; font-size: 13px; }

  /* MIX bar: the main action within thumb reach. It shows while the flask holds something. */
  .mixbar:not([hidden]) {
    display: flex;
    flex: none;
    gap: var(--sp-2);
    padding: var(--sp-2) var(--sp-3);
    padding-bottom: max(var(--sp-2), env(safe-area-inset-bottom));
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 -4px 14px rgba(38, 50, 74, 0.12);
    animation: mixbar-in 0.2s ease-out;
  }
  .mixbar button {
    min-height: 48px;
    border: 0;
    border-radius: 14px;
    font-family: var(--font-head);
    font-size: 17px;
    font-weight: 600;
  }
  .mixbar-clear { flex: 0 0 auto; padding: 0 var(--sp-4); background: #eef2f8; color: var(--ink-soft); }
  .mixbar-go { flex: 1 1 auto; background: #ff6f91; color: #fff; box-shadow: 0 3px 0 #d94f72; }
  .mixbar-go:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #d94f72; }
  .mixbar button:disabled { opacity: 0.6; }
  @keyframes mixbar-in { from { transform: translateY(100%); } }
  body.reduced .mixbar { animation: none; }
}
.welcome-steps { margin: var(--sp-2) 0 0; padding-left: 22px; line-height: 1.5; }
.welcome-steps li + li { margin-top: var(--sp-1); }

/* Short phones: the MIX bar and the quick tray give a little height back to the lists. */
@media (max-width: 699px) and (max-height: 700px) {
  .mixbar:not([hidden]) { padding-top: 6px; padding-bottom: max(6px, env(safe-area-inset-bottom)); }
  .mixbar button { min-height: 40px; font-size: 16px; }
  .qt-ball { width: 36px; height: 36px; }
  .qt-art { width: 26px; height: 26px; }
  .el-view .seg { min-height: 30px; }
}
