/*
 * Layout: a single grid that flips orientation for touch/small screens.
 *
 * Desktop - controls in a fixed left column, render view filling the rest.
 * Mobile  - render view on top (sticky, so it stays visible while the settings
 *           scroll underneath), settings below.
 */

/*
 * Caption fonts, bundled so the default looks the same everywhere.
 *
 * Impact — the face a caption wants — ships with Windows and macOS and is on
 * essentially no Linux or Android machine, where the stack used to fall
 * through to a generic sans. Shipping the real Impact is not an option: it is
 * Monotype's, and the old "Core fonts for the Web" licence allowed
 * redistribution only as Microsoft's original installer, a programme that
 * ended in 2002. These five are open lookalikes, all SIL OFL 1.1, with their
 * licences beside them in vendor/fonts/.
 *
 * Self-hosted rather than pulled from Google's CDN: the page makes no network
 * requests of its own and is not about to start, least of all ones that would
 * report every visitor's address to a third party.
 *
 * The latin subset only, about 92KB for the five. unicode-range is what makes
 * that safe — a character outside it falls through to the next font in the
 * stack instead of rendering as a missing-glyph box.
 *
 * One cut per family — Oswald's and Comic Neue's bold ones, since a caption
 * wants weight — each declared as the normal weight. The canvas asks for
 * "40px Oswald" with no weight of its own, so an exact match is what stops
 * the browser synthesising a fake regular or falling back.
 *
 * font-display: block, because these are measured. A swapped-in fallback
 * would not merely look wrong for an instant, it would be measured, sized and
 * wrapped as though it were the real thing.
 */

@font-face {
  font-family: 'Anton';
  font-style: normal;
  font-weight: normal;
  font-display: block;
  src: url('../vendor/fonts/anton-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Oswald';
  font-style: normal;
  font-weight: normal;
  font-display: block;
  src: url('../vendor/fonts/oswald-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Comic Neue';
  font-style: normal;
  font-weight: normal;
  font-display: block;
  src: url('../vendor/fonts/comic-neue-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Arimo';
  font-style: normal;
  font-weight: normal;
  font-display: block;
  src: url('../vendor/fonts/arimo-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

@font-face {
  font-family: 'Tinos';
  font-style: normal;
  font-weight: normal;
  font-display: block;
  src: url('../vendor/fonts/tinos-latin.woff2') format('woff2');
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
  /* Console: grey plastic. Each settings section overrides --accent with its
     own colour (see the Console block at the end of this file); everything
     outside the sections — the GitHub link, Browser check, the preview's
     checkboxes, the drop zone — takes Text's purple from here. */
  --bg: #232326;
  --panel: #323236;
  --panel-2: #3d3d42;
  --line: #55555c;
  --text: #f4f4f4;
  --muted: #c4c4cb;
  --accent: #8a4fe0;
  --on-accent: #fff;        /* text drawn on the accent colour */
  --field: #28282c;         /* text boxes, dropdowns, the progress track */
  --shadow: #1c1c1f;        /* the edge under a raised button */
  --danger: #e03131;
  --caution: #e8912d;
  --radius: 12px;
  /* Wide enough for the 460px title image to sit at its natural size: 460
     plus the panel's 12px padding either side, the title's 4px margins, and
     room for a scrollbar. */
  --panel-width: 508px;
  --gutter: 0px;            /* scroll-safe strip; only used on touch layouts */
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 Arimo, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  overscroll-behavior: none;
}

#app {
  display: grid;
  grid-template-columns: var(--panel-width) 1fr;
  grid-template-areas: "panel view";
  height: 100%;
}

/* ---------------------------------------------------------------- view */

#view {
  grid-area: view;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 12px;
  gap: 8px;
}

#stage {
  position: relative;
  flex: 1;
  min-height: 0;
  display: grid;
  place-items: center;
  background:
    linear-gradient(45deg, #2a2a2e 25%, transparent 25%, transparent 75%, #2a2a2e 75%),
    linear-gradient(45deg, #2a2a2e 25%, #303035 25%, #303035 75%, #2a2a2e 75%);
  background-size: 24px 24px;
  background-position: 0 0, 12px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
}

/*
 * The exported image, in layers.
 *
 * #frame is the finished picture — which On Top mode makes taller than the
 * render — and it is the only thing CSS scales. Its two rows are set in JS to
 * the real pixel heights of the band and the render, as `<band>fr <render>fr`,
 * so the two always scale by the same factor with nothing measured. Its
 * aspect-ratio is set the same way, which is what lets max-width and
 * max-height fit the whole composed image into the stage. With no band the
 * rows resolve to `0fr 1fr` and this is exactly the single-cell stack it
 * replaced.
 */
#frame {
  display: grid;
  max-width: 100%;
  max-height: 100%;
  /* Required for the max-* rules above to bite. As a grid item #frame gets
     min-height/min-width: auto, i.e. its automatic minimum size — the full
     render resolution — which outranks max-height and lets it overflow a stage
     shorter than the render. Zeroing both lets it actually scale down. */
  min-width: 0;
  min-height: 0;
}
/* Nothing is left of the image, so the empty stage shows the dropzone alone. */
#stage:has(#canvas.empty) #frame { display: none; }

#backdrop, #canvas, #fg-layer, #overlay {
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  display: block;
}

/*
 * Positioned, so the layers paint in source order. The picture layer has to be
 * position: relative to clip the <img> inside it, and a positioned element
 * paints above every non-positioned one whatever the source order says — so
 * without this the background picture covered the render and the caption.
 */
#canvas, #fg-layer, #overlay { position: relative; }

/*
 * The background colour, as a layer of its own. The renderer used to paint it
 * by clearing to it; now it sits under everything, which is what lets the
 * caption's Behind mode be imprinted on it. Left unset when Transparent is
 * ticked, so the stage's checkerboard shows through.
 */
#backdrop { grid-row: 1 / 3; grid-column: 1; }

/*
 * The background picture. It belongs to the render, so it takes the render's
 * row and is clipped to it; the <img> inside is placed in percentages of that
 * row from the same placeBackdrop() the export draws with, so it scales with
 * the preview and needs no redraw when the stage is resized.
 */
#backdrop-art {
  grid-row: 2;
  grid-column: 1;
  position: relative;
  overflow: hidden;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  pointer-events: none;
}
#backdrop-art[hidden] { display: none; }
#backdrop-image, #backdrop-frames {
  position: absolute;
  display: block;
  max-width: none;
  max-height: none;
}

