/*
 * efn.is — global styles
 * ----------------------
 * Served as a plain static file (not bundled by Astro) so the CMS preview
 * pane can load exactly the same CSS as the site: see public/admin/.
 *
 * The :root token block is copied verbatim from the design system's
 * colors_and_type.css (canonical). Only the two font-family tokens were
 * changed, and a few layout tokens were appended at the end.
 * @font-face rules are generated by Astro's Fonts API instead.
 *
 * Contrast (WCAG AA) rules agreed with Siggi, 2026-09-25:
 *  - amber buttons use basalt text, never white
 *  - meta text and dates use --fg-2 (ink-muted); --fg-3 and amber are
 *    for borders, markers and large numerals only
 *  - text on dark bands is at least 85% opaque
 */

:root {
  /* ── COLOR — Teal (primary) ─────────────────────────────── */
  --efnis-teal:        #1a6b5a;  /* forest-teal — geothermal water, calcite-spar */
  --efnis-teal-dark:   #0f4a3e;  /* deepest teal — bonds in the mark, dark CTAs */
  --efnis-teal-soft:   #9ccabf;  /* photo overlays, subtle illustration tints */
  --efnis-teal-50:     #e6f2ef;  /* tint — pill bg, icon-box bg, hover */
  --efnis-teal-100:    #c4dfd6;  /* light fills, scrollbar, dividers on dark */

  /* ── COLOR — Amber (accent — sparing) ───────────────────── */
  --efnis-amber:       #d4872e;  /* carbonate centre — accent, never bg */
  --efnis-amber-dark:  #b06f1f;  /* hover, pill text */
  --efnis-amber-50:    #f9ecd9;  /* pill bg, blockquote bg */

  /* ── COLOR — Neutrals ───────────────────────────────────── */
  --efnis-basalt:      #1c2a26;  /* near-black, very slight teal undertone */
                                  /* footer, dark CTA bands, body ink */
  --efnis-bg:          #ffffff;  /* white page background (warm off-white #fbfbf9 until 2026-11-29) */
  --efnis-cream:       #f3efe6;  /* warmer cream — section bg, info-card */
  --efnis-cream-dark:  #e3ddd0;  /* borders, dividers */
  --efnis-ink:         #1c2a26;  /* basalt as body ink */
  --efnis-ink-muted:   #5a6b66;  /* secondary text, article body */
  --efnis-ink-subtle:  #8a9b96;  /* meta, dates, hints */

  /* ── COLOR — Aliases (semantic) ─────────────────────────── */
  --fg-1:              var(--efnis-ink);
  --fg-2:              var(--efnis-ink-muted);
  --fg-3:              var(--efnis-ink-subtle);
  --fg-on-dark:        var(--efnis-cream);
  --bg-1:              var(--efnis-bg);
  --bg-2:              var(--efnis-cream);
  --bg-3:              var(--efnis-cream-dark);
  --bg-card:           #ffffff;        /* cards are pure white over warm bg */
  --bg-deep:           var(--efnis-basalt);
  --primary:           var(--efnis-teal);
  --primary-dark:      var(--efnis-teal-dark);
  --primary-tint:      var(--efnis-teal-50);
  --accent:            var(--efnis-amber);
  --accent-dark:       var(--efnis-amber-dark);
  --accent-tint:       var(--efnis-amber-50);
  --border-soft:       var(--efnis-cream-dark);
  --link:              var(--efnis-teal);
  --link-hover:        var(--efnis-teal-dark);

  /* ── GRADIENTS ──────────────────────────────────────────── */
  --efnis-gradient-warm:  linear-gradient(135deg, #ffffff 0%, #e6f2ef 100%);  /* hero, rules backdrop */
  --efnis-gradient-hero:  linear-gradient(160deg, #1a6b5a 0%, #0f4a3e 100%);  /* dark hero / CTA bands */
  --efnis-gradient-amber: linear-gradient(135deg, #f9ecd9 0%, #f3efe6 100%);  /* secondary section */
  --efnis-gradient-deep:  linear-gradient(160deg, #1c2a26 0%, #0f4a3e 100%);  /* footer, deep panel */

  /* ── TYPE — Families ────────────────────────────────────── */
  /* Astro's Fonts API defines --font-source-serif / --font-dm-sans (with
     metric-matched fallbacks). The fallback lists apply where those aren't
     defined, e.g. in the CMS preview pane. */
  --font-serif: var(--font-source-serif, 'Source Serif 4', Georgia, 'Times New Roman', serif);
  --font-sans:  var(--font-dm-sans, 'DM Sans', system-ui, -apple-system, 'Segoe UI', Helvetica, Arial, sans-serif);
  --font-mono:  ui-monospace, 'SF Mono', Menlo, Consolas, monospace;

  /* ── TYPE — Scale ───────────────────────────────────────── */
  --text-xs:   0.75rem;   /* 12px — pill, micro meta */
  --text-sm:   0.85rem;   /* 13.6px — captions, post-list */
  --text-base: 1rem;      /* 16px — body */
  --text-md:   1.1rem;    /* 17.6px — lead, hero subtitle */
  --text-lg:   1.25rem;   /* 20px — small heading */
  --text-xl:   1.5rem;    /* 24px — H3 / section title */
  --text-2xl:  1.75rem;   /* 28px — H2 */
  --text-3xl:  2.25rem;   /* 36px — page title */
  --text-4xl:  3rem;      /* 48px — hero (clamps down on mobile) */

  /* ── SPACING ────────────────────────────────────────────── */
  --efnis-space-xs:  0.5rem;
  --efnis-space-sm:  0.75rem;
  --efnis-space-md:  1.25rem;
  --efnis-space-lg:  2rem;
  --efnis-space-xl:  3rem;
  --efnis-space-2xl: 4.5rem;

  /* ── RADII ──────────────────────────────────────────────── */
  --efnis-radius-sm:    4px;
  --efnis-radius-md:    6px;
  --efnis-radius-lg:    12px;
  --efnis-radius-pill:  99px;

  /* ── SHADOW ─────────────────────────────────────────────── */
  /* All shadows tinted with basalt (rgba 28,42,38) for cohesion
     with the dark neutral — no pure-black shadows. */
  --efnis-shadow-sm:  0 1px 2px rgba(28,42,38,.05), 0 2px 6px rgba(28,42,38,.04);
  --efnis-shadow-md:  0 1px 3px rgba(28,42,38,.05), 0 4px 12px rgba(28,42,38,.06);
  --efnis-shadow-lg:  0 2px 6px rgba(28,42,38,.06), 0 8px 24px rgba(28,42,38,.08);

  /* ── MOTION ─────────────────────────────────────────────── */
  --ease-out:        cubic-bezier(.2, .7, .2, 1);
  --duration-fast:   150ms;
  --duration-base:   200ms;

  /* ── SITE ADDITIONS (not in the design system) ──────────── */
  --container:        1120px;
  --container-narrow: 720px;
  --gutter:           clamp(1rem, 4vw, 2rem);
  --header-height:    4rem;  /* 64px at the default text size; grows with it */
  --focus-ring:       var(--primary);    /* 6.15:1 on page bg */
  --focus-ring-dark:  var(--efnis-cream); /* 5.55:1 on teal */
  --duration-press:   100ms;              /* press feedback (.btn, .card--link) */
}

/* ── RESET ────────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; }
body, h1, h2, h3, h4, h5, p, figure, blockquote, dl, dd { margin: 0; }
img, svg { max-width: 100%; }
img { display: block; height: auto; }
button, input, select, textarea { font: inherit; }
html { -webkit-text-size-adjust: 100%; scroll-padding-top: calc(var(--header-height) + 1rem); }

/* ── SEMANTIC ELEMENT STYLES (from colors_and_type.css) ──── */
/* 100%, not 16px: a fixed px value overrides the text size people set in
   their browser. 100% is 16px unless they chose otherwise. */
html { font-size: 100%; }

body {
  font-family: var(--font-sans);
  font-size: var(--text-base);
  line-height: 1.65;
  color: var(--fg-1);
  background: var(--bg-1);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}
main { flex: 1; }

h1, h2, h3, h4, h5 {
  font-family: var(--font-serif);
  color: var(--primary-dark);
  letter-spacing: -0.01em;
  line-height: 1.2;
  font-weight: 700;
  margin: 0 0 0.5em;
  text-wrap: balance;
}

h1 { font-size: clamp(2rem, 4vw, var(--text-4xl)); line-height: 1.15; }
h2 { font-size: var(--text-2xl); }
h3 { font-size: var(--text-xl); }
h4 { font-size: var(--text-lg); font-weight: 600; }
h5 { font-size: var(--text-base); font-weight: 600; }

p { margin: 0 0 1em; text-wrap: pretty; }
p.lead { font-size: var(--text-md); color: var(--fg-2); max-width: 36em; }

a { color: var(--link); text-decoration: none; transition: color var(--duration-fast) var(--ease-out); }
a:hover { color: var(--link-hover); }

/* Contrast rule: meta text uses ink-muted, not ink-subtle. */
small, .text-meta { font-size: var(--text-sm); color: var(--fg-2); }

code, pre {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--bg-2);
  padding: 0.1em 0.35em;
  border-radius: var(--efnis-radius-sm);
}

::selection { background: var(--primary-tint); color: var(--primary-dark); }

/* ── FOCUS ────────────────────────────────────────────────── */
/* The design system relied on browser defaults; the quality floor asks
   for a visible, consistent focus ring. */
:focus-visible {
  outline: 3px solid var(--focus-ring);
  outline-offset: 2px;
  border-radius: 2px;
}
.on-dark :focus-visible { outline-color: var(--focus-ring-dark); }

/* ── MOTION ───────────────────────────────────────────────── */
/* In-page jumps (hero „Þumalputtareglur ↓“, skip link, heading anchors)
   scroll instead of teleporting, so the reader sees where they went. */
@media (prefers-reduced-motion: no-preference) {
  html { scroll-behavior: smooth; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}

/* Page to page: the header stays put while the page content cross-fades
   (cross-document view transitions; browsers without them just navigate).
   Only for people who haven't asked for reduced motion. */
@media (prefers-reduced-motion: no-preference) {
  @view-transition { navigation: auto; }
  ::view-transition-old(root),
  ::view-transition-new(root) { animation-duration: 220ms; animation-timing-function: var(--ease-out); }
}

/* ── BIREFRINGENCE (design system: optional wordmark optics device) ── */
/* A faint amber double of a word, as if read through a calcite crystal
   (Iceland spar, the mineral in the emblem story). Use sparingly: the
   homepage title only. The ghost is hidden from screen readers by the
   `/ ""` alternative text; browsers that don't know that syntax drop the
   declaration and show no ghost. */
.efnis-birefringence {
  position: relative;
  display: inline-block;
  isolation: isolate;
}
.efnis-birefringence::before {
  content: attr(data-text) / "";
  position: absolute;
  inset: 0;
  color: var(--accent);
  transform: translate(0.05em, 0.025em);
  opacity: 0.55;
  z-index: -1;
  pointer-events: none;
}

/* ── UTILITIES ────────────────────────────────────────────── */
.visually-hidden {
  position: absolute !important;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0 0 0 0);
  white-space: nowrap; border: 0;
}

.skip-link {
  position: absolute;
  left: 1rem; top: -100px;
  z-index: 1000;
  padding: 0.6rem 1rem;
  background: var(--primary-dark);
  color: #fff;
  border-radius: var(--efnis-radius-sm);
  font-weight: 600;
}
.skip-link:focus { top: 0.75rem; color: #fff; }

.container {
  width: 100%;
  max-width: calc(var(--container) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}
.container--narrow { max-width: calc(var(--container-narrow) + 2 * var(--gutter)); }

.section { padding-block: clamp(2.5rem, 6vw, 4rem); }
.section--cream { background: var(--bg-2); }
.section--warm { background: var(--efnis-gradient-warm); }

.section-head { text-align: center; margin-bottom: 2.5rem; }
.section-head h2 { margin-bottom: 0.5rem; }
.section-head p { color: var(--fg-2); max-width: 560px; margin-inline: auto; }

/* ── BUTTONS (Primitives.jsx → Button) ────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.4rem;
  padding: 0.7rem 1.5rem;
  border-radius: var(--efnis-radius-sm);
  border: 1.5px solid transparent;
  font-weight: 600;
  font-size: 0.9rem;
  line-height: 1.3;
  text-decoration: none;
  cursor: pointer;
  transition: background var(--duration-fast) var(--ease-out), color var(--duration-fast) var(--ease-out),
              transform var(--duration-press) var(--ease-out);
}
/* Feedback on press, not only on hover. */
.btn:active { transform: scale(0.97); }
.btn--primary { background: var(--primary); color: #fff; }
.btn--primary:hover { background: var(--primary-dark); color: #fff; }
/* Contrast: basalt on amber (5.19:1). White on amber is only 2.87:1.
   Hover lightens instead of darkening, so the text stays readable (6.1:1). */
.btn--accent { background: var(--accent); color: var(--efnis-basalt); }
.btn--accent:hover { background: color-mix(in srgb, var(--accent) 85%, #fff); color: var(--efnis-basalt); }
.btn--ghost { background: rgba(255,255,255,0.12); color: #fff; border-color: rgba(255,255,255,0.25); }
.btn--ghost:hover { background: rgba(255,255,255,0.20); color: #fff; }
.btn--outline { background: transparent; color: var(--primary); border-color: var(--primary); }
.btn--outline:hover { background: var(--primary-tint); color: var(--primary-dark); }

/* ── PILLS ────────────────────────────────────────────────── */
.efnis-pill {
  display: inline-block;
  padding: 0.2rem 0.65rem;
  border-radius: var(--efnis-radius-pill);
  font-size: var(--text-xs);
  font-weight: 600;
  letter-spacing: 0.02em;
  background: var(--primary-tint);
  color: var(--primary-dark);
}
/* Contrast: basalt on amber-50 (12.8:1). amber-dark text was 3.5:1. */
.efnis-pill-amber { background: var(--accent-tint); color: var(--efnis-basalt); }

/* ── CARD (signature: 3px top border, alternating teal/amber) ── */
.card {
  background: var(--bg-card);
  border-radius: var(--efnis-radius-md);
  border-top: 3px solid var(--primary);
  box-shadow: var(--efnis-shadow-md);
  padding: 1.5rem;
  transition: transform var(--duration-base) var(--ease-out), box-shadow var(--duration-base) var(--ease-out);
}
.card-list > :nth-child(even) .card,
.card-list > .card:nth-child(even) { border-top-color: var(--accent); }
.card--link:focus-within { transform: translateY(-2px); box-shadow: var(--efnis-shadow-lg); }
/* Hover lift only on devices that hover: on a phone a tapped card would stay lifted. */
@media (hover: hover) {
  .card--link:hover { transform: translateY(-2px); box-shadow: var(--efnis-shadow-lg); }
}
/* Press: the card settles back down, quickly. */
.card--link:active { transform: translateY(0) scale(0.99); box-shadow: var(--efnis-shadow-md); transition-duration: var(--duration-press); }

/* ── PLACEHOLDER (TODO(texti) markers must be impossible to miss) ── */
.todo {
  display: inline-block;
  padding: 0.1em 0.45em;
  border: 1.5px dashed var(--accent);
  border-radius: var(--efnis-radius-sm);
  background: var(--accent-tint);
  color: var(--efnis-basalt);
  font-family: var(--font-mono);
  font-size: 0.85em;
  font-style: normal;
  font-weight: 400;
  letter-spacing: 0;
}

/* ── PROSE (rendered Markdown bodies, also used by the CMS preview) ── */
.prose { color: var(--fg-1); }
/* Reading measure: about 75 characters a line (36em; DM Sans digits are wide,
   so 68ch came out at ~95 characters). Tables, images and two-column
   lists keep the full column. */
.prose:not(.prose--columns) > :is(p, ul, ol, blockquote, h2, h3, h4, dl) { max-width: 36em; }
.prose > * + * { margin-top: 1.1em; }
.prose p { margin-bottom: 0; } /* spacing comes from `.prose > * + *` */
/* Pages whose first paragraph is an introduction (Um Efnís). */
.prose--lead > p:first-child { font-size: var(--text-md); color: var(--fg-2); }
.prose h2 { font-size: 1.4rem; margin: 2.25rem 0 0.75rem; }
.prose h3 { font-size: 1.15rem; margin: 1.75rem 0 0.5rem; }
.prose h2 + *, .prose h3 + * { margin-top: 0; }
.prose ul, .prose ol { padding-left: 1.4rem; margin-bottom: 0; }
.prose li + li { margin-top: 0.35em; }
.prose li { text-wrap: pretty; } /* no one-word last lines in list items */
.prose a:not(.btn) { text-decoration: underline; text-underline-offset: 0.15em; text-decoration-thickness: 1px; }
.prose blockquote {
  border-left: 3px solid var(--accent);
  padding: 1rem 1.5rem;
  background: var(--accent-tint);
  border-radius: 0 var(--efnis-radius-md) var(--efnis-radius-md) 0;
  font-style: italic;
}
.prose img { border-radius: var(--efnis-radius-md); }
/* Small figure: in Markdown, an image on its own line followed by a caption
   written in _italics_ on the next line becomes a narrow figure (the 1999
   clipping and the silfurberg photo on Um Efnís). On wide screens it floats right beside the text. */
.prose > p:has(> img:only-child):has(+ p > em:only-child),
.prose > p:has(> img:only-child) + p:has(> em:only-child) { width: 14rem; }
.prose > p:has(> img:only-child) + p:has(> em:only-child) { margin-top: 0.5rem; font-size: var(--text-sm); color: var(--fg-2); }
@media (min-width: 900px) {
  .prose > p:has(> img:only-child):has(+ p > em:only-child),
  .prose > p:has(> img:only-child) + p:has(> em:only-child) { float: right; clear: right; margin-left: 2rem; }
  .prose > p:has(> img:only-child) + p:has(> em:only-child) { margin-bottom: 1.5rem; }
  /* A figure that opens a section stays in it: later headings start below it. */
  .prose > h2:has(+ p > img:only-child) ~ h2 { clear: right; }
}
/* Image with a caption from the CMS editor's image button ("Caption" field):
   saved as <figure><img><figcaption>…</figcaption></figure>. Full column
   width, caption styled like the small figure's above. */
.prose figure { max-width: 36em; }
.prose figcaption { margin-top: 0.5rem; font-size: var(--text-sm); color: var(--fg-2); }
.prose figcaption a { color: inherit; }
.prose hr { border: 0; border-top: 1px solid var(--border-soft); margin-block: 2rem; }
.prose table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.prose th, .prose td { text-align: left; padding: 0.55rem 0.75rem; border-bottom: 1px solid var(--border-soft); vertical-align: top; }
.prose th { color: var(--primary-dark); font-weight: 600; }
.prose td:first-child { white-space: nowrap; } /* keep short codes like P-01 on one line */
/* Markdown tables get this wrapper from scripts/markdown-plugins.mjs: a table
   wider than the column scrolls inside it instead of widening the page. */
.table-scroll { overflow-x: auto; }
@media (max-width: 480px) {
  .prose table { font-size: 0.85rem; }
  .prose th, .prose td { padding: 0.5rem 0.4rem; hyphens: auto; }
}
/* Long lists (Stjórn history, Bókagjafir, Tenglar): lists and line-broken
   paragraphs of names flow into two columns on wide screens. */
@media (min-width: 640px) {
  .prose--columns :is(ul, ol, p:has(> br)) { columns: 2; column-gap: 2rem; }
  .prose--columns li { break-inside: avoid; }
}
