/* base.css: tokens, reset, typography. Mobile first, logical properties only. */

/* Look: copy-shop flyer meets messenger channel: newsprint paper, ink, signal red,
   highlighter yellow, hard offset shadows instead of soft ones, (almost) square corners. */
:root {
  --font-body: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "SN Arabic", "SN Hebrew",
    "SN Devanagari", "SN SC", "SN KR", sans-serif;
  --font-display: "SN Display", "Arial Narrow", var(--font-body);
  --font-mono: ui-monospace, "Cascadia Mono", "DejaVu Sans Mono", "Courier New", monospace;
  --color-bg: #f3efe6;
  --color-surface: #fffdf7;
  --color-text: #151412;
  --color-ink: #151412;
  --color-muted: #4d4940;
  --color-accent: #b3121b;
  --color-accent-contrast: #ffffff;
  --color-done: #1e7a34;
  --color-done-contrast: #ffffff;
  --color-border: #cbc4b4;
  --color-focus: #0b57d0;
  --color-gold: #9a7400;
  --color-marker: #ffe066;
  --color-marker-text: #151412;
  /* Label-maker tape (chapter labels): colour pairs chosen as complements, AA contrast in both modes. */
  --tape-bg: #151412;
  --tape-text: #fffdf7;
  --tape-accent: #ffe066;
  --shadow-ink: #151412;
  --sx: 3px; /* shadow offset towards inline-end; mirrored for RTL below */
  --shadow-hard: var(--sx) 3px 0 var(--shadow-ink);
  --shadow-hard-lg: calc(var(--sx) * 2) 6px 0 var(--shadow-ink);
  --grain: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='180' height='180'%3E%3Cfilter id='g'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.9' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 .07 0'/%3E%3C/filter%3E%3Crect width='180' height='180' filter='url(%23g)'/%3E%3C/svg%3E");
  --radius: 2px;
  --space-1: 0.25rem;
  --space-2: 0.5rem;
  --space-3: 1rem;
  --space-4: 1.5rem;
  --space-5: 2.5rem;
  --tap: 2.75rem; /* 44 px touch targets */
  --measure: 70ch;
  --duration: 180ms;
  color-scheme: light dark;
}
[dir="rtl"] { --sx: -3px; }

@media (prefers-color-scheme: dark) {
  /* «typed into the phone at 3 a.m.» */
  :root {
    --color-bg: #131211;
    --color-surface: #1d1c1a;
    --color-text: #f1ece0;
    --color-ink: #f1ece0;
    --color-muted: #b9b2a3;
    --color-accent: #ff6b5e;
    --color-accent-contrast: #131211;
    --color-done: #5fd17a;
    --color-done-contrast: #131211;
    --color-border: #3d3a35;
    --color-focus: #8ab4f8;
    --color-gold: #f2c94c;
    --shadow-ink: #000000;
    --grain: none;
    --tape-bg: #ffe066;
    --tape-text: #131211;
    --tape-accent: #4b2bb3; /* violet: complement of the yellow tape */
  }
}

/* Scripts that join letters or have no monospace/display design of their own: no
   typewriter face and no tracking (letter-spacing breaks Arabic joining). */
:root:is(:lang(ar), :lang(fa), :lang(he), :lang(hi), :lang(ja), :lang(ko), :lang(zh-Hans)) { --font-mono: var(--font-body); }
:is(:lang(ar), :lang(fa), :lang(he), :lang(hi), :lang(ja), :lang(ko), :lang(zh-Hans)) * { letter-spacing: 0 !important; }

/* Japanese text: prefer Japanese glyph shapes for shared Han characters. */
:root:lang(ja) { --font-body: system-ui, "Hiragino Sans", "Yu Gothic", "SN JP", sans-serif; }
:root:lang(zh-Hans) { --font-body: system-ui, "PingFang SC", "Microsoft YaHei", "SN SC", sans-serif; }
:root:lang(ko) { --font-body: system-ui, "Apple SD Gothic Neo", "Malgun Gothic", "SN KR", sans-serif; }

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

html {
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

body {
  margin: 0;
  min-block-size: 100vh;
  background-color: var(--color-bg);
  background-image: var(--grain);
  color: var(--color-text);
  font-family: var(--font-body);
  font-size: 1.0625rem;
  line-height: 1.6;
  overflow-wrap: anywhere;
}

/* CJK and Devanagari need no extra letter-spacing and slightly more leading. */
:lang(zh-Hans) body, :lang(ja) body, :lang(ko) body, :lang(hi) body { line-height: 1.8; }

h1, h2, h3 { line-height: 1.2; margin-block: 0 var(--space-3); }
h1, h2 { font-family: var(--font-display); font-weight: 600; line-height: 1.08; letter-spacing: 0.005em; }
/* Scripts without the display face keep a comfortable leading. */
:is(:lang(ar), :lang(fa), :lang(he), :lang(hi), :lang(ja), :lang(ko), :lang(zh-Hans)) :is(h1, h2) { line-height: 1.35; }
h1 { font-size: clamp(1.75rem, 5vw + 1rem, 3rem); }
h2 { font-size: clamp(1.35rem, 2vw + 1rem, 2rem); }
p { margin-block: 0 var(--space-3); max-inline-size: var(--measure); }

a { color: var(--color-accent); text-underline-offset: 0.15em; text-decoration-thickness: 0.08em; }
mark { background: var(--color-marker); color: var(--color-marker-text); padding-inline: 0.15em; }

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

.skip-link {
  position: absolute;
  inset-block-start: var(--space-2);
  inset-inline-start: var(--space-2);
  padding: var(--space-2) var(--space-3);
  background: var(--color-surface);
  border-radius: var(--radius);
  transform: translateY(-200%);
}
.skip-link:focus { transform: none; }

.icon { inline-size: 1.25em; block-size: 1.25em; vertical-align: -0.2em; flex-shrink: 0; }

/* Icons with a direction (arrows, chevrons) mirror in right-to-left scripts. */
[dir="rtl"] .icon--dir { transform: scaleX(-1); }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
    scroll-behavior: auto !important;
  }
}
:root[data-motion="off"] *, :root[data-motion="off"] *::before, :root[data-motion="off"] *::after {
  animation: none !important;
  transition: none !important;
}

/* The hidden attribute always wins over component display values. */
[hidden] { display: none !important; }
