/* Web Labs styles. Same look as the Interactive Labs (dark by default), plus a light theme that
   follows the visitor's system setting. Self-contained: no external fonts, images, or imports. */

:root {
  --bg: #0d1117;
  --surface: #161b22;
  --border: #30363d;
  --text: #e6edf3;
  --muted: #8b949e;
  --accent: #58a6ff;
  --on-accent: #0d1117;
  --green: #3fb950;
  --yellow: #d29922;
  --red: #f85149;
  --purple: #bc8cff;
  --orange: #ffa657;
  --term-bg: #0a0e14;
  --term-text: #b3f7b3;
  --term-comment: #6e7681;
  --code-bg: rgba(255, 255, 255, 0.08);
  --hover-bg: rgba(255, 255, 255, 0.03);
  --active-bg: rgba(88, 166, 255, 0.08);
  --panel-bg: rgba(0, 0, 0, 0.2);
  --shadow: rgba(0, 0, 0, 0.5);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f6f8fa;
    --surface: #ffffff;
    --border: #d0d7de;
    --text: #1f2328;
    --muted: #59636e;
    --accent: #0969da;
    --on-accent: #ffffff;
    --green: #1a7f37;
    --yellow: #7d4e00;
    --red: #cf222e;
    --purple: #8250df;
    --orange: #953800;
    --term-bg: #ffffff;
    --term-text: #0a3069;
    --term-comment: #59636e;
    --code-bg: rgba(31, 35, 40, 0.07);
    --hover-bg: rgba(31, 35, 40, 0.04);
    --active-bg: rgba(9, 105, 218, 0.08);
    --panel-bg: rgba(31, 35, 40, 0.03);
    --shadow: rgba(31, 35, 40, 0.25);
    color-scheme: light;
  }
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  font-size: 15px;
  line-height: 1.5;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
a:focus-visible, button:focus-visible, summary:focus-visible, textarea:focus-visible, [tabindex]:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.skip-link { position: absolute; left: -999px; top: 0; background: var(--accent); color: var(--on-accent); padding: 0.4rem 0.8rem; z-index: 200; }
.skip-link:focus { left: 8px; top: 8px; }

/* NAV */
.nav {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.5rem;
  padding: 0.75rem 2rem;
  border-bottom: 1px solid var(--border);
  background: var(--surface);
  position: sticky;
  top: 0;
  z-index: 100;
}
.nav-brand { font-family: "Courier New", monospace; font-weight: 700; font-size: 1.1rem; color: var(--text); letter-spacing: -0.5px; }
.nav-brand span { color: var(--accent); }
.nav-brand:hover { text-decoration: none; }
.nav-links { display: flex; flex-wrap: wrap; gap: 0.25rem 1rem; margin-left: auto; }
.nav-links a { color: var(--muted); font-size: 0.875rem; }
.nav-links a:hover { color: var(--text); text-decoration: none; }
.nav-links a.active { color: var(--accent); }

/* LAB LAYOUT */
.lab-layout {
  display: grid;
  grid-template-columns: 340px minmax(0, 1fr);
  grid-template-rows: 100%;
  height: calc(100vh - 49px);
}
.sidebar { border-right: 1px solid var(--border); overflow-y: auto; display: flex; flex-direction: column; min-width: 0; }
.sidebar-header { padding: 1.25rem 1.5rem 1rem; border-bottom: 1px solid var(--border); }
.sidebar-header h1 { font-size: 1.1rem; font-weight: 600; margin-bottom: 0.25rem; }
.sidebar-header p { font-size: 0.8rem; color: var(--muted); }

.protocol-badge {
  display: inline-block;
  font-size: 0.7rem;
  font-weight: 600;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  margin-bottom: 0.5rem;
  font-family: "Courier New", monospace;
  letter-spacing: 0.05em;
  border: 1px solid var(--border);
  color: var(--accent);
}
.badge-html { color: var(--orange); border-color: var(--orange); }
.badge-css { color: var(--accent); border-color: var(--accent); }
.badge-js { color: var(--yellow); border-color: var(--yellow); }
.badge-play { color: var(--green); border-color: var(--green); }

.sim-note {
  margin-top: 0.6rem;
  padding: 0.4rem 0.6rem;
  border: 1px solid var(--yellow);
  border-radius: 6px;
  color: var(--yellow);
  font-size: 0.72rem;
  line-height: 1.4;
}

