/* Typewriter — psykaze.com */

@font-face {
  font-family: 'Sicarius Remake';
  src: url('/uploads/SicariusRemake-Regular.otf') format('opentype');
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

:root {
  /* Site palette (dark), used for everything around the paper */
  --ui-bg: oklch(0.16 0.008 260 / 0.96);
  --ui-surface: oklch(0.21 0.01 260);
  --ui-line: oklch(0.32 0.015 255);
  --ui-fg: oklch(0.96 0.003 0);
  --ui-muted: oklch(0.72 0.01 250);
  --ui-dim: oklch(0.56 0.012 250);
  --ui-accent: oklch(0.72 0.19 250);
  --ui-danger: oklch(0.68 0.16 25);
  --font-ui: 'Sicarius Remake', 'Helvetica Neue', Helvetica, Arial, sans-serif;
  --font-body: 'Helvetica Neue', Helvetica, Arial, sans-serif;

  /* Scene */
  --desk-1: #3a2619;
  --desk-2: #2a1a10;
  --desk-3: #1a0f09;
  --paper: #f3eee2;
  --ink: #1d1b1a;
  --machine-1: #2b2b2e;
  --machine-2: #141416;

  /* Set from settings.js at start-up */
  --font-size: 20px;
  --cell-w: 12px;
  --line-h: 25px;
  --sheet-w: 1020px;
  --strike-y: 60vh;
  --feed-ms: 900ms;
  --paper-font: 'Special Elite', 'Courier New', monospace;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body {
  overflow: hidden;
  background: var(--desk-3);
  color: var(--ui-fg);
  font-family: var(--font-body);
  -webkit-font-smoothing: antialiased;
}

/* ---------------------------------------------------------------- input */

#input {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  padding: 0;
  border: 0;
  opacity: 0;
  resize: none;
  pointer-events: none;
  overflow: hidden;
  white-space: pre;
  caret-color: transparent;
}

/* ---------------------------------------------------------------- desk */

#stage {
  position: fixed;
  inset: 0;
  overflow: hidden;
  cursor: text;
  background:
    radial-gradient(ellipse 70% 60% at 50% 38%, rgba(255, 214, 160, 0.13), transparent 70%),
    radial-gradient(ellipse 120% 90% at 50% 50%, transparent 55%, rgba(0, 0, 0, 0.55)),
    repeating-linear-gradient(92deg, rgba(0, 0, 0, 0.07) 0 2px, transparent 2px 9px, rgba(255, 255, 255, 0.025) 9px 11px, transparent 11px 23px),
    repeating-linear-gradient(88deg, rgba(0, 0, 0, 0.05) 0 1px, transparent 1px 37px),
    linear-gradient(180deg, var(--desk-1), var(--desk-2) 60%, var(--desk-3));
}

/* ---------------------------------------------------------------- paper */

#carriage, #feed {
  position: absolute;
  left: 0;
  top: 0;
  will-change: transform;
}

.sheet {
  position: absolute;
  left: 0;
  top: 0;
  width: var(--sheet-w);
  background: var(--paper);
  box-shadow:
    0 1px 0 rgba(255, 255, 255, 0.4) inset,
    0 2px 4px rgba(0, 0, 0, 0.25),
    0 18px 40px rgba(0, 0, 0, 0.45);
  transition: opacity 400ms ease;
}

/* Finished sheets leave the machine once the new one has fed in. */
.sheet.off {
  opacity: 0;
  transition-delay: calc(var(--feed-ms) * 0.55);
}
body.reading .sheet { opacity: 1; transition-delay: 0s; }

/* A sheet torn out of the machine stays out of sight (but can be read back). */
.sheet.ripped { opacity: 0; transition: none; }
body.reading .sheet.ripped { opacity: 1; }

/* Ageing: older notes yellow towards the edges (--age 0–1, set per note). */
.sheet::after {
  content: '';
  position: absolute;
  inset: 0;
  pointer-events: none;
  opacity: var(--age, 0);
  background:
    radial-gradient(ellipse 75% 70% at 50% 50%, rgba(214, 178, 100, 0) 55%, rgba(205, 165, 85, 0.35) 88%, rgba(180, 135, 60, 0.55) 100%),
    linear-gradient(180deg, rgba(220, 190, 120, 0.12), rgba(220, 190, 120, 0) 12%, rgba(220, 190, 120, 0) 88%, rgba(220, 190, 120, 0.14));
}
body.theme-minimal .sheet::after { display: none; }

.line {
  position: absolute;
  left: 0;
  right: 0;
}

.ch {
  position: absolute;
  top: 0;
  width: var(--cell-w);
  height: var(--line-h);
  line-height: var(--line-h);
  text-align: center;
  font-family: var(--paper-font);
  font-size: var(--font-size);
  white-space: pre;
  user-select: none;
}

.ch.fading {
  animation: fade-out 1s ease-in forwards;
}
@keyframes fade-out {
  to { opacity: 0; }
}

/* ---------------------------------------------------------------- ink (Phases 3–4) */

