/* CPAL-1.0 License. See chaosaccelerator.com/license.html */

:root {
  --bg: #14161c;
  --bg-panel: #1b1e27;
  --bg-input: #0f1116;
  --border: #2c3040;
  --text: #e6e8ef;
  --text-dim: #9399ad;
  --accent: #5b8cff;
  --accent-hover: #75a0ff;
  --danger: #ff5f56;
  --panel-width: 320px;
  /* Floating-panel inset and fill: lighter than --bg-panel so it reads as sitting ON the fractal. */
  --panel-inset: 14px;
  --bg-panel-float: rgba(27, 30, 39, 0.86);
  /* How far a floating card's shadow reaches; both scroll columns pad by this and pull it back with negative margin. */
  --menu-shadow-room: 40px;
  /* Kept clear for the back link, the two collapsed menu buttons and the render ring under them, a term each. */
  --menu-reserved: calc((var(--settings-btn-size) + 8px) * 3 + var(--settings-btn-size) * 0.75 + 8px);
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

#app {
  height: 100vh;
  display: flex;
  flex-direction: column;
}

.status-ok {
  font-size: 12px;
  padding: 4px 10px;
  border-radius: 999px;
  white-space: nowrap;
}
.status-ok { background: #21273a; color: #9db0e8; }
.status-error { background: #3a1418; color: #ff9a9a; }

/* Shown for errors only. */
#grid-status:not(.status-error) {
  display: none;
}
#grid-status.status-error {
  width: 100%;
}

#grid-main {
  position: relative;
  flex: 1;
  display: flex;
  min-height: 0;
}

/* ---- The menu column: the back link and four menus, a square button each until opened ---- */
/* Absolute over the map; pointer-events: none, back on per item, so drags beside a collapsed button reach the fractal. */
#grid-menu-column {
  position: absolute;
  z-index: 3;
  top: var(--panel-inset);
  left: var(--panel-inset);
  width: var(--panel-width);
  max-width: calc(100% - var(--panel-inset) * 2);
  pointer-events: none;
}
#grid-menu-stack {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 8px;
  /* Viewport units: a percentage max-height against this auto-height parent resolves to none. */
  max-height: calc(100vh - var(--panel-inset) * 2);
  overflow-y: auto;
  /* overflow-y alone pulls overflow-x to auto; a long hover readout grew a horizontal scrollbar. */
  overflow-x: hidden;
  /* Room for shadows a scroll container would clip, pulled back with negative margin; content-box keeps max-height measuring content. */
  box-sizing: content-box;
  padding: var(--panel-inset) var(--menu-shadow-room) var(--menu-shadow-room) var(--panel-inset);
  margin: calc(-1 * var(--panel-inset)) calc(-1 * var(--menu-shadow-room)) calc(-1 * var(--menu-shadow-room)) calc(-1 * var(--panel-inset));
}
#grid-menu-stack > * {
  pointer-events: auto;
  flex-shrink: 0;
}

/* Dark scrollbars: Firefox reads scrollbar-*, the rest the ::-webkit rules. */
#grid-menu-stack,
.menu-card-body {
  scrollbar-width: thin;
  scrollbar-color: var(--border) transparent;
}
#grid-menu-stack::-webkit-scrollbar,
.menu-card-body::-webkit-scrollbar {
  width: 10px;
}
#grid-menu-stack::-webkit-scrollbar-track,
.menu-card-body::-webkit-scrollbar-track {
  background: transparent;
}
#grid-menu-stack::-webkit-scrollbar-thumb,
.menu-card-body::-webkit-scrollbar-thumb {
  background-color: var(--border);
  border-radius: 6px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
#grid-menu-stack::-webkit-scrollbar-thumb:hover,
.menu-card-body::-webkit-scrollbar-thumb:hover {
  background-color: var(--accent);
  background-clip: padding-box;
}

/* The shared floating-card look. Two shadows: the tight one keeps the top and left edges readable. */
.menu-back,
.menu-toggle,
.menu-card {
  background: var(--bg-panel-float);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5), 0 10px 30px rgba(0, 0, 0, 0.45);
}

.menu-back {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: var(--settings-btn-size);
  padding: 0 14px;
  border-radius: 10px;
  font-size: 13px;
  line-height: 1;
  white-space: nowrap;
  text-decoration: none;
  color: var(--text);
}
.menu-back:hover {
  background: var(--bg-input);
  border-color: var(--accent);
}

.menu-item {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
}

