/* ─── Cosmos — Product Styles ─────────────────────────────────────────────────
 * Zero dependencies. System fonts. CSS custom properties for theming.
 * The entire visual identity lives here.
 */

:root {
  /* Colors — dark theme */
  --bg: #0d1117;
  --bg-surface: #161b22;
  --bg-card: #1c2128;
  --bg-hover: #21262d;
  --border: #30363d;
  --border-active: #58a6ff;
  --text: #e6edf3;
  --text-secondary: #8b949e;
  --text-muted: #484f58;
  --accent: #58a6ff;
  --accent-dim: rgba(88, 166, 255, 0.15);
  --positive: #3fb950;
  --warning: #d29922;
  --negative: #f85149;

  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  --font-mono: "SF Mono", "Cascadia Code", "Fira Code", monospace;
  --font-size: 13px;
  --font-small: 11px;

  /* Screen-invariant minimum text size, in WORLD px, maintained by
     applyZoomFloors() in canvas.js as (floor / zoom). The interpreter emits
     font-size: max(<authored>, var(--text-floor)), so zoomed-out text stops
     shrinking and content sheds instead. 0px = no floor. */
  --text-floor: 0px;

  /* Same idea for CHROME that must stay clickable — the traffic lights. Also
     world px, also maintained by applyZoomFloors(), and capped so the bulb
     column never outgrows its object. 0px = no floor. */
  --chrome-floor: 0px;

  /* Spacing */
  --gap: 8px;
  --radius: 6px;
  --radius-sm: 4px;
}

/* ─── Reset ──────────────────────────────────────────────────────────────── */

*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-sans);
  font-size: var(--font-size);
  color: var(--text);
  background: var(--bg);
  -webkit-font-smoothing: antialiased;
}

/* ─── Canvas Viewport ────────────────────────────────────────────────────── */
/* No toolbar bar — the toolbar is a Cosmos object on the canvas. */

#cosmos-viewport {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  /* clip, NOT hidden. hidden still creates a scroll container: any focus()
     deep inside (the Explorer's search input, a terminal, a frame's input)
     scrolls the nearest one — invisibly, with no scrollbar. Measured live
     2026-11-16: scrollTop 752 with overflow:hidden, which shifted the world
     AND the screen layer 752px above where every camera/pin formula assumes
     they are: zoom stopped centring on the cursor, pinned objects could not
     reach the lower half of the screen, and the whole canvas drew offset —
     the "top-left feels different" asymmetry. clip paints identically but
     is not scrollable, so the offset cannot exist. canvas.js also zeroes
     scrollTop on init and on any scroll event as a belt-and-braces guard
     for engines without overflow:clip. */
  overflow: clip;
  background: var(--bg);
  cursor: default;
}

/* The active tool (cursor / pan / pen) is canvas state, mirrored onto the
   viewport so bare canvas picks the right cursor up. Objects keep their own. */
#cosmos-viewport[data-tool="pan"] {
  cursor: grab;
}

#cosmos-viewport[data-tool="pen"] {
  cursor: crosshair;
}

#cosmos-world {
  position: absolute;
  top: 0;
  left: 0;
  width: 10000px;
  height: 10000px;
  transform-origin: 0 0;
  /* Panning writes nothing but this element's transform. Promoting it to its
     own composited layer turns a pan into a compositor move instead of a
     repaint of every object, box-shadow and grid tile inside it — including
     the 200000px grid, whose visible tiles are then cached rather than
     re-rastered each frame. */
  will-change: transform;
}

/* ─── Screen layer (pinned objects) ──────────────────────────────────────── */
/* Sits above the world and outside its camera transform, so a pinned object's
   box IS its screen box: panning and zooming cannot move or scale it, and its
   content never reflows because its CSS pixel size never changes. The layer
   itself is click-through; the objects in it are not. */
#cosmos-screen-layer {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  pointer-events: none;
  z-index: 10;
  /* Pinned objects are drawn in screen space, never scaled by the camera, so
     they are already at 1:1 screen px. Inheriting either world-space floor
     would inflate them as the user zooms out — the one thing a floor must not
     do. A declaration here is nearer than the inline one on :root, so it wins. */
  --text-floor: 0px;
  --chrome-floor: 0px;
}

#cosmos-screen-layer > .cosmos-obj {
  pointer-events: auto;
}

/* ─── Grid ───────────────────────────────────────────────────────────────── */