/* Ink colours as RGB triples, so blots and smears can use them with alpha.
   --wet-rgb is the darker, fresher shade a letter starts at. */
body { --ink-rgb: 29, 27, 26; --wet-rgb: 5, 4, 3; --gap: #f3eee2; }
body.theme-minimal { --ink-rgb: 85, 87, 92; --wet-rgb: 38, 40, 43; --gap: #f4f5f7; }
.ch { color: rgb(var(--ink-rgb)); transform-origin: 50% 72%; }
.ch.red { --ink-rgb: 166, 40, 32; --wet-rgb: 110, 18, 12; }
body.theme-minimal .ch.red { --ink-rgb: 178, 88, 80; --wet-rgb: 140, 55, 48; }

/* Ink feathering into the paper fibres */
.ch.bleed {
  text-shadow:
    0 0 0.5px rgba(var(--ink-rgb), 0.55),
    0 0 1.3px rgba(var(--ink-rgb), 0.16);
}
body.theme-minimal .ch.bleed {
  text-shadow:
    0 0 0.5px rgba(var(--ink-rgb), 0.4),
    0 0 1.2px rgba(var(--ink-rgb), 0.1);
}

/* Wet ink: a darker, slightly spread copy on top that fades as it dries */
.ch.wet::after {
  content: attr(data-c);
  position: absolute;
  inset: 0;
  color: rgb(var(--wet-rgb));
  text-shadow: 0 0 0.4px rgba(var(--wet-rgb), 0.9), 0 0 1.4px rgba(var(--wet-rgb), 0.45);
  pointer-events: none;
  animation: ink-dry var(--wet-ms, 1500ms) cubic-bezier(0.3, 0.1, 0.4, 1) forwards;
}
@keyframes ink-dry {
  from { opacity: 0.85; }
  to { opacity: 0; }
}

/* Worn type: a filled-in counter… */
.ch.flaw-fill::before {
  content: '';
  position: absolute;
  left: calc(var(--fx) - 0.11em);
  top: calc(var(--fy) - 0.1em);
  width: 0.22em;
  height: 0.2em;
  border-radius: 50%;
  background: radial-gradient(closest-side, rgba(var(--ink-rgb), 0.85), rgba(var(--ink-rgb), 0.35) 70%, rgba(var(--ink-rgb), 0));
  pointer-events: none;
}
/* …or a broken stroke: a hairline of bare paper across the letter */
.ch.flaw-break::before {
  content: '';
  position: absolute;
  left: 18%;
  right: 18%;
  top: var(--by);
  height: 1.1px;
  background: var(--gap);
  transform: rotate(var(--ba));
  pointer-events: none;
  z-index: 1;
}

/* Blots, smears and drags sit under the letter */
.ch > i {
  position: absolute;
  pointer-events: none;
  z-index: -1;
}
.ch { isolation: isolate; }

/* The faint smear a blot leaves behind (saved with the note) */
.ch > .smear {
  left: calc(50% - var(--sw) / 2 + var(--sx));
  top: calc(58% - var(--sh) / 2 + var(--sy));
  width: var(--sw);
  height: var(--sh);
  border-radius: 50%;
  transform: rotate(var(--sr));
  background: radial-gradient(closest-side, rgba(var(--ink-rgb), calc(var(--so) * 1.6)), rgba(var(--ink-rgb), var(--so)) 45%, rgba(var(--ink-rgb), 0));
}

/* The wet blob itself: dark and glossy, shrinking and fading as it soaks in */
.ch > .wet-blot {
  left: calc(50% - 0.75em);
  top: calc(58% - 0.75em);
  width: 1.5em;
  height: 1.5em;
  border-radius: 50%;
  z-index: 2;
  background:
    radial-gradient(circle at 38% 34%, rgba(255, 255, 255, 0.4) 0 7%, rgba(255, 255, 255, 0) 13%),
    radial-gradient(closest-side, rgba(var(--wet-rgb), 0.95), rgba(var(--wet-rgb), 0.85) 50%, rgba(var(--wet-rgb), 0.35) 78%, rgba(var(--wet-rgb), 0));
  animation: blot-dry var(--blot-ms, 4000ms) cubic-bezier(0.25, 0.1, 0.3, 1) forwards;
}
@keyframes blot-dry {
  0% { transform: scale(0.6); opacity: 0; }
  6% { transform: scale(1.1); opacity: 1; }
  100% { transform: scale(0.75); opacity: 0; }
}

/* A smear dragged sideways from a letter, as if the paper caught */
.ch > .drag {
  left: 50%;
  top: var(--dy);
  width: var(--dl);
  height: 0.3em;
  border-radius: 50%;
  transform-origin: 0 50%;
  transform: scaleX(var(--dd)) rotate(var(--dr));
  background: linear-gradient(90deg, rgba(var(--ink-rgb), 0.2), rgba(var(--ink-rgb), 0.08) 55%, rgba(var(--ink-rgb), 0));
}

/* ---------------------------------------------------------------- paper (Phase 3) */

.sheet { background-size: 100% 100%; }

/* The top edge curling slightly towards you */
body:not(.theme-minimal) .sheet::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: 0;
  height: 14px;
  background: linear-gradient(180deg, rgba(70, 55, 35, 0.1), rgba(70, 55, 35, 0));
  pointer-events: none;
}

/* Shading where the paper bends round the platen. Lives in the carriage, so
   it moves sideways with the paper but stays at the platen's height. */
#curl { display: none; }
body.paper-curl #curl {
  display: block;
  position: absolute;
  left: 0;
  top: calc(var(--strike-y) - 34px);
  width: var(--sheet-w);
  height: 37px;
  background: linear-gradient(180deg,
    rgba(60, 45, 30, 0) 0%,
    rgba(60, 45, 30, 0.06) 55%,
    rgba(40, 30, 20, 0.2) 100%);
  pointer-events: none;
  transition: opacity 300ms ease;
}
body.reading #curl,
body.unfed #curl { opacity: 0; }

