/* ==========================================================
   AI 演算法課程 · Lab design system (ai.willngo.com/lab/lab.css)
   One look for all 19 lessons: dark lab, lime action, calm data colours.
   ========================================================== */
@import url("https://fonts.googleapis.com/css2?family=JetBrains+Mono:wght@400;500;600&family=Noto+Sans+TC:wght@400;500;700;900&family=Space+Grotesk:wght@500;600;700&display=swap");

:root {
  --bg: #050806;
  --bg-2: #070d09;
  --surface: #0b120d;
  --surface-2: #0f1812;
  --surface-3: #142017;
  --line: rgba(255, 255, 255, 0.08);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #eef5ee;
  --muted: #94a795;
  --dim: #5d6d5f;

  --lime: #9eff57;
  --lime-2: #c6ff8f;
  --lime-soft: rgba(158, 255, 87, 0.12);
  --gold: #C9A96B;

  /* data colours — fixed meaning across every lesson */
  --c-pos: #ff6b8b;   /* class A / risk / default / fraud */
  --c-neg: #47d4ff;   /* class B / safe / normal */
  --c-new: #ffc857;   /* synthetic, pseudo-labelled, newly added */
  --c-alt: #b494ff;   /* third series */
  --c-ink: rgba(238, 245, 238, 0.55); /* unlabelled / neutral */

  --sans: "Noto Sans TC", "PingFang TC", "Microsoft JhengHei", system-ui, sans-serif;
  --num: "Space Grotesk", "Noto Sans TC", sans-serif;
  --mono: "JetBrains Mono", ui-monospace, Menlo, monospace;
  --ease: cubic-bezier(.16, 1, .3, 1);
  --r: 18px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html { -webkit-text-size-adjust: 100%; }
body.lab {
  min-height: 100vh; font-family: var(--sans); color: var(--text); line-height: 1.6;
  background:
    radial-gradient(1000px 520px at 90% -12%, rgba(158, 255, 87, .09), transparent 60%),
    radial-gradient(800px 500px at -10% 30%, rgba(71, 212, 255, .05), transparent 60%),
    var(--bg);
  -webkit-font-smoothing: antialiased; overflow-x: clip;
}
/* resets use :where() so they never out-rank component classes */
:where(.lab) a { color: inherit; }
:where(.lab) :is(button, input, select, textarea) { font: inherit; color: inherit; }
:where(.lab) button { cursor: pointer; border: 0; background: none; }
.lab [hidden] { display: none !important; }
.lab :focus-visible { outline: 2px solid var(--lime); outline-offset: 2px; border-radius: 8px; }
.lab ::selection { background: var(--lime); color: #071006; }

.lab-wrap { max-width: 1320px; margin: 0 auto; padding: 0 clamp(16px, 3vw, 36px); }

/* ---------- head ---------- */
.lab-head { padding: clamp(28px, 4vw, 52px) 0 clamp(20px, 2.6vw, 30px); display: flex; justify-content: space-between; align-items: flex-end; gap: 24px; }
.lab-kicker { display: flex; align-items: center; gap: 12px; font-family: var(--mono); font-size: 12px; letter-spacing: .14em; color: var(--muted); }
.lab-kicker b { font-family: var(--num); font-weight: 700; font-size: 13px; color: #071006; background: var(--lime); padding: 3px 9px; border-radius: 7px; letter-spacing: .04em; }
.lab-title { margin-top: 14px; font-weight: 900; font-size: clamp(30px, 4vw, 52px); line-height: 1.12; letter-spacing: -.01em; }
.lab-title em { font-style: normal; color: var(--lime); }
.lab-goal { margin-top: 12px; font-size: clamp(15px, 1.25vw, 17px); color: var(--muted); max-width: 640px; }
.lab-head__side { display: flex; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }

/* ---------- main grid ---------- */
.lab-main { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; align-items: start; }
.lab-main--wide { grid-template-columns: minmax(0, 1fr) 380px; }
.lab-main--full { grid-template-columns: minmax(0, 1fr); }

/* ---------- stage (the big interactive area) ---------- */
.stage { position: relative; border-radius: var(--r); background: linear-gradient(180deg, var(--surface), var(--bg-2)); border: 1px solid var(--line); overflow: hidden; }
.stage__bar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 12px 14px 12px 18px; border-bottom: 1px solid var(--line); min-height: 52px; flex-wrap: wrap; }
.stage__title { font-size: 13px; font-weight: 700; color: var(--text); display: flex; align-items: center; gap: 10px; }
.stage__title small { font-family: var(--mono); font-size: 11px; font-weight: 400; color: var(--dim); letter-spacing: .06em; }
.stage__tools { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.stage__canvas { position: relative; height: clamp(360px, 62vh, 600px); touch-action: none; }
.stage__canvas--short { height: clamp(300px, 48vh, 460px); }
.stage__canvas canvas, .stage__canvas svg.fill { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.stage__hint {
  position: absolute; left: 14px; bottom: 14px; z-index: 2; pointer-events: none;
  display: inline-flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px;
  font-size: 12.5px; color: var(--text); background: rgba(5, 8, 6, .72); border: 1px solid var(--line-2);
  -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px); transition: opacity .4s;
}
.stage__hint::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--lime); box-shadow: 0 0 10px var(--lime); }
.stage__hint.is-gone { opacity: 0; }
.stage__corner { position: absolute; right: 14px; top: 14px; z-index: 2; }
.stage__split { display: grid; grid-template-columns: 1fr 1fr; }
.stage__split > * + * { border-left: 1px solid var(--line); }
.stage__foot { border-top: 1px solid var(--line); padding: 14px 18px; }

/* ---------- legend chips ---------- */
.legend { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { display: inline-flex; align-items: center; gap: 7px; height: 28px; padding: 0 11px; border-radius: 999px; font-size: 12.5px; color: var(--muted); border: 1px solid var(--line); background: rgba(255, 255, 255, .02); white-space: nowrap; }
.chip i { width: 9px; height: 9px; border-radius: 50%; background: currentColor; flex: none; }
.chip i.sq { border-radius: 2px; }
.chip i.ring { background: transparent; border: 2px solid currentColor; }
.chip i.dash { width: 14px; height: 0; border-radius: 0; border-top: 2px dashed currentColor; background: none; }

/* ---------- panel ---------- */
.panel { display: grid; gap: 12px; }
.card { border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); padding: 16px 18px; }
.card__title { display: flex; justify-content: space-between; align-items: center; gap: 10px; font-size: 12px; font-family: var(--mono); letter-spacing: .12em; color: var(--muted); text-transform: uppercase; margin-bottom: 14px; }
.card__title b { color: var(--text); font-family: var(--sans); font-size: 14px; letter-spacing: 0; text-transform: none; font-weight: 700; }
.stack { display: grid; gap: 14px; }

/* slider */
.ctl { display: grid; gap: 8px; }
.ctl__row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; font-size: 13.5px; }
.ctl__row label { color: var(--text); }
.ctl__row output { font-family: var(--mono); font-size: 13px; color: var(--lime-2); min-width: 3ch; text-align: right; }
.ctl__note { font-size: 12px; color: var(--dim); }
input[type="range"] { -webkit-appearance: none; appearance: none; width: 100%; height: 22px; background: transparent; cursor: pointer; --p: 50%; }
input[type="range"]::-webkit-slider-runnable-track { height: 4px; border-radius: 4px; background: linear-gradient(90deg, var(--lime) 0 var(--p), rgba(255, 255, 255, .12) var(--p) 100%); }
input[type="range"]::-moz-range-track { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .12); }
input[type="range"]::-moz-range-progress { height: 4px; border-radius: 4px; background: var(--lime); }
input[type="range"]::-webkit-slider-thumb { -webkit-appearance: none; width: 18px; height: 18px; margin-top: -7px; border-radius: 50%; background: #fff; border: 4px solid var(--lime); box-shadow: 0 0 0 4px rgba(158, 255, 87, .12); transition: transform .2s var(--ease); }
input[type="range"]::-moz-range-thumb { width: 12px; height: 12px; border-radius: 50%; background: #fff; border: 4px solid var(--lime); }
input[type="range"]:active::-webkit-slider-thumb { transform: scale(1.18); }

/* segmented control */
.seg { display: flex; padding: 3px; gap: 3px; border-radius: 12px; background: rgba(255, 255, 255, .04); border: 1px solid var(--line); }
.seg button { flex: 1; min-height: 34px; padding: 0 10px; border-radius: 9px; font-size: 13px; color: var(--muted); transition: background .25s, color .25s; white-space: nowrap; }
.seg button:hover { color: var(--text); }
.seg button[aria-pressed="true"] { background: var(--lime); color: #071006; font-weight: 700; }
.seg--sm button { min-height: 28px; font-size: 12px; padding: 0 9px; }

/* buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 38px; padding: 0 16px; border-radius: 11px; font-size: 13.5px; font-weight: 700; transition: transform .3s var(--ease), background .25s, border-color .25s, color .25s, box-shadow .3s; white-space: nowrap; }
.btn svg { width: 15px; height: 15px; }
.btn--primary { background: var(--lime); color: #071006; box-shadow: 0 8px 26px -10px rgba(158, 255, 87, .7); }
.btn--primary:hover { transform: translateY(-1px); box-shadow: 0 12px 30px -10px rgba(158, 255, 87, .9); }
.btn--ghost { border: 1px solid var(--line-2); color: var(--text); background: rgba(255, 255, 255, .02); }
.btn--ghost:hover { border-color: var(--lime); color: var(--lime-2); }
.btn--icon { width: 38px; padding: 0; }
.btn--sm { min-height: 30px; padding: 0 11px; font-size: 12.5px; border-radius: 9px; }
.btn[disabled] { opacity: .35; pointer-events: none; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row > .btn { flex: 1; }

/* switch */
.switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; font-size: 13.5px; cursor: pointer; user-select: none; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch span.track { position: relative; width: 38px; height: 22px; border-radius: 999px; background: rgba(255, 255, 255, .14); transition: background .25s; flex: none; }
.switch span.track::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; border-radius: 50%; background: #fff; transition: transform .3s var(--ease); }
.switch input:checked + span.track { background: var(--lime); }
.switch input:checked + span.track::after { transform: translateX(16px); }
.switch input:focus-visible + span.track { outline: 2px solid var(--lime); outline-offset: 2px; }

/* metrics */
.metrics { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
.metrics--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.metric { padding: 12px 12px 11px; border-radius: 13px; background: rgba(255, 255, 255, .025); border: 1px solid var(--line); min-width: 0; }
.metric__label { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.metric__value { margin-top: 4px; font-family: var(--num); font-weight: 700; font-size: 22px; line-height: 1.1; font-variant-numeric: tabular-nums; white-space: nowrap; }
.metric__value small { font-size: 12px; font-weight: 500; color: var(--muted); margin-left: 3px; }
.metric--hl { border-color: rgba(158, 255, 87, .35); background: var(--lime-soft); }
.metric--hl .metric__value { color: var(--lime-2); }
.metric--pos .metric__value { color: var(--c-pos); }
.metric--neg .metric__value { color: var(--c-neg); }
.bar { height: 6px; border-radius: 6px; background: rgba(255, 255, 255, .08); overflow: hidden; margin-top: 8px; }
.bar > i { display: block; height: 100%; width: 0; background: var(--lime); border-radius: inherit; transition: width .45s var(--ease); }

/* verdict / callout inside panel */
.verdict { display: flex; align-items: center; gap: 10px; padding: 12px 14px; border-radius: 13px; font-weight: 700; font-size: 15px; border: 1px solid var(--line-2); }
.verdict i { width: 10px; height: 10px; border-radius: 50%; background: currentColor; box-shadow: 0 0 12px currentColor; }
.verdict--pos { color: var(--c-pos); background: rgba(255, 107, 139, .08); border-color: rgba(255, 107, 139, .35); }
.verdict--neg { color: var(--c-neg); background: rgba(71, 212, 255, .08); border-color: rgba(71, 212, 255, .35); }
.verdict--lime { color: var(--lime-2); background: var(--lime-soft); border-color: rgba(158, 255, 87, .35); }

/* ---------- missions ---------- */
.lab-foot { display: grid; grid-template-columns: minmax(0, 1fr) 340px; gap: 16px; margin-top: 16px; padding-bottom: clamp(40px, 6vw, 72px); }
.lab-foot--wide { grid-template-columns: minmax(0, 1fr) 380px; }
.missions { border-radius: var(--r); background: var(--surface); border: 1px solid var(--line); padding: 16px 18px 18px; }
.missions__head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 12px; }
.missions__head span { font-family: var(--mono); font-size: 12px; letter-spacing: .12em; color: var(--muted); }
.missions__head b { font-family: var(--num); font-size: 14px; color: var(--lime-2); }
.missions__list { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.mission { position: relative; display: flex; gap: 12px; align-items: flex-start; padding: 13px 14px; border-radius: 13px; border: 1px solid var(--line); background: rgba(255, 255, 255, .02); transition: border-color .4s, background .4s; }
.mission__n { flex: none; width: 26px; height: 26px; border-radius: 50%; display: grid; place-items: center; font-family: var(--num); font-weight: 700; font-size: 13px; color: var(--muted); border: 1px solid var(--line-2); transition: background .4s, color .4s, border-color .4s; }
.mission__t { font-size: 14px; line-height: 1.55; }
.mission.is-done { border-color: rgba(158, 255, 87, .45); background: var(--lime-soft); }
.mission.is-done .mission__n { background: var(--lime); color: #071006; border-color: var(--lime); font-size: 0; }
.mission.is-done .mission__n::after { content: ""; width: 10px; height: 6px; border-left: 2px solid #071006; border-bottom: 2px solid #071006; transform: translateY(-2px) rotate(-45deg); }
.mission.just-done { animation: pop .7s var(--ease); }
@keyframes pop { 30% { transform: scale(1.03); } }

.insight { border-radius: var(--r); padding: 18px 20px; border: 1px solid rgba(201, 169, 107, .3); background: linear-gradient(160deg, rgba(201, 169, 107, .1), rgba(201, 169, 107, .02)); display: flex; flex-direction: column; justify-content: center; gap: 10px; }
.insight span { font-family: var(--mono); font-size: 11.5px; letter-spacing: .14em; color: var(--gold); }
.insight p { font-size: 16px; font-weight: 700; line-height: 1.7; }
.formula { font-family: var(--mono); font-size: 13px; color: var(--lime-2); padding: 10px 12px; border-radius: 10px; background: rgba(0, 0, 0, .25); border: 1px solid var(--line); overflow-x: auto; white-space: nowrap; }

/* ---------- toast ---------- */
.lab-toast { position: fixed; left: 50%; bottom: 28px; z-index: 100; transform: translate(-50%, 16px); opacity: 0; pointer-events: none; padding: 11px 18px; border-radius: 999px; background: var(--lime); color: #071006; font-weight: 700; font-size: 14px; box-shadow: 0 18px 40px -14px rgba(158, 255, 87, .7); transition: opacity .3s, transform .5s var(--ease); }
.lab-toast.is-on { opacity: 1; transform: translate(-50%, 0); }

/* ---------- small helpers ---------- */
.mono { font-family: var(--mono); }
.num { font-family: var(--num); font-variant-numeric: tabular-nums; }
.muted { color: var(--muted); }
.pos { color: var(--c-pos); } .neg { color: var(--c-neg); } .new { color: var(--c-new); } .lime { color: var(--lime-2); }
.sr-only { position: absolute !important; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.mini { position: relative; height: 150px; }
.mini canvas { position: absolute; inset: 0; width: 100%; height: 100%; }

/* ---------- responsive ---------- */
@media (max-width: 1080px) {
  .lab-main, .lab-main--wide, .lab-foot, .lab-foot--wide { grid-template-columns: minmax(0, 1fr); }
  .panel { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 720px) {
  .lab-head { flex-direction: column; align-items: flex-start; }
  .panel { grid-template-columns: minmax(0, 1fr); }
  .stage__canvas { height: clamp(320px, 58vh, 460px); }
  .stage__split { grid-template-columns: 1fr; }
  .stage__split > * + * { border-left: 0; border-top: 1px solid var(--line); }
  .missions__list { grid-template-columns: 1fr; }
  .metrics--3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .metric__value { font-size: 19px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .001ms !important; transition-duration: .001ms !important; }
}
