/* Dev Journey — lab player (full-window: top bar, machine left, guide right). */
:root {
  /* "B1 terminal": same palette as chrome.css */
  --lab-top: #0c0d10;
  --lab-top-text: #e8e4da;
  --lab-top-muted: #a9a59b;
  --lab-vm: #101114;
  --lab-vm-text: #e8e4da;
  --lab-term: #0a0b0d;
  --lab-guide: #15161a;
  --lab-guide-line: #2a2c33;
  --lab-line-strong: #3a3d46;
  --lab-raised: #1c1d22;
  --lab-text: #e8e4da;
  --lab-strong: #f4f1ea;
  --lab-muted: #a9a59b;
  --lab-faint: #8a867c;
  --lab-bubble: #1c1d22;
  --lab-accent: #f2b24a;
  --lab-accent-hover: #ffc56b;
  --lab-accent-ink: #101114;
  --lab-good: #8fd0c5;
  --lab-good-soft: rgba(143, 208, 197, 0.08);
  --lab-bad: #f2867a;
  --lab-bad-soft: rgba(242, 134, 122, 0.08);
  --lab-code: #0a0b0d;
  --lab-code-text: #d6d2c6;
  --lab-guide-width: clamp(340px, 30vw, 480px);
  --lab-font: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", "Helvetica Neue", sans-serif;
  --lab-mono: "JetBrains Mono", "JetBrainsMono Nerd Font", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body.lab-page {
  display: grid;
  grid-template-rows: 44px minmax(0, 1fr);
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--lab-vm);
  color: var(--lab-text);
  font-family: var(--lab-font);
}
[hidden] { display: none !important; }

/* ---------- top bar ---------- */
.lab-top {
  display: flex;
  align-items: center;
  gap: 0.6rem;
  padding: 0 0.9rem;
  background: var(--lab-top);
  color: var(--lab-top-text);
  font-size: 0.9rem;
  min-width: 0;
}
.lab-top-back { color: var(--lab-top-muted); text-decoration: none; font-size: 1.1rem; }
.lab-top-back:hover { color: var(--lab-top-text); }
.lab-top-course, .lab-top-sep { color: var(--lab-top-muted); white-space: nowrap; }
.lab-top-title { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; min-width: 0; }
.lab-top-spacer { flex: 1; }
.lab-top-btn {
  background: transparent; border: 1px solid var(--lab-line-strong); color: var(--lab-top-text);
  border-radius: 6px; width: 30px; height: 28px; cursor: pointer; font-size: 1rem;
}
.lab-top-btn:hover { border-color: var(--lab-top-muted); }
.lab-timer {
  font-family: var(--lab-mono); font-size: 1.05rem; font-weight: 600;
  padding-left: 0.6rem; border-left: 1px solid var(--lab-line-strong); letter-spacing: 0.02em;
}
.lab-timer.is-low { color: var(--lab-accent); }
.lab-kind {
  display: inline-block; font-size: 0.68rem; font-weight: 700; text-transform: uppercase;
  letter-spacing: 0.06em; padding: 0.12rem 0.45rem; border-radius: 4px; margin-right: 0.35rem;
  vertical-align: 0.1em;
}
.lab-kind-guided { background: rgba(143, 208, 197, 0.14); color: var(--lab-good); }
.lab-kind-challenge { background: rgba(242, 178, 74, 0.16); color: var(--lab-accent); }

/* ---------- main split ---------- */
.lab-main {
  display: grid;
  grid-template-columns: minmax(0, 1fr) var(--lab-guide-width);
  min-height: 0;
}

/* ---------- machine ---------- */
.lab-vm {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  background: var(--lab-vm);
  color: var(--lab-vm-text);
}
.lab-tabs { display: flex; gap: 2px; background: var(--lab-top); border-bottom: 1px solid var(--lab-guide-line); padding: 4px 6px 0; }
.lab-tab {
  background: transparent; color: var(--lab-top-muted); border: 0;
  padding: 0.4rem 0.9rem; font: inherit; font-size: 0.82rem; border-radius: 6px 6px 0 0; cursor: pointer;
}
.lab-tab.is-active { background: var(--lab-term); color: var(--lab-text); }
.lab-vm-frame { flex: 1; width: 100%; border: 0; background: var(--lab-term); }

