:root {
  --bg: #eef2f6;
  --grid: rgba(47, 91, 211, 0.07);
  --surface: #ffffff;
  --surface-2: #f5f7fa;
  --ink: #16212d;
  --muted: #566677;
  --line: #d4dce5;
  --accent: #2f5bd3;
  --accent-ink: #ffffff;
  --accent-soft: #e4ebfb;
  --mark: #ffe46b;
  --mark-ink: #1a1a1a;
  --ok: #1c7f47;
  --ok-soft: #e0f3e7;
  --bad: #bf342c;
  --bad-soft: #fbe6e4;
  --warn-soft: #fff4d6;
  --warn: #8a5b00;
  --facit: #fff8e1;
  --facit-line: #ecd48a;
  --wc-substantiv: #2f5bd3;
  --wc-verb: #1c7f47;
  --wc-adjektiv: #c2410c;
  --wc-adverb: #7c3aed;
  --wc-pronomen: #0e7490;
  --wc-prepositioner: #be185d;
  --wc-rakneord: #475569;
  --shadow: 0 1px 2px rgba(22, 33, 45, 0.06), 0 4px 16px rgba(22, 33, 45, 0.05);
  --radius: 14px;
  --display: 'Bricolage Grotesque', 'Segoe UI', system-ui, sans-serif;
  --body: 'Atkinson Hyperlegible', 'Segoe UI', system-ui, -apple-system, sans-serif;
  --mono: ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f151c;
    --grid: rgba(134, 168, 255, 0.05);
    --surface: #17202a;
    --surface-2: #1c2733;
    --ink: #e3eaf2;
    --muted: #93a3b3;
    --line: #2b3a48;
    --accent: #86a8ff;
    --accent-ink: #0f151c;
    --accent-soft: #1f2e52;
    --mark: #e2c341;
    --mark-ink: #111111;
    --ok: #5bc987;
    --ok-soft: #16331f;
    --bad: #ff7d73;
    --bad-soft: #3b1c1a;
    --warn-soft: #3a2f12;
    --warn: #f0c35a;
    --facit: #2a2514;
    --facit-line: #5e5122;
    --wc-substantiv: #86a8ff;
    --wc-verb: #5bc987;
    --wc-adjektiv: #fb923c;
    --wc-adverb: #b794f6;
    --wc-pronomen: #4fc3d9;
    --wc-prepositioner: #f472b6;
    --wc-rakneord: #a0aec0;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 4px 16px rgba(0, 0, 0, 0.25);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  font: 16px/1.55 var(--body);
  color: var(--ink);
  background-color: var(--bg);
  background-image: linear-gradient(var(--grid) 1px, transparent 1px),
    linear-gradient(90deg, var(--grid) 1px, transparent 1px);
  background-size: 22px 22px;
  min-height: 100vh;
}
h1, h2, h3 { font-family: var(--display); line-height: 1.2; text-wrap: balance; margin: 0; }
h1 { font-size: clamp(1.6rem, 4vw, 2.1rem); font-weight: 700; letter-spacing: -0.01em; }
h2 { font-size: 1.3rem; font-weight: 650; }
h3 { font-size: 1.05rem; font-weight: 650; }
p { margin: 0; }
a { color: var(--accent); }
button, input, select, textarea { font: inherit; color: inherit; }
img { max-width: 100%; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--accent); outline-offset: 2px; border-radius: 6px; }
mark { background: var(--mark); color: var(--mark-ink); padding: 0 2px; border-radius: 3px; }
.num { font-variant-numeric: tabular-nums; }