/* The render occupies the lower row; the band, when there is one, is above. */
#canvas {
  grid-row: 2;
  grid-column: 1;
  object-fit: contain;
  /* Drag must orbit the model, not scroll the page behind it. */
  touch-action: none;
  cursor: grab;
}
#canvas.dragging { cursor: grabbing; }
#canvas.empty { display: none; }

/*
 * The caption spans both rows, because On Top draws into the band and the
 * other modes draw over the render. Clicks fall through to the canvas
 * underneath, which is what orbits the model.
 */
#overlay {
  grid-row: 1 / 3;
  grid-column: 1;
  pointer-events: none;
}
#overlay[hidden] { display: none; }

/*
 * The foreground picture belongs to the render, like the background: it takes
 * the render's row and sits between the render and the caption.
 */
#fg-layer {
  grid-row: 2;
  grid-column: 1;
  pointer-events: none;
}
#fg-layer[hidden] { display: none; }

/* Behind mode: the render, and the foreground with it, go over the caption. */
#frame.behind #canvas { z-index: 1; }
#frame.behind #fg-layer { z-index: 2; }

/*
 * Marks the exact edge of the exported image.
 *
 * With a transparent background the image shows the stage checkerboard, and
 * so does the stage *outside* the frame — so there is otherwise no visual cue
 * where the image ends and anything overhanging gets cropped. It rings the
 * whole frame, band included, because that is what gets exported.
 *
 * Two rings rather than one: a black line alone is near-invisible against the
 * dark checkerboard (about 1.2:1 contrast), and a white line alone would
 * disappear against a light render. Black inside, translucent white outside,
 * reads on any background. Both are drawn with box-shadow so they sit outside
 * the element and cannot shift the layout or overlap the image.
 */
#frame.show-border {
  box-shadow: 0 0 0 1px #000, 0 0 0 2px rgba(255, 255, 255, 0.5);
}