/* STEPS */
.steps { padding: 1rem 0; }
.step-item {
  display: flex;
  align-items: flex-start;
  gap: 0.75rem;
  padding: 0.65rem 1.5rem;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.step-item:hover { background: var(--hover-bg); }
.step-item.active { background: var(--active-bg); border-left-color: var(--accent); }
.step-item:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
.step-item.locked { opacity: 0.6; cursor: not-allowed; }
.step-item.locked .step-num { background: transparent; border: 1px solid var(--border); }
.step-num {
  flex-shrink: 0;
  width: 22px; height: 22px;
  border-radius: 50%;
  background: var(--border);
  color: var(--text);
  font-size: 0.7rem;
  font-weight: 600;
  display: flex; align-items: center; justify-content: center;
  margin-top: 1px;
}
.step-item.active .step-num { background: var(--accent); color: var(--on-accent); }
.step-item.done .step-num { background: var(--green); color: var(--on-accent); }
.step-info { flex: 1; min-width: 0; }
.step-title { font-size: 0.85rem; font-weight: 500; line-height: 1.3; }
.step-item:not(.active) .step-title { color: var(--muted); }
.step-desc { font-size: 0.75rem; color: var(--muted); margin-top: 0.1rem; }

/* INSTRUCTION PANEL */
.instruction-panel {
  padding: 1.25rem 1.5rem;
  border-top: 1px solid var(--border);
  background: var(--panel-bg);
  flex: 1 0 auto;
  min-height: 16rem;
}
.instruction-panel h2 { font-size: 0.95rem; font-weight: 600; margin-bottom: 0.6rem; color: var(--accent); }
.instruction-panel p { font-size: 0.82rem; color: var(--muted); line-height: 1.6; margin-bottom: 0.5rem; }
.instruction-panel ul, .instruction-panel ol { margin: 0.25rem 0 0.5rem 1.1rem; font-size: 0.82rem; color: var(--muted); line-height: 1.6; }
.instruction-panel code, .hint-label code {
  font-family: "Courier New", monospace;
  font-size: 0.8rem;
  background: var(--code-bg);
  padding: 0.1em 0.4em;
  border-radius: 3px;
  color: var(--orange);
}
.hint-label { font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; margin-bottom: 0.3rem; font-weight: 600; }
.takeaway { margin-top: 1rem; padding-top: 0.75rem; border-top: 1px solid var(--border); }
.continue-step {
  margin-top: 1rem;
  background: var(--accent);
  color: var(--on-accent);
  border: 0;
  border-radius: 6px;
  padding: 0.45rem 0.95rem;
  font: inherit;
  font-weight: 600;
  font-size: 0.8rem;
  cursor: pointer;
}
.continue-step:hover { filter: brightness(1.1); }

/* WORKSPACE */
.workspace { display: flex; flex-direction: column; background: var(--term-bg); min-width: 0; min-height: 0; }
.ws-toolbar {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.5rem;
  padding: 0.5rem 1rem;
  background: var(--hover-bg);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.ws-title { font-family: "Courier New", monospace; font-size: 0.75rem; color: var(--muted); }
.ws-actions { margin-left: auto; display: flex; gap: 0.5rem; flex-wrap: wrap; }
.btn-sm {
  font-size: 0.78rem;
  padding: 0.3rem 0.8rem;
  border-radius: 4px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-family: inherit;
  min-height: 30px;
}
.btn-sm:hover { border-color: var(--accent); color: var(--accent); }
.btn-sm.primary { border-color: var(--accent); background: var(--accent); color: var(--on-accent); font-weight: 600; }
.btn-sm.primary:hover { filter: brightness(1.1); color: var(--on-accent); }

.ws-split {
  flex: 1;
  min-height: 0;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  grid-auto-rows: minmax(0, 1fr);
}
.ws-split.three { grid-template-columns: minmax(0, 1fr) minmax(0, 1fr); grid-template-rows: minmax(0, 1fr) minmax(0, 1fr); }
.pane { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--border); }
.pane:last-child { border-right: 0; }
.pane-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 0.5rem;
  padding: 0.35rem 0.9rem;
  font-size: 0.72rem;
  color: var(--muted);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.pane-head label, .pane-head .pane-name { font-weight: 600; color: var(--text); text-transform: uppercase; letter-spacing: 0.06em; font-size: 0.7rem; }
.code-editor {
  flex: 1;
  min-height: 9rem;
  width: 100%;
  resize: none;
  border: 0;
  background: var(--term-bg);
  color: var(--text);
  font-family: "Courier New", Consolas, monospace;
  font-size: 0.85rem;
  line-height: 1.55;
  padding: 0.7rem 0.9rem;
  tab-size: 2;
  white-space: pre;
  overflow: auto;
}
.code-editor[readonly] { color: var(--muted); }
.editor-help { font-size: 0.7rem; color: var(--muted); padding: 0.25rem 0.9rem; border-top: 1px solid var(--border); flex-shrink: 0; }
.preview-frame { flex: 1; min-height: 9rem; width: 100%; border: 0; background: #ffffff; display: block; }
.ro-details { border-top: 1px solid var(--border); flex-shrink: 0; }
.ro-details summary { cursor: pointer; padding: 0.35rem 0.9rem; font-size: 0.72rem; color: var(--muted); }
.ro-details textarea { height: 9rem; min-height: 0; }

/* CHECKS */
.checks {
  flex-shrink: 0;
  max-height: 34%;
  overflow-y: auto;
  border-top: 1px solid var(--border);
  background: var(--panel-bg);
  padding: 0.55rem 1rem 0.65rem;
  font-size: 0.8rem;
}
.checks h2 { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--text); margin-bottom: 0.3rem; }
.check-summary { color: var(--muted); margin-bottom: 0.3rem; }
.check-summary.ok { color: var(--green); font-weight: 600; }
.check-list { list-style: none; }
.check-list li { display: flex; gap: 0.5rem; padding: 0.12rem 0; color: var(--muted); }
.check-list .mark { flex: 0 0 4.6rem; font-weight: 700; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.04em; }
.check-list li.met { color: var(--text); }
.check-list li.met .mark { color: var(--green); }
.check-list li.unmet .mark { color: var(--yellow); }
.check-list code { font-family: "Courier New", monospace; font-size: 0.76rem; background: var(--code-bg); padding: 0.05em 0.3em; border-radius: 3px; color: var(--orange); }
.notes { margin-top: 0.4rem; font-size: 0.75rem; color: var(--yellow); }

/* CONSOLE */
.console-out {
  flex: 1;
  min-height: 7rem;
  overflow: auto;
  padding: 0.6rem 0.9rem;
  font-family: "Courier New", Consolas, monospace;
  font-size: 0.82rem;
  line-height: 1.5;
  background: var(--term-bg);
}
.console-line { white-space: pre-wrap; overflow-wrap: anywhere; color: var(--term-text); }
.console-line.warn { color: var(--yellow); }
.console-line.error { color: var(--red); }
.console-line.system { color: var(--muted); font-style: italic; }
.console-line.info { color: var(--accent); }
.console-empty { color: var(--muted); font-style: italic; }

/* STATUS BAR */
.status-bar {
  display: flex; align-items: center; gap: 1rem; flex-wrap: wrap;
  padding: 0.3rem 1rem;
  font-size: 0.72rem;
  background: var(--panel-bg);
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-family: "Courier New", monospace;
  flex-shrink: 0;
}
.status-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--border); display: inline-block; margin-right: 0.3rem; }
.status-dot.ok { background: var(--green); }
.status-dot.wait { background: var(--yellow); }
.status-dot.err { background: var(--red); }
.progress-text { margin-left: auto; }

