/* ── CNC G-Code Simulator ──────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0d1117;
  --surface:   #161b27;
  --surface2:  #1f2535;
  --border:    #2a3050;
  --accent:    #43a047;
  --accent-lo: rgba(67,160,71,.22);
  --green:     #3ddc84;
  --red:       #ff5555;
  --gold:      #f5c842;
  --text:      #dde3f0;
  --text-dim:  #8b9dc3;
  --font:      'Segoe UI', system-ui, sans-serif;
  --mono:      'Courier New', monospace;
  --radius:    12px;
}

body { background: var(--bg); color: var(--text); font-family: var(--font); min-height: 100vh; padding: 0 16px; }
#app { max-width: 980px; margin: 0 auto; display: flex; flex-direction: column; gap: 14px; }

/* ── Header ────────────────────────────────────────────────── */
header { text-align: center; padding: 4px 0; }
header h1 {
  font-size: 1.8rem; font-weight: 700;
  background: linear-gradient(120deg, #43a047 0%, #81c784 100%);
  -webkit-background-clip: text; -webkit-text-fill-color: transparent; background-clip: text;
}
.subtitle { color: var(--text-dim); font-size: 0.85rem; margin-top: 3px; }

/* ── Controls bar ──────────────────────────────────────────── */
.controls-bar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 14px;
  padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.ctrl-group { display: flex; align-items: center; gap: 8px; }
.ctrl-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); white-space: nowrap; }

/* ── Pill tabs ─────────────────────────────────────────────── */
.pill-tabs { display: flex; background: var(--bg); border-radius: 8px; padding: 3px; gap: 2px; }
.pill {
  padding: 8px 16px; border: none; background: transparent; color: var(--text-dim);
  border-radius: 6px; cursor: pointer; font-size: 0.81rem; min-height: 44px;
  transition: background .18s, color .18s, box-shadow .18s;
}
.pill.active { background: var(--accent); color: #fff; box-shadow: 0 0 12px var(--accent-lo); }
.pill:hover:not(.active) { background: var(--surface2); color: var(--text); }

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
  padding: 10px 18px; border: none; border-radius: 8px; cursor: pointer;
  font-size: 0.84rem; font-weight: 600; min-height: 44px;
  transition: filter .18s, box-shadow .18s, opacity .18s;
}
.btn:disabled { opacity: 0.38; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:not(:disabled):hover { filter: brightness(1.12); box-shadow: 0 0 12px var(--accent-lo); }
.btn-ghost { background: var(--surface2); color: var(--text); border: 1px solid var(--border); }
.btn-ghost:hover { background: var(--border); }

/* Guide blink — yellow border pulse on next-action button */
@keyframes guideBlink {
  0%, 100% { border-color: rgba(245,200,66,.15); box-shadow: 0 0 0 rgba(245,200,66,0); }
  50% { border-color: rgba(245,200,66,.9); box-shadow: 0 0 12px rgba(245,200,66,.35); }
}
.sim-guide-blink:not(:disabled) { animation: guideBlink 1.4s ease-in-out infinite; }

/* ── Canvas card ───────────────────────────────────────────── */
.canvas-card {
  width: 100%; background: var(--surface);
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px; position: relative; overflow-x: clip;
  display: flex; flex-direction: column;
}
.canvas-card canvas { display: block; width: 100%; flex: 1; min-height: 0; cursor: grab; touch-action: none; }
.canvas-card canvas:active { cursor: grabbing; }

/* ── Sim toolbar ───────────────────────────────────────────── */
.sim-toolbar {
  display: flex; flex-wrap: wrap; align-items: center; gap: 10px;
  padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.sim-select {
  padding: 6px 12px; border: 1px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-size: 0.84rem;
  font-family: var(--font); cursor: pointer; min-width: 160px;
}
.sim-select:focus { outline: none; border-color: var(--accent); }
.sim-toolbar-title {
  font-size: 0.65rem; font-weight: 800; text-transform: uppercase;
  letter-spacing: 0.12em; color: var(--text-dim); opacity: 0.6;
  width: 100%; margin-bottom: -4px;
}

/* ── Cheat sheet overlay ──────────────────────────────────── */
.cheatsheet-backdrop {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,.55); z-index: 10001; display: none;
}
.cheatsheet-panel {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 92%; max-width: 620px; max-height: 80vh; overflow-y: auto;
  background: var(--surface); border: 2px solid var(--accent);
  border-radius: var(--radius); padding: 20px 24px; z-index: 10002;
  box-shadow: 0 12px 48px rgba(0,0,0,.6); display: none;
}
.cheatsheet-panel h3 { font-size: 1rem; color: var(--accent); margin-bottom: 10px; }
.cheatsheet-panel h4 { font-size: 0.78rem; color: var(--gold); margin: 12px 0 4px; text-transform: uppercase; letter-spacing: .06em; }
.cs-table { width: 100%; border-collapse: collapse; }
.cs-table th { text-align: left; font-size: 0.72rem; color: var(--text-dim); padding: 4px 8px; border-bottom: 1px solid var(--border); }
.cs-table td { font-size: 0.8rem; padding: 4px 8px; border-bottom: 1px solid rgba(42,48,80,.4); }
.cs-table td:first-child { font-family: var(--mono); color: var(--accent); font-weight: 700; white-space: nowrap; }
.cs-close { position: absolute; top: 12px; right: 16px; background: none; border: none; color: var(--text-dim); font-size: 1.4rem; cursor: pointer; }
.cs-close:hover { color: var(--text); }

/* ── Editor line highlight overlay ────────────────────────── */
.editor-wrap { position: relative; }
#editor-highlight {
  position: absolute; left: 12px; right: 12px; pointer-events: none; z-index: 1; overflow: hidden;
}
.editor-hl-line {
  position: absolute; left: 0; width: 100%;
  background: rgba(245,200,66,.14); border-left: 3px solid var(--gold);
}

