/* ==========================================================================
   Huginn — design tokens and components
   "Night watch" in the dark (ink ground, bone text, one cool accent), paper
   and ink in the light; the theme follows the system. Loaded before
   style.css, which builds the pages on these tokens; the hg-* components
   are for pages built on them (reading companion, stocks, Mastodon).
   Fonts: IBM Plex Sans / Mono / Serif, self-hosted in fonts/ (latin subset,
   SIL OFL 1.1, fonts/OFL.txt), so no page asks a third party for anything.
   ========================================================================== */

/* ---------- Fonts ---------- */
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/ibm-plex-sans-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 500; font-display: swap; src: url("fonts/ibm-plex-sans-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Sans"; font-style: normal; font-weight: 600; font-display: swap; src: url("fonts/ibm-plex-sans-latin-600-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/ibm-plex-mono-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Mono"; font-style: normal; font-weight: 500; font-display: swap; src: url("fonts/ibm-plex-mono-latin-500-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Serif"; font-style: normal; font-weight: 400; font-display: swap; src: url("fonts/ibm-plex-serif-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "IBM Plex Serif"; font-style: italic; font-weight: 400; font-display: swap; src: url("fonts/ibm-plex-serif-latin-400-italic.woff2") format("woff2"); }

/* ---------- Tokens ---------- */
/* Light. Text colours pass 4.5:1 on panel and ground. */
:root {
  /* Surfaces */
  --hg-ground: #F4F2ED;
  --hg-aside: #EFECE6;
  --hg-panel: #FFFFFF;
  --hg-raised: #ECE8E1;
  --hg-active: #E4DFD6;

  /* Lines */
  --hg-line: #E2DED6;
  --hg-line-soft: #ECE8E1;
  --hg-line-strong: #CFCAC0;
  --hg-field: #D3CEC4;
  --hg-btn-line: #C4BEB3;
  --hg-chip-line: #D3CEC4;

  /* Text */
  --hg-text: #1B1E21;
  --hg-text-hover: #000000;
  --hg-text-read: #2A2D31;
  --hg-text-2: #3F454B;
  --hg-text-3: #4A5056;
  --hg-muted: #5F656B;
  --hg-faint: #61676D;
  --hg-placeholder: #676D73;

  /* Accent and states */
  --hg-accent: #1D6A82;
  --hg-accent-wash: rgba(29, 106, 130, 0.18);
  --hg-warm: #94560F;            /* down moves, conflicts, private mode */
  --hg-warm-wash: rgba(227, 163, 91, 0.35);
  --hg-on-accent: #FFFFFF;
  --hg-ok: #2E7D32;
  --hg-error: #B3261E;

  /* Muninn's graph, one colour per note type */
  --hg-graph-chat: #1D6A82;
  --hg-graph-recap: #2E7D32;
  --hg-graph-briefing: #94560F;
  --hg-graph-reading: #6B4FA0;
  --hg-graph-concept: #7A6A2E;
  --hg-graph-topic: #A23B6B;
  --hg-graph-note: #3F454B;
  --hg-graph-unresolved: #B5AFA4;
  --hg-graph-edge: rgba(27, 30, 33, 0.16);

  /* Type */
  --hg-sans: "IBM Plex Sans", system-ui, -apple-system, "Segoe UI", sans-serif;
  --hg-mono: "IBM Plex Mono", ui-monospace, monospace;
  --hg-serif: "IBM Plex Serif", Georgia, serif;

  /* Shape & rhythm */
  --hg-r-sm: 6px;
  --hg-r: 10px;
  --hg-r-md: 12px;
  --hg-r-lg: 16px;
  --hg-tap: 44px;

  color-scheme: light;
}

/* Dark: the original night watch. Text colours pass 4.5:1 on panel. */
@media (prefers-color-scheme: dark) {
  :root {
    --hg-ground: #0E1012;
    --hg-aside: #121417;
    --hg-panel: #15181B;
    --hg-raised: #181B1F;
    --hg-active: #22262B;

    --hg-line: #1F2327;
    --hg-line-soft: #22262A;
    --hg-line-strong: #2E3338;
    --hg-field: #262A2F;
    --hg-btn-line: #3A3F45;
    --hg-chip-line: #2A2E33;

    --hg-text: #E9E6DF;
    --hg-text-hover: #FFFFFF;
    --hg-text-read: #D6D2CA;
    --hg-text-2: #B4B9BE;
    --hg-text-3: #A9AEB3;
    --hg-muted: #9AA0A6;
    --hg-faint: #8B9197;
    --hg-placeholder: #7D848B;

    /* Accent: swap for lilac #C9B6E4, sage #A8C99A or amber #E3A35B */
    --hg-accent: #8EC5D6;
    --hg-accent-wash: rgba(142, 197, 214, 0.28);
    --hg-warm: #E3A35B;
    --hg-warm-wash: rgba(227, 163, 91, 0.30);
    --hg-on-accent: #0E1012;
    --hg-ok: #A8C99A;
    --hg-error: #F2948C;

    --hg-graph-chat: #8EC5D6;
    --hg-graph-recap: #A8C99A;
    --hg-graph-briefing: #E3A35B;
    --hg-graph-reading: #C9B6E4;
    --hg-graph-concept: #D9C98A;
    --hg-graph-topic: #E89BBE;
    --hg-graph-note: #B4B9BE;
    --hg-graph-unresolved: #4A5056;
    --hg-graph-edge: rgba(233, 230, 223, 0.14);

    color-scheme: dark;
  }
}

/* ---------- Base ---------- */
*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--hg-ground);
  color: var(--hg-text);
  font-family: var(--hg-sans);
  font-size: 15px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}
button, input, select, textarea { font: inherit; }
:focus-visible { outline: 2px solid var(--hg-accent); outline-offset: 2px; }
::placeholder { color: var(--hg-placeholder); opacity: 1; }
.hg-sr {
  position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; border: 0;
  overflow: hidden; clip-path: inset(50%); white-space: nowrap;
}
/* Resets for pages built from the components; the older pages keep theirs. */
:where(.hg-app, .hg-reader) a { color: var(--hg-text); text-decoration: none; }
:where(.hg-app, .hg-reader) a:hover { color: var(--hg-text-hover); }
:where(.hg-app, .hg-reader) :where(h1, h2, h3, p) { margin: 0; }

/* ---------- Typography ---------- */
.hg-display { font-size: 44px; line-height: 1.05; font-weight: 500; letter-spacing: -0.025em; }
.hg-title   { font-size: 20px; font-weight: 500; line-height: 1.3; letter-spacing: -0.01em; }
.hg-subtitle{ font-size: 17px; font-weight: 500; line-height: 1.35; }
.hg-body    { font-size: 15px; line-height: 1.6; color: var(--hg-text-3); }
.hg-eyebrow {
  font-family: var(--hg-mono); font-size: 11px; font-weight: 500;
  letter-spacing: 0.12em; text-transform: uppercase; color: var(--hg-faint);
}
.hg-eyebrow--accent { color: var(--hg-accent); font-size: 12px; }
.hg-mono    { font-family: var(--hg-mono); font-size: 12px; color: var(--hg-faint); }
.hg-link    { font-size: 14px; color: var(--hg-accent); }
.hg-link:hover { color: var(--hg-text); }

/* ---------- App shell (sidebar + main; a nav strip on phones) ---------- */
.hg-app { min-height: 100vh; min-height: 100dvh; display: flex; flex-wrap: wrap; align-items: stretch; }

.hg-sidebar {
  flex: 1 1 232px;
  padding: 32px 20px;
  border-right: 1px solid var(--hg-line);
  display: flex; flex-direction: column; gap: 32px;
}
.hg-main { flex: 999 1 560px; min-width: 0; padding: 40px 48px 64px; }
.hg-container { max-width: 1120px; margin: 0 auto; display: flex; flex-direction: column; gap: 32px; }

.hg-brand { display: flex; align-items: center; gap: 12px; padding: 0 12px; font-size: 20px; font-weight: 600; letter-spacing: -0.01em; }
.hg-brand svg { color: var(--hg-accent); }

.hg-nav { display: flex; flex-direction: column; gap: 2px; }
.hg-nav a {
  display: flex; align-items: center; gap: 12px;
  min-height: var(--hg-tap); padding: 0 12px;
  border-radius: 8px; font-size: 15px; color: var(--hg-text-2);
}
.hg-nav a:hover { background: var(--hg-raised); color: var(--hg-text); }
.hg-nav a[aria-current="page"] { background: var(--hg-raised); color: var(--hg-text); font-weight: 500; }
.hg-nav a[aria-current="page"] svg { color: var(--hg-accent); }
/* A sub-page (Begriffe under Muninn): indented to the label above it. */
.hg-nav a.hg-nav__sub { min-height: 34px; padding-left: 42px; font-size: 14px; margin-top: -2px; }
.hg-nav a.hg-nav__sub svg { display: none; }

.hg-sources { display: flex; flex-direction: column; gap: 10px; padding: 0 12px; }
.hg-source { display: flex; align-items: center; justify-content: space-between; min-height: 28px; font-size: 14px; color: var(--hg-text-2); }
.hg-source__name { display: flex; align-items: center; gap: 10px; }

.hg-dot { width: 7px; height: 7px; border-radius: 50%; background: var(--hg-accent); flex: none; }
.hg-dot--warm { background: var(--hg-warm); }
.hg-dot--off  { background: var(--hg-line-strong); }

.hg-note-box {
  margin-top: auto; padding: 14px 12px;
  border: 1px solid var(--hg-line); border-radius: var(--hg-r);
  display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 500;
}
.hg-note-box span { font-size: 12px; font-weight: 400; color: var(--hg-faint); }

/* The support link (-coffee-url): quiet, at the sidebar's foot above the
   user box, which then doesn't push away from it. */
.hg-support { margin-top: auto; display: flex; align-items: center; gap: 10px; padding: 0 12px; min-height: 32px; font-size: 13px; color: var(--hg-faint); }
.hg-support:hover { color: var(--hg-text); }
.hg-support:hover svg { color: var(--hg-warm); }
.hg-support ~ .hg-note-box { margin-top: -16px; }

/* ---------- Page header ---------- */
.hg-header { display: flex; flex-wrap: wrap; align-items: flex-end; justify-content: space-between; gap: 16px; }
.hg-header__text { display: flex; flex-direction: column; gap: 8px; }

.hg-status {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 8px 12px; border: 1px solid var(--hg-line); border-radius: 999px;
  font-family: var(--hg-mono); font-size: 12px; color: var(--hg-muted);
}

/* ---------- Buttons ---------- */
.hg-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: var(--hg-tap); padding: 0 18px;
  border: 1px solid var(--hg-btn-line); border-radius: var(--hg-r);
  background: transparent; color: var(--hg-text);
  font-size: 15px; font-weight: 500; cursor: pointer;
}
.hg-btn:hover { background: var(--hg-raised); }
.hg-btn--primary { background: var(--hg-accent); border-color: var(--hg-accent); color: var(--hg-on-accent); font-weight: 600; }
.hg-btn--primary:hover { background: var(--hg-text); border-color: var(--hg-text); color: var(--hg-ground); }
.hg-btn--light { background: var(--hg-text); border-color: var(--hg-text); color: var(--hg-ground); }
.hg-btn--icon { width: var(--hg-tap); padding: 0; }

/* ---------- Ask bar ---------- */
.hg-ask {
  display: flex; align-items: center; gap: 12px;
  background: var(--hg-panel); border: 1px solid var(--hg-field);
  border-radius: 14px; padding: 8px 8px 8px 20px;
}
.hg-ask:focus-within { border-color: var(--hg-accent); }
.hg-ask svg { color: var(--hg-faint); flex: none; }
.hg-ask input {
  flex: 1; min-width: 0; height: var(--hg-tap);
  background: transparent; border: 0; outline: none;
  color: var(--hg-text); font-size: 16px;
}

/* ---------- Chips / filters ---------- */
.hg-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.hg-chip {
  min-height: 36px; padding: 0 14px; border-radius: 999px;
  border: 1px solid var(--hg-chip-line); background: transparent;
  color: var(--hg-text-2); font-size: 13px; font-weight: 400; cursor: pointer;
}
.hg-chip:hover { border-color: var(--hg-line-strong); color: var(--hg-text); }
.hg-chip[aria-pressed="true"] { background: var(--hg-text); border-color: var(--hg-text); color: var(--hg-ground); font-weight: 500; }

/* ---------- Tags ---------- */
.hg-tags { display: flex; flex-wrap: wrap; gap: 6px; }
.hg-tag {
  font-family: var(--hg-mono); font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: var(--hg-muted); border: 1px solid var(--hg-chip-line); border-radius: var(--hg-r-sm); padding: 3px 8px;
}

/* ---------- Cards ---------- */
.hg-grid { display: flex; flex-wrap: wrap; gap: 20px; }
.hg-card {
  flex: 1 1 300px; min-width: 0;
  background: var(--hg-panel); border: 1px solid var(--hg-line);
  border-radius: var(--hg-r-lg); padding: 28px;
  display: flex; flex-direction: column; gap: 14px;
}
.hg-card--wide { flex: 2 1 520px; gap: 20px; }
.hg-card__head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; }
.hg-card__foot { margin-top: auto; }
.hg-card--dashed {
  flex-direction: row; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px;
  background: transparent; border: 1px dashed var(--hg-line-strong); padding: 22px 28px;
}

