/* ==========================================================================
   kaasolai — main stylesheet
   Dark is the default theme; light is applied via html[data-theme="light"].
   ========================================================================== */

/* Fonts (self-hosted, no CDN) */
@font-face {
  font-family: "Playfair Display";
  src: url("/assets/fonts/playfair-display-latin.woff2") format("woff2");
  font-weight: 400 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Playfair Display";
  src: url("/assets/fonts/playfair-display-latin-italic.woff2") format("woff2");
  font-weight: 400 700;
  font-style: italic;
  font-display: swap;
}

@font-face {
  font-family: "Archivo Black";
  src: url("/assets/fonts/archivo-black-latin.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

/* ==========================================================================
   Design tokens
   ========================================================================== */
:root {
  --font-serif: "Playfair Display", Georgia, "Times New Roman", serif;
  --font-display: "Archivo Black", "Arial Black", sans-serif;
  --font-mono: "SFMono-Regular", Consolas, "Liberation Mono", monospace;
}

html[data-theme="dark"] {
  --bg: #000000;
  --text: #F3EEE3;
  --accent: #00F5FF;
  --muted: #8E877A;
  --panel: #1A1917;
  --border: #2A2824;
  --hover: #20201E;
  --focus-ring: #00F5FF;
  --danger: #FF5B5B;
  color-scheme: dark;
}

html[data-theme="light"] {
  --bg: #FAF8F3;
  --text: #111111;
  --accent: #007C85;
  --muted: #5E584D;
  --panel: #EFEBE1;
  --border: #D9D3C5;
  --hover: #E9E4D8;
  --focus-ring: #007C85;
  --danger: #C62828;
  color-scheme: light;
}

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

html {
  scroll-behavior: smooth;
}

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-serif);
  font-size: 1.0625rem; /* 17px */
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

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

img {
  max-width: 100%;
  height: auto;
  display: block;
}

a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 3px;
  text-decoration-thickness: 1px;
}

a:hover {
  text-decoration-thickness: 2px;
}

:focus-visible {
  outline: 2px solid var(--focus-ring);
  outline-offset: 2px;
}

/* ==========================================================================
   Skip link
   ========================================================================== */
.skip-link {
  position: absolute;
  inset-inline-start: -9999px;
  top: 0;
  background: var(--accent);
  color: var(--bg);
  padding: 0.6em 1em;
  z-index: 200;
  font-family: var(--font-display);
  font-size: 0.85rem;
  text-decoration: none;
}

.skip-link:focus {
  inset-inline-start: 0;
}

/* ==========================================================================
   Top bar (mobile only)
   ========================================================================== */
.topbar {
  display: none;
}

/* ==========================================================================
   Shell / sidebar / main
   ========================================================================== */
.shell {
  display: flex;
}

.sidebar {
  position: fixed;
  inset-block: 0;
  inset-inline-start: 0;
  width: 260px;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  border-inline-end: 1px solid var(--border);
  padding: 1.5rem 1.25rem;
  z-index: 40;
  overflow-y: auto;
}

.brand {
  font-family: var(--font-display);
  font-size: 1.6rem;
  color: var(--text);
  text-decoration: none;
  letter-spacing: -0.02em;
  margin-block-end: 2rem;
}

.brand:hover {
  color: var(--accent);
  text-decoration: none;
}

.nav ul {
  list-style: none;
  margin: 0;
  padding: 0;
}

.nav li + li {
  margin-block-start: 0.35rem;
}

.nav a {
  display: block;
  padding: 0.5rem 0.6rem;
  color: var(--text);
  text-decoration: none;
  border-inline-start: 3px solid transparent;
  border-radius: 4px;
  font-size: 1.02rem;
  line-height: 1.35;
}

.nav a:hover {
  background: var(--hover);
  color: var(--text);
  text-decoration: none;
}

.nav a[aria-current="page"] {
  color: var(--accent);
  border-inline-start-color: var(--accent);
  background: var(--hover);
}

.sidebar-footer {
  margin-block-start: auto;
  padding-block-start: 1.5rem;
}

.main {
  flex: 1;
  margin-inline-start: 260px;
  padding: 3rem 2.25rem 4rem;
  min-height: 100vh;
}

.main:focus {
  outline: none;
}

.entry {
  max-width: 68ch;
}

.entry h1,
.entry h2,
.entry h3,
.entry h4 {
  font-family: var(--font-serif);
  font-weight: 700;
  line-height: 1.25;
  color: var(--text);
}

.entry h1 {
  font-size: 2.1rem;
  margin-block: 0 1.75rem;
}

.entry h2 {
  font-size: 1.6rem;
  margin-block: 2.5rem 0.9rem;
  padding-block-end: 0.35rem;
  border-block-end: 1px solid var(--border);
}

.entry h3 {
  font-size: 1.3rem;
  margin-block: 2rem 0.7rem;
}

.entry h4 {
  font-size: 1.1rem;
  margin-block: 1.6rem 0.6rem;
}

.entry h2:first-of-type {
  margin-block-start: 1.5rem;
}

.entry p,
.entry ul,
.entry ol,
.entry table,
.entry blockquote,
.entry details {
  margin-block: 0 1.1rem;
}

