/* WiWiW stylesheet. Colours (background and text) are set by app.js on <body>. */

/* ---------- Fonts (self-hosted, open licence) ---------- */
@font-face { font-family: "Newsreader"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("fonts/newsreader-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Newsreader"; font-style: italic; font-weight: 400; font-display: swap;
  src: url("fonts/newsreader-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Newsreader"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("fonts/newsreader-latin-700-normal.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-style: normal; font-weight: 400; font-display: swap;
  src: url("fonts/source-serif-4-latin-400-normal.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-style: italic; font-weight: 400; font-display: swap;
  src: url("fonts/source-serif-4-latin-400-italic.woff2") format("woff2"); }
@font-face { font-family: "Source Serif 4"; font-style: normal; font-weight: 700; font-display: swap;
  src: url("fonts/source-serif-4-latin-700-normal.woff2") format("woff2"); }

/* Font choice (temporary comparison: body class toggled by app.js) */
.font-newsreader { --font: "Newsreader", Georgia, "Times New Roman", serif; }
.font-source     { --font: "Source Serif 4", Georgia, "Times New Roman", serif; }

/* ---------- Base ---------- */
* { box-sizing: border-box; }
html { height: 100%; }
body {
  margin: 0;
  min-height: 100vh; min-height: 100dvh;
  display: flex; flex-direction: column;
  font-family: var(--font);
  background-color: #fff;  /* replaced at once by app.js */
  color: #000;
  /* background-color and color transitions are enabled by app.js (class "morph") */
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}
body.morph {
  transition: background-color var(--morph, 1400ms) ease, color var(--morph, 1400ms) ease;
}

/* ---------- Word entry ---------- */
.stage { flex: 1; display: flex; align-items: center; justify-content: center; padding: 1.5rem var(--fit-margin, 5vw); overflow-x: clip; }
.group { width: 100%; position: relative; }
.entry {
  cursor: pointer; width: 100%; text-align: center;
  padding: 0.9rem 0 2.5rem; border-radius: 6px; user-select: none; -webkit-tap-highlight-color: transparent;
  transition: opacity 260ms ease;
}
/* First-load hint under the word (sits in the entry's bottom padding, so nothing moves when it goes) */
.hint {
  position: absolute; left: 0; right: 0; top: 100%; margin: -0.8rem auto 0; max-width: 34rem;
  text-align: center; font-style: italic; font-size: clamp(0.9rem, 2vw, 1.05rem); line-height: 1.4;
  pointer-events: none; opacity: 1; transition: opacity 600ms ease;
}
.hint span { display: inline-block; }  /* if the line has to wrap, it breaks at the comma, not mid-phrase */
.hint.gone { opacity: 0; }
body.about-open .hint { display: none; }
@media print { .hint { display: none; } }
.entry:focus-visible { outline: 2px solid currentColor; outline-offset: 6px; }
.entry.fading { opacity: 0; }
/* The site name above the entry: full on load, then one word that alternates with each click */
.title-row { display: flex; justify-content: center; margin-bottom: 0.2rem; }
.title-line {
  all: unset; cursor: pointer; box-sizing: border-box; flex-shrink: 0;
  display: flex; align-items: baseline;
  padding: 0.35rem 0.6rem; min-height: 1.5em;
  font-family: var(--font); font-size: clamp(1rem, 2.3vw, 1.3rem); letter-spacing: 0.03em; line-height: 1.5;
  transition: opacity 260ms ease;
}
.title-line.fading { opacity: 0; }
.title-line:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
/* Each word of the title. The bold core is "Words in Words in Words"; the extras run on
   off-screen both sides in regular type at half strength. */
.tw { display: block; white-space: pre; font-weight: 700; transition: opacity 500ms ease; }
.tw + .tw { margin-left: 0.32em; }
.tw.ex { font-weight: 400; opacity: 0.5; }
.tw.ex::before { content: attr(data-t); }  /* the faint extras are generated content: decoration, not text */
/* A thin rule under each bold title word, like the running head of a vintage dictionary page.
   For a broadsheet-style double rule instead, use: border-bottom: 3px double currentColor; */
.tw:not(.ex) { padding-bottom: 0.12em; border-bottom: 1px solid currentColor; }
.original {
  font-style: italic; font-weight: 400;
  font-size: clamp(1.05rem, 2.6vw, 1.55rem);
  letter-spacing: 0.02em; margin-bottom: 0.6rem; opacity: var(--soft85, 0.85); transition: opacity var(--morph, 1400ms) ease;
}
.split {
  font-weight: 700; line-height: 1.08;
  font-size: clamp(2rem, 9.5vw, 6.2rem);
  white-space: nowrap; letter-spacing: -0.01em;
}
.split .dot { display: inline-block; font-weight: 400; margin: 0 0.07em; opacity: 0.7; }
.note {
  margin: 1.6rem auto 0; max-width: 34rem; font-size: clamp(1rem, 2.2vw, 1.25rem);
  line-height: 1.5; font-weight: 400; text-align: center;
}

/* ---------- About (replaces the entry, below the title) ---------- */
/* Laid out like a dictionary entry: a small italic label (as the original word is on an entry),
   then numbered senses with a hanging number, left-aligned. */
.about { max-width: 38rem; margin: 1.2rem auto 0; padding: 0.9rem 0 1rem; font-size: clamp(1.05rem, 2.2vw, 1.2rem); line-height: 1.55;
  transition: opacity 500ms ease; }
.about[hidden] { display: none; }
.about.hold, .entry.hold { opacity: 0; transition: none; }  /* waiting for the title to clear the space */
.about-head { font-style: italic; font-size: clamp(1.05rem, 2.6vw, 1.55rem); letter-spacing: 0.02em; opacity: var(--soft85, 0.85); transition: opacity var(--morph, 1400ms) ease;
  margin-bottom: 0.7rem; padding-bottom: 0.4rem; border-bottom: 1px solid currentColor; }
.about p { margin: 0 0 0.8rem; display: grid; grid-template-columns: 1.8rem 1fr; text-align: left; hyphens: auto; }
.about .sense { font-weight: 700; }
.close {
  all: unset; cursor: pointer; margin-top: 0.8rem; padding: 0.4rem 0.9rem;
  border: 1px solid currentColor; border-radius: 3px; font-family: var(--font); font-size: 0.95rem; letter-spacing: 0.06em;
}
.close:focus-visible { outline: 2px solid currentColor; outline-offset: 3px; }
body.about-open .entry { display: none; }

@media (prefers-reduced-motion: reduce) { .tw { transition: none; } }

/* ---------- Utility ---------- */
.sr-only { position: absolute; width: 1px; height: 1px; margin: -1px; padding: 0; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; }
.nojs { text-align: center; padding: 2rem; }

/* ---------- How? page (how.html): a dictionary-style page of infographics ---------- */
.how { width: 100%; max-width: 40rem; margin: 0 auto; padding: 2rem 1rem 3rem; font-size: clamp(1.05rem, 2.2vw, 1.2rem); line-height: 1.55; }
.how-back { color: inherit; font-style: italic; text-decoration: none; border-bottom: 1px solid currentColor; letter-spacing: 0.02em; }
/* A link underlined word by word (as in the title) rather than as one line: each word is a span */
.how-back.words { border-bottom: none; }
.how-back.words span { border-bottom: 1px solid currentColor; padding-bottom: 0.12em; }
.how-back:focus-visible { outline: 2px solid currentColor; outline-offset: 4px; }
.how-back.foot { display: inline-block; margin-top: 2.5rem; }
.how-title { font-style: italic; font-weight: 400; font-size: clamp(1.6rem, 5vw, 2.4rem); margin: 2rem 0 0.4rem; padding-bottom: 0.4rem; border-bottom: 1px solid currentColor; }
.how-lead { margin: 0 0 1.5rem; }
.how-sec { margin-top: 2.2rem; }
.how-sec h2 { font-size: 1.15em; font-weight: 700; margin: 0 0 0.5rem; }
.how-sec p { margin: 0 0 0.9rem; }
.how .sense { margin-right: 0.3em; }
.note-small { font-size: 0.85em; font-style: italic; opacity: var(--soft80, 0.8); transition: opacity var(--morph, 1400ms) ease; }

/* Bar charts: label and number on one line, the bar underneath. Bars are drawn to scale (--w is a percentage). */
.bars { margin: 1rem 0 0.5rem; }
.bars .row { display: grid; grid-template-columns: 1fr auto; column-gap: 1rem; margin-bottom: 0.75rem; }
.bars .val { font-weight: 700; font-variant-numeric: tabular-nums; }
.bars .track { grid-column: 1 / -1; display: block; height: 0.85rem; }
.bars .track i { display: block; height: 100%; width: calc(var(--w) * 1%); min-width: 3px; background: currentColor; transform-origin: left; animation: grow 900ms cubic-bezier(0.22, 1, 0.36, 1) both; }
.bars .row.final .lab { font-weight: 700; }
.bars.slim .row { margin-bottom: 0.45rem; }
.bars.slim .track { height: 0.55rem; }
.bars.slim .track i { opacity: 0.8; }
@keyframes grow { from { transform: scaleX(0); } }

/* Stacked bars and their key: tones of the text colour only */
.stack { display: flex; gap: 2px; height: 2.2rem; margin: 1rem 0 0.8rem; }
.seg { flex: var(--v) 1 0; background: currentColor; transform-origin: left; animation: grow 900ms cubic-bezier(0.22, 1, 0.36, 1) both; }
.s1 { opacity: 1; } .s2 { opacity: 0.6; } .s3 { opacity: 0.3; } .s4 { opacity: 0.15; }
.key { list-style: none; margin: 0 0 1rem; padding: 0; font-size: 0.95em; }
.key li { display: grid; grid-template-columns: 1.1rem 1fr; column-gap: 0.6rem; margin-bottom: 0.3rem; align-items: baseline; }
.sw { display: block; width: 0.9rem; height: 0.9rem; background: currentColor; }
@media (prefers-reduced-motion: reduce) { .bars .track i, .seg { animation: none; } }

/* About: buttons on the left (Close) and right (How?) */
.about-actions { display: flex; justify-content: space-between; align-items: center; margin-top: 0.8rem; }
.about-actions .close { margin-top: 0; }
.about-actions a.close { text-decoration: none; color: inherit; display: inline-block; }
.how-sec .when { margin: -0.2rem 0 0.6rem; font-size: 0.85em; font-style: italic; opacity: var(--soft80, 0.8); transition: opacity var(--morph, 1400ms) ease; letter-spacing: 0.02em; }

/* Larger tap areas for links without changing how they look (an invisible extension, about 48px tall) */
.how-back { position: relative; }
.how-back::after { content: ""; position: absolute; inset: -12px -8px; }
.about-actions a.close { position: relative; }
.about-actions a.close::after { content: ""; position: absolute; inset: -5px; }

/* Switching between the word page and How? (one page, so the colour morph carries straight on): the view
   fades out (.page-out), then the other is shown and fades in by this animation. Same 500 ms ease as the other fades. */
@keyframes pagein { from { opacity: 0; } to { opacity: 1; } }
.stage, .how { animation: pagein 500ms ease; }
.stage.page-out, .how.page-out { opacity: 0; transition: opacity 500ms ease; pointer-events: none; }
body.how-open .stage { display: none; }
@media (prefers-reduced-motion: reduce) { .stage, .how { animation: none; } }

/* ---------- Print: black on white, no coloured backgrounds, no motion ---------- */
@media print {
  @page { margin: 18mm 16mm; }
  html, body { background: #fff !important; color: #000 !important; }
  *, *::before, *::after { animation: none !important; transition: none !important; }
  .stage, .how { opacity: 1 !important; }
  .how { max-width: none; padding: 0; font-size: 11pt; line-height: 1.5; }
  /* Softened text prints at full strength, and the page links (no use on paper) are left out */
  .note-small, .how-sec .when, .original, .about-head { opacity: 1 !important; }
  .how-back { display: none !important; }
  /* The charts are drawn with backgrounds, which browsers leave out of print unless asked to keep them */
  .bars .track i, .seg, .sw { background: #000 !important; -webkit-print-color-adjust: exact; print-color-adjust: exact; }
  /* Keep each heading, its date line, its intro and its chart together rather than stranding the intro at the foot of a page */
  .how-sec h2, .how-sec .when, .how-sec p:has(+ .bars), .how-sec p:has(+ .stack), .stack { break-after: avoid; }
  .how-sec p { orphans: 3; widows: 3; }
  .how-sec p:has(+ .bars), .how-sec p:has(+ .stack) { break-inside: avoid; }
  .bars, .stack, .key { break-inside: avoid; }
  .how::after { content: "wiwiw.uk/#how"; display: block; margin-top: 2rem; font-style: italic; font-size: 0.85em; }
}