/* Thread list (numbered briefing items) */
.hg-threads { margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; }
.hg-thread { display: flex; gap: 20px; padding: 18px 0; border-top: 1px solid var(--hg-line-soft); }
.hg-thread__n { font-family: var(--hg-mono); font-size: 13px; color: var(--hg-accent); padding-top: 3px; }
.hg-thread__body { display: flex; flex-direction: column; gap: 8px; min-width: 0; }

/* Ticker rows */
.hg-ticker { display: flex; align-items: center; gap: 14px; padding: 10px 0; border-top: 1px solid var(--hg-line-soft); }
.hg-ticker__id { display: flex; flex-direction: column; gap: 2px; width: 72px; }
.hg-ticker__sym { font-family: var(--hg-mono); font-size: 14px; font-weight: 500; }
.hg-ticker__name { font-size: 12px; color: var(--hg-faint); }
.hg-ticker__spark { flex: 1; height: 28px; color: var(--hg-accent); }
.hg-ticker__spark polyline { fill: none; stroke: currentColor; stroke-width: 1.5; stroke-linejoin: round; stroke-linecap: round; }
.hg-ticker__val { display: flex; flex-direction: column; align-items: flex-end; gap: 2px; font-family: var(--hg-mono); font-size: 14px; }
.hg-ticker__move { font-size: 12px; color: var(--hg-accent); }
.hg-ticker--down .hg-ticker__spark,
.hg-ticker--down .hg-ticker__move { color: var(--hg-warm); }

