/* lovgren.dev shell: the header, mobile tab bar, page transitions, terminal and theme menu
   shared by every page. Pages can re-skin it through the --shell-* tokens.
   Colour pairs are checked against WCAG AA (text 4.5:1). */

@font-face {
  font-family: 'Manrope';
  src: url('/assets/fonts/manrope-latin-wght.woff2') format('woff2');
  font-weight: 200 800;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: 'JetBrains Mono';
  src: url('/assets/fonts/jetbrains-mono-latin-wght.woff2') format('woff2');
  font-weight: 400 800;
  font-style: normal;
  font-display: swap;
}

:root {
  --shell-font: 'Manrope', ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  --shell-mono: 'JetBrains Mono', ui-monospace, 'Cascadia Code', 'SF Mono', Menlo, Consolas, monospace;
  /* Fluid type scale (1.2 on phones → 1.25 on desktops), shared by every page. */
  --step--1: clamp(0.83rem, 0.81rem + 0.1vw, 0.89rem);
  --step-0: clamp(1rem, 0.97rem + 0.15vw, 1.0625rem);
  --step-1: clamp(1.2rem, 1.14rem + 0.3vw, 1.33rem);
  --step-2: clamp(1.44rem, 1.33rem + 0.55vw, 1.66rem);
  --step-3: clamp(1.73rem, 1.54rem + 0.95vw, 2.07rem);
  --step-4: clamp(2.07rem, 1.76rem + 1.55vw, 2.59rem);
  --step-5: clamp(2.49rem, 1.98rem + 2.55vw, 4.4rem);
  --shell-max: 1480px;
  --shell-gutter: clamp(16px, 3.5vw, 40px);
  --shell-height: 64px;
  --shell-tabbar: 0px;
  --shell-bg: #f6f7fa;
  --shell-surface: #ffffff;
  --shell-line: #e1e3ea;
  --shell-line-strong: #c9ccd8;
  --shell-text: #11131a;
  --shell-muted: #4b5163;
  --shell-accent: #4f46e5;
  --shell-accent-ink: #ffffff;
  --shell-accent-soft: #eceeff;
  --shell-accent-text: #4338ca;
  --shell-shadow: 0 18px 50px -18px rgb(22 26 40 / 35%);
  --ease-out: cubic-bezier(.2, .7, .2, 1);
  /* The terminal is always dark. */
  --term-bg: #0d0f17;
  --term-surface: #151827;
  --term-line: #262a3f;
  --term-text: #e6e8f0;
  --term-dim: #9aa1b5;
  --term-accent: #a5a8ff;
  --term-ok: #7dd3e8;
  --term-fail: #ff8e85;
  --term-selected: #262a45;
}

:root[data-scheme="dark"] {
  --shell-bg: #0b0d12;
  --shell-surface: #12151c;
  --shell-line: #222733;
  --shell-line-strong: #343a4a;
  --shell-text: #eef0f6;
  --shell-muted: #aab1c2;
  --shell-accent: #5458e0;
  --shell-accent-ink: #ffffff;
  --shell-accent-soft: #1d1f3d;
  --shell-accent-text: #a5a8ff;
  --shell-shadow: 0 24px 60px -20px rgb(0 0 0 / 70%);
}

