/* ==========================================================================
   style.css — GPS Fundamentals (Pure 1967 Technical Book-Plate Aesthetic)
   Shared style language with Banana Shaft Lab, 3-2-1 Datum Lab, Straightness Lab,
   BeamLab & Engineering Graphics:
   Dark portfolio palette: Page (#090d16), Ink (#e9edf5), Vermilion (#ff7d61)
   ========================================================================== */

:root {
  color-scheme: dark;
  --bg-app: #090d16;
  --bg-panel: #0f151f;
  --bg-card: #111722;
  --bg-alt: #0e141e;
  --dia-plain: #0f151f;

  --border: rgba(233, 237, 245, 0.19);
  --border-subtle: rgba(233, 237, 245, 0.12);
  --border-strong: rgba(255, 125, 97, 0.55);

  --text: #e9edf5;
  --muted: #a8b3c5;
  --light: #7f8b9f;
  --ink: #e9edf5;
  --arc-stroke: #a8b3c5;
  --grid: #1d232e;

  --primary: #56a8e4;          /* Technical cobalt for tolerance zones */
  --primary-light: rgba(255, 125, 97, 0.08);
  --accent: #ff7d61;           /* Vermilion ink highlight & active controls */
  --accent-blue: #56a8e4;
  --accent-green: #58b691;
  --accent-2: #ed864b;
  --ok: #58b691;
  --bad: #ff7d61;
  --hl: #ff7d61;

  --given-bg: rgba(237, 134, 75, 0.09);
  --given-border: #ed864b;
  --pt-fill: #111722;
  --shadow: 0 2px 8px rgba(24, 23, 21, 0.06);
  --radius: 10px;

  --font: var(--xt-text);
  --font-display: var(--xt-title);
  --font-dia: var(--xt-sub);
  --mono: var(--xt-mono);
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  font: 14.5px/1.52 var(--font);
  background: var(--bg-app);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

/* Custom Ink Scrollbar */
::-webkit-scrollbar { width: 7px; height: 7px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(233, 237, 245, 0.25); border-radius: 4px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255, 125, 97, 0.55); }

/* ---------------- HEADER (1967 BOOK PLATE) ---------------- */

#app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 18px;
  background: var(--bg-panel);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 0;
}

.back-chip { text-decoration: none; }

.brand-badge-icon {
  width: 36px;
  height: 36px;
  border-radius: 9px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(255, 125, 97, 0.10);
  border: 1px solid var(--border-strong);
  color: var(--text);
  flex-shrink: 0;
}

.brand-text h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 800;
  letter-spacing: 0.04em;
  line-height: 1.15;
  white-space: nowrap;
}

.brand-text .sub-tag {
  font-weight: 600;
  color: var(--accent);
  margin-left: 6px;
}

.source-ref {
  margin: 0;
  font-size: 0.72rem;
  color: var(--muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.main-tabs {
  display: flex;
  align-items: center;
  gap: 4px;
  background: rgba(233, 237, 245, 0.06);
  padding: 4px;
  border-radius: 10px;
  border: 1px solid var(--border);
  flex-wrap: wrap;
}

.tabs button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font-family: var(--font);
  font-size: 0.8rem;
  font-weight: 600;
  padding: 7px 12px;
  border-radius: 7px;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.16s ease;
}

.tabs button:hover {
  color: var(--text);
  background: rgba(233, 237, 245, 0.06);
}

.tabs button.active {
  background: var(--accent);
  color: #111722;
}

.header-right {
  display: flex;
  align-items: center;
  gap: 8px;
}

.pill-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 7px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text);
  font-family: var(--font);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none;
  cursor: pointer;
  transition: all 0.15s ease;
  white-space: nowrap;
}

.pill-btn:hover {
  border-color: var(--border-strong);
  transform: translateY(-1px);
}

/* ---------------- WORKSPACE ---------------- */

