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

:root {
  --bg: #f7f4ee;
  --bg-glow: rgba(107, 132, 214, .12);
  --text: #1f242b;
  --muted: #6b716f;
  --line: #dcd6cc;
  --accent: #6b84d6;
  /* vennlig blå */
  --accent-2: #3f9960;
  /* grønn detalj */
  --kbd: #f1ede6;
  --quote-bg: #f2eee7;
  --table-head: #ece6dd;
  --surface: rgba(255, 255, 255, .42);
  --surface-strong: rgba(255, 255, 255, .68);
  --shadow: 0 1px 2px rgba(56, 45, 30, .05), 0 10px 26px rgba(56, 45, 30, .07);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #17191d;
    --bg-glow: rgba(147, 168, 226, .14);
    --text: #d8d3cb;
    --muted: #a8a099;
    --line: #35373d;
    --accent: #93a8e2;
    --accent-2: #68b287;
    --kbd: #20232a;
    --quote-bg: #1e2127;
    --table-head: #24272e;
    --surface: rgba(255, 255, 255, .02);
    --surface-strong: rgba(255, 255, 255, .04);
    --shadow: 0 1px 2px rgba(0, 0, 0, .22), 0 10px 26px rgba(0, 0, 0, .24);
  }
}

html {
  scroll-behavior: smooth;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0 auto;
  padding: clamp(16px, 4vw, 32px);
  max-width: 78ch;
  min-height: 100vh;
  background:
    radial-gradient(circle at top left, var(--bg-glow), transparent 30rem),
    linear-gradient(180deg, color-mix(in oklab, var(--bg) 92%, black 8%), var(--bg));
  color: var(--text);
  line-height: 1.72;
  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;
}

main {
  display: grid;
  gap: 0.2rem;
}

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

h1 {
  font-size: clamp(2.15rem, 3.8vw, 3rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  text-wrap: balance;
}

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;
  text-wrap: pretty;
}

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 h2::after,
.toc h2::after {
  display: none;
}

.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:
    linear-gradient(180deg, color-mix(in oklab, var(--surface-strong) 70%, var(--quote-bg)), var(--quote-bg));
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: clamp(1rem, 2.5vw, 1.45rem);
  margin: 2.5rem 0;
  box-shadow: var(--shadow);
  display: grid;
  gap: 0.85rem;
  position: relative;
  overflow: hidden;
}

.toc::before {
  content: "";
  position: absolute;
  inset: 0;
  background:
    linear-gradient(135deg, color-mix(in oklab, var(--accent) 9%, transparent), transparent 36%),
    linear-gradient(180deg, transparent, color-mix(in oklab, var(--accent-2) 6%, transparent));
  pointer-events: none;
}

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

.toc__heading > div {
  min-width: 0;
}

.toc h2 {
  margin-top: 0;
  margin-bottom: 0;
  border: 0;
  padding-bottom: 0;
  font-size: clamp(1.2rem, 2vw, 1.45rem);
  letter-spacing: -0.02em;
}

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

.toc__list {
  list-style: none;
  padding: 0;
  margin: 0;
  display: grid;
  gap: 0.4rem;
  position: relative;
  z-index: 1;
}

.toc li {
  line-height: 1.4;
}

.toc li > a {
  display: inline-block;
  font-weight: 600;
  color: inherit;
  border-bottom-color: transparent;
  padding: 0.08rem 0;
}

.toc__list > li > a {
  font-weight: 700;
}

.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);
  display: grid;
  gap: 0.3rem;
  list-style: none;
}

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

.toc__sublist > li > a {
  font-size: 0.97rem;
}

.toc__sublist--deep {
  margin-top: 0.3rem;
  margin-left: 0.9rem;
  padding-left: 0.85rem;
  gap: 0.24rem;
  border-left-color: color-mix(in oklab, var(--line) 78%, var(--accent));
}

.toc__sublist--deep a {
  font-size: 0.93rem;
  font-weight: 500;
  color: color-mix(in oklab, var(--muted) 88%, var(--text));
}

.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: color-mix(in oklab, var(--accent) 8%, var(--surface));
  padding: 0.55rem 1rem;
  font: inherit;
  font-weight: 600;
  color: var(--accent);
  cursor: pointer;
  box-shadow: inset 0 1px 0 color-mix(in oklab, white 30%, transparent);
  transition: background-color 160ms ease, color 160ms ease, border-color 160ms ease, transform 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);
  transform: translateY(-1px);
}

.toc[data-expanded="false"] {
  gap: 0;
  padding-block: 1rem;
}

.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: linear-gradient(180deg, color-mix(in oklab, var(--surface) 40%, var(--quote-bg)), var(--quote-bg));
  border-left: 4px solid var(--accent-2);
  border-radius: 14px;
}

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: 4px;
  width: 64px;
  margin-top: .65rem;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
}

.subtitle {
  margin-top: -0.15rem;
  margin-bottom: 1.35rem;
  max-width: 44ch;
  font-size: clamp(1.05rem, 1.6vw, 1.25rem);
  line-height: 1.55;
  color: var(--muted);
}

.subtitle em {
  font-style: italic;
}

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

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

footer {
  text-align: center;
  padding: 1.5rem;
  font-size: .88rem;
  border-top: 1px solid var(--line);
}

footer p {
  margin: 0;
}

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

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

  .subtitle {
    font-size: 1rem;
    margin-bottom: 1.1rem;
  }

  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(--line);
  border-radius: 3px;
}
pre:hover::-webkit-scrollbar-thumb {
  background: var(--muted);
}