/* ---------------------------------------------------------------- machine */

#machine {
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--strike-y) + 3px);
  bottom: 0;
  pointer-events: none;
  transition: transform 450ms cubic-bezier(0.55, 0.05, 0.25, 1);
}
body.reading #machine { transform: translateY(78%); }

#machine .platen {
  height: 58px;
  background:
    linear-gradient(180deg,
      #0b0b0c 0%, #2c2c30 18%, #3b3b40 32%, #222226 55%, #101012 78%, #050506 100%);
  box-shadow: 0 -6px 14px rgba(0, 0, 0, 0.35);
}

#machine .body {
  position: absolute;
  left: 0;
  right: 0;
  top: 58px;
  bottom: 0;
  background:
    radial-gradient(ellipse 60% 120% at 50% 0%, rgba(255, 255, 255, 0.06), transparent 70%),
    linear-gradient(180deg, var(--machine-1), var(--machine-2));
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

/* Strike point marker: a small notch pointing at the next letter. */
#guide {
  position: absolute;
  left: 50%;
  top: -2px;
  width: calc(var(--cell-w) * 5);
  height: 10px;
  transform: translateX(-50%);
  background: linear-gradient(180deg, rgba(210, 215, 222, 0.55), rgba(140, 145, 152, 0.4));
  border-radius: 0 0 3px 3px;
}
#guide .notch {
  position: absolute;
  left: 50%;
  top: -5px;
  width: 0;
  height: 0;
  margin-left: -5px;
  border: 5px solid transparent;
  border-bottom: 6px solid #b23a2e;
  border-top: 0;
}
#guide.flash { animation: guide-flash 300ms ease; }
@keyframes guide-flash {
  50% { opacity: 0.2; }
}

#bell {
  position: absolute;
  right: 28px;
  top: calc(var(--strike-y) - 30px);
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #f2c46b;
  opacity: 0;
  box-shadow: 0 0 18px 6px rgba(242, 196, 107, 0.6);
}
#bell.flash { animation: bell-flash 900ms ease-out; }
@keyframes bell-flash {
  0% { opacity: 0.9; }
  100% { opacity: 0; }
}

/* ---------------------------------------------------------------- paper types */

/* Stock layer inside each sheet, under the type. */
.stock { display: none; position: absolute; inset: 0; pointer-events: none; }

/* Lined: pale blue rules under each typed line and a red margin line. */
body.paper-lined .stock { display: block; }
body.paper-lined .stock::before {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  top: var(--rules-top);
  height: var(--rules-h);
  background: repeating-linear-gradient(180deg,
    transparent 0 calc(var(--line-h) - 4px),
    rgba(80, 120, 185, 0.3) calc(var(--line-h) - 4px) calc(var(--line-h) - 3px),
    transparent calc(var(--line-h) - 3px) var(--line-h));
}
body.paper-lined .stock::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: var(--margin-x);
  width: 1px;
  background: rgba(205, 80, 80, 0.38);
  box-shadow: 3px 0 0 rgba(205, 80, 80, 0.16);
}

