/* ===========================
Skyen, Speilet og Strømmen
Classless CSS – typografi først
=========================== */

:root {
  --bg: #ffffff;
  --text: #111214;
  --muted: #5b616e;
  --line: #e7e9ee;
  --accent: #5b7cfa;
  /* vennlig blå */
  --accent-2: #16a34a;
  /* grønn detalj */
  --kbd: #f6f7f9;
  --quote-bg: #f8fafc;
  --table-head: #f2f4f8;
  --shadow: 0 1px 2px rgba(0, 0, 0, .06), 0 8px 24px rgba(0, 0, 0, .06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0f1115;
    --text: #e5e7eb;
    --muted: #a0a8b5;
    --line: #2a2f3a;
    --accent: #86a5ff;
    --accent-2: #34d399;
    --kbd: #1a1d25;
    --quote-bg: #141823;
    --table-head: #161a23;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .3);
  }
}

html {
  scroll-behavior: smooth;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0 auto;
  padding: clamp(16px, 4vw, 32px);
  max-width: 78ch;
  background: var(--bg);
  color: var(--text);
  line-height: 1.6;
  font-family: ui-sans-serif, system-ui, -apple-system, Segoe UI, Roboto, "Noto Sans", "Helvetica Neue", Arial, "Apple Color Emoji", "Segoe UI Emoji";
  text-rendering: optimizeLegibility;
}

h1,
h2,
h3 {
  line-height: 1.2;
  margin: 2.2rem 0 0.8rem;
  letter-spacing: .2px;
}

h1 {
  font-size: clamp(1.9rem, 3vw, 2.4rem);
  font-weight: 800;
}

h1 strong {
  font-weight: 900;
}

h2 {
  font-size: clamp(1.4rem, 2.3vw, 1.7rem);
  border-bottom: 1px solid var(--line);
  padding-bottom: .35rem;
}

h3 {
  font-size: clamp(1.15rem, 1.8vw, 1.25rem);
  color: var(--muted);
  font-weight: 700;
}

p {
  margin: 0.8rem 0;
}

em,
i {
  color: inherit;
}

small,
.muted {
  color: var(--muted);
}

hr {
  border: 0;
  height: 1px;
  background: linear-gradient(to right, transparent, var(--line), transparent);
  margin: 2rem 0;
}

.book-nav {
  background: var(--quote-bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: clamp(1rem, 2.5vw, 1.75rem);
  margin: 2.5rem 0;
  box-shadow: var(--shadow);
}

.book-nav h2 {
  margin: 0 0 0.65rem;
  border: 0;
  padding-bottom: 0;
}

.book-nav p {
  margin: 0 0 1rem;
  color: var(--muted);
}

.book-nav__list {
  margin: 0;
  padding-left: 1.4rem;
  display: grid;
  gap: 0.5rem;
}

.book-nav__list a {
  font-weight: 600;
  color: inherit;
  text-decoration: none;
  border-bottom: 1px solid transparent;
}

.book-nav__list a:hover,
.book-nav__list a:focus-visible {
  color: var(--accent);
  border-bottom-color: color-mix(in oklab, var(--accent) 55%, transparent);
}

/* Innholdsfortegnelse */
.toc {
  background: var(--quote-bg);
  border: 1px solid var(--line);
  border-radius: 16px;
  padding: clamp(1rem, 2.5vw, 1.75rem);
  margin: 2.5rem 0;
  box-shadow: var(--shadow);
  display: grid;
  gap: 1rem;
}

.toc__heading {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: space-between;
}

.toc h2 {
  margin-top: 0;
  margin-bottom: 0.75rem;
  border: 0;
  padding-bottom: 0;
}

.toc p {
  margin-top: 0;
  margin-bottom: 1.2rem;
}

.toc__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.4rem;
}

.toc li {
  line-height: 1.4;
}

.toc li > a {
  font-weight: 600;
  color: inherit;
  border-bottom-color: transparent;
}

.toc li > a:hover,
.toc li > a:focus-visible {
  color: var(--accent);
  border-bottom-color: color-mix(in oklab, var(--accent) 60%, transparent);
}

.toc__sublist {
  margin-top: 0.35rem;
  margin-left: 1.2rem;
  padding-left: 1rem;
  border-left: 1px solid var(--line);
  gap: 0.3rem;
  list-style: none;
}

.toc__sublist a {
  font-weight: 500;
  color: var(--muted);
}

.toc__sublist a:hover,
.toc__sublist a:focus-visible {
  color: var(--accent);
}