.lab-vm-start, .lab-vm-boot, .lab-vm-ended {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1rem;
  padding: 2rem 1rem;
  text-align: center;
}
.lab-vm-start-text { margin: 0; font-size: 1rem; }
.lab-vm-thumb {
  position: relative;
  width: min(240px, 70%);
  aspect-ratio: 16 / 10;
  border: 1px solid var(--lab-line-strong);
  border-radius: 8px;
  background: var(--lab-guide);
  cursor: pointer;
  overflow: hidden;
  padding: 0;
  transition: transform 0.15s ease, box-shadow 0.15s ease;
}
.lab-vm-thumb:hover { transform: translateY(-2px); box-shadow: 0 10px 30px rgba(0, 0, 0, 0.35); }
.lab-vm-thumb:focus-visible { outline: 3px solid var(--lab-accent); outline-offset: 3px; }
.thumb-bar { position: absolute; left: 0; right: 0; bottom: 0; height: 12%; background: var(--lab-accent); }
.thumb-term {
  position: absolute; left: 12%; right: 12%; top: 16%; bottom: 22%;
  background: var(--lab-term); border-radius: 3px; border-top: 6px solid var(--lab-guide-line);
  color: var(--lab-good); font: 9px/1.4 var(--lab-mono); text-align: left; padding: 6px;
}
.thumb-term i { display: inline-block; width: 6px; height: 10px; background: var(--lab-accent); vertical-align: -1px; animation: lab-blink 1s steps(1) infinite; }
@keyframes lab-blink { 50% { opacity: 0; } }
.lab-vm-note { margin: 0; color: var(--lab-muted); font-size: 0.85rem; max-width: 26rem; min-height: 1.2em; }

.lab-sync { display: grid; gap: 0.7rem; width: min(22rem, 100%); font-size: 0.85rem; justify-items: center; }
.lab-sync p { margin: 0; color: var(--lab-muted); }
.lab-sync-code { width: 100%; text-align: left; color: var(--lab-muted); }
.lab-sync-code summary { cursor: pointer; text-align: center; }
.lab-sync-code label { display: block; margin: 0.6rem 0 0.3rem; }
.lab-sync-row { display: flex; gap: 0.4rem; }
.lab-sync input {
  flex: 1; min-width: 0; padding: 0.5rem 0.6rem; border-radius: 6px;
  border: 1px solid var(--lab-line-strong); background: var(--lab-term); color: var(--lab-text); font: 0.9rem var(--lab-mono);
}

.boot-brand { font-size: 1.4rem; font-weight: 700; letter-spacing: 0.02em; }
.boot-mark { font-family: var(--lab-mono); color: var(--lab-accent); }
.boot-sep { color: var(--lab-faint); font-weight: 400; margin: 0 0.4rem; }
.boot-bar { width: min(260px, 70%); height: 6px; background: var(--lab-guide-line); border-radius: 2px; overflow: hidden; }
.boot-bar span { display: block; height: 100%; width: 0; background: var(--lab-accent); transition: width 0.2s linear; }
.boot-lines { list-style: none; margin: 0; padding: 0; font: 0.82rem var(--lab-mono); color: var(--lab-muted); text-align: left; }
.boot-lines li { padding: 0.15rem 0 0.15rem 1.4rem; position: relative; }
.boot-lines li::before { content: "\00b7"; position: absolute; left: 0.3rem; color: var(--lab-faint); }
.boot-lines li.done::before { content: "\2713"; color: var(--lab-good); left: 0; }
.lab-vm-ended h2 { margin: 0; font-size: 1.2rem; }
.lab-vm-ended p { margin: 0; color: var(--lab-muted); max-width: 26rem; }

