:root {
  --bg: #0b0f14;
  --panel: #111821;
  --panel-2: #16202c;
  --line: #22303f;
  --text: #dbe6f2;
  --muted: #7f94aa;
  --accent: #f59e0b;
  --blue: #3b82f6;
  --red: #ef4444;
  --green: #22c55e;
  --amber: #f59e0b;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 14px;
  overflow: hidden;
}

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

/* ---------- panel ---------- */
.panel {
  background: var(--panel);
  border-right: 1px solid var(--line);
  padding: 16px 16px 8px;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 18px;
}

.brand { display: flex; gap: 12px; align-items: center; }
.logo {
  width: 44px; height: 44px; flex: 0 0 44px;
  display: grid; place-items: center;
  border-radius: 12px;
  background: linear-gradient(140deg, #f59e0b, #b45309);
  color: #1a1206; font-weight: 800; font-size: 12px; letter-spacing: .5px;
}
.brand h1 { font-size: 16px; margin: 0; letter-spacing: .2px; }
.brand p { margin: 2px 0 0; font-size: 11px; color: var(--muted); }

.group { display: flex; flex-direction: column; gap: 8px; }
.group + .group { border-top: 1px solid var(--line); padding-top: 16px; }

.lbl {
  font-size: 11px; text-transform: uppercase; letter-spacing: .8px;
  color: var(--muted); font-weight: 600;
}
.row { display: flex; justify-content: space-between; align-items: baseline; }
.row output { font-variant-numeric: tabular-nums; font-size: 12px; color: var(--text); }

select, input[type="range"] { width: 100%; }

select {
  background: var(--panel-2);
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13px;
  font-family: inherit;
}

/* Area tangkap 22 px, garis yang terlihat tetap 4 px.
   Sebelumnya height: 4px membuat slider sangat sulit digeser dengan mouse. */
input[type="range"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 22px;
  background: transparent;
  outline: none;
  margin: 2px 0 2px;
  cursor: pointer;
  touch-action: pan-y;
}
input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: var(--line);
}
input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--accent);
  border: 2px solid #1a1206;
  cursor: pointer;
  margin-top: -5.5px;
}
input[type="range"]::-moz-range-track {
  height: 4px; border-radius: 4px; background: var(--line);
}
input[type="range"]::-moz-range-thumb {
  width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent); border: 2px solid #1a1206; cursor: pointer;
}
input[type="range"]:focus-visible::-webkit-slider-thumb { box-shadow: 0 0 0 3px rgba(245,158,11,.35); }

.hint { margin: 0; font-size: 11px; color: var(--muted); line-height: 1.45; }

.seg { display: flex; gap: 6px; }
.seg button {
  flex: 1;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  padding: 8px 6px;
  font-size: 12px; font-family: inherit; cursor: pointer;
  transition: .15s;
}
.seg button.on {
  background: rgba(245, 158, 11, .14);
  border-color: var(--accent);
  color: #fbbf24;
  font-weight: 600;
}

.switch { display: flex; align-items: center; gap: 10px; cursor: pointer; user-select: none; }
.switch input { display: none; }
.slider {
  width: 38px; height: 21px; border-radius: 999px; background: var(--line);
  position: relative; transition: .18s; flex: 0 0 38px;
}
.slider::after {
  content: ""; position: absolute; top: 3px; left: 3px;
  width: 15px; height: 15px; border-radius: 50%; background: #8ba0b6;
  transition: .18s;
}
.switch input:checked + .slider { background: rgba(34,197,94,.35); }
.switch input:checked + .slider::after { left: 20px; background: var(--green); }
.switch-label { font-size: 13px; font-weight: 500; }

details { border-top: 1px dashed var(--line); padding-top: 10px; margin-top: 2px; }
details summary {
  cursor: pointer; font-size: 12px; color: var(--muted); margin-bottom: 10px;
  list-style: none;
}
details summary::before { content: "▸ "; }
details[open] summary::before { content: "▾ "; }
details .row { margin-top: 6px; }

