/*
 * Optical Simulator styling.
 *
 * Built for a phone first and widened for a desktop browser, because the target
 * is Android but development happens on a large screen. The canvas always owns
 * the whole stage; panels float above it rather than stealing layout space, so
 * the drawing never reflows when the inspector opens.
 *
 * Dark by default and not theme-switchable: ray rendering uses additive
 * blending, which only reads correctly against a dark ground.
 */

:root {
  --bg: #0d1117;
  --bg-raised: #161b22;
  --bg-panel: #1c2128e6;
  --border: #30363d;
  --border-soft: #21262d;
  --text: #e6edf3;
  --text-dim: #8b949e;
  --text-faint: #6e7681;
  --accent: #4c9aff;
  --accent-dim: #1f6feb;
  --danger: #f85149;
  --warn: #d29922;
  --good: #3fb950;
  --grid: #1b2129;
  --grid-major: #263039;

  --r-sm: 6px;
  --r-md: 10px;
  --r-lg: 16px;

  --topbar-h: 52px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

* { box-sizing: border-box; }

/*
 * The `hidden` attribute must actually hide things.
 *
 * The UA stylesheet expresses it as `[hidden] { display: none }`, which any
 * class-based `display` rule outranks on specificity. Several elements here are
 * flex containers and are toggled through the attribute, so without this rule
 * the add-object sheet, the scene menu, the results panel and the 3D canvas all
 * stay on screen permanently and the app is unusable. Declaring it once here is
 * more robust than remembering to pair every `display` rule with a matching
 * `[hidden]` override.
 */
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font: 14px/1.45 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

#app {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding-top: var(--safe-t);
}

/* ------------------------------------------------------------------ topbar */

#topbar {
  height: var(--topbar-h);
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 0 8px;
  background: var(--bg-raised);
  border-bottom: 1px solid var(--border);
  z-index: 30;
}

.spacer { flex: 1 1 auto; min-width: 0; }

/* ------------------------------------------------------------------ buttons */

.btn, .icon-btn, .seg-btn {
  font: inherit;
  color: var(--text);
  background: transparent;
  border: 1px solid transparent;
  border-radius: var(--r-sm);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  user-select: none;
  transition: background .12s, border-color .12s, opacity .12s;
}