#dropzone {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 24px;
}
#dropzone[hidden] { display: none; }
#app.dragover #dropzone {
  background: rgba(138, 79, 224, 0.12);
  outline: 2px dashed var(--accent);
  outline-offset: -12px;
}
.drop-inner { display: grid; gap: 10px; justify-items: center; }
.drop-inner strong { font-size: 16px; }

/* An id rule beats the UA [hidden] rule, so restate it explicitly. */
#busy[hidden] { display: none; }
#busy {
  position: absolute;
  inset: auto 12px 12px auto;
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(0, 0, 0, 0.65);
  padding: 8px 12px;
  border-radius: var(--radius);
}
.spinner {
  width: 14px; height: 14px;
  border: 2px solid rgba(255,255,255,0.25);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/*
 * The view's own controls: things that change what the preview shows without
 * changing what gets exported. They live here rather than in the settings list
 * because they are about looking, not about the output.
 */
#view-foot {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px 18px;
  flex-wrap: wrap;
}
.view-toggles { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
/* The rate belongs to the Preview box, so it sits tight against it rather than
   a full gap away. */
.preview-pair { position: relative; display: flex; align-items: center; gap: 6px; }

/*
 * The first-model tutorial: a rounded orange arrow bouncing just above the
 * Preview box, until Preview is ticked or the arrow is clicked away.
 */
.preview-hint {
  position: absolute;
  bottom: calc(100% + 6px);
  left: -20px;                /* the 56px arrow centred over the 16px checkbox */
  z-index: 5;
  padding: 0;
  min-height: 0;
  border: 0;
  background: none;
  box-shadow: none;
  color: #f07a1a;
  line-height: 0;
  cursor: pointer;
  filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.55));
  animation: preview-hint-bounce 0.9s ease-in-out infinite;
}
.preview-hint[hidden] { display: none; }
.preview-hint:hover:not(:disabled) { filter: drop-shadow(0 2px 2px rgba(0, 0, 0, 0.55)) brightness(1.12); }
.preview-hint:active:not(:disabled) { box-shadow: none; }
@keyframes preview-hint-bounce {
  0%, 100% { transform: translateY(0); }
  50% { transform: translateY(-9px); }
}
@media (prefers-reduced-motion: reduce) {
  .preview-hint { animation: none; }
}

/* Spin's loop line, with its own Preview box at the right. */
.loop-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.loop-row #loop-info { flex: 1; min-width: 0; }
.loop-preview {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  white-space: nowrap;
  cursor: pointer;
}
.loop-preview input[type="checkbox"] { width: 16px; height: 16px; margin: 0; }
#view-foot label {
  display: flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  cursor: pointer;
  white-space: nowrap;
}
#view-foot input[type="checkbox"] { width: 16px; height: 16px; margin: 0; }
#preview-fps {
  color: var(--muted);
  font-variant-numeric: tabular-nums;
}
/* Reserve nothing while the preview is off: an empty box would otherwise hold
   a gap open in a row that is already tight on a phone. */
#preview-fps:empty { display: none; }

/* --------------------------------------------------------------- panel */

#panel {
  grid-area: panel;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid var(--line);
  background: var(--panel);
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  -webkit-overflow-scrolling: touch;
}

#app-title {
  margin: 2px 4px 0;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.01em;
}
/* The wordmark. Scales down on narrow screens rather than forcing a
   horizontal scroll, which is why the panel width is the only thing sized to
   it. */
#app-logo {
  display: block;
  padding: 0;
  border: 0;
  min-height: 0;
  background: none;
  cursor: pointer;
}
#app-title img {
  display: block;
  width: 460px;
  max-width: 100%;
  height: auto;
}
/* Tucked up under the wordmark: the panel's 12px gap is for sections. */
#app-tagline {
  margin: -8px 4px 0;
  font-size: 12px;
  color: var(--muted);
  /* The Github line on the left, the version on the right. */
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  gap: 8px;
}
#app-tagline a { color: var(--accent); }

.group {
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px;
  /* On touch layouts this reserves the scroll-safe strip on the right. */
  padding-right: calc(12px + var(--gutter));
}
/*
 * Section titles: bright, larger, and marked with an accent bar, so each
 * section is easy to find in a long panel. A section with a reset puts it on
 * the title's line, at the right, as a small pill rather than a full-width
 * button of its own.
 */