/* Onionskin: thin, slightly see-through paper with a lighter shadow. */
body.paper-onionskin { --paper: rgba(246, 243, 235, 0.86); --gap: #ddd7cb; }
body.paper-onionskin .sheet {
  box-shadow:
    0 1px 2px rgba(0, 0, 0, 0.18),
    0 10px 24px rgba(0, 0, 0, 0.28);
}
body.paper-onionskin .ch.bleed {
  text-shadow:
    0 0 0.6px rgba(var(--ink-rgb), 0.5),
    0 0 1.6px rgba(var(--ink-rgb), 0.18);
}

/* Carbon copy: thin grey-white paper, soft blue type and a faint haze where
   the carbon sheet pressed. Every colour of ribbon copies through as blue. */
body.paper-carbon { --paper: #ebebe7; --gap: #ebebe7; }
body.paper-carbon .ch,
body.paper-carbon .ch.red { --ink-rgb: 46, 58, 138; --wet-rgb: 30, 38, 112; }
body.paper-carbon .ch.bleed {
  text-shadow:
    0 0 0.8px rgba(var(--ink-rgb), 0.7),
    0 0 2.2px rgba(var(--ink-rgb), 0.28);
}
body.paper-carbon .stock {
  display: block;
  background:
    radial-gradient(ellipse 34% 22% at var(--hx) var(--hy), rgba(60, 70, 140, 0.05), transparent 70%),
    radial-gradient(ellipse 26% 30% at var(--hx2) var(--hy2), rgba(60, 70, 140, 0.04), transparent 70%);
}

/* ---------------------------------------------------------------- desk lamp */
/* Three still layers over the scene; only their opacity changes (set by
   scene.js from the time of day). */

#lamp { display: none; position: absolute; inset: 0; pointer-events: none; }
body.lamp-on #lamp { display: block; }
#lamp > div {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity var(--lamp-fade, 2500ms) ease;
}
#lamp .dark {
  background: radial-gradient(ellipse 58% 62% at 50% 46%,
    rgba(8, 5, 3, 0) 0%, rgba(8, 5, 3, 0.3) 34%, rgba(8, 5, 3, 0.78) 64%, rgba(3, 2, 1, 0.97) 100%);
}
#lamp .pool {
  background:
    radial-gradient(ellipse 36% 44% at 54% 42%, rgba(255, 196, 110, 0.32), rgba(255, 170, 85, 0.13) 55%, rgba(255, 170, 85, 0) 80%),
    radial-gradient(ellipse 16% 14% at 56% 30%, rgba(255, 225, 170, 0.16), rgba(255, 225, 170, 0) 80%);
}
#lamp .daylight {
  background:
    linear-gradient(150deg, rgba(220, 232, 255, 0.14) 0%, rgba(220, 232, 255, 0.05) 35%, rgba(220, 232, 255, 0) 60%);
}
body.theme-minimal #lamp .dark {
  background: radial-gradient(ellipse 62% 66% at 50% 46%,
    rgba(40, 38, 45, 0) 0%, rgba(40, 38, 45, 0.05) 40%, rgba(40, 38, 45, 0.22) 75%, rgba(30, 28, 34, 0.42) 100%);
}
body.theme-minimal #lamp .pool {
  background: radial-gradient(ellipse 36% 44% at 50% 46%, rgba(255, 214, 150, 0.16), rgba(255, 214, 150, 0) 75%);
}
body.theme-minimal #lamp .daylight {
  background: linear-gradient(150deg, rgba(225, 236, 255, 0.35), rgba(225, 236, 255, 0) 55%);
}
@media (prefers-reduced-motion: reduce) {
  #lamp > div { transition: none; }
}

/* ---------------------------------------------------------------- visible typewriter */
/* Platen with knobs (moves with the carriage), ribbon spools and tape, the
   ribbon vibrator at the strike point, and the fan of typebars. */

#roller, #tape, .spool, #vibrator, #segment, #typebars { display: none; }
body.show-machine #roller,
body.show-machine #tape,
body.show-machine .spool,
body.show-machine #vibrator,
body.show-machine #segment,
body.show-machine #typebars { display: block; }
body.show-machine #machine .platen { visibility: hidden; }

#roller {
  position: absolute;
  top: 0;
  left: calc(var(--sheet-w) * -0.13);
  width: calc(var(--sheet-w) * 1.26);
  height: 58px;
  border-radius: 6px;
  background:
    linear-gradient(180deg,
      #0b0b0c 0%, #2c2c30 18%, #3b3b40 32%, #222226 55%, #101012 78%, #050506 100%);
  box-shadow: 0 -6px 14px rgba(0, 0, 0, 0.35), 0 8px 18px rgba(0, 0, 0, 0.5);
  will-change: transform;
}
#roller .knob {
  position: absolute;
  top: -7px;
  width: 44px;
  height: 72px;
  border-radius: 10px;
  overflow: hidden;
  background: linear-gradient(90deg, #121214, #3a3a3f 45%, #1a1a1d);
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.1);
}
#roller .knob.left { left: -52px; }
#roller .knob.right { right: -52px; }
/* Ridges that roll past as the knob turns, line by line. */
#roller .knob i {
  position: absolute;
  left: -14px;
  top: -14px;
  width: 72px;
  height: 100px;
  background: repeating-linear-gradient(180deg, rgba(255, 255, 255, 0.07) 0 2px, transparent 2px 7px);
  transform-origin: 50% 50%;
}

