/* Mory — base stylesheet.
   Wave 1 lands tokens + global a11y; Wave 2 lands typography (Inter VF +
   JetBrains Mono, type scale, weight/leading/tracking).
   Source of truth: MORY-STYLE-GUIDE.md §3 (color), §4 (typography),
   §5 (space), §6 (icons), §7.12 (focus ring), §8 (motion), §14.4
   (reduced transparency). */

/* === Webfonts (§4.1) === */
/* Inter is the variable font (single file covers the whole 100–900 axis).
   JetBrains Mono ships per-weight; Stage 0 only needs Regular. */

@font-face {
  font-family: "Inter";
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/InterVariable.woff2") format("woff2");
}

@font-face {
  font-family: "Inter";
  font-style: italic;
  font-weight: 100 900;
  font-display: swap;
  src: url("/fonts/InterVariable-Italic.woff2") format("woff2");
}

@font-face {
  font-family: "JetBrains Mono";
  font-style: normal;
  font-weight: 400;
  font-display: swap;
  src: url("/fonts/JetBrainsMono-Regular.woff2") format("woff2");
}

:root {
  /* === Surfaces (§3.1) === */
  --bg-base: #0E1310;
  --bg-surface: #161A14;
  --bg-elevated: #1F231C;
  --bg-overlay: rgba(14, 19, 16, 0.72);

  /* === Ink (§3.1) === */
  --ink-primary: #ECEFE5;
  --ink-secondary: #A3A8A0;
  --ink-tertiary: #6E7269;
  --ink-onaccent: #0E1310;

  /* === Accent (§3.1) === */
  --accent: #84CC16;
  --accent-hover: #95DC1F;
  --accent-pressed: #6FAA10;
  --accent-soft: rgba(132, 204, 22, 0.12);
  --accent-ring: rgba(132, 204, 22, 0.40);

  /* === Grade signals (§3.1) === */
  --grade-again: #F26B5E;
  --grade-hard: #F2B441;
  --grade-good: #46C28A;
  --grade-easy: var(--accent);

  /* === States (§3.1) === */
  --success: #46C28A;
  --error: #F26B5E;
  --warning: #F2B441;
  --info: #6FA8E5;

  /* === Lines (§3.1) === */
  --line-soft: rgba(236, 239, 229, 0.06);
  --line-base: rgba(236, 239, 229, 0.12);
  --line-strong: rgba(236, 239, 229, 0.20);

  /* === Type families (§4.1) === */
  --font-ui:
    "Inter", system-ui, -apple-system, "Segoe UI", "Roboto", sans-serif;
  --font-mono:
    "JetBrains Mono", ui-monospace, "Menlo", "Consolas", monospace;
  --font-display: var(--font-ui);

  /* === Type scale (§4.2) — base 16 px === */
  --text-xs: 0.75rem; /* 12 px */
  --text-sm: 0.875rem; /* 14 px */
  --text-base: 1rem; /* 16 px */
  --text-lg: 1.125rem; /* 18 px */
  --text-xl: 1.375rem; /* 22 px */
  --text-2xl: 1.75rem; /* 28 px */
  --text-3xl: 2.25rem; /* 36 px */
  --text-4xl: 3rem; /* 48 px */

  /* === Weights (§4.3) === */
  --weight-regular: 400;
  --weight-medium: 500;
  --weight-semibold: 600;
  --weight-bold: 700;

  /* === Line heights (§4.3) === */
  --leading-tight: 1.15;
  --leading-snug: 1.30;
  --leading-normal: 1.55;
  --leading-relaxed: 1.70;

  /* === Tracking (§4.3) === */
  --tracking-tight: -0.02em;
  --tracking-normal: 0;
  --tracking-wide: 0.08em;

  /* === Space — 4-pt base (§5.1) === */
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 20px;
  --space-6: 24px;
  --space-8: 32px;
  --space-12: 48px;
  --space-16: 64px;
  --space-24: 96px;

  /* === Containers (§5.2) === */
  --container-sm: 640px;
  --container-md: 720px;
  --container-lg: 960px;
  --container-xl: 1200px;

  /* === Icons (§6.2) === */
  --icon-sm: 16px;
  --icon-md: 20px;
  --icon-lg: 24px;
  --icon-xl: 32px;

  /* === Motion (§8.1) === */
  --motion-fast: 80ms;
  --motion-base: 160ms;
  --motion-slow: 240ms;
  --ease-out: cubic-bezier(0.16, 1, 0.3, 1);
  --ease-in: cubic-bezier(0.4, 0, 1, 1);
  --ease-in-out: cubic-bezier(0.4, 0, 0.2, 1);

  /* === Stage-0 holdovers, retained per migration table (§15) === */
  --touch-min: 44px;
  --radius: 8px;
}