.group h2 {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0 0 12px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  color: var(--text);
}
.group h2::before {
  content: "";
  width: 4px;
  height: 1.05em;
  border-radius: 2px;
  background: var(--accent);
}
.group-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin: 0 0 12px;
}
.group-head h2 { margin: 0; }
button.reset {
  min-height: 0;
  padding: 3px 10px;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  font-size: 12px;
  white-space: nowrap;
}
button.reset:hover:not(:disabled) { color: var(--text); }
/* A finger needs more to aim at than a mouse does. */
@media (pointer: coarse) { button.reset { padding: 7px 14px; } }

.row {
  display: grid;
  grid-template-columns: 108px 1fr auto;
  align-items: center;
  gap: 10px;
  margin-bottom: 8px;
}
.row:last-child { margin-bottom: 0; }
.row label { color: var(--muted); font-size: 13px; }
.row.actions { grid-template-columns: 1fr auto; }
/* Canvas: two small number boxes with a × between them, then Square. */
.canvas-size { display: flex; align-items: center; gap: 6px; min-width: 0; }
.canvas-size input[type="number"] { width: 72px; }
.canvas-square { display: flex; align-items: center; gap: 6px; white-space: nowrap; cursor: pointer; }
/* Output: each format's option centred over its Save button, so the two
   columns here line up with .save-grid's below. */
.save-options {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
  justify-items: center;
  margin-top: 8px;
}
.check-inline {
  display: flex;
  align-items: center;
  gap: 6px;
  white-space: nowrap;
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
}
#frames-note { font-style: italic; }
/* The Image section shows only the rows for the chosen kind of background. */
#image:not([data-background="solid"]) .bg-solid-only,
#image:not([data-background="image"]) .bg-image-only { display: none; }
#row-bg-sync[hidden], #bg-sync-note[hidden], #backdrop-image[hidden],
#backdrop-frames[hidden] { display: none; }
#background-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row.file-row { grid-template-columns: 1fr auto; }
.row output { font-variant-numeric: tabular-nums; min-width: 64px; text-align: right; cursor: text; }

/*
 * The box a slider's reading turns into when you double-click it. Sized to
 * roughly the reading it replaces so the row does not jump, and the spinners
 * go because at this width they would cost more than they are worth.
 */
.row input.number-edit {
  width: 84px;
  min-width: 0;
  padding: 3px 5px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  appearance: textfield;
  -moz-appearance: textfield;
}
.row input.number-edit::-webkit-outer-spin-button,
.row input.number-edit::-webkit-inner-spin-button { appearance: none; margin: 0; }

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  /* Vertical swipes scroll the page even when they start on a slider;
     horizontal drags still change the value. */
  touch-action: pan-y;
}
input[type="number"], input[type="text"], textarea, select {
  width: 100%;
  background: var(--field);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 6px 8px;
  font: inherit;
}
input[type="checkbox"] { width: 18px; height: 18px; accent-color: var(--accent); justify-self: start; }
input[type="color"] { width: 56px; height: 30px; padding: 2px; background: var(--field); border: 1px solid var(--line); border-radius: 6px; }
input[readonly] { color: var(--muted); }

button {
  background: var(--panel);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 8px 12px;
  font: inherit;
  cursor: pointer;
  min-height: 36px;
}
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: 0.45; cursor: not-allowed; }
button.primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
button.primary:hover:not(:disabled) { filter: brightness(1.08); }

/* Four exports, so an even 2x2 — no odd one out needing to span. */
.save-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 10px; }

#progress-wrap {
  height: 6px;
  background: var(--field);
  border-radius: 999px;
  overflow: hidden;
  margin: 8px 0;
}
#progress { height: 100%; width: 0; background: var(--accent); transition: width 0.1s linear; }

.muted { color: var(--muted); }
.small { font-size: 12px; }
.warn { color: var(--danger); font-weight: 600; }
/* One step short of .warn: still going to work, but it will cost you. */
.caution { color: var(--caution); font-weight: 600; }
footer { padding: 0 4px 8px; }
button.link {
  background: none;
  border: none;
  padding: 0;
  margin-left: 4px;
  color: var(--accent);
  font: inherit;
  text-decoration: underline;
  cursor: pointer;
}

/*
 * Browser problems, under the file browser (see src/preflight.js): one line
 * each, the headline in .warn (red) or .caution (orange) like every other
 * error, and a link to the Browser check, which holds the explanation.
 */
