/* viewer.css — dark theme for statics-tutor */

/* Chrome palette retinted to forged-kit tokens (see forged.css / BRAND.md).
   Domain visualization colors (--tension/--compression/--reaction/--load/
   --warn/--err) are tool-local and unchanged. */
:root {
  --bg: #030201;                       /* --fk-bg */
  --panel: #0d0b0a;                    /* --fk-card-bg base (solid) */
  --panel-2: #171210;                  /* warm raised surface, derived from --fk-surface */
  --text: #e0e0e0;                     /* --fk-text */
  --muted: #9ca3af;                    /* --fk-text-dim */
  --accent: #FF8800;                   /* --fk-accent */
  --tension: #4a9eff;
  --compression: #ff5c5c;
  --reaction: #66ff99;
  --load: #ff9933;
  --warn: #ffcc00;
  --err: #ff5c5c;
  --border: rgba(255, 136, 0, 0.12);   /* --fk-border-soft */
}

* { box-sizing: border-box; }

/* fk-header accommodation: the sticky 3rem brand band would otherwise cover
   anchor-jump targets and sticky step snapshots. */
html { scroll-padding-top: 3.5rem; }

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

.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 24px;
}

.exam-header {
  border-bottom: 2px solid var(--border);
  padding-bottom: 16px;
  margin-bottom: 24px;
}
.exam-header h1 {
  margin: 0 0 4px;
  font-size: 28px;
  color: var(--text);
}
.exam-header .meta {
  color: var(--muted);
  font-size: 14px;
}

.problem {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 20px 24px;
  margin-bottom: 28px;
}

.problem-header h2 {
  margin: 0 0 8px;
  font-size: 20px;
  color: var(--accent);
}
.problem-header .prompt {
  color: var(--text);
  font-size: 15px;
  margin-bottom: 12px;
}
.problem-header .prompt b, .problem-header .prompt strong {
  color: var(--warn);
}

.problem-layout {
  display: grid;
  grid-template-columns: 360px 1fr;
  gap: 20px;
  align-items: start;
}
@media (max-width: 900px) {
  .problem-layout { grid-template-columns: 1fr; }
}

