:root {
  --bg: #f5f6f8; --surface: #ffffff; --surface-2: #f0f2f5; --border: #dfe3e8;
  --text: #1c2430; --muted: #5f6b7a; --brand: #2f5bea; --brand-ink: #ffffff;
  --ok: #16865a; --ok-bg: #e5f5ee; --warn: #a76100; --warn-bg: #fdf1dc;
  --danger: #c4302b; --danger-bg: #fce8e7; --code-bg: #1e1e1e; --code-text: #e6e6e6;
  --radius: 8px; --shadow: 0 1px 2px rgba(16, 24, 40, .06), 0 1px 3px rgba(16, 24, 40, .08);
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body { font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; background: var(--bg); color: var(--text); }
a { color: var(--brand); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 .75rem; }
h2 { font-size: 1.15rem; margin: 1.5rem 0 .6rem; }
h3 { font-size: 1rem; margin: 1rem 0 .4rem; }
code { font-family: var(--mono); font-size: .9em; background: var(--surface-2); padding: .1em .35em; border-radius: 4px; }
pre { font-family: var(--mono); font-size: 13px; background: var(--surface-2); padding: .75rem; border-radius: var(--radius); overflow: auto; }
pre code { background: none; padding: 0; }
table { border-collapse: collapse; width: 100%; }
th, td { text-align: left; padding: .5rem .6rem; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); font-weight: 600; }

/* topo */
.topbar { display: flex; align-items: center; gap: 1rem; padding: 0 1rem; height: 52px; background: var(--surface); border-bottom: 1px solid var(--border); }
.logo { font-weight: 700; font-size: 1.05rem; color: var(--text); display: flex; align-items: center; gap: .4rem; }
.logo span { display: inline-grid; place-items: center; width: 26px; height: 26px; border-radius: 6px; background: var(--brand); color: #fff; font-size: .8rem; }
.topbar .spacer { flex: 1; }
.topbar .who { color: var(--muted); font-size: .9rem; }
.container { max-width: 1100px; margin: 0 auto; padding: 1.5rem 16px 3rem; }
.narrow { max-width: 420px; }

/* componentes */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); }
.grid { display: grid; gap: 1rem; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); }
.stack > * + * { margin-top: 1rem; }
.row { display: flex; gap: .6rem; align-items: center; flex-wrap: wrap; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
.btn { display: inline-flex; align-items: center; gap: .35rem; border: 1px solid var(--border); background: var(--surface); color: var(--text); padding: .45rem .9rem; border-radius: 6px; font: inherit; font-size: .9rem; cursor: pointer; text-decoration: none; }
.btn:hover { background: var(--surface-2); text-decoration: none; }
.btn.primary { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); }
.btn.primary:hover { filter: brightness(1.08); }
.btn.success { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: .55; cursor: default; }
.btn.sm { padding: .25rem .6rem; font-size: .8rem; }
label { display: block; font-weight: 600; font-size: .85rem; margin-bottom: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=datetime-local], textarea, select {
  width: 100%; padding: .5rem .65rem; border: 1px solid var(--border); border-radius: 6px; font: inherit; background: var(--surface); color: var(--text); }
textarea.code { font-family: var(--mono); font-size: 13px; min-height: 60vh; tab-size: 2; }
.field + .field { margin-top: .85rem; }
.alert { padding: .7rem .9rem; border-radius: 6px; margin-bottom: 1rem; }
.alert.error { background: var(--danger-bg); color: var(--danger); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: var(--warn); }
.badge { display: inline-block; padding: .1rem .5rem; border-radius: 999px; font-size: .75rem; font-weight: 600; background: var(--surface-2); color: var(--muted); }
.badge.ok { background: var(--ok-bg); color: var(--ok); }
.badge.warn { background: var(--warn-bg); color: var(--warn); }
.badge.danger { background: var(--danger-bg); color: var(--danger); }
.progressbar { height: 6px; background: var(--surface-2); border-radius: 3px; overflow: hidden; }
.progressbar > div { height: 100%; background: var(--ok); }
.kv { display: grid; grid-template-columns: max-content 1fr; gap: .25rem 1rem; font-size: .9rem; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }

/* grade de resultados */
.results-wrap { overflow-x: auto; }
.results td.cell { text-align: center; white-space: nowrap; }
.results td.cell a { display: inline-flex; align-items: center; gap: .25rem; padding: .2rem .45rem; border-radius: 6px; }
.results td.cell a:hover { background: var(--surface-2); text-decoration: none; }
.st { font-weight: 700; }
.st.completed { color: var(--ok); }
.st.passed { color: var(--ok); opacity: .7; }
.st.in_progress { color: var(--warn); }
.st.none { color: var(--border); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; }
.dot.l1 { background: var(--warn); }
.dot.l2 { background: var(--danger); }