#alerts { margin: 0 0 8px; }
#alerts:empty { display: none; }
#alerts a { color: var(--accent); white-space: nowrap; }

/*
 * The Advanced picker in the 3D model section. Collapsed by default: it only
 * has anything to say about zips that leave a real choice open, and even then
 * the automatic answer is usually right.
 */
#advanced {
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding-top: 8px;
}
#advanced[hidden] { display: none; }
#advanced > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  list-style: revert;          /* keep the disclosure triangle */
  padding: 2px 0;
}
#advanced > summary:hover { color: var(--text); }
#advanced .row { grid-template-columns: 108px 1fr; margin-top: 8px; }
/* Unflip Backside Image: a label too long for the 108px column. Depth's
   rows share its column, so the picture's checkboxes line up. */
#advanced #row-unflip, #advanced #row-depth { grid-template-columns: 140px auto; justify-content: start; }
#advanced #row-depth-amount { grid-template-columns: 140px 1fr auto; }
#advanced .row[hidden] { display: none; }
#advanced select { min-width: 0; }
#advanced-note { margin: 8px 0 2px; }
#advanced-note:empty { display: none; }

/*
 * The mesh picker: a disclosure inside the Advanced disclosure, because the
 * list is per-model and can run to dozens of entries. It scrolls in its own
 * box so a busy model cannot push the rest of the panel off the screen.
 */
#meshes { margin-top: 8px; }
#meshes[hidden] { display: none; }
#meshes > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 13px;
  list-style: revert;
}
#mesh-toggle-all { margin: 8px 0 6px; }
/*
 * The boxes are labelled by position alone, so they wrap into a grid rather
 * than stacking: twenty-one full-width rows each reading "7" would be almost
 * entirely whitespace, and three wrapped lines can be taken in at a glance.
 */
#mesh-list {
  display: flex;
  flex-wrap: wrap;
  gap: 2px 10px;
  max-height: 240px;
  overflow-y: auto;
  /* Its own edge, so a half-scrolled list reads as a list and not as the end
     of the panel. */
  border: 1px solid var(--line);
  border-radius: 4px;
  padding: 5px 7px;
}
.mesh-row {
  display: flex;
  align-items: center;
  gap: 4px;
  font-size: 12px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  cursor: pointer;
}
.mesh-row input { flex: none; margin: 0; }

/*
 * The Rendering section's two disclosures. Styled as the Model section's
 * Advanced one is, so "there is more in here" reads the same everywhere.
 */
details.more {
  border-top: 1px solid var(--line);
  margin-top: 10px;
  padding-top: 8px;
}
details.more > summary {
  cursor: pointer;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  list-style: revert;
  padding: 2px 0;
}
details.more > summary:hover { color: var(--text); }
details.more[open] > summary { margin-bottom: 8px; }

/*
 * Each setting hides the controls that mean nothing under it: Phong's
 * highlight pair under Realistic, the environment under Retro, which never
 * uses one, the ambient while an environment stands in for it, exposure with
 * no tone mapping to apply it, and the floor's darkness with no floor. The
 * attributes are set from main.js.
 */
#rendering[data-shading="physical"] .classic-only,
#rendering[data-shading="classic"] .pbr-only,
#rendering[data-environment="lit"] .hemi-only,
#rendering:not([data-environment="lit"]) .env-only,
#rendering[data-tone="none"] .tone-only,
#rendering:not([data-shadows="ground"]) .ground-only { display: none; }

/* The quick lighting buttons: two rows of four. */
.preset-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  margin: 4px 0 2px;
}
.preset-grid button {
  min-width: 0;
  padding: 6px 4px;
  font-size: 13px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
/* A phone leaves each button about 60px, and the touch gutter takes more. */
@media (max-width: 480px) {
  .preset-grid { gap: 4px; }
  .preset-grid button { font-size: 12px; padding: 6px 2px; }
}
.preset-grid button[aria-pressed="true"] {
  border-color: var(--accent);
  background: var(--accent);
  color: var(--on-accent);
}
#shading-note { margin: -2px 0 8px; }
#shading-note:empty { display: none; }

/* The layer switches: two columns of checkboxes, greyed when unused. */
#layer-list {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px 10px;
  margin: 2px 0 10px;
}
.layer-row {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 12px;
  color: var(--muted);
  cursor: pointer;
}
.layer-row input { flex: none; margin: 0; }
.layer-row.unused { opacity: 0.45; cursor: default; }
.layer-row .count { font-variant-numeric: tabular-nums; margin-left: auto; }