/* No JavaScript: follow the device. */
@media (prefers-color-scheme: dark) {
  :root:not([data-scheme]) {
    --shell-bg: #0b0d12;
    --shell-surface: #12151c;
    --shell-line: #222733;
    --shell-line-strong: #343a4a;
    --shell-text: #eef0f6;
    --shell-muted: #aab1c2;
    --shell-accent: #5458e0;
    --shell-accent-soft: #1d1f3d;
    --shell-accent-text: #a5a8ff;
  }
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

.skip-link {
  position: absolute;
  top: -100px;
  left: 16px;
  z-index: 100;
  padding: 10px 16px;
  border-radius: 10px;
  background: var(--shell-accent);
  color: var(--shell-accent-ink);
  font: 700 15px var(--shell-font);
  text-decoration: none;
}
.skip-link:focus { top: 12px; }

/* ---------- Typography defaults ---------- */

html { font-kerning: normal; font-optical-sizing: auto; font-synthesis: none; text-rendering: optimizeLegibility; }
/* Headings wrap into even lines; paragraphs avoid a lonely last word. */
:where(h1, h2, h3, h4, figcaption) { text-wrap: balance; }
/* Short titles in narrow cards read better unbalanced ("Co-Op" stays on one line). */
:where(.np-title, .card-title) { text-wrap: wrap; }
:where(p, li, dd, td, blockquote, summary) { text-wrap: pretty; }
:where(table, time, kbd, .metric-value, .view-count, .score-ring) { font-variant-numeric: tabular-nums; }
:where(abbr[title]) { text-decoration: underline dotted; text-underline-offset: 0.2em; }

/* ---------- Header ---------- */

.site-bar {
  position: sticky;
  top: 0;
  z-index: 40;
  border-bottom: 1px solid color-mix(in srgb, var(--shell-line) 75%, transparent);
  background: color-mix(in srgb, var(--shell-bg) 82%, transparent);
  -webkit-backdrop-filter: saturate(1.4) blur(14px);
  backdrop-filter: saturate(1.4) blur(14px);
  color: var(--shell-text);
  font-family: var(--shell-font);
  view-transition-name: site-bar;
}
.site-bar-inner {
  display: flex;
  align-items: center;
  gap: 12px;
  max-width: var(--shell-max);
  min-height: var(--shell-height);
  margin: 0 auto;
  padding: 0 var(--shell-gutter);
}

.site-logo {
  display: inline-flex;
  flex: none;
  align-items: center;
  gap: 10px;
  border-radius: 12px;
  color: var(--shell-text);
  font-size: 16px;
  font-weight: 800;
  letter-spacing: -0.01em;
  text-decoration: none;
}
.site-logo:hover .site-logo-text { color: var(--shell-accent-text); }
.site-logo .monogram {
  display: grid;
  width: 40px;
  height: 40px;
  place-items: center;
  border-radius: 12px;
  background: var(--shell-accent);
  color: var(--shell-accent-ink);
  font-size: 15px;
  font-weight: 800;
  letter-spacing: -0.03em;
  box-shadow: 0 8px 20px -8px var(--shell-accent);
}

.site-nav { margin-left: 8px; }
.site-nav ul { display: flex; gap: 4px; margin: 0; padding: 0; list-style: none; }
.site-nav a {
  position: relative;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 999px;
  color: var(--shell-muted);
  font-size: 15px;
  font-weight: 700;
  text-decoration: none;
  transition: background-color .15s var(--ease-out), color .15s var(--ease-out);
}
.site-nav a:hover { background: var(--shell-surface); color: var(--shell-text); }
.site-nav a[aria-current="page"] { background: var(--shell-accent-soft); color: var(--shell-accent-text); view-transition-name: nav-current; }
.site-nav .nav-icon { display: none; }

.site-actions { display: flex; align-items: center; gap: 6px; margin-left: auto; }

.shell-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-width: 40px;
  min-height: 40px;
  padding: 0 12px;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--shell-muted);
  font: 700 14px var(--shell-font);
  white-space: nowrap;
  cursor: pointer;
  transition: background-color .15s var(--ease-out), color .15s var(--ease-out), border-color .15s var(--ease-out);
}
.shell-button:hover,
.shell-button[aria-expanded="true"] { background: var(--shell-surface); color: var(--shell-text); }
.shell-button.is-outlined { border-color: var(--shell-line-strong); background: var(--shell-surface); color: var(--shell-text); }
.shell-button.is-outlined:hover { border-color: var(--shell-accent); }
.shell-button svg { width: 18px; height: 18px; flex: none; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.shell-button .prompt { color: var(--shell-accent-text); font: 800 14px var(--shell-mono); }
.shell-button kbd,
.site-bar kbd {
  padding: 1px 6px;
  border: 1px solid var(--shell-line-strong);
  border-bottom-width: 2px;
  border-radius: 6px;
  background: var(--shell-bg);
  color: var(--shell-text);
  font: 600 11px/1.5 var(--shell-mono);
}

.site-bar :focus-visible,
.theme-menu :focus-visible { outline: 2px solid var(--shell-accent); outline-offset: 2px; }

/* ---------- Theme menu (popover) ---------- */

.theme-menu {
  position: fixed;
  inset: auto;
  min-width: 190px;
  margin: 0;
  padding: 6px;
  border: 1px solid var(--shell-line);
  border-radius: 14px;
  background: var(--shell-surface);
  color: var(--shell-text);
  box-shadow: var(--shell-shadow);
  font-family: var(--shell-font);
}
.theme-menu:popover-open { animation: shell-pop .14s var(--ease-out); }
.theme-menu p { margin: 0; padding: 8px 10px 6px; color: var(--shell-muted); font-size: 11.5px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.theme-option {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  min-height: 40px;
  padding: 0 10px;
  border: 0;
  border-radius: 9px;
  background: transparent;
  color: var(--shell-text);
  font: 650 14px var(--shell-font);
  text-align: left;
  cursor: pointer;
}
.theme-option:hover { background: color-mix(in srgb, var(--shell-line) 60%, transparent); }
.theme-option svg { width: 17px; height: 17px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
.theme-option[aria-checked="true"] { background: var(--shell-accent-soft); color: var(--shell-accent-text); }
.theme-option[aria-checked="true"]::after { margin-left: auto; content: '✓'; font-weight: 800; }
.theme-menu hr { margin: 6px 4px; border: 0; border-top: 1px solid var(--shell-line); }
/* A switch, not a choice of theme: only the tick shows it's on. */
.weather-option[aria-checked="true"] { background: transparent; color: var(--shell-text); }
.weather-option[aria-checked="true"]:hover { background: color-mix(in srgb, var(--shell-line) 60%, transparent); }

/* ---------- Weather (assets/weather.js) ----------
   Stockholm's weather behind the page: a tint from data-weather-* on <html>, and a canvas with the
   rain, snow, clouds, fog or stars. Purely decorative and faded out towards the bottom of the screen. */

:root { --weather-tint: transparent; }
:root[data-weather-kind="clear"][data-weather-phase="day"] { --weather-tint: rgb(245 181 68 / 15%); }
:root[data-weather-phase="twilight"] { --weather-tint: rgb(255 128 96 / 14%); }
:root[data-weather-kind="clear"][data-weather-phase="night"] { --weather-tint: rgb(84 88 224 / 14%); }
:root[data-weather-kind="clouds"] { --weather-tint: rgb(140 150 172 / 14%); }
:root[data-weather-kind="fog"] { --weather-tint: rgb(165 170 182 / 20%); }
:root[data-weather-kind="rain"],
:root[data-weather-kind="sleet"] { --weather-tint: rgb(70 125 200 / 15%); }
:root[data-weather-kind="snow"] { --weather-tint: rgb(190 215 255 / 20%); }
:root[data-weather-kind="thunder"] { --weather-tint: rgb(120 88 220 / 18%); }
/* The dark weeks of winter are dimmer; midsummer nights glow. */
:root[data-weather-season="dark"] { --weather-dim: 0.7; }
:root[data-weather-season="bright"][data-weather-phase="twilight"] { --weather-tint: rgb(255 170 120 / 16%); }

.weather-layer {
  position: fixed;
  inset: 0;
  z-index: -1;
  width: 100%;
  height: 100%;
  background: radial-gradient(70rem 32rem at 60% -10%, var(--weather-tint), transparent 70%);
  opacity: var(--weather-dim, 1);
  -webkit-mask-image: linear-gradient(to bottom, #000 0%, #000 35%, transparent 85%);
  mask-image: linear-gradient(to bottom, #000 0%, #000 35%, transparent 85%);
  pointer-events: none;
}

/* ---------- Language menu and suggestion ---------- */

.language-button { gap: 6px; }
.language-button .language-code { font: 700 12.5px/1 var(--shell-mono); letter-spacing: 0.02em; }
.language-menu ul { margin: 0; padding: 0; list-style: none; }
.language-menu a { text-decoration: none; }
.language-menu a[aria-current] { background: var(--shell-accent-soft); color: var(--shell-accent-text); }
.language-menu a[aria-current]::after { margin-left: auto; content: '✓'; font-weight: 800; }

.lang-suggest {
  position: fixed;
  right: 16px;
  bottom: calc(16px + var(--shell-tabbar));
  z-index: 45;
  max-width: min(22rem, calc(100% - 32px));
  padding: 14px 16px;
  border: 1px solid var(--shell-line);
  border-radius: 14px;
  background: var(--shell-surface);
  color: var(--shell-text);
  box-shadow: var(--shell-shadow);
  font: 600 14.5px/1.45 var(--shell-font);
  animation: shell-pop .2s var(--ease-out);
}
.lang-suggest p { margin: 0 0 10px; }
.lang-suggest-actions { display: flex; flex-wrap: wrap; gap: 8px; }
.lang-suggest-go,
.lang-suggest-close {
  display: inline-flex;
  align-items: center;
  min-height: 40px;
  padding: 0 14px;
  border-radius: 10px;
  font: 750 14px var(--shell-font);
}
.lang-suggest-go { background: var(--shell-accent); color: var(--shell-accent-ink); text-decoration: none; }
.lang-suggest-close { border: 1px solid var(--shell-line-strong); background: transparent; color: var(--shell-text); cursor: pointer; }
.lang-suggest :focus-visible { outline: 2px solid var(--shell-accent); outline-offset: 2px; }

/* ---------- Page transitions (cross-document View Transitions) ---------- */

@view-transition {
  navigation: auto;
  types: page;
}
html:active-view-transition-type(page)::view-transition-old(root) { animation: shell-fade-out .16s ease-in both; }
html:active-view-transition-type(page)::view-transition-new(root) { animation: shell-rise-in .3s var(--ease-out) both; }
::view-transition-group(site-bar) { animation-duration: .2s; }
::view-transition-group(nav-current) { animation-duration: .32s; animation-timing-function: var(--ease-out); }
::view-transition-old(nav-current),
::view-transition-new(nav-current) { height: 100%; }

@keyframes shell-fade-out { to { opacity: 0; } }
@keyframes shell-rise-in { from { opacity: 0; transform: translateY(10px); } }
@keyframes shell-pop { from { opacity: 0; transform: translateY(-4px); } }

/* ---------- Scroll-driven motion (CSS only, compositor-run) ----------
   Content rises into place as it scrolls into view. Only transforms are animated, never opacity,
   so text keeps full contrast at every moment. Off for reduced motion and in older browsers. */

@supports (animation-timeline: view()) {
  @media (prefers-reduced-motion: no-preference) {
    :where(.home .section-head, .now-playing, .link-list > li, .contact-list, .ops-section > .section-head, .metric, .chart, .replay, .arch, .component, .incidents, .changelog-day) {
      animation: shell-reveal linear both;
      animation-timeline: view();
      animation-range: entry 0% entry 80%;
    }
  }
  /* The header lifts off the page once you scroll, and article pages show reading progress. */
  .site-bar { animation: shell-bar-lift linear both; animation-timeline: scroll(root); animation-range: 0 140px; }
  body:has(.article) .site-bar::after {
    position: absolute;
    right: 0;
    bottom: -1px;
    left: 0;
    height: 2px;
    background: var(--shell-accent);
    content: '';
    transform-origin: 0 50%;
    /* Hidden by default: a page too short to scroll has an inactive timeline and shows no bar. */
    scale: 0 1;
    animation: shell-progress linear both;
    animation-timeline: scroll(root);
  }
}
@keyframes shell-reveal { from { translate: 0 2.25rem; scale: 0.97; } }
@keyframes shell-bar-lift { to { border-bottom-color: var(--shell-line-strong); box-shadow: 0 12px 32px -22px rgb(10 12 24 / 55%); } }
@keyframes shell-progress { from { scale: 0 1; } to { scale: 1 1; } }

/* ---------- Terminal ---------- */

.terminal {
  width: min(44rem, calc(100% - 2rem));
  max-width: none;
  max-height: min(34rem, 85vh);
  padding: 0;
  overflow: hidden;
  border: 1px solid var(--term-line);
  border-radius: 16px;
  background: var(--term-bg);
  color: var(--term-text);
  box-shadow: 0 40px 100px -30px rgb(0 0 0 / 75%);
  font-family: var(--shell-font);
}
.terminal[open] { display: flex; flex-direction: column; animation: shell-pop .18s var(--ease-out); }
.terminal::backdrop { background: rgb(5 6 12 / 55%); -webkit-backdrop-filter: blur(3px); backdrop-filter: blur(3px); }
.term-bar {
  display: flex;
  flex: none;
  align-items: center;
  gap: 12px;
  padding: 10px 12px 10px 16px;
  border-bottom: 1px solid var(--term-line);
  background: var(--term-surface);
}
.term-dots { display: inline-flex; gap: 6px; }
.term-dots i { width: 11px; height: 11px; border-radius: 50%; background: #3a3f57; }
.term-bar h2 { flex: 1; margin: 0; color: var(--term-dim); font: 600 13.5px var(--shell-mono); text-align: center; }
.term-close {
  width: 32px;
  height: 32px;
  border: 0;
  border-radius: 8px;
  background: transparent;
  color: var(--term-dim);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
}
.term-close:hover { background: rgb(255 255 255 / 8%); color: var(--term-text); }
.terminal :focus-visible { outline: 2px solid var(--term-accent); outline-offset: 2px; }
.term-body { display: flex; min-height: 0; flex: 1; flex-direction: column; padding: 14px 18px 10px; font: 500 14.5px/1.6 var(--shell-mono); }
.term-log { flex: 1; min-height: 6rem; overflow-y: auto; }
.term-line { margin: 0; white-space: pre-wrap; overflow-wrap: anywhere; }
.term-line + .term-line { margin-top: 2px; }
.term-line.cmd { margin-top: 11px; }
.term-line.cmd::before { color: var(--term-accent); content: '~ $ '; }
.term-line.dim { color: var(--term-dim); }
.term-line.ok { color: var(--term-ok); }
.term-line.err { color: var(--term-fail); }
.term-line a { color: var(--term-accent); }
.term-line .key { display: inline-block; min-width: 12ch; padding-right: 1ch; color: var(--term-accent); }
.term-input-row { display: flex; flex: none; align-items: center; gap: 10px; margin-top: 10px; }
.term-input-row:focus-within { box-shadow: 0 2px 0 0 var(--term-accent); }
.term-prompt { color: var(--term-accent); font-weight: 700; white-space: nowrap; }
.term-input {
  flex: 1;
  min-width: 0;
  padding: 6px 0;
  border: 0;
  background: transparent;
  color: var(--term-text);
  font: inherit;
  caret-color: var(--term-accent);
}
.term-input:focus { outline: none; }
.term-suggestions {
  flex: none;
  max-height: 13rem;
  overflow-y: auto;
  margin: 8px 0 0;
  padding: 5px;
  border: 1px solid var(--term-line);
  border-radius: 10px;
  background: var(--term-surface);
  list-style: none;
}
.term-suggestions li {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  padding: 6px 10px;
  border-radius: 7px;
  color: var(--term-text);
  cursor: pointer;
}
.term-suggestions li span { overflow: hidden; color: var(--term-dim); font-size: .85em; text-align: right; text-overflow: ellipsis; white-space: nowrap; }
.term-suggestions li .term-group { margin-right: auto; padding: 0 6px; border-radius: 5px; background: rgb(165 168 255 / 14%); color: var(--term-accent); font-size: .75em; line-height: 1.7; }
.term-suggestions li[aria-selected="true"] { background: var(--term-selected); }
.term-line.cmd-plain::before { color: var(--term-accent); content: '> '; }
.term-game {
  margin: 10px 0 4px;
  color: var(--term-ok);
  font: 600 14px/1.15 var(--shell-mono);
  letter-spacing: 0.04em;
  white-space: pre;
  overflow-x: auto;
}
.term-pad { display: none; gap: 6px; margin: 8px 0; grid-template-columns: repeat(3, 44px) 1fr; grid-template-areas: ". up . quit" "left down right quit"; }
.term-pad button { min-height: 44px; border: 1px solid var(--term-line); border-radius: 10px; background: var(--term-surface); color: var(--term-text); font: 700 16px var(--shell-mono); cursor: pointer; }
.term-pad .pad-up { grid-area: up; }
.term-pad .pad-left { grid-area: left; }
.term-pad .pad-down { grid-area: down; }
.term-pad .pad-right { grid-area: right; }
.term-pad .pad-quit { grid-area: quit; justify-self: end; padding: 0 16px; font-size: 13px; }
@media (pointer: coarse) { .term-pad { display: grid; } }
.term-hint { flex: none; margin: 0; padding: 9px 18px 11px; border-top: 1px solid var(--term-line); color: var(--term-dim); font: 500 12.5px var(--shell-mono); }
.term-hint kbd { padding: 1px 5px; border: 1px solid var(--term-line); border-radius: 5px; background: var(--term-surface); color: var(--term-text); font: 600 11px var(--shell-mono); }

/* ---------- Responsive: bottom tab bar on phones ---------- */

@media (max-width: 1024px) {
  .shell-button .label-optional,
  .shell-button kbd { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
  .shell-button { padding: 0 10px; }
}

@media (max-width: 640px) {
  :root { --shell-height: 58px; --shell-tabbar: calc(64px + env(safe-area-inset-bottom, 0px)); }
  body { padding-bottom: var(--shell-tabbar); }
  /* backdrop-filter and view-transition-name would make the header the containing block
     of the fixed tab bar inside it, so the header goes solid on phones. */
  .site-bar { -webkit-backdrop-filter: none; backdrop-filter: none; background: var(--shell-bg); view-transition-name: none; }
  .site-logo-text { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); clip-path: inset(50%); white-space: nowrap; }
  .site-logo .monogram { width: 38px; height: 38px; border-radius: 11px; }
  .site-nav {
    position: fixed;
    right: 0;
    bottom: 0;
    left: 0;
    z-index: 40;
    margin: 0;
    padding: 6px 10px calc(6px + env(safe-area-inset-bottom, 0px));
    border-top: 1px solid var(--shell-line);
    background: color-mix(in srgb, var(--shell-bg) 88%, transparent);
    -webkit-backdrop-filter: saturate(1.4) blur(14px);
    backdrop-filter: saturate(1.4) blur(14px);
    view-transition-name: tab-bar;
  }
  .site-nav ul { justify-content: space-around; gap: 4px; }
  .site-nav li { flex: 1; }
  .site-nav a { flex-direction: column; justify-content: center; gap: 2px; width: 100%; min-height: 52px; padding: 4px 6px; border-radius: 14px; font-size: 12px; }
  .site-nav .nav-icon { display: block; width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .terminal { width: 100%; max-height: 82dvh; margin: auto 0 0; border-radius: 16px 16px 0 0; }
  .term-hint { display: none; }
}

@media (prefers-reduced-motion: reduce) {
  @view-transition { navigation: none; }
  ::view-transition-group(*),
  ::view-transition-old(*),
  ::view-transition-new(*) { animation: none !important; }
  .theme-menu:popover-open,
  .lang-suggest,
  .terminal[open] { animation: none; }
}

@media print {
  .site-bar,
  .site-nav,
  .weather-layer { display: none !important; }
  body { padding-bottom: 0; }
}