/* ===== ambiente do laboratório ===== */
body.lab { height: 100vh; overflow: hidden; display: flex; flex-direction: column; }
.lab-main { flex: 1; display: grid; grid-template-columns: minmax(320px, 40%) 1fr; min-height: 0; }
.lab-left { display: flex; flex-direction: column; min-height: 0; border-right: 1px solid var(--border); background: var(--surface); }
.tabs { display: flex; border-bottom: 1px solid var(--border); padding: 0 .75rem; }
.tabs button { background: none; border: 0; padding: .7rem .8rem; font: inherit; font-size: .9rem; color: var(--muted); cursor: pointer; border-bottom: 2px solid transparent; }
.tabs button.active { color: var(--text); border-bottom-color: var(--brand); font-weight: 600; }
.lab-scroll { flex: 1; overflow: auto; padding: 1rem 1.25rem 2rem; }
.no-copy { user-select: none; -webkit-user-select: none; }
.instructions img { max-width: 100%; }
.param { font-family: var(--mono); background: #eef2ff; color: #3730a3; padding: 0 .3em; border-radius: 4px; }
.ex-nav { display: flex; gap: .35rem; flex-wrap: wrap; }
.ex-nav button { width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--border); background: var(--surface); cursor: pointer; font-weight: 600; font-size: .8rem; color: var(--muted); }
.ex-nav button.current { border-color: var(--brand); color: var(--brand); box-shadow: 0 0 0 2px #dbe4ff; }
.ex-nav button.completed { background: var(--ok); border-color: var(--ok); color: #fff; }
.ex-nav button.passed { background: var(--ok-bg); border-color: var(--ok); color: var(--ok); }
.ex-nav button.in_progress { border-color: var(--warn); color: var(--warn); }
.feedback { border-radius: var(--radius); padding: .8rem 1rem; margin-top: 1rem; white-space: pre-wrap; }
.feedback.ok { background: var(--ok-bg); color: #0d5c3d; }
.feedback.fail { background: var(--danger-bg); color: #8a1f1b; }
.feedback .reason { font-size: .85rem; margin-top: .35rem; opacity: .9; }
.feedback ul { margin: .5rem 0 0; padding-left: 1.1rem; font-size: .85rem; }
.hint { background: var(--warn-bg); color: #6b3f00; border-radius: 6px; padding: .6rem .8rem; margin-top: .5rem; font-size: .9rem; }
.reflection textarea { min-height: 120px; }

.lab-right { display: grid; grid-template-rows: auto 1fr 6px minmax(140px, 35%); min-height: 0; background: var(--code-bg); }
.toolbar { display: flex; gap: .5rem; align-items: center; padding: .5rem .75rem; background: #252526; border-bottom: 1px solid #333; }
.toolbar .btn { background: #333; border-color: #444; color: #eee; }
.toolbar .btn:hover { background: #3c3c3c; }
.toolbar .btn.primary { background: var(--brand); border-color: var(--brand); }
.toolbar .btn.success { background: var(--ok); border-color: var(--ok); }
.toolbar .status { color: #aaa; font-size: .8rem; margin-left: auto; }
#editor { min-height: 0; }
.splitter { background: #333; cursor: row-resize; }
.console { display: flex; flex-direction: column; min-height: 0; color: var(--code-text); font: 13px/1.45 var(--mono); }
.console-head { padding: .3rem .75rem; font-size: .75rem; color: #999; text-transform: uppercase; letter-spacing: .05em; border-bottom: 1px solid #333; display: flex; }
.console-head .spacer { flex: 1; }
.console-head button { background: none; border: 0; color: #999; cursor: pointer; font-size: .75rem; }
.console-out { flex: 1; overflow: auto; padding: .5rem .75rem; white-space: pre-wrap; word-break: break-word; }
.console-out .err { color: #f48771; }
.console-out .sys { color: #888; font-style: italic; }
.console-out .in { color: #9cdcfe; }
.console-out img { max-width: 100%; background: #fff; border-radius: 4px; margin: .4rem 0; display: block; }
.console-in { display: flex; align-items: center; border-top: 1px solid #333; padding: .3rem .75rem; }
.console-in span { color: #6a9955; margin-right: .5rem; }
.console-in input { flex: 1; background: transparent; border: 0; color: var(--code-text); font: inherit; outline: none; }
.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: #222; color: #fff; padding: .6rem 1rem; border-radius: 8px; font-size: .9rem; z-index: 100; box-shadow: var(--shadow); opacity: 0; transition: opacity .2s; pointer-events: none; }
.toast.show { opacity: 1; }

/* replay */
.replay { display: grid; grid-template-rows: auto 420px auto; border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; background: var(--code-bg); }
.replay-controls { display: flex; gap: .5rem; align-items: center; padding: .5rem .75rem; background: var(--surface); border-bottom: 1px solid var(--border); flex-wrap: wrap; }
.replay-controls input[type=range] { flex: 1; min-width: 160px; }
.replay-timeline { position: relative; height: 26px; background: var(--surface); border-top: 1px solid var(--border); }
.replay-timeline i { position: absolute; top: 6px; width: 3px; height: 14px; border-radius: 2px; }
.replay-legend { display: flex; gap: 1rem; flex-wrap: wrap; font-size: .8rem; color: var(--muted); margin-top: .5rem; }
.replay-legend i { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: .3rem; vertical-align: -1px; }
.ev-paste { background: var(--danger); } .ev-large { background: #8b5cf6; } .ev-blur { background: var(--warn); }
.ev-run { background: #64748b; } .ev-submit { background: var(--brand); } .ev-pass { background: var(--ok); }

@media (max-width: 860px) {
  body.lab { height: auto; overflow: auto; }
  .lab-main { grid-template-columns: 1fr; }
  .lab-right { height: 85vh; }
}
.console-out .vars { color: #c5e1a5; }
.terms h2 { font-size: 1rem; margin: 1.1rem 0 .4rem; }
.terms h2:first-child { margin-top: 0; }
.terms ul { padding-left: 1.2rem; }