#tape {
  position: absolute;
  top: 14px;
  height: 9px;
  background: linear-gradient(180deg, #151515, #262626 50%, #101010);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.6);
  opacity: 0.92;
}
.spool {
  position: absolute;
  top: -12px;
  width: 64px;
  height: 64px;
  margin-left: -32px;
  border-radius: 50%;
  background: radial-gradient(circle, #2a2a2a 0 34%, #161616 35% 62%, #6e6f74 63% 66%, #44454a 67% 100%);
  box-shadow: 0 6px 12px rgba(0, 0, 0, 0.55);
}
.spool .hub {
  position: absolute;
  inset: 14px;
  border-radius: 50%;
  background: conic-gradient(#8b8d93 0 12%, #4a4b50 12% 33%, #8b8d93 33% 45%, #4a4b50 45% 66%, #8b8d93 66% 78%, #4a4b50 78% 100%);
  -webkit-mask: radial-gradient(circle, transparent 0 22%, #000 23%);
  mask: radial-gradient(circle, transparent 0 22%, #000 23%);
  transition: transform 90ms ease-out;
}

/* The ribbon fork: black half on top, red half below. It rests just below
   the line and lifts on each strike (higher for red). */
#vibrator {
  --band: 15px;
  position: absolute;
  top: 9px;
  height: calc(var(--band) * 2);
  border-radius: 2px;
  background: linear-gradient(180deg, #121212 0 50%, #7d1d17 50% 100%);
  box-shadow: 0 0 0 1.5px #8b8d93, 0 3px 6px rgba(0, 0, 0, 0.5);
  will-change: transform;
}

#segment {
  position: absolute;
  border-radius: 50%;
  border: 9px solid #3d3e43;
  box-shadow: inset 0 2px 0 rgba(255, 255, 255, 0.06), 0 2px 4px rgba(0, 0, 0, 0.5);
  background: radial-gradient(circle, rgba(0, 0, 0, 0.38), rgba(0, 0, 0, 0.12) 70%, transparent 71%);
}
#typebars { position: absolute; inset: 0; }
#typebars .bar {
  position: absolute;
  width: 3px;
  transform-origin: 50% 100%;
  background: linear-gradient(90deg, #4c4d52, #a3a5ab 50%, #45464b);
  border-radius: 1.5px;
  will-change: transform;
}
/* The type slug on the end of each arm */
#typebars .bar::before {
  content: '';
  position: absolute;
  left: -2.5px;
  top: 0;
  width: 8px;
  height: 11px;
  border-radius: 1.5px;
  background: linear-gradient(90deg, #5b5c61, #c2c4ca 50%, #55565b);
}

/* Reading back: the whole machine slides down out of the way (as before). */
body.reading #typebars .bar { transition: none; }

/* The option only applies to the classic desk. */
.machine-hint { display: none; margin: 0 0 4px 26px; }
body.machine-unavailable .machine-hint { display: block; }
body.machine-unavailable .machine-toggle { opacity: 0.5; cursor: default; }

/* ---------------------------------------------------------------- UI chrome */

.ui {
  position: fixed;
  top: 18px;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 14px;
}
.ui-top-left { left: 20px; }
.ui-top-right { right: 22px; font-family: var(--font-ui); font-size: 14px; color: rgba(255, 240, 225, 0.55); letter-spacing: 0.04em; }

.ui-btn {
  font-family: var(--font-ui);
  font-size: 15px;
  letter-spacing: 0.05em;
  color: var(--ui-fg);
  background: rgba(20, 16, 14, 0.55);
  border: 1px solid rgba(255, 240, 225, 0.16);
  border-radius: 999px;
  padding: 9px 18px;
  cursor: pointer;
  text-decoration: none;
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  transition: border-color 0.2s, background-color 0.2s, opacity 0.2s;
}
.ui-btn:hover { border-color: var(--ui-accent); }
.ui-btn.wide { display: block; width: 100%; text-align: center; background: var(--ui-surface); border-color: var(--ui-line); }
:focus-visible { outline: 2px solid var(--ui-accent); outline-offset: 3px; }

.ui-stack {
  display: flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-ui);
  font-size: 14px;
  letter-spacing: 0.04em;
  color: rgba(255, 240, 225, 0.6);
  background: none;
  border: 0;
  padding: 6px 4px;
  cursor: pointer;
}
.ui-stack:hover { color: var(--ui-fg); }
.ui-stack[hidden] { display: none; }
.pile { position: relative; width: 18px; height: 22px; }
.pile i {
  position: absolute;
  inset: 0;
  background: var(--paper);
  border-radius: 1px;
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.4);
}
.pile i:nth-child(1) { transform: rotate(-7deg) translate(-2px, 1px); opacity: 0.75; }
.pile i:nth-child(2) { transform: rotate(4deg) translate(1px, 0); opacity: 0.85; }

#status { opacity: 0; }
#status.show { animation: status 1.8s ease forwards; }
@keyframes status {
  0%, 60% { opacity: 1; }
  100% { opacity: 0; }
}

/* ---------------------------------------------------------------- words, audio */

/* Word count: barely there until you point at it. */
#words {
  opacity: 0.3;
  transition: opacity 250ms ease, color 250ms ease;
  cursor: default;
  padding: 6px 2px;
}
#words:hover { opacity: 1; color: var(--ui-fg); }

.audio { display: flex; align-items: center; gap: 8px; }
.icon-toggle {
  display: grid;
  place-items: center;
  width: 32px;
  height: 32px;
  padding: 0;
  color: currentColor;
  background: none;
  border: 0;
  border-radius: 50%;
  cursor: pointer;
  opacity: 0.8;
}
.icon-toggle:hover { opacity: 1; }
.icon-toggle .cross { display: none; }
.icon-toggle.silent .waves { display: none; }
.icon-toggle.silent .cross { display: inline; }