main {
  flex: 1;
  width: 100%;
  max-width: 1380px;
  margin: 0 auto;
  padding: 18px 20px 28px;
}

.tab { display: none; }
.tab.active { display: block; }

.plate-kicker {
  font-family: var(--xt-small);
  font-size: 0.68rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  color: var(--accent);
  margin-bottom: 3px;
}

.tab-head h2 {
  margin: 0 0 4px;
  font-family: var(--font-display);
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: 0.01em;
  color: var(--text);
}

.tab-head p {
  margin: 0 0 16px;
  color: var(--muted);
  max-width: 960px;
  font-size: 0.86rem;
}

.layout {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 400px;
  gap: 16px;
  align-items: start;
}
@media (max-width: 1020px) { .layout { grid-template-columns: 1fr; } }

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 15px 17px;
  min-width: 0;
}

.card + .card { margin-top: 14px; }

.card h3 {
  margin: 0 0 10px;
  font-family: var(--font-display);
  font-size: 1rem;
  font-weight: 700;
  color: var(--text);
  display: flex;
  align-items: baseline;
  gap: 6px;
  flex-wrap: wrap;
}
.card h3 .score { margin-left: auto; }
.side .card h3 { font-size: 0.95rem; }

/* Highlight box "Given: ..." */
.given-box {
  background: var(--given-bg);
  border: 1px solid rgba(237, 134, 75, 0.28);
  border-left: 3.5px solid var(--given-border);
  padding: 8px 12px;
  border-radius: 0 7px 7px 0;
  font-size: 0.85rem;
  margin-bottom: 10px;
}
.given-box b { color: var(--text); }
.overline { text-decoration: overline; }

/* Construction drawing canvas (SVG) per DIN ISO 128 */
.dia {
  width: 100%;
  height: auto;
  display: block;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
  font-family: var(--font-dia);
  --halo: var(--dia-plain);
  background: var(--dia-plain);
  border-radius: 8px;
  border: 1px solid var(--border);
  margin: 10px 0;
}
.dia text { fill: var(--ink); }
.dia .bg-plain { fill: var(--dia-plain); }
.dia .halo { paint-order: stroke; stroke: var(--halo); stroke-width: 4.5px; stroke-linejoin: round; }
.dia .given-line { stroke: var(--ink); fill: none; stroke-linecap: round; }
.dia .res-line { stroke: var(--primary); fill: none; stroke-linecap: round; }
.dia .arc-line { stroke: var(--arc-stroke); fill: none; stroke-width: 1.25; stroke-linecap: round; }
.dia .thin-arc { stroke: var(--arc-stroke); fill: none; stroke-width: 0.9; stroke-dasharray: 4 3; }
.dia .thin-line { stroke: var(--ink); fill: none; stroke-width: 1.05; }
.dia .proof-line { stroke: var(--accent-green); fill: none; stroke-width: 1.5; stroke-dasharray: 5 3; }
.dia .proof-fill { fill: var(--accent-green); fill-opacity: 0.10; stroke: var(--accent-green); stroke-width: 1.3; stroke-dasharray: 5 3; }
.dia .warn-arc { stroke: var(--bad); fill: none; stroke-width: 1.6; stroke-dasharray: 4 3; }
.dia .ax-head { fill: var(--ink); stroke: none; }
.dia .pt { fill: var(--pt-fill); stroke: var(--ink); stroke-width: 1.6; }
.dia .pt.sel { stroke: var(--accent); stroke-width: 2.5; }
.dia .pt.pt-res { fill: var(--accent); stroke: var(--ink); stroke-width: 1.5; }
.dia text.step-num { fill: var(--accent); font-weight: 800; }
.dia text.lbl-strong { font-weight: 700; }
.dia text.lbl-muted { fill: var(--muted); }
.dia .center-mark line { stroke: var(--muted); opacity: 0.65; }

/* Controls */
.ctl-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px 12px;
  align-items: center;
  margin: 8px 0;
  font-size: 0.84rem;
}