/*
 * The caption boxes are three lines tall so a whole caption is visible while
 * it is being written, and the label sits at the top of that box rather than
 * floating in the middle of it.
 */
.row-text { align-items: start; }
.row-text label { padding-top: 6px; }
/*
 * Two lines for the three In Front boxes, three for On Top's single one —
 * the band is one paragraph, so it earns the extra row. Both stay draggable.
 */
#text-blocks textarea, #text-band textarea {
  resize: vertical;
  min-height: calc(2em + 12px);
  font-family: inherit;
  line-height: 1.35;
}
#text-band textarea { min-height: calc(3em + 12px); }
#text-blocks[hidden], #text-band[hidden], #text-style[hidden],
#text-stroke-row[hidden], #fg-rows[hidden], #row-fg-sync[hidden],
#fg-sync-note[hidden] { display: none; }
#fg-name { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#spin-more .row[hidden] { display: none; }

#replacers[hidden] { display: none; }
/*
 * Each replacer is a Replace/With pair under its own heading. The rule above
 * the heading is the divider: without it a run of four pairs reads as eight
 * unrelated dropdowns rather than four things.
 */
.replacer-head {
  margin: 12px 0 2px;
  padding-top: 9px;
  border-top: 1px dashed var(--line);
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}
/* The trailing empty pair is an invitation, not a setting. */
.replacer-head.empty { opacity: 0.6; }

/* --------------------------------------------------- mobile / touch layout
 * Width alone misses landscape tablets, so pointer:coarse is included too.
 * Being pure CSS, this switches instantly on rotation with no JS involved.
 */
@media (max-width: 860px), (pointer: coarse) {
  :root { --gutter: 56px; }

  #app {
    grid-template-columns: 1fr;
    grid-template-rows: 45vh 1fr;
    grid-template-areas:
      "view"
      "panel";
    height: auto;
    min-height: 100%;
  }

  /* Keep the model on screen while the settings scroll past it, otherwise
     adjusting a slider low in the list gives no visible feedback. */
  #view {
    position: sticky;
    top: 0;
    z-index: 2;
    height: 45vh;
    background: var(--bg);
    border-bottom: 1px solid var(--line);
  }

  #panel {
    overflow: visible;       /* the page scrolls, not the panel */
    border-right: none;
  }

  /* 96px wrapped the longest label, "Z (Move Forward)", onto two lines. */
  .row { grid-template-columns: 104px 1fr auto; }
  .row output { min-width: 56px; }
  /* Match the reading it replaces, so editing barely narrows the slider. */
  .row input.number-edit { width: 64px; }
  /* Canvas fits a phone's width on one line: its short label gives up the
     label column's spare room, and the boxes hold four digits and no more. */
  .canvas-row { grid-template-columns: auto 1fr auto; }
  .canvas-size input[type="number"] { width: 56px; padding: 6px 5px; }

  /*
   * Stack the Advanced rows. These dropdowns hold filenames — "Adeleine
   * Medium-High.dae" — and a 108px label column leaves them too narrow to
   * tell two variants of the same model apart, which is the entire reason
   * the picker exists.
   */
  #advanced .row { grid-template-columns: 1fr; gap: 4px; }

  /* Fit the view's toggles on one line on a phone. */
  #view-foot { font-size: 13px; gap: 6px 10px; }
  .view-toggles { gap: 10px; }
  #view-foot input[type="checkbox"] { width: 15px; height: 15px; }

  /* Three toggles, a frame rate and a resolution will not fit across a phone.
     While the preview is running the rate takes the resolution's slot: the
     resolution is also the Image section's Width and Height, whereas the rate
     actually achieved is shown nowhere else. */
  #view-foot:has(#preview-fps:not(:empty)) #view-size { display: none; }
}