/* Light mode (§3.2). Only the values that differ from dark are overridden. */
@media (prefers-color-scheme: light) {
  :root {
    --bg-base: #FAFAF6;
    --bg-surface: #FFFFFF;
    --bg-elevated: #FFFFFF;
    --bg-overlay: rgba(26, 28, 24, 0.40);

    --ink-primary: #1A1C18;
    --ink-secondary: #585B54;
    --ink-tertiary: #888B83;
    --ink-onaccent: #0E1310;

    --accent-hover: #76B814;
    --accent-soft: rgba(132, 204, 22, 0.10);
    --accent-ring: rgba(132, 204, 22, 0.45);

    --grade-again: #DC4F44;
    --grade-hard: #C99020;
    --grade-good: #2EA572;

    --success: #2EA572;
    --error: #DC4F44;
    --warning: #C99020;
    --info: #4A8AC8;

    --line-soft: rgba(26, 28, 24, 0.06);
    --line-base: rgba(26, 28, 24, 0.12);
    --line-strong: rgba(26, 28, 24, 0.20);
  }
}

/* === Globals === */

* {
  box-sizing: border-box;
}

/* Inter VF supports optical sizing — let the renderer scale glyphs to the
   text size automatically (§4.4). One approach per build; ss03 is skipped. */
html {
  font-optical-sizing: auto;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  background: var(--bg-base);
  color: var(--ink-primary);
  font-family: var(--font-ui);
  font-size: var(--text-base);
  font-weight: var(--weight-regular);
  line-height: var(--leading-normal);
}

/* Visible focus indicator on every interactive element (§7.12). The #1
   a11y regression is forgetting this, so it lives globally and wins by
   specificity over per-element overrides. */
:focus-visible {
  outline: 2px solid var(--accent-ring);
  outline-offset: 2px;
  border-radius: inherit;
}

/* Honour OS reduced-motion preference (§8.3). Opacity transitions stay
   allowed (instant cuts feel jarring even to motion-sensitive users);
   spatial/duration transitions are clamped. */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    transition-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    scroll-behavior: auto !important;
  }
}

/* Honour OS reduced-transparency preference (§14.4) — collapse the
   tinted scrim onto an opaque surface. */
@media (prefers-reduced-transparency: reduce) {
  :root {
    --bg-overlay: var(--bg-elevated);
  }
}

/* === Components === */
/* Wave 3 — refactored against MORY-STYLE-GUIDE.md §7. Each interactive
   surface gets its full state matrix (default/hover/pressed/focus/disabled);
   the focus ring lives globally above. */

/* In-page wordmark — App-nav register at 24 px tall (§2 variant matrix,
   §9.2 hero). Loading-screen wordmark is sized separately via inline
   #loading-screen img in index.html. */
.wordmark {
  display: block;
  height: 24px;
  width: auto;
  margin: var(--space-6) 0 var(--space-2);
}

/* Page container with responsive side padding (§5.5).
   < 600 px: --space-4   |   600–960: --space-6   |   ≥ 960: --space-8. */
.page {
  max-width: var(--container-md);
  margin: 0 auto;
  padding: var(--space-8) var(--space-4);
}

@media (min-width: 600px) {
  .page {
    padding-left: var(--space-6);
    padding-right: var(--space-6);
  }
}

@media (min-width: 960px) {
  .page {
    padding-left: var(--space-8);
    padding-right: var(--space-8);
  }
}

.heading {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  margin: 0;
}

.body {
  color: var(--ink-secondary);
}

.error {
  color: var(--error);
  font-family: var(--font-mono);
  background: rgba(242, 107, 94, 0.12);
  padding: var(--space-3);
  border-radius: var(--radius);
  border: 1px solid rgba(242, 107, 94, 0.30);
}

