:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface-2: #f8f9fa;
  --border: #dde1e6;
  --text: #1f2328;
  --muted: #656d76;
  --accent: #217346;        /* Excel-grønn, brukt sparsomt */
  --accent-soft: #e6f2eb;
  --ok: #1a7f37;
  --ok-soft: #e8f5ec;
  --bad: #c62828;
  --bad-soft: #fdecec;
  --warn: #b26a00;
  --key-bg: #fbfbfc;
  --key-shadow: #c9ced6;
  --radius: 10px;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 "Segoe UI", system-ui, -apple-system, Roboto, Helvetica, Arial, sans-serif;
}

[hidden] { display: none !important; }

h1, h2, h3, h4 { margin: 0 0 .5rem; line-height: 1.25; }
h1 { font-size: 1.6rem; }
h2 { font-size: 1.35rem; }
h3 { font-size: 1.05rem; }
h4 { font-size: .95rem; }
.muted { color: var(--muted); }
.small { font-size: .82rem; }

/* ───── Topplinje ───── */
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 12px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.brand { display: flex; align-items: center; gap: 12px; }
.logo {
  width: 34px; height: 34px; border-radius: 7px;
  background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700; font-size: 18px;
}
.brand-title { font-weight: 600; }
.brand-sub { font-size: .8rem; color: var(--muted); }
.hud { display: flex; align-items: center; gap: 10px; }
.hud strong { font-variant-numeric: tabular-nums; font-size: 1.05rem; }

main { max-width: 1120px; margin: 0 auto; padding: 24px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 24px;
  margin-bottom: 16px;
}

