/* ------------------------------------------------------------
   Tokens
   ------------------------------------------------------------ */
:root {
  --bg: #f7f8fa;
  --surface: #ffffff;
  --surface-2: #eef1f5;
  --text: #111827;
  --muted: #5b6474;
  --border: #dde2ea;
  --accent: #0d9668;
  --accent-soft: rgba(13, 150, 104, 0.12);
  --accent-2: #2563eb;
  --dim-opacity: 0.28;
  --term-bg: #0f172a;
  --term-text: #d6e2f0;
  --term-green: #34d399;
  --term-blue: #7dd3fc;
  --term-yellow: #fcd34d;
  --term-red: #f87171;
  --shadow: 0 1px 2px rgba(16, 24, 40, 0.06), 0 6px 20px rgba(16, 24, 40, 0.06);
  --radius: 12px;
  --mono: ui-monospace, "SFMono-Regular", "JetBrains Mono", "Cascadia Code", Menlo, Consolas, monospace;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #0b1120;
    --surface: #111a2e;
    --surface-2: #17223a;
    --text: #e5ebf5;
    --muted: #94a0b8;
    --border: #24304a;
    --accent: #34d399;
    --accent-soft: rgba(52, 211, 153, 0.14);
    --accent-2: #60a5fa;
    --term-bg: #070c18;
    --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
  }
}
:root[data-theme="dark"] {
  --bg: #0b1120;
  --surface: #111a2e;
  --surface-2: #17223a;
  --text: #e5ebf5;
  --muted: #94a0b8;
  --border: #24304a;
  --accent: #34d399;
  --accent-soft: rgba(52, 211, 153, 0.14);
  --accent-2: #60a5fa;
  --term-bg: #070c18;
  --shadow: 0 1px 2px rgba(0, 0, 0, 0.3), 0 8px 24px rgba(0, 0, 0, 0.25);
}

/* ------------------------------------------------------------
   Base
   ------------------------------------------------------------ */
*, *::before, *::after { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 72px; }
@media (prefers-reduced-motion: reduce) {
  html { scroll-behavior: auto; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
}
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.6 var(--sans);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent-2); }
h1, h2, h3 { line-height: 1.2; margin: 0; }
button { font: inherit; color: inherit; }
kbd {
  font: 0.85em var(--mono);
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-bottom-width: 2px;
  border-radius: 5px;
  background: var(--surface);
}
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; border-radius: 6px; }

.skip {
  position: absolute; left: 16px; top: -48px; z-index: 100;
  background: var(--accent); color: #fff; padding: 8px 14px; border-radius: 8px;
}
.skip:focus { top: 12px; }

main { max-width: 1080px; margin: 0 auto; padding: 0 16px; }
section { padding: 56px 0 8px; }
section h2 {
  font-size: clamp(1.4rem, 3vw, 1.8rem);
  margin-bottom: 20px;
  display: flex; align-items: baseline; gap: 12px;
}
.num { font: 600 0.9rem var(--mono); color: var(--accent); }
.hint { color: var(--muted); margin: -8px 0 16px; }

/* ------------------------------------------------------------
   Top bar
   ------------------------------------------------------------ */
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px;
  padding: 10px 16px;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.brand { font: 600 1rem var(--mono); color: var(--text); text-decoration: none; white-space: nowrap; }