/* HUB PAGE */
.hero { padding: 4rem 1.5rem 2rem; text-align: center; max-width: 760px; margin: 0 auto; }
.hero h1 { font-size: 2.2rem; font-weight: 700; letter-spacing: -0.5px; margin-bottom: 1rem; line-height: 1.2; }
.hero h1 span { color: var(--accent); }
.hero p { color: var(--muted); font-size: 1.02rem; line-height: 1.7; margin-bottom: 1.5rem; }
.hero-badge-row { display: flex; justify-content: center; gap: 0.5rem; margin-bottom: 2rem; flex-wrap: wrap; }
.tag { font-family: "Courier New", monospace; font-size: 0.75rem; padding: 0.3rem 0.7rem; border-radius: 999px; border: 1px solid var(--border); color: var(--muted); }
.labs-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 1.25rem; max-width: 1100px; margin: 0 auto 3rem; padding: 0 1.5rem; }
.lab-card { background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 1.5rem; display: block; color: var(--text); }
.lab-card:hover { border-color: var(--accent); text-decoration: none; }
.lab-card-icon { font-size: 1.6rem; margin-bottom: 0.6rem; font-family: "Courier New", monospace; font-weight: 700; color: var(--accent); }
.lab-card h2 { font-size: 1rem; font-weight: 600; margin-bottom: 0.4rem; }
.lab-card p { font-size: 0.82rem; color: var(--muted); line-height: 1.5; margin-bottom: 0.9rem; }
.lab-card-meta { display: flex; gap: 0.75rem; font-size: 0.72rem; color: var(--muted); flex-wrap: wrap; }
.section-label { text-align: center; font-size: 0.75rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.1em; font-weight: 600; margin-bottom: 1.25rem; }
.safety { max-width: 760px; margin: 0 auto 3rem; padding: 0 1.5rem; }
.safety h2 { font-size: 1.05rem; margin-bottom: 0.6rem; }
.safety p, .safety li { color: var(--muted); font-size: 0.9rem; line-height: 1.65; }
.safety ul { margin: 0.4rem 0 0.8rem 1.2rem; }
.footer { border-top: 1px solid var(--border); padding: 1.5rem 1.5rem; text-align: center; font-size: 0.78rem; color: var(--muted); }
.footer a { color: var(--muted); text-decoration: underline; }
.footer a:hover { color: var(--accent); }