.col-editor {
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.col-editor label {
  font-size: 13px;
  color: var(--muted);
  display: block;
}
.col-editor .hint {
  color: var(--muted);
  font-weight: normal;
  font-style: italic;
}
.model-json {
  width: 100%;
  min-height: 260px;
  background: #0a0e12;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 10px;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  font-size: 12px;
  resize: vertical;
  tab-size: 2;
}
.model-json:focus {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}
.btn-row {
  display: flex;
  gap: 8px;
}
.btn {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px 12px;
  font-size: 13px;
  cursor: pointer;
}
.btn:hover { background: #241c15; border-color: var(--accent); }

.error-display {
  color: var(--err);
  font-family: monospace;
  font-size: 12px;
  white-space: pre-wrap;
  min-height: 1em;
}

.col-output {
  min-width: 0;
}
.svg-box {
  background: #0a0e12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 14px;
  min-height: 320px;
}

.solver-banner {
  background: rgba(255, 92, 92, 0.12);
  border: 1px solid var(--err);
  border-radius: 6px;
  padding: 8px 14px;
  color: var(--err);
  font-size: 13px;
  margin-bottom: 10px;
  font-family: "JetBrains Mono", monospace;
}
.solver-banner b { color: var(--warn); }
.truss-svg, .beam-svg, .beam-diagram {
  display: block;
  width: 100%;
  max-width: 100%;
  height: auto;
}
.truss-svg { max-height: 520px; cursor: grab; }
.truss-svg:active { cursor: grabbing; }
.joint-fbd { cursor: grab; }
.joint-fbd:active { cursor: grabbing; }
.beam-svg { cursor: grab; }
.beam-svg:active { cursor: grabbing; }
.beam-diagram { cursor: grab; }
.beam-diagram:active { cursor: grabbing; }
.beam-diagram { background: #070a0d; border-radius: 4px; margin-top: 4px; }

/* Wrapper around stretched beam diagrams so we can overlay undistorted HTML labels */
.strip-wrap {
  position: relative;
  width: 100%;
}
.diagram-overlay-label {
  position: absolute;
  transform: translate(-50%, -50%);
  font-size: 12px;
  font-weight: 700;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  pointer-events: none;
  white-space: nowrap;
  text-shadow:
    -1px -1px 2px #0a0e12, 1px -1px 2px #0a0e12,
    -1px  1px 2px #0a0e12, 1px  1px 2px #0a0e12,
    0 0 3px #0a0e12;
  text-align: center;
  line-height: 1.25;
}
.diagram-area-label {
  font-size: 10px;
  font-weight: 600;
  opacity: 0.9;
}
.diagram-area-label .tag {
  font-size: 9px;
  opacity: 0.7;
  font-style: italic;
}
.event-callout {
  font-size: 10px;
  background: rgba(255, 204, 0, 0.10);
  border: 1px solid rgba(255, 204, 0, 0.45);
  border-radius: 3px;
  padding: 2px 6px;
  color: #e4d070;
  text-shadow: none;
  line-height: 1.25;
}
.event-callout .cause {
  color: #fff;
  font-weight: 700;
}
.event-callout .effect {
  color: #ffcc00;
  font-weight: 700;
  font-size: 11px;
}
.slope-label {
  font-size: 10px;
  color: #8bd88b;
  opacity: 0.9;
}
.slope-label .tag {
  font-size: 9px;
  opacity: 0.65;
  font-style: italic;
}

.scrub-readout {
  position: absolute;
  background: rgba(10, 14, 18, 0.96);
  color: #fff;
  padding: 7px 11px;
  border: 1px solid rgba(255, 204, 0, 0.7);
  border-radius: 5px;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  font-size: 11.5px;
  line-height: 1.45;
  pointer-events: none;
  z-index: 100;
  white-space: nowrap;
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.6);
}
.scrub-readout .rk { color: #ffcc00; font-weight: 700; }
.scrub-readout .rv { color: #4a9eff; font-weight: 700; }
.scrub-readout .rm { color: #66ff99; font-weight: 700; }
.diagram-label {
  font-size: 12px;
  color: var(--muted);
  margin-top: 10px;
  margin-bottom: 2px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
}

.member { cursor: pointer; transition: stroke-width 0.1s; }
.member:hover { stroke-width: 0.15 !important; filter: brightness(1.3); }

.steps-box {
  margin-top: 8px;
}
.steps-list {
  padding-left: 24px;
  margin: 0;
}
.steps-list li.step {
  margin-bottom: 14px;
  padding: 8px 12px;
  background: var(--panel-2);
  border-left: 3px solid var(--accent);
  border-radius: 4px;
}
.steps-list li.step.with-snapshot {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 280px;
  gap: 14px;
  align-items: start;
}
.steps-list li.step .step-content { min-width: 0; }
.steps-list li.step .step-snapshot {
  background: #0a0e12;
  border: 1px solid var(--border);
  border-radius: 5px;
  padding: 6px;
  position: sticky;
  top: calc(3rem + 8px); /* clear the sticky fk-header band */
}

/* --- Structured step sections (v2 schema) --- */
.step-section {
  margin: 10px 0;
  padding: 8px 12px;
  border-left: 3px solid var(--border);
  border-radius: 0 4px 4px 0;
  background: rgba(255, 255, 255, 0.02);
}
.step-section .sec-label {
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 600;
}
.step-section .sec-body { color: var(--text); }

.sec-explain {
  border-left-color: #5c6770;
}
.sec-explain .sec-body p { margin: 6px 0; }

.sec-givens {
  border-left-color: #8fa4c0;
  background: rgba(143, 164, 192, 0.05);
}
.sec-givens .givens-list {
  margin: 4px 0;
  padding-left: 20px;
  list-style: square;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  font-size: 13px;
}
.sec-givens .givens-list li { margin-bottom: 3px; }
.sec-givens .given-note {
  color: var(--muted);
  font-family: inherit;
  font-style: italic;
  font-size: 11px;
}

.sec-equation {
  border-left-color: var(--accent);
  background: rgba(255, 136, 0, 0.08);
  padding: 10px 14px;
}
.sec-equation .sec-label { color: var(--accent); }
.sec-equation .sec-body { font-size: 1.04em; overflow-x: auto; }

.sec-work {
  border-left-color: var(--warn);
  background: rgba(255, 204, 0, 0.05);
}
.sec-work .sec-label { color: var(--warn); }
.sec-work .work-list {
  margin: 4px 0 4px 0;
  padding-left: 28px;
  counter-reset: worklist;
}
.sec-work .work-list li {
  list-style: decimal outside;
  margin: 4px 0;
  padding-left: 6px;
}
.sec-work .work-list li .katex-display { margin: 0.2em 0; }

.sec-answer {
  border-left-color: var(--reaction);
  background: rgba(102, 255, 153, 0.08);
  padding: 12px 16px;
  font-weight: 700;
}
.sec-answer .sec-label { color: var(--reaction); font-size: 11px; }
.sec-answer .sec-body { font-size: 1.1em; text-align: center; }

.sec-interpret {
  border-left-color: transparent;
  background: rgba(255, 255, 255, 0.02);
  font-style: italic;
  color: var(--muted);
}
.sec-interpret .sec-body { font-style: italic; }
.sec-interpret .sec-body b,
.sec-interpret .sec-body strong { color: var(--text); font-style: normal; }
.mini-fbd {
  display: block;
  width: 100%;
  height: auto;
  max-height: 260px;
  aspect-ratio: 1;
}
.mini-fbd.mini-fbd-beam {
  aspect-ratio: 2 / 1;
  max-height: 180px;
}
@media (max-width: 900px) {
  .steps-list li.step.with-snapshot {
    grid-template-columns: 1fr;
  }
  .steps-list li.step .step-snapshot { position: static; }
}
.step-heading {
  font-weight: 600;
  color: var(--warn);
  margin-bottom: 4px;
}
.step-text {
  color: var(--text);
  margin-bottom: 6px;
}
.step-katex {
  padding: 4px 0;
  color: var(--text);
  overflow-x: auto;
}
.step-note {
  color: var(--muted);
  font-size: 13px;
  font-style: italic;
  margin-top: 4px;
}

.answer-box {
  margin-top: 12px;
  padding: 12px 16px;
  background: #14241c;
  border: 1px solid #2a5a3e;
  border-radius: 6px;
  color: var(--reaction);
  font-weight: 600;
}
.answer-box b, .answer-box strong { color: #b6ffd2; }

/* MCQ */
.mcq-list { padding-left: 24px; }
.mcq-item {
  margin-bottom: 20px;
  padding: 12px 16px;
  background: var(--panel-2);
  border-radius: 6px;
}
.mcq-question {
  margin-bottom: 10px;
  font-weight: 500;
}
.mcq-options {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 10px;
}
.mcq-option {
  text-align: left;
  padding: 8px 12px;
  background: #0f0c09;
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 5px;
  cursor: pointer;
  font-size: 14px;
  transition: all 0.15s;
}
.mcq-option:hover { border-color: var(--accent); background: #171210; }
.mcq-option .letter { font-weight: 700; color: var(--muted); margin-right: 8px; }
.mcq-option.picked { border-width: 2px; }
.mcq-option.correct {
  background: #14241c;
  border-color: var(--reaction);
  color: var(--reaction);
}
.mcq-option.correct .letter { color: var(--reaction); }
.mcq-option.wrong {
  background: #241418;
  border-color: var(--err);
  color: var(--err);
}
.mcq-option.wrong .letter { color: var(--err); }

.mcq-rationale {
  display: none;
  padding: 10px 12px;
  background: #1a1a12;
  border-left: 3px solid var(--warn);
  border-radius: 4px;
  font-size: 13px;
  color: var(--text);
}
.mcq-rationale.revealed { display: block; }
.mcq-rationale b { color: var(--warn); }

/* TOC / nav */
.toc {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  margin-bottom: 24px;
}
.toc h3 {
  margin: 0 0 8px;
  font-size: 14px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.08em;
}
.toc ul { margin: 0; padding-left: 20px; list-style: none; }
.toc li { margin-bottom: 2px; }
.toc a { color: var(--accent); text-decoration: none; font-size: 14px; }
.toc a:hover { text-decoration: underline; }

/* Legend */
.legend {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
  margin-top: 8px;
  flex-wrap: wrap;
}
.legend span { display: inline-flex; align-items: center; gap: 4px; }
.legend .dot { width: 10px; height: 10px; border-radius: 2px; display: inline-block; }
.legend .t-c { background: var(--tension); }
.legend .c-c { background: var(--compression); }
.legend .z-c { background: #666; }
.legend .r-c { background: var(--reaction); }
.legend .l-c { background: var(--load); }

/* KaTeX sizing */
.katex { font-size: 1.05em; }
.katex-display { margin: 0.4em 0; overflow-x: auto; overflow-y: hidden; }

/* ---------- v2 additions: side tables, CodeMirror, joint FBD ---------- */

.table-wrap {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  margin-top: 12px;
}
@media (max-width: 700px) { .table-wrap { grid-template-columns: 1fr; } }

.side-table {
  width: 100%;
  border-collapse: collapse;
  background: var(--panel-2);
  border: 1px solid var(--border);
  border-radius: 6px;
  overflow: hidden;
  font-size: 13px;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
}
.side-table caption {
  caption-side: top;
  background: #0f0c09;
  color: var(--muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  padding: 5px 10px;
  text-align: left;
  border-bottom: 1px solid var(--border);
}
.side-table th, .side-table td {
  padding: 4px 10px;
  border-bottom: 1px solid var(--border);
}
.side-table th {
  background: #14100c;
  color: var(--muted);
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.side-table tr:last-child td { border-bottom: none; }
.side-table tr.st-t td { color: var(--tension); }
.side-table tr.st-c td { color: var(--compression); }
.side-table tr.st-z td { color: var(--muted); }
.side-table tr.emph td { background: #1a2a1e; color: var(--reaction); font-weight: 700; }

/* Joint FBD sub-diagram */
.fbd-box:not(:empty) {
  background: #0a0e12;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  margin-top: 12px;
}
.joint-fbd {
  display: block;
  width: 100%;
  max-width: 420px;
  margin: 0 auto;
  height: auto;
  max-height: 320px;
}
.fbd-empty {
  color: var(--muted);
  font-style: italic;
  padding: 10px;
}

/* CodeMirror dark-theme integration */
.CodeMirror {
  height: auto;
  min-height: 260px;
  max-height: 420px;
  border: 1px solid var(--border);
  border-radius: 6px;
  font-family: "JetBrains Mono", "Fira Code", Consolas, monospace;
  font-size: 12px;
  line-height: 1.5;
}
.CodeMirror-focused {
  outline: 1px solid var(--accent);
  border-color: var(--accent);
}
.CodeMirror-gutters {
  background: #0a0e12 !important;
  border-right: 1px solid var(--border) !important;
}
.cm-s-material-darker.CodeMirror {
  background: #0a0e12 !important;
}
.cm-s-material-darker .CodeMirror-linenumber {
  color: #4a5260 !important;
}
/* Hide original textarea when CodeMirror wraps it */
.col-editor .model-json + .CodeMirror { margin-bottom: 8px; }

/* Edit help bar */
.edit-help {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.6;
  background: rgba(255, 136, 0, 0.06);
  border-left: 2px solid var(--accent);
  padding: 8px 12px;
  margin-top: 6px;
  border-radius: 4px;
}
.edit-help b { color: var(--text); font-weight: 600; }

.storage-badge {
  font-size: 12px;
  color: var(--warn);
  background: rgba(255, 204, 0, 0.08);
  border-left: 2px solid var(--warn);
  padding: 6px 10px;
  margin-top: 6px;
  border-radius: 4px;
}
.storage-badge b { color: var(--text); }

/* Interactive SVG elements */
.node-circle {
  transition: stroke 0.1s, stroke-width 0.1s;
}
.node-circle:hover {
  stroke: var(--accent) !important;
  stroke-width: 0.15 !important;
  filter: brightness(1.15);
}
.support-glyph {
  transition: opacity 0.1s;
}
.support-glyph:hover {
  opacity: 0.85;
}
.support-glyph:hover polygon,
.support-glyph:hover circle,
.support-glyph:hover line {
  stroke: var(--accent) !important;
}
.member-handle {
  transition: opacity 0.1s, r 0.1s;
  pointer-events: all;
}
.member-handle:hover {
  opacity: 1 !important;
  stroke-width: 0.08 !important;
}

.draggable-label {
  cursor: grab;
}
.draggable-label:hover text {
  filter: brightness(1.4);
}
.draggable-label:active { cursor: grabbing; }

.clickable-arrow:hover line:nth-child(2) {
  stroke-width: 0.12 !important;
  filter: brightness(1.25);
}

/* Support picker popup */
.support-picker {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 4px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  z-index: 10000;
  min-width: 260px;
  max-width: 320px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.picker-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  padding: 8px 12px;
  background: transparent;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 5px;
  cursor: pointer;
  font-size: 13px;
  text-align: left;
  font-family: inherit;
}
.picker-btn:hover { background: var(--panel-2); border-color: var(--border); }
.picker-btn.current {
  border-color: var(--accent);
  background: rgba(255, 136, 0, 0.08);
}
.picker-btn .picker-main { display: flex; flex-direction: column; gap: 2px; }
.picker-btn .lbl { font-weight: 600; color: var(--text); }
.picker-btn .sub { font-size: 11px; color: var(--muted); }
.picker-btn .status {
  font-size: 11px;
  font-family: "JetBrains Mono", monospace;
  padding: 2px 6px;
  border-radius: 3px;
  white-space: nowrap;
}
.picker-btn.ok .status    { color: var(--reaction); background: rgba(102, 255, 153, 0.1); }
.picker-btn.indet .status { color: var(--warn);     background: rgba(255, 204, 0, 0.1); }
.picker-btn.mech  .status { color: var(--err);      background: rgba(255, 92, 92, 0.1); }
.picker-btn.mech {
  opacity: 0.65;
}
.picker-btn.mech:hover {
  opacity: 0.9;
}