/* ---------- guide ---------- */
.lab-guide {
  display: flex;
  flex-direction: column;
  min-height: 0;
  background: var(--lab-guide);
  border-left: 1px solid var(--lab-guide-line);
}
.lab-guide-head {
  position: relative;
  display: flex; align-items: center; justify-content: space-between;
  padding: 0.6rem 0.9rem 0.4rem;
}
.lab-guide-name { font-weight: 700; font-size: 0.95rem; display: flex; align-items: center; gap: 0.4rem; }
.lab-guide-avatar {
  display: inline-grid; place-items: center; width: 22px; height: 22px; border-radius: 50%;
  background: var(--lab-accent); color: var(--lab-accent-ink); font: 700 9px/1 var(--lab-mono); border-radius: 3px;
}
.lab-guide-menu-btn { background: none; border: 0; font-size: 1.1rem; cursor: pointer; color: var(--lab-muted); padding: 0.2rem 0.4rem; border-radius: 6px; }
.lab-guide-menu-btn:hover { background: var(--lab-raised); color: var(--lab-text); }
.lab-steps-menu {
  position: absolute; z-index: 5; top: 100%; left: 0.6rem; right: 0.6rem;
  margin: 0; padding: 0.4rem; list-style: none; counter-reset: step;
  background: var(--lab-raised); border: 1px solid var(--lab-line-strong); border-radius: 6px;
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.5); max-height: 60vh; overflow: auto;
}
.lab-steps-menu button {
  width: 100%; text-align: left; background: none; border: 0; font: inherit; font-size: 0.88rem;
  padding: 0.45rem 0.6rem; border-radius: 6px; cursor: pointer; color: var(--lab-text);
}
.lab-steps-menu button:hover:not(:disabled) { background: var(--lab-guide); }
.lab-steps-menu button:disabled { color: var(--lab-faint); cursor: default; }
.lab-steps-menu button.is-done::after { content: " \2713"; color: var(--lab-good); }
.lab-steps-menu button.is-current { font-weight: 700; color: var(--lab-accent); }

.lab-progress { display: flex; gap: 4px; padding: 0 0.9rem 0.6rem; border-bottom: 1px solid var(--lab-guide-line); }
.lab-seg { flex: 1; height: 4px; border-radius: 1px; background: var(--lab-guide-line); }
.lab-seg.done { background: var(--lab-accent); }
.lab-seg.current { background: rgba(242, 178, 74, 0.45); }

.lab-chat {
  flex: 1;
  overflow-y: auto;
  padding: 0.9rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
  position: relative;
}
.lab-chat > * { flex-shrink: 0; }
.lab-msg { display: flex; flex-direction: column; gap: 0.3rem; max-width: 100%; }
.lab-msg-who { display: flex; align-items: center; gap: 0.35rem; font-size: 0.75rem; color: var(--lab-muted); }
.lab-msg.from-guide .lab-bubble {
  background: var(--lab-bubble); border: 1px solid var(--lab-guide-line); border-radius: 6px; padding: 0.15rem 1rem 0.8rem;
  font-size: 0.92rem; line-height: 1.6; overflow-wrap: anywhere;
}
.lab-msg.from-me { align-items: flex-end; }
.lab-msg.from-me .lab-bubble {
  /* the echo of a click: a quiet log line, not something that looks clickable */
  background: none; color: var(--lab-faint); border: 0; padding: 0; font: 0.78rem var(--lab-mono);
}
.lab-msg.from-me .lab-bubble::before { content: "› "; color: var(--lab-accent); }
.lab-bubble h2 { font-size: 1.15rem; margin: 0.8rem 0 0.4rem; color: var(--lab-strong); }
.lab-bubble h3 { font-size: 1rem; margin: 0.9rem 0 0.3rem; color: var(--lab-strong); }
.lab-bubble p { margin: 0.5rem 0; }
.lab-bubble ul, .lab-bubble ol { padding-left: 1.3rem; margin: 0.5rem 0; }
.lab-bubble li { margin: 0.2rem 0; }
.lab-bubble code { font-family: var(--lab-mono); font-size: 0.85em; background: var(--lab-term); color: var(--lab-accent); padding: 0.08rem 0.32rem; border-radius: 4px; }
.lab-bubble pre {
  position: relative; background: var(--lab-code); color: var(--lab-code-text);
  border: 1px solid var(--lab-guide-line); border-radius: 4px; padding: 0.75rem 3.6rem 0.75rem 0.9rem; overflow-x: auto; margin: 0.6rem 0;
}
.lab-bubble pre code { background: none; color: inherit; padding: 0; font-size: 0.82rem; }
.lab-copy {
  position: absolute; top: 6px; right: 6px; background: var(--lab-raised); color: var(--lab-muted); border: 1px solid var(--lab-line-strong);
  border-radius: 5px; font-size: 0.7rem; padding: 0.2rem 0.45rem; cursor: pointer; opacity: 0.75;
}
.lab-copy:hover { opacity: 1; }
.lab-bubble-actions { display: flex; justify-content: flex-end; margin-top: 0.4rem; }
.lab-thinking { color: var(--lab-muted); font-style: italic; }
.lab-ai-reply { white-space: pre-wrap; }