/* ── Zoom controls ───────────────────────────────────────── */
.zoom-controls {
  position: absolute; top: 10px; right: 10px; z-index: 4;
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  background: rgba(13,17,23,.85); border: 1px solid var(--border);
  border-radius: 8px; padding: 4px;
}
.zoom-btn {
  width: 28px; height: 28px; border: none; border-radius: 6px;
  background: rgba(255,255,255,.08); color: var(--text);
  font-size: 1rem; font-weight: 700; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s;
}
.zoom-btn:hover { background: rgba(255,255,255,.18); }
.zoom-btn:active { background: rgba(255,255,255,.25); }
.zoom-reset { font-size: 0.85rem; }
.zoom-badge {
  font-family: var(--mono); font-size: 0.65rem; color: var(--text-dim);
  padding: 1px 0; user-select: none;
}

/* ── Sim layout (editor + canvas side by side) ─────────────── */
.sim-layout {
  display: grid; grid-template-columns: 1fr 1fr; gap: 14px;
  align-items: stretch;
}

/* ── G-Code Editor ─────────────────────────────────────────── */
.editor-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 10px; display: flex; flex-direction: column;
}
.editor-header {
  display: flex; justify-content: space-between; align-items: center;
  margin-bottom: 8px; padding: 0 4px;
}
.line-indicator { font-family: var(--mono); font-size: 0.76rem; color: var(--accent); }

