/* NRTHMAIL base: tokens, type, header, footer, controls, dialogs.
   Art direction: "Polar Day / Polar Night instrument log" (SPEC §7). */

/* ---------- Fonts (self-hosted, latin + latin-ext) ---------- */
@font-face {
  font-family: "Schibsted Grotesk";
  font-style: normal;
  font-display: swap;
  font-weight: 400 900;
  src: url(../fonts/schibsted-grotesk-latin.woff2?v=4fa72f8c35e9) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Schibsted Grotesk";
  font-style: normal;
  font-display: swap;
  font-weight: 400 900;
  src: url(../fonts/schibsted-grotesk-latin-ext.woff2?v=4fa72f8c35e9) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
@font-face {
  font-family: "Schibsted Grotesk";
  font-style: italic;
  font-display: swap;
  font-weight: 400 900;
  src: url(../fonts/schibsted-grotesk-latin-italic.woff2?v=4fa72f8c35e9) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Schibsted Grotesk";
  font-style: italic;
  font-display: swap;
  font-weight: 400 900;
  src: url(../fonts/schibsted-grotesk-latin-ext-italic.woff2?v=4fa72f8c35e9) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}
/* Martian Mono: both axes, so font-stretch 75%–112.5% drives wdth. */
@font-face {
  font-family: "Martian Mono";
  font-style: normal;
  font-display: swap;
  font-weight: 100 800;
  font-stretch: 75% 112.5%;
  src: url(../fonts/martian-mono-latin.woff2?v=4fa72f8c35e9) format("woff2");
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}
@font-face {
  font-family: "Martian Mono";
  font-style: normal;
  font-display: swap;
  font-weight: 100 800;
  font-stretch: 75% 112.5%;
  src: url(../fonts/martian-mono-latin-ext.woff2?v=4fa72f8c35e9) format("woff2");
  unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

/* ---------- Tokens ---------- */
:root {
  --sans: "Schibsted Grotesk", "Helvetica Neue", Helvetica, sans-serif;
  --mono: "Martian Mono", ui-monospace, Menlo, Consolas, monospace;

  --fs-addr: clamp(1.375rem, 1rem + 3.4vw, 3.5rem);
  --fs-xl: clamp(1.75rem, 1.3rem + 1.6vw, 2.5rem);
  --fs-l: 1.375rem;
  --fs-m: 1.0625rem;
  --fs-body: 1rem;
  --fs-s: 0.875rem;
  --fs-label: 0.6875rem;

  --radius: 0;
  --radius-s: 2px;

  --s1: 4px;
  --s2: 8px;
  --s3: 12px;
  --s4: 16px;
  --s5: 24px;
  --s6: 32px;
  --s7: 48px;
  --s8: 72px;
  --s9: 112px;

  --wrap: 1240px;
  --gutter: clamp(16px, 4vw, 40px);
  --header-h: 56px;
  --measure: 68ch;

  --t-fast: 120ms;
  --t-med: 220ms;
  --t-slow: 600ms;
  --ease: cubic-bezier(.2, .7, .1, 1);

  --z-header: 10;
  --z-menu: 20;
  --z-sheet: 40;
  --z-toast: 50;
}

/* Polar Day (light) is the default; Polar Night follows the system unless a choice is stored. */
:root,
:root[data-theme="day"] {
  color-scheme: light;
  --bg: #EEF0EC;
  --paper: #F8F9F6;
  --ink: #111417;
  --ink-2: #41474D;
  --ink-3: #5E656C;
  --rule: #C5CAC4;
  --rule-2: #DADDD8;
  --signal: #FF4F00;
  --signal-ink: #111417;
  --signal-text: #B23A00;
  --ok: #2E6B45;
  --warn: #8A5A00;
  --err: #B3261E;
  --select: #FFD9C2;
  /* The orange ring alone sits at 2.9:1 on firn white; a hairline of ink outside it keeps
     the focus indicator above 3:1 (WCAG 1.4.11). */
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--signal), 0 0 0 5px var(--ink);
  /* Same rule for rings drawn inside an element (nav links, log rows): orange, then ink. */
  --focus-inset: inset 0 0 0 2px var(--signal), inset 0 0 0 3px var(--ink);
  --scrim: rgba(17, 20, 23, .38);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme]) {
    color-scheme: dark;
    --bg: #0E1114;
    --paper: #151A1F;
    --ink: #E4E7E1;
    --ink-2: #A9B0B6;
    --ink-3: #868E96;
    --rule: #2A3138;
    --rule-2: #1F252B;
    --signal: #FF5F1A;
    --signal-ink: #0E1114;
    --signal-text: #FF8A4C;
    --ok: #7CC495;
    --warn: #E3B25A;
    --err: #FF8A80;
    --select: #5A2A10;
    --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--signal);
    --focus-inset: inset 0 0 0 2px var(--signal);
    --scrim: rgba(0, 0, 0, .6);
  }
}
:root[data-theme="night"] {
  color-scheme: dark;
  --bg: #0E1114;
  --paper: #151A1F;
  --ink: #E4E7E1;
  --ink-2: #A9B0B6;
  --ink-3: #868E96;
  --rule: #2A3138;
  --rule-2: #1F252B;
  --signal: #FF5F1A;
  --signal-ink: #0E1114;
  --signal-text: #FF8A4C;
  --ok: #7CC495;
  --warn: #E3B25A;
  --err: #FF8A80;
  --select: #5A2A10;
  --focus: 0 0 0 2px var(--bg), 0 0 0 4px var(--signal);
  --focus-inset: inset 0 0 0 2px var(--signal);
  --scrim: rgba(0, 0, 0, .6);
}

