/* base.css - colours, page layout, header, side panels and the workspace frame. */
:root {
  --bg: #0a0f1c;
  --panel: #0f1629;
  --panel-2: #131c33;
  --card: #151f38;
  --card-2: #1a2644;
  --line: #22304f;
  --line-2: #2c3c61;
  --text: #e6edf9;
  --muted: #8d9dbd;
  --dim: #6a7a9b;
  --accent: #38bdf8;
  --ok: #34d399;
  --err: #f87171;
  --warn: #fbbf24;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", "DejaVu Sans", "Liberation Sans", sans-serif;
  --mono: "SFMono-Regular", Consolas, "DejaVu Sans Mono", "Liberation Mono", monospace;
}
* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  background: var(--bg); color: var(--text); font: 13px/1.45 var(--font);
  overflow: hidden; -webkit-font-smoothing: antialiased;
}
button { font: inherit; color: inherit; }
kbd {
  font: 600 10.5px/1 var(--mono); padding: 2px 5px; border-radius: 5px; background: #0b1222;
  border: 1px solid var(--line-2); border-bottom-width: 2px; color: #cbd5e1; white-space: nowrap;
}
[hidden] { display: none !important; }
.ic { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.grow { flex: 1; }

#app {
  height: 100vh;
  display: grid;
  grid-template-rows: 58px minmax(0, 1fr);
  grid-template-columns: clamp(212px, 15vw, 264px) minmax(0, 1fr) clamp(292px, 20vw, 360px);
}