.menu-toggle {
  width: var(--settings-btn-size);
  height: var(--settings-btn-size);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  font-size: 18px;
  line-height: 1;
  color: var(--text);
  border-radius: 10px;
  cursor: pointer;
}
.menu-toggle:hover {
  background: var(--bg-input);
  border-color: var(--accent);
}
/* Exactly one of the button and the card is in the layout at a time. */
.menu-item.is-open > .menu-toggle {
  display: none;
}

.menu-card {
  width: var(--panel-width);
  max-width: 100%;
  /* Room for the back link and menu buttons, so one tall card cannot swallow the column. */
  max-height: calc(100vh - var(--panel-inset) * 2 - var(--menu-reserved));
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  /* Grows from the button's corner. An animation, not a transition: the card is display: none when shut. */
  transform-origin: top left;
  animation: menu-card-open 0.14s ease-out;
}
.menu-card[hidden] {
  display: none;
}
@keyframes menu-card-open {
  from { opacity: 0; transform: scale(0.96); }
  to { opacity: 1; transform: scale(1); }
}

/* The whole header row is the collapse control (see makeMenu in fractal-grid.js). */
.menu-card-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 10px 10px 14px;
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  cursor: pointer;
}
.menu-card-header:hover {
  background: var(--bg-input);
}
.menu-card-header h2 {
  font-size: 14px;
  margin: 0;
  flex: 1;
  min-width: 0;
}
.menu-card-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  color: var(--text-dim);
  font-size: 15px;
  line-height: 1;
}
.menu-collapse {
  flex-shrink: 0;
  font-size: 16px;
}

.menu-card-body {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  min-width: 0;
  overflow-y: auto;
  /* As for #grid-menu-stack: keeps overflow-y from growing a horizontal scrollbar. */
  overflow-x: hidden;
}
.menu-card-body > .panel-section + .panel-section {
  margin-top: 8px;
}

/* Pinned to the column's right edge, outside the scrolling stack; the drag handler writes --panel-width. */
#panel-resizer {
  position: absolute;
  top: 0;
  right: 0;
  height: 100%;
  width: 6px;
  cursor: col-resize;
  background: transparent;
  border-radius: 0 12px 12px 0;
  pointer-events: auto;
  display: none;
}
#grid-menu-column.has-open-menu > #panel-resizer {
  display: block;
}
#panel-resizer:hover,
#panel-resizer.dragging {
  background: var(--accent);
}
/* Widen the hit area past the visible 6px line. */
#panel-resizer::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  left: -3px;
  right: -3px;
}

button {
  font-family: inherit;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid transparent;
  background: var(--accent);
  color: white;
  cursor: pointer;
}
button:hover { background: var(--accent-hover); }
#grid-view button:disabled {
  cursor: default;
  opacity: 0.5;
  background: var(--border);
  color: var(--text-dim);
}
#grid-view button.secondary {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
  padding: 6px 10px;
}
button.secondary:hover { background: var(--bg-input); }
/* Inspect Line/Grid idle: outlined like .tool-btn. Not .secondary, whose padding would resize the button as it arms. */
#btn-inspect-line,
#btn-inspect-grid {
  background: transparent;
  border-color: var(--border);
  color: var(--text);
}
#btn-inspect-line:hover,
#btn-inspect-grid:hover {
  background: var(--bg-input);
}
/* Armed: blue, like .tool-btn.active. ID plus class so this outranks the idle rule on specificity, not source order. */
#btn-inspect-line.inspect-armed,
#btn-inspect-grid.inspect-armed {
  background: var(--accent);
  border-color: var(--accent);
  color: white;
}
#btn-inspect-line.inspect-armed:hover,
#btn-inspect-grid.inspect-armed:hover {
  background: var(--accent-hover);
}

#grid-view .field-row {
  display: flex;
  align-items: center;
  gap: 10px;
}
#grid-view #btn-reset-view {
  flex: none;
  font-size: 12px;
  padding: 5px 10px;
}
#grid-view #zoom-readout {
  flex: 1;
  margin: 0;
  white-space: normal;
}

.tool-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.section-label {
  font-size: 12px;
  color: var(--text-dim);
  margin: 12px 0 8px 0;
}

