:root {
  --bg: #FAF6EE; --paper: #FFFDF8; --ink: #1E2433; --muted: #5E6576; --line: #E4DACA;
  --navy: #1B2A4A; --orange: #E8742A; --action: #B9520F; --action-hover: #9C440B;
  --ok: #2F7D4F; --ok-bg: #E6F2EA; --bad: #B3261E; --bad-bg: #FBEAE8; --info-bg: #ECEFF5;
  --term-bg: #300A24; --term-fg: #EEEEEC; --term-dim: #BCA9B6; --term-head: #2C2C2C;
  --term-green: #8AE234; --term-blue: #729FCF; --term-yellow: #FCE94F; --term-red: #EF2929;
  --ui: 'Ubuntu', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: 'Ubuntu Mono', 'DejaVu Sans Mono', Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #121826; --paper: #1A2233; --ink: #E8E6E1; --muted: #A3A9B8; --line: #2C3547;
    --navy: #C9D4EE; --action: #D2651C; --action-hover: #E8742A;
    --ok: #6CC48F; --ok-bg: #16301F; --bad: #F08A80; --bad-bg: #3A1A18; --info-bg: #222C40;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font: 16px/1.6 var(--ui); }
a { color: var(--action); }
:focus-visible { outline: 3px solid var(--orange); outline-offset: 2px; }
code { font-family: var(--mono); font-size: 1.02em; background: color-mix(in srgb, var(--navy) 9%, transparent); padding: .05em .35em; border-radius: 4px; }
h1, h2, h3 { color: var(--navy); line-height: 1.2; margin: 0; }

/* ---------- top bar ---------- */
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; padding: .75rem clamp(1rem, 4vw, 2.5rem); border-bottom: 1px solid var(--line); background: var(--paper); position: sticky; top: 0; z-index: 5; }
.brand { display: flex; align-items: center; gap: .6rem; color: var(--navy); text-decoration: none; font-weight: 700; }
.brand-mark { font-family: var(--mono); font-weight: 700; background: var(--term-bg); color: var(--term-green); padding: .1rem .45rem; border-radius: 6px; }
.who { display: flex; align-items: center; gap: .75rem; font-size: .9rem; color: var(--muted); }
.who strong { color: var(--ink); font-weight: 500; }
.who-label { white-space: nowrap; }
@media (max-width: 600px) { .who-label { display: none; } .who { font-size: .8rem; gap: .5rem; text-align: right; } .brand span:last-child { font-size: .95rem; } }
.linkbtn { background: none; border: 0; color: var(--action); font: inherit; cursor: pointer; padding: 0; text-decoration: underline; }

main:focus, main:focus-visible { outline: none; }
main { max-width: 1180px; margin: 0 auto; padding: clamp(1.25rem, 4vw, 2.75rem) clamp(1rem, 4vw, 2.5rem) 4rem; outline: none; }
.loading { color: var(--muted); }