/* The dot field. positionGrid() in canvas.js repositions this element every
   camera change to cover the visible world rect (snapped to 100px cells so
   the pattern stays anchored to world coordinates), which makes the field
   unbounded — the old fixed ±100,000px box had EDGES: pan far enough in any
   direction and the canvas visibly stopped being canvas. The values below are
   only the pre-JS fallback. */
.cosmos-grid {
  position: absolute;
  left: -100000px;
  top: -100000px;
  width: 200000px;
  height: 200000px;
  background-image:
    radial-gradient(circle, rgba(48, 54, 61, 0.5) 1px, transparent 1px),
    radial-gradient(circle, rgba(48, 54, 61, 0.25) 1px, transparent 1px);
  background-size: 100px 100px, 20px 20px;
  pointer-events: none;
}

/* Zoom level-of-detail, driven by applyGridLOD() in canvas.js. The first
   gradient is the 100px field and the second the 20px one, so the fine field is
   the first to go subpixel — and the first to be dropped. */
.cosmos-grid.grid-major-only {
  background-image: radial-gradient(circle at 1px 1px, var(--dot) 1px, transparent 0);
  background-size: 100px 100px;
}

.cosmos-grid.grid-off { background-image: none; }

/* ─── Objects ────────────────────────────────────────────────────────────── */

.cosmos-obj {
  position: absolute;
  display: flex;
  flex-direction: column;
  border: var(--obj-border, 1px solid var(--border));
  border-radius: var(--radius);
  background: var(--bg-card);
  overflow: visible;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.3), 0 4px 12px rgba(0, 0, 0, 0.15);
  transition: box-shadow 0.2s ease, border-color 0.2s ease;
}

.cosmos-obj:hover {
  border-color: var(--text-muted);
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.4), 0 8px 24px rgba(0, 0, 0, 0.2);
}

/* Panning slides the world under a stationary cursor, so hover fires on every
   object it passes — each one repainting a two-layer shadow across 0.2s and
   revealing its lights and resize handles. Zoomed out the objects are smaller,
   so the cursor crosses more of them per second: that is why a pan stutters
   worst there. Stand hover down for the length of the gesture. */
#cosmos-viewport.is-panning .cosmos-obj {
  pointer-events: none;
  transition: none;
}

.cosmos-obj.selected {
  border-color: var(--accent);
  box-shadow: 0 0 0 1.5px var(--accent), 0 4px 20px rgba(88, 166, 255, 0.15), 0 2px 8px rgba(0, 0, 0, 0.3);
}

.cosmos-obj.is-frame {
  border-style: dashed;
  border-width: 1.5px;
  /* The fill alpha is a per-frame variable written by canvas.js from the frame's
     Theming object (or the board-level default). Default 0.5 == the old hardcoded
     value, so a board with no Theming object looks exactly as before. Only the FILL
     fades; contents stay crisp. hover/selected keep their small lift relative to it. */
  background: rgba(22, 27, 34, var(--frame-opacity, 0.5));
  backdrop-filter: blur(4px);
  box-shadow: none;
}

.cosmos-obj.is-frame:hover {
  background: rgba(22, 27, 34, calc(var(--frame-opacity, 0.5) + 0.1));
}

.cosmos-obj.is-frame.selected {
  border-color: var(--accent);
  background: rgba(22, 27, 34, calc(var(--frame-opacity, 0.5) + 0.05));
}

/* Frame as drop target while dragging an object over it.
   Edge only, deliberately: this used to wash the whole frame with
   rgba(88,166,255,.08) plus an outer ring, so dragging over a large (or
   expanded, i.e. full-screen) frame tinted the entire viewport blue — "the frame
   going blue is excessive" (2026-11-13). The border + inset ring name the target
   without repainting its contents. */
.cosmos-obj.is-frame.frame-drop-target {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 1px var(--accent);
}
.cosmos-frame-drop-hint {
  position: absolute;
  top: 30px;
  left: 50%;
  transform: translateX(-50%);
  font-size: max(10px, var(--text-floor, 0px));
  color: var(--accent);
  background: rgba(13, 17, 23, 0.85);
  padding: 3px 10px;
  border-radius: 4px;
  pointer-events: none;
  white-space: nowrap;
  z-index: 5;
}