.btn {
  padding: 7px 14px;
  border-color: var(--border);
  background: var(--bg-panel);
  font-weight: 500;
  min-height: 36px;
}
.btn:hover:not(:disabled) { background: #21262d; }
.btn:active:not(:disabled) { transform: translateY(1px); }
.btn.primary { background: var(--accent-dim); border-color: var(--accent); }
.btn.primary:hover:not(:disabled) { background: var(--accent); }
.btn.tiny { padding: 3px 9px; min-height: 26px; font-size: 12px; }
.btn.wide { width: 100%; justify-content: flex-start; }
.btn.danger { color: var(--danger); border-color: #5c2b2b; }
.btn:disabled, .icon-btn:disabled { opacity: .35; cursor: default; }

.icon-btn {
  width: 38px; height: 38px;
  flex: 0 0 auto;
  padding: 0;
}
.icon-btn:hover:not(:disabled) { background: #21262d; }
.icon-btn.small { width: 30px; height: 30px; }
.icon-btn.danger:hover:not(:disabled) { background: #3d1d1d; color: var(--danger); }

.icon-btn svg, .btn svg {
  width: 19px; height: 19px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.9;
  stroke-linecap: round;
  stroke-linejoin: round;
}
.icon-btn.small svg { width: 16px; height: 16px; }

.seg {
  display: inline-flex;
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  overflow: hidden;
  flex: 0 0 auto;
}
.seg-btn {
  padding: 6px 13px;
  border-radius: 0;
  font-size: 13px;
  color: var(--text-dim);
  min-height: 32px;
}
.seg-btn.active { background: var(--accent-dim); color: #fff; }

.chip {
  font-size: 12px;
  color: var(--text-dim);
  background: #0d1117;
  border: 1px solid var(--border-soft);
  border-radius: 20px;
  padding: 4px 11px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.chip .dim { color: var(--text-faint); margin-left: 5px; }

/* ------------------------------------------------------------------- stage */

#stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background: var(--bg);
  touch-action: none;
}

#canvas2d, #canvas3d {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.overlay-hint {
  position: absolute;
  top: 50%; left: 50%;
  transform: translate(-50%, -50%);
  text-align: center;
  color: var(--text-faint);
  display: flex;
  flex-direction: column;
  gap: 6px;
  pointer-events: none;
}
.overlay-hint strong { color: var(--text-dim); font-size: 16px; }
.overlay-hint b { color: var(--accent); }

.fab {
  position: absolute;
  right: 16px;
  bottom: calc(16px + var(--safe-b));
  width: 54px; height: 54px;
  border-radius: 50%;
  border: none;
  background: var(--accent-dim);
  color: #fff;
  box-shadow: 0 4px 16px #0008;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 20;
}
.fab:active { transform: scale(.94); }
.fab svg {
  width: 26px; height: 26px;
  fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round;
}

.viewhud {
  position: absolute;
  left: 12px;
  bottom: calc(12px + var(--safe-b));
  display: flex;
  flex-direction: column;
  gap: 6px;
  align-items: flex-start;
  z-index: 15;
}
.viewhud .icon-btn {
  background: var(--bg-panel);
  border: 1px solid var(--border);
  backdrop-filter: blur(8px);
}
.scalebar {
  margin-top: 4px;
  font-size: 11px;
  color: var(--text-dim);
  border-left: 2px solid var(--text-dim);
  border-right: 2px solid var(--text-dim);
  border-bottom: 2px solid var(--text-dim);
  padding: 0 4px 2px;
  min-width: 60px;
  text-align: center;
  background: #0d1117aa;
}

.progress {
  position: absolute;
  left: 50%;
  top: 16px;
  transform: translateX(-50%);
  width: min(420px, calc(100% - 32px));
  background: var(--bg-panel);
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 12px;
  backdrop-filter: blur(10px);
  z-index: 25;
}
.progress-bar {
  height: 5px;
  background: #0d1117;
  border-radius: 3px;
  overflow: hidden;
}
#progress-fill {
  height: 100%;
  width: 0;
  background: var(--accent);
  transition: width .15s linear;
}
.progress-label {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 7px;
  font-size: 12px;
  color: var(--text-dim);
}
.progress-label span { flex: 1 1 auto; }

/* ------------------------------------------------------------------ panels */

.panel {
  background: var(--bg-panel);
  backdrop-filter: blur(14px);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  min-height: 0;
  z-index: 22;
}

.panel-head {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  font-weight: 600;
  font-size: 13px;
  flex: 0 0 auto;
}

.panel-body {
  overflow-y: auto;
  overscroll-behavior: contain;
  padding: 10px 12px calc(14px + var(--safe-b));
  flex: 1 1 auto;
  -webkit-overflow-scrolling: touch;
}

.panel-grip { display: none; }

.muted { color: var(--text-faint); font-size: 13px; margin: 6px 0; }

/* ------------------------------------------------------------------ parts */

/*
 * The parts list. Selecting here never moves the view: the point is to reach a
 * part somewhere else in the scene while staying zoomed in on the one being
 * studied.
 */
#parts { --parts-w: 232px; }
.parts-filter { padding: 6px 8px; border-bottom: 1px solid var(--border-soft); }
.parts-filter input {
  width: 100%;
  background: #0d1117;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 5px 8px;
  font: inherit;
  font-size: 12.5px;
}
.parts-filter input:focus { outline: none; border-color: var(--accent); }
#parts-list { padding: 4px 4px 12px; }
#parts .dim { color: var(--text-faint); font-weight: 400; margin-left: 6px; }
.parts-group {
  margin: 8px 6px 3px;
  font-size: 10.5px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-faint);
}
.part-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 6px;
  border-radius: var(--r-sm);
  cursor: pointer;
  user-select: none;
  font-size: 12.5px;
  min-height: 28px;
}
.part-row:hover { background: #21262d; }
.part-row.sel { background: #1f6feb40; outline: 1px solid var(--accent-dim); }
.part-row.hidden-obj .part-name { opacity: .45; text-decoration: line-through; }
.part-dot { width: 9px; height: 9px; border-radius: 2px; flex: 0 0 auto; border: 1px solid #0006; }
.part-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.part-kind { color: var(--text-faint); font-size: 10.5px; flex: 0 0 auto; }
.part-btn {
  width: 22px; height: 22px; flex: 0 0 auto;
  border: none; background: transparent; color: var(--text-faint);
  border-radius: 4px; cursor: pointer; padding: 0;
  display: inline-flex; align-items: center; justify-content: center;
}
.part-btn:hover { background: #30363d; color: var(--text); }
.part-btn svg { width: 14px; height: 14px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
#btn-parts.active { background: var(--accent-dim); }

/* Desktop: inspector docks right, results docks bottom-right above it. */
@media (min-width: 861px) {
  #stage { margin-right: 320px; margin-left: 232px; }
  body.parts-off #stage { margin-left: 0; }
  #parts {
    position: absolute;
    top: calc(var(--topbar-h) + var(--safe-t));
    left: 0;
    bottom: 0;
    width: 232px;
    border-left: none;
    border-top: none;
    border-bottom: none;
  }
  body.parts-off #parts { display: none; }
  body:not(.parts-off) #results { left: 232px; }
  /* The properties panel can be put away entirely, not just collapsed. */
  body.inspector-off #inspector { display: none; }
  body.inspector-off #stage { margin-right: 0; }
  body.inspector-off #results { right: 0; }
  /* Results take a share of the height set by dragging their top edge; the
     view shrinks to fit rather than hiding behind them. */
  #results.collapsed { height: auto !important; }
  .results-resizer { flex: 0 0 auto; height: 6px; margin-top: -1px; cursor: ns-resize; border-top: 1px solid var(--border); }
  .results-resizer:hover, .results-resizer.dragging { background: var(--accent-dim); }
  #results.collapsed .results-resizer { display: none; }
  #inspector {
    position: absolute;
    top: calc(var(--topbar-h) + var(--safe-t));
    right: 0;
    bottom: 0;
    width: 320px;
    border-right: none;
    border-top: none;
    border-bottom: none;
  }
  #results {
    position: absolute;
    left: 0;
    right: 320px;
    bottom: 0;
    height: 262px;
    border-left: none;
    border-bottom: none;
  }
  #inspector.collapsed .panel-body { display: none; }
  #inspector.collapsed { bottom: auto; }
}

/* Mobile: both become bottom sheets over the canvas. */
@media (max-width: 860px) {
  #inspector {
    position: absolute;
    left: 0; right: 0; bottom: 0;
    max-height: 55%;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    border-bottom: none;
    transform: translateY(calc(100% - 46px));
    transition: transform .22s cubic-bezier(.2,.8,.2,1);
  }
  #inspector.open { transform: translateY(0); }
  .panel .panel-grip {
    display: block;
    width: 38px; height: 4px;
    background: var(--border);
    border-radius: 2px;
    margin: 7px auto 1px;
    flex: 0 0 auto;
  }
  #results {
    position: absolute;
    left: 0; right: 0;
    bottom: 0;
    max-height: 62%;
    border-radius: var(--r-lg) var(--r-lg) 0 0;
    z-index: 24;
  }
  .fab { bottom: calc(62px + var(--safe-b)); }
  .viewhud { bottom: calc(58px + var(--safe-b)); }
  #btn-collapse { display: none; }
  /* A slide-over from the left on a phone, shown only on request. */
  #parts {
    position: absolute;
    top: calc(var(--topbar-h) + var(--safe-t));
    left: 0;
    bottom: 46px;
    width: min(280px, 80vw);
    z-index: 26;
    border-radius: 0 var(--r-lg) var(--r-lg) 0;
  }
  body:not(.parts-open) #parts { display: none; }
  .results-resizer { display: none; }
}