.prompt { color: var(--accent); font-family: var(--mono); }
.topbar nav { display: flex; gap: 4px; margin-left: auto; overflow-x: auto; scrollbar-width: none; }
.topbar nav a {
  color: var(--muted); text-decoration: none; padding: 6px 10px; border-radius: 8px;
  font-size: 0.93rem; white-space: nowrap;
}
.topbar nav a:hover, .topbar nav a.active { color: var(--text); background: var(--surface-2); }
.tools { display: flex; gap: 4px; }
.icon-btn {
  display: inline-grid; place-items: center;
  width: 36px; height: 36px; border-radius: 9px;
  border: 1px solid transparent; background: transparent; cursor: pointer;
}
a.icon-btn { color: inherit; }
.icon-btn:hover { background: var(--surface-2); border-color: var(--border); }
.icon-btn svg { width: 19px; height: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
@media (max-width: 720px) {
  .topbar nav { display: none; }
  .tools { margin-left: auto; }
}

/* ------------------------------------------------------------
   Hero
   ------------------------------------------------------------ */
.hero {
  display: grid; grid-template-columns: 1.1fr 1fr; gap: 40px; align-items: center;
  padding-top: 64px;
}
.eyebrow { font: 500 0.9rem var(--mono); color: var(--accent); margin: 0 0 10px; }
.hero h1 { font-size: clamp(2.2rem, 6vw, 3.6rem); letter-spacing: -0.02em; }
.hero-title { font-size: 1.25rem; color: var(--muted); margin: 10px 0 18px; }
.hero-tagline { font-size: 1.08rem; max-width: 46ch; margin: 0 0 26px; }
.hero-cta { display: flex; gap: 10px; flex-wrap: wrap; }
.btn {
  display: inline-block; padding: 10px 18px; border-radius: 10px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  text-decoration: none; font-weight: 500; box-shadow: var(--shadow);
  transition: transform 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
:root[data-theme="dark"] .btn.primary { color: #052e1f; }
@media (prefers-color-scheme: dark) { :root:not([data-theme="light"]) .btn.primary { color: #052e1f; } }

/* Neutral window header: a prompt badge, the title and a status label --
   deliberately not styled after any OS's window controls. */
.term-chrome {
  display: flex; align-items: center; gap: 10px;
  padding: 8px 14px; background: rgba(255, 255, 255, 0.04);
  border-bottom: 1px solid rgba(255, 255, 255, 0.07);
  font: 0.8rem var(--mono); color: #8a96ad;
}
.term-badge {
  padding: 1px 6px; border-radius: 4px;
  background: rgba(52, 211, 153, 0.14); color: var(--term-green); font-weight: 700;
}
.term-title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.term-meta {
  display: inline-flex; align-items: center; gap: 6px; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
}
.term-meta::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: var(--term-green); }
.hero-term, .term {
  background: var(--term-bg); color: var(--term-text);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
  border: 1px solid rgba(255, 255, 255, 0.06);
}
.hero-term pre {
  margin: 0; padding: 16px 18px; min-height: 290px;
  font: 0.84rem/1.6 var(--mono); white-space: pre-wrap; word-break: break-word;
}
.c-g { color: var(--term-green); }
.c-b { color: var(--term-blue); }
.c-y { color: var(--term-yellow); }
.c-r { color: var(--term-red); }
.c-m { color: #8a96ad; }
.cursor::after {
  content: "▋"; color: var(--term-green); animation: blink 1s steps(1) infinite;
}
@keyframes blink { 50% { opacity: 0; } }
@media (max-width: 860px) {
  .hero { grid-template-columns: 1fr; padding-top: 40px; }
  .hero-term pre { min-height: 0; }
}

/* ------------------------------------------------------------
   Stats
   ------------------------------------------------------------ */
.stats {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 14px; padding-top: 48px;
}
.stat {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 18px; box-shadow: var(--shadow);
}
.stat b { display: block; font: 700 2rem var(--mono); color: var(--accent); }
.stat span { color: var(--muted); font-size: 0.92rem; }
@media (max-width: 720px) { .stats { grid-template-columns: repeat(2, 1fr); } }

.about p { max-width: 70ch; font-size: 1.05rem; }

/* ------------------------------------------------------------
   Skills
   ------------------------------------------------------------ */
.skill-filter { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.skill-group {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
}
.skill-group h3 { font-size: 0.95rem; margin-bottom: 10px; color: var(--muted); font-weight: 600; }
.skill {
  display: grid; grid-template-columns: 1fr 92px; align-items: center; gap: 10px;
  width: 100%; text-align: left; padding: 6px 8px; margin: 0 -8px; width: calc(100% + 16px);
  border: 0; background: transparent; border-radius: 8px; cursor: pointer;
}
.skill:hover { background: var(--surface-2); }
.skill[aria-pressed="true"] { background: var(--accent-soft); }
.skill[aria-pressed="true"] .skill-name { color: var(--accent); font-weight: 600; }
.skill-name { font-size: 0.95rem; }
.meter { display: flex; gap: 3px; }
.meter i { flex: 1; height: 7px; border-radius: 3px; background: var(--surface-2); transition: background 0.4s ease; }
.meter i.on { background: var(--accent); }
.filter-status { min-height: 1.6em; margin: 14px 0 0; color: var(--muted); }
.filter-status button {
  margin-left: 8px; border: 1px solid var(--border); background: var(--surface);
  padding: 2px 10px; border-radius: 999px; cursor: pointer; font-size: 0.85rem;
}

/* ------------------------------------------------------------
   Timeline
   ------------------------------------------------------------ */
.timeline-bar {
  position: relative; height: 34px; margin: 0 0 28px;
  border-bottom: 1px solid var(--border);
}
.timeline-bar .seg {
  position: absolute; top: 4px; height: 14px; border-radius: 4px;
  background: var(--accent); opacity: 0.75; cursor: pointer;
}
.timeline-bar .seg.dim { opacity: 0.18; }
.timeline-bar .year {
  position: absolute; bottom: -2px; font: 0.7rem var(--mono); color: var(--muted); transform: translateX(-50%);
}
.timeline { list-style: none; padding: 0; margin: 0; position: relative; }
.timeline::before {
  content: ""; position: absolute; left: 11px; top: 6px; bottom: 6px; width: 2px; background: var(--border);
}
.job { position: relative; padding-left: 40px; margin-bottom: 18px; transition: opacity 0.3s ease; }
.job::before {
  content: ""; position: absolute; left: 4px; top: 22px; width: 16px; height: 16px; border-radius: 50%;
  background: var(--surface); border: 3px solid var(--accent);
}
.job.current::before { background: var(--accent); box-shadow: 0 0 0 5px var(--accent-soft); }
.job-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow: hidden;
}
.job-head {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; align-items: start;
  width: 100%; text-align: left; padding: 16px 18px; border: 0; background: transparent; cursor: pointer;
}
.job-head h3 { font-size: 1.1rem; }
.job-company { color: var(--muted); }
.job-dates { font: 0.85rem var(--mono); color: var(--muted); text-align: right; white-space: nowrap; }
.job-dur { display: block; color: var(--accent); }
.chev { width: 18px; height: 18px; fill: none; stroke: var(--muted); stroke-width: 2; transition: transform 0.2s; vertical-align: -3px; }
.job.open .chev { transform: rotate(180deg); }
.job-body { display: grid; grid-template-rows: 0fr; transition: grid-template-rows 0.3s ease; }
.job.open .job-body { grid-template-rows: 1fr; }
.job-body > div { overflow: hidden; }
.job-body-inner { padding: 0 18px 16px; }
.job-body ul { margin: 6px 0 12px; padding-left: 20px; }
.job-body li { margin-bottom: 4px; }
.tags { display: flex; flex-wrap: wrap; gap: 6px; }
.tag {
  font: 0.75rem var(--mono); padding: 3px 8px; border-radius: 999px;
  background: var(--surface-2); color: var(--muted); border: 1px solid transparent;
}
.tag.hit { background: var(--accent-soft); color: var(--accent); border-color: var(--accent); }
.dim, .reveal.in.dim { opacity: var(--dim-opacity); }
.todo { color: #b45309; }

/* ------------------------------------------------------------
   Projects ("pods")
   ------------------------------------------------------------ */
.kind-filter { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 16px; }
.chip {
  border: 1px solid var(--border); background: var(--surface); padding: 5px 12px;
  border-radius: 999px; cursor: pointer; font: 0.85rem var(--mono); color: var(--muted);
}
.chip[aria-pressed="true"] { background: var(--accent); color: #fff; border-color: var(--accent); }
.pods { display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.pod {
  position: relative; text-align: left; cursor: pointer;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px; box-shadow: var(--shadow);
  transition: transform 0.18s ease, border-color 0.18s ease, opacity 0.3s ease;
  display: flex; flex-direction: column; gap: 8px;
}
.pod:hover { transform: translateY(-3px); border-color: var(--accent); }
.pod-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; font: 0.75rem var(--mono); color: var(--muted); }
.status { display: inline-flex; align-items: center; gap: 6px; color: var(--accent); }
.status::before {
  content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent);
  animation: pulse 2.4s ease-in-out infinite;
}
@keyframes pulse { 0%, 100% { box-shadow: 0 0 0 0 var(--accent-soft); } 50% { box-shadow: 0 0 0 6px transparent; } }
.pod h3 { font-size: 1.05rem; }
.pod p { margin: 0; color: var(--muted); font-size: 0.92rem; flex: 1; }
.pod[hidden] { display: none; }

dialog {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 64px);
  border: 1px solid var(--border); border-radius: var(--radius); padding: 0;
  background: var(--surface); color: var(--text); box-shadow: var(--shadow);
}
dialog::backdrop { background: rgba(5, 10, 20, 0.55); backdrop-filter: blur(2px); }
.dialog-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 14px 16px 14px 20px; border-bottom: 1px solid var(--border);
}
#pod-dialog-body { padding: 16px 20px 20px; }
#pod-dialog-body pre {
  background: var(--term-bg); color: var(--term-text); padding: 12px 14px; border-radius: 8px;
  font: 0.8rem/1.6 var(--mono); overflow-x: auto; margin: 0 0 14px;
}

/* ------------------------------------------------------------
   Education, contact
   ------------------------------------------------------------ */
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
@media (max-width: 720px) { .two-col { grid-template-columns: 1fr; } }
.plain-list {
  list-style: none; margin: 0; padding: 6px 18px;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.plain-list li { padding: 10px 0; display: flex; justify-content: space-between; gap: 12px; }
.plain-list li + li { border-top: 1px solid var(--border); }
.plain-list small { color: var(--muted); font-family: var(--mono); white-space: nowrap; }

.contact { list-style: none; padding: 0; margin: 0; display: grid; grid-template-columns: repeat(auto-fill, minmax(240px, 1fr)); gap: 14px; }
.contact a {
  display: block; padding: 16px; text-decoration: none; color: var(--text);
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow);
}
.contact a:hover { border-color: var(--accent); }
.contact small { display: block; color: var(--muted); font: 0.78rem var(--mono); }

/* ------------------------------------------------------------
   Interactive terminal
   ------------------------------------------------------------ */
.term { cursor: text; }
.term-out {
  padding: 14px 18px 0; height: 340px; overflow-y: auto;
  font: 0.86rem/1.6 var(--mono); white-space: pre-wrap; word-break: break-word;
}
.term-in { display: flex; gap: 10px; align-items: center; padding: 4px 18px 16px; font: 0.86rem var(--mono); }
.term-in .prompt { color: var(--term-green); white-space: nowrap; }
.term-in input {
  flex: 1; min-width: 0; background: transparent; border: 0; outline: none;
  color: var(--term-text); font: inherit; caret-color: var(--term-green);
}
.term a { color: var(--term-blue); }

.footer { text-align: center; color: var(--muted); font-size: 0.85rem; padding: 48px 16px; }

/* ------------------------------------------------------------
   Reveal on scroll
   ------------------------------------------------------------ */
.reveal { opacity: 0; transform: translateY(14px); transition: opacity 0.6s ease, transform 0.6s ease; }
.reveal.in { opacity: 1; transform: none; }

/* ------------------------------------------------------------
   Language switcher (links to /en/, /no/, /sv/)
   ------------------------------------------------------------ */
.lang-switch {
  display: inline-flex; align-items: center; margin-right: 4px;
  border: 1px solid var(--border); border-radius: 9px; overflow: hidden;
}
.lang-switch a {
  font: 600 0.75rem var(--mono); color: var(--muted); text-decoration: none;
  padding: 7px 8px; line-height: 1;
}
.lang-switch a + a { border-left: 1px solid var(--border); }
.lang-switch a:hover { color: var(--text); background: var(--surface-2); }
.lang-switch a[aria-current="true"] { color: var(--accent); background: var(--accent-soft); }

.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; border: 0;
}

/* ------------------------------------------------------------
   References: locked panel + per-role cards once unlocked
   ------------------------------------------------------------ */
.refs-panel {
  display: flex; gap: 16px; align-items: flex-start;
  margin: 8px 0 0 40px; padding: 16px 18px;
  background: var(--surface); border: 1px dashed var(--border); border-radius: var(--radius);
}
.refs-panel.unlocked { border-style: solid; border-color: var(--accent); }
.refs-icon { flex: none; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: var(--surface-2); }
.refs-icon svg { width: 20px; height: 20px; fill: none; stroke: var(--muted); stroke-width: 1.8; stroke-linecap: round; }
.refs-panel.unlocked .refs-icon { background: var(--accent-soft); }
.refs-panel.unlocked .refs-icon svg { stroke: var(--accent); }
.refs-icon .shackle { transition: transform 0.3s ease; transform-origin: 16px 11px; }
.refs-panel.unlocked .refs-icon .shackle { transform: rotate(35deg) translateY(-1px); }
.refs-body { flex: 1; min-width: 0; }
.refs-body h3 { font-size: 1.02rem; margin-bottom: 4px; }
.refs-body p { margin: 0 0 10px; color: var(--muted); }
.refs-form { display: flex; gap: 8px; flex-wrap: wrap; }
.refs-form input {
  width: 11ch; min-width: 0; padding: 9px 12px; font: 600 1rem var(--mono); letter-spacing: 0.08em;
  color: var(--text); background: var(--bg); border: 1px solid var(--border); border-radius: 10px;
}
.refs-form input:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }
.refs-form .btn { box-shadow: none; cursor: pointer; }
.refs-form .btn:disabled { opacity: 0.6; cursor: progress; }
.refs-error { color: var(--term-red); min-height: 1.4em; margin: 8px 0 0 !important; font-size: 0.9rem; }
#refs-unlocked .btn { cursor: pointer; box-shadow: none; }
@media (max-width: 720px) { .refs-panel { margin-left: 0; } }

.job-refs { margin-top: 14px; padding-top: 12px; border-top: 1px dashed var(--border); }
.job-refs h4 { margin: 0 0 8px; font-size: 0.85rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.08em; }
.ref {
  display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px;
  padding: 8px 12px; margin-bottom: 6px; border-radius: 8px; background: var(--accent-soft);
}
.ref-role { color: var(--muted); }
.ref a { font: 0.88rem var(--mono); }

/* ------------------------------------------------------------
   Print: a plain, one-column CV
   ------------------------------------------------------------ */
@media print {
  :root { --bg: #fff; --surface: #fff; --text: #000; --muted: #444; --border: #ccc; --accent: #0d6e4f; --shadow: none; }
  body { font-size: 10.5pt; }
  .topbar, .hero-term, .hero-cta, #terminal, .refs-panel, .hint, .filter-status, .kind-filter, .timeline-bar, .footer, .skip, dialog, .chev { display: none !important; }
  .reveal { opacity: 1 !important; transform: none !important; }
  section { padding: 14px 0 0; break-inside: auto; }
  .hero { display: block; padding-top: 0; }
  .stats { display: none; }
  .job-body { grid-template-rows: 1fr !important; }
  .job, .pod, .skill-group { break-inside: avoid; }
  .dim { opacity: 1 !important; }
  .pods { grid-template-columns: 1fr 1fr; }
  .pod-top { display: none; }
  .skill { padding: 2px 8px; }
  a { color: inherit; text-decoration: none; }
}

/* Sections switched off on the admin page get [hidden]; it must win over
   the display values above. Until the settings have been applied the page is
   invisible (no flash of a switched-off section); the animation shows it
   anyway after 2 s if the script never gets there. */
[hidden] { display: none !important; }
.cfg-loading main, .cfg-loading .paper { visibility: hidden; animation: cfg-show 0s 2s forwards; }
@keyframes cfg-show { to { visibility: visible; } }
.hero.no-term { grid-template-columns: 1fr; }