/* ---------- Ramverk ---------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--surface) 92%, transparent);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--line);
  padding-top: env(safe-area-inset-top, 0px);
}
.topbar-inner {
  max-width: 1040px; margin: 0 auto; padding: 10px 16px 0;
  display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px;
}
.brand { display: flex; align-items: center; gap: 10px; font-family: var(--display); font-weight: 750; font-size: 1.3rem; text-decoration: none; color: var(--ink); }
.brand-mark { width: 30px; height: 30px; flex: none; }
.who { margin-left: auto; display: flex; align-items: center; gap: 10px; font-size: 0.92rem; color: var(--muted); }
.who b { color: var(--ink); font-weight: 700; }
.role-pill { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; padding: 2px 8px; border-radius: 999px; background: var(--accent-soft); color: var(--accent); font-weight: 700; }
.tabs { width: 100%; display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 4px -4px 0; padding: 0 4px; }
.tabs::-webkit-scrollbar { display: none; }
.tabs a {
  flex: none; padding: 10px 14px 12px; text-decoration: none; color: var(--muted); font-weight: 700;
  border-bottom: 3px solid transparent; white-space: nowrap;
}
.tabs a:hover { color: var(--ink); }
.tabs a[aria-current='page'] { color: var(--accent); border-bottom-color: var(--accent); }
main { max-width: 1040px; margin: 0 auto; padding: 24px 16px 80px; display: grid; gap: 20px; }
.page-head { display: flex; flex-wrap: wrap; align-items: end; justify-content: space-between; gap: 12px; }
.page-head p { color: var(--muted); margin-top: 4px; max-width: 60ch; }

/* ---------- Byggstenar ---------- */
.panel { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px; box-shadow: var(--shadow); }
.panel > h2, .panel > h3 { margin-bottom: 12px; }
.stack { display: grid; gap: 12px; }
.row { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; }
.row > .field { flex: 1 1 160px; }
.row > .field.narrow { flex: 0 1 110px; }
.field { display: grid; gap: 4px; min-width: 0; }
.field > label, .label { font-size: 0.82rem; font-weight: 700; color: var(--muted); letter-spacing: 0.02em; }
.help { font-size: 0.85rem; color: var(--muted); }
input[type='text'], input[type='email'], input[type='password'], input[type='search'], input[type='number'], select, textarea {
  width: 100%; padding: 10px 12px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface-2); min-height: 44px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--accent); background: var(--surface); }
textarea { resize: vertical; line-height: 1.5; }
input[type='file'] { font-size: 0.9rem; max-width: 100%; }
input[type='color'] { width: 44px; height: 44px; padding: 2px; border: 1.5px solid var(--line); border-radius: 10px; background: var(--surface-2); }

.btn, button.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 44px; padding: 8px 16px; border-radius: 10px; border: 1.5px solid var(--line);
  background: var(--surface); color: var(--ink); font-weight: 700; cursor: pointer; text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: var(--accent); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-ink); }
.btn.primary:hover { filter: brightness(1.07); }
.btn.danger { color: var(--bad); }
.btn.danger:hover { border-color: var(--bad); }
.btn.small { min-height: 34px; padding: 4px 10px; font-size: 0.88rem; }
.btn:disabled { opacity: 0.55; cursor: progress; }
.link { background: none; border: none; padding: 0; color: var(--accent); font-weight: 700; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
.back { font-weight: 700; text-decoration: none; }

.chip { display: inline-flex; align-items: center; gap: 6px; font-size: 0.8rem; font-weight: 700; padding: 3px 10px; border-radius: 999px; background: var(--surface-2); border: 1px solid var(--line); white-space: nowrap; }
.chip i { width: 9px; height: 9px; border-radius: 50%; background: var(--c, var(--accent)); }
.badge { display: inline-block; font-size: 0.78rem; font-weight: 700; padding: 2px 8px; border-radius: 6px; background: var(--warn-soft); color: var(--warn); }
.muted { color: var(--muted); }
.empty { text-align: center; color: var(--muted); padding: 32px 16px; border: 2px dashed var(--line); border-radius: var(--radius); }
.notice { padding: 12px 14px; border-radius: 10px; background: var(--warn-soft); color: var(--warn); font-size: 0.92rem; }
.job { display: flex; align-items: center; gap: 10px; font-size: 0.92rem; color: var(--muted); }
.job::before { content: ''; width: 16px; height: 16px; border-radius: 50%; border: 2.5px solid var(--line); border-top-color: var(--accent); animation: spin 0.9s linear infinite; flex: none; }
.job.error { color: var(--bad); }
.job.error::before { display: none; }
@keyframes spin { to { transform: rotate(360deg); } }
.filters { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding-bottom: 2px; }
.filters button { flex: none; min-height: 38px; padding: 6px 14px; border-radius: 999px; border: 1.5px solid var(--line); background: var(--surface); font-weight: 700; cursor: pointer; display: inline-flex; gap: 6px; align-items: center; }
.filters button i { width: 9px; height: 9px; border-radius: 50%; background: var(--c); }
.filters button[aria-pressed='true'] { background: var(--ink); color: var(--surface); border-color: var(--ink); }

.seg { display: inline-flex; flex-wrap: wrap; gap: 4px; padding: 4px; border-radius: 12px; background: var(--surface-2); border: 1px solid var(--line); }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: block; padding: 7px 14px; border-radius: 9px; font-weight: 700; color: var(--muted); }
.seg input:checked + span { background: var(--surface); color: var(--ink); box-shadow: var(--shadow); }
.seg input:focus-visible + span { outline: 3px solid var(--accent); }