/* Inside the desktop app the window's own top bar carries these tools. */
body.embedded { --topbar-h: 0px; }
body.embedded #topbar { display: none; }
body.embedded.od-studio3d .iso-banner { top: 10px; }

/*
 * Collapsed panels keep their header and drop their body.
 *
 * Both panels are anchored to the bottom edge, so hiding the body is enough to
 * shrink them to a title bar. That is the behaviour the results panel needed:
 * a run leaves it covering half a phone screen, and closing it outright throws
 * the numbers away, so there was no way to glance at the model and come back.
 */
.panel.collapsed .panel-body { display: none; }
.panel.collapsed #results-chart-hint { display: none; }

#btn-collapse-results svg,
#btn-collapse .icon,
#btn-collapse svg {
  transition: transform .18s ease;
}
.panel.collapsed #btn-collapse-results svg,
#inspector.collapsed #btn-collapse svg {
  transform: rotate(180deg);
}

#results .panel-head { cursor: pointer; }

/* A quiet dot on the toolbar button when results exist but are not showing. */
#btn-results { position: relative; }
#btn-results.has-results::after {
  content: '';
  position: absolute;
  top: 6px; right: 6px;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--good);
  border: 1.5px solid var(--bg-raised);
}

/* ------------------------------------------------------------------ fields */