.group-bar { margin-bottom: 12px; }

.seg {
  display: inline-flex;
  background: rgba(233, 237, 245, 0.06);
  padding: 3px;
  border: 1px solid var(--border);
  border-radius: 9px;
  gap: 3px;
  flex-wrap: wrap;
}
.seg button {
  appearance: none;
  border: 0;
  background: transparent;
  color: var(--muted);
  font: 600 0.8rem var(--font);
  padding: 6px 12px;
  border-radius: 6px;
  cursor: pointer;
  transition: all 0.14s ease;
}
.seg button:hover { color: var(--text); background: rgba(233, 237, 245, 0.06); }
.seg button.on { background: var(--accent); color: #111722; }

label.chk { display: inline-block; font-size: 0.84rem; font-weight: 600; color: var(--text); cursor: pointer; }
label.chk input { vertical-align: middle; margin: 0 5px 2px 0; accent-color: var(--accent); }

.slider {
  display: grid;
  grid-template-columns: minmax(125px, auto) 1fr auto;
  gap: 8px;
  align-items: center;
  font-size: 0.82rem;
  color: var(--muted);
  margin: 7px 0;
}
.slider input[type=range] { width: 100%; accent-color: var(--accent); }
.slider output { font: 700 0.8rem var(--mono); min-width: 72px; text-align: right; color: var(--text); }

.btn {
  appearance: none;
  border: 1px solid var(--accent);
  background: var(--accent);
  color: #111722;
  font: 600 0.78rem var(--font);
  padding: 6px 12px;
  border-radius: 7px;
  cursor: pointer;
  transition: all 0.14s ease;
}
.btn:hover { filter: brightness(0.95); transform: translateY(-1px); }
.btn.ghost {
  background: var(--bg-panel);
  border-color: var(--border);
  color: var(--text);
}
.btn.ghost:hover { border-color: var(--border-strong); }

input.num, select {
  font: 600 0.84rem var(--mono);
  padding: 5px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--bg-panel);
  color: var(--text);
}
select { font-family: var(--font); }
input.num { width: 88px; }
input.num:focus, select:focus { outline: 2px solid var(--accent); outline-offset: -1px; }

.rules { list-style: none; margin: 0; padding: 0; }
.rules li {
  display: block;
  border-left: 3px solid var(--accent);
  padding: 7px 11px;
  margin: 6px 0;
  font-size: 0.82rem;
  border-radius: 0 6px 6px 0;
  background: var(--bg-panel);
}
.rules li b { color: var(--text); }

.note { font-size: 0.8rem; color: var(--muted); margin: 8px 0 0; }
.feedback { margin-top: 10px; font-size: 0.88rem; font-weight: 600; min-height: 1.4em; }
.feedback.ok { color: var(--ok); }
.feedback.bad { color: var(--bad); }
.score { font: 700 0.82rem var(--mono); color: var(--accent); margin-left: auto; }

/* ---------------- GPS OVERVIEW & TABLE ---------------- */

.ovgrid { display: grid; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); gap: 14px; }
.ovgrid .card + .card { margin-top: 0; }
.group-card { border-top: 3px solid var(--text); }
.group-card:nth-child(2) { border-top-color: var(--accent-blue); }
.group-card:nth-child(3) { border-top-color: var(--accent); }
.group-card:nth-child(4) { border-top-color: var(--accent-green); }

.symgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.symcard {
  appearance: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  padding: 10px 6px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg-panel);
  color: var(--text);
  font: 600 0.78rem var(--font);
  cursor: pointer;
  text-align: center;
  transition: all 0.14s ease;
}
.symcard:hover {
  border-color: var(--border-strong);
  background: rgba(255, 125, 97, 0.08);
  transform: translateY(-1px);
}