details.panel > summary { cursor: pointer; font-family: var(--display); font-weight: 650; font-size: 1.1rem; list-style: none; display: flex; align-items: center; gap: 10px; }
details.panel > summary::-webkit-details-marker { display: none; }
details.panel > summary::before { content: '+'; display: grid; place-items: center; width: 28px; height: 28px; border-radius: 8px; background: var(--accent); color: var(--accent-ink); font-family: var(--body); font-weight: 700; }
details.panel[open] > summary::before { content: '−'; }
details.panel[open] > summary { margin-bottom: 16px; }

/* ---------- Uppgiftslistor ---------- */
.sets { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.set-card { display: grid; gap: 10px; align-content: start; text-decoration: none; color: inherit; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); transition: transform 0.12s, border-color 0.12s; }
.set-card:hover { border-color: var(--accent); transform: translateY(-2px); }
.set-card h3 { font-size: 1.12rem; }
.set-meta { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; font-size: 0.85rem; color: var(--muted); }
.progress { display: grid; gap: 6px; }
.prog-row { display: grid; grid-template-columns: minmax(60px, auto) 1fr auto; gap: 10px; align-items: center; font-size: 0.85rem; }
.bar { height: 8px; border-radius: 99px; background: var(--surface-2); border: 1px solid var(--line); overflow: hidden; }
.bar b { display: block; height: 100%; background: var(--ok); border-radius: 99px; }

.set-head { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 14px; align-items: start; }
.set-head .eyebrow { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; margin-bottom: 8px; font-size: 0.88rem; color: var(--muted); }
.set-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.score { margin-top: 8px; font-weight: 700; }
.tasks { list-style: none; margin: 0; padding: 0; display: grid; gap: 12px; }
.task { display: grid; grid-template-columns: 40px 1fr; gap: 14px; background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.task.is-ok { border-color: color-mix(in srgb, var(--ok) 55%, var(--line)); }
.task.is-bad { border-color: color-mix(in srgb, var(--bad) 45%, var(--line)); }
.task-n { width: 40px; height: 40px; border-radius: 50%; display: grid; place-items: center; font-family: var(--display); font-weight: 700; background: var(--accent-soft); color: var(--accent); }
.task.is-ok .task-n { background: var(--ok-soft); color: var(--ok); }
.task-main { display: grid; gap: 10px; min-width: 0; }
.q { white-space: pre-wrap; font-size: 1.08rem; overflow-wrap: anywhere; }
.answer { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.answer input, .answer textarea { flex: 1 1 180px; font-size: 1.1rem; }
.answer .unit { font-weight: 700; color: var(--muted); }
.verdict { font-size: 1.7rem; line-height: 1; min-width: 1.7rem; }
.verdict.pop { animation: pop 0.35s ease-out; }
@keyframes pop { 0% { transform: scale(0.4); } 70% { transform: scale(1.2); } 100% { transform: scale(1); } }
.feedback { font-size: 0.95rem; padding: 8px 12px; border-radius: 10px; background: var(--surface-2); }
.feedback.ok { background: var(--ok-soft); color: var(--ok); }
.feedback.bad { background: var(--bad-soft); color: var(--bad); }
.hint { padding: 10px 12px; border-radius: 10px; background: var(--accent-soft); font-size: 0.96rem; }
.howto { border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; background: var(--ok-soft); }
.howto summary { cursor: pointer; font-weight: 700; color: var(--ok); }
.howto p { margin-top: 8px; }
pre.steps { font: 0.98rem/1.6 var(--mono); white-space: pre-wrap; overflow-wrap: anywhere; margin: 8px 0 0; padding: 10px 12px; background: var(--surface); border-radius: 8px; border: 1px solid var(--line); }
.facit { border: 1.5px dashed var(--facit-line); background: var(--facit); border-radius: 10px; padding: 12px 14px; display: grid; gap: 8px; }
.facit-label { font-size: 0.74rem; text-transform: uppercase; letter-spacing: 0.08em; font-weight: 700; color: var(--warn); }
.facit-answer { font-size: 1.15rem; font-weight: 700; }
.facit details summary { cursor: pointer; font-weight: 700; }
.results { display: flex; flex-wrap: wrap; gap: 6px; }
.res { font-size: 0.85rem; padding: 4px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); }
.res.ok { background: var(--ok-soft); border-color: transparent; }
.res.bad { background: var(--bad-soft); border-color: transparent; }
.task-tools { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.kind { font-size: 0.78rem; color: var(--muted); font-weight: 700; }
.test-answer { border-top: 1px solid var(--line); padding-top: 10px; }

/* ---------- Sök & sidvisning ---------- */
.hits { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.hit a { display: grid; gap: 6px; padding: 14px 16px; border-radius: 12px; background: var(--surface); border: 1px solid var(--line); text-decoration: none; color: inherit; }
.hit a:hover { border-color: var(--accent); }
.hit-head { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; font-size: 0.9rem; }
.page-no { font-family: var(--display); font-weight: 700; color: var(--accent); }
.viewer { display: grid; grid-template-columns: minmax(0, 1.1fr) minmax(0, 1fr); gap: 16px; align-items: start; }
.viewer .canvas-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px; overflow: auto; }
.viewer canvas { width: 100%; height: auto; display: block; border-radius: 6px; background: #fff; }
.page-text { white-space: pre-wrap; overflow-wrap: anywhere; font-size: 1rem; line-height: 1.65; max-height: 75vh; overflow: auto; }
.pager { display: flex; flex-wrap: wrap; gap: 8px; align-items: center; }
.pager input { width: 90px; }
.view-toggle { display: none; }

/* ---------- Ordklasser ---------- */
.checks { display: flex; flex-wrap: wrap; gap: 8px; }
.checks label { display: inline-flex; align-items: center; gap: 8px; padding: 8px 12px; border-radius: 10px; border: 1.5px solid var(--line); background: var(--surface-2); cursor: pointer; font-weight: 700; }
.checks label:has(input:checked) { border-color: var(--c); background: var(--surface); }
.checks input { accent-color: var(--c); width: 18px; height: 18px; }
.wc-groups { display: grid; gap: 14px; grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); align-items: start; }
.wc-group { background: var(--surface); border: 1px solid var(--line); border-top: 5px solid var(--c); border-radius: var(--radius); padding: 14px 16px; }
.wc-group header { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; }
.wc-group h3 { color: var(--c); text-transform: capitalize; }
.count { font-family: var(--body); font-size: 0.85rem; color: var(--muted); font-weight: 700; margin-left: 6px; }
.words { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 6px; }
.words li { padding: 5px 10px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--line); font-size: 0.98rem; line-height: 1.3; }
.words li small { display: block; font-size: 0.74rem; color: var(--muted); }
.history { list-style: none; margin: 0; padding: 0; display: grid; gap: 8px; }
.history a { display: flex; flex-wrap: wrap; justify-content: space-between; gap: 6px 12px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line); background: var(--surface); text-decoration: none; color: inherit; }
.history a:hover { border-color: var(--accent); }