/* Syntax highlight wrapper */
.syntax-wrap {
  position: relative; flex: 1; display: flex; flex-direction: column; min-height: 0;
}
.syntax-highlight {
  position: absolute; top: 0; left: 0; right: 0; bottom: 0;
  background: var(--bg); border: 2px solid transparent; border-radius: 8px;
  padding: 12px; font-family: var(--mono); font-size: 0.85rem;
  line-height: 1.6; tab-size: 4; overflow: hidden;
  white-space: pre-wrap; word-wrap: break-word;
  color: transparent; pointer-events: none; z-index: 1;
}
.syntax-highlight .sy-g { color: #43a047; font-weight: 700; }
.syntax-highlight .sy-m { color: #ef6c00; font-weight: 700; }
.syntax-highlight .sy-coord { color: #42a5f5; }
.syntax-highlight .sy-num { color: #a5d6a7; }
.syntax-highlight .sy-comment { color: #607080; font-style: italic; }
.syntax-highlight .sy-s { color: #ab47bc; }

.gcode-editor {
  background: transparent; border: 2px solid var(--border); border-radius: 8px;
  padding: 12px; font-family: var(--mono); font-size: 0.85rem;
  color: rgba(230,237,243,.85); width: 100%; min-height: 340px; resize: vertical;
  line-height: 1.6; tab-size: 4; position: relative; z-index: 2;
  caret-color: var(--accent);
}
.gcode-editor:focus { border-color: var(--accent); outline: none; }

/* ── Speed slider row ──────────────────────────────────────── */
.sim-speed-row {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.sim-slider-label { font-size: 0.76rem; font-weight: 700; color: var(--text-dim); white-space: nowrap; min-width: 50px; }
.sim-slider {
  flex: 1; -webkit-appearance: none; appearance: none; height: 6px;
  background: var(--surface2); border-radius: 3px; outline: none;
}
.sim-slider::-webkit-slider-thumb {
  -webkit-appearance: none; width: 18px; height: 18px;
  border-radius: 50%; background: var(--accent); cursor: pointer;
  box-shadow: 0 0 8px var(--accent-lo);
}
.sim-slider::-moz-range-thumb {
  width: 18px; height: 18px; border: none;
  border-radius: 50%; background: var(--accent); cursor: pointer;
}
.sim-slider-val {
  font-family: var(--mono); font-size: 0.9rem; font-weight: 700;
  color: var(--accent); min-width: 40px; text-align: right;
}

/* ── Readout row ───────────────────────────────────────────── */
.readout-row {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); gap: 8px;
}
.readout-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 8px 12px; text-align: center;
}
.readout-label { font-size: 0.62rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-dim); margin-bottom: 3px; }
.readout-val { font-family: var(--mono); font-size: 1.15rem; font-weight: 700; color: var(--accent); }
.readout-unit { font-size: 0.68rem; color: var(--text-dim); margin-left: 2px; }

/* readout colour overrides */
.readout-card.pos-x .readout-val { color: #42a5f5; }
.readout-card.pos-y .readout-val { color: #ef5350; }
.readout-card.pos-z .readout-val { color: #ab47bc; }
.readout-card.feed .readout-val { color: #ffa000; }
.readout-card.spindle .readout-val { color: #7c4dff; }
.readout-card.line-num .readout-val { color: #3ddc84; }
.readout-card.path-len .readout-val { color: #f5c842; }

/* ── Explore mode ──────────────────────────────────────────── */
.item-selector {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 14px 16px;
}
.is-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(155px, 1fr)); gap: 8px; margin-top: 10px; }
.is-btn {
  padding: 10px 14px; border: 2px solid var(--border); border-radius: 10px;
  background: var(--surface2); color: var(--text-dim); font-size: 0.82rem;
  font-weight: 600; cursor: pointer; text-align: left;
  transition: border-color .18s, color .18s, background .18s, box-shadow .18s;
}
.is-btn:hover { border-color: rgba(67,160,71,.45); color: var(--text); }
.is-btn.active { border-color: var(--accent); color: #fff; background: rgba(67,160,71,.15); box-shadow: 0 0 14px var(--accent-lo); }
.is-btn-name { display: block; font-size: 0.82rem; font-weight: 700; }
.is-btn-sym  { display: block; font-size: 0.68rem; color: var(--accent); margin-top: 2px; font-family: var(--mono); }

.item-info {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; display: flex; flex-direction: column; gap: 8px;
}
.ii-top { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.ii-name { font-size: 1.15rem; font-weight: 800; color: var(--text); }
.ii-cat-badge {
  font-size: 0.62rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .07em; padding: 3px 10px; border-radius: 20px;
  background: var(--accent-lo); color: var(--accent);
}
.ii-desc { font-size: 0.85rem; color: var(--text-dim); line-height: 1.65; }

.formula-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 10px 14px; display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
}
.fb-formula { font-family: var(--mono); font-size: 1.1rem; font-weight: 700; color: var(--accent); }
.fb-unit { font-size: 0.78rem; color: var(--text-dim); }

.code-box {
  background: var(--bg); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px; font-family: var(--mono); font-size: 0.84rem;
  color: var(--text); line-height: 1.7; white-space: pre-wrap;
}

.example-box {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  padding: 12px 14px;
}
.example-box h4 { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); margin-bottom: 8px; }
.example-box .ex-problem { font-size: 0.84rem; color: var(--text); margin-bottom: 8px; line-height: 1.6; }
.example-box .ex-step { font-size: 0.8rem; color: var(--text-dim); line-height: 1.6; padding: 2px 0; }
.example-box .ex-step strong { color: var(--green); font-family: var(--mono); }

/* ── Practice mode ─────────────────────────────────────────── */
.practice-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px;
}
.pp-prompt { font-size: 0.92rem; font-weight: 600; color: var(--text); margin-bottom: 14px; line-height: 1.6; }
.pp-input-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.pp-input {
  flex: 1; min-width: 120px; max-width: 320px;
  padding: 10px 14px; border: 2px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-family: var(--mono);
  font-size: 1rem; font-weight: 700; transition: border-color .18s;
}
.pp-input:focus { outline: none; border-color: var(--accent); }
.pp-unit { font-size: 0.88rem; color: var(--text-dim); font-weight: 600; }
.pp-bottom { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; margin-top: 14px; }
.feedback { font-size: 0.88rem; font-weight: 600; }
.feedback.ok  { color: var(--green); }
.feedback.err { color: var(--red); }

.solution-panel {
  background: var(--surface2); border: 1px solid var(--border); border-radius: 8px;
  padding: 14px 16px; margin-top: 12px;
}
.solution-panel h4 { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--accent); margin-bottom: 8px; }
.sol-step { font-size: 0.82rem; color: var(--text-dim); line-height: 1.7; padding: 2px 0; }
.sol-step strong { color: var(--green); font-family: var(--mono); }

.practice-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.pbar-score { font-size: 0.84rem; color: var(--text-dim); margin-left: auto; white-space: nowrap; }
.pbar-score span { color: var(--text); font-weight: 700; }

/* ── Quiz panels ───────────────────────────────────────────── */
.question-panel {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px;
}
.qp-prompt { font-size: 0.88rem; font-weight: 600; color: var(--text); margin-bottom: 12px; line-height: 1.6; }
.answer-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.answer-btn {
  padding: 14px 16px; border: 2px solid var(--border); border-radius: 10px;
  background: var(--surface2); color: var(--text); font-size: 0.88rem;
  font-weight: 600; cursor: pointer; text-align: center;
  transition: border-color .18s, background .18s, color .18s, transform .12s;
}
.answer-btn:hover:not(.locked) { border-color: var(--accent); background: rgba(67,160,71,.06); }
.answer-btn.correct { border-color: var(--green); background: rgba(61,220,132,.12); color: var(--green); }
.answer-btn.wrong { border-color: var(--red); background: rgba(255,85,85,.08); color: var(--red); }
.answer-btn.locked { cursor: default; opacity: 0.6; }
.answer-btn.correct.locked { opacity: 1; }

.quiz-input-row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 10px; }
.qi-input {
  flex: 1; min-width: 120px; max-width: 200px;
  padding: 10px 14px; border: 2px solid var(--border); border-radius: 8px;
  background: var(--bg); color: var(--text); font-family: var(--mono);
  font-size: 1rem; font-weight: 700; transition: border-color .18s;
}
.qi-input:focus { outline: none; border-color: var(--accent); }
.qi-unit { font-size: 0.84rem; color: var(--text-dim); font-weight: 600; }

.quiz-bar {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  padding: 12px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.qbar-counter { display: flex; align-items: baseline; gap: 3px; background: var(--bg); border: 1px solid var(--border); border-radius: 8px; padding: 4px 12px; }
.qbar-q-label { font-size: 0.7rem; font-weight: 700; color: var(--accent); text-transform: uppercase; letter-spacing: .08em; }
.qbar-q-num { font-family: var(--mono); font-size: 1.3rem; font-weight: 700; color: var(--text); line-height: 1; }
.qbar-q-sep { font-size: 0.82rem; color: var(--text-dim); }
.qbar-q-total { font-family: var(--mono); font-size: 0.88rem; color: var(--text-dim); }
.quiz-feedback { font-size: 0.88rem; font-weight: 600; }
.quiz-feedback.ok  { color: var(--green); }
.quiz-feedback.err { color: var(--red); }

/* Quiz result */
.quiz-result {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 20px 22px; display: flex; flex-direction: column; gap: 14px;
}
.qr-header { display: flex; align-items: flex-start; justify-content: space-between; }
.qr-title-wrap { display: flex; flex-direction: column; gap: 5px; }
.qr-title  { font-size: 1.1rem; font-weight: 700; color: var(--text); }
.qr-stars  { font-size: 1.2rem; letter-spacing: 3px; }
.qr-score-wrap { text-align: right; }
.qr-score { font-family: var(--mono); font-size: 2.2rem; font-weight: 700; line-height: 1; text-shadow: 0 0 14px currentColor; }
.qr-score.perfect { color: var(--gold); }
.qr-score.good { color: var(--green); }
.qr-score.poor { color: var(--red); }
.qr-verdict { font-size: 0.72rem; color: var(--text-dim); margin-top: 3px; }
.qr-rows { display: flex; flex-direction: column; gap: 7px; }
.qr-row {
  display: grid; grid-template-columns: 30px 1fr 26px; align-items: center; gap: 10px;
  background: var(--surface2); border: 1px solid var(--border); border-left-width: 3px;
  border-radius: 8px; padding: 9px 12px;
}
.qr-row.ok  { border-left-color: var(--green); }
.qr-row.err { border-left-color: var(--red); }
.qr-qnum { font-size: 0.72rem; font-weight: 700; color: var(--accent); }
.qr-detail { font-size: 0.78rem; color: var(--text-dim); }
.qr-detail strong { color: var(--text); }
.qr-mark { text-align: right; font-size: 1rem; font-weight: 700; }
.qr-row.ok .qr-mark { color: var(--green); }
.qr-row.err .qr-mark { color: var(--red); }

/* ── SEO article ───────────────────────────────────────────── */
.seo-article { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 22px 24px; line-height: 1.7; }
.seo-article h2 { font-size: 1.25rem; font-weight: 700; color: var(--text); margin-bottom: 12px; }
.seo-article h3 { font-size: 1rem; font-weight: 700; color: var(--accent); margin: 16px 0 8px; }
.seo-article p { font-size: 0.88rem; color: var(--text-dim); margin-bottom: 10px; }
.seo-article strong { color: var(--text); }
.seo-article a { color: var(--accent); text-decoration: none; }
.seo-article a:hover { text-decoration: underline; }

/* ── Hint bar ─────────────────────────────────────────────── */
.hint-bar {
  padding: 10px 16px; background: var(--accent-lo); border: 1px solid var(--accent);
  border-radius: var(--radius); font-size: 0.82rem; color: var(--text);
  cursor: pointer; position: relative;
}
.hint-dismiss {
  position: absolute; right: 12px; top: 50%; transform: translateY(-50%);
  font-size: 1.1rem; color: var(--text-dim); cursor: pointer;
}

/* ── Warning bar ──────────────────────────────────────────── */
.warn-bar {
  padding: 6px 12px; background: rgba(255,85,85,.1); border: 1px solid var(--red);
  border-radius: var(--radius); display: flex; flex-wrap: wrap; align-items: center; gap: 8px;
}
.warn-item {
  display: flex; align-items: center; gap: 4px;
  font-size: 0.8rem; color: var(--red); font-weight: 600;
}
.warn-goto {
  padding: 2px 7px; border: 1px solid var(--red); border-radius: 5px;
  background: transparent; color: var(--red); font-size: 0.72rem; font-weight: 700;
  cursor: pointer; font-family: var(--mono); white-space: nowrap;
}
.warn-goto:hover { background: rgba(255,85,85,.18); }
.warn-more {
  font-size: 0.72rem; color: var(--text-dim); font-weight: 600;
  padding: 2px 6px; background: var(--surface2); border-radius: 5px; border: 1px solid var(--border);
}

/* ── Toolbar separator ────────────────────────────────────── */
.toolbar-sep {
  width: 1px; height: 24px; background: var(--border); margin: 0 4px;
}

/* ── Right-click context menu ─────────────────────────────── */
.ctx-menu {
  position: fixed; z-index: 1000; min-width: 160px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 8px;
  padding: 4px 0; box-shadow: 0 8px 24px rgba(0,0,0,.4);
}
.ctx-item {
  display: block; width: 100%; padding: 8px 16px; border: none;
  background: transparent; color: var(--text); font-size: 0.82rem;
  text-align: left; cursor: pointer; transition: background .12s;
}
.ctx-item:hover { background: var(--accent-lo); color: var(--accent); }

/* ── Toggle buttons (3D, Tool) ────────────────────────────── */
.toggle-btn { transition: background .15s, border-color .15s, color .15s; }
.toggle-btn.active {
  background: var(--accent) !important; color: #fff !important;
  border-color: var(--accent) !important;
}

/* ── Coordinate tooltip ──────────────────────────────────── */
.coord-tooltip {
  position: absolute; z-index: 5;
  padding: 3px 8px; background: rgba(13,17,23,.92);
  border: 1px solid var(--accent); border-radius: 6px;
  font-family: var(--mono); font-size: 0.72rem; color: var(--accent);
  pointer-events: none; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(0,0,0,.4);
}

/* ── Toolpath Statistics ─────────────────────────────────── */
.stats-panel {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 10px 16px;
}
.stats-panel .sim-toolbar-title { margin-bottom: 8px; display: block; }

/* ── Fullscreen button ────────────────────────────────────── */
.fs-btn {
  position: absolute; bottom: 10px; right: 10px; z-index: 4;
  width: 32px; height: 32px; border: none; border-radius: 8px;
  background: rgba(245,200,66,.18); border: 2px solid rgba(245,200,66,.6);
  color: var(--gold); font-size: 1.05rem; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
  transition: background .15s, border-color .15s, transform .15s;
  box-shadow: 0 0 8px rgba(245,200,66,.2);
}
.fs-btn:hover { background: rgba(245,200,66,.35); border-color: rgba(245,200,66,.9); transform: scale(1.1); }

/* ── Fullscreen mode ─────────────────────────────────────── */
#sim-panel.is-fullscreen {
  position: fixed; inset: 0; z-index: 9999;
  background: var(--bg);
  display: flex; flex-direction: column;
  overflow-y: auto; padding: 10px 14px;
}
#sim-panel.is-fullscreen .sim-toolbar {
  flex-shrink: 0;
}
#sim-panel.is-fullscreen .hint-bar,
#sim-panel.is-fullscreen .warn-bar {
  flex-shrink: 0;
}
#sim-panel.is-fullscreen .sim-layout {
  flex: 1; min-height: 0;
  grid-template-columns: minmax(280px, 1fr) 2fr;
}
#sim-panel.is-fullscreen .editor-wrap {
  min-height: 0; display: flex; flex-direction: column;
}
#sim-panel.is-fullscreen .syntax-wrap {
  flex: 1; min-height: 0;
}
#sim-panel.is-fullscreen .gcode-editor {
  flex: 1; min-height: 0; resize: none;
}
#sim-panel.is-fullscreen .canvas-card {
  min-height: 0; display: flex; flex-direction: column;
}
#sim-panel.is-fullscreen .canvas-card canvas {
  flex: 1; min-height: 0;
}
#sim-panel.is-fullscreen .sim-speed-row {
  flex-shrink: 0;
}
#sim-panel.is-fullscreen .readout-row {
  flex-shrink: 0;
}

