/* ==========================================================================
   S-Way theme — "the typewriter left in the abandoned house"
   Daylight: dusty attic light on cream paper, faded damask wallpaper.
   Lamplight: the same room after dark; sheets glow amber against walnut.
   ========================================================================== */

:root {
  /* Core palette */
  --paper: #EDE3CC;
  --paper-aged: #E4D6B6;
  --beige: #DCC9A3;
  --wallpaper: #C9B48E;
  --wallpaper-motif: #B9A17A;
  --walnut: #4A3426;
  --walnut-deep: #33241A;
  --ink: #2B1F17;
  --ink-soft: #5B4636;
  --ink-faint: #8A735E;
  --ribbon: #8B2E24;       /* typewriter ribbon red: stamps, alerts */
  --brass: #9A7B3F;        /* tarnished brass: rims, focus, rules */
  --moss: #5D6440;         /* faded green felt: "low" / ok states */

  /* Roles */
  --bg: var(--wallpaper);
  --surface: var(--paper);
  --surface-2: var(--paper-aged);
  --surface-3: var(--beige);
  --text: var(--ink);
  --text-soft: var(--ink-soft);
  --text-faint: var(--ink-faint);
  --rule: #B9A37F;
  --rule-strong: var(--walnut);
  --accent: var(--ribbon);
  --key-face: var(--walnut);
  --key-text: var(--paper);
  --key-rim: var(--brass);
  --focus: #B07A1E;
  --shadow: 0 1px 0 rgba(255, 250, 235, .6) inset, 0 10px 24px -14px rgba(51, 36, 26, .55), 0 2px 3px rgba(51, 36, 26, .18);
  --mark-exact: rgba(139, 46, 36, .22);
  --mark-near: rgba(154, 123, 63, .32);
  --mark-para: rgba(93, 100, 64, .25);

  /* Type */
  --font-display: 'Special Elite', 'Courier New', monospace;
  --font-body: 'Courier Prime', 'Courier New', Courier, monospace;
  --step--1: .875rem;
  --step-0: 1.0625rem;
  --step-1: 1.25rem;
  --step-2: 1.5rem;
  --step-3: 2rem;
  --step-4: 2.75rem;
  --step-5: 3.75rem;
  --measure: 68ch;

  --radius-sheet: 2px;
  --radius-key: 6px;
  color-scheme: light;
}

/* Lamplight (dark) — applied when the OS prefers dark and the user has not chosen daylight,
   or when the user explicitly chooses lamplight. */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --is-dark: 1; }
  :root:not([data-theme="light"]) {
    --bg: #1A130E;
    --surface: #2A2019;
    --surface-2: #33271E;
    --surface-3: #3D2F24;
    --text: #EADDC2;
    --text-soft: #CDB995;
    --text-faint: #9C8669;
    --rule: #5C4837;
    --rule-strong: #C9A15C;
    --accent: #D46A58;
    --key-face: #C9A15C;
    --key-text: #1E1610;
    --key-rim: #7A5C2E;
    --focus: #E8B65C;
    --wallpaper-motif: #241A13;
    --shadow: 0 0 0 1px rgba(201, 161, 92, .08), 0 14px 30px -16px rgba(0, 0, 0, .9);
    --mark-exact: rgba(212, 106, 88, .3);
    --mark-near: rgba(201, 161, 92, .3);
    --mark-para: rgba(150, 160, 110, .28);
    --moss: #A3AC7A;
    color-scheme: dark;
  }
}
:root[data-theme="dark"] {
  --bg: #1A130E;
  --surface: #2A2019;
  --surface-2: #33271E;
  --surface-3: #3D2F24;
  --text: #EADDC2;
  --text-soft: #CDB995;
  --text-faint: #9C8669;
  --rule: #5C4837;
  --rule-strong: #C9A15C;
  --accent: #D46A58;
  --key-face: #C9A15C;
  --key-text: #1E1610;
  --key-rim: #7A5C2E;
  --focus: #E8B65C;
  --wallpaper-motif: #241A13;
  --shadow: 0 0 0 1px rgba(201, 161, 92, .08), 0 14px 30px -16px rgba(0, 0, 0, .9);
  --mark-exact: rgba(212, 106, 88, .3);
  --mark-near: rgba(201, 161, 92, .3);
  --mark-para: rgba(150, 160, 110, .28);
  --moss: #A3AC7A;
  color-scheme: dark;
}

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

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

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font-body);
  font-size: var(--step-0);
  line-height: 1.6;
  color: var(--text);
  background-color: var(--bg);
  /* Faded damask wallpaper, a water stain and a dim vignette. */
  background-image:
    radial-gradient(120% 90% at 50% 20%, transparent 55%, rgba(30, 20, 12, .35) 100%),
    radial-gradient(28rem 18rem at 88% 12%, rgba(120, 88, 50, .16), transparent 70%),
    radial-gradient(18rem 26rem at 6% 78%, rgba(90, 64, 38, .14), transparent 70%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='160' viewBox='0 0 120 160'%3E%3Cg fill='none' stroke='%23000' stroke-opacity='.07' stroke-width='1.4'%3E%3Cpath d='M60 10c10 18 30 22 30 46S70 90 60 104C50 90 30 80 30 56S50 28 60 10z'/%3E%3Cpath d='M60 34c5 9 14 12 14 24s-9 18-14 24c-5-6-14-12-14-24s9-15 14-24z'/%3E%3Cpath d='M0 130c14-8 18-26 0-34M120 130c-14-8-18-26 0-34'/%3E%3Ccircle cx='60' cy='140' r='5'/%3E%3C/g%3E%3C/svg%3E"),
    repeating-linear-gradient(90deg, transparent 0 58px, rgba(0, 0, 0, .025) 58px 60px);
}

h1, h2, h3, h4 {
  font-family: var(--font-display);
  font-weight: 400;
  line-height: 1.15;
  margin: 0 0 .5em;
  color: var(--text);
  text-wrap: balance;
}
h1 { font-size: var(--step-4); letter-spacing: -.01em; }
h2 { font-size: var(--step-3); }
h3 { font-size: var(--step-2); }
h4 { font-size: var(--step-1); }

p { margin: 0 0 1em; max-width: var(--measure); }
small, .fine { font-size: var(--step--1); color: var(--text-soft); }

a { color: inherit; text-decoration-color: var(--brass); text-decoration-thickness: 2px; text-underline-offset: .2em; }
a:hover { color: var(--accent); }

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

::selection { background: var(--mark-near); color: var(--text); }

code, kbd, pre { font-family: var(--font-body); }

hr {
  border: 0;
  height: 1px;
  background: repeating-linear-gradient(90deg, var(--rule) 0 6px, transparent 6px 10px);
  margin: 2rem 0;
}

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

.skip-link {
  position: absolute;
  left: 1rem; top: -4rem;
  z-index: 100;
  background: var(--surface);
  padding: .5rem 1rem;
  border: 2px solid var(--rule-strong);
}
.skip-link:focus { top: 1rem; }

/* Paper fibres for every sheet. */
.paper-grain {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.85' numOctaves='2' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 .3 0 0 0 0 .22 0 0 0 0 .14 0 0 0 .09 0'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E");
}

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