/* ---------- Böcker, familj, admin ---------- */
.list { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.item { display: flex; flex-wrap: wrap; gap: 10px 16px; align-items: center; justify-content: space-between; padding: 14px 16px; background: var(--surface); border: 1px solid var(--line); border-radius: 12px; }
.item-main { display: grid; gap: 4px; min-width: 0; flex: 1 1 240px; }
.item-main b { font-size: 1.05rem; overflow-wrap: anywhere; }
.item-tools { display: flex; flex-wrap: wrap; gap: 8px; }
.code { font-family: var(--mono); font-size: 1.15rem; font-weight: 700; letter-spacing: 0.08em; padding: 4px 10px; border-radius: 8px; background: var(--accent-soft); color: var(--accent); user-select: all; }
.two-col { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 20px; align-items: start; }

/* ---------- Inloggning ---------- */
.login-wrap { min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.login { width: min(420px, 100%); display: grid; gap: 18px; }
.login .brand { font-size: 2rem; justify-content: center; }
.login .brand-mark { width: 44px; height: 44px; }
.login .tagline { text-align: center; color: var(--muted); }

/* ---------- Dialog & toast ---------- */
dialog { border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; background: var(--surface); color: var(--ink); width: min(440px, calc(100vw - 32px)); box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3); }
dialog::backdrop { background: rgba(10, 16, 24, 0.45); }
dialog form { display: grid; gap: 14px; }
dialog .actions { display: flex; justify-content: flex-end; gap: 8px; flex-wrap: wrap; }
.toast { position: fixed; left: 50%; bottom: calc(20px + env(safe-area-inset-bottom, 0px)); transform: translateX(-50%); background: var(--ink); color: var(--surface); padding: 12px 18px; border-radius: 12px; font-weight: 700; z-index: 50; max-width: calc(100vw - 32px); box-shadow: var(--shadow); }
.toast.error { background: var(--bad); color: #fff; }

@media (max-width: 720px) {
  main { padding-top: 18px; gap: 16px; }
  .viewer { grid-template-columns: 1fr; }
  .view-toggle { display: inline-flex; }
  .viewer[data-show='text'] .canvas-wrap { display: none; }
  .viewer[data-show='image'] .text-panel { display: none; }
  .task { grid-template-columns: 1fr; gap: 10px; padding: 14px; }
  .task-n { width: 34px; height: 34px; }
  .who .who-name { display: none; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