#grid-view .field {
  display: block;
  font-size: 13px;
  margin-bottom: 14px;
}
#grid-view .field span {
  display: block;
  margin-bottom: 6px;
  color: var(--text-dim);
}
/* ---- Scoped to #grid-view ---- */
/* The editor styles the same classes globally; scoping these keeps load order from deciding which view wins. */
#grid-view .field select {
  width: 100%;
  font: inherit;
  padding: 5px 7px;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 5px;
}
/* A hint under a control. Two classes deep to outrank `.field span` above. */
.field .field-hint,
.toggle-field .field-hint {
  display: block;
  margin: 6px 0 0 0;
  font-size: 11.5px;
  line-height: 1.45;
  color: var(--text-dim);
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

/* Dual-handle slider: two native ranges on one track, pointer-events: none except their thumbs (see resolutionMinSlider in fractal-grid.js). */
.dual-range {
  position: relative;
  height: 24px;
  display: flex;
  align-items: center;
}
.dual-range-track {
  position: absolute;
  left: 0;
  right: 0;
  height: 4px;
  border-radius: 2px;
  background: var(--border);
}
.dual-range-fill {
  position: absolute;
  height: 4px;
  border-radius: 2px;
  background: var(--accent);
}
.dual-range input[type="range"] {
  position: absolute;
  left: 0;
  right: 0;
  width: 100%;
  margin: 0;
  background: none;
  pointer-events: none;
  -webkit-appearance: none;
  appearance: none;
}
.dual-range input[type="range"]::-webkit-slider-runnable-track {
  -webkit-appearance: none;
  background: transparent;
  height: 4px;
}
.dual-range input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  pointer-events: auto;
  width: 14px;
  height: 14px;
  margin-top: -5px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-panel);
  cursor: pointer;
}
.dual-range input[type="range"]::-moz-range-track {
  background: transparent;
  height: 4px;
}
.dual-range input[type="range"]::-moz-range-thumb {
  pointer-events: auto;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-panel);
  cursor: pointer;
}

/* Apple-style switch drawn over the real checkbox (visually hidden), styled off :checked; mirrors the editor's Sticky Edges toggle. */
#grid-view .toggle-field {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  font-size: 13px;
  margin-bottom: 14px;
  cursor: pointer;
}
.toggle-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 24px;
  flex-shrink: 0;
}
.toggle-switch input {
  position: absolute;
  opacity: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  cursor: pointer;
}
.toggle-slider {
  position: absolute;
  inset: 0;
  background: var(--border);
  border-radius: 999px;
  transition: background 0.15s ease;
  pointer-events: none;
}
.toggle-slider::before {
  content: "";
  position: absolute;
  width: 18px;
  height: 18px;
  left: 3px;
  top: 3px;
  background: white;
  border-radius: 50%;
  transition: transform 0.15s ease;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.4);
}
/* Off, the Playback with Inspect tab switch asks for attention: a pulsing glow, a sweep of light, the label lit. */
#evolution-inspect-checkbox:not(:checked) + .toggle-slider {
  overflow: hidden;
  background: color-mix(in srgb, var(--accent) 35%, var(--border));
  box-shadow: 0 0 0 1px var(--accent), 0 0 10px var(--accent);
  animation: toggle-nudge-glow 1.6s ease-in-out infinite;
}
#evolution-inspect-checkbox:not(:checked) + .toggle-slider::after {
  content: "";
  position: absolute;
  top: 0;
  bottom: 0;
  width: 40%;
  left: -40%;
  background: linear-gradient(100deg, transparent, rgba(255, 255, 255, 0.55), transparent);
  animation: toggle-nudge-sweep 1.6s ease-in-out infinite;
}
.toggle-field:has(#evolution-inspect-checkbox:not(:checked)) > span:first-child {
  color: var(--accent);
  font-weight: 600;
}
@keyframes toggle-nudge-glow {
  0%, 100% { box-shadow: 0 0 0 1px var(--accent), 0 0 4px var(--accent); }
  50% { box-shadow: 0 0 0 2px var(--accent), 0 0 14px var(--accent); }
}
@keyframes toggle-nudge-sweep {
  0%, 35% { left: -40%; }
  100% { left: 100%; }
}
@media (prefers-reduced-motion: reduce) {
  #evolution-inspect-checkbox:not(:checked) + .toggle-slider,
  #evolution-inspect-checkbox:not(:checked) + .toggle-slider::after { animation: none; }
}
.toggle-switch input:checked + .toggle-slider {
  background: var(--accent);
}
.toggle-switch input:checked + .toggle-slider::before {
  transform: translateX(20px);
}

#grid-view .readout {
  font-size: 12px;
  color: var(--text-dim);
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

/* The one long readout: wraps. Two IDs so it beats #grid-view .readout regardless of order. */
#grid-view #hover-readout {
  white-space: normal;
  overflow-wrap: break-word;
}