/* HINT CORNER (same as the Interactive Labs) */
.hint-corner {
  position: fixed;
  left: 16px;
  bottom: 16px;
  z-index: 60;
  width: min(380px, calc(100vw - 32px));
  max-height: 45vh;
  overflow-y: auto;
  background: var(--surface);
  border: 1px solid var(--accent);
  border-radius: 8px;
  padding: 0.65rem 0.85rem 0.75rem;
  box-shadow: 0 10px 28px var(--shadow);
  font-size: 0.82rem;
}
.hint-corner[hidden] { display: none; }
.hint-corner-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 0.35rem; }
.hint-corner-title { font-size: 0.7rem; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; color: var(--accent); }
.hint-corner-close { background: none; border: 0; color: var(--muted); font-size: 1.25rem; line-height: 1; cursor: pointer; padding: 0.1rem 0.4rem; }
.hint-corner-close:hover { color: var(--text); }
.hint-corner-body p { color: var(--text); line-height: 1.55; margin: 0 0 0.4rem; }
.hint-corner-body pre {
  background: var(--term-bg); border: 1px solid var(--border); border-radius: 6px; padding: 0.5rem 0.65rem;
  font-family: "Courier New", monospace; font-size: 0.78rem; color: var(--term-text); white-space: pre-wrap; overflow-wrap: anywhere;
}
.hint-corner-comment { color: var(--term-comment); }
.hint-corner-actions[hidden] { display: none; }

.visually-hidden { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* PHONE */
@media (max-width: 768px) {
  .nav { padding: 0.6rem 1rem; }
  .lab-layout { grid-template-columns: minmax(0, 1fr); grid-template-rows: auto auto; height: auto; }
  .sidebar { border-right: 0; border-bottom: 1px solid var(--border); overflow: visible; }
  .steps { max-height: 11rem; overflow-y: auto; padding: 0.5rem 0; }
  .step-desc { display: none; }
  .instruction-panel { min-height: 0; padding: 1rem; }
  .sidebar-header { padding: 1rem; }
  .step-item { padding: 0.5rem 1rem; }
  .ws-split, .ws-split.three { grid-template-columns: minmax(0, 1fr); grid-template-rows: none; grid-auto-rows: auto; }
  .pane { border-right: 0; border-bottom: 1px solid var(--border); }
  .code-editor { min-height: 12rem; }
  .preview-frame { min-height: 16rem; }
  .console-out { min-height: 9rem; max-height: 16rem; }
  .checks { max-height: none; }
  .hero h1 { font-size: 1.7rem; }
  .hero { padding-top: 2.5rem; }
}

/* PREVIEW HOST and PLAYGROUND STACKS */
.preview-host { display: flex; flex-direction: column; flex: 1; min-height: 0; }
.stack { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--border); }
.stack:last-child { border-right: 0; }
.stack > .pane { flex: 1 1 0; border-right: 0; border-bottom: 1px solid var(--border); }
.stack > .pane:last-child { border-bottom: 0; }
.stack .code-editor { min-height: 5rem; }
.measure-host { position: absolute; width: 0; height: 0; overflow: hidden; }
.play-notes { padding: 0.3rem 0.9rem; border-top: 1px solid var(--border); font-size: 0.75rem; color: var(--yellow); }
.play-notes p { margin: 0.1rem 0; }
@media (max-width: 768px) {
  .stack { border-right: 0; border-bottom: 1px solid var(--border); }
  .stack > .pane { flex: none; }
  .stack .code-editor { min-height: 9rem; }
}