/* ───── Knapper ───── */
.btn {
  font: inherit; cursor: pointer;
  padding: 8px 14px;
  border-radius: 7px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { background: var(--surface-2); border-color: #c4c9d0; }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; font-weight: 600; }
.btn-primary:hover:not(:disabled) { background: #1b5e3a; border-color: #1b5e3a; }
.btn-ghost { border-color: transparent; color: var(--muted); }
.btn-small { padding: 4px 10px; font-size: .85rem; }
.btn-large { padding: 12px 22px; font-size: 1rem; width: 100%; margin-top: 8px; }
.btn-link { border: none; background: none; color: var(--muted); padding: 0; text-decoration: underline; font-size: .85rem; }

/* ───── Startskjerm ───── */
.intro p { max-width: 780px; margin: 0; }
.start-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.start-grid .card { margin-bottom: 0; }
.cat-list { display: flex; flex-direction: column; gap: 4px; }
.check { display: flex; align-items: center; gap: 10px; padding: 6px 0; cursor: pointer; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }
.check .count { margin-left: auto; color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.field { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0; }
.field select { font: inherit; padding: 5px 8px; border-radius: 6px; border: 1px solid var(--border); background: var(--surface); }
.check.is-empty { opacity: .45; }
.field-block { padding: 6px 0 10px; }
.field-label { display: block; font-size: .88rem; margin-bottom: 6px; }
.segmented { display: inline-flex; border: 1px solid var(--border); border-radius: 8px; overflow: hidden; background: var(--surface); }
.segmented label { cursor: pointer; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { display: block; padding: 7px 16px; font-size: .9rem; border-left: 1px solid var(--border); color: var(--muted); user-select: none; }
.segmented label:first-child span { border-left: none; }
.segmented label:hover span { background: var(--surface-2); }
.segmented input:checked + span { background: var(--accent); color: #fff; font-weight: 600; }
.segmented input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: -3px; }
.howto { margin-top: 12px; padding: 12px 14px; background: var(--surface-2); border-radius: 8px; font-size: .9rem; }
.howto ul { margin: 0; padding-left: 18px; }
.howto li { margin: 4px 0; }
.error { color: var(--bad); min-height: 1.2em; margin: 8px 0 0; }
.history { margin-top: 16px; }
.history:empty { display: none; }
.weak-list { list-style: none; padding: 0; margin: 0 0 10px; columns: 2; }
.weak-list li { display: flex; justify-content: space-between; gap: 12px; padding: 4px 12px 4px 0; break-inside: avoid; }

/* ───── Tastecaps ───── */
kbd {
  display: inline-block;
  min-width: 1.9em;
  padding: 2px 7px;
  font: 600 .85rem/1.4 "Segoe UI", system-ui, sans-serif;
  text-align: center;
  background: var(--key-bg);
  border: 1px solid var(--key-shadow);
  border-bottom-width: 3px;
  border-radius: 5px;
  color: var(--text);
}
.chord { display: inline-flex; align-items: center; gap: 3px; white-space: nowrap; }
.plus { color: var(--muted); font-weight: 600; padding: 0 1px; }
.then { color: var(--muted); font-size: 1.2rem; padding: 0 8px; }
.or { color: var(--muted); font-size: .85rem; padding: 0 10px; }

/* ───── Spørsmålspanel ───── */
.question-panel { padding-bottom: 22px; }
.q-meta { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; }
.tag { font-size: .78rem; font-weight: 600; padding: 3px 9px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); }
.tag-level.level-1 { background: #e8f1fb; color: #1f5fa8; }
.tag-level.level-2 { background: #fff4e0; color: var(--warn); }
.tag-level.level-3 { background: #f3e8fb; color: #6b2fa0; }
.tag-muted { background: var(--surface-2); color: var(--muted); border: 1px solid var(--border); }
.q-num { margin-left: auto; color: var(--muted); font-size: .85rem; font-variant-numeric: tabular-nums; }
.progress { height: 4px; background: var(--surface-2); border-radius: 4px; overflow: hidden; margin-bottom: 18px; }
#progress-bar { height: 100%; background: var(--accent); transition: width .25s; }
#q-text { font-size: 1.3rem; font-weight: 600; max-width: 900px; }
.hint { color: var(--muted); font-size: .88rem; margin: 6px 0 0; }

.feedback { margin-top: 16px; padding: 14px 16px; border-radius: 8px; border-left: 4px solid; }
.feedback.ok { background: var(--ok-soft); border-color: var(--ok); }
.feedback.bad { background: var(--bad-soft); border-color: var(--bad); }
.fb-title { font-weight: 700; font-size: 1.05rem; margin-bottom: 6px; }
.feedback.ok .fb-title { color: var(--ok); }
.feedback.bad .fb-title { color: var(--bad); }
.fb-row { display: flex; align-items: center; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.fb-label { min-width: 110px; color: var(--muted); font-size: .88rem; }
.fb-note { margin: 8px 0 0; font-size: .88rem; color: #3d444d; }

/* ───── Svarpanel ───── */
.answer-panel { background: var(--surface-2); }
.answer-display {
  display: flex; align-items: center; gap: 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 12px 16px;
  min-height: 58px;
  margin-bottom: 16px;
}
.answer-label { font-size: .78rem; font-weight: 600; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); white-space: nowrap; }
.preview { display: flex; align-items: center; flex-wrap: wrap; gap: 2px; font-size: 1.05rem; }
.preview kbd { font-size: .95rem; }
.placeholder { color: #9aa1a9; font-size: .9rem; }
.pending kbd { border-style: dashed; background: var(--accent-soft); }
.dots { color: var(--muted); }

/* ───── Skjermtastatur ───── */
.keyboard { display: flex; gap: 20px; justify-content: center; align-items: flex-start; }
.kb-main, .kb-nav { display: flex; flex-direction: column; gap: 6px; }
.kb-row { display: flex; gap: 6px; }
.kb-main .kb-row:first-child { margin-bottom: 8px; }
.kb-nav .kb-row:nth-child(3) { margin-top: 26px; }

.key {
  --u: 46px;
  width: var(--u); height: 42px;
  font: 600 .85rem "Segoe UI", system-ui, sans-serif;
  color: var(--text);
  background: var(--key-bg);
  border: 1px solid var(--key-shadow);
  border-bottom-width: 3px;
  border-radius: 6px;
  cursor: pointer;
  user-select: none;
  transition: background .08s, transform .05s;
}
.key:hover:not(:disabled) { background: #eef1f4; }
.key:active:not(:disabled) { transform: translateY(1px); border-bottom-width: 2px; }
.key:disabled { opacity: .55; cursor: default; }
.key.w15 { width: calc(var(--u) * 1.5); }
.key.w2 { width: calc(var(--u) * 2 + 6px); }
.key.w6 { width: calc(var(--u) * 6 + 30px); }
.key.ml { margin-left: calc(var(--u) * .5); }
.key-gap { width: var(--u); visibility: hidden; }
.kb-nav .key { width: calc(var(--u) * 1.2); }
.key-mod { background: #eef0f3; }
.key-mod.active { background: var(--accent); border-color: #17532f; color: #fff; }
.kb-main .kb-row:first-child .key { height: 34px; font-size: .78rem; }

/* ───── Flervalg ───── */
.mc-area { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.mc-option {
  display: flex; align-items: center; gap: 12px;
  text-align: left; font: inherit;
  padding: 14px 16px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  cursor: pointer;
  color: var(--text);
}
.mc-option:hover:not(:disabled) { border-color: var(--accent); background: #fcfefd; }
.mc-option:disabled { cursor: default; }
.mc-letter {
  flex: none; width: 26px; height: 26px; border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 700; font-size: .8rem;
  background: var(--surface-2); border: 1px solid var(--border); color: var(--muted);
}
.mc-option.is-correct { border-color: var(--ok); background: var(--ok-soft); }
.mc-option.is-correct .mc-letter { background: var(--ok); border-color: var(--ok); color: #fff; }
.mc-option.is-wrong { border-color: var(--bad); background: var(--bad-soft); }
.mc-option.is-wrong .mc-letter { background: var(--bad); border-color: var(--bad); color: #fff; }

/* ───── Handlinger ───── */
.actions {
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  margin-top: 18px; padding-top: 16px;
  border-top: 1px solid var(--border);
}
.actions-left, .actions-right { display: flex; gap: 8px; flex-wrap: wrap; }
.actions-right { margin-left: auto; }

/* ───── Resultater ───── */
.results-head { display: flex; align-items: center; gap: 24px; }
.results-head h2 { font-size: 1.6rem; }
.score-ring {
  --size: 110px;
  width: var(--size); height: var(--size); flex: none;
  border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--surface-2) 0);
  display: grid; place-items: center;
}
.score-ring span {
  width: calc(var(--size) - 22px); height: calc(var(--size) - 22px);
  border-radius: 50%; background: var(--surface);
  display: grid; place-items: center;
  font-size: 1.5rem; font-weight: 700; font-variant-numeric: tabular-nums;
}
.cat-table { display: flex; flex-direction: column; gap: 10px; }
.cat-row { display: grid; grid-template-columns: 240px 1fr 110px 130px; align-items: center; gap: 14px; }
.cat-name { font-weight: 500; }
.bar { height: 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: 6px; overflow: hidden; }
.bar-fill { height: 100%; }
.bar-fill.good { background: var(--ok); }
.bar-fill.mid { background: #d29922; }
.bar-fill.low { background: var(--bad); }
.cat-score { font-variant-numeric: tabular-nums; color: var(--muted); font-size: .9rem; text-align: right; }
.badge { font-size: .75rem; font-weight: 600; padding: 3px 8px; border-radius: 999px; background: var(--bad-soft); color: var(--bad); justify-self: start; }
.badge-ok { background: var(--ok-soft); color: var(--ok); }

.missed { width: 100%; border-collapse: collapse; }
.missed th { text-align: left; font-size: .8rem; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); font-weight: 600; padding: 8px 10px; border-bottom: 1px solid var(--border); }
.missed td { padding: 10px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.missed tr:last-child td { border-bottom: none; }
.results-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* ───── Mindre skjermer ───── */
@media (max-width: 960px) {
  .key { --u: 36px; height: 38px; font-size: .78rem; }
  .keyboard { flex-direction: column; align-items: center; }
  .kb-nav .kb-row:nth-child(3) { margin-top: 6px; }
  .cat-row { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 720px) {
  main { padding: 16px; }
  .start-grid, .mc-area { grid-template-columns: 1fr; }
  .key { --u: 24px; height: 34px; font-size: .68rem; border-radius: 4px; }
  .kb-row { gap: 3px; }
  .key.w6 { width: calc(var(--u) * 6 + 15px); }
  .key.w2 { width: calc(var(--u) * 2 + 3px); }
  .weak-list { columns: 1; }
}