/* ── Responsive ────────────────────────────────────────────── */
@media (max-width: 768px) {
  .sim-layout { grid-template-columns: 1fr; }
  .gcode-editor { min-height: 200px; }
  .answer-grid { grid-template-columns: 1fr 1fr; }
  .is-grid { grid-template-columns: repeat(auto-fill, minmax(130px, 1fr)); }
  .controls-bar { gap: 10px; }
  .readout-row { grid-template-columns: repeat(3, 1fr); }
  .sim-toolbar { gap: 8px; }
}
/* ── Editor line numbers gutter ──────────────────────────── */
.editor-linenos {
  position: absolute; left: 0; top: 0; bottom: 0; width: 36px; z-index: 3;
  background: rgba(13,17,23,.9); border-right: 1px solid var(--border);
  border-radius: 8px 0 0 8px;
  font-family: var(--mono); font-size: 0.85rem; line-height: 1.6;
  padding: 14px 4px 12px 0; overflow: hidden;
  user-select: none; pointer-events: none; opacity: 0.65;
  text-align: right; color: var(--text-dim);
  display: flex; flex-direction: column;
}
.editor-linenos span { display: block; padding-right: 4px; flex-shrink: 0; }

/* Shift editor/highlight text right to make room for the line-number gutter */
.syntax-wrap .gcode-editor { padding-left: 44px; }
.syntax-wrap .syntax-highlight { padding-left: 44px; }
.syntax-wrap #editor-highlight { left: 36px; }

