:root {
  color-scheme: dark;
  --bg: #090d16;
  --surface: #0f1522;
  --surface-2: #141c2c;
  --surface-3: #192337;
  --border: #263249;
  --border-soft: #1e293c;
  --text: #e8edf7;
  --muted: #8d9ab0;
  --faint: #647189;
  --blue: #5b9cff;
  --blue-strong: #397ee8;
  --green: #3ddc97;
  --red: #ff6b7a;
  --amber: #f4b95f;
  --mono: "SFMono-Regular", Consolas, "Liberation Mono", Menlo, monospace;
  --sans: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #f3f6fb;
  --surface: #ffffff;
  --surface-2: #f5f7fb;
  --surface-3: #e9eef7;
  --border: #d6deeb;
  --border-soft: #e3e8f1;
  --text: #172033;
  --muted: #59677c;
  --faint: #7b879a;
  --blue: #2768d7;
  --blue-strong: #2463c7;
  --green: #159b68;
  --red: #d14352;
  --amber: #b87811;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body { height: 100%; }

body {
  margin: 0;
  overflow: hidden;
  color: var(--text);
  background: var(--bg);
  font-family: var(--sans);
  font-size: 16px;
}

button, textarea { font: inherit; }
button { color: inherit; }

.app-shell { height: 100vh; display: flex; flex-direction: column; }

.topbar {
  height: 62px;
  flex: 0 0 62px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 24px;
  padding: 0 18px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(9, 13, 22, 0.96);
}

.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-button { padding: 0; border: 0; background: transparent; color: inherit; text-align: left; cursor: pointer; }
.brand-mark {
  width: 34px; height: 34px; display: grid; place-items: center;
  border-radius: 9px; background: linear-gradient(145deg, #67a6ff, #326fd7);
  color: white; font-weight: 850; box-shadow: 0 8px 28px rgba(57,126,232,.28);
}
.brand-name { font-weight: 750; letter-spacing: -0.02em; }
.brand-tag { color: var(--muted); font-size: 13px; padding-left: 10px; border-left: 1px solid var(--border); }

.top-progress { min-width: 260px; display: flex; align-items: center; gap: 12px; }
.progress-copy { display: flex; align-items: baseline; gap: 7px; white-space: nowrap; }
.progress-copy span { font-weight: 700; font-variant-numeric: tabular-nums; }
.progress-copy small { color: var(--muted); }
.progress-track { width: 128px; height: 7px; border-radius: 99px; overflow: hidden; background: var(--surface-3); }
.progress-track span { display: block; height: 100%; width: 0; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--green)); transition: width .3s ease; }
.top-actions { justify-self: end; display: flex; align-items: center; gap: 8px; }
.top-center { display: flex; align-items: center; gap: 20px; }
.mode-switch { display: flex; padding: 3px; border: 1px solid var(--border); border-radius: 9px; background: var(--surface-2); }
.mode-switch button { padding: 6px 11px; border: 0; border-radius: 6px; background: transparent; color: var(--muted); cursor: pointer; font-size: 13px; font-weight: 650; }
.mode-switch button.active { color: var(--text); background: var(--surface); box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.theme-button { width: 37px; height: 37px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 17px; }
.theme-button:hover { color: var(--text); background: var(--surface-3); }
.training-button { padding: 9px 12px; border: 1px solid rgba(61,220,151,.34); border-radius: 8px; background: rgba(61,220,151,.1); color: var(--green); font-weight: 720; cursor: pointer; }
.training-button.locked { border-color: var(--border); background: var(--surface-2); color: var(--faint); }

/* Algorithm library — quiet, spacious, macOS-inspired working surface. */
.library-view { height: 100vh; min-height: 0; overflow-x: hidden; overflow-y: auto; overscroll-behavior-y: contain; -webkit-overflow-scrolling: touch; color: var(--text); background: radial-gradient(circle at 12% -8%, rgba(70,129,255,.13), transparent 28rem), radial-gradient(circle at 88% 18%, rgba(88,205,166,.09), transparent 25rem), var(--bg); }
.library-nav { position: sticky; top: 0; z-index: 10; height: 72px; display: flex; align-items: center; justify-content: space-between; padding: 0 clamp(22px, 5vw, 72px); border-bottom: 1px solid color-mix(in srgb, var(--border-soft) 76%, transparent); background: color-mix(in srgb, var(--bg) 78%, transparent); backdrop-filter: saturate(170%) blur(22px); -webkit-backdrop-filter: saturate(170%) blur(22px); }
.library-brand { display: flex; align-items: center; gap: 11px; font-size: 17px; font-weight: 760; letter-spacing: -.02em; }
.library-brand .brand-mark { width: 32px; height: 32px; border-radius: 9px; }
.library-nav-actions { display: flex; align-items: center; gap: 13px; }
.account-button { height: 37px; display: inline-flex; align-items: center; gap: 8px; padding: 0 12px; border: 1px solid var(--border); border-radius: 10px; color: var(--muted); background: color-mix(in srgb, var(--surface-2) 88%, transparent); cursor: pointer; font-size: 13px; font-weight: 650; }
.account-button:hover { color: var(--text); border-color: color-mix(in srgb, var(--blue) 55%, var(--border)); }
.account-avatar { width: 20px; height: 20px; display: grid; place-items: center; border-radius: 50%; color: white; background: linear-gradient(145deg, #67a6ff, #326fd7); font-size: 12px; font-weight: 800; }
.account-button.signed-in .account-avatar { background: linear-gradient(145deg, #48d99b, #168b62); }
.library-status { color: var(--faint); font-size: 13px; }
.library-content { width: min(1180px, calc(100% - 44px)); margin: 0 auto; padding: clamp(64px, 9vw, 112px) 0 70px; }
.library-intro { max-width: 720px; }
.library-eyebrow { color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .14em; }
.library-intro h1 { margin: 12px 0 13px; font-size: clamp(43px, 7vw, 72px); line-height: 1; letter-spacing: -.065em; }
.library-intro p { max-width: 660px; margin: 0; color: var(--muted); font-size: 17px; line-height: 1.75; }
.library-summary { width: min(610px, 100%); display: grid; grid-template-columns: repeat(3, 1fr); margin: 44px 0 70px; padding: 17px 0; border-top: 1px solid var(--border); border-bottom: 1px solid var(--border); }
.library-summary div { padding: 3px 24px; border-right: 1px solid var(--border); }
.library-summary div:first-child { padding-left: 0; }
.library-summary div:last-child { border: 0; }
.library-summary strong { display: block; margin-bottom: 3px; font-size: 25px; letter-spacing: -.035em; }
.library-summary span { color: var(--faint); font-size: 13px; }
.algorithm-section { margin-top: 10px; }
.section-heading-row { display: flex; align-items: end; justify-content: space-between; margin-bottom: 22px; }
.section-heading-row > div { display: flex; align-items: baseline; gap: 12px; }
.section-heading-row h2 { margin: 0; font-size: 24px; letter-spacing: -.035em; }
.section-heading-row > span { color: var(--faint); font-size: 13px; }
.section-index { color: var(--blue); font-family: var(--mono); font-size: 12px; font-weight: 750; }
.algorithm-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.algorithm-card { min-height: 260px; padding: 24px; border: 1px solid var(--border); border-radius: 20px; color: var(--text); background: color-mix(in srgb, var(--surface) 91%, transparent); box-shadow: 0 14px 42px rgba(0,0,0,.055); text-align: left; }
button.algorithm-card { font: inherit; }
.active-algorithm { grid-row: span 2; min-height: 536px; display: flex; flex-direction: column; border-color: color-mix(in srgb, var(--blue) 43%, var(--border)); background: linear-gradient(145deg, color-mix(in srgb, var(--surface) 96%, var(--blue)), var(--surface)); cursor: pointer; transition: transform .22s ease, border-color .22s ease, box-shadow .22s ease; }
.active-algorithm:hover { transform: translateY(-3px); border-color: var(--blue); box-shadow: 0 24px 60px rgba(26,75,150,.15); }
.algorithm-card-top { display: flex; justify-content: space-between; align-items: start; margin-bottom: 29px; }
.algorithm-icon { width: 48px; height: 48px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 13px; color: var(--muted); background: var(--surface-2); font-family: Georgia, serif; font-size: 21px; font-weight: 700; }
.ppo-icon { width: 64px; height: 64px; border: 0; border-radius: 17px; color: white; background: linear-gradient(145deg, #5c9dff, #315fcd); box-shadow: 0 12px 30px rgba(49,95,205,.25); font-size: 35px; }
.available-pill, .locked-pill { padding: 6px 9px; border-radius: 99px; font-size: 12px; font-weight: 700; }
.available-pill { color: var(--green); background: rgba(61,220,151,.11); }
.locked-pill { color: var(--faint); background: var(--surface-2); }
.algorithm-order { color: var(--faint); font-size: 12px; font-weight: 700; letter-spacing: .06em; text-transform: uppercase; }
.algorithm-card h3 { margin: 10px 0; font-size: 22px; letter-spacing: -.035em; }
.active-algorithm h3 { max-width: 420px; margin-top: 15px; font-size: clamp(27px, 3vw, 38px); line-height: 1.12; }
.algorithm-card p { margin: 0; color: var(--muted); line-height: 1.65; }
.algorithm-meta { display: flex; flex-wrap: wrap; gap: 7px 19px; margin-top: auto; padding-top: 36px; color: var(--faint); font-size: 13px; }
.algorithm-progress { height: 6px; margin: 17px 0 12px; overflow: hidden; border-radius: 99px; background: var(--surface-3); }
.algorithm-progress span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--green)); transition: width .35s ease; }
.algorithm-cta { display: flex; justify-content: space-between; align-items: center; color: var(--faint); font-size: 13px; }
.algorithm-cta strong { color: var(--blue); font-size: 14px; }
.locked-algorithm { opacity: .72; }
.library-footer { padding: 22px; border-top: 1px solid var(--border-soft); color: var(--faint); text-align: center; font-size: 12px; }

.account-modal { position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 20px; }
.account-backdrop { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; background: rgba(3,7,14,.66); backdrop-filter: blur(13px); -webkit-backdrop-filter: blur(13px); cursor: default; }
.account-sheet { position: relative; width: min(430px, 100%); padding: 35px; border: 1px solid color-mix(in srgb, var(--border) 86%, white 5%); border-radius: 24px; background: color-mix(in srgb, var(--surface) 96%, transparent); box-shadow: 0 30px 100px rgba(0,0,0,.38); }
.account-close { position: absolute; top: 15px; right: 16px; width: 31px; height: 31px; border: 0; border-radius: 50%; color: var(--muted); background: var(--surface-2); cursor: pointer; font-size: 21px; line-height: 1; }
.account-kicker { color: var(--blue); font-size: 11px; font-weight: 800; letter-spacing: .13em; }
.account-sheet h2 { margin: 10px 0 9px; font-size: 29px; letter-spacing: -.045em; }
.account-intro, .account-user-view > p { margin: 0; color: var(--muted); line-height: 1.65; font-size: 14px; }
.account-tabs { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin: 25px 0 20px; padding: 4px; border-radius: 11px; background: var(--surface-2); }
.account-tabs button { padding: 8px; border: 0; border-radius: 8px; color: var(--muted); background: transparent; cursor: pointer; font-weight: 650; }
.account-tabs button.active { color: var(--text); background: var(--surface); box-shadow: 0 3px 12px rgba(0,0,0,.15); }
#accountForm { display: grid; gap: 14px; }
#accountForm label { display: grid; gap: 7px; color: var(--muted); font-size: 12px; font-weight: 650; }
#accountForm input { width: 100%; height: 45px; padding: 0 13px; border: 1px solid var(--border); border-radius: 10px; outline: none; color: var(--text); background: var(--surface-2); font: 15px var(--sans); }
#accountForm input:focus { border-color: var(--blue); box-shadow: 0 0 0 3px color-mix(in srgb, var(--blue) 18%, transparent); }
.account-honeypot { position: absolute !important; left: -10000px; width: 1px; height: 1px; overflow: hidden; }
.account-error { min-height: 18px; margin: -2px 0; color: var(--red); font-size: 12px; }
.account-submit { height: 46px; border: 0; border-radius: 11px; color: white; background: linear-gradient(145deg, #5c9dff, #315fcd); box-shadow: 0 9px 24px rgba(49,95,205,.24); cursor: pointer; font-weight: 750; }
.account-submit:disabled { opacity: .58; cursor: wait; }
.account-note { margin: 17px 0 0; color: var(--faint); font-size: 11px; line-height: 1.6; text-align: center; }
.account-user-view { text-align: center; }
.account-user-avatar { width: 64px; height: 64px; display: grid; place-items: center; margin: 20px auto 4px; border-radius: 19px; color: white; background: linear-gradient(145deg, #48d99b, #168b62); box-shadow: 0 12px 30px rgba(22,139,98,.2); font-size: 28px; font-weight: 800; }
.account-sync-state { display: inline-flex; align-items: center; margin: 24px 0 18px; padding: 9px 12px; border-radius: 99px; color: var(--muted); background: var(--surface-2); font-size: 12px; }
.account-logout { display: block; width: 100%; height: 43px; }

.workspace {
  min-height: 0;
  flex: 1;
  display: grid;
  grid-template-columns: 276px minmax(330px, .85fr) minmax(520px, 1.35fr);
}

.task-sidebar, .problem-pane, .editor-pane { min-width: 0; min-height: 0; }
.task-sidebar { display: flex; flex-direction: column; border-right: 1px solid var(--border-soft); background: #0b101b; }
.sidebar-heading { display: flex; align-items: center; justify-content: space-between; padding: 22px 16px 13px; }
.eyebrow { color: var(--blue); font-size: 12px; font-weight: 750; letter-spacing: .11em; text-transform: uppercase; }
.sidebar-heading h1 { margin: 4px 0 0; font-size: 20px; letter-spacing: -.03em; }
.icon-button { width: 30px; height: 30px; border: 1px solid var(--border); border-radius: 7px; background: transparent; color: var(--muted); cursor: pointer; }

.filter-row { display: flex; gap: 5px; padding: 0 12px 14px; }
.filter { padding: 7px 10px; border: 0; border-radius: 7px; background: transparent; color: var(--muted); font-size: 13px; cursor: pointer; }
.filter:hover { color: var(--text); background: var(--surface-2); }
.filter.active { color: var(--text); background: var(--surface-3); }

.task-list { overflow-y: auto; padding: 0 8px 12px; }
.group-label { padding: 17px 10px 7px; color: var(--faint); font-size: 12px; font-weight: 750; letter-spacing: .08em; text-transform: uppercase; }
.task-item { width: 100%; display: grid; grid-template-columns: 30px 1fr 18px; gap: 9px; align-items: center; padding: 11px 9px; border: 1px solid transparent; border-radius: 9px; background: transparent; text-align: left; cursor: pointer; }
.task-item:hover { background: var(--surface); }
.task-item.active { border-color: #2d4771; background: linear-gradient(90deg, rgba(63,126,232,.17), rgba(63,126,232,.06)); }
.task-number { color: var(--faint); font-family: var(--mono); font-size: 12px; }
.task-title { overflow: hidden; color: #c9d2e2; font-size: 14px; font-weight: 560; line-height: 1.35; text-overflow: ellipsis; white-space: nowrap; }
.task-item.active .task-title { color: white; }
.status-dot { width: 9px; height: 9px; justify-self: center; border-radius: 50%; border: 1.5px solid #526077; }
.status-dot.attempted { border-color: var(--amber); background: rgba(244,185,95,.22); }
.status-dot.failed { border-color: var(--red); background: rgba(255,107,122,.25); }
.status-dot.passed { border-color: var(--green); background: var(--green); box-shadow: 0 0 0 3px rgba(61,220,151,.12); }
.sidebar-foot { margin-top: auto; padding: 13px 16px; border-top: 1px solid var(--border-soft); color: var(--faint); font-size: 12px; }
.local-dot { display: inline-block; width: 7px; height: 7px; margin-right: 7px; border-radius: 50%; background: var(--green); }

.problem-pane { display: flex; flex-direction: column; border-right: 1px solid var(--border-soft); background: var(--surface); }
.pane-tabs { height: 48px; flex: 0 0 48px; display: flex; align-items: end; padding: 0 18px; border-bottom: 1px solid var(--border-soft); }
.pane-tab { height: 100%; padding: 0 14px; border: 0; border-bottom: 2px solid transparent; background: transparent; color: var(--muted); cursor: pointer; font-size: 14px; }
.pane-tab.active { color: white; border-bottom-color: var(--blue); }
.problem-content { flex: 1; overflow-y: auto; padding: 30px 30px 40px; }
.problem-kicker { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.problem-number { color: var(--blue); font-family: var(--mono); font-weight: 700; }
.difficulty { padding: 4px 8px; border-radius: 99px; color: var(--green); background: rgba(61,220,151,.1); font-size: 12px; font-weight: 700; }
.problem-content h2 { margin: 0 0 10px; font-size: 27px; letter-spacing: -.035em; }
.summary { margin: 0 0 28px; color: #aab6c9; line-height: 1.65; }
.section-label { margin: 26px 0 10px; color: white; font-size: 14px; font-weight: 750; }
.description-copy { color: #c6cfde; line-height: 1.75; }
.theory-block { margin: 24px 0; padding: 17px 18px; border: 1px solid rgba(91,156,255,.28); border-radius: 10px; background: linear-gradient(135deg, rgba(91,156,255,.09), rgba(61,220,151,.035)); }
.theory-block p { margin: 7px 0 0; color: #cbd5e5; line-height: 1.78; }
.theory-label { color: var(--blue); font-size: 12px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.theory-jump { margin: -11px 0 5px; padding: 0; border: 0; background: transparent; color: var(--blue); cursor: pointer; font-size: 13px; font-weight: 680; }
.theory-jump:hover { text-decoration: underline; }
.requirement-list { margin: 0; padding-left: 20px; color: #b6c2d4; line-height: 1.8; }
.concept-row { display: flex; flex-wrap: wrap; gap: 7px; }
.concept { padding: 5px 8px; border: 1px solid var(--border); border-radius: 6px; color: #95a7bf; background: #111928; font-family: var(--mono); font-size: 12px; }
.hint-card, .solution-card { margin-bottom: 12px; padding: 16px; border: 1px solid var(--border); border-radius: 10px; background: #111827; color: #c8d2e2; line-height: 1.65; }
.hint-index { display: block; margin-bottom: 5px; color: var(--blue); font-size: 12px; font-weight: 750; }
.solution-warning { margin-bottom: 16px; padding: 12px 14px; border-left: 3px solid var(--amber); border-radius: 6px; background: rgba(244,185,95,.08); color: #d9c39c; font-size: 14px; line-height: 1.55; }
.solution-code { margin: 0; padding: 18px; overflow-x: auto; border: 1px solid var(--border); border-radius: 10px; background: #090e18; color: #d5deed; font-family: var(--mono); font-size: 13px; line-height: 1.65; white-space: pre; }
.reveal-button { margin-top: 10px; }
.problem-footer { height: 58px; flex: 0 0 58px; display: flex; justify-content: space-between; align-items: center; padding: 0 18px; border-top: 1px solid var(--border-soft); }

.editor-pane { display: grid; grid-template-rows: 48px minmax(260px, 1fr) minmax(190px, .55fr); background: #090e18; }
.editor-toolbar { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 0 14px; border-bottom: 1px solid var(--border-soft); background: #0d1320; }
.editor-title, .editor-actions { display: flex; align-items: center; gap: 9px; min-width: 0; }
.editor-title { font-family: var(--mono); font-size: 13px; }
.file-dot { width: 8px; height: 8px; border-radius: 2px; background: #4f8fe9; }
.saved-state { color: var(--faint); font-family: var(--sans); font-size: 12px; }
.runtime-label { color: var(--faint); font-size: 12px; }
.ghost-button, .run-button { border-radius: 7px; cursor: pointer; font-weight: 650; transition: background .15s ease, border-color .15s ease, transform .1s ease; }
.ghost-button { padding: 8px 12px; border: 1px solid var(--border); background: var(--surface-2); color: #b8c4d7; }
.ghost-button:hover { border-color: #3c4b64; background: var(--surface-3); color: white; }
.ghost-button.compact { padding: 6px 9px; font-size: 12px; }
.run-button { padding: 8px 13px; border: 1px solid #5d9fff; background: var(--blue-strong); color: white; box-shadow: 0 5px 16px rgba(57,126,232,.2); }
.run-button:hover { background: #478cec; }
.run-button:active, .ghost-button:active { transform: translateY(1px); }
.run-button:disabled { cursor: wait; opacity: .65; }

.editor-wrap { min-height: 0; display: grid; grid-template-columns: 50px 1fr; overflow: hidden; }
.line-numbers { margin: 0; padding: 18px 11px 80px 0; overflow: hidden; border-right: 1px solid #141e2c; color: #46546b; background: #080d16; text-align: right; font-family: var(--mono); font-size: 14px; line-height: 1.65; user-select: none; }
.code-editor { width: 100%; height: 100%; resize: none; padding: 18px 20px 80px; border: 0; outline: 0; color: #dce5f4; background: #090e18; caret-color: var(--blue); font-family: var(--mono); font-size: 14px; line-height: 1.65; tab-size: 4; white-space: pre; overflow: auto; }
.code-editor::selection { background: rgba(66,130,225,.35); }

.console-panel { min-height: 0; display: flex; flex-direction: column; border-top: 1px solid var(--border-soft); background: #0c121e; }
.console-header { height: 42px; flex: 0 0 42px; display: flex; align-items: center; justify-content: space-between; padding: 0 16px; border-bottom: 1px solid var(--border-soft); }
.console-tabs { display: flex; align-items: center; gap: 14px; color: var(--faint); font-size: 12px; }
.console-tabs .active { color: #cdd6e5; font-weight: 700; }
.shortcut { color: #56647a; font-size: 12px; }
.console-output { flex: 1; overflow: auto; padding: 17px 18px; font-family: var(--mono); font-size: 13px; line-height: 1.6; white-space: pre-wrap; }
.console-output.idle { color: var(--faint); }
.console-output.success { color: #9ce8c3; background: linear-gradient(180deg, rgba(61,220,151,.055), transparent); }
.console-output.failure { color: #ff9aa5; background: linear-gradient(180deg, rgba(255,107,122,.055), transparent); }
.empty-console { height: 100%; display: flex; align-items: center; justify-content: center; gap: 11px; font-family: var(--sans); text-align: center; }
.empty-console span { color: #42516a; font-family: var(--mono); font-size: 22px; }
.runtime-loader { width: min(520px, calc(100% - 24px)); margin: clamp(32px, 8vh, 74px) auto 0; font-family: var(--sans); }
.runtime-loader-head { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin-bottom: 11px; color: var(--muted); font-size: 13px; }
.runtime-loader-head strong { color: var(--text); font-variant-numeric: tabular-nums; }
.runtime-loader-track { height: 8px; overflow: hidden; border-radius: 99px; background: var(--surface-3); }
.runtime-loader-track span { display: block; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--green)); transition: width .16s ease; }
.runtime-loader small { display: block; margin-top: 9px; color: var(--faint); font-size: 11px; font-variant-numeric: tabular-nums; }
.runtime-loader.initializing .runtime-loader-track span { width: 34%; animation: runtime-loading 1.1s ease-in-out infinite alternate; }
@keyframes runtime-loading { from { transform: translateX(-75%); } to { transform: translateX(270%); } }

.toast { position: fixed; right: 22px; bottom: 22px; z-index: 20; max-width: 340px; padding: 12px 15px; border: 1px solid var(--border); border-radius: 9px; background: #172033; box-shadow: 0 16px 44px rgba(0,0,0,.38); color: white; opacity: 0; transform: translateY(10px); pointer-events: none; transition: .2s ease; }
.toast.show { opacity: 1; transform: translateY(0); }

/* Book-grounded theory course */
body.theory-open { overflow: hidden; }
.theory-view { height: calc(100vh - 62px); overflow-y: auto; background: var(--bg); }
.theory-view { display: grid; grid-template-columns: 240px minmax(430px, 720px) minmax(340px, 470px); justify-content: center; align-items: start; gap: clamp(24px, 3vw, 48px); padding: 40px clamp(20px, 3vw, 50px) 80px; }
.theory-sidebar { position: sticky; top: 0; min-width: 0; }
.theory-sidebar-head { padding: 6px 10px 20px; }
.theory-sidebar-head h1 { margin: 7px 0 7px; font-size: 20px; letter-spacing: -.03em; }
.theory-sidebar-head p { margin: 0; color: var(--faint); font-size: 12px; }
.theory-chapter-list { display: grid; gap: 4px; }
.theory-chapter-item { width: 100%; display: grid; grid-template-columns: 28px 1fr 22px; align-items: center; gap: 8px; padding: 11px 10px; border: 0; border-radius: 10px; background: transparent; color: var(--muted); text-align: left; cursor: pointer; }
.theory-chapter-item:hover { background: var(--surface-2); }
.theory-chapter-item.active { color: var(--text); background: var(--surface-3); }
.theory-chapter-number { color: var(--faint); font-family: var(--mono); font-size: 11px; }
.theory-chapter-item strong { display: block; font-size: 13px; line-height: 1.3; }
.theory-chapter-item small { display: block; margin-top: 3px; color: var(--faint); font-size: 11px; }
.theory-check { width: 18px; height: 18px; display: grid; place-items: center; border: 1px solid var(--border); border-radius: 50%; color: transparent; font-style: normal; font-size: 11px; }
.theory-check.complete { border-color: var(--green); color: white; background: var(--green); }
.theory-progress-block { margin: 18px 10px 0; padding-top: 15px; border-top: 1px solid var(--border); }
.theory-progress-block > div:first-child { display: flex; justify-content: space-between; color: var(--faint); font-size: 12px; }
.theory-progress-block strong { color: var(--text); }
.theory-progress-track { height: 5px; margin-top: 9px; overflow: hidden; border-radius: 99px; background: var(--surface-3); }
.theory-progress-track span { display: block; width: 0; height: 100%; border-radius: inherit; background: linear-gradient(90deg, var(--blue), var(--green)); transition: width .25s ease; }
.theory-article { min-width: 0; padding: 5px 0 30px; }
.lesson-header { padding-bottom: 30px; border-bottom: 1px solid var(--border); }
.lesson-meta { display: flex; gap: 15px; margin-bottom: 16px; color: var(--blue); font-size: 12px; font-weight: 750; }
.lesson-header h1 { max-width: 620px; margin: 0 0 17px; font-size: clamp(34px, 4vw, 52px); line-height: 1.08; letter-spacing: -.05em; }
.lesson-header p { max-width: 650px; margin: 0; color: var(--muted); font-size: 17px; line-height: 1.78; }
.lesson-objectives { margin: 27px 0; padding: 18px 20px; border-radius: 13px; background: var(--surface-2); }
.lesson-objectives > span { color: var(--blue); font-size: 12px; font-weight: 780; }
.lesson-objectives ul { margin: 11px 0 0; padding-left: 20px; color: var(--text); line-height: 1.85; }
.lesson-section { margin: 0 0 45px; }
.lesson-section h2 { margin: 0 0 15px; font-size: 23px; letter-spacing: -.03em; }
.lesson-section p { margin: 0 0 15px; color: color-mix(in srgb, var(--text) 79%, var(--muted)); font-size: 16px; line-height: 1.9; }
.lesson-formula { margin-top: 22px; padding: 18px 20px; overflow-x: auto; border: 1px solid var(--border); border-radius: 12px; background: var(--surface); color: var(--text); font-family: Georgia, "Times New Roman", serif; font-size: 18px; line-height: 1.6; white-space: nowrap; }
.lesson-section .lesson-citation { margin-top: 14px; color: var(--faint); font-size: 12px; line-height: 1.55; }
.lesson-citation::before { content: "参考："; color: var(--muted); font-weight: 700; }
.practice-bridge { display: flex; align-items: center; justify-content: space-between; gap: 18px; margin: 24px 0; padding: 15px 17px; border: 1px solid rgba(91,156,255,.28); border-radius: 12px; background: rgba(91,156,255,.07); color: var(--muted); font-size: 13px; }
.practice-bridge button { flex: 0 0 auto; padding: 0; border: 0; background: transparent; color: var(--blue); cursor: pointer; font-weight: 700; }
.lesson-footer { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; gap: 10px; padding-top: 24px; border-top: 1px solid var(--border); }
.lesson-footer > :last-child { justify-self: end; }
.complete-lesson { padding: 9px 14px; border: 1px solid var(--blue); border-radius: 8px; background: var(--blue-strong); color: white; cursor: pointer; font-weight: 700; }
.complete-lesson.is-complete { border-color: rgba(61,220,151,.4); background: rgba(61,220,151,.1); color: var(--green); }
.theory-viz-pane { position: sticky; top: 0; min-width: 0; }
.viz-sticky { padding: 21px; border: 1px solid var(--border); border-radius: 18px; background: var(--surface); box-shadow: 0 18px 48px rgba(0,0,0,.08); }
.viz-heading { margin-bottom: 18px; }
.viz-heading h2 { margin: 5px 0 0; font-size: 20px; letter-spacing: -.025em; }
.theory-viz-controls { display: grid; gap: 12px; margin-bottom: 16px; }
.viz-control { display: block; }
.viz-control > span { display: flex; justify-content: space-between; margin-bottom: 7px; color: var(--muted); font-size: 12px; }
.viz-control strong { color: var(--text); font-variant-numeric: tabular-nums; }
.viz-control input { width: 100%; accent-color: var(--blue); }
.viz-button-row, .viz-segmented { display: flex; gap: 6px; }
.viz-button-row button, .viz-segmented button { flex: 1; padding: 7px 8px; border: 1px solid var(--border); border-radius: 7px; background: var(--surface-2); color: var(--muted); cursor: pointer; font-size: 11px; }
.viz-button-row button:hover, .viz-segmented button.active { border-color: var(--blue); color: var(--text); background: rgba(91,156,255,.1); }
.theory-viz-pane canvas { width: 100%; height: 370px; display: block; border-top: 1px solid var(--border-soft); border-bottom: 1px solid var(--border-soft); }
.viz-readout { min-height: 68px; padding-top: 15px; }
.viz-readout strong, .viz-readout span { display: block; }
.viz-readout strong { color: var(--text); font-size: 14px; }
.viz-readout span { margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.55; }

/* Training lab */
body.lab-open { overflow: auto; background: var(--bg); }
.training-view { flex: 1; min-height: 0; overflow-y: auto; padding: 34px clamp(22px, 4vw, 60px) 60px; background: radial-gradient(circle at 80% 0%, rgba(61,220,151,.08), transparent 32%), var(--bg); }
.lab-header { max-width: 1480px; margin: 0 auto 28px; display: flex; align-items: end; justify-content: space-between; gap: 30px; }
.lab-header h1 { margin: 8px 0 8px; font-size: clamp(30px, 4vw, 48px); letter-spacing: -.045em; }
.lab-header p { max-width: 740px; margin: 0; color: var(--muted); line-height: 1.65; }
.back-button { display: block; margin-bottom: 25px; padding: 0; border: 0; background: transparent; color: var(--muted); cursor: pointer; }
.back-button:hover { color: var(--text); }
.lab-run { flex: 0 0 auto; padding: 12px 18px; font-size: 15px; }
.lab-grid { max-width: 1480px; margin: auto; display: grid; grid-template-columns: minmax(400px, .95fr) minmax(520px, 1.35fr); gap: 18px; }
.lab-card { min-width: 0; padding: 22px; border: 1px solid var(--border); border-radius: 14px; background: var(--surface); box-shadow: 0 16px 45px rgba(0,0,0,.08); }
.card-heading { display: flex; align-items: start; justify-content: space-between; gap: 18px; margin-bottom: 18px; }
.card-heading h2, .explanation-card h2 { margin: 4px 0 0; font-size: 20px; letter-spacing: -.02em; }
.card-label { color: var(--blue); font-size: 11px; font-weight: 820; letter-spacing: .11em; }
.simulation-card canvas { width: 100%; height: 320px; display: block; border: 1px solid var(--border-soft); border-radius: 10px; background: var(--surface-2); }
.segmented { display: flex; padding: 3px; border: 1px solid var(--border); border-radius: 8px; background: var(--surface-2); }
.segmented button { padding: 6px 10px; border: 0; border-radius: 5px; background: transparent; color: var(--muted); cursor: pointer; font-size: 12px; }
.segmented button.active { background: var(--surface); color: var(--text); box-shadow: 0 2px 8px rgba(0,0,0,.12); }
.segmented button:disabled { opacity: .45; cursor: not-allowed; }
.sim-footer { display: flex; justify-content: space-between; gap: 12px; padding-top: 13px; color: var(--faint); font-size: 12px; }
.metric-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 18px; }
.metric-row div { padding: 12px; border: 1px solid var(--border-soft); border-radius: 9px; background: var(--surface-2); }
.metric-row span { display: block; min-height: 30px; color: var(--muted); font-size: 12px; line-height: 1.25; }
.metric-row strong { display: block; margin-top: 4px; font-size: 19px; font-variant-numeric: tabular-nums; }
.training-status { padding: 5px 9px; border-radius: 99px; background: var(--surface-3); color: var(--muted); font-size: 12px; font-weight: 700; }
.training-status.running { color: var(--amber); background: rgba(244,185,95,.12); }
.training-status.complete { color: var(--green); background: rgba(61,220,151,.12); }
.training-status.failed { color: var(--red); background: rgba(255,107,122,.12); }
.chart-wrap { height: 270px; }
.chart-wrap canvas { width: 100%; height: 100%; display: block; }
.chart-legend { display: flex; justify-content: space-between; color: var(--muted); font-size: 12px; }
.legend-line { display: inline-block; width: 19px; height: 3px; margin: 0 7px 3px 0; border-radius: 3px; background: var(--green); }
.target-copy { color: var(--faint); }
.explanation-card { grid-column: 1 / -1; }
.explanation-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 22px; margin-top: 18px; }
.explanation-grid div { padding-left: 16px; border-left: 2px solid var(--border); }
.explanation-grid strong { font-size: 14px; }
.explanation-grid p { margin: 7px 0 0; color: var(--muted); line-height: 1.6; font-size: 14px; }

/* Light theme refinements for surfaces that intentionally use code-editor colors in dark mode. */
:root[data-theme="light"] .topbar { background: rgba(255,255,255,.96); }
:root[data-theme="light"] .task-sidebar { background: #f7f9fc; }
:root[data-theme="light"] .task-title { color: #4d5b70; }
:root[data-theme="light"] .task-item.active .task-title,
:root[data-theme="light"] .pane-tab.active,
:root[data-theme="light"] .section-label { color: #172033; }
:root[data-theme="light"] .problem-pane { background: #fff; }
:root[data-theme="light"] .summary { color: #59677c; }
:root[data-theme="light"] .description-copy,
:root[data-theme="light"] .requirement-list,
:root[data-theme="light"] .theory-block p { color: #3f4c60; }
:root[data-theme="light"] .concept { color: #53647c; background: #f5f7fb; }
:root[data-theme="light"] .hint-card,
:root[data-theme="light"] .solution-card { color: #344258; background: #f7f9fc; }
:root[data-theme="light"] .solution-code { color: #22314a; background: #f7f9fc; }
:root[data-theme="light"] .editor-pane,
:root[data-theme="light"] .code-editor { color: #263650; background: #fbfcfe; }
:root[data-theme="light"] .editor-toolbar,
:root[data-theme="light"] .console-panel { background: #f5f7fb; }
:root[data-theme="light"] .line-numbers { color: #91a0b5; background: #f4f6fa; border-right-color: #e2e7ef; }
:root[data-theme="light"] .ghost-button { color: #536176; }
:root[data-theme="light"] .ghost-button:hover { color: #172033; }
:root[data-theme="light"] .console-output.success { color: #08764b; }
:root[data-theme="light"] .console-output.failure { color: #bf3142; }
:root[data-theme="light"] .toast { color: #172033; background: #fff; box-shadow: 0 16px 44px rgba(30,45,70,.18); }

body.sidebar-collapsed .workspace { grid-template-columns: 0 minmax(330px, .85fr) minmax(520px, 1.35fr); }
body.sidebar-collapsed .task-sidebar { overflow: hidden; border: 0; }

@media (max-width: 1100px) {
  .workspace { grid-template-columns: 230px minmax(310px, .85fr) minmax(430px, 1.15fr); }
  .runtime-label, .brand-tag { display: none; }
  .training-button { font-size: 0; }
  .training-button span { font-size: 16px; }
  .lab-grid { grid-template-columns: 1fr; }
  .explanation-card { grid-column: auto; }
  .theory-view { grid-template-columns: 210px minmax(0, 1fr); }
  .theory-viz-pane { position: static; grid-column: 2; }
}

@media (max-width: 820px) {
  body { overflow: auto; }
  .app-shell { min-height: 100vh; height: auto; }
  .topbar { position: sticky; top: 0; z-index: 10; grid-template-columns: auto 1fr auto; gap: 8px; padding: 0 10px; }
  .top-center { justify-self: center; }
  .top-progress { display: none; }
  .brand-name { display: none; }
  .mode-switch button { padding: 6px 8px; font-size: 12px; }
  .top-actions .ghost-button { display: none; }
  .workspace { display: block; }
  .task-sidebar { min-height: 280px; max-height: 380px; border-right: 0; border-bottom: 1px solid var(--border-soft); }
  .problem-pane { min-height: 620px; border-right: 0; border-bottom: 1px solid var(--border-soft); }
  .editor-pane { height: 760px; }
  .editor-actions .compact { display: none; }
  .training-view { padding: 24px 14px 45px; }
  .lab-header { align-items: start; flex-direction: column; }
  .lab-grid { display: block; }
  .lab-card { margin-bottom: 14px; padding: 17px; }
  .metric-row { grid-template-columns: repeat(2, 1fr); }
  .explanation-grid { grid-template-columns: 1fr; }
  .theory-view { display: block; height: calc(100vh - 62px); padding: 0 16px 60px; }
  .theory-sidebar { position: static; margin: 0 -16px 30px; padding: 20px 16px 14px; border-bottom: 1px solid var(--border); background: var(--surface); }
  .theory-sidebar-head { padding: 0 4px 13px; }
  .theory-chapter-list { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 7px; }
  .theory-chapter-item { min-width: 0; }
  .theory-progress-block { margin-top: 12px; }
  .theory-viz-pane { margin-top: 30px; }
  .viz-sticky { padding: 16px; }
  .theory-viz-pane canvas { height: 330px; }
  .lesson-header { padding-top: 8px; }
  .lesson-footer { grid-template-columns: 1fr 1fr; }
  .complete-lesson { grid-column: 1 / -1; grid-row: 1; }
  .library-nav { height: 62px; }
  .library-status { display: none; }
  .compact-account [data-account-label] { display: none; }
  .compact-account { width: 37px; padding: 0; justify-content: center; }
  .library-content { width: min(100% - 28px, 620px); padding-top: 52px; }
  .library-summary { margin: 35px 0 52px; }
  .library-summary div { padding: 3px 12px; }
  .algorithm-grid { grid-template-columns: 1fr; }
  .active-algorithm { grid-row: auto; min-height: 430px; }
  .section-heading-row > span { display: none; }
}

@media (max-width: 540px) {
  .theory-chapter-list { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .library-nav .account-button [data-account-label] { display: none; }
  .library-nav .account-button { width: 37px; padding: 0; justify-content: center; }
  .account-sheet { padding: 30px 22px 24px; border-radius: 20px; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition: none !important; }
}
