/* see CLAUDE_notes.md */

.fim3d-root {
  position: relative;
  display: flex;
  flex: 1 1 auto;
  min-height: 420px;
  width: 100%;
  overflow: hidden;
  background: var(--bg-body, #ffffff);
  font-family: 'DM Mono', ui-monospace, monospace;
  color: var(--text-color, #2a2e42);
  /* The canvas handles its own gestures; without this, a touch drag scrolls
     the page instead of turning the molecule. */
  touch-action: none;
}

.fim3d-canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* ─── Labels ─────────────────────────────────────────────────────────────── */
/* Positioned by JS each frame from the projected atom coordinates. */
.fim3d-labels {
  position: absolute;
  inset: 0;
  pointer-events: none;
  overflow: hidden;
}

.fim3d-label {
  position: absolute;
  top: 0;
  left: 0;
  padding: 0 2px;
  font-size: var(--fs-4xs, 0.60rem);
  line-height: 1.2;
  color: var(--text-color, #2a2e42);
  background: rgba(255, 255, 255, .72);
  border-radius: 3px;
  white-space: nowrap;
}

/* ─── Options panel ──────────────────────────────────────────────────────── */
.fim3d-panel[hidden],
.fim3d-tabs[hidden],
.fim3d-pane[hidden],
.fim3d-help-btn[hidden] { display: none; }

.fim3d-panel {
  position: absolute;
  top: 10px;
  left: 10px;
  z-index: 2;
  width: 260px;
  max-width: calc(100% - 20px);
  max-height: calc(100% - 64px);
  display: flex;
  flex-direction: column;
  background: rgba(255, 255, 255, .94);
  border: 1px solid var(--border-color, #e2e6f0);
  border-radius: 8px;
  box-shadow: 0 2px 10px rgba(20, 24, 40, .10);
  backdrop-filter: blur(3px);
}

.fim3d-panel-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0.4rem 0.55rem;
  border-bottom: 1px solid var(--border-color, #e2e6f0);
}

.fim3d-panel-title {
  font-size: var(--fs-2xs, 0.72rem);
  font-weight: 600;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: #7a8199;
}

.fim3d-collapse {
  width: 20px;
  height: 20px;
  padding: 0;
  font: inherit;
  font-size: var(--fs-sm, 0.85rem);
  line-height: 1;
  color: #7a8199;
  background: transparent;
  border: 1px solid var(--border-color, #e2e6f0);
  border-radius: 4px;
  cursor: pointer;
}
.fim3d-collapse:hover { background: rgba(0, 0, 0, .05); color: var(--text-color, #2a2e42); }

.fim3d-panel-btns {
  display: flex;
  align-items: center;
  gap: 0.3rem;
}

/* ─── Tab strip ──────────────────────────────────────────────────────────── */
/* Simulation and Appearance share one box. The strip is hidden by ui_config
   when only one tab is enabled — a single tab is a label, not a choice. */
.fim3d-tabs {
  flex: 0 0 auto;
  display: flex;
  flex-wrap: wrap;
  gap: 1px;
  row-gap: 2px;
  padding: 0.3rem 0.4rem 0;
  border-bottom: 1px solid var(--border-color, #e2e6f0);
}
.fim3d-panel.is-collapsed .fim3d-tabs { display: none; }

.fim3d-tab {
  /* Grow to share the row, but never shrink below the label: `1 1 0` divided
     the width evenly regardless of how long the words were, which is why four
     tabs ran into each other. */
  flex: 1 1 auto;
  min-width: 0;
  padding: 0.28rem 0.3rem;
  font: inherit;
  font-size: var(--fs-3xs, 0.65rem);
  font-weight: 600;
  letter-spacing: .03em;
  color: #7a8199;
  background: transparent;
  border: 1px solid transparent;
  border-bottom: none;
  border-radius: 5px 5px 0 0;
  cursor: pointer;
  /* The tab that is not selected must not shift when it becomes selected, so
     both states reserve the same space and only the colours change. */
  margin-bottom: -1px;
}
.fim3d-tab:hover { color: var(--text-color, #2a2e42); background: rgba(0, 0, 0, .04); }
.fim3d-tab.is-active {
  color: var(--primary-color, #1d5390);
  background: rgba(255, 255, 255, .96);
  border-color: var(--border-color, #e2e6f0);
  border-bottom: 1px solid rgba(255, 255, 255, .96);
}

.fim3d-panel-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.5rem 0.55rem 0.6rem;
}
.fim3d-panel.is-collapsed .fim3d-panel-body { display: none; }

.fim3d-group { margin-bottom: 0.7rem; }
.fim3d-group:last-of-type { margin-bottom: 0.45rem; }

.fim3d-group-title {
  margin: 0 0 0.25rem;
  font-size: var(--fs-3xs, 0.65rem);
  font-weight: 700;
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--primary-color, #1d5390);
}

.fim3d-group-note {
  margin: 0 0 0.35rem;
  font-size: var(--fs-4xs, 0.60rem);
  line-height: 1.35;
  color: #9da3b8;
}

.fim3d-select {
  width: 100%;
  min-width: 0;
  max-width: 100%;
  padding: 0.25rem 0.35rem;
  font: inherit;
  font-size: var(--fs-2xs, 0.72rem);
  color: var(--text-color, #2a2e42);
  background: #fff;
  border: 1px solid var(--border-color, #e2e6f0);
  border-radius: 5px;
}

.fim3d-hint {
  margin: 0.3rem 0 0;
  font-size: var(--fs-4xs, 0.60rem);
  line-height: 1.4;
  color: #9da3b8;
}

.fim3d-check {
  display: flex;
  align-items: flex-start;
  gap: 0.4rem;
  padding: 0.13rem 0;
  font-size: var(--fs-2xs, 0.72rem);
  line-height: 1.35;
  cursor: pointer;
}
.fim3d-check input[type="checkbox"] {
  flex: 0 0 auto;
  width: 13px;
  min-width: 0;
  height: 13px;
  margin: 0.15em 0 0;
  padding: 0;
  cursor: pointer;
}
.fim3d-check:hover .fim3d-check-label { color: var(--primary-color, #1d5390); }

.fim3d-check-label { flex: 1 1 auto; }

/* The little "i" that marks a control with an explanation on hover. `em` on
   purpose — it should track the label it sits in, not the root. */
.fim3d-why {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 1.05em;
  height: 1.05em;
  margin-left: 0.3em;
  font-size: 0.82em;
  font-style: normal;
  line-height: 1;
  color: #9da3b8;
  border: 1px solid currentColor;
  border-radius: 50%;
  vertical-align: baseline;
}

.fim3d-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.3rem;
  padding-top: 0.15rem;
}

.fim3d-btn {
  flex: 1 1 auto;
  padding: 0.28rem 0.4rem;
  font: inherit;
  font-size: var(--fs-3xs, 0.65rem);
  color: #7a8199;
  background: transparent;
  border: 1px solid var(--border-color, #e2e6f0);
  border-radius: 5px;
  cursor: pointer;
  transition: background .12s, color .12s, border-color .12s;
}
.fim3d-btn:hover {
  background: rgba(0, 0, 0, .04);
  color: var(--text-color, #2a2e42);
  border-color: #9da3b8;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Per-tab reset
   ═══════════════════════════════════════════════════════════════════════════ */
/* A bar at the top of any pane whose tab declared snapshot+restore. Right
   aligned and quiet: it is an escape hatch, not a primary control, and it is
   disabled far more often than not. */
.fim3d-pane-bar {
  display: flex;
  justify-content: flex-end;
  margin: -0.15rem 0 0.5rem;
}

.fim3d-reset-btn {
  padding: 0.12rem 0.45rem;
  font: inherit;
  font-size: var(--fs-4xs, 0.60rem);
  letter-spacing: .03em;
  color: #7a8199;
  background: none;
  border: 1px solid var(--border-color, #e2e6f0);
  border-radius: 5px;
  cursor: pointer;
  transition: color .12s, border-color .12s, background .12s;
}
.fim3d-reset-btn:hover:not(:disabled) {
  color: var(--primary-color, #1d5390);
  border-color: var(--primary-color, #1d5390);
  background: rgba(29, 83, 144, .06);
}
/* Disabled is the resting state, so it must not look broken — just quiet. */
.fim3d-reset-btn:disabled {
  opacity: .35;
  cursor: default;
}

/* A tab whose settings have been changed carries a dot. Small, and on the tab
   itself, so "which of these six have I touched" is answerable without opening
   each one. */
.fim3d-tab.is-dirty::after {
  content: '';
  display: inline-block;
  width: 4px;
  height: 4px;
  margin-left: 0.3rem;
  vertical-align: middle;
  background: var(--primary-color, #1d5390);
  border-radius: 50%;
}

/* ═══════════════════════════════════════════════════════════════════════════
   Info pane
   ═══════════════════════════════════════════════════════════════════════════ */
/* Prose, not controls — so it gets a readable measure and line height rather
   than the tight rhythm the option rows use. */
.fim3d-info .fim3d-group { margin-bottom: 0.9rem; }

.fim3d-info-p {
  margin: 0 0 0.5rem;
  font-size: var(--fs-3xs, 0.65rem);
  line-height: 1.55;
  color: #7a8199;
}
.fim3d-info-p:last-child { margin-bottom: 0; }

.fim3d-info-list {
  margin: 0;
  padding-left: 0.9rem;
  font-size: var(--fs-3xs, 0.65rem);
  line-height: 1.5;
  color: #7a8199;
}
.fim3d-info-list li { margin-bottom: 0.35rem; }
.fim3d-info-list li:last-child { margin-bottom: 0; }

body.dark-mode .fim3d-info-p,
body.dark-mode .fim3d-info-list { color: #a6acc0; }
body.dark-mode .fim3d-reset-btn { border-color: #2f3448; color: #a6acc0; }
body.dark-mode .fim3d-reset-btn:hover:not(:disabled) {
  color: #8ab4f0;
  border-color: #8ab4f0;
  background: rgba(138, 180, 240, .08);
}
body.dark-mode .fim3d-tab.is-dirty::after { background: #8ab4f0; }

/* ─── Readout ────────────────────────────────────────────────────────────── */
.fim3d-readout {
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 8px;
  z-index: 2;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem;
  padding: 0.3rem 0.5rem;
  font-size: var(--fs-3xs, 0.65rem);
  color: #7a8199;
  background: rgba(255, 255, 255, .90);
  border: 1px solid var(--border-color, #e2e6f0);
  border-radius: 6px;
  pointer-events: none;
}

.fim3d-status {
  flex: 0 0 auto;
  padding: 0.08rem 0.4rem;
  font-weight: 600;
  border-radius: 999px;
}
.fim3d-status.is-busy    { color: #8a5a00; background: #fdf1d8; }
.fim3d-status.is-settled { color: #1d6b3a; background: #e2f4e8; }
.fim3d-status.is-static  { color: #4a5170; background: #eceef5; }

.fim3d-measure { flex: 0 1 auto; }

.fim3d-hoverinfo {
  flex: 1 1 100%;
  color: #9da3b8;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* ─── States ─────────────────────────────────────────────────────────────── */
.fim3d-loading,
.fim3d-error {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  font-size: var(--fs-xs, 0.78rem);
  text-align: center;
  color: #9da3b8;
}
.fim3d-error { color: #c43c1a; }


/* ─── Explanations ───────────────────────────────────────────────────────── */
.fim3d-group-note,
.fim3d-explain { display: none; }
.fim3d-explaining .fim3d-group-note,
.fim3d-explaining .fim3d-explain { display: block; }

/* The Info tab is nothing but explanation. Hiding it would leave a blank pane,
   so it opts out — as does anything that is a live VALUE rather than prose. */
.fim3d-info .fim3d-group-note,
.fim3d-info .fim3d-explain,
.fm3d-readout { display: block; }

.fim3d-explain-toggle {
  display: inline-flex;
  align-items: center;
  gap: .25rem;
  margin-right: .35rem;
  font-size: var(--fs-4xs, 0.60rem);
  color: #7a8199;
  cursor: pointer;
  user-select: none;
}
.fim3d-explain-toggle input { margin: 0; cursor: pointer; }
body.dark-mode .fim3d-explain-toggle { color: #9aa2bb; }

/* ─── Dark mode ──────────────────────────────────────────────────────────── */
/* The canvas paints its own background (view.js reads body.dark-mode); these
   rules are for the HTML chrome layered over it. */
body.dark-mode .fim3d-root { background: #14161f; color: #dfe3ee; }
body.dark-mode .fim3d-panel {
  background: rgba(26, 29, 40, .94);
  border-color: #2f3448;
  box-shadow: 0 2px 10px rgba(0, 0, 0, .45);
}
body.dark-mode .fim3d-panel-head { border-bottom-color: #2f3448; }
body.dark-mode .fim3d-select {
  color: #dfe3ee;
  background: #1f2331;
  border-color: #2f3448;
}
body.dark-mode .fim3d-collapse,
body.dark-mode .fim3d-btn { border-color: #2f3448; }
body.dark-mode .fim3d-collapse:hover,
body.dark-mode .fim3d-btn:hover { background: rgba(255, 255, 255, .07); color: #dfe3ee; }
body.dark-mode .fim3d-readout {
  color: #a6acc0;
  background: rgba(26, 29, 40, .90);
  border-color: #2f3448;
}
body.dark-mode .fim3d-label {
  color: #dfe3ee;
  background: rgba(20, 22, 31, .72);
}
body.dark-mode .fim3d-status.is-busy    { color: #f0c46a; background: #3a2f16; }
body.dark-mode .fim3d-status.is-settled { color: #7fd6a0; background: #16311f; }
body.dark-mode .fim3d-status.is-static  { color: #b6bcd4; background: #262a38; }

/* ─── Narrow viewports ───────────────────────────────────────────────────── */
/* Below this the panel would cover the molecule, so it starts collapsed-width
   and the readout drops the hover line. */
@media (max-width: 560px) {
  .fim3d-panel { width: 216px; max-height: calc(100% - 76px); }
  .fim3d-hoverinfo { display: none; }
}

/* ═══════════════════════════════════════════════════════════════════════════
   Group headings with a help button
   ═══════════════════════════════════════════════════════════════════════════ */
.fim3d-group-title {
  display: flex;
  align-items: center;
  gap: 0.35rem;
}
.fim3d-group-name { flex: 0 0 auto; }

.fim3d-help-btn {
  flex: 0 0 auto;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 15px;
  height: 15px;
  padding: 0;
  font: inherit;
  font-size: var(--fs-4xs, 0.60rem);
  font-weight: 700;
  line-height: 1;
  color: #9da3b8;
  background: transparent;
  border: 1px solid currentColor;
  border-radius: 50%;
  cursor: pointer;
  transition: color .12s, background .12s;
}
.fim3d-help-btn:hover {
  color: var(--primary-color, #1d5390);
  background: rgba(29, 83, 144, .08);
}

/* ═══════════════════════════════════════════════════════════════════════════
   Help dialog
   ═══════════════════════════════════════════════════════════════════════════ */
.fim3d-help-overlay {
  position: absolute;
  inset: 0;
  z-index: 20;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2vh 2vw;
  background: rgba(20, 24, 40, .38);
  backdrop-filter: blur(2px);
}

.fim3d-help-box {
  display: flex;
  flex-direction: column;
  width: min(760px, 100%);
  max-height: 100%;
  background: var(--bg-body, #fff);
  border: 1px solid var(--border-color, #e2e6f0);
  border-radius: 10px;
  box-shadow: 0 8px 40px rgba(20, 24, 40, .28);
  overflow: hidden;
}

.fim3d-help-head {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.6rem 0.9rem;
  border-bottom: 1px solid var(--border-color, #e2e6f0);
}
.fim3d-help-title {
  font-size: var(--fs-sm, 0.85rem);
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
  color: var(--primary-color, #1d5390);
}
.fim3d-help-close {
  width: 28px;
  height: 28px;
  font: inherit;
  font-size: var(--fs-lg, 1.10rem);
  line-height: 1;
  color: #7a8199;
  background: transparent;
  border: 1px solid var(--border-color, #e2e6f0);
  border-radius: 6px;
  cursor: pointer;
}
.fim3d-help-close:hover { background: #fdeef2; border-color: #e0a0ac; color: #c43c1a; }

.fim3d-help-body {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  padding: 0.9rem 1.1rem 1.4rem;
  font-size: var(--fs-xs, 0.78rem);
  line-height: 1.6;
  color: var(--text-color, #2a2e42);
}
.fim3d-help-body h3 {
  margin: 0 0 .5rem;
  font-size: var(--fs-md, 0.92rem);
  color: var(--primary-color, #1d5390);
}
.fim3d-help-body h4 {
  margin: 1.4rem 0 .35rem;
  font-size: var(--fs-sm, 0.85rem);
  color: var(--text-color, #2a2e42);
}
.fim3d-help-body h5 {
  margin: 1rem 0 .3rem;
  font-size: var(--fs-xs, 0.78rem);
  color: #7a8199;
}
.fim3d-help-body p { margin: 0 0 .7rem; }
.fim3d-help-body ul,
.fim3d-help-body ol { margin: 0 0 .8rem; padding-left: 1.2rem; }
.fim3d-help-body li { margin-bottom: .3rem; }
.fim3d-help-body hr {
  margin: 1.1rem 0;
  border: 0;
  border-top: 1px solid var(--border-color, #e2e6f0);
}
.fim3d-help-body code {
  padding: .05em .3em;
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: .92em;
  background: rgba(0, 0, 0, .05);
  border-radius: 3px;
}
.fim3d-help-body blockquote {
  margin: 0 0 .8rem;
  padding: .1rem 0 .1rem .8rem;
  border-left: 3px solid var(--border-color, #e2e6f0);
  color: #7a8199;
}
.fim3d-help-math {
  margin: 0 0 .9rem;
  padding: .55rem .7rem;
  overflow-x: auto;
  font-family: 'DM Mono', ui-monospace, monospace;
  font-size: var(--fs-2xs, 0.72rem);
  color: #4a5170;
  background: rgba(0, 0, 0, .035);
  border-radius: 6px;
  white-space: pre;
}

/* Wide tables scroll inside their own box rather than pushing the dialog out. */
.fim3d-help-table {
  display: block;
  overflow-x: auto;
  width: 100%;
  margin: 0 0 1rem;
  border-collapse: collapse;
  font-size: var(--fs-2xs, 0.72rem);
}
.fim3d-help-table th,
.fim3d-help-table td {
  padding: .3rem .55rem;
  text-align: left;
  vertical-align: top;
  border-bottom: 1px solid var(--border-color, #e2e6f0);
}
.fim3d-help-table th {
  font-weight: 700;
  color: #7a8199;
  white-space: nowrap;
  border-bottom-width: 2px;
}
.fim3d-help-loading { color: #9da3b8; text-align: center; padding: 2rem 0; }

/* ═══════════════════════════════════════════════════════════════════════════
   Appearance pane
   ═══════════════════════════════════════════════════════════════════════════ */
/* It lives in the same box as the Simulation pane now, so it needs no docking
   of its own — only a little more width for the label + slider + value rows. */
.fim3d-panel--config { width: 272px; }

.fim3d-arow {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.1rem 0;
  font-size: var(--fs-3xs, 0.65rem);
  line-height: 1.3;
  cursor: pointer;
}
.fim3d-alabel {
  flex: 0 0 6.3rem;
  color: #7a8199;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.fim3d-avalue {
  flex: 0 0 2.4rem;
  text-align: right;
  font-variant-numeric: tabular-nums;
  color: #9da3b8;
}

.fim3d-range {
  flex: 1 1 auto;
  min-width: 0;
  height: 14px;
  margin: 0;
  padding: 0;
  accent-color: var(--primary-color, #1d5390);
  cursor: pointer;
}
.fim3d-range--mini { flex: 1 1 auto; height: 12px; }

.fim3d-color {
  flex: 0 0 auto;
  width: 26px;
  height: 17px;
  min-width: 0;
  padding: 0;
  border: 1px solid var(--border-color, #e2e6f0);
  border-radius: 3px;
  background: none;
  cursor: pointer;
}

/* Per-element row: symbol, colour, opacity, size. */
.fim3d-elrow {
  display: flex;
  align-items: center;
  gap: 0.35rem;
  padding: 0.08rem 0;
}
.fim3d-elname {
  flex: 0 0 1.1rem;
  font-size: var(--fs-3xs, 0.65rem);
  font-weight: 700;
  color: var(--text-color, #2a2e42);
}

.fim3d-check.is-disabled { opacity: .45; cursor: not-allowed; }

/* ═══════════════════════════════════════════════════════════════════════════
   Dark mode for the new pieces
   ═══════════════════════════════════════════════════════════════════════════ */
body.dark-mode .fim3d-help-box {
  background: #1a1d28;
  border-color: #2f3448;
}
body.dark-mode .fim3d-help-head { border-bottom-color: #2f3448; }
body.dark-mode .fim3d-help-body { color: #dfe3ee; }
body.dark-mode .fim3d-help-body h4 { color: #dfe3ee; }
body.dark-mode .fim3d-help-body hr,
body.dark-mode .fim3d-help-table th,
body.dark-mode .fim3d-help-table td { border-color: #2f3448; }
body.dark-mode .fim3d-help-body code,
body.dark-mode .fim3d-help-math { background: rgba(255, 255, 255, .07); color: #b6bcd4; }
body.dark-mode .fim3d-help-close { border-color: #2f3448; }
body.dark-mode .fim3d-color { border-color: #2f3448; }
body.dark-mode .fim3d-tabs { border-bottom-color: #2f3448; }
body.dark-mode .fim3d-tab.is-active {
  background: #1a1d28;
  border-color: #2f3448;
  border-bottom-color: #1a1d28;
  color: #8ab4e8;
}
body.dark-mode .fim3d-elname { color: #dfe3ee; }

/* ═══════════════════════════════════════════════════════════════════════════
   Narrow viewports
   ═══════════════════════════════════════════════════════════════════════════ */
@media (max-width: 720px) {
  .fim3d-panel--config { width: 232px; }
}
@media (max-width: 560px) {
  .fim3d-help-box { width: 100%; }
  .fim3d-alabel { flex-basis: 4.6rem; }
  .fim3d-tab { font-size: var(--fs-4xs, 0.60rem); }
}