/* ── Toolpath scrubber row ────────────────────────────────── */
.scrubber-row {
  display: flex; align-items: center; gap: 10px; padding: 8px 16px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
}
.scrubber-label { font-size: 0.76rem; font-weight: 700; color: var(--text-dim); white-space: nowrap; min-width: 60px; }
.scrubber-val { font-family: var(--mono); font-size: 0.84rem; color: var(--accent); white-space: nowrap; min-width: 80px; text-align: right; }

/* ── Save/Load slots ──────────────────────────────────────── */
.save-slots {
  display: flex; align-items: center; gap: 6px;
  padding: 6px 4px 2px; border-top: 1px solid var(--border); margin-top: 6px;
}
.save-slots-label {
  font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: .06em; color: var(--text-dim); margin-right: 4px; white-space: nowrap;
}
.save-slot-btn {
  width: 36px; height: 28px; border: 1px dashed var(--border); border-radius: 6px;
  background: var(--bg); color: var(--text-dim); font-size: 0.72rem; font-weight: 700;
  cursor: pointer; transition: border-color .15s, background .15s, color .15s;
}
.save-slot-btn:hover { border-color: var(--accent); color: var(--accent); }
.save-slot-btn.has-save {
  border-style: solid; border-color: rgba(67,160,71,.45);
  background: var(--accent-lo); color: var(--accent);
}
.save-slot-btn.has-save:hover { border-color: var(--accent); }