#hover-preview {
  position: relative;
  width: 100%;
  border-radius: 8px;
  overflow: hidden;
  border: 1px solid var(--border);
  /* A plain color, not transparent: the background between shapes carries the Output value. */
  background: #0c0d11;
}

#hover-canvas {
  display: block;
  width: 100%;
  height: auto;
  aspect-ratio: 280 / 200;
}

#hover-empty-state {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  padding: 12px;
  font-size: 12px;
  color: var(--text-dim);
  background: #0c0d11;
  pointer-events: none;
}
#hover-empty-state[hidden] {
  display: none;
}

#grid-canvas-area {
  /* Toast clearance above the render-progress ring and the watermark. */
  --toast-bottom: calc(var(--panel-inset) + var(--settings-btn-size) * 0.75 + 16px);
  flex: 1;
  position: relative;
  min-width: 0;
  background: #0c0d11;
  /* Clips .inspect-marker dots for points panned outside the visible grid. */
  overflow: hidden;
  /* Touch gestures go to fractal-grid.js's own pan/pinch handlers, not the browser's. */
  touch-action: none;
}

/* The center of the frame while the Movie card is open: a light line with a dark halo reads on any color. */
#movie-center-lines {
  position: absolute;
  inset: 0;
  z-index: 2;
  pointer-events: none;
}
#movie-center-lines span {
  position: absolute;
  background: rgba(255, 255, 255, 0.85);
  box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
}
#movie-center-lines span:first-child { left: 0; right: 0; top: 50%; height: 1px; transform: translateY(-50%); }
#movie-center-lines span:last-child { top: 0; bottom: 0; left: 50%; width: 1px; transform: translateX(-50%); }

/* One per Inspect point, on the grid itself (a grid entry draws its mesh in #inspect-preview instead). */
/* --marker-color and left/top (CSS px in #grid-canvas-area's box) are set from JS; clickable to remove the point. */
.inspect-marker {
  position: absolute;
  width: 14px;
  height: 14px;
  margin-left: -7px;
  margin-top: -7px;
  border-radius: 50%;
  border: 2px solid #000;
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.5);
  cursor: pointer;
  background: var(--marker-color);
}
/* Hover previews the click: a plain x on a dark disc, the same meaning as .inspect-row-remove. */
.inspect-marker:hover {
  background: var(--bg-panel);
  border-color: var(--danger);
  display: flex;
  align-items: center;
  justify-content: center;
}
.inspect-marker:hover::after {
  content: "\00d7";
  font-size: 13px;
  font-weight: 700;
  line-height: 1;
  color: var(--danger);
}

/* One SVG for the Inspect (Line) drag preview, the Inspect (Grid) drag rectangle, and an added grid's permanent mesh. */
/* No viewBox: 1 SVG unit = 1 CSS pixel, matching worldToCanvasAreaPixel. */
#inspect-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}
/* The UA [hidden] rule does not reliably hide SVG shapes; this explicit one does. */
#inspect-preview [hidden] {
  display: none;
}

/* The render-progress gauge, lower left: a fifth menu on the shared .menu-item machinery, in the LEFT accordion group. */
#menu-render-progress {
  position: absolute;
  left: var(--panel-inset);
  bottom: var(--panel-inset);
}