/* ---------- Reset and base type ---------- */
*,
*::before,
*::after { box-sizing: border-box; }
[hidden] { display: none !important; }

html {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 100%;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
  font-kerning: normal;
  scroll-padding-top: calc(var(--header-h) + var(--s5));
  overflow-x: clip;
}
body {
  margin: 0;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  overflow-x: clip;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
main { flex: 1 0 auto; }
main:focus { outline: none; }
h1, h2, h3, h4, p, ul, ol, dl, figure, pre { margin: 0; }
ul, ol { padding: 0; }
img, svg { display: block; max-width: 100%; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
button:disabled { cursor: default; }
::selection { background: var(--select); color: var(--ink); }
b, strong { font-weight: 650; }
code, kbd, samp, pre { font-family: var(--mono); font-size: 0.875em; font-stretch: 100%; }
pre, .table-wrap { scrollbar-width: thin; scrollbar-color: var(--rule) transparent; }

a { color: var(--ink); text-decoration-line: underline; text-decoration-thickness: 1px; text-decoration-color: var(--ink-3); text-underline-offset: 3px; }
a:hover { text-decoration-color: var(--ink); text-decoration-thickness: 2px; }

:focus { outline: none; }
:focus-visible { outline: none; box-shadow: var(--focus); }
a:focus-visible { -webkit-box-decoration-break: clone; box-decoration-break: clone; }

.wrap {
  width: 100%;
  max-width: calc(var(--wrap) + 2 * var(--gutter));
  margin-inline: auto;
  padding-inline: var(--gutter);
}

.sr-only {
  position: absolute !important;
  width: 1px;
  height: 1px;
  margin: -1px;
  padding: 0;
  overflow: hidden;
  clip-path: inset(50%);
  white-space: nowrap;
  border: 0;
}

/* Engraved instrument label */
.label {
  font-family: var(--mono);
  font-size: var(--fs-label);
  font-weight: 500;
  font-stretch: 112.5%;
  line-height: 1.45;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
}
.mono { font-family: var(--mono); font-stretch: 100%; }

.skip {
  position: absolute;
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  left: var(--gutter);
  top: -100px;
  z-index: 100;
  padding: var(--s2) var(--s3);
  background: var(--ink);
  color: var(--bg);
  text-decoration: none;
  font-weight: 600;
}
.skip:focus { top: var(--s2); }

/* ---------- Header ---------- */
.site-header {
  position: sticky;
  top: 0;
  z-index: var(--z-header);
  background: var(--bg);
  border-bottom: 1px solid var(--rule);
}
.header-row {
  display: flex;
  align-items: center;
  height: var(--header-h);
  gap: var(--s7);
}

.wordmark {
  display: inline-flex;
  align-items: center;
  min-height: 44px;
  color: var(--ink);
  text-decoration: none;
  flex: none;
}
.wordmark:hover { text-decoration: none; }
.wm-nrth {
  font-family: var(--sans);
  font-weight: 800;
  font-size: 1.25rem;
  line-height: 1;
  letter-spacing: .015em;
}
/* The north marker: a 4px orange square at the top-right of the N, flush with its cap
   height (the glyph's inline box starts 0.3em above the cap line). */
.wm-n { position: relative; margin-right: 5px; }
.wm-n::after {
  content: "";
  position: absolute;
  top: .3em;
  right: -5px;
  width: 4px;
  height: 4px;
  background: var(--signal);
}
.wm-rule {
  width: 1px;
  height: 20px;
  background: var(--ink);
  margin-inline: 11px 10px;
}
.wm-mail {
  font-family: var(--mono);
  font-weight: 500;
  font-size: .75rem;
  font-stretch: 112.5%;
  letter-spacing: .12em;
  line-height: 1;
  color: var(--ink-2);
  text-transform: uppercase;
}

.menu {
  display: flex;
  align-items: center;
  flex: 1;
  gap: var(--s6);
  min-width: 0;
}
.nav { display: flex; align-items: stretch; gap: var(--s5); height: var(--header-h); }
.nav a {
  display: inline-flex;
  align-items: center;
  font-size: var(--fs-s);
  font-weight: 500;
  color: var(--ink-2);
  text-decoration: none;
  border-bottom: 2px solid transparent;
  padding-top: 2px;
}
.nav a:hover { color: var(--ink); }
.nav a[aria-current="page"] { color: var(--ink); border-bottom-color: var(--ink); }
.nav a:focus-visible { box-shadow: var(--focus-inset); }

.switches { margin-left: auto; display: flex; align-items: center; gap: var(--s5); }
.switch { display: flex; align-items: center; }
.switch-sep { color: var(--rule); font-family: var(--mono); font-size: var(--fs-label); }
.switch a,
.switch button {
  display: inline-flex;
  align-items: center;
  min-height: 32px;
  padding: 0 6px;
  font-family: var(--mono);
  font-size: var(--fs-label);
  font-weight: 500;
  font-stretch: 112.5%;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-3);
  background: none;
  border: 0;
  text-decoration: none;
}
.switch a:hover,
.switch button:hover { color: var(--ink); }
.switch a[aria-current="true"],
:root[data-theme="day"] .switch [data-set-theme="day"],
:root[data-theme="night"] .switch [data-set-theme="night"] {
  color: var(--ink);
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-underline-offset: 5px;
}
.theme-icon { width: 16px; height: 16px; color: var(--ink-2); margin-right: 4px; flex: none; }
.theme-icon .sun-night { display: none; }
:root[data-theme="night"] .theme-icon .sun-day { display: none; }
:root[data-theme="night"] .theme-icon .sun-night { display: inline; }

.menu-btn {
  display: none;
  align-items: center;
  min-height: 44px;
  margin-left: auto;
  padding: 0 0 0 var(--s4);
  background: none;
  border: 0;
  font-family: var(--mono);
  font-size: var(--fs-label);
  font-weight: 500;
  font-stretch: 112.5%;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink);
}
.menu-btn-bars { display: inline-block; width: 14px; height: 7px; margin-left: 10px; border-block: 1px solid currentColor; }
[data-menu-open] .menu-btn-bars { height: 1px; border-bottom: 0; }