.symsvg { display: block; flex-shrink: 0; }
.sym, .symsvg { color: var(--ink); }
.sym path, .sym circle { fill: none; stroke: currentColor; stroke-width: 1.3; stroke-linecap: round; stroke-linejoin: round; }
.sym .fillsym { fill: currentColor; stroke-width: 0.6; }

.dbadge {
  font: 600 0.61rem var(--xt-small);
  padding: 2px 5px;
  border-radius: 5px;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--muted);
  white-space: nowrap;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
}
.dbadge.d-ja { border-color: rgba(86, 168, 228, 0.45); color: var(--accent-blue); background: rgba(86, 168, 228, 0.08); }
.dbadge.d-optional { border-color: rgba(237, 134, 75, 0.45); color: var(--accent-2); background: rgba(237, 134, 75, 0.08); }

.rulebox {
  background: rgba(255, 125, 97, 0.08);
  border: 1px solid rgba(255, 125, 97, 0.26);
  border-left: 3.5px solid var(--accent);
  padding: 9px 14px;
  border-radius: 0 7px 7px 0;
  margin: 10px 0 12px;
  font-size: 0.88rem;
}

.tolwrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--bg-card);
  box-shadow: var(--shadow);
}
.toltable { border-collapse: collapse; width: 100%; min-width: 900px; }
.toltable th {
  text-align: left;
  font-family: var(--xt-small);
  font-size: 0.7rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  padding: 10px 12px;
  background: var(--bg-panel);
  border-bottom: 1.5px solid var(--text);
  color: var(--text);
}
.toltable td {
  border-top: 1px solid var(--border);
  border-left: 1px solid var(--border-subtle);
  vertical-align: top;
  padding: 8px;
  width: 30%;
}
.toltable td.symcell { width: 10%; border-left: 0; text-align: center; font-size: 0.82rem; background: var(--bg-panel); }
.toltable td.symcell .symsvg { margin: 4px auto 6px; }
.toltable td.symcell b { display: block; margin-bottom: 6px; font-family: var(--font-display); }
.toltable tr.focus td { background: rgba(255, 125, 97, 0.09); }
.toltable tr.info td { border-top: 1px dashed var(--border); background: var(--bg-panel); padding: 9px 14px; }
.toltable dl { display: grid; grid-template-columns: max-content 1fr; gap: 4px 14px; margin: 0; font-size: 0.82rem; }
.toltable dt { color: var(--muted); font-weight: 700; font-family: var(--mono); font-size: 0.72rem; text-transform: uppercase; padding-top: 2px; }
.toltable dd { margin: 0; color: var(--text); }

/* Technical SVG Drawings (1967 Book-Plate Ink Palette) */
.fig { width: 100%; height: auto; display: block; font-family: var(--font-dia); background: var(--dia-plain); border-radius: 6px; border: 1px solid var(--border-subtle); }
.fig .part, .dia .part { stroke: var(--ink); stroke-width: 1.65; fill: none; stroke-linejoin: round; }
.fig .thin, .dia .thin { stroke: var(--ink); stroke-width: 0.9; fill: none; }
.fig .center, .dia .center { stroke: var(--light); stroke-width: 0.85; stroke-dasharray: 12 3 2 3; fill: none; }
.fig .head, .dia .head { fill: var(--ink); stroke: none; }
.fig .zone, .dia .zone { stroke: var(--primary); stroke-width: 1.2; stroke-dasharray: 5 3; fill: none; }
.fig .zonefill { fill: var(--primary); fill-opacity: 0.13; stroke: none; }
.fig .zonecirc { stroke: var(--primary); stroke-width: 0.75; fill: none; opacity: 0.75; }
.fig .real, .dia .real { stroke: var(--accent); stroke-width: 1.7; fill: none; stroke-linejoin: round; }
.fig .realpt { fill: var(--accent); stroke: none; }
.fig .devline { stroke: var(--accent-green); stroke-width: 1.2; fill: none; }
.fig .datumplane { fill: var(--muted); fill-opacity: 0.25; stroke: var(--ink); stroke-width: 0.85; }
.fig .datumtri { fill: var(--ink); stroke: var(--ink); stroke-width: 0.6; stroke-linejoin: round; }
.fig .framebox, .framebig .framebox, .qframe .framebox { fill: var(--bg-card); stroke: var(--ink); stroke-width: 1.1; }
.fig .tedbox { fill: none; stroke: var(--ink); stroke-width: 0.95; }
.fig .gauge { fill: var(--bg-alt); stroke: var(--ink); stroke-width: 1.15; }
.fig text, .dia text, .framebig text, .qframe text { fill: var(--ink); font-size: 10px; }
.fig .frametxt, .framebig .frametxt, .qframe .frametxt { font-size: 10.5px; font-weight: 700; font-family: var(--xt-small); }
.fig .dimtxt { font-size: 10px; font-family: var(--xt-small); }
.fig .zonetxt, .dia .zonetxt { fill: var(--primary); font-size: 10px; font-weight: 700; }
.fig .devtxt { fill: var(--accent-green); font-size: 10px; font-weight: 700; }
.fig .small, .dia .small { fill: var(--muted); font-size: 8.6px; }
.dia .warnline { stroke: var(--bad); stroke-width: 1.5; stroke-dasharray: 5 3; fill: none; }