/* Chromeless: annotation/overlay objects (presents.chrome === false) */
.cosmos-obj.is-chromeless {
  border-color: transparent;
  background: transparent;
  box-shadow: none;
}
.cosmos-obj.is-chromeless:hover {
  border-color: transparent;
  box-shadow: none;
}
.cosmos-obj.is-chromeless > .cosmos-titlebar {
  display: none;
}
/* A bare object's minimised form IS its own paint (the turn pills): the
   lights, float-title and grip are chrome too, and left visible they both
   dress the pill in a titlebar it replaced and sit on top of it, stealing
   the clicks that expand it (measured 2026-11-03). Scoped to bare, not
   chromeless: a chromeless annotation like the toolbar keeps its lights —
   hiding them there amputated chrome the user expects (same day). The grip
   returns on hover so an expanded trace can still be resized by hand. */
.cosmos-obj.is-bare > .cosmos-lights,
.cosmos-obj.is-bare > .cosmos-float-title,
.cosmos-obj.is-bare > .cosmos-resize-handle {
  display: none;
}
.cosmos-obj.is-bare:hover > .cosmos-resize-handle {
  display: block;
}
/* Chromeless objects that KEEP their lights (the toolbar) still park them on
   top of the body: on a pill-sized object that overlay eats the click that
   expands it, even before any bare migration reaches it (measured
   2026-11-03). Visible but never clickable; the grip stays live so an
   expanded trace can still be resized by hand. */
.cosmos-obj.is-chromeless > .cosmos-lights,
.cosmos-obj.is-chromeless > .cosmos-float-title {
  pointer-events: none;
}
/* fill: the leaf is the rectangle — remove the content inset so the painted
   geometry matches the placement exactly (stacker flags, composites). */
.cosmos-obj.is-fill .cosmos-content {
  padding: 0;
  overflow: hidden;
}
.cosmos-viewport[data-tool="pick"] {
  cursor: crosshair;
}

/* ─── Ink (pen strokes) ──────────────────────────────────────────────────── */
/* A stroke is an object, but only the ink itself is hittable — its bounding box
   must not swallow the canvas underneath. Selecting it hands the box back, so a
   stroke can then be dragged and deleted like anything else. */
.cosmos-obj.is-ink {
  border: none;
  background: transparent;
  box-shadow: none;
  pointer-events: none;
}

.cosmos-obj.is-ink:hover {
  border: none;
  box-shadow: none;
}

.cosmos-obj.is-ink.selected {
  pointer-events: auto;
  box-shadow: 0 0 0 1.5px var(--accent);
}

/* The path is written in the object's own local coordinates, so the content box
   has to BE the placement box: no padding, no border, no clipping. */
.cosmos-obj.is-ink .cosmos-content {
  padding: 0;
  overflow: visible;
}

.cosmos-obj.is-ink .cosmos-content > svg {
  display: block;
  flex: 1 1 auto;
  width: 100%;
  height: 100%;
  min-height: 0;
  overflow: visible;
}

.cosmos-obj.is-ink .cosmos-content > svg path {
  pointer-events: stroke;
}

/* A stroke stays the size it was drawn — resizing the box would not resize it. */
.cosmos-obj.is-ink .cosmos-resize-handle {
  display: none;
}

/* Live preview while the pen is down: world space, above what it is drawn over,
   and never a pointer target (the drag is owned by the canvas). */
.cosmos-ink-preview {
  position: absolute;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  overflow: visible;
  pointer-events: none;
  z-index: 100000;
}