/* ---------- buttons & forms ---------- */
.btn { display: inline-flex; align-items: center; gap: .5rem; border: 0; border-radius: 8px; padding: .7rem 1.15rem; font: 500 1rem var(--ui); cursor: pointer; text-decoration: none; background: var(--action); color: #fff; }
.btn:hover { background: var(--action-hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.quiet { background: transparent; color: var(--navy); border: 1.5px solid var(--line); }
.btn.quiet:hover { border-color: var(--navy); }
label { display: block; font-weight: 500; margin: 1rem 0 .3rem; }
input[type=text], input[type=password], input[type=number], select { width: 100%; font: 1rem var(--ui); padding: .65rem .75rem; border: 1.5px solid var(--line); border-radius: 8px; background: var(--paper); color: var(--ink); }
input:focus { border-color: var(--navy); outline: none; }
.field-help { font-size: .85rem; color: var(--muted); margin-top: .25rem; }
.error { background: var(--bad-bg); color: var(--bad); border-radius: 8px; padding: .6rem .8rem; margin-top: 1rem; }

/* ---------- home ---------- */
.home-head { display: grid; gap: 1.5rem; grid-template-columns: 1fr; margin-bottom: 2.25rem; }
@media (min-width: 860px) { .home-head { grid-template-columns: 1.1fr 1fr; align-items: end; } }
.home-head h1 { font-size: clamp(2rem, 4.5vw, 3rem); letter-spacing: -.01em; }
.home-head p { color: var(--muted); max-width: 46ch; margin: .75rem 0 0; }

.path { list-style: none; margin: 0; padding: 0; border-top: 1px solid var(--line); }
.stop { display: grid; grid-template-columns: 3rem 1fr auto; gap: 1rem; align-items: center; padding: 1.1rem 0; border-bottom: 1px solid var(--line); }
.stop-n { font: 700 1.6rem var(--mono); color: var(--muted); }
.stop.open .stop-n, .stop.done .stop-n { color: var(--orange); }
.stop h2 { font-size: 1.15rem; }
.stop-meta { font-size: .9rem; color: var(--muted); margin-top: .15rem; }
.stop-actions { display: flex; gap: .5rem; flex-wrap: wrap; justify-content: flex-end; }
.badge { display: inline-block; font-size: .8rem; font-weight: 500; padding: .15rem .55rem; border-radius: 99px; background: var(--info-bg); color: var(--navy); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
@media (max-width: 640px) { .stop { grid-template-columns: 2.25rem 1fr; } .stop-actions { grid-column: 2; justify-content: flex-start; } }

/* ---------- terminal window (the one bold element) ---------- */
.term { background: var(--term-bg); color: var(--term-fg); border-radius: 10px; overflow: hidden; font: 15px/1.45 var(--mono); box-shadow: 0 1px 0 rgba(0,0,0,.25), 0 12px 32px -18px rgba(48,10,36,.7); }
.term-bar { display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; background: var(--term-head); color: #DADADA; font: 500 .85rem var(--ui); padding: .45rem .7rem; }
.term-bar span { grid-column: 2; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.term-dots { grid-column: 3; justify-self: end; display: flex; gap: .4rem; }
.term-dots i { width: 13px; height: 13px; border-radius: 50%; background: #4A4A4A; display: block; }
.term-dots i:last-child { background: #E95420; }
.term-body { padding: .8rem 1rem 1rem; white-space: pre-wrap; word-break: break-word; overflow-x: auto; }
.p-user { color: var(--term-green); font-weight: 700; }
.p-path { color: var(--term-blue); font-weight: 700; }
.t-out { color: var(--term-fg); }
.t-dim { color: var(--term-dim); }

.countdown { font-size: clamp(1rem, 2.4vw, 1.25rem); }
.countdown .big { color: var(--term-yellow); font-weight: 700; }

/* ---------- lesson ---------- */
.lesson { max-width: 74ch; }
.crumbs { font-size: .9rem; margin-bottom: 1rem; }
.lesson h1 { font-size: clamp(1.9rem, 4vw, 2.6rem); margin-bottom: .5rem; }
.lesson .kicker { color: var(--muted); margin: 0 0 1.5rem; }
.lesson h2 { font-size: 1.45rem; margin: 2.4rem 0 .6rem; padding-top: .9rem; border-top: 3px solid var(--orange); display: inline-block; }
.lesson p { margin: .7rem 0; }
.lesson .term { margin: 1.1rem 0 1.3rem; }
table.ref { width: 100%; border-collapse: collapse; margin: 1rem 0 1.3rem; font-size: .95rem; }
.table-wrap { overflow-x: auto; }
table.ref th { text-align: left; color: var(--navy); border-bottom: 2px solid var(--navy); padding: .45rem .6rem; font-weight: 700; }
table.ref td { border-bottom: 1px solid var(--line); padding: .5rem .6rem; vertical-align: top; }
.note { border-left: 4px solid var(--navy); background: var(--info-bg); padding: .75rem 1rem; border-radius: 0 8px 8px 0; margin: 1.1rem 0; }
.note.warn { border-color: var(--orange); background: color-mix(in srgb, var(--orange) 11%, var(--paper)); }
.lesson-end { margin-top: 2.5rem; padding: 1.4rem; border: 1.5px solid var(--line); border-radius: 12px; background: var(--paper); }
.lesson-end p { margin: 0 0 1rem; }

/* ---------- identity ---------- */
.idbox { max-width: 30rem; margin: 0 auto; background: var(--paper); border: 1.5px solid var(--line); border-radius: 14px; padding: 1.6rem; }
.idbox h1 { font-size: 1.5rem; }
.idbox > p { color: var(--muted); margin: .5rem 0 0; }
.tabs { display: flex; gap: .25rem; margin-top: 1.2rem; border-bottom: 1.5px solid var(--line); }
.tabs button { background: none; border: 0; padding: .55rem .8rem; font: 500 .95rem var(--ui); color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1.5px; }
.tabs button[aria-selected=true] { color: var(--navy); border-color: var(--orange); }
.idbox .btn { margin-top: 1.3rem; width: 100%; justify-content: center; }

/* ---------- lab ---------- */
.lab-head { display: flex; flex-wrap: wrap; align-items: baseline; justify-content: space-between; gap: .5rem 1.5rem; margin-bottom: 1rem; }
.lab-head h1 { font-size: clamp(1.4rem, 3vw, 1.9rem); }
.lab-stats { color: var(--muted); font-size: .95rem; }
.lab-stats strong { color: var(--ink); }
.track { display: flex; gap: 3px; margin-bottom: 1.4rem; }
.track i { flex: 1; height: 7px; border-radius: 3px; background: var(--line); }
.track i.done { background: var(--navy); }
.track i.half { background: color-mix(in srgb, var(--navy) 45%, var(--line)); }
.track i.current { background: var(--orange); }

.lab-grid { display: grid; gap: 1.25rem; grid-template-columns: minmax(0, 1fr); }
.lab-grid > * { min-width: 0; }
@media (min-width: 960px) { .lab-grid { grid-template-columns: minmax(0, 1fr) minmax(0, 1.15fr); align-items: start; } }
.task { background: var(--paper); border: 1.5px solid var(--line); border-radius: 12px; padding: 1.15rem 1.25rem; margin-bottom: 1.1rem; }
.task-no { font: 700 .9rem var(--mono); color: var(--orange); }
.task h2 { font-size: 1.2rem; margin: .15rem 0 .5rem; }
.task p { margin: .45rem 0; }
.task pre { font: 14.5px/1.4 var(--mono); background: var(--term-bg); color: var(--term-fg); padding: .6rem .8rem; border-radius: 8px; overflow-x: auto; margin: .6rem 0; }
.task-tools { display: flex; align-items: center; gap: .75rem; flex-wrap: wrap; margin-top: .9rem; }
.guide { margin-top: .8rem; background: var(--info-bg); border-radius: 8px; padding: .6rem .8rem; }
.exam-note { border-left: 4px solid var(--orange); }
.guide code { background: none; padding: 0; font-weight: 700; }

.input-term .term-body { min-height: 7.5rem; max-height: 14rem; overflow-y: auto; }
.input-line { display: flex; align-items: baseline; gap: .5ch; padding: .55rem 1rem .8rem; border-top: 1px solid rgba(255,255,255,.08); }
.input-line .ps { white-space: nowrap; }
.input-line input { flex: 1; min-width: 6ch; background: transparent; border: 0; color: var(--term-fg); font: 15px/1.45 var(--mono); padding: 0; caret-color: var(--term-green); }
.input-line input:focus { outline: none; }
.input-term:focus-within { box-shadow: 0 0 0 3px var(--orange); }
.run-row { display: flex; justify-content: space-between; align-items: center; gap: .75rem; margin-top: .6rem; font-size: .85rem; color: var(--muted); }

.output-term .term-body { min-height: 22rem; max-height: 68vh; overflow-y: auto; }
.entry { padding-bottom: .55rem; margin-bottom: .55rem; border-bottom: 1px dashed rgba(255,255,255,.1); }
.entry:last-child { border-bottom: 0; }
.verdict { display: block; margin-top: .35rem; padding: .35rem .6rem; border-radius: 6px; font-family: var(--ui); font-size: .9rem; line-height: 1.45; white-space: normal; }
.verdict code { background: rgba(255,255,255,.12); color: inherit; }
.verdict.ok { background: rgba(138,226,52,.14); color: #C7F59A; }
.verdict.wrong { background: rgba(239,41,41,.16); color: #FFC9C4; }
.verdict.info { background: rgba(114,159,207,.16); color: #CFE1F5; }
.empty-out { color: var(--term-dim); }

.finish { background: var(--paper); border: 1.5px solid var(--line); border-radius: 14px; padding: clamp(1.25rem, 3vw, 2rem); display: grid; gap: 1.5rem; }
@media (min-width: 860px) { .finish { grid-template-columns: 1fr 1fr; align-items: center; } }
.finish h1 { font-size: clamp(1.6rem, 3.5vw, 2.2rem); }
.score-line { font: 700 clamp(2.4rem, 6vw, 3.4rem) var(--mono); color: var(--navy); margin: .6rem 0 .2rem; }
.score-line small { font-size: .45em; color: var(--muted); }
.finish p { color: var(--muted); margin: .4rem 0; }
.finish .btns { display: flex; gap: .6rem; flex-wrap: wrap; margin-top: 1rem; }

.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
@media (prefers-reduced-motion: no-preference) {
  .verdict.ok { animation: pop .35s ease-out; }
  @keyframes pop { from { transform: scale(.98); opacity: .4; } to { transform: none; opacity: 1; } }
}
.lesson .term-body { white-space: pre; }

/* ---------- SQL lab ---------- */
@media (min-width: 960px) { .sql-grid { grid-template-columns: minmax(0, .8fr) minmax(0, 1.35fr); } }
.editor { display: block; width: 100%; min-height: 9.5rem; max-height: 22rem; resize: vertical; background: var(--term-bg); color: var(--term-fg); border: 0; padding: .8rem 1rem; font: 15px/1.5 var(--mono); caret-color: var(--term-green); tab-size: 2; }
.editor:focus { outline: none; }
.editor::placeholder { color: var(--term-dim); }
.run-btns { display: flex; gap: .5rem; flex-shrink: 0; }
.run-row { margin-bottom: 1rem; }
.t-err { color: #FFB4AE; }
.guide-sql { margin: .4rem 0 0; font: 14px/1.45 var(--mono); white-space: pre-wrap; background: none; color: var(--ink); padding: 0; }
.output-term .term-body { white-space: pre; overflow-x: auto; }
.output-term .verdict { white-space: normal; }
.lesson .term-body { white-space: pre; }

.labtabs { display: flex; gap: .25rem; margin-bottom: .6rem; border-bottom: 1.5px solid var(--line); }
.labtabs button { background: none; border: 0; padding: .5rem .9rem; font: 500 .95rem var(--ui); color: var(--muted); cursor: pointer; border-bottom: 3px solid transparent; margin-bottom: -1.5px; }
.labtabs button[aria-selected=true] { color: var(--navy); border-color: var(--orange); }

.schema { background: var(--paper); border: 1.5px solid var(--line); border-radius: 12px; padding: .9rem 1.1rem; font-size: .9rem; }
.schema-head { display: flex; flex-wrap: wrap; gap: .4rem; align-items: baseline; margin-bottom: .3rem; }
.schema h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: .8rem 0 .3rem; }
.schema details { border-bottom: 1px solid var(--line); padding: .25rem 0; }
.schema summary { cursor: pointer; font-family: var(--mono); color: var(--navy); }
.schema ul { list-style: none; margin: .3rem 0 .4rem .2rem; padding: 0; }
.schema li { padding: .1rem 0; }
.sc-type { color: var(--muted); font-size: .85em; }
.sc-key { font-size: .72rem; font-weight: 700; padding: 0 .35rem; border-radius: 4px; background: color-mix(in srgb, var(--orange) 18%, transparent); color: var(--action); }
.sc-row { padding: .2rem 0; border-bottom: 1px solid var(--line); }
.sc-idx { color: var(--muted); font-size: .85em; }

.appview { background: var(--paper); border: 1.5px solid var(--line); border-radius: 12px; padding: 1rem; min-height: 20rem; }
.app-top { display: flex; align-items: center; gap: .6rem; padding-bottom: .8rem; border-bottom: 3px solid var(--navy); margin-bottom: 1rem; }
.app-logo { background: #7B1113; color: #FFD700; font: 700 .75rem var(--ui); padding: .25rem .45rem; border-radius: 5px; letter-spacing: .05em; }
.app-note { margin-left: auto; font-size: .8rem; color: var(--muted); }
.app-card { border: 1px solid var(--line); border-radius: 10px; padding: .8rem 1rem; margin-bottom: 1rem; background: var(--bg); }
.app-card h3 { font-size: 1rem; margin-bottom: .5rem; }
.app-card.missing { border-style: dashed; color: var(--muted); }
.app-table { width: 100%; border-collapse: collapse; font-size: .88rem; }
.app-table th { text-align: left; background: var(--navy); color: var(--paper); padding: .35rem .5rem; font-weight: 500; }
.app-table td { padding: .35rem .5rem; border-bottom: 1px solid var(--line); }
.null { color: var(--muted); font-style: italic; }
@media (max-width: 600px) { .run-row { flex-direction: column; align-items: stretch; } .run-btns { justify-content: flex-end; } }