/* Feed posts */
.hg-post { display: flex; gap: 12px; padding-top: 12px; border-top: 1px solid var(--hg-line-soft); }
.hg-avatar { flex: 0 0 32px; height: 32px; border-radius: 50%; background: var(--hg-field); object-fit: cover; }
.hg-post__body { display: flex; flex-direction: column; gap: 4px; min-width: 0; }
.hg-post__who { font-size: 13px; font-weight: 500; }
.hg-post__text { font-size: 14px; line-height: 1.5; color: var(--hg-text-3); }

/* ==========================================================================
   Reading companion
   ========================================================================== */
.hg-reader { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; }
.hg-topbar {
  display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 16px;
  padding: 20px 40px; border-bottom: 1px solid var(--hg-line);
}
.hg-topbar__left, .hg-topbar__right { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; }
.hg-back {
  display: flex; align-items: center; justify-content: center;
  width: var(--hg-tap); height: var(--hg-tap);
  border: 1px solid var(--hg-field); border-radius: var(--hg-r);
}
.hg-reader__body { flex: 1; display: flex; flex-wrap: wrap; }

/* Article column */
.hg-article { flex: 999 1 560px; min-width: 0; padding: 56px 40px 80px; }
.hg-article__inner { max-width: 680px; margin: 0 auto; display: flex; flex-direction: column; gap: 24px; }
.hg-article h1 { font-family: var(--hg-serif); font-size: 40px; line-height: 1.15; font-weight: 400; letter-spacing: -0.015em; }
.hg-article .hg-article__byline { font-family: var(--hg-sans); font-size: 14px; line-height: 1.5; color: var(--hg-muted); }
.hg-rule { height: 1px; background: var(--hg-line); border: 0; margin: 0; }
.hg-article p { font-family: var(--hg-serif); font-size: 19px; line-height: 1.75; color: var(--hg-text-read); }