@media (max-width: 899.98px) {
  .header-row { gap: var(--s4); }
  .menu-btn { display: inline-flex; }
  .menu {
    display: none;
    position: fixed;
    top: var(--header-h);
    left: 0;
    right: 0;
    z-index: var(--z-menu);
    flex-direction: column;
    align-items: stretch;
    gap: 0;
    max-height: calc(100dvh - var(--header-h));
    overflow-y: auto;
    padding: 0 var(--gutter) var(--s6);
    background: var(--bg);
    border-bottom: 1px solid var(--ink);
  }
  [data-menu-open] .menu { display: flex; }
  .nav { flex-direction: column; height: auto; gap: 0; }
  .nav a {
    min-height: 56px;
    font-size: var(--fs-l);
    font-weight: 600;
    color: var(--ink);
    border-bottom: 1px solid var(--rule);
    padding-top: 0;
  }
  .nav a[aria-current="page"] { border-bottom-color: var(--rule); }
  .nav a[aria-current="page"]::after {
    content: "";
    width: 6px;
    height: 6px;
    margin-left: var(--s3);
    background: var(--ink);
  }
  .switches { margin: var(--s5) 0 0; justify-content: space-between; }
  .switch a,
  .switch button { min-height: 44px; min-width: 44px; justify-content: center; padding: 0 var(--s2); }
}