.actions { flex-direction: row !important; gap: 8px; }
button.primary, .actions button {
  flex: 1;
  padding: 10px 12px;
  border-radius: 9px;
  border: 1px solid var(--line);
  background: var(--panel-2);
  color: var(--text);
  font-family: inherit; font-size: 13px; font-weight: 600;
  cursor: pointer; transition: .15s;
}
button.primary { background: linear-gradient(140deg,#f59e0b,#d97706); color: #1a1206; border-color: #d97706; }
.actions button:hover { filter: brightness(1.12); }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button {
  background: var(--panel-2); border: 1px solid var(--line);
  color: var(--muted); border-radius: 999px; padding: 6px 11px;
  font-size: 11.5px; font-family: inherit; cursor: pointer;
}
.chips button:hover { border-color: var(--accent); color: #fbbf24; }

.foot { margin-top: auto; padding: 10px 0 4px; font-size: 10.5px; color: #55677a; }

.spec-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px 10px; }
.spec-grid label { display: flex; flex-direction: column; gap: 3px; font-size: 10.5px; color: var(--muted); }
.spec-grid input {
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 7px;
  color: var(--text); font-family: inherit; font-size: 12.5px; padding: 5px 7px;
  font-variant-numeric: tabular-nums; width: 100%;
}
.spec-grid input:focus { outline: 1px solid var(--accent); border-color: var(--accent); }
.spec-grid small { color: #55677a; }

/* ---------- stage ---------- */
.stage-wrap { display: flex; flex-direction: column; min-width: 0; }

.stage { position: relative; flex: 1; min-height: 0; }
#view { display: block; width: 100%; height: 100%; }

.hud {
  position: absolute; top: 14px; left: 14px; right: 14px;
  display: flex; flex-wrap: wrap; gap: 8px;
  pointer-events: none;
}
.card {
  background: rgba(13, 20, 28, .82);
  border: 1px solid rgba(52, 74, 96, .8);
  border-radius: 10px;
  padding: 7px 12px;
  min-width: 96px;
  backdrop-filter: blur(6px);
}
.card .k { display: block; font-size: 9.5px; letter-spacing: .9px; text-transform: uppercase; color: var(--muted); }
.card b { font-size: 17px; font-variant-numeric: tabular-nums; font-weight: 650; letter-spacing: -.3px; }
.card.state b { font-size: 13px; letter-spacing: .3px; }

.state.s-cruise b { color: #8ba0b6; }
.state.s-warn b { color: var(--amber); }
.state.s-partial b { color: #fb923c; }
.state.s-full b { color: var(--red); }
.state.s-stopped b { color: var(--green); }
.state.s-collision b { color: var(--red); }

.verdict {
  position: absolute; left: 50%; bottom: 22px; transform: translateX(-50%) translateY(10px);
  padding: 11px 20px; border-radius: 12px;
  background: rgba(13,20,28,.92);
  border: 1px solid var(--line);
  font-size: 14px; font-weight: 600;
  opacity: 0; transition: .25s; pointer-events: none;
  text-align: center; max-width: 82%;
}
.verdict.show { opacity: 1; transform: translateX(-50%) translateY(0); }
.verdict.ok { border-color: rgba(34,197,94,.6); color: #86efac; }
.verdict.bad { border-color: rgba(239,68,68,.6); color: #fca5a5; }
.verdict small { display: block; font-weight: 400; font-size: 11.5px; color: var(--muted); margin-top: 4px; }

/* ---------- bottom ---------- */
.bottom {
  height: var(--bottom-h, 200px);
  flex: 0 0 auto;
  overflow: hidden;
  border-top: 1px solid var(--line);
  display: grid;
  grid-template-columns: 1fr 300px;
  background: #0d141c;
}
.chartbox, .logbox { display: flex; flex-direction: column; min-width: 0; min-height: 0; overflow: hidden; padding: 8px 12px; }
.logbox { border-left: 1px solid var(--line); }
.chart-head {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 10px; letter-spacing: .9px; text-transform: uppercase; color: var(--muted);
  margin-bottom: 4px;
}
.legend { display: flex; align-items: center; gap: 5px; text-transform: none; letter-spacing: 0; }
.legend i { width: 9px; height: 3px; border-radius: 2px; display: inline-block; }
.legend i.s { background: #38bdf8; }
.legend i.b { background: #f97316; margin-left: 6px; }

#chart { flex: 1 1 0; width: 100%; height: auto; min-height: 0; display: block; }

#log {
  list-style: none; margin: 0; padding: 0 6px 0 0;
  flex: 1 1 0; min-height: 0;
  overflow-y: auto; overflow-x: hidden;
  font-size: 11.5px; line-height: 1.55;
  font-variant-numeric: tabular-nums;
  scrollbar-width: thin; scrollbar-color: #2b3d52 transparent;
}
#log::-webkit-scrollbar { width: 9px; }
#log::-webkit-scrollbar-track { background: transparent; }
#log::-webkit-scrollbar-thumb { background: #2b3d52; border-radius: 5px; }
#log::-webkit-scrollbar-thumb:hover { background: #3b5470; }
#log li { display: flex; gap: 8px; }
#log li span.t { color: #55677a; flex: 0 0 42px; }
#log li.warn { color: #fbbf24; }
#log li.partial { color: #fb923c; }
#log li.full { color: #fca5a5; }
#log li.ok { color: #86efac; }
#log li.bad { color: #f87171; }

/* ---------- modal metode perhitungan ---------- */
.modal {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(4, 8, 12, .78);
  backdrop-filter: blur(3px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
}
.modal[hidden] { display: none; }
.modal-body {
  background: #0e151d;
  border: 1px solid var(--line);
  border-radius: 14px;
  width: min(920px, 100%);
  max-height: 88vh;
  display: flex; flex-direction: column;
  box-shadow: 0 24px 60px rgba(0,0,0,.6);
}
.modal-body header {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 22px; border-bottom: 1px solid var(--line);
}
.modal-body h2 { margin: 0; font-size: 15px; letter-spacing: .3px; }
.modal-body header button {
  background: transparent; border: 1px solid var(--line); color: var(--muted);
  width: 30px; height: 30px; border-radius: 8px; cursor: pointer; font-size: 14px;
}
.modal-body header button:hover { color: var(--text); border-color: var(--accent); }

.modal-content { overflow-y: auto; padding: 18px 24px 28px; font-size: 13px; line-height: 1.62; }
.modal-content .lead { color: var(--muted); }
.modal-content h3 {
  font-size: 12px; text-transform: uppercase; letter-spacing: .9px;
  color: #9db2c8; margin: 26px 0 10px; padding-bottom: 6px;
  border-bottom: 1px solid var(--line);
}
.modal-content h3:first-of-type { margin-top: 18px; }
.modal-content p { margin: 8px 0; }
.modal-content code {
  background: #16202c; padding: 1px 5px; border-radius: 4px;
  font-size: 12px; color: #cbd5e1;
}
.modal-content pre.formula {
  background: #0a1016; border: 1px solid var(--line); border-left: 3px solid #33475b;
  border-radius: 8px; padding: 12px 14px; overflow-x: auto;
  font-family: "JetBrains Mono", ui-monospace, monospace;
  font-size: 12px; line-height: 1.65; color: #b9cade; margin: 10px 0;
}
.modal-content table.eq { width: 100%; border-collapse: collapse; margin: 8px 0; }
.modal-content table.eq td { padding: 5px 8px; border-bottom: 1px solid rgba(34,48,63,.6); vertical-align: top; }
.modal-content table.eq td:first-child {
  width: 130px; color: #93c5fd; font-family: ui-monospace, monospace; font-size: 12.5px;
}
.modal-content ul { margin: 8px 0; padding-left: 20px; color: var(--muted); }
.modal-content li { margin: 4px 0; }
.modal-content .warn {
  color: #fcd34d; background: rgba(245,158,11,.07);
  border-left: 3px solid #b45309; padding: 8px 12px; border-radius: 0 6px 6px 0;
}
.modal-content .ok {
  color: #86efac; background: rgba(34,197,94,.07);
  border-left: 3px solid #15803d; padding: 8px 12px; border-radius: 0 6px 6px 0;
}
.modal-content .tag {
  font-size: 9.5px; letter-spacing: .5px; text-transform: none;
  background: rgba(245,158,11,.15); color: #fbbf24;
  border: 1px solid rgba(245,158,11,.35); border-radius: 999px;
  padding: 1px 8px; margin-left: 6px; vertical-align: middle;
}
svg.timeline { width: 100%; height: auto; margin: 10px 0 4px; }
svg.timeline .tl { fill: #9db2c8; font-size: 10.5px; font-family: Inter, system-ui, sans-serif; }
svg.timeline .tl2 { fill: #5d7186; font-size: 9.5px; font-family: Inter, system-ui, sans-serif; }

.modal-content { scrollbar-width: thin; scrollbar-color: #2b3d52 #0a1016; }
.modal-content::-webkit-scrollbar { width: 11px; }
.modal-content::-webkit-scrollbar-track { background: #0a1016; border-radius: 0 0 14px 0; }
.modal-content::-webkit-scrollbar-thumb { background: #2b3d52; border-radius: 6px; border: 2px solid #0a1016; }
.modal-content::-webkit-scrollbar-thumb:hover { background: #3b5470; }
.modal-body header .hintkbd {
  font-size: 10px; color: #55677a; margin-left: 10px; letter-spacing: .4px;
}

.modal-content table.eq.wide td:first-child { width: auto; color: #cbd5e1; font-family: inherit; font-size: 12.5px; }
.modal-content table.eq.wide th {
  text-align: left; font-size: 10px; text-transform: uppercase; letter-spacing: .6px;
  color: var(--muted); padding: 6px 8px; border-bottom: 1px solid var(--line); font-weight: 600;
}
.modal-content table.eq.wide td { font-size: 12.5px; }


/* ---------- divider yang bisa ditarik ---------- */
.dragbar {
  flex: 0 0 7px; height: 7px; cursor: ns-resize;
  background: #0b1219; border-top: 1px solid var(--line);
  position: relative;
}
.dragbar::after {
  content: ""; position: absolute; left: 50%; top: 2px; margin-left: -26px;
  width: 52px; height: 3px; border-radius: 2px; background: #22303f; transition: background .15s;
}
.dragbar:hover::after, .dragbar.dragging::after { background: var(--accent); }
body.resizing { cursor: ns-resize; user-select: none; }

.modal-content .tl2note { font-size: 11px; color: #5d7186; margin-top: -2px; }

/* ---------- diagram SVG di menu metode ---------- */
svg.diagram { width: 100%; height: auto; margin: 12px 0 6px; display: block; }
svg.diagram .dbox { fill: #111a24; stroke: #33475b; stroke-width: 1.2; }
svg.diagram .dt { fill: #dbe6f2; font: 600 11.5px Inter, system-ui, sans-serif; }
svg.diagram .ds { fill: #7f94aa; font: 9.5px Inter, system-ui, sans-serif; }
svg.diagram .dlabel { fill: #cbd5e1; font: 600 11px Inter, system-ui, sans-serif; }
svg.diagram .dsmall { fill: #7f94aa; font: 9.5px Inter, system-ui, sans-serif; }
svg.diagram .darrow { stroke: #5b7793; stroke-width: 1.6; fill: none; }

.modal-content h4 {
  font-size: 12.5px; color: #cbd5e1; margin: 20px 0 6px; font-weight: 650;
}

.verifychip {
  position: absolute; left: 14px; bottom: 14px;
  background: #1b2430; border: 1px solid #3b4a5c;
  color: #fbbf24; font-size: 11px; font-weight: 600; letter-spacing: .2px;
  padding: 6px 11px; border-radius: 8px;
  pointer-events: none;
  transition: none;
  animation: none;
  /* tanpa transparansi dan tanpa backdrop-filter: latar yang berkedip di belakang
     (canvas yang digambar ulang 60x/detik) membuat chip tampak berkedip di sebagian GPU */
  background-color: #1b2430;
  mix-blend-mode: normal;
}
.verifychip[hidden] { display: none; }

/* ---------- indikator spek belum diverifikasi ---------- */
@keyframes specBlink {
  0%, 100% { opacity: 1; }
  50%      { opacity: 0.12; }
}
#specBox.needs-verify > summary {
  color: #fbbf24;
  font-weight: 700;
  animation: specBlink 0.9s steps(1, end) infinite;
}
#specBox.needs-verify > summary::before { color: #fbbf24; }
@media (prefers-reduced-motion: reduce) {
  #specBox.needs-verify > summary { animation: none; color: #fbbf24; font-weight: 700; }
}