.review-header {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  margin-bottom: var(--space-6);
}

.review-progress {
  color: var(--ink-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-sm);
}

.card {
  background: var(--bg-surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: var(--space-6);
  /* §9.1: --space-6 between the card and the reveal button (or the
     grade row when show_back is true). */
  margin-bottom: var(--space-6);
  min-height: 200px;
}

.card-kind {
  color: var(--ink-secondary);
  font-family: var(--font-mono);
  font-size: var(--text-xs);
  font-weight: var(--weight-medium);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  margin-bottom: var(--space-4);
}

.dev-due {
  text-transform: none;
  letter-spacing: 0;
  opacity: 0.6;
}

.card-front {
  font-size: var(--text-lg);
  line-height: var(--leading-snug);
  white-space: pre-wrap;
}

.card-back {
  margin-top: var(--space-6);
  padding-top: var(--space-6);
  border-top: 1px solid var(--line-soft);
  font-size: var(--text-base);
  color: var(--ink-primary);
  white-space: pre-wrap;
}

/* Secondary button (§7.1): transparent fill, line-coloured border. */
.reveal {
  width: 100%;
  min-height: var(--touch-min);
  padding: var(--space-3) var(--space-5);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  background: transparent;
  color: var(--ink-primary);
  border: 1px solid var(--line-base);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    border-color var(--motion-fast) var(--ease-out),
    background-color var(--motion-fast) var(--ease-out),
    transform var(--motion-fast) var(--ease-out);
}

.reveal:hover:not(:disabled) {
  border-color: var(--line-strong);
}

.reveal:active:not(:disabled) {
  background-color: var(--line-soft);
  transform: scale(0.98);
}

.reveal:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.grades {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: var(--space-2);
}

/* Grade buttons (§9.1): per-grade colour as text + border, transparent
   fill until hover paints with the same hue at 12% alpha. */
.grade {
  min-height: var(--touch-min);
  padding: var(--space-3) var(--space-2);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  background: transparent;
  color: var(--ink-primary);
  border: 1px solid currentColor;
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    background-color var(--motion-fast) var(--ease-out),
    transform var(--motion-fast) var(--ease-out);
}

.grade-again {
  color: var(--grade-again);
}
.grade-hard {
  color: var(--grade-hard);
}
.grade-good {
  color: var(--grade-good);
}
.grade-easy {
  color: var(--grade-easy);
}

.grade:hover:not(:disabled) {
  background-color: color-mix(in srgb, currentColor 12%, transparent);
}

.grade:active:not(:disabled) {
  background-color: color-mix(in srgb, currentColor 18%, transparent);
  transform: scale(0.98);
}

.grade:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.ingest-form {
  display: flex;
  flex-direction: column;
  gap: var(--space-3);
  margin-top: var(--space-4);
}

/* Inputs (§7.2): default/hover/focus/invalid/disabled. */
.ingest-title,
.ingest-text {
  width: 100%;
  padding: var(--space-3) var(--space-4);
  font-family: inherit;
  font-size: var(--text-base);
  background: var(--bg-surface);
  color: var(--ink-primary);
  border: 1px solid var(--line-base);
  border-radius: var(--radius);
  transition: border-color var(--motion-fast) var(--ease-out);
}

.ingest-text {
  font-family: var(--font-mono);
  font-size: var(--text-sm);
  line-height: var(--leading-normal);
  resize: vertical;
  min-height: 240px;
}

.ingest-title:hover:not(:disabled),
.ingest-text:hover:not(:disabled) {
  border-color: var(--line-strong);
}

.ingest-title:focus,
.ingest-text:focus {
  border-color: var(--accent);
}

.ingest-title[aria-invalid="true"],
.ingest-text[aria-invalid="true"] {
  border-color: var(--error);
}

.ingest-title:disabled,
.ingest-text:disabled {
  background: var(--bg-base);
  opacity: 0.6;
  cursor: not-allowed;
}

/* Primary button (§7.1): accent fill, ink-onaccent text. */
.button-primary {
  min-height: var(--touch-min);
  padding: var(--space-3) var(--space-5);
  font-family: inherit;
  font-size: var(--text-sm);
  font-weight: var(--weight-semibold);
  background: var(--accent);
  color: var(--ink-onaccent);
  border: 1px solid var(--accent);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    background-color var(--motion-fast) var(--ease-out),
    border-color var(--motion-fast) var(--ease-out),
    transform var(--motion-fast) var(--ease-out);
}

.button-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
}