.cosmos-ink-preview path {
  fill: none;
  stroke: var(--accent);
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* App-focused: display-leaf has input focus (app mode) */
.cosmos-display-leaf.app-focused {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

/* ─── Title Bar ──────────────────────────────────────────────────────────── */

.cosmos-titlebar {
  min-height: 26px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 8px;
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  border-radius: calc(var(--radius) - 1px) calc(var(--radius) - 1px) 0 0;
  cursor: grab;
  user-select: none;
  flex-shrink: 0;
  /* Exactly one line of text, however large the floor makes it: min-height
     holds the 26px bar at normal zoom, and nowrap below stops a long title
     ever adding a second line — so the bar grows to fit its text and no
     further. Clipping is safe here because the lights, frame grip and operate
     bar are children of the object WRAPPER, not of the bar
     (attachObjectChrome / conversation.js closeOperateBar). */
  overflow: hidden;
}

.cosmos-titlebar:active {
  cursor: grabbing;
}

.cosmos-title {
  font-size: max(var(--font-small), var(--text-floor, 0px));
  line-height: 1.2;
  font-weight: 500;
  color: var(--text);
  text-transform: capitalize;
  /* Bound to the bar's shape: one line, ellipsised rather than wrapped or
     overflowing. min-width:0 is load-bearing — a flex item defaults to
     min-width:auto and will not shrink below its content, so without it the
     ellipsis never appears and the bar overflows instead. */
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1 1 auto;
  min-width: 0;
}

.cosmos-title-id {
  font-size: max(10px, var(--text-floor, 0px));
  line-height: 1.2;
  font-family: var(--font-mono);
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  /* The title outranks the id. Flex shrinkage is distributed in proportion to
     shrink-factor × basis, so a factor this far above the title's 1 makes the
     id absorb essentially all of it: it collapses to zero (min-width:0) and
     only then does the title start giving way. Under an active text floor that
     is exactly what a zoomed-out bar needs — the old even split left a few
     unreadable letters of each, and a bar that shows neither is worse than one
     that shows the title.
     Note the bar's own box does NOT change size with zoom, so this has to be
     flex shrinkage driven by content, not a container query: the titlebar's
     inline size is constant across zoom and the query would never fire. */
  flex: 0 999 auto;
  min-width: 0;
  max-width: 55%;
  margin-left: 8px;
}

/* ─── Content Area ───────────────────────────────────────────────────────── */

.cosmos-content {
  flex: 1;
  overflow: auto;
  padding: 8px;
  font-size: max(var(--font-size), var(--text-floor, 0px));
  line-height: 1.5;
  display: flex;
  flex-direction: column;
  min-height: 0;
  border-radius: 0 0 calc(var(--radius) - 1px) calc(var(--radius) - 1px);
}

/* The interpreted root fills the content box in BOTH axes: flex children
   stretch cross-axis (width) by default but not main-axis (height) — the
   cause of "inner shape resizes horizontally but not vertically".
   Scoped to interpreted roots so custom builders (explorer) keep their
   own flex discipline. */
.cosmos-content > .cosmos-object {
  flex: 1 1 auto;
  min-height: 0;
}
.cosmos-content > * {
  min-height: 0;
}
.cosmos-obj.is-chromeless .cosmos-content {
  border-radius: calc(var(--radius) - 1px);
}

.cosmos-content::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.cosmos-content::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.cosmos-empty {
  color: var(--text-muted);
  font-style: italic;
  font-size: max(var(--font-small), var(--text-floor, 0px));
}

.cosmos-error {
  color: var(--negative);
  font-family: var(--font-mono);
  font-size: max(var(--font-small), var(--text-floor, 0px));
}

/* ─── Frame Children ─────────────────────────────────────────────────────── */

/* Clip and camera are separate divs. A transform moves an element's paint AND
   hit-test box, so when the clipping div was also the transformed one, panning
   or zooming a frame's view dragged the clip boundary off the frame: children
   rendered outside it, and the overgrown invisible container captured presses
   meant for the canvas (a pan outside the frame "caught" the frame). The clip
   never transforms; the camera moves inside it. */
.cosmos-frame-clip {
  position: absolute;
  inset: 0;
  overflow: hidden;
}

.cosmos-frame-children {
  position: absolute;
  inset: 0;
  transform-origin: 0 0;
}

/* Frames are their own spatial canvas: no object chrome, just the viewport */
.cosmos-obj.is-frame > .cosmos-titlebar {
  display: none;
}
.cosmos-frame-grip {
  position: absolute;
  top: 4px;
  left: 6px;
  z-index: 6;
  /* The grip is the frame's ONE handle (title + drag), so it is chrome, not
     content: it holds a minimum SCREEN size via --chrome-floor, the same var the
     traffic lights use, and stays grabbable when the board is zoomed out. It was
     a fixed 9px, unaimable at zoom (2026-11-12). Padding/letter-spacing are in
     em so the chip keeps its proportions as the glyph floors up. */
  font-size: max(9px, var(--chrome-floor, 0px));
  letter-spacing: 0.11em;
  line-height: 1.35;
  color: var(--text-muted);
  background: rgba(13, 17, 23, 0.7);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0.14em 0.78em;
  cursor: grab;
  user-select: none;
}

/* ─── Traffic lights (hover/focus-revealed object controls) ──────────────── */
/* Outside the window, on the left. Direct-child selectors so hovering a
   frame reveals only the frame's lights, not every child's. */
.cosmos-lights {
  /* The bulb size is declared HERE, on the column, so the column can position
     itself around it — and so the bulbs inherit it. The offset has to grow with
     the bulbs, or a floored column spills onto the object's left edge instead of
     hanging beside it. `bulb + 10` is `bulb + 8px horizontal padding + 2px gap`,
     which at the authored 14px reproduces the previous hardcoded -24px exactly. */
  --bulb: max(14px, var(--chrome-floor, 0px));
  position: absolute;
  top: 0;
  left: calc(-1 * (var(--bulb) + 10px));
  z-index: 7;
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 2px 6px 2px 2px;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.12s;
}
.cosmos-obj:hover > .cosmos-lights,
.cosmos-obj.selected > .cosmos-lights {
  opacity: 1;
  pointer-events: auto;
}
.cosmos-light {
  /* A bulb is chrome, not content: it has to stay a clickable target when the
     board is zoomed out, so it holds a minimum SCREEN size. --chrome-floor is
     (lightFloorScreen / zoom) in world px, maintained by applyZoomFloors() in
     canvas.js, and --bulb resolves it once on .cosmos-lights so the column can
     position itself around the same value.
     The cap is a CLICKABILITY bound (LIGHT_MIN_USABLE_SCREEN held down to
     LIGHT_USABLE_TO_ZOOM), not an object-fit bound: the column hangs outside the
     object at left: -(bulb + 10px) and is hover-gated, so outgrowing a small
     object spills into empty canvas rather than over content. The old fit-the-
     default-object cap left bulbs at 9 screen px by zoom 0.35 — too small to
     aim at, which is what was reported. */
  width: var(--bulb, 14px);
  height: var(--bulb, 14px);
  border-radius: 50%;
  border: none;
  cursor: pointer;
  padding: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  /* The glyph scales WITH its container rather than being floored on its own.
     That is the resolution of the old exception: a floored glyph in a FIXED
     14px circle escapes the circle, but now the circle grows too. Ratios are
     the originals — 10/14 here, 8/14 and 9/14 on the overrides below. */
  font-size: calc(var(--bulb, 14px) * 0.714);
  line-height: 1;
  color: rgba(0, 0, 0, 0.8);
  font-weight: 900;
}
.cosmos-light.light-close { background: #f85149; }
.cosmos-light.light-min { background: #d29922; }
.cosmos-light.light-op { background: #db6d28; font-size: calc(var(--bulb, 14px) * 0.571); }
.cosmos-light.light-save { background: #58a6ff; font-size: calc(var(--bulb, 14px) * 0.643); }
.cosmos-light.light-expand { background: #3fb950; font-size: calc(var(--bulb, 14px) * 0.643); }
/* Pin: violet, the one hue the other bulbs don't use, with a location-pin
   icon. A lit pin wears a ring separated by a gap of canvas background, so
   "on" reads at a glance among the row — that ring is the whole signal; a
   pinned object is clear in itself once you pan and it doesn't move. */
.cosmos-light.light-pin { background: #a371f7; }
/* The icon is an inline <svg width="10" height="10"> — a presentation
   attribute, so a percentage here overrides it and the pin scales with the
   bulb instead of staying 10px inside a growing circle. */
.cosmos-light.light-pin svg { display: block; width: 71.4%; height: 71.4%; }
.cosmos-light.light-pin.is-on {
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px #a371f7;
}
.cosmos-obj.is-minimized .cosmos-content { display: none; }
/* Expanded frames keep their lights visible so they can be collapsed — and
   move them INSIDE: an expanded frame's left edge is the viewport's left
   edge, so the hanging column lands off-screen at x<0 and the frame cannot
   be collapsed by mouse (soft lock; Escape in canvas.js is the other exit).
   z-index 7 keeps them over .cosmos-frame-children — "over the frame" is
   exactly the ask. */
.cosmos-obj.is-expanded > .cosmos-lights {
  opacity: 1;
  pointer-events: auto;
  left: 6px;
  top: 4px;
}
/* The grip shares that corner, and resizing an expanded frame is meaningless
   — collapse restores the placement anyway. */
.cosmos-obj.is-expanded > .cosmos-frame-grip {
  opacity: 0;
  pointer-events: none;
}

/* ─── Toolbar object (toolbar-1) ─────────────────────────────────────────── */
/* Buttons are language objects with inline backgrounds, so their hover
   feedback is a filter rather than a background swap CSS could win. The
   toolbar keeps the standard light column like every other object. */
.cosmos-obj[data-id="toolbar-1"] .cosmos-content > .cosmos-object > .cosmos-object {
  transition: filter 0.12s;
}
.cosmos-obj[data-id="toolbar-1"] .cosmos-content > .cosmos-object > .cosmos-object:hover {
  filter: brightness(1.35);
}

/* Operate bar (★ light): speak to the canvas from any object */
.cosmos-operate-bar {
  position: absolute;
  top: 100%;
  left: -24px;
  margin-top: 6px;
  z-index: 9;
  display: flex;
  align-items: center;
  gap: 8px;
  width: max(100%, 300px);
  background: var(--bg-surface);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 5px 8px;
  box-shadow: 0 6px 20px rgba(0, 0, 0, 0.45);
}
.cosmos-operate-bar input {
  flex: 1;
  min-width: 0;
  background: transparent;
  border: none;
  outline: none;
  color: var(--text);
  font-family: var(--font-sans);
  font-size: max(12px, var(--text-floor, 0px));
}
.cosmos-operate-bar input::placeholder {
  color: var(--text-muted);
}
.cosmos-operate-bar .op-hint {
  font-size: max(9px, var(--text-floor, 0px));
  color: var(--text-muted);
  white-space: nowrap;
}

/* Floating title for chromeless objects (theming `titles` default) */
.cosmos-float-title {
  position: absolute;
  bottom: 100%;
  left: 0;
  margin-bottom: 2px;
  font-size: max(10px, var(--text-floor, 0px));
  color: var(--text-muted);
  background: rgba(13, 17, 23, 0.6);
  padding: 1px 6px;
  border-radius: 4px;
  cursor: text;
  user-select: none;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* Explorer stays visible even when the chrome preset hides object chrome */
.cosmos-obj.is-explorer.is-chromeless {
  background: var(--bg-surface);
  border-color: var(--border);
}

.cosmos-frame-hint {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  color: var(--text-muted);
  font-size: max(var(--font-small), var(--text-floor, 0px));
  pointer-events: none;
  opacity: 0.5;
}

/* ─── Resize Handles ─────────────────────────────────────────────────────── */
/* Eight grips: four edges, four corners. All share .cosmos-resize-handle so
   the hover/selection reveal and the is-bare/is-ink rules apply to every one. */

.cosmos-resize-handle {
  position: absolute;
  opacity: 0;
  transition: opacity 0.15s;
  z-index: 3;
}

/* DIRECT CHILD only. A frame's children are DOM descendants of its wrapper
   (.cosmos-obj.is-frame > .cosmos-frame-clip > .cosmos-frame-children > …), so
   a descendant selector here made hovering the FRAME light up every grip of
   every object inside it — 8 accents × 9 children = 72 squares blooming across
   the board at once (measured 2026-11-15: descendant matched 72, direct child
   8). The lights already use `>` for the same reason. */
.cosmos-obj:hover > .cosmos-resize-handle,
.cosmos-obj.selected > .cosmos-resize-handle {
  opacity: 0.6;
}

.cosmos-resize-handle:hover {
  opacity: 1;
}

/* Corners — the SE one keeps the classic etched-grip gradient; the other three
   are quiet accent squares that only exist while hovered/selected. */
.cosmos-rh-se {
  bottom: 0;
  right: 0;
  width: 14px;
  height: 14px;
  cursor: nwse-resize;
  background: linear-gradient(135deg, transparent 50%, var(--text-muted) 50%, var(--text-muted) 60%, transparent 60%, transparent 70%, var(--text-muted) 70%, var(--text-muted) 80%, transparent 80%);
}

.cosmos-rh-nw { top: -3px; left: -3px; width: 12px; height: 12px; cursor: nwse-resize; background: var(--accent); border-radius: 2px; }
.cosmos-rh-ne { top: -3px; right: -3px; width: 12px; height: 12px; cursor: nesw-resize; background: var(--accent); border-radius: 2px; }
.cosmos-rh-sw { bottom: -3px; left: -3px; width: 12px; height: 12px; cursor: nesw-resize; background: var(--accent); border-radius: 2px; }

/* Edges — thin bars straddling the border; they sit outside the content box so
   they never eat a click meant for the object (or its title bar, beyond the
   3px overhang). */
.cosmos-rh-n { top: -3px; left: 14px; right: 14px; height: 7px; cursor: ns-resize; background: var(--accent); }
.cosmos-rh-s { bottom: -3px; left: 14px; right: 14px; height: 7px; cursor: ns-resize; background: var(--accent); }
.cosmos-rh-w { left: -3px; top: 14px; bottom: 14px; width: 7px; cursor: ew-resize; background: var(--accent); }
.cosmos-rh-e { right: -3px; top: 14px; bottom: 14px; width: 7px; cursor: ew-resize; background: var(--accent); }

/* ─── Browser leaf ─────────────────────────────────────────────────────── */
/* Search-result rows: the hover belongs to the row, so it lives here rather
   than in the leaf's inline styles (which cannot express :hover). */
.cosmos-browser-result:hover {
  background: var(--bg-hover);
}
.cosmos-browser-leaf iframe {
  color-scheme: light;
}

/* ─── Marquee ────────────────────────────────────────────────────────────── */

.cosmos-marquee {
  position: absolute;
  border: 1px dashed var(--accent);
  background: var(--accent-dim);
  pointer-events: none;
  z-index: 10000;
}

/* No status bar — info is shown in the explorer's status section. */

/* ─── Drop Zone ──────────────────────────────────────────────────────────── */

#cosmos-viewport.drag-over {
  outline: 1px dashed rgba(88, 166, 255, 0.35);
  outline-offset: -4px;
}

/* Cursor-following drop chip (replaces the old centred overlay) */
.cosmos-drop-chip {
  position: fixed;
  display: none;
  pointer-events: none;
  z-index: 9999;
  font-size: 10px;
  color: var(--accent);
  background: rgba(13, 17, 23, 0.9);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 2px 8px;
}

/* ─── Controls (rendered by interpreter) ─────────────────────────────────── */

.cosmos-control {
  margin: 4px 0;
}

.cosmos-control input[type="text"],
.cosmos-control input[type="number"],
.cosmos-control textarea,
.cosmos-control select {
  width: 100%;
  padding: 4px 8px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: max(var(--font-size), var(--text-floor, 0px));
  outline: none;
}

.cosmos-control input:focus,
.cosmos-control textarea:focus,
.cosmos-control select:focus {
  border-color: var(--accent);
}

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

.cosmos-control input[type="checkbox"] {
  accent-color: var(--accent);
}

.cosmos-button {
  padding: 4px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: max(var(--font-small), var(--text-floor, 0px));
  cursor: pointer;
}

.cosmos-button:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

/* ─── Interpreter-rendered text ──────────────────────────────────────────── */

.cosmos-content p {
  margin: 4px 0;
}

.cosmos-content h1, .cosmos-content h2, .cosmos-content h3 {
  margin: 8px 0 4px;
  font-weight: 600;
}

.cosmos-content h1 { font-size: max(18px, var(--text-floor, 0px)); }
.cosmos-content h2 { font-size: max(15px, var(--text-floor, 0px)); }
.cosmos-content h3 { font-size: max(13px, var(--text-floor, 0px)); }

.cosmos-content code {
  font-family: var(--font-mono);
  font-size: max(var(--font-small), var(--text-floor, 0px));
  background: var(--bg);
  padding: 1px 4px;
  border-radius: 3px;
}

.cosmos-content pre {
  background: var(--bg);
  padding: 8px;
  border-radius: var(--radius-sm);
  overflow-x: auto;
  font-family: var(--font-mono);
  font-size: max(var(--font-small), var(--text-floor, 0px));
  line-height: 1.4;
}

.cosmos-content ul, .cosmos-content ol {
  padding-left: 20px;
  margin: 4px 0;
}

.cosmos-content table {
  width: 100%;
  border-collapse: collapse;
  font-size: max(var(--font-small), var(--text-floor, 0px));
}

.cosmos-content th, .cosmos-content td {
  padding: 4px 8px;
  border: 1px solid var(--border);
  text-align: left;
}

.cosmos-content th {
  background: var(--bg-surface);
  font-weight: 500;
}

/* ─── Chart bars (simple CSS charts) ─────────────────────────────────────── */

.cosmos-chart {
  display: flex;
  align-items: flex-end;
  gap: 4px;
  height: 100%;
  padding-top: 8px;
}

.cosmos-bar {
  flex: 1;
  background: var(--accent);
  border-radius: 3px 3px 0 0;
  min-width: 20px;
  position: relative;
  transition: height 0.3s ease;
}

.cosmos-bar-label {
  position: absolute;
  bottom: -18px;
  left: 50%;
  transform: translateX(-50%);
  font-size: max(10px, var(--text-floor, 0px));
  color: var(--text-muted);
  white-space: nowrap;
}

/* ─── Conjure Palette ─────────────────────────────────────────────────────── */

#conjure-overlay {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  padding-top: 15vh;
  background: rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(4px);
  z-index: 9999;
}

#conjure-palette {
  width: 480px;
  max-height: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: 0 16px 48px rgba(0, 0, 0, 0.5);
  overflow: hidden;
}

#conjure-input {
  width: 100%;
  padding: 12px 16px;
  border: none;
  border-bottom: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  font-size: 15px;
  font-family: var(--font-sans);
  outline: none;
}

#conjure-input::placeholder {
  color: var(--text-muted);
}

#conjure-results {
  max-height: 300px;
  overflow-y: auto;
}

.conjure-item {
  padding: 10px 16px;
  cursor: pointer;
  font-size: var(--font-size);
  color: var(--text);
  transition: background 0.1s;
}

.conjure-item:hover {
  background: var(--bg-hover);
}

.conjure-item:first-child {
  background: var(--accent-dim);
}

/* ─── Animations ─────────────────────────────────────────────────────────── */

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(4px); }
  to { opacity: 1; transform: translateY(0); }
}

.cosmos-obj {
  animation: fadeIn 0.15s ease;
}

/* ─── Explorer ────────────────────────────────────────────────────────────── */

/* Row hover in explorer results */
.cosmos-obj .cosmos-content [style*="cursor: pointer"]:hover {
  background: rgba(136, 198, 255, 0.04);
}

/* Separator lines in pinned sections */
.cosmos-obj .cosmos-content [style*="height: 1px"] {
  flex-shrink: 0;
}

/* Explorer scrollbar styling */
.cosmos-obj.is-explorer .cosmos-content {
  scrollbar-width: thin;
  scrollbar-color: #30363d transparent;
}

.cosmos-obj.is-explorer .cosmos-content::-webkit-scrollbar {
  width: 6px;
}

.cosmos-obj.is-explorer .cosmos-content::-webkit-scrollbar-track {
  background: transparent;
}

.cosmos-obj.is-explorer .cosmos-content::-webkit-scrollbar-thumb {
  background: #30363d;
  border-radius: 3px;
}

/* Search input in explorer */
.cosmos-obj input[placeholder*="Search"] {
  background: transparent;
  border: none;
  color: var(--text);
  font-size: max(13px, var(--text-floor, 0px));
  outline: none;
  width: 100%;
  max-width: 340px;
  padding: 4px 0;
}

.cosmos-obj input[placeholder*="Search"]::placeholder {
  color: #484f58;
}

/* ─── Floor controls (Theming) ───────────────────────────────────────────── */
/* Leaves rather than the declarative {control:"range"}: a state write marks the
   owning object dirty, and rerenderObjectContent() rebuilds its content
   wholesale — destroying the input mid-drag, so a two-way-bound slider would
   stop responding after its first tick. These drive their floor live on `input`
   (no state write, no re-render) and persist once, on `change`.

   The leaf owns the whole row because renderLeaf returns the renderer's element
   straight through, so `presents` declared on a leaf part is inert — layout has
   to live here. As a direct child of the object's col it stretches to full
   width, which is what makes the two rows align.
   Specificity note: `.floor-control input[type=range]` ties with the earlier
   `.cosmos-control input[type=range]` (both 0,2,1), so being later in the file
   is what lets it override width and margin. */
.floor-control {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
}

/* Fixed width rather than intrinsic: "min text" and "min lights" are different
   lengths, and without this the two sliders start at different x, so the pair
   reads as sloppiness instead of as two related controls. */
.floor-label {
  flex: 0 0 auto;
  min-width: 5.6em;
  font-size: max(10px, var(--text-floor, 0px));
  line-height: 1.2;
  color: var(--text-muted);
}

.floor-control input[type="range"] {
  flex: 1 1 auto;
  width: auto;
  min-width: 0;
  margin: 0;
  cursor: pointer;
}

.floor-readout {
  flex: 0 0 auto;
  font-family: var(--font-mono);
  font-size: max(10px, var(--text-floor, 0px));
  line-height: 1;
  color: var(--text-muted);
  /* Reserved for the LONGEST value this readout can show, not the typical one:
     "44px" is wider than "off", and a readout that grows with its content pushes
     the <input> sideways mid-drag — the horizontal half of the very problem the
     panel freeze solves. `ch` scales with the floored font-size, so the reserve
     stays proportional. */
  min-width: 5ch;
  text-align: right;
}