/* Highlights */
.hg-mark { background: transparent; color: var(--hg-text); padding: 0 1px; box-shadow: inset 0 -0.45em 0 var(--hg-accent-wash); }
.hg-mark--conflict { box-shadow: inset 0 -0.45em 0 var(--hg-warm-wash); }

/* Companion panel */
.hg-companion {
  flex: 1 1 380px; min-width: 0; padding: 40px 32px;
  background: var(--hg-aside); border-left: 1px solid var(--hg-line);
  display: flex; flex-direction: column; gap: 28px;
}
.hg-tabs { display: flex; gap: 4px; padding: 4px; background: var(--hg-ground); border: 1px solid var(--hg-line); border-radius: var(--hg-r-md); }
.hg-tab {
  flex: 1; min-height: var(--hg-tap); border: 0; border-radius: 8px;
  padding: 0 12px; background: transparent; color: var(--hg-muted); font-size: 14px; font-weight: 400; cursor: pointer;
}
.hg-tab:hover { color: var(--hg-text); }
.hg-tab[aria-selected="true"], .hg-tab[aria-pressed="true"] { background: var(--hg-active); color: var(--hg-text); font-weight: 500; }

.hg-section { display: flex; flex-direction: column; gap: 14px; }

.hg-claim {
  display: flex; gap: 14px; padding: 16px;
  background: var(--hg-panel); border: 1px solid var(--hg-line); border-radius: var(--hg-r-md);
}
.hg-claim .hg-dot { width: 8px; height: 8px; margin-top: 7px; }
.hg-claim__text { font-size: 15px; line-height: 1.5; }
.hg-claim__note { font-size: 13px; color: var(--hg-muted); }