.field {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 7px 0;
  min-height: 30px;
}
.field > label {
  flex: 0 0 42%;
  color: var(--text-dim);
  font-size: 12.5px;
  line-height: 1.25;
}
.field > .control { flex: 1 1 auto; min-width: 0; display: flex; align-items: center; gap: 6px; }

.field input[type="number"],
.field input[type="text"],
.field select {
  width: 100%;
  min-width: 0;
  background: #0d1117;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  padding: 6px 8px;
  font: inherit;
  font-size: 13px;
  min-height: 32px;
}
.field input:focus, .field select:focus {
  outline: none;
  border-color: var(--accent);
}
.field input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  min-height: 24px;
}
.field input[type="checkbox"] {
  width: 18px; height: 18px;
  accent-color: var(--accent);
  flex: 0 0 auto;
}
.field .val {
  flex: 0 0 auto;
  font-variant-numeric: tabular-nums;
  font-size: 12px;
  color: var(--text-dim);
  min-width: 46px;
  text-align: right;
}
.field .unit { color: var(--text-faint); font-size: 11.5px; flex: 0 0 auto; }
/* A sentence beside a checkbox wraps instead of pushing the panel wider. */
.field .unit.wrap { flex: 1 1 auto; min-width: 0; white-space: normal; line-height: 1.3; }

.group {
  margin: 12px 0 4px;
  border-top: 1px solid var(--border-soft);
  padding-top: 9px;
}
.group:first-child { border-top: none; margin-top: 2px; padding-top: 0; }
.group > h4 {
  margin: 0 0 4px;
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-faint);
}

.note {
  font-size: 11.5px;
  color: var(--text-faint);
  margin: 4px 0 2px;
  line-height: 1.4;
}
.note.warn { color: var(--warn); }

.readout {
  display: flex;
  justify-content: space-between;
  gap: 8px;
  font-size: 12px;
  padding: 3px 0;
  border-bottom: 1px dotted var(--border-soft);
}
.readout:last-child { border-bottom: none; }
.readout .k { color: var(--text-dim); }
.readout .v { font-variant-numeric: tabular-nums; color: var(--text); }
.readout .v.good { color: var(--good); }
.readout .v.warn { color: var(--warn); }
.readout .v.bad { color: var(--danger); }

.swatch {
  width: 22px; height: 22px;
  border-radius: 4px;
  border: 1px solid var(--border);
  flex: 0 0 auto;
}

.btn-row { display: flex; gap: 6px; margin: 8px 0 2px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 auto; justify-content: center; }

/* ------------------------------------------------------------------ sheets */