.lab-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 0.3rem;
  background: var(--lab-accent); color: var(--lab-accent-ink); border: 1px solid var(--lab-accent);
  border-radius: 4px; padding: 0.45rem 1rem; font: inherit; font-size: 0.88rem; font-weight: 600;
  cursor: pointer; text-decoration: none;
}
.lab-btn:hover { background: var(--lab-accent-hover); border-color: var(--lab-accent-hover); }
.lab-btn.ghost { background: transparent; color: var(--lab-text); border-color: var(--lab-line-strong); }
.lab-btn.ghost:hover { background: transparent; border-color: var(--lab-muted); }

/* Inspect Result card */
.lab-inspect {
  position: relative; overflow: hidden;
  border: 1px solid var(--lab-guide-line); border-radius: 6px; padding: 0.7rem 1rem 0.8rem;
  background: var(--lab-bubble); font-size: 0.88rem;
}
.lab-inspect.is-pass { border-color: rgba(143, 208, 197, 0.45); background: var(--lab-good-soft); }
.lab-inspect.is-fail { border-color: rgba(242, 134, 122, 0.45); background: var(--lab-bad-soft); }
.lab-inspect-head { font-weight: 700; font-size: 1rem; margin-bottom: 0.4rem; }
.lab-checks { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.35rem; }
.lab-checks li { position: relative; padding-left: 1.5rem; }
.lab-checks li::before { position: absolute; left: 0; top: 0; width: 1.1rem; text-align: center; }
.lab-checks li.ok { color: var(--lab-good); font-weight: 600; }
.lab-checks li.ok::before { content: "\2713"; }
.lab-checks li.bad { color: var(--lab-bad); font-weight: 600; }
.lab-checks li.bad::before { content: "\2717"; }
.lab-checks li.idle::before { content: "\25cb"; color: var(--lab-muted); }
.lab-checks li.run::before {
  content: ""; width: 0.8rem; height: 0.8rem; margin: 0.25rem 0.15rem; border-radius: 50%;
  border: 2px solid var(--lab-guide-line); border-top-color: var(--lab-accent); animation: lab-spin 0.8s linear infinite;
}
@keyframes lab-spin { to { transform: rotate(360deg); } }
.lab-check-why { display: block; font-weight: 400; color: var(--lab-muted); margin-top: 0.15rem; }
.lab-inspect-msg { margin: 0.5rem 0 0; color: var(--lab-muted); }
.lab-inspect-actions { display: flex; flex-wrap: wrap; gap: 0.4rem; justify-content: flex-end; margin-top: 0.7rem; }

.lab-done {
  border: 1px solid var(--lab-accent); background: rgba(242, 178, 74, 0.07); border-radius: 6px; padding: 0.9rem 1rem; text-align: center;
}
.lab-done-title { font-weight: 800; font-size: 1.1rem; }
.lab-done p { margin: 0.35rem 0; }
.lab-done-actions { display: grid; gap: 0.5rem; margin-top: 0.7rem; }
.lab-done-next { font-size: 0.8rem; color: var(--lab-muted); }

.lab-guide-foot { border-top: 1px solid var(--lab-guide-line); padding: 0.5rem 0.8rem; display: grid; gap: 0.5rem; }
.lab-foot-actions { display: flex; gap: 0.4rem; }
.lab-chip {
  background: var(--lab-raised); border: 1px solid var(--lab-guide-line); border-radius: 4px; padding: 0.3rem 0.8rem;
  font: inherit; font-size: 0.8rem; color: var(--lab-text); cursor: pointer;
}
.lab-chip:hover { border-color: var(--lab-line-strong); }
.lab-ask { display: flex; gap: 0.4rem; align-items: flex-end; }
.lab-ask textarea {
  flex: 1; min-width: 0; resize: vertical; font: inherit; font-size: 0.88rem; padding: 0.5rem 0.6rem;
  border: 1px solid var(--lab-line-strong); border-radius: 4px; background: var(--lab-term); color: var(--lab-text);
}