.entry ul,
.entry ol {
  padding-inline-start: 1.6rem;
}

.entry li + li {
  margin-block-start: 0.35rem;
}

.entry li > ul,
.entry li > ol {
  margin-block-start: 0.35rem;
  margin-block-end: 0.35rem;
}

.entry code {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

.entry blockquote {
  border-inline-start: 3px solid var(--accent);
  margin-inline: 0;
  padding-inline-start: 1rem;
  color: var(--muted);
}

/* Tables — exact content, horizontally scrollable on small screens */
.entry table {
  width: 100%;
  border-collapse: collapse;
  font-family: var(--font-serif);
  display: block;
  max-width: 100%;
  overflow-x: auto;
}

.entry caption {
  caption-side: top;
  text-align: start;
  color: var(--muted);
  padding-block-end: 0.4rem;
}

.entry th,
.entry td {
  border: 1px solid var(--border);
  padding: 0.45em 0.6em;
  vertical-align: top;
  text-align: start;
  font-weight: 400;
}

.entry th {
  font-weight: 700;
  border-block-end-width: 2px;
}

.entry tbody tr:nth-child(even) {
  background: var(--hover);
}

/* Key numbers use the display face — deliberate contrast against content */
.entry table .num,
.key-number {
  font-family: var(--font-display);
  font-weight: 400;
  color: var(--accent);
  white-space: nowrap;
}

/* Negative values are shown in red (Market landmarks table) */
.neg,
.entry table .num.neg {
  color: var(--danger);
}

.entry details {
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--panel);
  padding: 0.75rem 1rem;
}

.entry summary {
  cursor: pointer;
  font-weight: 700;
}

.entry .updated {
  color: var(--muted);
  font-size: 0.95rem;
  margin-block-start: 3rem;
}

/* Buttons */
.btn {
  display: inline-block;
  font-family: var(--font-display);
  font-size: 0.95rem;
  line-height: 1;
  color: var(--bg);
  background: var(--accent);
  border: 0;
  border-radius: 6px;
  padding: 0.8em 1.4em;
  text-decoration: none;
  cursor: pointer;
}

.btn:hover {
  text-decoration: none;
  filter: brightness(1.08);
}

/* ==========================================================================
   Community list (references page)
   ========================================================================== */
.person {
  display: grid;
  grid-template-columns: 23% 1fr;
  gap: 1.25rem;
  align-items: start;
  margin-block: 1.4rem;
}

.person-photo {
  width: 100%;
  height: auto;
  border-radius: 6px;
}

.person-head {
  font-family: var(--font-display);
  font-size: 1rem;
  line-height: 1.3;
  margin-block: 0 0.4rem;
}

.person-info p {
  margin-block: 0 0.5rem;
}

.person-info p:last-child {
  margin-block-end: 0;
}

@media (max-width: 700px) {
  .person {
    grid-template-columns: 1fr;
  }
}

/* ==========================================================================
   Theme toggle
   ========================================================================== */
.theme-toggle {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 44px;
  height: 44px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  cursor: pointer;
}

.theme-toggle:hover {
  color: var(--accent);
}

.theme-toggle .icon-sun {
  display: none;
}

html[data-theme="light"] .theme-toggle .icon-sun {
  display: block;
}

html[data-theme="light"] .theme-toggle .icon-moon {
  display: none;
}

/* ==========================================================================
   Footer
   ========================================================================== */
.site-footer {
  margin-inline-start: 260px;
  padding: 1rem 2.25rem 2rem;
  color: var(--muted);
  font-size: 0.95rem;
  border-block-start: 1px solid var(--border);
}

.site-footer p {
  margin: 0;
}

/* ==========================================================================
   Scrim (mobile drawer)
   ========================================================================== */
.scrim {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.55);
  z-index: 30;
}

/* ==========================================================================
   Mobile navigation drawer (below 900px)
   ========================================================================== */
@media (max-width: 899px) {
  body {
    font-size: 1rem;
  }

  .topbar {
    position: sticky;
    inset-block-start: 0;
    z-index: 50;
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.6rem 1rem;
    background: var(--bg);
    border-block-end: 1px solid var(--border);
  }

  .menu-toggle {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 44px;
    height: 44px;
    border: 0;
    border-radius: 6px;
    background: transparent;
    color: var(--text);
    cursor: pointer;
  }

  .topbar-brand {
    flex: 1;
    font-family: var(--font-display);
    font-size: 1.2rem;
    color: var(--text);
    text-decoration: none;
  }

  .topbar-brand:hover {
    text-decoration: none;
    color: var(--accent);
  }

  .sidebar {
    transform: translateX(-100%);
    transition: transform 0.22s ease;
    padding-block-start: 1rem;
    width: min(300px, 84vw);
    box-shadow: 6px 0 24px rgba(0, 0, 0, 0.35);
  }

  .sidebar.open {
    transform: translateX(0);
  }

  .main {
    margin-inline-start: 0;
    padding: 1.75rem 1.25rem 3rem;
  }

  .site-footer {
    margin-inline-start: 0;
    padding: 1.25rem 1.25rem 2rem;
  }

  .entry h1 {
    font-size: 1.7rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  .sidebar {
    transition: none;
  }
}