:root {
  /* Follows the system; the header toggle pins it via data-theme. */
  color-scheme: light dark;
  --fg: light-dark(#111, #e4e0d6);
  --bg: light-dark(#fbfaf6, #161512);
  --dim: light-dark(#8a8780, #7d7a72);
  --line: light-dark(#d9d6cc, #34322c);
  --accent: light-dark(#c8102e, #ff4d5e);     /* the one colour: change */
  --bar: light-dark(#111, #3a3833);
  --ink: light-dark(#3b4a6b, #8fa3cc);        /* Mom's hand */
  --head: 52px;         /* sticky header height; the right column pins below it */
  --serif: Georgia, "Iowan Old Style", "Times New Roman", serif;
  --mono: ui-monospace, "SF Mono", Menlo, Consolas, monospace;
  --hand: "Bradley Hand", "Segoe Print", "Chalkboard SE", "Comic Neue", cursive;
}

:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="dark"] { color-scheme: dark; }

* { box-sizing: border-box; }
html { touch-action: manipulation; }
[hidden] { display: none !important; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font: 14px/1.55 var(--mono);
}

main { max-width: 1180px; margin: 0 auto; padding: 8px 24px 40px; }

header {
  display: flex; justify-content: space-between; align-items: center;
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  height: var(--head); margin-bottom: 4px;
}
h1 { font: italic 18px var(--serif); margin: 0; }
h2 { font-size: 12px; font-weight: normal; letter-spacing: 0.12em; margin: 0 0 12px; padding-bottom: 4px; border-bottom: 1px solid var(--fg); }
#diffLabel { margin-left: 1em; letter-spacing: 0; }
.dim { color: var(--dim); }

button {
  font: inherit; color: var(--fg); background: transparent;
  border: 1px solid var(--fg); padding: 2px 10px; cursor: pointer;
}
button:hover:not(:disabled) { background: var(--fg); color: var(--bg); }
button:disabled { color: var(--dim); border-color: var(--line); cursor: default; }
#close { margin-left: 16px; }
#theme { border: none; padding: 0 4px; margin-left: 8px; color: var(--dim); }
#theme:hover:not(:disabled) { background: none; color: var(--fg); }
#more, #strip { display: none; }
.link { border: none; padding: 0; text-decoration: underline; color: var(--dim); }
.link:hover:not(:disabled) { background: none; color: var(--fg); }

#cols { display: grid; grid-template-columns: 1fr 1fr; gap: 32px; }
#journal, aside { min-width: 0; }
#journal > h2 { position: sticky; top: var(--head); z-index: 4; background: var(--bg); }
aside {
  display: flex; flex-direction: column; gap: 24px;
  position: sticky; top: var(--head); align-self: start;
  max-height: calc(100vh - var(--head)); overflow-y: auto; padding: 0 0 12px;
}

/* ---- journal ---- */

#pages { font: 17px/1.7 var(--serif); }
article { margin-bottom: 26px; }
article .date { font: 12px var(--mono); color: var(--dim); margin-bottom: 2px; }
article p { margin: 0; }

.moment { text-decoration: underline; text-decoration-thickness: 1px; text-underline-offset: 3px; cursor: pointer; }
.moment:hover { color: var(--accent); }
.hand { font-family: var(--hand); font-size: 0.95em; }

/* Black bars: blackouts and words you can't read any more. */
.bar, .gone { background: var(--bar); color: transparent; user-select: none; }
.moment .bar { cursor: pointer; }
.moment:hover .bar { background: var(--accent); }
.fresh { animation: ink 1.6s ease-in; }
.fresh.slow { animation: ink 2.8s ease-in 1.4s both; }   /* jump 1: after the rewrite, while you're looking */
@keyframes ink { from { background: transparent; color: var(--fg); } }
.reveal { animation: reveal 1.8s ease-out; }
@keyframes reveal { from { background: var(--bar); color: transparent; } }

del, .del { color: var(--accent); text-decoration: line-through; }
.ins { color: var(--accent); }

/* ---- today ---- */

#todayText { margin: 0 0 16px; min-height: 8em; }
#todayText del { text-decoration: none; }
#todayText del.struck { text-decoration: line-through; }
#todayText .ins:empty { display: none; }
#todayText .caret::after { content: '▍'; color: var(--accent); }

#people { border-collapse: collapse; width: 100%; }
#people td { padding: 1px 12px 1px 0; white-space: nowrap; }
#people td:first-child { font-weight: bold; letter-spacing: 0.05em; }
#people td:nth-child(2) { color: var(--dim); }
#people .lost td:nth-child(3) { color: var(--dim); }
#people td:last-child { width: 1%; color: var(--accent); }

/* ---- log ---- */

#commits .row { display: block; width: 100%; text-align: left; border: none; padding: 1px 0; white-space: pre; overflow: hidden; text-overflow: ellipsis; }
#commits .row:hover { background: none; color: var(--accent); }
#commits .head { font-weight: bold; }
#commits .acts { padding: 2px 0 8px 4ch; display: flex; gap: 12px; }
#commits .up { color: var(--fg); }
#commits .down { color: var(--accent); }

/* ---- go there ---- */

#moment, #conflict, #ending {
  position: fixed; inset: 0; background: var(--bg); z-index: 10;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  overflow-y: auto; animation: fade 0.5s ease-out;
}
/* Auto margins centre when there's room and let a tall overlay scroll from its top when there isn't. */
#moment .inner, #conflict > div, #ending:not(.story) .inner, #intro .inner { margin-block: auto; }
@keyframes fade { from { opacity: 0; } }
#moment .inner { max-width: 520px; width: 100%; font: 18px/1.7 var(--serif); }
#moment .date { font: 12px var(--mono); color: var(--dim); margin-bottom: 18px; }
#moment p { margin: 0 0 14px; }
#moment .opts { display: flex; flex-direction: column; gap: 8px; margin: 26px 0 20px; }
#moment .opts button { text-align: left; font: 15px var(--mono); padding: 6px 12px; }
#moment .opts .was { font-size: 12px; margin-left: 1ch; }

#conflict { background: color-mix(in srgb, var(--bg) 94%, transparent); }
#conflict pre { font: 15px/1.6 var(--mono); margin: 0 0 16px; }
#conflict .marker { color: var(--accent); }

/* ---- endings ---- */

#ending .inner { max-width: 560px; width: 100%; }
#ending h3 { font: italic 22px var(--serif); font-weight: normal; margin: 0 0 24px; }
#ending table { margin-bottom: 20px; border-collapse: collapse; }
#ending td { padding: 1px 16px 1px 0; vertical-align: top; }
#ending td:first-child { color: var(--dim); }
#ending .again { margin-top: 28px; }

#ending.photo { background: #111; flex-direction: column; justify-content: safe center; animation: fade 3s ease-in; }
#ending.photo svg { width: min(92vw, 820px); height: auto; box-shadow: 0 0 60px rgba(0, 0, 0, 0.6); }
#ending.photo .caption { font: 18px var(--hand); color: #d8d2c4; margin-top: 18px; animation: fade 6s ease-in; }
#ending.photo .again { color: #777; border-color: #444; animation: fade 8s ease-in; }

/* ---- intro ---- */

#intro {
  position: fixed; inset: 0; background: var(--bg); z-index: 20; overflow-y: auto;
  display: flex; align-items: center; justify-content: center; padding: 24px;
  transition: opacity 1.2s ease;
}
#intro.out { opacity: 0; pointer-events: none; }
#intro .inner { max-width: 520px; width: 100%; font: 17px/1.7 var(--serif); animation: fade 1.5s ease-out; }
#intro h1 { font-size: 26px; margin: 0 0 28px; }
#intro p { margin: 0 0 12px; }
#intro .warning { font: 13px/1.6 var(--mono); color: var(--dim); border-left: 2px solid var(--accent); padding-left: 12px; margin-bottom: 28px; }
#intro .dim { font: 12px var(--mono); margin-top: 24px; }
#intro button { margin-top: 20px; font: 15px var(--mono); padding: 6px 14px; }

/* ---- dev ---- */

#dev { margin-top: 40px; border-top: 1px dashed var(--line); padding-top: 8px; font-size: 12px; }
#dev summary { cursor: pointer; color: var(--dim); }
#dev label { display: inline-block; margin: 4px 16px 4px 0; }
#dev select { font: inherit; }
#dev table { border-collapse: collapse; margin: 8px 0; }
#dev td { padding: 0 12px 0 0; }
#dev .row { margin: 8px 0; display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* ---- phones: the journal is the page; Today and the Log are a sheet at the bottom ---- */

@media (max-width: 800px) {
  main { padding: 0 16px calc(var(--strip, 48px) + 8px + env(safe-area-inset-bottom)); }
  #cols { grid-template-columns: 1fr; }

  #bar { display: flex; align-items: center; }
  #more { display: block; border: none; font-size: 20px; line-height: 1; padding: 8px 4px 8px 14px; }
  #more:hover:not(:disabled) { background: none; color: var(--fg); }
  #menu {
    display: none; position: absolute; top: var(--head); right: 0;
    flex-direction: column; align-items: flex-start; gap: 16px;
    padding: 16px; background: var(--bg); border: 1px solid var(--fg);
  }
  header.menu #menu { display: flex; animation: fade 0.15s ease-out; }
  #close { margin-left: 0; padding: 8px 12px; }
  #theme { margin-left: 0; padding: 4px 0; font-size: 18px; }
  #menu #langPick select { margin-left: 0; padding: 6px; }

  /* One fixed height, slid down so only the strip shows: opening is a slide, and Today rewriting doesn't move its edge. */
  aside {
    position: fixed; top: auto; left: 0; right: 0; bottom: 0; z-index: 6;
    height: 85dvh; max-height: none; overflow-y: hidden; overscroll-behavior: contain;
    gap: 24px; padding: 0 16px calc(24px + env(safe-area-inset-bottom));
    background: var(--bg); border-top: 1px solid var(--fg);
    transform: translateY(calc(100% - var(--strip, 48px) - env(safe-area-inset-bottom)));
    box-shadow: 0 0 0 100vmax transparent;
    transition: transform 0.45s cubic-bezier(0.32, 0.72, 0, 1), box-shadow 0.45s ease;
  }
  body.sheet aside { transform: none; overflow-y: auto; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.35); }

  #strip {
    display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 14px;
    position: sticky; top: 0; z-index: 1; width: 100%; padding: 14px 0;
    border: none; background: var(--bg); text-align: left; letter-spacing: 0.05em;
  }
  #strip:hover:not(:disabled) { background: var(--bg); color: var(--fg); }
  #strip .lost { color: var(--dim); }
  #strip .up, #strip .down { color: var(--accent); }
  #strip::after { content: '▴'; margin-left: auto; color: var(--dim); }
  body.sheet #strip::after { content: '▾'; }
  #todayText { min-height: 0; }
}

#moment.leaving { opacity: 0; transition: opacity 0.3s ease; }

@media (prefers-reduced-motion: reduce) {
  aside, #moment.leaving { transition: none !important; }
}

/* Fingers, not cursors. */
@media (pointer: coarse) {
  #commits .row { padding: 8px 0; }
  #commits .acts { gap: 20px; }
  #commits .acts .link { padding: 6px 0; }
  #moment .opts button { padding: 10px 12px; }
  #moment .link { padding: 8px 0; }
}

/* Hide the moment underline under blackout bars. */
.moment .bar { text-decoration: none; box-shadow: 0 2px 0 var(--bar); }

/* ---- strange ---- */

/* Mom's hand, in the margins. */
.note { font-family: var(--hand); font-size: 0.9em; color: var(--ink); }
#moment .odd { font-style: italic; }
#people .kit td { color: var(--dim); animation: flicker 7s infinite; }
@keyframes flicker { 0%, 92%, 100% { opacity: 1; } 94% { opacity: 0.2; } 96% { opacity: 0.8; } 97% { opacity: 0.1; } }
body[data-strange="5"] #pages article:last-child .date { color: var(--ink); }
.gone.note { color: transparent; }

/* ---- the back pages and clues ---- */

article.back { border-top: 1px dashed var(--line); padding-top: 14px; }
article.back p { font-family: var(--hand); font-size: 0.95em; }
#moment.strange { background: var(--bg); }

/* ---- thread endings: each has its own look ---- */

#ending.story { overflow-y: auto; align-items: flex-start; padding-top: 12vh; }
#ending.story .inner { max-width: 600px; width: 100%; font: 19px/1.75 var(--serif); animation: fade 1.2s ease-out; }
#ending.story p { margin: 0 0 18px; }
#ending.story .hand { font-family: var(--hand); }
#ending.story h3 { margin: 40px 0 8px; font: 13px var(--mono); letter-spacing: 0.3em; }
#ending.story .pager { display: flex; justify-content: space-between; align-items: center; margin-top: 30px; font: 12px var(--mono); }
#ending.story del { color: inherit; opacity: 0.55; }
#ending.story .ins { color: var(--accent); font-family: var(--hand); }
#ending.story button { color: inherit; border-color: currentColor; }
#ending.story button:hover { background: transparent; color: inherit; opacity: 0.6; }

.end-ship { background: radial-gradient(ellipse at 50% 120%, #1b2a44 0%, #070b14 70%) !important; color: #cfd8e6; }
.end-ship .dim { color: #6f7c93; }
.end-ship .ins { color: #f0b85a !important; }

.end-pen { background: var(--bg) !important; color: light-dark(#1a1712, #e8e0cf); }
.end-pen .inner { font-family: var(--serif); }
.end-pen p:first-letter { font-size: 1.1em; }

.end-atom { background: #000 !important; color: #e8e8e8; animation: dawn 30s ease-in forwards !important; }
@keyframes dawn { to { background: #1a1a1a; } }
.end-atom .inner { text-align: center; }
.end-atom .pager { justify-content: center !important; gap: 20px; }

.end-parasite { background: var(--bg) !important; color: light-dark(#20302a, #cfe0d6); }
.end-parasite .inner { font-family: var(--mono) !important; font-size: 16px !important; }
.end-parasite .hand { font-size: 20px; color: light-dark(#2d4a8a, #8fa8e0); }

.end-draft { background: var(--bg) !important; color: light-dark(#222, #ddd); }
.end-draft .inner { font-family: "Courier New", Courier, monospace !important; font-size: 17px !important; border-left: 2px solid light-dark(#e4b4b4, #6a3a3a); padding-left: 24px; }
.end-draft del { color: var(--accent) !important; opacity: 1 !important; }

/* ---- languages ---- */

#langPick select, #intro .lang select {
  font: 12px var(--mono); color: var(--dim); background: transparent; border: 1px solid var(--line); margin-left: 12px;
}
#intro .lang { margin-top: 28px; }
#intro .lang select:first-child { margin-left: 0; }

/* Faces that have the letters, where the defaults don't. Italic is left to the English. */
:lang(ru), :lang(kk) { --hand: "Segoe Print", "Comic Sans MS", cursive; }
:lang(zh-Hans) { --serif: "Songti SC", "Noto Serif SC", "SimSun", serif; --hand: "Kaiti SC", "STKaiti", "KaiTi", cursive; }
:lang(zh-Hant), :lang(yue) { --serif: "Songti TC", "Noto Serif TC", "PMingLiU", serif; --hand: "Kaiti TC", "BiauKai", "DFKai-SB", cursive; }
:lang(ja) { --serif: "Hiragino Mincho ProN", "Yu Mincho", "Noto Serif JP", serif; --hand: "Klee", "Yu Kyokasho", cursive; }
:lang(ko) { --serif: "AppleMyungjo", "Nanum Myeongjo", "Batang", serif; --hand: "Nanum Pen Script", "Nanum Pen", cursive; }
:lang(th) { --serif: "Sukhumvit Set", "Thonburi", "Tahoma", serif; --hand: "Chalkboard SE", cursive; }
:lang(zh-Hans) h1, :lang(zh-Hant) h1, :lang(yue) h1, :lang(ja) h1, :lang(ko) h1, :lang(th) h1,
:lang(zh-Hans) #ending h3, :lang(zh-Hant) #ending h3, :lang(yue) #ending h3, :lang(ja) #ending h3, :lang(ko) #ending h3, :lang(th) #ending h3,
:lang(zh-Hans) #moment .odd, :lang(zh-Hant) #moment .odd, :lang(yue) #moment .odd, :lang(ja) #moment .odd, :lang(ko) #moment .odd, :lang(th) #moment .odd { font-style: normal; }