/* Without JavaScript: no theme switch or menu sheet; the nav stays inline. */
html:not(.js) .js-only { display: none !important; }
@media (max-width: 899.98px) {
  html:not(.js) .header-row { flex-wrap: wrap; height: auto; min-height: var(--header-h); column-gap: var(--s4); }
  html:not(.js) .menu-btn { display: none; }
  html:not(.js) .menu {
    display: flex;
    position: static;
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    gap: 0 var(--s4);
    padding: 0;
    max-height: none;
    overflow: visible;
    background: none;
    border: 0;
  }
  html:not(.js) .nav { flex-direction: row; height: auto; gap: var(--s4); }
  html:not(.js) .nav a { min-height: 44px; font-size: var(--fs-s); font-weight: 500; border-bottom: 0; }
  html:not(.js) .nav a[aria-current="page"]::after { display: none; }
  html:not(.js) .switches { margin: 0 0 0 auto; }
}

/* ---------- Footer ---------- */
.site-footer { border-top: 1px solid var(--ink); }
.footer-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: var(--s3) var(--s6);
  padding-block: var(--s5) var(--s6);
}
.footer-line { font-weight: 650; font-size: var(--fs-s); }
.footer-nav { display: flex; flex-wrap: wrap; gap: var(--s1) var(--s5); font-size: var(--fs-s); }
.footer-nav a { color: var(--ink-2); display: inline-flex; align-items: center; min-height: 32px; padding-inline: 2px; }
.footer-stats { margin-left: auto; }
@media (max-width: 899.98px) {
  .footer-nav a { min-height: 44px; min-width: 44px; justify-content: center; }
}
@media (max-width: 559.98px) {
  .footer-row { flex-direction: column; gap: var(--s3); }
  .footer-stats { margin-left: 0; }
}