.hg-connection {
  display: flex; flex-direction: column; gap: 4px; padding: 16px;
  background: var(--hg-panel); border: 1px solid var(--hg-line); border-radius: var(--hg-r-md);
  font-size: 15px; line-height: 1.45;
}
.hg-connection:hover { border-color: var(--hg-line-strong); }
.hg-connection__src { font-family: var(--hg-mono); font-size: 11px; letter-spacing: 0.08em; text-transform: uppercase; color: var(--hg-accent); }

.hg-question {
  padding-left: 16px; border-left: 2px solid var(--hg-line-strong);
  font-family: var(--hg-serif); font-style: italic; font-size: 17px; line-height: 1.55; color: var(--hg-text-read);
}

.hg-field { display: flex; flex-direction: column; gap: 8px; }
.hg-field label { font-size: 13px; color: var(--hg-muted); }
.hg-field__row { display: flex; gap: 8px; }
/* 16px: iOS Safari zooms into any smaller field on focus. */
.hg-input {
  flex: 1; min-width: 0; height: var(--hg-tap); padding: 0 14px;
  background: var(--hg-ground); border: 1px solid var(--hg-field); border-radius: var(--hg-r);
  color: var(--hg-text); font-size: 16px;
}
.hg-input:focus { border-color: var(--hg-accent); }
.hg-input:focus-visible { outline: none; box-shadow: 0 0 0 1px var(--hg-accent); }
.hg-companion .hg-field { margin-top: auto; }

/* ---------- Touch: every control at least the tap size ---------- */
@media (pointer: coarse) {
  .hg-chip { min-height: var(--hg-tap); }
}

/* ---------- Small screens ---------- */
@media (max-width: 720px) {
  /* The sidebar becomes a strip of brand and nav above the page; sources
     and the note box would push the content a screen down. */
  .hg-sidebar {
    flex-basis: 100%; min-width: 0; flex-direction: row; align-items: center; gap: 8px;
    padding: 8px 16px; border-right: 0; border-bottom: 1px solid var(--hg-line);
  }
  .hg-brand { padding: 0 4px; font-size: 17px; }
  /* flex-basis 0: the strip scrolls instead of widening the page. */
  .hg-nav { flex-direction: row; flex: 1 1 0; min-width: 0; overflow-x: auto; scrollbar-width: none; }
  .hg-nav a { flex: none; padding: 0 8px; font-size: 14px; }
  .hg-nav a.hg-nav__sub { min-height: var(--hg-tap); padding: 0 8px; margin-top: 0; }
  /* More pages than fit (Über Huginn, Admin): the edge fades where the
     strip goes on, so it reads as scrollable (nav.js sets the classes). */
  .hg-nav.hg-nav--more-right { mask-image: linear-gradient(to right, #000 calc(100% - 36px), transparent); }
  .hg-nav.hg-nav--more-left { mask-image: linear-gradient(to left, #000 calc(100% - 36px), transparent); }
  .hg-nav.hg-nav--more-left.hg-nav--more-right { mask-image: linear-gradient(to right, transparent, #000 36px, #000 calc(100% - 36px), transparent); }
  .hg-nav a.hg-nav__sub svg { display: block; }
  .hg-sources, .hg-note-box { display: none; }
  /* The support link: the cup alone, a tap target at the strip's end. */
  .hg-support { flex: none; margin: 0; padding: 0; min-height: var(--hg-tap); min-width: var(--hg-tap); justify-content: center; }
  .hg-support__label { position: absolute; width: 1px; height: 1px; margin: -1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
  .hg-main { padding: 28px 16px 48px; }
  .hg-display { font-size: 34px; }
  .hg-card { padding: 22px; }
  .hg-topbar { padding: 16px; }
  .hg-article { padding: 32px 16px 56px; }
  .hg-article h1 { font-size: 30px; }
  .hg-article p { font-size: 18px; }
  .hg-companion { border-left: 0; border-top: 1px solid var(--hg-line); padding: 28px 16px; }
}

@media (prefers-reduced-motion: no-preference) {
  .hg-btn, .hg-chip, .hg-nav a, .hg-tab, .hg-connection, .hg-ask { transition: background-color .15s, border-color .15s, color .15s; }
}
