/* Terrariet (docs/TERRARIUM_PLAN.md "UI-omgörning"): the Banverkstad's look (css/bv-app.css: .bv-bar, .bv-btn, .bv-dialog,
   .bv-tile) around a cross-section of a terrarium. Three columns: the tools (left), the world with its own controls under it
   (middle), the materials WITH their names (right). Everything should fit one screen on a computer; a phone held upright
   keeps the world at the top while the tools and materials scroll under it. */
.terrarium { max-width: 92rem; padding: 0.5rem 0.75rem 0.6rem; --tile: 3.3rem; --top: 9rem; }
.terrarium button { cursor: pointer; }
.terrarium :is(input, select, canvas, button, a):focus-visible { outline: 3px solid var(--yellow); outline-offset: 2px; }

/* ---------- The top row ---------- */
.tr-bar { margin-bottom: 0.55rem; }
.tr-worldchip {
  display: flex; align-items: center; gap: 0.55rem; flex: 1 1 9rem; max-width: 19rem; min-width: 0; height: 3.4rem; padding: 0 0.75rem; font: inherit; text-align: left;
  color: var(--cyan); background: #120a2c; border: 2px solid #5ef0ff66; border-radius: 0.95rem; box-shadow: 0 4px 0 #090418;
}
.tr-worldchip:hover { border-color: var(--cyan); }
.tr-worldchip:active { transform: translateY(3px); box-shadow: 0 1px 0 #090418; }
.tr-worldchip > .bv-ico { width: 1.7rem; height: 1.7rem; flex: none; color: var(--yellow); }
.tr-worldchip-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.tr-worldchip-kicker { font-size: 0.66rem; font-weight: 800; letter-spacing: 0.08em; text-transform: uppercase; color: var(--text-muted); }
.tr-worldchip strong { font-size: 1.05rem; font-weight: 850; font-style: italic; color: var(--text); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tr-caret { display: inline-grid; width: 1.1rem; height: 1.1rem; margin-left: auto; flex: none; }
.tr-caret svg { width: 100%; height: 100%; fill: currentColor; }
.draft-badge { flex: none; color: var(--yellow); border: 1px solid #ffe94d66; padding: 0.15rem 0.55rem; font-weight: 800; font-size: 0.66rem; letter-spacing: 0.1em; text-transform: uppercase; transform: skew(-8deg); opacity: 0.8; }
.tr-clock { display: flex; align-items: center; gap: 0.45rem; }
.tr-pause .tr-when-paused { display: none; }
.tr-pause[aria-pressed="true"] .tr-when-paused { display: grid; }
.tr-pause[aria-pressed="true"] .tr-when-running { display: none; }
.tr-pause[aria-pressed="true"] { box-shadow: 0 4px 0 #a08a00, 0 0 22px #ffe94dcc; }
.tr-speed {
  display: flex; align-items: center; gap: 0.25rem; height: 3.4rem; padding: 0 0.3rem 0 0.55rem; color: var(--cyan);
  background: linear-gradient(#2c1d5c, #1b1040); border: 2px solid #5ef0ff77; border-radius: 0.95rem; box-shadow: 0 4px 0 #090418;
}
.tr-speed .bv-ico { width: 1.4rem; height: 1.4rem; }
.tr-speed select { font: inherit; font-weight: 850; font-size: 1rem; color: var(--yellow); background: transparent; border: 0; min-height: 2.75rem; padding: 0 0.2rem; cursor: pointer; }
.tr-speed select option { background: var(--bg-raised); color: var(--text); }

/* ---------- The three columns ---------- */
.tr-stage { display: grid; grid-template-columns: auto minmax(0, 1fr) 16.5rem; gap: 0.7rem; align-items: start; }

/* The tool box (left) */
.tr-rail {
  display: flex; flex-direction: column; gap: 0.55rem; padding: 0.4rem; min-width: 0;
  background: #170d38; border: 2px solid #5ef0ff33; border-radius: 0.9rem;
}
.tool-buttons { display: flex; flex-direction: column; gap: 0.45rem; }
.tr-group {
  display: grid; grid-template-columns: repeat(3, var(--tile)); gap: 0.4rem; padding: 0.3rem;
  background: color-mix(in srgb, var(--g) 10%, transparent); border-top: 4px solid var(--g); border-radius: 0.6rem;
}
.tr-group .bv-paint {
  width: var(--tile); height: var(--tile); padding: 0.2rem 0 0.15rem; justify-content: center; gap: 0.05rem; font-size: 0.68rem; font-weight: 800;
  color: color-mix(in srgb, var(--g) 70%, white); background: #0f0826; border-radius: 0.7rem; border-color: color-mix(in srgb, var(--g) 50%, transparent);
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.tr-group .bv-paint .bv-ico { width: 1.6rem; height: 1.6rem; }
.tr-group .bv-paint[aria-pressed="true"] { color: var(--yellow); border-color: var(--yellow); background: #2b2260; box-shadow: 0 0 12px #ffe94dbb; }
.tr-brush { padding: 0 0.25rem; }
.slider-label { display: flex; align-items: center; gap: 0.35rem; font-size: 0.78rem; font-weight: 700; color: var(--text-muted); }
.slider-label output { margin-left: auto; color: var(--yellow); font-variant-numeric: tabular-nums; }
.tr-brush-dot { width: 0.75rem; height: 0.75rem; border-radius: 50%; border: 2px solid var(--cyan); }
.terrarium input[type="range"] { width: 100%; accent-color: var(--cyan); margin: 0; min-height: 30px; }
.inspector { display: flex; align-items: flex-start; gap: 0.55rem; padding: 0.45rem; background: #0f0826; border: 1px solid #5ef0ff33; border-radius: 0.6rem; }
#loupe { image-rendering: pixelated; width: 52px; height: 52px; border: 2px solid var(--yellow); border-radius: 0.35rem; flex: none; }
.inspector div { min-width: 0; font-size: 0.72rem; line-height: 1.35; color: var(--text-muted); max-width: calc(var(--tile) * 3 + 0.8rem - 52px - 1.5rem); }
.inspector strong { display: block; color: var(--yellow); font-size: 0.85rem; overflow-wrap: anywhere; }
.inspector span { display: block; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.inspector span:empty { display: none; }

/* The world (middle): as big as the window lets it be, never cut off below */
.world-panel { min-width: 0; }
.tr-world { width: 100%; max-width: calc((var(--window-height) - var(--top) - 4.6rem - var(--readout, 0rem)) * 1.6); justify-self: center; }
.world-window { position: relative; overflow: hidden; border: 3px solid var(--cyan); border-radius: 0.8rem; background: #162329; box-shadow: 0 0 15px #5ef0ff19; }
#world { display: block; width: 100%; aspect-ratio: 256 / 160; image-rendering: pixelated; touch-action: none; cursor: crosshair; user-select: none; }
.world-cursor { position: absolute; pointer-events: none; border: 1px solid #fff; outline: 1px solid #162329; border-radius: 50%; transform: translate(-50%, -50%); }
.world-fps { position: absolute; right: 5px; bottom: 4px; z-index: 2; padding: 1px 3px; border-radius: 2px; background: #101b22b3; color: #c1ccd0; font: 10px/1.2 monospace; font-variant-numeric: tabular-nums; pointer-events: none; user-select: none; }
.world-paused {
  position: absolute; top: 0.5rem; left: 0.5rem; display: flex; align-items: center; gap: 0.25rem; padding: 0.15rem 0.55rem 0.15rem 0.35rem;
  color: var(--bg); background: var(--yellow); border-radius: 0.6rem; font-size: 0.8rem; font-weight: 850; pointer-events: none;
}
.world-paused[hidden] { display: none; }
.world-paused .bv-ico { width: 1rem; height: 1rem; }
.world-foot { position: absolute; left: 0; bottom: 4px; width: 100%; padding-left: 0.5rem; pointer-events: none; font-size: 0.65rem; font-weight: 700; color: #dfe7ea; text-shadow: 0 1px 2px #000; }
.scale-bar { display: inline-block; width: 19.53125%; border-bottom: 2px solid currentColor; text-align: center; line-height: 1.4; position: relative; }
.scale-bar::before, .scale-bar::after { content: ''; position: absolute; width: 2px; height: 5px; background: currentColor; bottom: -2px; }
.scale-bar::before { left: 0; } .scale-bar::after { right: 0; }
.tr-lid-flag { display: none; }
.tr-help { opacity: 0.55; transition: opacity 0.15s; }
.tr-help:hover, .tr-help:focus-visible { opacity: 1; }
.drainage-outlets { position: absolute; inset: 0; pointer-events: none; }
.drainage-outlets span { position: absolute; top: 81%; left: 24%; width: 13.3%; height: 13%; border: 1px dashed var(--yellow); }
.drainage-outlets span + span { left: 70.9%; }

/* The world's own row: views · invisible · sun · lid */
.tr-worldbar { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.6rem; margin-top: 0.5rem; }
.tr-worldbar-gap { flex: 1 1 0; }
.tr-seg { display: flex; padding: 3px; gap: 3px; background: #120a2c; border: 2px solid #5ef0ff44; border-radius: 0.85rem; }
.tr-segbtn {
  display: flex; align-items: center; gap: 0.3rem; min-height: 2.6rem; padding: 0 0.7rem; font: inherit; font-size: 0.8rem; font-weight: 800;
  color: var(--text-muted); background: transparent; border: 0; border-radius: 0.6rem;
}
.tr-segbtn .bv-ico { width: 1.25rem; height: 1.25rem; }
.tr-segbtn:hover { color: var(--text); }
.tr-segbtn[aria-pressed="true"] { color: var(--bg); background: var(--cyan); }
.invisible-toggle {
  position: relative; display: inline-flex; align-items: center; gap: 0.3rem; min-height: 2.75rem; padding: 0 0.7rem; font-size: 0.8rem; font-weight: 800;
  color: var(--text-muted); background: #120a2c; border: 2px solid #5ef0ff44; border-radius: 0.85rem; cursor: pointer; user-select: none;
}
.invisible-toggle input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.invisible-toggle .bv-ico { width: 1.3rem; height: 1.3rem; }
.invisible-toggle input:checked ~ .tr-eye-off, .invisible-toggle input:not(:checked) ~ .tr-eye-on { display: none; }
.invisible-toggle input:checked ~ * { color: var(--cyan); }
.invisible-toggle:has(input:checked) { border-color: var(--cyan); }
.invisible-toggle:has(input:focus-visible) { outline: 3px solid var(--yellow); outline-offset: 2px; }
.tr-sun { display: flex; align-items: center; gap: 0.4rem; min-height: 2.75rem; padding: 0 0.7rem; color: var(--yellow); background: #120a2c; border: 2px solid #ffe94d44; border-radius: 0.85rem; }
.tr-sun .bv-ico { width: 1.35rem; height: 1.35rem; flex: none; }
.tr-sun input[type="range"] { width: 7rem; accent-color: var(--yellow); min-height: 2rem; }
.tr-sun output { min-width: 2.8rem; font-size: 0.8rem; font-weight: 800; text-align: right; font-variant-numeric: tabular-nums; }
.tr-lid {
  display: flex; align-items: center; gap: 0.35rem; min-height: 2.75rem; padding: 0 0.75rem; font: inherit; font-size: 0.8rem; font-weight: 800;
  color: var(--text-muted); background: #120a2c; border: 2px solid #5ef0ff44; border-radius: 0.85rem;
}
.tr-lid .bv-ico { width: 1.3rem; height: 1.3rem; }
.tr-lid[aria-pressed="true"] { color: var(--cyan); border-color: var(--cyan); }
.view-key { min-height: 1.6rem; display: flex; flex-wrap: wrap; gap: 0.2rem 1rem; padding: 0.3rem 0.2rem 0; font-size: 0.72rem; color: var(--text-muted); align-items: center; }
.gas-key { display: inline-flex; align-items: center; gap: 0.3rem; }
.gas-swatch { width: 12px; height: 12px; border: 1px solid currentColor; background-image: radial-gradient(currentColor 1.4px, transparent 1.5px); background-size: 4px 4px; }
.heat-ramp, .moisture-ramp { display: inline-block; width: 110px; height: 10px; border-radius: 3px; }
.heat-ramp { background: linear-gradient(90deg, #3559ad, #60a9af, #e4c16e, #e45b45); }
.moisture-ramp { background: linear-gradient(90deg, #65503c, #3c7dba); }
/* A message (file opened, experiment changed) is a note over the world, so it never pushes the page down */
.file-status { position: absolute; top: 0.5rem; right: 0.5rem; z-index: 3; max-width: 62%; margin: 0; padding: 0.2rem 0.55rem; color: var(--yellow); background: #101b22ec; border: 1px solid #ffe94d55; border-radius: 0.6rem; font-size: 0.8rem; font-weight: 700; pointer-events: none; }
.file-status:empty { display: none; }

/* What an experiment measures (UX-5): ONE short row under the world – icons and numbers, no sentences. The explanations are in the "?"
   dialog. The world gives up --readout of its room while a row is shown, so the page never scrolls. */
.tr-world { --readout: 0rem; }
/* A narrow world (a shrunk window, or a readout row taking room) keeps its own row on ONE line: the words go, the icons stay */
.tr-world { container: tr-world / inline-size; }
@container tr-world (max-width: 44rem) {
  .tr-segbtn span:not(.bv-ico), .tr-eye-text { display: none; }
  .tr-segbtn { padding-inline: 0.55rem; }
  .tr-sun input[type="range"] { width: 5rem; }
}
.tr-world:has(.tr-readout:not([hidden])) { --readout: 4.6rem; }
.tr-readout {
  display: flex; align-items: center; gap: 0.5rem; min-height: 3rem; margin: 0.4rem 0 0; padding: 0.25rem 0.5rem; font-size: 0.74rem; color: var(--text-muted);
  background: #170d38; border: 1px solid #5ef0ff33; border-radius: 0.7rem;
}
.tr-readout[hidden] { display: none; }
.tr-readout { min-width: 0; max-width: 100%; box-sizing: border-box; }
.tr-readout > .bv-ico { width: 1.4rem; height: 1.4rem; flex: none; color: var(--cyan); }
.tr-readout strong { color: var(--text); font-size: 0.78rem; }
.tr-legend { margin-block: 0.4rem 0; gap: 0.35rem; font-weight: 800; color: var(--text); }
.tr-legend .tr-sep { flex: 1 1 0; }
.tr-worm-text { display: flex; flex-direction: column; min-width: 0; flex: 1 1 auto; line-height: 1.2; }
.tr-worm-text span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-variant-numeric: tabular-nums; }
.tr-state { font-weight: 800; color: var(--text); white-space: nowrap; }
.tr-meters { flex-wrap: wrap; }
.tr-meters > div { display: flex; flex-wrap: wrap; gap: 0.4rem; margin-left: auto; min-width: 0; }
.tr-meters .tr-mini { font-variant-numeric: tabular-nums; }
/* The small keys of the rows (Följ, Mata, Öppna, the drainage meters): the workshop's rounded keys */
.tr-mini {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem; min-height: 2.5rem; padding: 0 0.7rem; font: inherit; font-size: 0.74rem; font-weight: 800;
  color: var(--cyan); background: linear-gradient(#2c1d5c, #1b1040); border: 2px solid #5ef0ff66; border-radius: 0.75rem; box-shadow: 0 3px 0 #090418; flex: none;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.tr-mini .bv-ico { width: 1.2rem; height: 1.2rem; }
.tr-mini:hover { border-color: var(--cyan); }
.tr-mini:active { transform: translateY(2px); box-shadow: 0 1px 0 #090418; }
.tr-mini:disabled { opacity: 0.4; cursor: default; }
.cycle-cards { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 0.4rem; width: 100%; }
.cycle-cards > div {
  display: grid; grid-template-columns: minmax(0, 1fr) auto; grid-template-areas: "a b" "c b" "d b"; column-gap: 0.35rem; align-items: center; min-width: 0;
  padding: 0.25rem 0.35rem; line-height: 1.15; border: 1px solid #5ef0ff55; border-radius: 0.5rem;
}
.cycle-cards strong { grid-area: a; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cycle-cards span { grid-area: c; font-variant-numeric: tabular-nums; font-size: 0.68rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cycle-cards em { grid-area: d; font-style: normal; color: #f4dc72; font-size: 0.68rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cycle-cards .tr-mini { grid-area: b; padding: 0 0.45rem; min-height: 2.5rem; }
.cycle-cards .tr-mini span { grid-area: auto; font-size: 0.7rem; }
.cycle-cards .tr-mini span:not(.bv-ico) { display: none; }
#experiment-help li { margin-bottom: 0.4rem; }
#experiment-help[hidden], #experiment-help [hidden] { display: none; }

/* The materials (right): search, groups, then a tile per material with its name */
.tr-materials {
  display: flex; flex-direction: column; gap: 0.45rem; min-width: 0; padding: 0.45rem; max-height: calc(var(--window-height) - var(--top));
  background: #170d38; border: 2px solid #5ef0ff33; border-radius: 0.9rem;
}
.tr-search { display: flex; align-items: center; gap: 0.35rem; padding: 0 0.5rem; color: var(--text-muted); background: var(--bg); border: 2px solid #5ef0ff44; border-radius: 0.7rem; }
.tr-search:focus-within { border-color: var(--cyan); }
.tr-search .bv-ico { width: 1.1rem; height: 1.1rem; flex: none; }
.tr-search input { flex: 1; min-width: 0; min-height: 2.5rem; padding: 0; font: inherit; font-size: 0.85rem; color: var(--text); background: transparent; border: 0; outline: 0; }
.material-tabs { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 0.25rem; }
.material-tabs button {
  min-height: 2.2rem; padding: 0 0.3rem; font: inherit; font-size: 0.72rem; font-weight: 800;
  color: var(--text-muted); background: var(--bg); border: 1px solid #5ef0ff33; border-radius: 0.55rem;
}
.material-tabs button[aria-pressed="true"] { color: var(--bg); background: var(--yellow); border-color: var(--yellow); }
.material-paints {
  display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0.3rem; align-content: start;
  flex: 1 1 auto; min-height: 9rem; overflow-y: auto; overscroll-behavior: contain; scrollbar-width: thin; scrollbar-color: var(--cyan) transparent; padding: 2px;
}
.material-paints .bv-paint {
  flex-direction: row; justify-content: flex-start; gap: 0.4rem; min-height: 2.6rem; padding: 0.25rem 0.35rem; text-align: left;
  font-size: 0.74rem; font-weight: 750; line-height: 1.1; background: #0f0826; border: 2px solid #5ef0ff2e; border-radius: 0.6rem;
  touch-action: manipulation; -webkit-tap-highlight-color: transparent;
}
.material-paints .bv-paint canvas { image-rendering: pixelated; width: 24px; height: 24px; flex: none; border-radius: 4px; }
.material-paints .bv-paint span { min-width: 0; overflow-wrap: normal; word-break: normal; hyphens: auto; }
.material-paints .bv-paint[aria-pressed="true"] { background: #2b2260; border-color: var(--yellow); }
#no-results { margin: 0; font-size: 0.8rem; color: var(--text-muted); }
.material-facts { margin: 0; font-size: 0.78rem; flex: none; }
.material-facts > summary { font-size: 0.82rem; min-height: 2.2rem; }
.material-facts[open] #material-facts { max-height: 14rem; overflow-y: auto; }
.material-facts dl { display: grid; grid-template-columns: auto 1fr; gap: 0.3rem 0.7rem; margin: 0.4rem 0; }
.material-facts dd { margin: 0; color: var(--yellow); overflow-wrap: anywhere; }
.material-facts p { font-size: 0.72rem; color: var(--text-muted); }

/* ---------- The dialogs ---------- */
.tr-dialog-title { display: flex; align-items: center; gap: 0.5rem; font-size: 1.15rem; font-weight: 850; font-style: italic; color: var(--text); }
.tr-experiments { width: min(52rem, 95vw); }
.tr-cards-title {
  margin: 0.7rem 0 0.4rem; padding-left: 0.5rem; font-size: 0.78rem; font-weight: 850; font-style: italic; text-transform: uppercase; letter-spacing: 0.07em;
  color: var(--g, var(--cyan)); border-left: 4px solid var(--g, var(--cyan));
}
.tr-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(9.2rem, 1fr)); gap: 0.5rem; }
.tr-card {
  display: flex; align-items: center; gap: 0.5rem; min-height: 3.2rem; padding: 0.45rem 0.6rem; font: inherit; font-size: 0.85rem; font-weight: 800; text-align: left; line-height: 1.15;
  color: var(--text); background: linear-gradient(#2c1d5c, #1b1040); border: 2px solid #5ef0ff55; border-radius: 0.85rem; box-shadow: 0 4px 0 #090418;
}
.tr-card .bv-ico { width: 1.6rem; height: 1.6rem; flex: none; color: var(--cyan); }
.tr-card:hover { border-color: var(--cyan); }
.tr-card:active { transform: translateY(3px); box-shadow: 0 1px 0 #090418; }
.tr-card.is-current { border-color: var(--yellow); box-shadow: 0 4px 0 #a08a00, 0 0 12px #ffe94d66; }
.tr-card.is-current .bv-ico { color: var(--yellow); }
.tr-replace { width: min(25rem, 92vw); }
.tr-replace h2 { margin: 0 0 0.4rem; font-size: 1.2rem; }
.tr-replace form { display: flex; justify-content: flex-end; gap: 0.5rem; }
#help-dialog .prototype-note { margin: 0; color: var(--text-muted); font-size: 0.8rem; }

/* Fullscreen: the whole workshop fills the screen */
.terrarium:fullscreen { width: 100%; height: 100%; max-width: none; padding: 0.6rem 1rem; overflow-y: auto; background: var(--bg); --top: 4.8rem; }

/* ---------- A narrower computer / a tablet held sideways: three tighter columns (tools two across, materials one) ---------- */
@media (max-width: 1100px) and (min-width: 761px) and (orientation: landscape), (max-width: 1100px) and (min-width: 900px) {
  .tr-stage { grid-template-columns: auto minmax(0, 1fr) 12.5rem; gap: 0.55rem; }
  .tr-group { grid-template-columns: repeat(2, var(--tile)); }
  .inspector { flex-direction: column; }
  .inspector div { max-width: calc(var(--tile) * 2 + 0.4rem); }
  .material-paints { grid-template-columns: minmax(0, 1fr); }
  .tr-segbtn span:not(.bv-ico), .tr-eye-text { display: none; }
  .tr-sun input[type="range"] { width: 5.5rem; }
}
/* A tablet held upright: the world over the full width, the tools and materials side by side under it */
@media (min-width: 761px) and (max-width: 899px) and (orientation: portrait) {
  .tr-stage { grid-template-columns: auto minmax(0, 1fr); }
  .tr-world { grid-column: 1 / -1; grid-row: 1; max-width: none; }
  .tr-rail { grid-row: 2; }
  .tr-materials { grid-row: 2; max-height: 30rem; }
  .material-paints { grid-template-columns: repeat(auto-fill, minmax(8rem, 1fr)); }
}

/* ---------- A phone or small tablet held upright: the world on top (it stays while the rest scrolls), then the tools,
   then the materials ---------- */
@media (max-width: 760px) and (orientation: portrait) {
  .terrarium { padding-inline: 0.5rem; --tile: 2.75rem; }
  .tr-rail { padding: 0.3rem; gap: 0.45rem; }
  .tool-buttons { gap: 0.3rem; }
  .tr-group { gap: 0.25rem; padding: 0.2rem; }
  .tr-group .bv-paint { font-size: 0.62rem; }
  .tr-group .bv-paint .bv-ico { width: 1.35rem; height: 1.35rem; }
  .tr-stage { grid-template-columns: minmax(0, 1fr); gap: 0.55rem; }
  .tr-world { order: 1; max-width: none; --readout: 0rem !important; }
  .tr-rail { order: 2; flex-direction: row; flex-wrap: wrap; align-items: flex-start; }
  .tool-buttons { flex-direction: row; flex-wrap: wrap; }
  .tr-group { grid-template-columns: repeat(var(--n, 3), var(--tile)); }
  .tr-group:nth-child(2) { --n: 2; }
  .tr-brush { flex: 1 1 9rem; }
  .inspector { flex: 1 1 14rem; }
  .inspector div { max-width: none; }
  .tr-materials { order: 3; max-height: none; }
  .material-tabs { grid-template-columns: repeat(6, minmax(0, 1fr)); }
  .material-paints { grid-template-columns: repeat(auto-fill, minmax(6.8rem, 1fr)); max-height: 15rem; flex: none; }
  .world-window { position: sticky; top: 0; z-index: 5; }
  .tr-worldbar { gap: 0.4rem; }
  .tr-worldbar-gap { display: none; }
  .tr-seg { flex: 1 1 100%; }
  .tr-segbtn { flex: 1; justify-content: center; }
  .tr-sun { order: 5; flex: 1 1 100%; }
  .tr-sun input[type="range"] { width: auto; flex: 1; }
  .cycle-cards { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 560px) {
  .tr-worldchip { flex: 1 1 8rem; height: 2.75rem; }
  .tr-worldchip-kicker { display: none; }
  .draft-badge { display: none; }
  .tr-speed { height: 2.75rem; }
  .tr-clock { gap: 0.35rem; }
  .tr-bar .bv-break + .bv-spacer + #undo { margin-right: auto; }
}

/* ---------- A phone held sideways: the site's top bar is gone (css/bv-app.css), three tight columns ---------- */
@media (max-height: 500px) and (orientation: landscape) {
  .terrarium { --tile: 2.75rem; --top: 3.6rem; padding-top: 0.3rem; padding-bottom: 0; }
  .tr-bar { margin-bottom: 0.35rem; }
  .tr-worldchip, .tr-speed { height: 2.75rem; }
  .tr-worldchip-kicker, .draft-badge { display: none; }
  .tr-stage { grid-template-columns: auto minmax(0, 1fr) 11rem; gap: 0.45rem; }
  .tr-rail { max-height: calc(var(--window-height) - var(--top)); overflow-y: auto; }
  .tr-group { grid-template-columns: repeat(2, var(--tile)); }
  .tr-group .bv-paint { font-size: 0.6rem; }
  .tr-group .bv-paint .bv-ico { width: 1.3rem; height: 1.3rem; }
  .inspector { flex-direction: column; }
  .inspector div { max-width: calc(var(--tile) * 2 + 0.4rem); }
  #loupe { width: 40px; height: 40px; }
  .tr-world { max-width: calc((var(--window-height) - var(--top) - 3.7rem - var(--readout, 0rem)) * 1.6); }
  .view-key { display: none; }
  .tr-worldbar { margin-top: 0.3rem; gap: 0.3rem; }
  .tr-segbtn span:not(.bv-ico), .tr-eye-text, #lid-text { display: none; }
  .tr-segbtn, .invisible-toggle, .tr-lid, .tr-sun { min-height: 2.6rem; padding-inline: 0.5rem; }
  .tr-sun input[type="range"] { width: 4.5rem; }
  .tr-sun output { display: none; }
  .material-paints { grid-template-columns: minmax(0, 1fr); min-height: 3rem; }
  .tr-materials { gap: 0.3rem; padding: 0.35rem; }
  .material-tabs button { min-height: 2rem; padding: 0 0.3rem; font-size: 0.65rem; }  /* a readout row here: names and status only (the gases are in the loupe), so it stays one low row */
  .tr-world:has(.tr-readout:not([hidden])) { --readout: 3.4rem; }
  .tr-readout { min-height: 2.6rem; margin-top: 0.3rem; padding-block: 0.15rem; }
  .cycle-cards > div { grid-template-areas: "a b" "d b"; }
  .cycle-cards span:not(.bv-ico) { display: none; }
  .tr-mini { min-height: 2.2rem; }
  .file-status { max-width: 90%; font-size: 0.7rem; }
}

/* The dot beside "Pensel" grows with the brush */
.tr-brush-dot { --size: 2; width: calc(0.45rem + var(--size) * 0.07rem); height: calc(0.45rem + var(--size) * 0.07rem); flex: none; }

/* K08-F: a blast shakes the world window (terrarium.js shakeWorld sets --shake); none with reduced motion */
@keyframes tr-shake {
  0% { transform: translate(0, 0); } 20% { transform: translate(calc(var(--shake) * -1), calc(var(--shake) * .6)); }
  40% { transform: translate(var(--shake), calc(var(--shake) * -.5)); } 60% { transform: translate(calc(var(--shake) * -.6), calc(var(--shake) * -.4)); }
  80% { transform: translate(calc(var(--shake) * .4), calc(var(--shake) * .3)); } 100% { transform: translate(0, 0); }
}
.world-window.is-shaking { animation: tr-shake .22s linear; }
@media (prefers-reduced-motion: reduce) { .world-window.is-shaking { animation: none; } }
