/* ==========================================================================
   Base — reset, typography, application shell (top bar + tab rail)
   ========================================================================== */

*, *::before, *::after { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }
html.is-scroll-locked, html.is-scroll-locked body { overflow: hidden; }

body {
  margin: 0;
  min-height: 100vh;
  background: var(--plane);
  color: var(--ink);
  font-family: var(--font-ui);
  font-size: var(--t-base);
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 600;
  letter-spacing: -0.011em;
  text-wrap: balance;
  margin: 0;
}
h1 { font-size: var(--t-h1); }
h2 { font-size: var(--t-h2); }
h3 { font-size: var(--t-h3); }

p { margin: 0; }
ul, ol { margin: 0; padding: 0; list-style: none; }

a { color: var(--accent); text-decoration-color: color-mix(in srgb, var(--accent) 40%, transparent); }
a:hover { color: var(--accent-hover); }

button, input, select, textarea { font: inherit; color: inherit; }

svg { display: block; }

:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
  border-radius: var(--r-sm);
}

::selection { background: var(--accent-soft); color: var(--ink); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.001ms !important;
    scroll-behavior: auto !important;
  }
}

/* -- shared type utilities ------------------------------------------------ */

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

.skip-link {
  position: absolute; left: 8px; top: -60px; z-index: 100;
  background: var(--surface-raised); color: var(--ink);
  padding: 10px 14px; border: 1px solid var(--rule-strong); border-radius: var(--r-md);
  transition: top .15s ease;
}
.skip-link:focus { top: 8px; }

.label {
  font-family: var(--font-mono);
  font-size: var(--t-micro);
  font-weight: 500;
  letter-spacing: 0.09em;
  text-transform: uppercase;
  color: var(--ink-muted);
}

.num { font-variant-numeric: tabular-nums; }
.mono { font-family: var(--font-mono); font-variant-numeric: tabular-nums; }

/* -- top bar -------------------------------------------------------------- */

.topbar {
  position: sticky; top: 0; z-index: 40;
  background: var(--surface);
  border-bottom: 1px solid var(--rule);
}

.topbar__inner {
  height: var(--topbar-h);
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: 0 var(--gutter);
  display: flex; align-items: center; gap: 16px;
}

.brand {
  display: flex; align-items: center; gap: 10px;
  color: var(--ink); text-decoration: none; flex: none;
}
.brand__mark { width: 22px; height: 22px; }
.brand__mark .slot { fill: var(--rule-strong); }
.brand__mark .slot--on { fill: var(--accent); }
.brand__text { display: flex; flex-direction: column; line-height: 1.05; }
.brand__name {
  font-family: var(--font-display); font-weight: 700;
  font-size: var(--t-lead); letter-spacing: -0.02em;
}
.brand__sub {
  font-family: var(--font-mono); font-size: 0.625rem;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--ink-muted);
}

.topbar__search {
  position: relative; flex: 1 1 auto; max-width: 420px;
  display: flex; align-items: center;
}
.topbar__search-icon {
  position: absolute; left: 10px; width: 15px; height: 15px;
  color: var(--ink-muted); pointer-events: none;
}
.topbar__search input {
  width: 100%; height: 34px;
  padding: 0 34px 0 31px;
  background: var(--plane);
  border: 1px solid var(--rule);
  border-radius: var(--r-md);
  font-size: var(--t-body);
}
.topbar__search input::placeholder { color: var(--ink-muted); }
.topbar__search input:focus { border-color: var(--accent); background: var(--surface); }
.topbar__search input::-webkit-search-cancel-button { -webkit-appearance: none; }
.topbar__kbd {
  position: absolute; right: 8px;
  font-family: var(--font-mono); font-size: 0.625rem; color: var(--ink-muted);
  border: 1px solid var(--rule); border-radius: var(--r-sm);
  padding: 1px 5px; pointer-events: none; background: var(--surface);
}
.topbar__search input:focus ~ .topbar__kbd { opacity: 0; }

.topbar__actions { margin-left: auto; display: flex; align-items: center; gap: 8px; }

/* theme icon swap */
.icon-sun, .icon-moon { width: 15px; height: 15px; }
.icon-moon { display: none; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) .icon-sun { display: none; }
  :root:not([data-theme="light"]) .icon-moon { display: block; }
}
:root[data-theme="dark"] .icon-sun { display: none; }
:root[data-theme="dark"] .icon-moon { display: block; }
:root[data-theme="light"] .icon-sun { display: block; }
:root[data-theme="light"] .icon-moon { display: none; }

/* -- tab rail ------------------------------------------------------------- */

.tabrail { background: var(--surface); border-bottom: 1px solid var(--rule); }
.tabrail__inner {
  max-width: var(--shell-max); margin: 0 auto;
  padding: 0 var(--gutter);
  height: var(--tabrail-h);
  display: flex; align-items: stretch; gap: 2px;
}

.tab {
  position: relative;
  display: inline-flex; align-items: center;
  padding: 0 14px;
  font-family: var(--font-display); font-weight: 600;
  font-size: var(--t-body); letter-spacing: 0.005em;
  color: var(--ink-secondary); text-decoration: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
}
.tab:hover { color: var(--ink); background: var(--surface-hover); }
.tab.is-active { color: var(--ink); border-bottom-color: var(--accent); }

.tabrail__meta {
  margin-left: auto; display: flex; align-items: center; gap: 14px;
  font-family: var(--font-mono); font-size: var(--t-micro);
  letter-spacing: 0.06em; text-transform: uppercase; color: var(--ink-muted);
}
.tabrail__meta b {
  font-weight: 600; color: var(--ink-secondary);
  font-variant-numeric: tabular-nums;
}

/* -- view shell ----------------------------------------------------------- */

.view {
  max-width: var(--shell-max);
  margin: 0 auto;
  padding: var(--gutter) var(--gutter) 56px;
}
.view:focus { outline: none; }
.view--bleed { max-width: none; padding-left: 0; padding-right: 0; }

.viewhead {
  display: flex; align-items: flex-end; justify-content: space-between;
  gap: 16px; flex-wrap: wrap;
  margin-bottom: 14px;
}
.viewhead__title { display: flex; flex-direction: column; gap: 3px; }
.viewhead__title p { color: var(--ink-secondary); font-size: var(--t-body); }
.viewhead__actions { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

@media (max-width: 860px) {
  :root { --gutter: 14px; }
  .brand__text { display: none; }
  .topbar__kbd { display: none; }
}