/* PLAYGROUND PAGE */
.play-main { height: calc(100vh - 49px); }
.badge-flat { margin: 0; }
.play-help { padding: 0 0.9rem; }
.play-help ul { margin: 0.3rem 0 0.6rem 1.1rem; font-size: 0.8rem; color: var(--muted); line-height: 1.6; }
.noscript-note { padding: 1rem; }
@media (max-width: 768px) {
  .play-main { height: auto; }
}

/* Playground: Save panel */
.save-panel { margin: 0.75rem 1rem; padding: 0.9rem 1rem 0.8rem; border: 1px solid var(--border); border-radius: 8px; background: var(--panel-bg); }
.save-panel[hidden] { display: none; }
.save-panel h2 { font-size: 0.95rem; font-weight: 600; margin: 0 0 0.6rem; color: var(--text); }
.save-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem 0.75rem; margin-bottom: 0.6rem; }
.save-row label { font-size: 0.82rem; color: var(--text); font-weight: 600; }
.save-row input[type="text"] { min-width: 14rem; padding: 0.35rem 0.55rem; border: 1px solid var(--border); border-radius: 6px; background: var(--bg); color: var(--text); font: inherit; font-family: "Courier New", monospace; font-size: 0.85rem; }
.save-row input[type="text"]:disabled { opacity: 0.5; }
.save-hint { font-size: 0.75rem; color: var(--muted); }
.save-modes { border: 0; margin: 0 0 0.7rem; padding: 0; }
.save-modes legend { font-size: 0.82rem; font-weight: 600; color: var(--text); padding: 0; margin-bottom: 0.3rem; }
.save-modes label { display: block; font-size: 0.82rem; color: var(--text); margin-bottom: 0.25rem; }
.save-actions { display: flex; gap: 0.5rem; margin-bottom: 0.6rem; }
.save-note { font-size: 0.75rem; color: var(--muted); line-height: 1.55; margin: 0 0 0.4rem; max-width: 70ch; }
.save-msg { font-size: 0.82rem; color: var(--text); min-height: 1.2em; margin: 0; }

/* NAV GROUPS: one entry per lab group, with the group's labs in a menu that opens on hover or keyboard focus.
   The entry itself is a real link to the group, so touch screens and anyone without hover still get there. */
.nav-links { align-items: center; }
.nav-group { position: relative; }
.nav-group > a { color: var(--muted); font-size: 0.875rem; }
.nav-group > a:hover { color: var(--text); text-decoration: none; }
.nav-group.active > a { color: var(--accent); }
.nav-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: -0.75rem;
  min-width: 11rem;
  padding: 0.4rem;
  flex-direction: column;
  gap: 0.1rem;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: 0 8px 24px var(--shadow);
  z-index: 200;
}
.nav-group:focus-within > .nav-menu { display: flex; }
@media (hover: hover) { .nav-group:hover > .nav-menu { display: flex; } }
.nav-menu a { padding: 0.35rem 0.65rem; border-radius: 6px; white-space: nowrap; font-size: 0.85rem; }
.nav-menu a:hover, .nav-menu a:focus-visible { background: var(--hover-bg); color: var(--text); }
@media (max-width: 768px) {
  .nav-menu { display: none !important; }   /* phones: the entry links straight to the group */
}