/* ── Tool diameter input ─────────────────────────────────── */
.tool-diam-input {
  width: 62px; padding: 5px 8px; border: 1px solid var(--border); border-radius: 7px;
  background: var(--bg); color: var(--accent); font-family: var(--mono);
  font-size: 0.88rem; font-weight: 700; text-align: center;
  transition: border-color .18s;
}
.tool-diam-input:focus { outline: none; border-color: var(--accent); }
.tool-diam-input::-webkit-inner-spin-button,
.tool-diam-input::-webkit-outer-spin-button { opacity: 0.4; }

/* ── Drill legend badge row ──────────────────────────────── */
.drill-legend {
  display: flex; gap: 14px; flex-wrap: wrap; align-items: center;
  padding: 6px 14px; background: rgba(124,77,255,.07);
  border: 1px solid rgba(124,77,255,.25); border-radius: 8px;
  font-size: 0.74rem; color: var(--text-dim);
}
.dl-swatch { display: inline-block; width: 12px; height: 12px; border-radius: 50%; margin-right: 4px; vertical-align: middle; }

/* ── Speeds & Feeds Calculator overlay ───────────────────── */
.sfc-backdrop {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background: rgba(0,0,0,.55); z-index: 10001; display: none;
}
.sfc-panel {
  position: fixed; top: 50%; left: 50%; transform: translate(-50%, -50%);
  width: 92%; max-width: 560px; max-height: 85vh; overflow-y: auto;
  background: var(--surface); border: 2px solid var(--gold);
  border-radius: var(--radius); padding: 20px 24px; z-index: 10002;
  box-shadow: 0 12px 48px rgba(0,0,0,.6); display: none;
}
.sfc-panel h3 { font-size: 1rem; color: var(--gold); margin-bottom: 14px; }
.sfc-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 16px; }
.sfc-field { display: flex; flex-direction: column; gap: 5px; }
.sfc-label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-dim); }
.sfc-results { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; margin-bottom: 14px; }
.sfc-result-card {
  background: var(--bg); border: 1px solid var(--border);
  border-radius: 8px; padding: 10px 14px; text-align: center;
}
.sfc-res-label { font-size: 0.62rem; text-transform: uppercase; letter-spacing: .07em; color: var(--text-dim); margin-bottom: 4px; }
.sfc-res-val { font-family: var(--mono); font-size: 1.2rem; font-weight: 700; color: var(--gold); }
.sfc-res-unit { font-size: 0.68rem; color: var(--text-dim); }
.sfc-formulas {
  font-size: 0.74rem; color: var(--text-dim); text-align: center;
  padding: 8px; background: var(--surface2); border-radius: 6px;
  font-family: var(--mono); margin-bottom: 2px;
}
@media (max-width: 500px) { .sfc-grid { grid-template-columns: 1fr; } }

@media (max-width: 500px) {
  header h1 { font-size: 1.4rem; }
  .subtitle  { font-size: 0.78rem; }
  .controls-bar { padding: 10px 12px; gap: 8px; }
  .pill { padding: 5px 10px; font-size: 0.76rem; }
  .answer-grid { grid-template-columns: 1fr; }
  .is-grid { grid-template-columns: 1fr 1fr; }
  .readout-row { grid-template-columns: 1fr 1fr; }
  .sim-toolbar { padding: 10px 12px; }
  .sim-select { min-width: 120px; font-size: 0.78rem; }
}