/* ---- Settings and Map Evolution, top right: their own accordion group, never closing anything on the left ---- */
/* A real column like #grid-menu-stack: a button leaves the layout when its card opens, so they must stack; flex-end pins the right edge. */
#grid-right-menu-column {
  position: absolute;
  z-index: 3;
  top: var(--panel-inset);
  right: var(--panel-inset);
  max-width: calc(100% - var(--panel-inset) * 2);
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 8px;
  max-height: calc(100vh - var(--panel-inset) * 2);
  /* Scrolls: the Movie card stays open beside Map Evolution, and the two are taller than a laptop screen. */
  overflow-y: auto;
  overflow-x: hidden;
  /* Shadow room as for #grid-menu-stack, mirrored; negative margins keep the buttons and cards put. */
  box-sizing: content-box;
  padding: var(--panel-inset) var(--panel-inset) var(--menu-shadow-room) var(--menu-shadow-room);
  margin: calc(-1 * var(--panel-inset)) calc(-1 * var(--panel-inset)) calc(-1 * var(--menu-shadow-room)) calc(-1 * var(--menu-shadow-room));
  pointer-events: none;
}
#grid-right-menu-column > .menu-item {
  max-width: 100%;
  flex-shrink: 0;
  pointer-events: auto;
}
/* Cards grow from top right and leave room for the other three collapsed buttons plus gaps. */
#grid-right-menu-column .menu-card {
  transform-origin: top right;
  max-height: calc(100vh - var(--panel-inset) * 2 - (var(--settings-btn-size) + 8px) * 3);
}
/* The Challenges card's one link, dressed as a button. */
.challenges-link {
  display: inline-block;
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 6px;
  background: var(--accent);
  color: white;
  text-decoration: none;
}
.challenges-link:hover { background: var(--accent-hover); color: white; text-decoration: none; }
/* The collapsed gauge: no button chrome, just the ring at three-quarter size and half opacity; drop-shadow follows the stroke, box-shadow would be square. */
/* Not .menu-toggle (that carries a square button's chrome), so it needs its own copy of the is-open rule. */
.menu-item.is-open > .render-progress-toggle {
  display: none;
}
.render-progress-toggle {
  width: calc(var(--settings-btn-size) * 0.75);
  height: calc(var(--settings-btn-size) * 0.75);
  padding: 0;
  border: none;
  background: none;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  /* Puts the ring's bottom on the watermark's baseline. */
  position: relative;
  top: -2px;
}
.render-progress-toggle #render-progress-ring {
  width: 100%;
  height: 100%;
  opacity: 0.5;
  filter: drop-shadow(0 2px 6px rgba(0, 0, 0, 0.5)) drop-shadow(0 10px 30px rgba(0, 0, 0, 0.45));
}
/* The open state: a header row and no body, so clicking anywhere closes it; sized to that line and grown from the ring's corner. */
.render-progress-card {
  width: auto;
  max-width: none;
  max-height: none;
  transform-origin: bottom left;
}
.render-progress-header {
  border-bottom: none;
  padding: 6px 16px 6px 6px;
}
.render-progress-icon {
  width: calc(var(--settings-btn-size) * 0.75);
  height: calc(var(--settings-btn-size) * 0.75);
  flex-shrink: 0;
}
.render-progress-icon svg {
  width: 100%;
  height: 100%;
}
.render-progress-lines {
  display: flex;
  flex-direction: column;
  gap: 2px;
  min-width: 0;
}
.render-progress-label {
  font-size: 13px;
  white-space: nowrap;
}
.render-progress-precision {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}
.render-progress-precision-glyph {
  width: 13px;
  height: 13px;
  flex-shrink: 0;
}
.render-progress-precision-glyph[hidden] {
  display: none;
}
/* The precision glyph (see the <defs> in chaos.html): currentColor, so the inline copy takes the line's dim text. */
.precision-glyph-defs {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}
.precision-glyph {
  fill: none;
  stroke: currentColor;
  stroke-width: 2.4;
  stroke-linecap: round;
  stroke-linejoin: round;
}
#render-progress-ring,
.render-progress-icon svg {
  color: #fff;
}
.render-progress-glyph[hidden] {
  display: none;
}
/* Both rings share one path. Rotated 90deg so the dash start lands at 6 o'clock; JS drives dashoffset clockwise from there. */
.render-progress-ring-track {
  fill: none;
  stroke-width: 3;
  stroke-linecap: round;
  transform: rotate(90deg);
  transform-origin: 20px 20px;
}
#render-progress-ring-coarse,
#render-progress-ring-coarse-open {
  stroke: var(--text-dim);
}
#render-progress-ring-aa,
#render-progress-ring-aa-open {
  stroke: #fff;
}

/* ---- The timeline transport: the Map Evolution card's body (see #menu-playback in chaos.html) ---- */
#grid-view #grid-timeline-readout {
  margin: 6px 0 0 0;
  text-align: center;
}

#btn-inspect-clear-all {
  margin-top: 10px;
}
#inspect-list #btn-inspect-clear-all {
  flex: none;
  margin: 0;
  padding: 2px 10px;
  font-size: 12px;
}

#inspect-list {
  list-style: none;
  margin: 12px 0 0 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.inspect-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  color: var(--text-dim);
}

/* 3px either side: the same 18px slot as .inspect-row-icon, so dots and glyphs line up. */
.inspect-dot {
  width: 12px;
  height: 12px;
  margin: 0 3px;
  flex-shrink: 0;
  border-radius: 50%;
  border: 2px solid #000;
}

/* A line/grid row's stand-in for .inspect-dot; align-self: stretch so the big glyph spans the two-line coords group. */
.inspect-row-icon {
  flex-shrink: 0;
  width: 18px;
  align-self: stretch;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  line-height: 1;
  color: var(--text-dim);
}