#volume {
  --fill: 80%;
  -webkit-appearance: none;
  appearance: none;
  width: 84px;
  height: 18px;
  background: none;
  cursor: pointer;
  opacity: 0.7;
  transition: opacity 200ms ease;
}
#volume:hover, #volume:focus-visible { opacity: 1; }
#volume::-webkit-slider-runnable-track {
  height: 2px;
  border-radius: 2px;
  background: linear-gradient(90deg, currentColor var(--fill), rgba(128, 128, 128, 0.35) var(--fill));
}
#volume::-moz-range-track { height: 2px; border-radius: 2px; background: rgba(128, 128, 128, 0.35); }
#volume::-moz-range-progress { height: 2px; border-radius: 2px; background: currentColor; }
#volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 10px;
  height: 10px;
  margin-top: -4px;
  border-radius: 50%;
  background: currentColor;
  border: 0;
}
#volume::-moz-range-thumb { width: 10px; height: 10px; border-radius: 50%; background: currentColor; border: 0; }

/* ---------------------------------------------------------------- ribbon */

.ribbon-toggle {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  padding: 0;
  border-radius: 50%;
  border: 1px solid rgba(255, 240, 225, 0.16);
  background: rgba(20, 16, 14, 0.55);
  cursor: pointer;
}
.ribbon-toggle i {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  /* a two-colour ribbon: the half in use is on top */
  background: linear-gradient(180deg, #1d1b1a 0 50%, #a62820 50% 100%);
  box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.25);
  transition: transform 250ms ease;
}
.ribbon-toggle.red i { transform: rotate(180deg); }
.ribbon-toggle:hover { border-color: var(--ui-accent); }
body.theme-minimal .ribbon-toggle { background: rgba(255, 255, 255, 0.75); border-color: var(--ui-line); }
body.theme-minimal .ribbon-toggle i { background: linear-gradient(180deg, #55575c 0 50%, #b2584f 50% 100%); box-shadow: none; }

.ribbon-row { display: flex; align-items: center; justify-content: space-between; gap: 10px; padding: 6px 0 2px; }
#ribbon-ink { font-size: 13px; color: var(--ui-muted); letter-spacing: 0.04em; }

/* ---------------------------------------------------------------- feed the paper in */

.feed-in {
  position: fixed;
  z-index: 4;
  left: 50%;
  top: calc(var(--strike-y) - 150px);
  transform: translateX(-50%);
  font-family: var(--font-ui);
  font-size: 17px;
  letter-spacing: 0.12em;
  color: rgba(255, 240, 225, 0.8);
  background: none;
  border: 0;
  padding: 14px 22px;
  cursor: pointer;
  animation: feed-breathe 2.6s ease-in-out infinite;
}
.feed-in[hidden] { display: none; }
@keyframes feed-breathe {
  0%, 100% { opacity: 0.9; }
  50% { opacity: 0.45; }
}
body.unfed .sheet { opacity: 0; }
body.unfed #cursor, body.unfed #glow { opacity: 0; }
#cursor, #glow { transition: opacity 600ms ease; }
body.theme-minimal .feed-in { color: #7a7e85; }

/* ---------------------------------------------------------------- drawer */

#drawer {
  position: fixed;
  top: 0;
  left: 0;
  bottom: 0;
  z-index: 10;
  width: 360px;
  display: flex;
  flex-direction: column;
  gap: 16px;
  padding: 22px 22px 18px;
  background: var(--ui-bg);
  border-right: 1px solid var(--ui-line);
  box-shadow: 20px 0 60px rgba(0, 0, 0, 0.45);
  color: var(--ui-fg);
  font-family: var(--font-ui);
  overflow-y: auto;
  transform: translateX(-102%);
  transition: transform 320ms cubic-bezier(0.2, 0.7, 0.2, 1);
}
#drawer.open { transform: none; }

.drawer-head { display: flex; align-items: center; justify-content: space-between; }
.mark { font-family: var(--font-ui); font-weight: 400; font-size: 30px; letter-spacing: 0.04em; margin: 0; }
.icon-btn {
  font-family: var(--font-body);
  font-size: 26px;
  line-height: 1;
  color: var(--ui-muted);
  background: none;
  border: 0;
  cursor: pointer;
  padding: 4px 8px;
}
.icon-btn:hover { color: var(--ui-fg); }

#note-list { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 4px; }
.note { border-radius: 12px; }
.note.active { background: var(--ui-surface); }
.note-open {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  width: 100%;
  padding: 10px 12px;
  background: none;
  border: 0;
  border-radius: 12px;
  color: var(--ui-fg);
  font-family: var(--font-ui);
  font-size: 16px;
  text-align: left;
  cursor: pointer;
}
.note-open:hover { background: rgba(255, 255, 255, 0.04); }
.note-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.note-date { flex: none; font-size: 12px; color: var(--ui-dim); letter-spacing: 0.04em; }
.note-actions { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; padding: 0 10px 10px; }
.chip {
  font-family: var(--font-ui);
  font-size: 13px;
  letter-spacing: 0.04em;
  color: var(--ui-muted);
  background: none;
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  padding: 5px 11px;
  cursor: pointer;
}
.chip:hover { color: var(--ui-fg); border-color: var(--ui-accent); }
.chip.danger:hover { border-color: var(--ui-danger); color: var(--ui-danger); }
.confirm-text { font-size: 13px; color: var(--ui-muted); margin-right: 4px; }
.rename {
  width: 100%;
  font-family: var(--font-ui);
  font-size: 16px;
  color: var(--ui-fg);
  background: oklch(0.13 0.008 260);
  border: 1px solid var(--ui-accent);
  border-radius: 10px;
  padding: 9px 11px;
}

.settings { margin-top: 8px; padding-top: 16px; border-top: 1px solid var(--ui-line); }
.settings h2 { font-family: var(--font-ui); font-weight: 400; font-size: 18px; letter-spacing: 0.06em; margin: 0 0 10px; color: var(--ui-muted); }
.settings fieldset { border: 0; margin: 0 0 12px; padding: 0; }
.settings legend { font-size: 12px; letter-spacing: 0.22em; text-transform: uppercase; color: var(--ui-accent); margin-bottom: 6px; padding: 0; }
.settings label { display: flex; align-items: center; gap: 10px; font-size: 15px; padding: 5px 0; cursor: pointer; color: var(--ui-fg); }
.settings input { accent-color: var(--ui-accent); margin: 0; }
.hint { font-family: var(--font-body); font-size: 12px; line-height: 1.5; color: var(--ui-dim); margin: 6px 0 0; }
.drawer-foot { margin-top: auto; font-size: 13px; letter-spacing: 0.3em; text-transform: uppercase; }
.drawer-foot a { color: var(--ui-dim); text-decoration: none; }
.drawer-foot a:hover { color: var(--ui-fg); }

/* ---------------------------------------------------------------- keyboard needed */

.card-wrap {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  align-items: center;
  justify-content: center;
  padding: 24px 16px;
  background:
    radial-gradient(ellipse 80% 60% at 50% 40%, rgba(255, 214, 160, 0.1), transparent 70%),
    linear-gradient(180deg, var(--desk-1), var(--desk-3));
}
.card {
  max-width: 380px;
  width: 100%;
  text-align: center;
  padding: 36px 28px;
  background: var(--ui-bg);
  border: 1px solid var(--ui-line);
  border-radius: 20px;
}
.card p { font-family: var(--font-ui); font-size: 18px; line-height: 1.45; color: var(--ui-muted); margin: 14px 0 24px; }
.card .ui-btn { display: inline-block; }

body.no-keyboard .card-wrap { display: flex; }
body.no-keyboard #stage,
body.no-keyboard .ui,
body.no-keyboard #drawer { display: none; }

/* ---------------------------------------------------------------- reduced motion */

@media (prefers-reduced-motion: reduce) {
  #carriage, #feed, #machine, #drawer { transition: none !important; }
  .ribbon-toggle i { transition: none; }
  .feed-in { animation: none; }
  .sheet.off { transition: none; }
}

/* ---------------------------------------------------------------- minimal theme */
/* Soft white page, no desk or machine. A thin rule runs across the screen;
   a T caret and a small white pill ride along it, with a warm glow rising
   from the next letter like a desk lamp. */

#glow, #rule, #cursor { display: none; }

body.theme-minimal {
  --paper: transparent;
  --ink: #55575c;
  --ui-bg: rgba(250, 250, 251, 0.97);
  --ui-surface: #eff0f2;
  --ui-line: #e2e3e6;
  --ui-fg: #2b2e34;
  --ui-muted: #6f737a;
  --ui-dim: #9a9ea5;
  --ui-accent: #8a9bb0;
  --ui-danger: #b0655a;
  background: #f4f5f7;
}
body.theme-minimal #stage {
  background: radial-gradient(ellipse 120% 90% at 50% 40%, #f7f8f9 0%, #f0f1f4 70%, #e9ebee 100%);
}
body.theme-minimal #machine,
body.theme-minimal #bell { display: none; }
body.theme-minimal .sheet { box-shadow: none; background: transparent; }
/* Earlier sheets read back as separate pages, divided by a hairline. */
body.theme-minimal.reading .sheet { box-shadow: 0 -1px 0 #dfe1e5; }
body.theme-minimal .ch { letter-spacing: 0.02em; }

/* The line the type sits on */
body.theme-minimal #rule {
  display: block;
  position: absolute;
  left: 0;
  right: 0;
  top: calc(var(--strike-y) + 6px);
  height: 1.5px;
  background: #3f4246;
  box-shadow: 0 1px 0 rgba(255, 255, 255, 0.9), 0 2px 6px rgba(0, 0, 0, 0.06);
  opacity: 0.85;
  transition: opacity 400ms ease;
}

/* Caret group: positioned at x = 0 and moved with transform by main.js */
body.theme-minimal #cursor {
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  will-change: transform;
}
#tee {
  position: absolute;
  left: calc(var(--cell-w) * -0.3);
  top: calc(var(--strike-y) - var(--line-h) * 0.82);
  width: calc(var(--cell-w) * 0.6);
  height: calc(var(--line-h) * 0.82 + 2px);
}
#tee::before, #tee::after {
  content: '';
  position: absolute;
  background: #3a3c40;
  border-radius: 1px;
}
#tee::before { left: 0; right: 0; top: 0; height: 1.5px; }               /* crossbar */
#tee::after { left: calc(50% - 0.75px); width: 1.5px; top: 0; bottom: 0; } /* stem */
#tee.flash { animation: tee-nudge 400ms ease; }
@keyframes tee-nudge {
  50% { opacity: 0.15; }
}