/* ---------- Controls ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--s3);
  min-height: 44px;
  padding: 0 var(--s4);
  border: 1px solid var(--ink);
  border-radius: var(--radius);
  background: transparent;
  color: var(--ink);
  font-family: var(--sans);
  font-size: var(--fs-body);
  font-weight: 600;
  line-height: 1;
  text-decoration: none;
  white-space: nowrap;
}
.btn:hover { background: var(--ink); color: var(--bg); text-decoration: none; }
.btn-primary { background: var(--ink); color: var(--bg); }
.btn-primary:hover { background: var(--ink-2); border-color: var(--ink-2); }
.btn-danger { border-color: var(--err); color: var(--err); }
.btn-danger:hover { background: var(--err); color: var(--bg); }
.btn:disabled { opacity: .45; pointer-events: none; }

.btn-text {
  display: inline-flex;
  align-items: center;
  gap: var(--s2);
  min-height: 44px;
  padding: 0 var(--s2);
  background: none;
  border: 0;
  color: var(--ink);
  font-weight: 500;
  text-decoration: underline;
  text-decoration-thickness: 1px;
  text-decoration-color: var(--ink-3);
  text-underline-offset: 4px;
}
.btn-text:hover { text-decoration-color: var(--ink); text-decoration-thickness: 2px; }

kbd {
  display: inline-grid;
  place-items: center;
  min-width: 20px;
  height: 20px;
  padding: 0 4px;
  border: 1px solid var(--rule);
  font-family: var(--mono);
  font-size: var(--fs-label);
  font-weight: 500;
  font-stretch: 100%;
  line-height: 1;
  color: var(--ink-3);
}

/* Copy confirmation: the label swaps and an orange line sweeps under the control. */
.copyable { position: relative; }
.copyable::after {
  content: "";
  position: absolute;
  left: 0;
  right: 0;
  bottom: -5px;
  height: 2px;
  background: var(--signal);
  transform: scaleX(0);
  transform-origin: left center;
  pointer-events: none;
}
.copyable.is-copied::after { transform: scaleX(1); transition: transform var(--t-med) var(--ease); }

.input {
  min-height: 44px;
  padding: 0 var(--s3);
  border: 1px solid var(--ink-3);
  border-radius: var(--radius-s);
  background: var(--paper);
  color: var(--ink);
}
.input:focus-visible { border-color: var(--ink); }
.input[aria-invalid="true"] { border-color: var(--err); }

/* ---------- Dialogs ---------- */
dialog.dlg {
  width: min(560px, calc(100vw - 2 * var(--gutter)));
  max-height: calc(100dvh - 2 * var(--s6));
  padding: 0;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: var(--bg);
  color: var(--ink);
  box-shadow: none;
  overflow: auto;
}
dialog.dlg::backdrop { background: rgba(17, 20, 23, .38); }
:root[data-theme="night"] dialog.dlg::backdrop { background: rgba(0, 0, 0, .6); }
.dlg-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--s4);
  padding: var(--s2) var(--s2) var(--s2) var(--s5);
  border-bottom: 1px solid var(--rule);
}
.dlg-title { font-size: var(--fs-m); font-weight: 700; line-height: 1.3; }
.dlg-x {
  min-height: 44px;
  padding: 0 var(--s3);
  background: none;
  border: 0;
  font-family: var(--mono);
  font-size: var(--fs-label);
  font-weight: 500;
  font-stretch: 112.5%;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--ink-2);
}
.dlg-x:hover { color: var(--ink); }
.dlg-body { padding: var(--s5); display: grid; gap: var(--s4); }
.dlg-body p { max-width: 52ch; }
.dlg-actions {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: var(--s3) var(--s4);
  padding: var(--s4) var(--s5) var(--s5);
}
@media (max-width: 559.98px) {
  dialog.dlg {
    width: 100%;
    max-width: 100%;
    margin: auto 0 0;
    max-height: calc(100dvh - var(--s6));
    border-width: 1px 0 0;
  }
  .dlg-actions .btn { flex: 1 1 auto; }
}

/* ---------- Toast ---------- */
.toast {
  position: fixed;
  left: var(--gutter);
  bottom: var(--gutter);
  z-index: var(--z-toast);
  display: flex;
  align-items: center;
  gap: var(--s4);
  max-width: min(520px, calc(100vw - 2 * var(--gutter)));
  padding: var(--s3) var(--s3) var(--s3) var(--s4);
  background: var(--ink);
  color: var(--bg);
  font-size: var(--fs-s);
  line-height: 1.4;
}
.toast[hidden] { display: none; }
.toast .btn-text { color: var(--bg); text-decoration-color: var(--bg); min-height: 36px; }

/* ---------- Motion preferences ---------- */
@keyframes breathe {
  0%, 100% { opacity: 1; }
  50% { opacity: .3; }
}
/* Reduced motion: every movement becomes an instant state change. (A tiny duration would
   still create a transition for every property, so switch them off outright.) */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
    scroll-behavior: auto !important;
  }
}