.toc li.is-active > a,
.toc [aria-current="true"] {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.toc li.is-active > a {
  font-weight: 700;
}

.toc__toggle {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: transparent;
  padding: 0.45rem 0.9rem;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease;
}

.toc__toggle:hover,
.toc__toggle:focus-visible {
  color: var(--accent);
  border-color: var(--accent);
  background-color: color-mix(in oklab, var(--accent) 14%, transparent);
}

.toc[data-expanded="false"] {
  gap: 0.75rem;
}

.toc[data-expanded="false"] .toc__list {
  display: none;
}

.toc[data-expanded="false"] .toc__sublist {
  display: none;
}

@media (prefers-reduced-motion: reduce) {
  .toc__toggle {
    transition: none;
  }
}

@media (max-width: 640px) {
  .toc {
    padding: 1.2rem;
    margin: 2rem 0;
  }

  .toc__list {
    gap: 0.3rem;
  }
}

/* Lenker */
a {
  color: var(--accent);
  text-decoration: none;
  border-bottom: 1px solid color-mix(in oklab, var(--accent) 60%, transparent);
}

a:hover {
  border-bottom-color: var(--accent);
}

a:focus {
  outline: 2px dashed var(--accent);
  outline-offset: 2px;
}

/* Tabeller – passer dine kapitler */
table {
  width: 100%;
  border-collapse: collapse;
  margin: 1rem 0 1.5rem;
  box-shadow: var(--shadow);
  border-radius: 12px;
  overflow: hidden;
}

thead th {
  background: var(--table-head);
  color: var(--text);
  text-align: left;
  padding: .8rem .9rem;
  font-weight: 700;
  border-bottom: 1px solid var(--line);
}

tbody td {
  padding: .75rem .9rem;
  vertical-align: top;
  border-bottom: 1px solid var(--line);
}

tbody tr:nth-child(even) {
  background: color-mix(in oklab, var(--table-head) 35%, transparent);
}

/* Blokksitater – «poetisk, men rolig» */
blockquote {
  margin: 1.2rem 0;
  padding: 1rem 1.2rem;
  background: var(--quote-bg);
  border-left: 4px solid var(--accent-2);
  border-radius: 10px;
}

blockquote p {
  margin: 0.4rem 0;
}

/* Lister */
ul,
ol {
  margin: .6rem 0 1rem 1.4rem;
}

li+li {
  margin-top: .25rem;
}

/* Kode og tastetrykk – til tekniske innslag */
code,
kbd,
samp {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, "Liberation Mono", monospace;
  font-size: .95em;
  background: var(--kbd);
  padding: .15em .35em;
  border-radius: 6px;
  border: 1px solid var(--line);
}

pre {
  background: var(--kbd);
  padding: 1rem;
  border-radius: 12px;
  overflow: auto;
  border: 1px solid var(--line);
}

pre code {
  background: transparent;
  border: 0;
  padding: 0;
}

/* Bilder/figurer hvis du legger inn senere */
img,
video {
  max-width: 100%;
  height: auto;
  border-radius: 12px;
}

figure {
  margin: 1.2rem 0;
}

figcaption {
  color: var(--muted);
  font-size: .95rem;
  text-align: center;
  margin-top: .4rem;
}

/* Innholdsdetaljer / toggles (kan brukes senere) */
details {
  background: var(--quote-bg);
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: .7rem .9rem;
  margin: 1rem 0;
}

summary {
  cursor: pointer;
  font-weight: 700;
}

/* Ankere til overskrifter (du bruker id=... allerede) */
h1[id],
h2[id],
h3[id] {
  scroll-margin-top: 12vh;
}

/* Callout-badges for kapittel-emojis – subtil forankring */
h1:has(strong)::after,
h2::after {
  content: "";
  display: block;
  height: 3px;
  width: 56px;
  margin-top: .5rem;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
}

/* Avsnitt som starter med emoji – litt luft */
p:has(> em)::first-letter {}

h1,
h2,
h3 :where(emoji) {
  margin-right: .25ch;
}

/* Fot, forfatterlinje osv. */
header,
footer {
  color: var(--muted);
}

/* Tilgjengelighet: større klikkflate for tabeller på mobil */
@media (max-width: 640px) {
  body {
    padding: 16px;
  }

  table {
    font-size: .95rem;
  }

  thead {
    position: sticky;
    top: 0;
    z-index: 1;
  }
}

/* Utskrift */
@media print {
  body {
    max-width: none;
    box-shadow: none;
  }

  a {
    color: inherit;
    border-bottom: 1px dotted #999;
  }

  table {
    box-shadow: none;
  }

  hr {
    break-inside: avoid;
  }
}

pre::-webkit-scrollbar {
  height: 6px;
  background: transparent;
}
pre::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}
pre:hover::-webkit-scrollbar-thumb {
  background: var(--muted);
}
