/* Layout: sticky console header with tabs; one working column (max 920px); domain rows read like a SOC status board. */
:root {
  --bg: #F2F5F6;
  --surface: #FFFFFF;
  --ink: #13222A;
  --muted: #586B75;
  --line: #D6DFE3;
  --accent: #0D6A70;
  --accent-ink: #FFFFFF;
  --accent-soft: #DCEEEF;
  --ok: #1D7646;
  --ok-soft: #E1F2E8;
  --bad: #B0302A;
  --bad-soft: #F8E3E1;
  --warn: #9A6200;
  --warn-soft: #FBF0D6;
  --crit: #7A1B5C;
  --track: #E3EAED;
  --f-display: "Familjen Grotesk", "Segoe UI", system-ui, sans-serif;
  --f-body: "IBM Plex Sans", "Segoe UI", system-ui, sans-serif;
  --f-mono: "IBM Plex Mono", ui-monospace, Consolas, monospace;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0E1418; --surface: #161F25; --ink: #E2EAEE; --muted: #91A3AD; --line: #283740;
    --accent: #4DB5BB; --accent-ink: #062226; --accent-soft: #15353A;
    --ok: #4CC283; --ok-soft: #14301F; --bad: #F07A70; --bad-soft: #3A1B19; --warn: #E0A940; --warn-soft: #3A2E10; --crit: #E68BC4; --track: #22303A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #0E1418; --surface: #161F25; --ink: #E2EAEE; --muted: #91A3AD; --line: #283740;
  --accent: #4DB5BB; --accent-ink: #062226; --accent-soft: #15353A;
  --ok: #4CC283; --ok-soft: #14301F; --bad: #F07A70; --bad-soft: #3A1B19; --warn: #E0A940; --warn-soft: #3A2E10; --crit: #E68BC4; --track: #22303A;
  color-scheme: dark;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
img { max-width: 100%; }
:root { padding-block: env(safe-area-inset-top, 0px) env(safe-area-inset-bottom, 0px); }
body { margin: 0; background: var(--bg); color: var(--ink); font-family: var(--f-body); font-size: 15px; line-height: 1.55; }
body::before { content: ""; position: fixed; inset: 0 0 auto; height: env(safe-area-inset-top, 0px); z-index: 10; background: var(--surface); }
button { font: inherit; color: inherit; cursor: pointer; }
button:focus-visible, select:focus-visible, textarea:focus-visible, .card3d:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
h1, h2, h3 { font-family: var(--f-display); text-wrap: balance; margin: 0; line-height: 1.2; }
.mono { font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.label { font-size: 11.5px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 600; }

header.top { position: sticky; top: env(safe-area-inset-top, 0px); z-index: 5; background: var(--surface); border-bottom: 1px solid var(--line); }
.wrap { max-width: 920px; margin: 0 auto; padding-left: max(16px, env(safe-area-inset-left, 0px)); padding-right: max(16px, env(safe-area-inset-right, 0px)); }
.top .wrap { display: flex; align-items: center; gap: 16px; flex-wrap: wrap; padding-block: 12px 0; }
.brand { display: flex; align-items: baseline; gap: 10px; flex: 1 1 auto; min-width: 0; }
.brand h1 { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.brand .code { font-family: var(--f-mono); font-size: 12px; color: var(--accent); border: 1px solid var(--accent); border-radius: 4px; padding: 1px 6px; }
.sync { font-size: 12.5px; color: var(--muted); display: flex; align-items: center; gap: 6px; }
.sync i { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); display: inline-block; }
.sync.on i { background: var(--ok); }
nav.tabs { display: flex; gap: 4px; width: 100%; overflow-x: auto; }
nav.tabs button { background: none; border: 0; padding: 10px 14px 11px; font-weight: 500; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; }
nav.tabs button[aria-selected="true"] { color: var(--ink); border-bottom-color: var(--accent); }
nav.tabs button:hover { color: var(--ink); }

main { padding-block: 24px 64px; }
section.view { display: grid; gap: 20px; }
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 20px; min-width: 0; }
.row { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; }
.grow { flex: 1 1 auto; }

.btn { border: 1px solid var(--line); background: var(--surface); border-radius: 7px; padding: 8px 14px; font-weight: 500; }
.btn:hover { border-color: var(--muted); }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.primary:hover { filter: brightness(1.08); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn.small { padding: 5px 10px; font-size: 13px; }
select { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 7px 10px; }

/* Overview */
.hero { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 24px; align-items: center; }
.hero h2 { font-size: 26px; }
.hero p { margin: 6px 0 0; color: var(--muted); max-width: 52ch; }
.gauge { position: relative; width: 132px; height: 132px; }
.gauge svg { width: 100%; height: 100%; transform: rotate(-90deg); }
.gauge .val { position: absolute; inset: 0; display: grid; place-content: center; text-align: center; }
.gauge .val b { font-family: var(--f-display); font-size: 30px; line-height: 1; }
.gauge .val span { font-size: 11px; color: var(--muted); letter-spacing: .06em; text-transform: uppercase; margin-top: 4px; }
.facts { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 1px; background: var(--line); border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.facts div { background: var(--surface); padding: 12px 14px; }
.facts b { display: block; font-family: var(--f-mono); font-size: 18px; font-weight: 500; }
.domains { display: grid; gap: 0; }
.dom { display: grid; grid-template-columns: 52px minmax(0, 1fr) 150px 64px; gap: 14px; align-items: center; padding: 14px 0; border-top: 1px solid var(--line); }
.dom:first-of-type { border-top: 0; }
.dom .num { font-family: var(--f-mono); color: var(--accent); font-weight: 500; }
.dom .name { font-weight: 600; }
.dom .sub { font-size: 12.5px; color: var(--muted); }
.bar { height: 8px; background: var(--track); border-radius: 4px; position: relative; overflow: hidden; }
.bar > span { position: absolute; inset: 0 auto 0 0; border-radius: 4px; background: var(--accent); }
.bar .target { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--ink); opacity: .35; left: 80%; }
.pct { text-align: right; font-family: var(--f-mono); font-variant-numeric: tabular-nums; }
.pill { display: inline-block; font-size: 11.5px; font-weight: 600; padding: 2px 8px; border-radius: 999px; letter-spacing: .02em; }
.pill.ok { background: var(--ok-soft); color: var(--ok); }
.pill.bad { background: var(--bad-soft); color: var(--bad); }
.pill.mid { background: var(--accent-soft); color: var(--accent); }
.pill.none { background: var(--track); color: var(--muted); }
.topics { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.topics span { font-size: 12px; border: 1px solid var(--line); border-radius: 5px; padding: 1px 7px; color: var(--muted); }
table.hist { width: 100%; border-collapse: collapse; font-size: 14px; }
table.hist td, table.hist th { padding: 8px 6px; border-top: 1px solid var(--line); text-align: left; }
table.hist th { font-weight: 600; color: var(--muted); font-size: 12px; text-transform: uppercase; letter-spacing: .06em; border-top: 0; }
table.hist td.r, table.hist th.r { text-align: right; }
.empty { color: var(--muted); padding: 8px 0; }

/* Practice */
.qhead { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; align-items: center; margin-bottom: 12px; }
.progress { height: 4px; background: var(--track); border-radius: 2px; overflow: hidden; margin-bottom: 18px; }
.progress span { display: block; height: 100%; background: var(--accent); transition: width .25s; }
.qtext { font-size: 17px; font-weight: 500; margin: 0 0 16px; max-width: 68ch; }
.qtext, .opt, .explain, .x-item, .face .def { overflow-wrap: anywhere; }
.opts { display: grid; gap: 8px; }
.opt { display: grid; grid-template-columns: 28px minmax(0, 1fr); gap: 10px; text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 11px 12px; align-items: start; }
.opt:hover:not(:disabled) { border-color: var(--accent); }
.opt .k { font-family: var(--f-mono); font-size: 13px; width: 24px; height: 24px; border-radius: 5px; display: grid; place-content: center; background: var(--track); color: var(--muted); }
.opt.right { border-color: var(--ok); background: var(--ok-soft); }
.opt.right .k { background: var(--ok); color: var(--surface); }
.opt.wrong { border-color: var(--bad); background: var(--bad-soft); }
.opt.wrong .k { background: var(--bad); color: var(--surface); }
.opt:disabled { cursor: default; }
.explain { margin-top: 16px; border-left: 3px solid var(--accent); padding: 4px 0 4px 14px; max-width: 70ch; }
.explain .verdict { font-weight: 600; }
.verdict.ok { color: var(--ok); } .verdict.bad { color: var(--bad); }
.ai-out { margin-top: 10px; font-size: 14.5px; }
.ai-out p { margin: 0 0 8px; }
.ai-out ul { margin: 0 0 8px; padding-left: 20px; }
.ai-out code, .msg code { font-family: var(--f-mono); font-size: 13px; background: var(--track); padding: 1px 4px; border-radius: 3px; }
.score { font-family: var(--f-display); font-size: 44px; font-weight: 700; line-height: 1; }
.tag { font-family: var(--f-mono); font-size: 12px; color: var(--accent); }
.gen-note { font-size: 13px; color: var(--muted); }

/* Flashcards */
.deckbar { display: flex; gap: 12px; flex-wrap: wrap; align-items: center; justify-content: space-between; }
.card3d { perspective: 1200px; height: 260px; cursor: pointer; border-radius: 12px; }
.card3d .inner { position: relative; width: 100%; height: 100%; transition: transform .45s; transform-style: preserve-3d; }
.card3d.flipped .inner { transform: rotateY(180deg); }
.face { position: absolute; inset: 0; backface-visibility: hidden; border: 1px solid var(--line); border-radius: 12px; background: var(--surface); padding: 24px; display: flex; flex-direction: column; justify-content: center; gap: 10px; overflow: auto; }
.face.back { transform: rotateY(180deg); background: var(--accent-soft); border-color: var(--accent); }
.face .term { font-family: var(--f-display); font-size: 30px; font-weight: 700; }
.face .def { font-size: 16px; max-width: 62ch; }
.face .hint { font-size: 12.5px; color: var(--muted); }

/* Tutor */
.chat { display: grid; gap: 12px; max-height: 60vh; overflow-y: auto; padding-right: 4px; }
.msg { max-width: 85%; padding: 10px 14px; border-radius: 10px; font-size: 14.5px; min-width: 0; overflow-wrap: anywhere; }
.msg p { margin: 0 0 8px; } .msg p:last-child { margin: 0; }
.msg ul { margin: 0 0 8px; padding-left: 20px; }
.msg.me { justify-self: end; background: var(--accent); color: var(--accent-ink); }
.msg.me code { background: rgba(255,255,255,.18); }
.msg.ai { justify-self: start; background: var(--bg); border: 1px solid var(--line); }
.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip { border: 1px solid var(--line); background: var(--surface); border-radius: 999px; padding: 5px 12px; font-size: 13px; }
.chip:hover { border-color: var(--accent); color: var(--accent); }
.composer { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 8px; align-items: end; }
textarea { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; resize: vertical; min-height: 46px; width: 100%; }
.notice { font-size: 13.5px; color: var(--muted); background: var(--bg); border: 1px dashed var(--line); border-radius: 8px; padding: 10px 12px; }

@media (max-width: 640px) {
  .hero { grid-template-columns: 1fr; }
  .gauge { justify-self: start; }
  .facts { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .dom { grid-template-columns: 40px minmax(0, 1fr) 56px; }
  .dom .barcell { grid-column: 2 / 4; }
  .dom .pct { grid-row: 1; grid-column: 3; }
  .msg { max-width: 100%; }
  .card3d { height: 300px; }
}
@media (prefers-reduced-motion: reduce) {
  .card3d .inner, .progress span { transition: none; }
}

/* Log labs */
.lab-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(260px, 1fr)); gap: 12px; }
.lab-card { text-align: left; background: var(--surface); border: 1px solid var(--line); border-radius: 10px; padding: 16px; display: grid; gap: 6px; align-content: start; min-width: 0; }
.lab-card:hover { border-color: var(--accent); }
.lab-card h3 { font-size: 17px; }
.lab-card .src { font-size: 13px; color: var(--muted); }
.lab-card .meta { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-top: 6px; }
.step { font-weight: 600; margin-bottom: 8px; display: flex; gap: 8px; align-items: baseline; flex-wrap: wrap; }
.step > .mono:first-child { color: var(--accent); }
.logwrap { overflow-x: auto; border: 1px solid var(--line); border-radius: 8px; background: var(--bg); }
table.log { border-collapse: collapse; font-family: var(--f-mono); font-size: 12.5px; width: 100%; font-variant-numeric: tabular-nums; }
table.log th { position: sticky; top: 0; text-align: left; font-weight: 500; color: var(--muted); background: var(--surface); padding: 7px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.log td { padding: 6px 10px; border-bottom: 1px solid var(--line); white-space: nowrap; }
table.log tr.line { cursor: pointer; }
table.log tr.line:hover td { background: var(--track); }
table.log tr.line td:first-child { box-shadow: inset 3px 0 0 transparent; }
table.log tr.line.flag td { background: var(--accent-soft); }
table.log tr.line.flag td:first-child { box-shadow: inset 3px 0 0 var(--accent); }
table.log tr.line:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }
table.log.graded tr.line { cursor: default; }
table.log tr.hit td { background: var(--ok-soft); }
table.log tr.hit td:first-child { box-shadow: inset 3px 0 0 var(--ok); }
table.log tr.miss td { background: var(--warn-soft); }
table.log tr.miss td:first-child { box-shadow: inset 3px 0 0 var(--warn); }
table.log tr.false td { background: var(--bad-soft); }
table.log tr.false td:first-child { box-shadow: inset 3px 0 0 var(--bad); }
table.log tr.note td { white-space: normal; font-family: var(--f-body); font-size: 13px; color: var(--muted); padding-top: 0; }
table.log tr.note b { font-weight: 600; }
.mk { font-weight: 600; }
.mk.ok { color: var(--ok); } .mk.bad { color: var(--bad); } .mk.warn { color: var(--warn); }
.opt.sel { border-color: var(--accent); background: var(--accent-soft); }
.opt.sel .k { background: var(--accent); color: var(--accent-ink); }
.lab-q { margin-top: 4px; }
.lab-q + .lab-q { margin-top: 18px; }

/* CVSS */
input[type="text"] { font: inherit; color: var(--ink); background: var(--surface); border: 1px solid var(--line); border-radius: 7px; padding: 6px 10px; min-width: 0; }
input[type="text"]:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.seg { display: inline-flex; gap: 3px; padding: 3px; border: 1px solid var(--line); border-radius: 8px; background: var(--surface); }
.seg button { border: 0; background: none; padding: 6px 14px; border-radius: 6px; font-weight: 500; color: var(--muted); }
.seg button[aria-pressed="true"] { background: var(--accent-soft); color: var(--accent); }
.cv-layout { display: grid; grid-template-columns: minmax(0, 1fr) 300px; gap: 20px; align-items: start; }
.cv-score { position: sticky; top: calc(env(safe-area-inset-top, 0px) + 112px); }
.cv-row { display: grid; grid-template-columns: 170px minmax(0, 1fr); gap: 12px; align-items: center; padding: 9px 0; border-top: 1px solid var(--line); }
.cv-row:first-child { border-top: 0; padding-top: 0; }
.cv-row:last-child { padding-bottom: 0; }
.cv-name { font-weight: 600; font-size: 14px; }
.cv-name .mono { color: var(--muted); font-weight: 400; font-size: 12px; margin-left: 6px; }
.cv-seg { display: flex; flex-wrap: wrap; gap: 6px; }
.cv-opt { border: 1px solid var(--line); background: var(--surface); border-radius: 6px; padding: 5px 11px; font-size: 13.5px; }
.cv-opt:hover:not(:disabled) { border-color: var(--accent); }
.cv-opt.on { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.cv-opt.right { background: var(--ok-soft); border-color: var(--ok); color: var(--ok); font-weight: 600; }
.cv-opt.wrong { background: var(--bad-soft); border-color: var(--bad); color: var(--bad); text-decoration: line-through; }
.cv-opt:disabled { cursor: default; }
.cv-num { font-family: var(--f-display); font-size: 60px; font-weight: 700; line-height: 1; font-variant-numeric: tabular-nums; }
.sevtext-none { color: var(--muted); } .sevtext-low { color: var(--ok); } .sevtext-med { color: var(--warn); }
.sevtext-high { color: var(--bad); } .sevtext-crit { color: var(--crit); }
.pill.sev-none { background: var(--track); color: var(--muted); }
.pill.sev-low { background: var(--ok-soft); color: var(--ok); }
.pill.sev-med { background: var(--warn-soft); color: var(--warn); }
.pill.sev-high { background: var(--bad-soft); color: var(--bad); }
.pill.sev-crit { background: var(--crit); color: var(--surface); }
.cv-scale { position: relative; display: grid; grid-template-columns: 40fr 30fr 20fr 10fr; gap: 2px; height: 8px; }
.cv-scale span { border-radius: 2px; opacity: .85; }
.cv-scale .s-low { background: var(--ok); } .cv-scale .s-med { background: var(--warn); }
.cv-scale .s-high { background: var(--bad); } .cv-scale .s-crit { background: var(--crit); }
.cv-marker { position: absolute; top: -5px; width: 4px; height: 18px; border-radius: 2px; background: var(--ink); box-shadow: 0 0 0 2px var(--surface); transform: translateX(-50%); transition: left .25s; }
.cv-ticks { position: relative; height: 16px; font-size: 11px; color: var(--muted); margin-top: 4px; }
.cv-ticks span { position: absolute; transform: translateX(-50%); }
.cv-ticks span:nth-child(1) { left: 0; transform: none; } .cv-ticks span:nth-child(2) { left: 40%; }
.cv-ticks span:nth-child(3) { left: 70%; } .cv-ticks span:nth-child(4) { left: 90%; }

.cv-vec { display: block; font-family: var(--f-mono); font-size: 12.5px; background: var(--bg); border: 1px solid var(--line); border-radius: 6px; padding: 8px 10px; margin-top: 6px; overflow-wrap: anywhere; }
.cv-mean { display: grid; gap: 10px; }
.cv-m { display: grid; grid-template-columns: 52px minmax(0, 1fr); gap: 10px; font-size: 14px; max-width: 80ch; }
.cv-m .mono { color: var(--accent); }
.cv-vecs { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 12px; }
table.cv-why td { vertical-align: top; }
table.cv-why td:last-child { min-width: 240px; }
@media (max-width: 760px) {
  .cv-layout { grid-template-columns: 1fr; }
  .cv-score { position: static; }
}
@media (max-width: 640px) {
  .cv-row { grid-template-columns: 1fr; gap: 6px; }
}
@media (prefers-reduced-motion: reduce) { .cv-marker { transition: none; } }
#cv-paste { flex: 1 1 0; width: 0; }

/* Mock exam */
.x-intro { margin: 6px 0 14px; color: var(--muted); max-width: 64ch; }
#x-setup .facts { margin-bottom: 12px; }
#x-note { margin: 0 0 14px; }
#x-past:not(:empty) { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.x-timer { font-size: 17px; font-weight: 500; padding: 2px 10px; border-radius: 6px; background: var(--track); }
.x-timer.warn { background: var(--warn-soft); color: var(--warn); }
.x-timer.low { background: var(--bad-soft); color: var(--bad); }
.x-nav { margin-top: 18px; }
#x-flag[aria-pressed="true"] { border-color: var(--warn); background: var(--warn-soft); color: var(--warn); }
.x-map { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.x-map summary { cursor: pointer; font-weight: 600; }
.x-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(40px, 1fr)); gap: 6px; margin-top: 12px; }
.x-cell { font-family: var(--f-mono); font-size: 12.5px; padding: 6px 0; border: 1px solid var(--line); border-radius: 6px; background: var(--surface); color: var(--muted); }
.x-cell:hover { border-color: var(--accent); }
.x-cell.ans { background: var(--accent-soft); border-color: var(--accent-soft); color: var(--accent); }
.x-cell.flag { box-shadow: inset 0 -3px 0 var(--warn); }
.x-cell.cur { border-color: var(--ink); color: var(--ink); font-weight: 600; }
.x-foot { margin-top: 18px; padding-top: 14px; border-top: 1px solid var(--line); }
.x-confirm { margin-top: 12px; }
.x-scale-note { max-width: 70ch; margin: 10px 0 6px; }
.x-item { padding: 14px 0; border-top: 1px solid var(--line); }
.x-item:first-child { border-top: 0; }
.x-item .qhead { margin-bottom: 4px; }
.x-item p { margin: 0 0 8px; max-width: 70ch; font-weight: 500; }
.x-ans { display: grid; gap: 2px; font-size: 14px; }
.x-why { font-size: 14px; color: var(--muted); margin-top: 6px; max-width: 70ch; }