.button-primary:active:not(:disabled) {
  background: var(--accent-pressed);
  border-color: var(--accent-pressed);
  transform: scale(0.98);
}

.button-primary:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.helper {
  margin: 0;
  color: var(--ink-secondary);
  font-size: var(--text-sm);
}

/* ===========================================================================
   Drawer — slide-in utility tray (left edge).
   See components/drawer.rs and styles::DRAWER_*.
   =========================================================================== */

/* Hamburger trigger pinned top-left of the viewport on every page. The
   button sits above page content (z=20) but below the drawer panel (z=40)
   and overlay (z=30), so opening the drawer hides it visually under the
   panel without needing to toggle display. */
.drawer-trigger {
  position: fixed;
  top: var(--space-3);
  left: var(--space-3);
  z-index: 20;
  width: var(--touch-min);
  height: var(--touch-min);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background: transparent;
  color: var(--ink-primary);
  border: 1px solid var(--line-base);
  border-radius: var(--radius);
  cursor: pointer;
  transition:
    background-color var(--motion-fast) var(--ease-out),
    border-color var(--motion-fast) var(--ease-out);
}

.drawer-trigger:hover {
  background-color: var(--line-soft);
  border-color: var(--line-strong);
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  z-index: 30;
  background: var(--bg-overlay);
  opacity: 0;
  pointer-events: none;
  transition: opacity var(--motion-base) var(--ease-out);
}

.drawer-overlay--visible {
  opacity: 1;
  pointer-events: auto;
}

/* Closed state: panel is translated off-screen to the left. The
   transition runs in both directions so the slide-out animation plays
   when the user closes the drawer. */
.drawer-panel {
  position: fixed;
  top: 0;
  left: 0;
  z-index: 40;
  height: 100%;
  width: min(320px, 88vw);
  background: var(--bg-surface);
  border-right: 1px solid var(--line-base);
  display: flex;
  flex-direction: column;
  transform: translateX(-100%);
  transition: transform var(--motion-slow) var(--ease-in-out);
}

.drawer-panel--open {
  transform: translateX(0);
}

.drawer__header {
  padding: var(--space-6) var(--space-5);
  border-bottom: 1px solid var(--line-soft);
}

.drawer__header-link {
  display: inline-flex;
  text-decoration: none;
  /* Tap target — matches the trigger so muscle memory carries across. */
  min-height: var(--touch-min);
  align-items: center;
}

.drawer__header-wordmark {
  display: block;
  height: 24px;
  width: auto;
}

.drawer__body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: var(--space-3) 0;
}

.drawer__footer {
  display: flex;
  flex-wrap: wrap;
  gap: var(--space-1) var(--space-4);
  padding: var(--space-5);
  border-top: 1px solid var(--line-soft);
}

.drawer__footer-link {
  color: var(--ink-secondary);
  font-size: var(--text-sm);
  text-decoration: none;
  padding: var(--space-2) 0;
  transition: color var(--motion-fast) var(--ease-out);
}

.drawer__footer-link:hover {
  color: var(--ink-primary);
}

/* ===========================================================================
   Markdown body — rendered prose for /about, /privacy, /api, etc.
   =========================================================================== */

.markdown-page__title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  margin: 0 0 var(--space-6);
}

.content-body {
  color: var(--ink-primary);
  line-height: var(--leading-relaxed);
}

.content-body h1,
.content-body h2,
.content-body h3,
.content-body h4 {
  font-weight: var(--weight-semibold);
  letter-spacing: var(--tracking-tight);
  margin: var(--space-8) 0 var(--space-3);
  line-height: var(--leading-snug);
}

.content-body h1 { font-size: var(--text-2xl); }
.content-body h2 { font-size: var(--text-xl); }
.content-body h3 { font-size: var(--text-lg); }
.content-body h4 {
  font-size: var(--text-base);
  text-transform: uppercase;
  letter-spacing: var(--tracking-wide);
  color: var(--ink-secondary);
}