.inspect-coords-group {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
  font-variant-numeric: tabular-nums;
  /* Deep zooms give long coordinates. */
  overflow-wrap: anywhere;
}

.separation-plot {
  position: relative;
}
#separation-canvas {
  display: block;
  width: 100%;
  height: 150px;
}
/* The playback bar's thumb, on the curve at the frame being shown. */
#separation-playhead {
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent);
  border: 2px solid var(--bg-panel);
  transform: translate(-50%, -50%);
  pointer-events: none;
}
/* Over the plot's top-left corner, right of the axis label; a faint backdrop for when the curve starts up there. */
#separation-lambda {
  position: absolute;
  left: 26px;
  top: 4px;
  padding: 0 3px;
  border-radius: 3px;
  background: rgba(27, 30, 39, 0.7);
  font-size: 11px;
  color: var(--text);
  font-variant-numeric: tabular-nums;
  cursor: default;
}
#separation-lambda sub {
  font-size: 8px;
}

.inspect-row-remove {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-dim);
  border-radius: 6px;
  padding: 0 6px;
  line-height: 1.6;
  cursor: pointer;
}
.inspect-row-remove:hover {
  background: var(--bg-input);
  color: var(--text);
}

/* Opacity-animated and never [hidden]: display: none in the same moment leaves the transition nothing to animate from. */
.inspect-toast {
  position: absolute;
  left: 50%;
  /* See --toast-bottom on #grid-canvas-area. */
  bottom: var(--toast-bottom);
  transform: translateX(-50%);
  z-index: 20;
  max-width: 320px;
  text-align: center;
  background: rgba(12, 13, 17, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 16px;
  color: var(--text);
  font-size: 13px;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s ease;
}
.inspect-toast.visible {
  opacity: 1;
}

/* While a higher precision builds; the spinner stops during the build's pause, the text stays. */
#precision-loading {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 10px;
  background: rgba(12, 13, 17, 0.92);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 18px;
  color: var(--text);
  font-size: 14px;
  white-space: nowrap;
  pointer-events: none;
}
#precision-loading[hidden] {
  display: none;
}
.precision-loading-spinner {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: precision-loading-spin 0.8s linear infinite;
}
.precision-loading-glyph {
  flex-shrink: 0;
  width: 15px;
  height: 15px;
}
@keyframes precision-loading-spin {
  to { transform: rotate(360deg); }
}
@media (prefers-reduced-motion: reduce) {
  .precision-loading-spinner { animation: none; }
}

#grid-canvas {
  width: 100%;
  height: 100%;
  display: block;
  cursor: default;
  touch-action: none;
  /* The backing store matches device pixels; this only guards sub-pixel rounding mismatches. */
  image-rendering: pixelated;
  image-rendering: crisp-edges;
}
#grid-canvas.dragging { cursor: grabbing; }

#empty-state {
  position: absolute;
  inset: 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--text-dim);
  font-size: 14px;
  text-align: center;
  padding: 24px;
}
/* An unconditional display: flex would beat the UA [hidden] rule. */
#empty-state:not([hidden]) {
  display: flex;
}
#empty-state a {
  color: var(--accent);
}

/* Tool tip popover, placed by app-tips.js. Fixed, so the scrolling menu column cannot clip it. */
.tip-popover {
  position: fixed;
  z-index: 1000;
  max-width: 260px;
  background: var(--bg-panel);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.45);
}
.tip-popover[hidden] {
  display: none;
}
/* Arrow offset set per tip by app-tips.js: the body is clamped inside the viewport, so a fixed arrow could point at nothing. */
.tip-popover::before {
  content: "";
  position: absolute;
  top: -6px;
  left: var(--tip-arrow-left, 16px);
  width: 10px;
  height: 10px;
  background: var(--bg-panel);
  border-left: 1px solid var(--accent);
  border-top: 1px solid var(--accent);
  transform: rotate(45deg);
}
.tip-popover p {
  margin: 0 0 10px 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text);
}
.tip-popover-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}
.tip-popover-actions button {
  flex-shrink: 0;
  white-space: nowrap;
  font-size: 12px;
  padding: 5px 14px;
}
/* Gray beside the accent button. */
#tip-popover-dismiss {
  padding: 4px 10px;
  border: 1px solid #555b6e;
  background: #353a4a;
  color: var(--text-dim);
  font-size: 11px;
  line-height: 1.3;
  text-align: left;
}
#tip-popover-dismiss:hover {
  background: #424859;
  color: var(--text);
}