.sheet-backdrop {
  position: fixed;
  inset: 0;
  background: #00000090;
  z-index: 60;
  display: flex;
  align-items: flex-end;
  justify-content: center;
}
.sheet {
  background: var(--bg-raised);
  border: 1px solid var(--border);
  border-radius: var(--r-lg) var(--r-lg) 0 0;
  width: min(560px, 100%);
  max-height: 78vh;
  display: flex;
  flex-direction: column;
  animation: rise .18s cubic-bezier(.2,.8,.2,1);
}
@keyframes rise { from { transform: translateY(18px); opacity: .5; } }
@media (min-width: 861px) {
  .sheet-backdrop { align-items: center; }
  .sheet { border-radius: var(--r-lg); }
}
.sheet-head {
  display: flex;
  align-items: center;
  padding: 12px 14px;
  border-bottom: 1px solid var(--border-soft);
}
.sheet-head strong { flex: 1 1 auto; }
.sheet-body {
  overflow-y: auto;
  padding: 10px 12px calc(16px + var(--safe-b));
}

.cat { margin: 6px 0 12px; }
.cat > h4 {
  margin: 0 0 7px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: .06em;
  color: var(--text-faint);
}
.tiles {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(104px, 1fr));
  gap: 7px;
}
.tile {
  background: #0d1117;
  border: 1px solid var(--border);
  border-radius: var(--r-md);
  padding: 10px 8px;
  cursor: pointer;
  text-align: center;
  color: var(--text);
  font-size: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  min-height: 74px;
  justify-content: center;
}
.tile:hover { border-color: var(--accent); background: #131b26; }
.tile:active { transform: scale(.97); }
.tile svg {
  width: 26px; height: 26px;
  fill: none; stroke: var(--accent); stroke-width: 1.6;
  stroke-linecap: round; stroke-linejoin: round;
}
.tile .sub { color: var(--text-faint); font-size: 10.5px; }

/* ----------------------------------------------------------------- results */

.det-block { margin-bottom: 14px; }
.det-title {
  display: flex;
  align-items: baseline;
  gap: 8px;
  font-size: 12.5px;
  font-weight: 600;
  margin-bottom: 5px;
}
.det-title .sub { font-weight: 400; color: var(--text-faint); font-size: 11px; }
.det-chart {
  width: 100%;
  height: 104px;
  display: block;
  background: #0d1117;
  border: 1px solid var(--border-soft);
  border-radius: var(--r-sm);
}
.det-stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(112px, 1fr));
  gap: 3px 12px;
  margin-top: 6px;
}