#cursor .pill {
  position: absolute;
  left: -22px;
  top: calc(var(--strike-y) + 6.75px - 8px);
  width: 44px;
  height: 16px;
  border-radius: 999px;
  background: linear-gradient(180deg, #ffffff, #f3f4f6);
  box-shadow:
    0 0 0 0.5px rgba(0, 0, 0, 0.08),
    0 1px 2px rgba(0, 0, 0, 0.12),
    0 3px 10px rgba(0, 0, 0, 0.08);
}
#cursor .pill i {
  position: absolute;
  top: 6.75px;
  width: 2.5px;
  height: 2.5px;
  border-radius: 50%;
  background: #b4b7bd;
}
#cursor .pill i:nth-child(1) { left: 10px; }
#cursor .pill i:nth-child(2) { left: 15px; }

/* Warm lamp glow rising from the caret */
body.theme-minimal #glow {
  display: block;
  position: absolute;
  left: 0;
  top: 0;
  width: 0;
  height: 0;
  pointer-events: none;
  will-change: transform;
}
#glow::before {
  content: '';
  position: absolute;
  left: -380px;
  width: 760px;
  top: calc(var(--strike-y) + 6px - 560px);
  height: 560px;
  background:
    radial-gradient(ellipse 30% 58% at 50% 100%, rgba(255, 228, 170, 0.95), rgba(255, 236, 198, 0.5) 45%, rgba(255, 246, 228, 0) 100%),
    radial-gradient(ellipse 60% 85% at 50% 100%, rgba(255, 250, 238, 0.7), rgba(255, 250, 238, 0) 70%);
  opacity: 0.8;
  transition: opacity 900ms ease;
}
body.theme-minimal.typing #glow::before { opacity: 1; transition-duration: 300ms; }