.icon-button {
  flex-shrink: 0;
  width: 32px;
  height: 32px;
  padding: 0;
  font-size: 16px;
  line-height: 1;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text);
}
.icon-button:hover {
  background: var(--bg-input);
}

/* ---- Display Mode rows: a thumbnail and a sentence per mode; a radiogroup, since the thumbnail IS the explanation ---- */
#grid-display-panel-body {
  padding: 14px 6px 6px 6px;
}
#grid-display-mode-list {
  display: flex;
  flex-direction: column;
  gap: 0;
}

.display-mode-row {
  display: flex;
  align-items: center;
  gap: 11px;
  width: 100%;
  padding: 8px;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  text-align: left;
  color: var(--text);
  cursor: pointer;
  /* Rows are buttons: undo button's own centring and font-size. */
  font: inherit;
}
.display-mode-row + .display-mode-row {
  margin-top: 2px;
}
.display-mode-row:hover {
  background: var(--bg-input);
}
.display-mode-row[aria-checked="true"] {
  background: var(--bg-input);
  border-color: var(--accent);
}

/* A share of the row, so the resizer scales thumbnail and text together. */
.display-mode-row img {
  flex: 0 0 auto;
  /* min-width: 0 too: an <img>'s intrinsic 400px is what min-width: auto resolves to in a flex row. */
  width: 44%;
  min-width: 0;
  height: auto;
  display: block;
  border-radius: 6px;
}

/* min-width: 0 so a long word wraps instead of pushing the thumbnail out. */
/* Font size and line height are tuned so the text ends a little short of the thumbnail at the card's DEFAULT width; narrower cards get more text than picture. */
.display-mode-text {
  min-width: 0;
  font-size: 13px;
  line-height: 1.5;
  color: var(--text-dim);
}
.display-mode-row[aria-checked="true"] .display-mode-text {
  color: var(--text);
}
.display-mode-name {
  display: block;
  font-weight: 600;
  color: var(--text);
}
.display-mode-text .toggle-field {
  margin-top: 6px;
}
/* Two stacked switches: pull the second up under the first. */
.display-mode-text .toggle-field + .toggle-field {
  margin-top: -6px;
}
.display-mode-cost {
  display: block;
  font-size: 12px;
  color: var(--text-dim);
}

/* ---- Longest-ridge / longest-valley overlay: made from JS (setFeatureOverlay) only while asked for; no pointer events ---- */
#grid-feature-overlay {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* ---- The Movie card (see "Movies" in fractal-grid.js) ---- */

#movie-add-keyframe,
#movie-done {
  width: 100%;
}
#grid-view #movie-inspect,
#grid-view #movie-export {
  display: block;
  margin: 8px auto 0;
  padding: 4px 10px;
  font-size: 12px;
}
#movie-export-progress {
  margin: 10px 0 0 0;
  padding: 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--bg-input);
}
#grid-view #movie-export[hidden],
#movie-export-progress[hidden] {
  display: none;
}
#movie-export-progress p {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--text);
}
.movie-export-track {
  height: 6px;
  margin-bottom: 8px;
  border-radius: 3px;
  background: var(--bg-panel);
  overflow: hidden;
}
#movie-export-bar {
  width: 0;
  height: 100%;
  background: var(--accent);
}
#movie-export-cancel {
  padding: 4px 10px;
  font-size: 12px;
}

#movie-keyframe-list {
  list-style: none;
  margin: 10px 0 12px 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
#movie-keyframe-list:empty {
  display: none;
}