/* Result image tools: grid and scale toggles and the save button. */
/* Far-field row: polar plot beside its numbers. */
.lum-row { display: flex; gap: 16px; align-items: flex-start; flex-wrap: wrap; }
.lum-row .det-stats, .det-stats.narrow { flex: 1 1 260px; grid-template-columns: repeat(2, minmax(210px, 1fr)); max-width: 680px; }
/* Astro preview. */
.sheet.wide { width: min(1040px, 100%); }
.astro-grid { display: grid; grid-template-columns: minmax(260px, 340px) 1fr; gap: 18px; }
@media (max-width: 760px) { .astro-grid { grid-template-columns: 1fr; } }
.astro-figs { display: flex; flex-wrap: wrap; gap: 12px; margin-top: 10px; }
.astro-figs figure { margin: 0; }
.astro-figs figcaption { font-size: 11px; color: var(--text-faint); margin-top: 4px; }
.astro-canvas { display: block; width: 360px; max-width: 100%; border: 1px solid var(--border); background: #000; }
.astro-canvas.pixelated { image-rendering: pixelated; }
.astro-canvas.wide { width: 560px; }
.astro-figs figure { position: relative; }
.astro-figs .fig-tools { position: absolute; top: 4px; right: 4px; display: flex; gap: 4px; opacity: 0; transition: opacity .12s; }
.astro-figs figure:hover .fig-tools, .astro-figs .fig-tools:focus-within { opacity: 1; }
.fig-tools button { background: #000a; color: #fff; border: 1px solid #fff3; border-radius: 6px; width: 26px; height: 26px; display: grid; place-items: center; cursor: pointer; padding: 0; }
.fig-tools button:hover { background: var(--accent); }
.fig-tools svg, .astro-viewer-bar svg { width: 15px; height: 15px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.astro-canvas { cursor: zoom-in; }
.astro-links { font-size: 11.5px; margin-top: 8px; line-height: 1.7; }
.astro-links a { color: var(--accent); }
.astro-local { margin-top: 10px; }
.astro-local-head { font-size: 11px; text-transform: uppercase; letter-spacing: .06em; color: var(--text-faint); margin: 14px 0 6px; }
.astro-local-btns { display: flex; gap: 8px; margin: 8px 0; }
.note.bad { color: var(--danger); }
.astro-local .readout .v { white-space: normal; text-align: right; }
/* Sheet window controls: maximise to the window, minimise to a bar. */
.sheet.wide.max { width: 100%; height: 100%; max-height: 100vh; border-radius: 0; }
.sheet-backdrop.min { background: transparent; pointer-events: none; align-items: flex-end; justify-content: flex-end; padding: 12px; }
.sheet-backdrop.min .sheet { pointer-events: auto; width: 300px; animation: none; }
.sheet-backdrop.min .sheet-body { display: none; }
.sheet-head .win-btns { display: flex; gap: 2px; margin-right: 4px; }
/* Full-resolution viewer: pan by dragging, wheel to zoom. */
.astro-viewer { position: fixed; inset: 0; z-index: 80; background: #000; display: flex; flex-direction: column; }
.astro-viewer-bar { display: flex; align-items: center; gap: 8px; padding: 8px 12px; background: var(--bg-raised); border-bottom: 1px solid var(--border); font-size: 12px; color: var(--text-dim); }
.astro-viewer-bar .title { flex: 1 1 auto; color: var(--text); }
.astro-viewer-stage { flex: 1 1 auto; overflow: hidden; position: relative; cursor: grab; touch-action: none; }
.astro-viewer-stage.dragging { cursor: grabbing; }
.astro-viewer-stage canvas { position: absolute; left: 0; top: 0; transform-origin: 0 0; image-rendering: pixelated; }
.astro-viewer-stage .busy { position: absolute; inset: 0; display: grid; place-items: center; color: #aaa; }
.det-tools { margin-left: 16px; display: flex; align-items: center; gap: 8px; font-weight: 400; font-size: 11.5px; color: var(--text-dim); }
.det-toggle { display: inline-flex; align-items: center; gap: 4px; cursor: pointer; user-select: none; }
.det-toggle input { accent-color: var(--accent); margin: 0; }
.det-image { display: block; max-width: 100%; margin: 2px 0 4px; }
.field input[type="color"] { width: 52px; height: 30px; padding: 0 2px; border: 1px solid var(--border); background: #0d1117; border-radius: var(--r-sm); cursor: pointer; }

/* Right-click menus, as in Render Studio. */
.ctx-menu { position: fixed; z-index: 100; min-width: 220px; padding: 4px; background: #1c2128f8; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 10px 30px #000c; font-size: 13px; }
.ctx-item { display: flex; align-items: center; gap: 6px; height: 26px; padding: 0 8px 0 4px; border-radius: 5px; cursor: default; white-space: nowrap; }
.ctx-item:hover:not(.disabled) { background: var(--accent-dim); }
.ctx-item.disabled { color: var(--text-faint); }
.ctx-item.danger:not(.disabled) { color: #ff9b95; }
.ctx-item.danger:hover:not(.disabled) { background: #6e2320; color: #fff; }
.ctx-check { width: 16px; text-align: center; color: var(--accent); flex: 0 0 auto; }
.ctx-item:hover .ctx-check { color: #fff; }
.ctx-label { flex: 1 1 auto; }
.ctx-shortcut { color: var(--text-faint); font-size: 11.5px; margin-left: 18px; }
.ctx-item:hover:not(.disabled) .ctx-shortcut { color: #cfe3ff; }
.ctx-sep { height: 1px; background: var(--border-soft); margin: 4px 6px; }
.ctx-heading { padding: 4px 10px 3px 24px; color: var(--text-faint); font-size: 11px; text-transform: uppercase; letter-spacing: .05em; max-width: 320px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Isolation: a banner saying so, with the way out. */
.iso-banner { position: absolute; top: 10px; left: 50%; transform: translateX(-50%); z-index: 24; display: flex; align-items: center; gap: 10px; padding: 4px 5px 4px 12px; background: #1f3a5fee; border: 1px solid var(--accent); color: #cfe3ff; border-radius: 16px; font-size: 12.5px; box-shadow: 0 4px 14px #0008; }
body.od-studio3d .iso-banner { top: 54px; }
body.od-studio3d .viewhud { display: none; }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-b));
  transform: translateX(-50%);
  background: #21262dee;
  border: 1px solid var(--border);
  color: var(--text);
  padding: 9px 16px;
  border-radius: 22px;
  font-size: 13px;
  z-index: 80;
  pointer-events: none;
  box-shadow: 0 4px 18px #0009;
  max-width: calc(100% - 32px);
  text-align: center;
}

/* In the desktop app the results panel sits where the toast would, over its numbers. */
body.embedded .toast { bottom: auto; top: 12px; }

/* Lens prescription */
.rx-summary { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 6px 14px; margin-bottom: 12px; }
.rx-stat { display: flex; flex-direction: column; gap: 1px; padding: 6px 8px; border: 1px solid var(--border); border-radius: 6px; }
.rx-stat span { color: var(--text-faint); font-size: 11.5px; }
.rx-stat b { font-variant-numeric: tabular-nums; font-weight: 600; }
.rx-stat.good b { color: #3fb950; }
.rx-wrap { overflow: auto; max-height: 52vh; border: 1px solid var(--border); border-radius: 6px; }
.rx-table { border-collapse: collapse; width: 100%; font-size: 12.5px; font-variant-numeric: tabular-nums; }
.rx-table th { position: sticky; top: 0; background: var(--panel, #161b22); text-align: left; font-weight: 600; color: var(--text-dim); padding: 6px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.rx-table td { padding: 2px 8px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.rx-table td.num input { width: 92px; text-align: right; font: inherit; background: transparent; color: var(--text); border: 1px solid transparent; border-radius: 4px; padding: 3px 5px; }
.rx-table td.num input:hover { border-color: var(--border); }
.rx-table td.num input::placeholder { color: var(--text-faint); }
.rx-table td.num input:focus { border-color: var(--accent); outline: none; background: var(--bg, #0d1117); }
.rx-table td.ro { text-align: right; }
.rx-table td.muted { color: var(--text-faint); }
.rx-table td.idx { color: var(--text-faint); }
.rx-table tr.rx-front td.glass { color: #79c0ff; }
.rx-table tr.rx-stop td, .rx-table tr.rx-image td { background: rgba(255,255,255,0.03); }
.rx-foot { display: flex; align-items: center; gap: 12px; margin-top: 10px; flex-wrap: wrap; }
.rx-foot .note { color: var(--text-faint); font-size: 12px; }

/* Glass catalogue */
.gl-disclaimer { margin: 0 0 10px; padding: 8px 10px; border: 1px solid #5c4a1f; background: rgba(210,153,34,0.08); border-radius: 6px; color: var(--text); font-size: 12.5px; line-height: 1.4; }
.gl-bar { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; margin-bottom: 8px; }
.gl-bar input[type=search] { flex: 1 1 240px; min-width: 0; }
.gl-mine { display: flex; gap: 6px; align-items: center; font-size: 12.5px; color: var(--text-dim); }
.gl-actions { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 8px; }
.gl-count { margin: 4px 0 6px; }
.gl-table td.glass { color: #79c0ff; }
.gl-table td button + button { margin-left: 4px; }