body.theme-minimal.reading #cursor,
body.theme-minimal.reading #glow { opacity: 0; transition: opacity 300ms ease; }
body.theme-minimal.reading #rule { opacity: 0; }

body.theme-minimal .ui-top-right { color: var(--ui-dim); }
body.theme-minimal .ui-btn {
  color: var(--ui-muted);
  background: rgba(255, 255, 255, 0.75);
  border-color: var(--ui-line);
}
body.theme-minimal .ui-btn:hover { color: var(--ui-fg); border-color: var(--ui-accent); }
body.theme-minimal .ui-stack { color: var(--ui-dim); }
body.theme-minimal .ui-stack:hover { color: var(--ui-fg); }
body.theme-minimal .pile i { box-shadow: 0 0 0 1px #dcdde0; background: #fff; }
body.theme-minimal #drawer { box-shadow: none; }
body.theme-minimal #drawer.open { box-shadow: 12px 0 40px rgba(0, 0, 0, 0.06); }
body.theme-minimal .note-open:hover { background: rgba(0, 0, 0, 0.03); }
body.theme-minimal .rename { background: #ffffff; }

@media (prefers-reduced-motion: reduce) {
  #glow::before { transition: none; }
}

/* Paper types on the white page: gentler versions of each. */
body.theme-minimal.paper-lined .stock::before {
  background: repeating-linear-gradient(180deg,
    transparent 0 calc(var(--line-h) - 4px),
    rgba(120, 140, 175, 0.22) calc(var(--line-h) - 4px) calc(var(--line-h) - 3px),
    transparent calc(var(--line-h) - 3px) var(--line-h));
}
body.theme-minimal.paper-lined .stock::after { background: rgba(200, 120, 115, 0.25); box-shadow: none; }
body.theme-minimal.paper-onionskin .sheet { background: rgba(255, 253, 247, 0.6); box-shadow: 0 0 0 0.5px rgba(0, 0, 0, 0.05); }
body.theme-minimal.paper-carbon .ch,
body.theme-minimal.paper-carbon .ch.red { --ink-rgb: 92, 104, 160; --wet-rgb: 62, 74, 135; }
body.theme-minimal.paper-carbon .stock { opacity: 0.6; }
body.theme-minimal.paper-onionskin,
body.theme-minimal.paper-carbon { --gap: #f4f5f7; }