.movie-keyframe {
  padding: 6px 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-input);
  font-size: 12px;
  color: var(--text-dim);
}
.movie-keyframe-what {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px 8px;
  white-space: pre;
}
.movie-keyframe-what b {
  flex-shrink: 0;
  min-width: 18px;
  height: 18px;
  padding: 0 4px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 9px;
  background: var(--accent);
  color: #fff;
  font-size: 11px;
}
.movie-field {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  flex-shrink: 0;
}
.movie-field-caption {
  color: var(--text-dim);
  font-size: 11px;
}
.movie-field input {
  width: 62px;
  padding: 2px 4px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
  text-align: right;
  color: var(--text);
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: 5px;
}
.movie-field input:focus {
  outline: none;
  border-color: var(--accent);
}
.movie-field-arrows {
  display: inline-flex;
  flex-direction: column;
  gap: 1px;
}
.movie-field-arrows button {
  width: 16px;
  height: 10px;
  padding: 0;
  font-size: 7px;
  line-height: 1;
  color: var(--text-dim);
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  cursor: pointer;
}
.movie-field-arrows button:hover {
  color: var(--text);
  background: var(--bg-input);
  border-color: var(--accent);
}
.movie-keyframe-actions {
  display: flex;
  justify-content: flex-end;
  gap: 4px;
  margin-top: 6px;
}
.movie-keyframe-actions .icon-button {
  width: 26px;
  height: 24px;
  font-size: 13px;
}
#movie-summary {
  margin: 10px 0;
}
#movie-paused {
  margin: 0 0 12px 0;
  padding: 10px;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--bg-input);
}
#movie-paused[hidden] {
  display: none;
}
#movie-paused p {
  margin: 0 0 8px 0;
  font-size: 13px;
  color: var(--text);
}
.movie-size {
  display: flex;
  align-items: center;
  gap: 8px;
  color: var(--text-dim);
}
.movie-size input {
  flex: 1;
  min-width: 0;
  padding: 5px 7px;
  font: inherit;
  font-variant-numeric: tabular-nums;
  text-align: center;
  color: var(--text);
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 5px;
}
.movie-size input:focus {
  outline: none;
  border-color: var(--accent);
}

/* ---- Settings > Performance Settings (see Performance settings in fractal-grid.js) ---- */

.settings-section {
  display: flex;
  flex-direction: column;
  margin-top: 4px;
  padding-top: 14px;
  border-top: 1px solid var(--border);
}
.settings-section h3 {
  margin: 0 0 12px 0;
  font-size: 12px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--text-dim);
}
#grid-view #perf-readout-field {
  margin: 4px 0 0 0;
  padding-top: 14px;
  border-top: 1px dashed var(--border);
}

/* Preset labels: a three-column grid so Custom stays under the middle stop. */
.perf-preset {
  margin-bottom: 10px;
}
.perf-preset-labels {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  gap: 6px;
  margin-top: 4px;
  font-size: 11px;
  line-height: 1.25;
  color: var(--text-dim);
}
.perf-preset-labels span {
  padding: 2px 0;
}
.perf-preset-labels [data-preset="low"] { text-align: left; }
.perf-preset-labels [data-preset="custom"] { text-align: center; }
.perf-preset-labels [data-preset="high"] { text-align: right; }
/* Low and High can be pressed; Custom only ever happens. */
.perf-preset-labels [data-preset="low"],
.perf-preset-labels [data-preset="high"] {
  cursor: pointer;
}
.perf-preset-labels .is-current {
  color: var(--text);
  font-weight: 600;
}
/* Custom only shows while the slider is there; hidden, not removed, since it is the grid's middle column. */
.perf-preset-labels [data-preset="custom"]:not(.is-current) {
  visibility: hidden;
}
/* The controls the slider sets, folded under it (#perf-details): the editor's Advanced disclosure, on this card's fill. */
#perf-details {
  margin-top: 0;
}
#perf-details[open] > summary,
#separation-details[open] > summary {
  background: #1e212b;
}
#perf-details[open] {
  padding-top: 16px;
}
#grid-view .field select:disabled {
  opacity: 0.55;
}

/* Performance readout: bottom center, the one edge no menu opens over. Wraps, since phones are narrower than some lines. */
#perf-readout {
  left: 50%;
  transform: translateX(-50%);
  bottom: 32px;
  z-index: 2;
}
#perf-readout,
#editor-perf-readout {
  position: absolute;
  margin: 0;
  width: max-content;
  max-width: min(440px, calc(100% - 16px));
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(8, 9, 12, 0.78);
  color: #c9f5d0;
  font: 10.5px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}
#perf-readout[hidden] {
  display: none;
}
/* Above the context-lost overlay (z-index 40): both stay readable and tappable while it is up. */
#grid-debug-log {
  position: absolute;
  left: 8px;
  right: 8px;
  top: 8px;
  z-index: 45;
  margin: 0;
  max-height: 60%;
  overflow: auto;
  padding: 6px 8px;
  border-radius: 6px;
  background: rgba(8, 9, 12, 0.85);
  color: #f5d7c9;
  font: 10.5px/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
  user-select: text;
  -webkit-user-select: text;
}
#grid-debug-log[hidden] {
  display: none;
}
#grid-debug-copy {
  position: absolute;
  right: 12px;
  bottom: 40px; /* clear of the watermark */
  z-index: 46;
  padding: 6px 10px;
  font-size: 12px;
}
#grid-debug-copy[hidden] {
  display: none;
}
