/* viewer3d.css — dark theme, full-page canvas with fixed sidebar */
/* Chrome palette retinted to forged-kit tokens (see ../forged.css / BRAND.md).
   Domain visualization colors below (--tension/--comp/--zero/--load/
   --reaction/--node) are tool-local and unchanged. */
:root {
  --bg:       #030201;                     /* --fk-bg */
  --panel:    #0d0b0a;                     /* --fk-card-bg base (solid) */
  --border:   rgba(255, 136, 0, 0.12);     /* --fk-border-soft */
  --text:     #e0e0e0;                     /* --fk-text */
  --muted:    #9ca3af;                     /* --fk-text-dim */
  --accent:   #FF8800;                     /* --fk-accent */
  --tension:  #4a9eff;
  --comp:     #ff5c5c;
  --zero:     #888;
  --load:     #ff9933;
  --reaction: #66ff99;
  --node:     #ffcc00;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; padding: 0;
  width: 100vw; height: 100vh;
  overflow: hidden;
  font-family: system-ui, -apple-system, sans-serif;
  background: var(--bg);
  color: var(--text);
}

.app {
  display: grid;
  grid-template-columns: 1fr 360px;
  width: 100vw; height: 100vh;
}

.canvas-wrap {
  position: relative;
  background: var(--bg);
}

canvas {
  display: block;
  width: 100%;
  height: 100%;
}

/* Floating hud in the canvas corner */
.hud {
  position: absolute;
  top: 16px; left: 16px;
  padding: 8px 12px;
  background: rgba(13, 11, 10, 0.85);
  border: 1px solid var(--border);
  border-radius: 6px;
  font-size: 12px;
  color: var(--muted);
  pointer-events: none;
  line-height: 1.5;
}
/* V/M diagram panel — sits below the 3D canvas when a beam model is loaded */
.vm-panel {
  position: absolute;
  bottom: 0; left: 0; right: 0;
  background: rgba(9, 7, 6, 0.92);
  border-top: 1px solid var(--border);
  padding: 10px 14px;
  backdrop-filter: blur(4px);
  display: none;
  z-index: 4;
  max-height: 35vh;
  overflow: hidden;
}
.vm-panel.active { display: block; }
.vm-panel h3 {
  margin: 0 0 6px;
  font-size: 11px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
}
.vm-panel .strip {
  width: 100%;
  height: 90px;
  background: #060a0e;
  border: 1px solid var(--border);
  border-radius: 3px;
  margin-bottom: 6px;
}
.vm-panel .strip-label {
  display: flex;
  justify-content: space-between;
  font-size: 10px;
  color: var(--muted);
  margin-bottom: 2px;
}
.vm-panel .strip-label .value { color: var(--text); font-family: 'Consolas', monospace; }
.vm-panel .strip svg { width: 100%; height: 100%; display: block; }