/* ------------------------------------------- portrait phones: square stage
 * A fixed 45vh strip is much wider than it is tall on a phone held upright,
 * so a square render had its top and bottom cropped. Here the stage takes its
 * size from its *width* and is locked square, which is the shape the render
 * almost always is — so it fits exactly, with no letterboxing either.
 *
 * Capped at 55vh so a short phone still shows the top of the settings list
 * and it is obvious the page scrolls. Past that cap the stage stops being
 * square and the canvas falls back to fitting inside it, which the min-height
 * rule above now allows.
 */
@media (max-width: 860px) and (orientation: portrait),
       (pointer: coarse) and (orientation: portrait) {
  /* Let the row take its height from the square stage instead of forcing 45vh. */
  #app { grid-template-rows: auto 1fr; }
  #view { height: auto; }

  #stage {
    flex: none;               /* stop it stretching to fill the view */
    width: min(100%, 55vh);
    max-height: 55vh;
    aspect-ratio: 1 / 1;
    align-self: center;       /* column flex: cross axis is horizontal */
  }
}

/* ------------------------------------------------------------- console */

/*
 * The Console look: grey plastic, buttons that press down, and a colour per
 * section, red at the top running through the rainbow to a purplish red at
 * Output. A section's colour is its --accent, so its title dot, sliders,
 * checkboxes, chosen preset and main button all share it. Outside the
 * sections the accent is Text's purple, from :root.
 *
 * Sections are matched by position in the panel, top to bottom: 3D model,
 * Spin, View, Position, Image, Rendering, Text, Output.
 */
#panel > section.group:nth-of-type(1) { --accent: #e8392f; --on-accent: #fff; }
#panel > section.group:nth-of-type(2) { --accent: #f07a1a; --on-accent: #232326; }
#panel > section.group:nth-of-type(3) { --accent: #f2b705; --on-accent: #232326; }
#panel > section.group:nth-of-type(4) { --accent: #2fae4a; --on-accent: #232326; }
#panel > section.group:nth-of-type(5) { --accent: #17a6a6; --on-accent: #232326; }
#panel > section.group:nth-of-type(6) { --accent: #2f6fe0; --on-accent: #fff; }
#panel > section.group:nth-of-type(7) { --accent: #8a4fe0; --on-accent: #fff; }
#panel > section.group:nth-of-type(8) { --accent: #c8378a; --on-accent: #fff; }

#panel { scrollbar-color: var(--line) var(--panel); }

.group {
  border: 2px solid #232326;
  box-shadow: inset 0 2px 0 #ffffff12;
}
/* Oswald, the bundled bold cut: condensed, but less so than Anton. */
.group h2 {
  font-family: 'Oswald', Impact, sans-serif;
  font-weight: 400;
  font-size: 17px;
  letter-spacing: 0.08em;
}
.group h2::before {
  width: 12px;
  height: 12px;
  border-radius: 50%;
  box-shadow: inset 0 -2px 0 #0004;
}

input[type="number"], input[type="text"], textarea, select, input[type="color"] {
  border-radius: 9px;
}
input[type="checkbox"] { accent-color: var(--accent); }

/* Buttons stand proud of the panel on a dark edge, and press down into it. */
button {
  background: #4a4a50;
  border: none;
  border-radius: 9px;
  box-shadow: 0 3px 0 var(--shadow);
  font-weight: 600;
}
button:hover:not(:disabled) { filter: brightness(1.12); }
button:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 var(--shadow); }
button.primary {
  background: var(--accent);
  color: var(--on-accent);
  box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 55%, black);
}
.preset-grid button[aria-pressed="true"] {
  box-shadow: 0 3px 0 color-mix(in srgb, var(--accent) 55%, black);
}
button.reset {
  background: transparent;
  border: 1px solid var(--line);
  border-radius: 999px;
  box-shadow: none;
  font-weight: 400;
}
button.reset:hover:not(:disabled) { border-color: var(--accent); filter: none; }
button.reset:active:not(:disabled) { transform: none; box-shadow: none; }
button.link { box-shadow: none; font-weight: inherit; }
/* The wordmark is a button (it plays the theme), but it should look like
   nothing but the logo: no raised edge, no glow, no press. */
#app-logo, #app-logo:hover, #app-logo:active {
  box-shadow: none;
  filter: none;
  transform: none;
  border-radius: 0;
}
button.link:active:not(:disabled) { transform: none; }

/* Sliders keep the browser's own look; accent-color (set on them above)
   paints each one in its section's colour. */