/* confetti */
.lab-confetti { position: absolute; inset: 0; pointer-events: none; overflow: hidden; }
.lab-confetti i {
  position: absolute; top: -10px; width: 7px; height: 11px; border-radius: 2px; opacity: 0.9;
  animation: lab-fall 1.6s ease-in forwards;
}
@keyframes lab-fall {
  to { transform: translate(var(--drift, 0), 260px) rotate(var(--spin, 360deg)); opacity: 0; }
}

/* modal */
.lab-modal {
  position: fixed; inset: 0; z-index: 50; display: grid; place-items: center; padding: 1rem;
  background: rgba(0, 0, 0, 0.6);
}
.lab-modal-card {
  position: relative; overflow: hidden; width: min(28rem, 100%); background: var(--lab-guide); color: var(--lab-text);
  border: 1px solid var(--lab-line-strong); border-radius: 8px; box-shadow: 0 25px 60px rgba(0, 0, 0, 0.35);
}
.lab-modal-x {
  position: absolute; top: 0.5rem; right: 0.6rem; z-index: 2; background: none; border: 0;
  font-size: 1.5rem; line-height: 1; color: inherit; cursor: pointer; opacity: 0.8;
}
.lab-congrats-top { background: var(--lab-accent); color: var(--lab-accent-ink); text-align: center; padding: 1.4rem 1.2rem 1.1rem; }
.lab-congrats-top h2 { margin: 0.2rem 0; font-size: 1.6rem; }
.lab-congrats-top p { margin: 0.25rem 0; }
.lab-congrats-icon { font-size: 2.4rem; }
.lab-streak { font-weight: 700; }
.lab-congrats-body { text-align: center; padding: 1rem 1.2rem 1.3rem; }
.lab-congrats-body p { margin: 0 0 0.6rem; font-weight: 600; }
.lab-rating { display: flex; justify-content: center; gap: 0.8rem; margin-bottom: 1rem; }
.lab-rating button {
  font-size: 1.7rem; background: none; border: 2px solid transparent; border-radius: 50%;
  width: 3rem; height: 3rem; cursor: pointer; filter: grayscale(0.5);
}
.lab-rating button:hover, .lab-rating button.is-picked { filter: none; border-color: var(--lab-accent); background: rgba(242, 178, 74, 0.1); }
.lab-modal-actions { display: flex; justify-content: center; gap: 0.5rem; flex-wrap: wrap; }
.lab-limit { padding: 1.5rem 1.4rem 1.3rem; }
.lab-limit h2 { margin: 0 2rem 0.6rem 0; font-size: 1.25rem; }
.lab-limit p { margin: 0 0 0.6rem; color: var(--lab-muted); line-height: 1.55; }
.lab-limit .lab-modal-actions { justify-content: flex-end; margin-top: 1rem; }

/* narrow screens: machine on top, guide underneath */
@media (max-width: 900px) {
  body.lab-page { height: auto; overflow: auto; grid-template-rows: 44px auto; }
  .lab-main { grid-template-columns: 1fr; }
  .lab-vm { height: 60vh; }
  .lab-guide { border-left: 0; height: 80vh; }
  .lab-top-course, .lab-top-sep { display: none; }
}

/* Quick recall: fold-out answers (docs/courses/standard.md rule 6) */
.lab-bubble details { margin: 0.4rem 0; border: 1px solid var(--lab-guide-line); border-radius: 4px; padding: 0.4rem 0.7rem; background: var(--lab-term); }
.lab-bubble summary { cursor: pointer; color: var(--lab-text); }
.lab-bubble summary:hover { color: var(--lab-accent); }
.lab-bubble details[open] { color: var(--lab-good); }
.lab-bubble details[open] summary { margin-bottom: 0.35rem; color: var(--lab-muted); }