.hud b { color: var(--text); }
.hud .axis-x { color: #ff5c5c; }
.hud .axis-y { color: #66ff99; }
.hud .axis-z { color: #4a9eff; }

/* Left-side floating build panel (under the HUD) */
.build-dock {
  position: absolute;
  top: 78px;           /* below HUD */
  left: 16px;
  width: 290px;
  max-height: calc(100vh - 110px);
  overflow-y: auto;
  background: rgba(13, 11, 10, 0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px 12px;
  backdrop-filter: blur(4px);
  pointer-events: auto;
  z-index: 5;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
}
.build-dock .dock-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 0 8px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.build-dock .dock-header h2 {
  margin: 0;
  padding: 0;
  border: none;
  font-size: 12px;
}
.build-dock .dock-toggle {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--muted);
  padding: 2px 8px;
  font-size: 11px;
  cursor: pointer;
}
.build-dock .dock-toggle:hover { color: var(--accent); border-color: var(--accent); }
.build-dock.collapsed > *:not(.dock-header) { display: none; }
.build-dock.collapsed {
  max-height: 36px;
  width: 170px;
  padding: 6px 10px;
}
.build-dock.collapsed .dock-header { border-bottom: none; margin: 0; }

/* Sidebar */
.sidebar {
  background: var(--panel);
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 18px 20px;
}

.sidebar h1 {
  font-size: 17px;
  margin: 0 0 4px;
  font-weight: 700;
}
.sidebar .subtitle {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 18px;
}

.sidebar h2 {
  font-size: 13px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 20px 0 8px;
  font-weight: 700;
  border-bottom: 1px solid var(--border);
  padding-bottom: 4px;
}

.legend {
  display: flex; flex-wrap: wrap; gap: 10px 14px;
  font-size: 12px;
  color: var(--muted);
}
.dot {
  display: inline-block;
  width: 10px; height: 10px;
  border-radius: 50%;
  margin-right: 5px;
  vertical-align: middle;
}
.dot.t-c { background: var(--tension); }
.dot.c-c { background: var(--comp); }
.dot.z-c { background: var(--zero); }
.dot.r-c { background: var(--reaction); }
.dot.l-c { background: var(--load); }

/* Force table */
table.forces {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  font-variant-numeric: tabular-nums;
}
table.forces th, table.forces td {
  padding: 4px 8px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
table.forces th {
  color: var(--muted);
  font-weight: 600;
  font-size: 11px;
  text-transform: uppercase;
}
.tag-T { color: var(--tension); font-weight: 700; }
.tag-C { color: var(--comp);    font-weight: 700; }
.tag-Z { color: var(--zero);    font-weight: 700; }

.meta-row {
  display: flex; justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
  padding: 3px 0;
}
.meta-row b { color: var(--text); }

/* Controls: buttons + select */
.controls-row {
  display: flex; flex-wrap: wrap; gap: 6px;
  margin: 6px 0 10px;
}
.controls-row button,
.controls-row select {
  background: #0f0c09;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 12px;
  font-family: inherit;
  cursor: pointer;
}
.controls-row button:hover {
  border-color: var(--accent);
  color: var(--accent);
}
.controls-row button:active { background: rgba(255, 136, 0, 0.15); } /* --fk-btn-bg-hover */
.controls-row select {
  width: 100%;
  padding: 6px 10px;
}

/* JSON editor */
textarea.json-editor {
  width: 100%;
  height: 240px;
  background: #0a0807;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 8px 10px;
  font-family: 'Consolas', 'Monaco', monospace;
  font-size: 11px;
  line-height: 1.4;
  resize: vertical;
  white-space: pre;
  overflow: auto;
  tab-size: 2;
}
.editor-status {
  font-size: 11px;
  padding: 4px 0;
  color: var(--muted);
}
.editor-status.ok  { color: #66ff99; }
.editor-status.err { color: #ff5c5c; white-space: pre-wrap; }

/* View-mode toggle */
.view-toggle { flex: 1; }
.view-toggle.active { border-color: var(--accent); color: var(--accent); background: rgba(255, 136, 0, 0.08); } /* --fk-chip-bg */

/* Load editor */
.load-editor {
  display: grid;
  grid-template-columns: repeat(3, 1fr) auto;
  gap: 6px;
  align-items: end;
  margin-bottom: 6px;
}
.load-editor label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  display: block;
}
.load-editor input {
  width: 100%;
  background: #0a0807;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 8px;
  font-family: 'Consolas', monospace;
  font-size: 13px;
  margin-top: 2px;
}

/* Hide browser-native number-input spinner arrows everywhere in the viewer — they
   steal ~30% of narrow input widths and duplicate the +/- keyboard controls. */
input[type="number"]::-webkit-outer-spin-button,
input[type="number"]::-webkit-inner-spin-button {
  -webkit-appearance: none;
  margin: 0;
}
input[type="number"] { -moz-appearance: textfield; appearance: textfield; }
.load-editor button {
  background: #0f0c09;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 10px;
  font-size: 12px;
  cursor: pointer;
}
.load-editor button:hover { border-color: var(--accent); color: var(--accent); }

/* =================================================================== */
/* Solve panel — scrollable step-by-step walkthrough                    */
/* =================================================================== */
.app.with-steps {
  grid-template-columns: 1fr 320px 460px;
}
.step-panel {
  display: none;
  background: #0b0908;
  border-left: 1px solid var(--border);
  overflow-y: auto;
  padding: 16px 20px;
}
.app.with-steps .step-panel { display: block; }

.step-panel h1 {
  font-size: 15px;
  margin: 0 0 4px;
  font-weight: 700;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.step-panel .close-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 4px;
  color: var(--muted);
  padding: 3px 8px;
  font-size: 11px;
  cursor: pointer;
}
.step-panel .close-btn:hover { color: var(--comp); border-color: var(--comp); }
.step-panel .panel-subtitle {
  color: var(--muted);
  font-size: 11px;
  margin-bottom: 14px;
}
.step-card {
  background: #0a0807;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 12px 14px;
  margin-bottom: 12px;
  transition: border-color 0.2s;
}
.step-card.active-step { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent) inset; }
.step-card h3 {
  font-size: 13px;
  margin: 0 0 8px;
  color: var(--accent);
  font-weight: 700;
}
.step-card .sec {
  padding: 6px 0 6px 10px;
  margin: 6px 0;
  border-left: 3px solid var(--border);
  font-size: 12px;
  line-height: 1.45;
}
.step-card .sec p { margin: 0 0 6px; }
.step-card .sec ul { margin: 4px 0 4px 16px; padding: 0; }
.step-card .sec-explain  { border-left-color: #8a99ab; color: #cdd5df; }
.step-card .sec-givens   { border-left-color: #ffcc00; }
.step-card .sec-equation { border-left-color: var(--accent); }
.step-card .sec-work     { border-left-color: #c28cff; }
.step-card .sec-answer   { border-left-color: var(--reaction); font-weight: 600; }
.step-card .sec-interpret { border-left-color: #ff9933; font-style: italic; color: #cdd5df; }
.step-card .given-row {
  display: flex;
  gap: 8px;
  align-items: baseline;
  font-family: 'Consolas', monospace;
  font-size: 11px;
  padding: 1px 0;
}
.step-card .given-row .note { color: var(--muted); margin-left: auto; font-style: italic; font-family: inherit; }
.step-card .katex { font-size: 1.0em; }

.solve-btn {
  background: rgba(255, 136, 0, 0.2);   /* --fk-btn-filled-bg */
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 8px 12px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  width: 100%;
}
.solve-btn:hover { background: rgba(255, 136, 0, 0.35); } /* --fk-btn-filled-bg-hover */
.solve-btn:disabled { opacity: 0.5; cursor: not-allowed; }

/* =================================================================== */
/* Build/edit tables — structured model authoring                       */
/* =================================================================== */
details.build-section {
  background: #0a0807;
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 0;
  margin-bottom: 10px;
}
details.build-section > summary {
  cursor: pointer;
  padding: 8px 12px;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  font-weight: 700;
  user-select: none;
}
details.build-section[open] > summary { border-bottom: 1px solid var(--border); color: var(--text); }
details.build-section > .body { padding: 8px 10px; }
table.build-table {
  width: 100%;
  border-collapse: collapse;
  font-family: 'Consolas', monospace;
  font-size: 11px;
  margin-bottom: 6px;
}
table.build-table th, table.build-table td {
  padding: 2px 3px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
table.build-table th {
  color: var(--muted);
  font-weight: 600;
  font-size: 10px;
  text-transform: uppercase;
  border-bottom: 1px solid var(--border);
}
table.build-table input, table.build-table select {
  width: 100%;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 2px 4px;
  font: inherit;
}
table.build-table input:focus, table.build-table select:focus {
  border-color: var(--accent);
  background: #0f0c09;
  outline: none;
}
.del-btn {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: 3px;
  width: 20px;
  height: 20px;
  padding: 0;
  cursor: pointer;
  font-size: 12px;
  line-height: 1;
}
.del-btn:hover { border-color: var(--comp); color: var(--comp); }
.add-row {
  display: grid;
  gap: 4px;
  margin-top: 4px;
  align-items: center;
}
.add-row.cols4 { grid-template-columns: 1.2fr 1fr 1fr 1fr auto; }
.add-row.cols3 { grid-template-columns: 1fr 1fr auto; }
.add-row.cols2 { grid-template-columns: 1fr 1fr auto; }
.add-row input, .add-row select {
  /* min-width:0 lets grid children shrink below their intrinsic text-input width */
  min-width: 0;
  width: 100%;
  box-sizing: border-box;
  background: #0f0c09;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px 5px;
  font-family: 'Consolas', monospace;
  font-size: 11px;
}
.add-row button {
  background: #0f0c09;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 3px;
  padding: 3px 10px;
  font-size: 11px;
  font-weight: 700;
  cursor: pointer;
}
.add-row button:hover { background: rgba(255, 136, 0, 0.15); } /* --fk-btn-bg-hover */

/* =================================================================== */
/* Saved scenes list                                                    */
/* =================================================================== */
.scenes-list {
  display: flex;
  flex-direction: column;
  gap: 4px;
  margin-bottom: 6px;
}
.scene-row {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 4px;
  align-items: center;
  padding: 4px 6px;
  background: #0a0807;
  border: 1px solid var(--border);
  border-radius: 3px;
  font-size: 11px;
}
.scene-row input.scene-name {
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 3px;
  padding: 2px 4px;
  font: inherit;
}
.scene-row input.scene-name:focus {
  border-color: var(--accent);
  background: #0f0c09;
  outline: none;
}
.scene-row .load-btn {
  background: transparent;
  border: 1px solid var(--border);
  border-radius: 3px;
  color: var(--muted);
  font-size: 10px;
  padding: 2px 6px;
  cursor: pointer;
}
.scene-row .load-btn:hover { color: var(--accent); border-color: var(--accent); }
.scene-row.current-scene {
  border-color: var(--accent);
  background: rgba(255, 136, 0, 0.08); /* --fk-chip-bg */
}
.scene-row.current-scene .load-btn { color: var(--accent); border-color: var(--accent); }

.scenes-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 6px;
}
.scenes-actions button {
  background: #0f0c09;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
  font-size: 11px;
  cursor: pointer;
  font-weight: 600;
}
.scenes-actions button.primary { color: var(--accent); border-color: var(--accent); }
.scenes-actions button:hover { background: rgba(255, 136, 0, 0.15); } /* --fk-btn-bg-hover */

/* =================================================================== */
/* AutoCAD-style editor toolbar + status line + popups                  */
/* (3d/EDITOR_DESIGN.md)                                                */
/* =================================================================== */
.editor-toolbar {
  position: absolute;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 6;                      /* above build-dock (5) */
  background: rgba(13, 11, 10, 0.92);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  backdrop-filter: blur(4px);
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.4);
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.editor-toolbar .et-row { display: flex; align-items: center; gap: 6px; }
.editor-toolbar button {
  background: #0f0c09;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.editor-toolbar button:hover { border-color: var(--accent); color: var(--accent); }
.editor-toolbar button.et-mode.active {
  border-color: var(--accent);
  color: var(--accent);
  background: rgba(255, 136, 0, 0.15);   /* --fk-btn-bg-hover */
}
.editor-toolbar .et-sep { width: 1px; align-self: stretch; background: var(--border); margin: 0 2px; }
.editor-toolbar .et-plane-row { display: none; }   /* shown by JS in + Node / + Member modes */
.editor-toolbar label {
  display: flex; align-items: center; gap: 4px;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  white-space: nowrap;
}
.editor-toolbar input[type="number"],
.editor-toolbar input[type="text"],
#et-entry {
  background: #0a0807;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 3px 6px;
  font-family: 'Consolas', monospace;
  font-size: 11px;
  width: 56px;
}
.editor-toolbar #et-entry { width: 138px; }
.editor-toolbar input:focus { border-color: var(--accent); outline: none; }

.editor-status-line {
  position: absolute;
  bottom: 12px; left: 16px;
  z-index: 6;                      /* above vm-panel (4) — beams never enter placement modes */
  max-width: min(72%, 640px);
  padding: 6px 10px;
  background: rgba(13, 11, 10, 0.88);
  border: 1px solid var(--border);
  border-radius: 5px;
  font-size: 11px;
  color: var(--muted);
  pointer-events: none;
  line-height: 1.4;
}
.editor-status-line b { color: var(--accent); font-family: 'Consolas', monospace; }
.editor-status-line.ok  { color: #66ff99; }
.editor-status-line.err { color: #ff5c5c; }

.cursor-tip {
  display: none;
  position: absolute;
  z-index: 7;
  padding: 2px 6px;
  background: rgba(13, 11, 10, 0.92);
  border: 1px solid var(--border);
  border-radius: 3px;
  font-family: 'Consolas', monospace;
  font-size: 10px;
  color: var(--text);
  pointer-events: none;
  white-space: nowrap;
}

.editor-popup {
  display: none;
  position: absolute;
  top: 96px; right: 16px;          /* fixed position, clear of toolbar + sidebar */
  z-index: 7;
  width: 210px;
  background: rgba(13, 11, 10, 0.95);
  border: 1px solid var(--accent);
  border-radius: 6px;
  padding: 10px 12px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.5);
}
.editor-popup h3 {
  margin: 0 0 8px;
  font-size: 11px;
  color: var(--text);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.editor-popup h3 span { color: var(--node); }
.editor-popup .ep-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-bottom: 8px;
}
.editor-popup label {
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  display: block;
}
.editor-popup input, .editor-popup select {
  width: 100%;
  box-sizing: border-box;
  background: #0a0807;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 3px;
  padding: 4px 6px;
  font-family: 'Consolas', monospace;
  font-size: 12px;
  margin-top: 2px;
}
.editor-popup select { margin-bottom: 8px; font-family: inherit; }
.editor-popup .ep-actions { display: flex; gap: 6px; }
.editor-popup .ep-actions button {
  flex: 1;
  background: #0f0c09;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 5px 0;
  font-size: 11px;
  cursor: pointer;
}
.editor-popup .ep-actions button.ep-apply {
  color: var(--accent);
  border-color: var(--accent);
  font-weight: 700;
}
.editor-popup .ep-actions button:hover { background: rgba(255, 136, 0, 0.15); } /* --fk-btn-bg-hover */

/* =================================================================== */
/* Small-screen gate — layout is a fixed desktop grid, no responsive    */
/* rebuild; below 900px an overlay covers the app with an honest        */
/* message and a link back to the main tool.                            */
/* =================================================================== */
.small-screen-gate {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 100;                 /* above build-dock (5) and vm-panel (4) */
  background: var(--bg);
  color: var(--text);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 32px 24px;
  text-align: center;
}
.small-screen-gate h2 {
  margin: 0;
  font-size: 17px;
  font-weight: 700;
}
.small-screen-gate p {
  margin: 0;
  font-size: 13px;
  color: var(--muted);
  max-width: 320px;
  line-height: 1.5;
}
.small-screen-gate a {
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 4px;
  padding: 8px 14px;
  font-size: 13px;
  font-weight: 700;
  text-decoration: none;
}
.small-screen-gate a:hover { background: rgba(255, 136, 0, 0.15); } /* --fk-btn-bg-hover */
@media (max-width: 900px) {
  .small-screen-gate { display: flex; }
}