/* ---------- Header ---------- */
.top {
  grid-column: 1 / -1; display: flex; align-items: center; gap: 14px; padding: 0 14px 0 16px;
  background: linear-gradient(180deg, #111a31, #0d1427); border-bottom: 1px solid var(--line); position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 180px; }
.logo { width: 34px; height: 34px; filter: drop-shadow(0 4px 10px rgba(56, 189, 248, .35)); }
.brand-name { font-weight: 700; font-size: 16px; letter-spacing: .2px; }
.brand-sub { font-size: 11px; color: var(--muted); }
.stepper { flex: 1; display: flex; align-items: center; justify-content: center; min-width: 0; }
.stp {
  display: flex; align-items: center; gap: 7px; background: none; border: 0; padding: 6px 8px;
  border-radius: 999px; cursor: pointer; color: var(--muted); white-space: nowrap;
}
.stp:hover { background: rgba(148, 163, 184, .08); color: var(--text); }
.stp-dot {
  width: 24px; height: 24px; border-radius: 50%; display: grid; place-items: center; font-weight: 700;
  font-size: 12px; border: 1.5px solid var(--line-2); background: #0c1325;
}
.stp-dot .ic { width: 14px; height: 14px; stroke-width: 3; }
.stp-txt { font-weight: 600; font-size: 12.5px; }
.stp.active { color: var(--text); background: rgba(56, 189, 248, .08); }
.stp.active .stp-dot { border-color: var(--accent); color: #fff; background: rgba(56, 189, 248, .2); box-shadow: 0 0 0 4px rgba(56, 189, 248, .12); }
.stp.done .stp-dot { background: var(--ok); border-color: var(--ok); color: #05281c; }
.stp-line { width: 20px; height: 2px; background: var(--line-2); border-radius: 2px; flex: none; }
.stp-line.done { background: var(--ok); }
.top-actions { display: flex; gap: 6px; }

.icon-btn {
  width: 34px; height: 34px; display: inline-grid; place-items: center; border-radius: 9px; border: 1px solid transparent;
  background: transparent; color: var(--muted); cursor: pointer; transition: background .15s, color .15s; flex: none;
}
.icon-btn:hover:not(:disabled) { background: rgba(148, 163, 184, .12); color: var(--text); }
.icon-btn:disabled { opacity: .35; cursor: default; }
.icon-btn.sm { width: 28px; height: 28px; }
.icon-btn.sm .ic { width: 16px; height: 16px; }
.top-actions .icon-btn { border-color: var(--line); background: var(--panel-2); }

/* ---------- Side panels ---------- */
.panel { background: var(--panel); overflow-y: auto; overflow-x: hidden; scrollbar-width: thin; scrollbar-color: var(--line-2) transparent; }
.panel.left { border-right: 1px solid var(--line); padding: 14px 12px 16px; }
.panel.right { border-left: 1px solid var(--line); padding: 14px 14px 18px; display: flex; flex-direction: column; gap: 12px; }
.panel h2 { margin: 0 0 8px; font-size: 11px; font-weight: 700; letter-spacing: 1.1px; text-transform: uppercase; color: var(--muted); }
.panel section + section { margin-top: 16px; }
.hint { margin: -4px 0 9px; color: var(--dim); font-size: 11.5px; }

.palette { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.pcard {
  display: flex; flex-direction: column; align-items: center; padding: 7px 4px 7px; border-radius: 11px;
  border: 1px solid var(--line); background: linear-gradient(180deg, var(--card-2), var(--card));
  cursor: grab; touch-action: none; user-select: none; transition: transform .12s, border-color .15s, box-shadow .15s;
}
.pcard:hover { border-color: #3b82f6; box-shadow: 0 6px 16px rgba(0, 0, 0, .35); transform: translateY(-1px); }
.pcard:active { cursor: grabbing; }
.pcard svg { width: 100%; height: 38px; pointer-events: none; }
.ptext { display: flex; flex-direction: column; align-items: center; line-height: 1.3; }
.pname { font-weight: 600; font-size: 12px; white-space: nowrap; }
.pblurb { font-size: 10.5px; color: var(--dim); white-space: nowrap; }
.pcard:last-child:nth-child(odd) { grid-column: 1 / -1; flex-direction: row; justify-content: center; gap: 10px; }
.pcard:last-child:nth-child(odd) svg { width: 76px; }
.pcard:last-child:nth-child(odd) .ptext { align-items: flex-start; }

.examples { display: grid; gap: 5px; }
.ex {
  display: flex; align-items: center; gap: 9px; height: 31px; padding: 0 10px; border-radius: 9px; text-align: left;
  border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; transition: background .15s, border-color .15s;
}
.ex:hover { border-color: var(--line-2); background: var(--card-2); }
.ex-name { flex: 1; font-weight: 600; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.ex .ic { width: 14px; height: 14px; color: var(--dim); }
.ex:hover .ic { color: var(--accent); }
.ex-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--accent); flex: none; }
.ex-series .ex-dot { background: #a78bfa; }
.ex-parallel .ex-dot { background: #fbbf24; }
.ex-ohm .ex-dot { background: #34d399; }
.ex-faulty .ex-dot { background: #fb923c; }
.ex-short .ex-dot { background: #f87171; }

.tips ul { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; color: var(--muted); font-size: 11.5px; }
.tips li { padding-left: 12px; position: relative; }
.tips li::before { content: ''; position: absolute; left: 0; top: 7px; width: 5px; height: 5px; border-radius: 50%; background: var(--accent); opacity: .7; }
.tips b { color: var(--text); font-weight: 600; }

/* ---------- Workspace ---------- */
.stage { position: relative; overflow: hidden; background: radial-gradient(1200px 800px at 50% 40%, #111b33 0%, #0b1224 60%, #090f1e 100%); }
#board { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; user-select: none; }
.toolbar {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); display: flex; align-items: center; gap: 2px;
  padding: 5px; border-radius: 14px; background: rgba(15, 22, 41, .93); border: 1px solid var(--line-2);
  box-shadow: 0 10px 30px rgba(0, 0, 0, .45); z-index: 4;
}
.toolbar .sep { width: 1px; height: 20px; background: var(--line-2); margin: 0 4px; }
.zoom-pct { min-width: 44px; text-align: center; font: 600 12px var(--mono); color: var(--muted); }
.status {
  position: absolute; right: 14px; top: 12px; display: flex; gap: 12px; padding: 6px 12px; border-radius: 999px;
  background: rgba(15, 22, 41, .88); border: 1px solid var(--line); color: var(--muted); font-size: 11.5px; z-index: 3; white-space: nowrap;
}
.status span { display: inline-flex; align-items: center; gap: 6px; }
.dot-c, .dot-l { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot-c { background: #fbbf24; box-shadow: 0 0 6px rgba(251, 191, 36, .7); }
.dot-l { border: 1.5px solid #cbd5e1; }
.empty-hint {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center;
  text-align: center; gap: 6px; width: 320px; color: var(--muted); pointer-events: none; padding: 24px;
  border: 1.5px dashed var(--line-2); border-radius: 18px; background: rgba(10, 15, 28, .6);
}
.empty-hint b { color: var(--text); font-size: 15px; }
.empty-art .ic { width: 38px; height: 38px; color: var(--accent); }

/* ---------- Right panel: the Start Test button ---------- */
.btn-test {
  position: relative; display: flex; align-items: center; justify-content: center; gap: 10px; width: 100%; height: 56px; flex: none;
  border: 0; border-radius: 14px; cursor: pointer; font-size: 17px; font-weight: 700; letter-spacing: .3px; color: #fff;
  background: linear-gradient(135deg, #10b981, #0ea5e9); overflow: hidden;
  box-shadow: 0 10px 24px rgba(14, 165, 233, .28), inset 0 1px 0 rgba(255, 255, 255, .25); transition: transform .12s, box-shadow .2s, filter .2s;
}
.btn-test:hover:not(:disabled) { transform: translateY(-1px); filter: brightness(1.06); box-shadow: 0 14px 30px rgba(14, 165, 233, .38), inset 0 1px 0 rgba(255, 255, 255, .25); }
.btn-test:active:not(:disabled) { transform: translateY(1px); }
.btn-test .bt-icon { width: 30px; height: 30px; border-radius: 50%; display: grid; place-items: center; background: rgba(255, 255, 255, .2); }
.btn-test .bt-icon .ic { width: 16px; height: 16px; margin-left: 2px; }
.btn-test kbd { position: absolute; right: 12px; background: rgba(0, 0, 0, .18); border-color: rgba(255, 255, 255, .25); color: #e0f2fe; }
.btn-test.testing { cursor: progress; }
.btn-test.testing::after {
  content: ''; position: absolute; inset: 0; background: linear-gradient(90deg, transparent, rgba(255, 255, 255, .35), transparent);
  animation: sweep .65s linear;
}
@keyframes sweep { from { transform: translateX(-100%); } to { transform: translateX(100%); } }
.auto { display: flex; align-items: center; gap: 8px; color: var(--muted); font-size: 12px; cursor: pointer; margin-top: -3px; }
.auto input { accent-color: #0ea5e9; width: 15px; height: 15px; margin: 0; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 6px; height: 32px; padding: 0 12px; border-radius: 9px; border: 1px solid var(--line-2);
  background: var(--card-2); color: var(--text); cursor: pointer; font-weight: 600; font-size: 12.5px; white-space: nowrap;
}
.btn .ic { width: 15px; height: 15px; }
.btn:hover:not(:disabled) { border-color: #475a85; background: #213055; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.sm { height: 28px; padding: 0 9px; font-size: 12px; }
.btn.primary { background: linear-gradient(135deg, #0ea5e9, #6366f1); border-color: transparent; color: #fff; }
.btn.primary:hover:not(:disabled) { filter: brightness(1.1); background: linear-gradient(135deg, #0ea5e9, #6366f1); }
.btn.danger { color: #fecaca; border-color: rgba(248, 113, 113, .35); background: rgba(248, 113, 113, .08); }
.btn.danger:hover { background: rgba(248, 113, 113, .18); border-color: rgba(248, 113, 113, .6); }
.link { background: none; border: 0; color: var(--accent); cursor: pointer; font-size: 12px; padding: 0; }

/* ---------- Test animation ---------- */
.scanline {
  position: absolute; top: 0; bottom: 0; width: 180px; left: -220px; pointer-events: none; opacity: 0; z-index: 2;
  background: linear-gradient(90deg, transparent, rgba(56, 189, 248, .12), rgba(56, 189, 248, .32), transparent);
}
.stage.scanning .scanline { animation: scan .65s ease-in-out; }
@keyframes scan { 0% { left: -220px; opacity: 1; } 100% { left: 100%; opacity: 1; } }
.stage.shake #board { animation: shake .45s; }
@keyframes shake {
  0%, 100% { transform: translate(0); } 20% { transform: translate(-6px, 2px); } 40% { transform: translate(5px, -2px); }
  60% { transform: translate(-4px, 1px); } 80% { transform: translate(3px, 0); }
}

/* ---------- Smaller screens ---------- */
@media (max-width: 1180px) { .stp-txt { display: none; } .stp-line { width: 14px; } }
@media (max-width: 1100px) { .brand-sub { display: none; } .brand { min-width: 0; } }
@media (max-height: 800px) { .tips { display: none; } .pcard svg { height: 34px; } }