.content-body p,
.content-body ul,
.content-body ol,
.content-body blockquote {
  margin: 0 0 var(--space-4);
}

.content-body ul,
.content-body ol {
  padding-left: var(--space-6);
}

.content-body li + li {
  margin-top: var(--space-2);
}

.content-body a {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 0.15em;
}

.content-body a:hover {
  color: var(--accent-hover);
}

.content-body code {
  font-family: var(--font-mono);
  font-size: 0.92em;
  background: var(--line-soft);
  border: 1px solid var(--line-soft);
  border-radius: 4px;
  padding: 0.05em 0.35em;
}

.content-body pre {
  background: var(--bg-elevated);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: var(--space-3) var(--space-4);
  overflow-x: auto;
  margin: 0 0 var(--space-4);
}

.content-body pre code {
  background: transparent;
  border: 0;
  padding: 0;
  font-size: var(--text-sm);
  line-height: var(--leading-snug);
}

.content-body blockquote {
  border-left: 2px solid var(--line-strong);
  padding-left: var(--space-4);
  color: var(--ink-secondary);
}

.content-body hr {
  border: 0;
  border-top: 1px solid var(--line-soft);
  margin: var(--space-8) 0;
}

.markdown-table-wrap {
  overflow-x: auto;
  margin: 0 0 var(--space-4);
}

.markdown-table {
  width: 100%;
  border-collapse: collapse;
  font-size: var(--text-sm);
}

.markdown-table th,
.markdown-table td {
  padding: var(--space-2) var(--space-3);
  border-bottom: 1px solid var(--line-soft);
  vertical-align: top;
}

.markdown-table th {
  font-weight: var(--weight-semibold);
  color: var(--ink-primary);
  border-bottom-color: var(--line-base);
  text-align: left;
}

.markdown-table .align-left   { text-align: left; }
.markdown-table .align-center { text-align: center; }
.markdown-table .align-right  { text-align: right; }

/* ===========================================================================
   Contact page — categorical mailto tiles.
   See pages/contact.rs and styles::CONTACT_*.
   =========================================================================== */

.contact-page__title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  margin: 0 0 var(--space-3);
}

.contact-page__subtitle {
  color: var(--ink-secondary);
  margin: 0 0 var(--space-8);
}

.contact-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: var(--space-3);
}

@media (min-width: 600px) {
  .contact-grid {
    grid-template-columns: 1fr 1fr;
  }
}

.contact-tile {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  background: var(--bg-surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: var(--space-4);
  text-decoration: none;
  color: var(--ink-primary);
  transition:
    border-color var(--motion-fast) var(--ease-out),
    background-color var(--motion-fast) var(--ease-out);
}

.contact-tile:hover {
  border-color: var(--line-strong);
  background-color: var(--bg-elevated);
}

.contact-tile__heading {
  font-weight: var(--weight-semibold);
}

.contact-tile__description {
  font-size: var(--text-sm);
  color: var(--ink-secondary);
}

/* ===========================================================================
   Legal directory page — list of subpages.
   See pages/legal.rs and styles::LEGAL_*.
   =========================================================================== */

.legal-page__title {
  font-size: var(--text-2xl);
  font-weight: var(--weight-bold);
  letter-spacing: var(--tracking-tight);
  margin: 0 0 var(--space-6);
}

.legal-nav {
  display: flex;
  flex-direction: column;
  gap: var(--space-2);
  margin-top: var(--space-4);
}

.legal-nav__item {
  display: flex;
  flex-direction: column;
  gap: var(--space-1);
  background: var(--bg-surface);
  border: 1px solid var(--line-soft);
  border-radius: var(--radius);
  padding: var(--space-4);
  text-decoration: none;
  color: var(--ink-primary);
  transition:
    border-color var(--motion-fast) var(--ease-out),
    background-color var(--motion-fast) var(--ease-out);
}

.legal-nav__item:hover {
  border-color: var(--line-strong);
  background-color: var(--bg-elevated);
}

.legal-nav__label {
  font-weight: var(--weight-semibold);
}

.legal-nav__desc {
  font-size: var(--text-sm);
  color: var(--ink-secondary);
}