/* Tolerance Frame Checker */
.framebig {
  background: var(--dia-plain);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 18px;
  margin: 12px 0;
}
.framebig svg { display: block; height: 84px; width: auto; max-width: 100%; margin: 0 auto; }
.reading p { margin: 5px 0; font-size: 0.86rem; color: var(--text); }
input.num.short { width: 56px; text-transform: uppercase; text-align: center; font-family: var(--mono); }

.checks { list-style: none; margin: 0; padding: 0; font-size: 0.84rem; }
.checks li {
  padding: 7px 11px;
  margin: 6px 0;
  border-radius: 0 6px 6px 0;
  border-left: 3.5px solid var(--border);
  background: var(--bg-panel);
}
.checks li.ok { border-left-color: var(--ok); background: rgba(88, 182, 145, 0.08); }
.checks li.bad { border-left-color: var(--bad); background: rgba(255, 125, 97, 0.09); }
.checks li.warn { border-left-color: var(--accent-2); background: rgba(237, 134, 75, 0.09); }

/* Principles List */
.plist { display: grid; gap: 6px; }
.pcard {
  display: flex;
  gap: 12px;
  padding: 9px 6px;
  border-bottom: 1px solid var(--border-subtle);
}
.pcard:last-child { border-bottom: 0; }
.pcard p { margin: 3px 0; font-size: 0.84rem; }
.pnum { font: 800 0.82rem var(--mono); color: var(--accent); min-width: 40px; padding-top: 2px; }

/* Practice Quiz */
.quiz { max-width: 780px; }
.qtext { font-family: var(--font-display); font-size: 1.12rem; font-weight: 700; margin: 12px 0; }
.qsvg { min-height: 10px; }
.qsvg .symsvg { margin: 6px 0 12px; }
.qframe { display: block; width: 100%; max-width: 420px; height: auto; margin: 8px 0 12px; }
.choice.right { background: var(--ok); border-color: var(--ok); color: #111722; }
.choice.wrong { border-color: var(--bad); color: var(--bad); background: rgba(255, 125, 97, 0.09); }

/* ---------------- FOOTER ---------------- */

footer {
  margin-top: auto;
  padding: 12px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-panel);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  color: var(--muted);
  font-size: 0.74rem;
  flex-wrap: wrap;
}

footer a { color: var(--accent); font-weight: 600; text-decoration: none; }
footer a:hover { text-decoration: underline; }
.footer-meta { white-space: nowrap; }

@media (max-width: 640px) {
  main { padding: 12px 12px 24px; }
  .card { padding: 12px; }
}
