/* TypeSesame — the whole look is three colours (--bg, --ink, --glow) that app.js
   rewrites every frame as a weighted blend of the mood themes, plus a few
   weight-driven effects (vignette, jitter, light position, breathing halo,
   corner radius). Everything here just consumes those variables. */

:root {
  --bg: oklab(0.2 0 0);
  --ink: oklab(0.85 0 0);
  --glow: oklab(0.6 0 0);
  --vignette: 0;
  --light-x: 50%;
  --light-y: 30%;
  --light-a: 0.18;
  --breath: 0;        /* 0..1, pulses at a rate set by energy */
  --radius: 14px;     /* softens with cozy/romantic, sharpens with corporate */
  --slnt: 0;          /* slants when the writer is being ironic */
  --world-a: 0.6;     /* how much the street shows through; app.js follows daylight */
  --font: "Roboto Flex", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font);
  font-weight: 400;
  overflow: hidden; /* the textarea is the scroller, not the page */
  touch-action: manipulation; /* no double-tap zoom; pinch is off via the viewport meta */
  -webkit-font-smoothing: antialiased;
  font-variation-settings: "slnt" var(--slnt);
}

/* layers, back to front: world (or motes) → light → vignette → glass → page */
#world, #bg, #light, #vignette, #glass {
  position: fixed;
  inset: 0;
  pointer-events: none;
}
#world {
  z-index: 0;
  width: 100%;
  height: 100%;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  /* the street is a backdrop behind the room, not a scene the words fight:
     it shows through the room's dark colour, dimmer by day, fuller at night */
  opacity: var(--world-a, 0.6);
}
body.motes #world { display: none; }
#bg { z-index: 0; }
body:not(.motes) #bg { display: none; }
#glass { display: none; }
/* over the street, the words get a soft halo in the room's colour: invisible
   as a shape, but it lifts light type off a busy backdrop */
body:not(.motes) #mirror .line,
body:not(.motes) #mast,
body:not(.motes) .status,
body:not(.motes) #meters,
body:not(.motes) #controls,
body:not(.motes) .credit {
  text-shadow: 0 0 8px color-mix(in oklab, var(--bg) 90%, transparent),
               0 0 3px color-mix(in oklab, var(--bg) 90%, transparent),
               0 1px 1px color-mix(in oklab, var(--bg) 70%, transparent);
}
body.motes #glass { display: none; }
/* over the street, the words get a soft halo in the room's colour: invisible
   as a shape, but it lifts light type off a busy backdrop */
body:not(.motes) #mirror .line,
body:not(.motes) #mast,
body:not(.motes) .status,
body:not(.motes) #meters,
body:not(.motes) #controls,
body:not(.motes) .credit {
  text-shadow: 0 0 8px color-mix(in oklab, var(--bg) 90%, transparent),
               0 0 3px color-mix(in oklab, var(--bg) 90%, transparent),
               0 1px 1px color-mix(in oklab, var(--bg) 70%, transparent);
}
#light {
  z-index: 1;
  /* the room breathes: the light swells and settles with --breath */
  background: radial-gradient(60vmax circle at var(--light-x) var(--light-y),
    color-mix(in oklab, var(--glow) calc(var(--light-a) * (85% + var(--breath) * 25%)), transparent),
    transparent 70%);
}
#vignette {
  z-index: 2;
  opacity: var(--vignette);
  background: radial-gradient(ellipse at center, transparent 40%, oklab(0.05 0 0 / 0.9) 100%);
}

/* --- the open page -------------------------------------------------------
   #page is fixed and viewport-sized (the visual viewport on a phone). #entry
   is the real input and the scroller, with transparent text. #content is the
   visible page — header, then one element per line — translated to follow
   #entry's scrollTop. #measure is an offscreen twin used to find the caret.
   Entry, mirror and measure share the metrics in .page-text so wrapping is
   identical. Only width-neutral font axes vary per line (GRAD, YTLC, YOPQ,
   YTAS), so a typeset line still wraps exactly like the textarea. */
#page {
  position: fixed;
  inset: 0;
  z-index: 3;
  overflow: hidden;
  cursor: text;
  transform: translate(var(--jx, 0px), var(--jy, 0px));
}
#scroll {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
}
#content {
  position: relative;
  max-width: 44rem;
  margin: 0 auto;
  /* vertical padding is set by lines.js (open space so any line can be
     centred); these are only the fallback before it runs */
  padding: 40vh 16px 50vh;
  will-change: transform;
  transform: translate3d(0, 0, 0);
}
/* the masthead: wordmark and the one quiet line, fixed at the top centre —
   about the room, not part of the writing */
#mast {
  position: fixed;
  top: 18px;
  left: 16px;
  right: 16px;
  z-index: 4;
  display: grid;
  grid-template-columns: 1fr auto 1fr; /* the dot sits on the centre line; the wordmark never moves */
  align-items: baseline;
  column-gap: 0.6em;
  margin: 0;
  pointer-events: none;
  opacity: 0.6;
}
h1 {
  margin: 0;
  justify-self: end;
  font-size: 0.72rem;
  font-weight: 500;
  letter-spacing: 0.22em;
  text-transform: uppercase;
}
#mast .dot { font-size: 0.85rem; font-weight: 300; }
/* the one quiet line: the old phrase dissolves letter by letter, the new one
   condenses out of the same blur, left to right */
.hint {
  position: relative;
  margin: 0;
  justify-self: start;
  font-size: 0.85rem;
  font-weight: 300;
  white-space: nowrap;
}
.hint .phrase { display: inline-block; }
.hint .phrase.out { position: absolute; left: 0; top: 0; }
.hint .ch {
  display: inline-block;
  white-space: pre;
  animation: ch-in 1100ms cubic-bezier(.2, .7, .2, 1) both;
  animation-delay: calc(var(--i) * 26ms + 380ms);
}
.hint .out .ch {
  animation: ch-out 800ms cubic-bezier(.4, 0, .6, 1) both;
  animation-delay: calc(var(--i) * 16ms);
}
@keyframes ch-in {
  from { opacity: 0; filter: blur(5px); transform: translateY(3px); }
  to { opacity: 1; filter: blur(0); transform: none; }
}
@keyframes ch-out {
  to { opacity: 0; filter: blur(4px); transform: translateY(-4px); }
}
@media (prefers-reduced-motion: reduce) {
  .hint .ch, .hint .out .ch { animation-duration: 300ms; animation-delay: 0ms; filter: none; transform: none; }
}

.page-text, #entry, #mirror, #measure {
  font: inherit;
  font-weight: 300;
  font-size: clamp(1.15rem, 2.3vw, 1.35rem);
  line-height: 1.7;
  letter-spacing: 0.005em;
  padding: 0;
  white-space: pre-wrap;
  overflow-wrap: break-word;
  word-break: normal;
  -webkit-hyphens: none; hyphens: none;
  tab-size: 4;
  font-optical-sizing: auto;
}
#entry {
  position: absolute;
  inset: 0;
  box-sizing: border-box;
  width: 100%;
  height: 100%;
  margin: 0;
  border: 0;
  background: none;
  color: transparent;
  caret-color: transparent;
  resize: none;
  overflow-y: auto;
  overflow-x: hidden;
  scrollbar-width: none;
  -webkit-overflow-scrolling: touch;
  outline: none;
  z-index: 1;
  font-variation-settings: "slnt" var(--slnt);
}
#entry::-webkit-scrollbar { display: none; }
#entry::selection { background: color-mix(in oklab, var(--glow) 22%, transparent); }
#mirrorwrap { position: relative; min-height: 9.5rem; }
#mirror { color: var(--ink); }
#mirror .line {
  position: relative;
  /* a line is typeset in the state it was written in; all axes here are
     width-neutral so wrapping never diverges from the textarea */
  font-variation-settings:
    "slnt" var(--slnt),
    "GRAD" var(--l-grad, 0),
    "YTLC" var(--l-ytlc, 514),
    "YOPQ" var(--l-yopq, 79),
    "YTAS" var(--l-ytas, 750);
  filter: blur(var(--l-blur, 0px));
  color: var(--l-tint, var(--ink));
  transition: opacity 420ms ease, font-variation-settings 1200ms ease, filter 1200ms ease, color 1200ms ease;
}
#mirror .line.trembling { animation: tremble 90ms steps(2, jump-none) infinite; }
@keyframes tremble {
  from { transform: translate(calc(var(--l-tremor, 0) * -1px), 0); }
  to   { transform: translate(calc(var(--l-tremor, 0) * 1px), calc(var(--l-tremor, 0) * 0.5px)); }
}
/* what you erased stays: sits where it was, dissolves on its own clock */
.ghost {
  position: absolute;
  white-space: pre;
  pointer-events: none;
  color: var(--ink);
  font-size: 0.72em;
  line-height: 1;
  margin-top: -0.55em; /* floats just above where the words were, not on the new ones */
  opacity: var(--ghost-a, 0.09);
  filter: blur(0.3px);
  animation: dissolve var(--life, 45s) linear forwards;
}
@keyframes dissolve { to { opacity: 0; } }
#measure {
  position: absolute;
  top: 0; left: 0;
  visibility: hidden;
  pointer-events: none;
  height: 0;
  overflow: hidden;
  font-variation-settings: "slnt" var(--slnt);
}
#caret {
  position: absolute;
  top: 0; left: 0;
  width: 2px;
  /* the glyph height, centred in the 1.7em line — a native caret's proportions */
  height: 1.15em;
  margin-top: 0.275em;
  font-size: clamp(1.15rem, 2.3vw, 1.35rem);
  border-radius: 1px;
  background: var(--glow);
  opacity: 0.9;
  pointer-events: none;
  z-index: 2;
  animation: caret-blink 1.05s steps(2, start) infinite;
  transition: transform 60ms linear;
}
#caret.focused { opacity: 1; }
@keyframes caret-blink { to { visibility: hidden; } }
/* spellcheck stays on for autocorrect; the text is transparent anyway */
#entry::spelling-error, #entry::grammar-error { text-decoration: none; }

.status {
  min-height: 1.4em;
  margin: 0.7rem 0 0;
  font-size: 0.75rem;
  font-weight: 300;
  opacity: 0.4;
  font-variant-numeric: tabular-nums;
}
/* autocorrect note: rises softly from the corrected word and fades */
.note {
  position: absolute;
  white-space: pre;
  pointer-events: none;
  font-size: 0.62em;
  line-height: 1;
  margin-top: -0.22em;
  color: var(--glow);
  opacity: 0;
  animation: note-rise 2.4s ease forwards;
}
@keyframes note-rise {
  0% { opacity: 0; transform: translateY(6px); }
  18% { opacity: 0.95; transform: translateY(0); }
  70% { opacity: 0.95; transform: translateY(-2px); }
  100% { opacity: 0; transform: translateY(-8px); }
}

/* --- meters ------------------------------------------------------------ */
#meters {
  position: fixed;
  left: 16px;
  bottom: 40px;
  z-index: 4;
  width: min(15rem, calc(100vw - 32px));
  font-size: 0.66rem;
  font-weight: 400;
  letter-spacing: 0.01em;
  opacity: 0.8;
  font-variant-numeric: tabular-nums;
}
#meters .row {
  display: grid;
  grid-template-columns: 5.4em 1fr 2.6em;
  align-items: center;
  gap: 0.5em;
  margin: 0.18em 0;
}
#meters .k { opacity: 0.65; }
#meters .v { text-align: right; opacity: 0.65; }
#meters .v.wide { grid-column: 2 / 4; text-align: left; }
#meters .bar {
  display: block;
  height: 3px;
  border-radius: 2px;
  background: color-mix(in oklab, var(--ink) 12%, transparent);
  overflow: hidden;
}
#meters .bar i {
  display: block;
  height: 100%;
  width: 0%;
  border-radius: 2px;
  background: var(--glow);
  transition: width 120ms linear;
}
#meters[hidden] { display: none; }
#meters .affect { margin-bottom: 0.7em; }
#meters .emotions { margin-bottom: 0.7em; }

/* --- credit (footer, centred) -------------------------------------------- */
.credit {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 14px;
  z-index: 4;
  margin: 0;
  text-align: center;
  font-size: 0.7rem;
  font-weight: 300;
  opacity: 0.4;
  pointer-events: none;
}
.credit a { pointer-events: auto; }
.credit #status:not(:empty)::before { content: " · "; }
.credit #status { font-variant-numeric: tabular-nums; }
.credit a { color: inherit; }

/* --- controls (bottom right) ------------------------------------------- */
#controls {
  position: fixed;
  right: 16px;
  bottom: 40px;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 0.45em;
  font-size: 0.7rem;
}
#controls button {
  display: inline-flex;
  align-items: center;
  gap: 0.55em;
  padding: 0.3em 0.2em 0.3em 0.6em;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  letter-spacing: 0.02em;
  opacity: 0.5;
  cursor: pointer;
  transition: opacity 300ms ease;
}
#controls button:hover, #controls button:focus-visible { opacity: 0.9; outline: none; }
#controls button i {
  order: 2;
  width: 1.6em;
  height: 0.9em;
  border-radius: 0.45em;
  background: color-mix(in oklab, var(--ink) 18%, transparent);
  position: relative;
  transition: background 400ms ease;
}
#controls button i::after {
  content: "";
  position: absolute;
  top: 0.12em; left: 0.12em;
  width: 0.66em; height: 0.66em;
  border-radius: 50%;
  background: var(--ink);
  opacity: 0.7;
  transition: transform 400ms cubic-bezier(.2,.8,.2,1), opacity 400ms ease;
}
#controls button[aria-pressed="true"] i { background: color-mix(in oklab, var(--glow) 55%, transparent); }
#controls button[aria-pressed="true"] i::after { transform: translateX(0.7em); opacity: 1; }

/* --- sign in / entries: a plain word top right, and its sheet ----------------- */
#t-account {
  position: fixed;
  top: 16px;
  left: 16px;
  z-index: 5;
  padding: 0.45em 0.7em;
  border: 0;
  background: none;
  color: var(--ink);
  font: inherit;
  font-size: 0.72rem;
  letter-spacing: 0.04em;
  opacity: 0.55;
  cursor: pointer;
  transition: opacity 300ms ease;
}
#t-account:hover, #t-account:focus-visible { opacity: 0.95; outline: none; }
#account {
  position: fixed;
  left: 16px;
  top: 3.2rem;
  z-index: 5;
  width: min(22rem, calc(100vw - 32px));
  max-height: 60vh;
  overflow: auto;
  padding: 0.9rem 1rem;
  border-radius: 10px;
  background: color-mix(in oklab, var(--bg) 97%, transparent);
  border: 1px solid color-mix(in oklab, var(--ink) 12%, transparent);
  font-size: 0.8rem;
  font-weight: 300;
  scrollbar-width: none;
}
#account[hidden] { display: none; }
/* while the sheet is open the writing behind it steps back, so neither is
   read through the other */
#page, #mast { transition: opacity 320ms ease; }
body.sheet-open #page { opacity: 0.25; }
body.sheet-open #mast { opacity: 0; }
#account .signin { display: grid; gap: 0.6rem; }
#account label { opacity: 0.6; font-size: 0.72rem; letter-spacing: 0.04em; }
#account input {
  font: inherit; font-size: 0.95rem;
  padding: 0.55em 0.7em;
  border-radius: 7px;
  border: 1px solid color-mix(in oklab, var(--ink) 18%, transparent);
  background: color-mix(in oklab, var(--ink) 5%, transparent);
  color: var(--ink);
  outline: none;
}
#account input:focus { border-color: color-mix(in oklab, var(--glow) 60%, transparent); }
/* the six digits from the letter: big, centred, spaced like a code */
#account input.code {
  font-size: 1.6rem;
  font-weight: 400;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.45em;
  text-align: center;
  text-indent: 0.45em; /* balances the trailing letter-space so the digits sit centred */
  padding: 0.35em 0.5em;
}
#account input.code::placeholder { opacity: 0.25; letter-spacing: 0.45em; }
#account button {
  font: inherit; font-size: 0.78rem;
  padding: 0.5em 0.9em;
  border-radius: 7px;
  border: 1px solid color-mix(in oklab, var(--glow) 45%, transparent);
  background: color-mix(in oklab, var(--glow) 14%, transparent);
  color: var(--ink);
  cursor: pointer;
}
#account button.quiet { border-color: transparent; background: none; opacity: 0.6; }
#account button:disabled { opacity: 0.5; cursor: default; }
#account .status { margin: 0; opacity: 0.65; min-height: 1.3em; }

/* --- memories: a wall that slides in from the left ---------------------------
   No card and no border: the room's own colour, fading into the scene at its
   right edge. Each memory is its first line in the room's typeface; under it,
   small, the hour on the scene clock it was written under, the date, and its
   top emotion in that emotion's own light. */
#memories {
  position: fixed;
  top: 0; bottom: 0; left: 0;
  z-index: 5;
  width: min(26rem, 88vw);
  display: flex;
  flex-direction: column;
  padding: 1.325rem 3.2rem 1.2rem 1.5rem;
  box-sizing: border-box;
  background: linear-gradient(to right,
    color-mix(in oklab, var(--bg) 97%, transparent) 0,
    color-mix(in oklab, var(--bg) 97%, transparent) 78%,
    transparent 100%);
  color: var(--ink);
  font-weight: 300;
  animation: wall-in 420ms cubic-bezier(.2,.8,.2,1);
}
#memories[hidden] { display: none; }
@keyframes wall-in {
  from { opacity: 0; transform: translateX(-14px); }
  to   { opacity: 1; transform: none; }
}
#memories .head {
  display: flex; align-items: baseline; justify-content: space-between;
  margin: 0 0 1.1rem;
}
/* the wall has no heading of its own: the word top left stays put over it
   and reads as the title; the head row only holds "new memory", on the
   word's baseline */
#memories .head { justify-content: flex-end; min-height: 1.6rem; margin-top: -0.45rem; }
#memories:not([hidden]) ~ #t-account { opacity: 0.95; }
#memories button {
  font: inherit; font-size: 0.74rem;
  padding: 0.3em 0; border: 0; background: none;
  color: var(--ink); cursor: pointer;
  letter-spacing: 0.04em;
  opacity: 0.55;
  transition: opacity 240ms ease;
}
#memories button:hover, #memories button:focus-visible { opacity: 0.95; outline: none; }
#memories ol.memories {
  list-style: none; margin: 0; padding: 0;
  flex: 1; min-height: 0;
  overflow: auto; scrollbar-width: none;
  /* the list dissolves at its own ends rather than stopping */
  mask-image: linear-gradient(to bottom, transparent, black 1.2rem, black calc(100% - 1.6rem), transparent);
  -webkit-mask-image: linear-gradient(to bottom, transparent, black 1.2rem, black calc(100% - 1.6rem), transparent);
  padding: 1rem 0 1.4rem;
}
#memories ol.memories::-webkit-scrollbar { display: none; }
#memories li { position: relative; }
#memories .memory {
  display: block; width: 100%; text-align: left;
  padding: 0.55em 1.6em 0.6em 0;
  opacity: 0.62;
  transition: opacity 300ms ease;
}
#memories .memory:hover, #memories .memory:focus-visible, #memories li.current .memory { opacity: 1; }
#memories .first {
  display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2;
  overflow: hidden;
  font-size: 1.02rem; line-height: 1.35; letter-spacing: 0;
}
/* the one that's open now carries a little of the room's light */
#memories li.current .first { color: var(--glow); }
#memories .meta {
  display: flex; gap: 0.5em; align-items: baseline;
  margin-top: 0.22em;
  font-size: 0.66rem; letter-spacing: 0.05em;
  opacity: 0.7;
  font-variant-numeric: tabular-nums;
}
#memories .clock { font-size: 0.72rem; opacity: 0.8; }
/* the emotion in its own light, pulled toward the ink so it reads on any wall */
#memories .top { font-weight: 400; color: color-mix(in oklab, var(--tint, var(--ink)) 62%, var(--ink)); }
#memories .delete {
  position: absolute; right: 0; top: 0.55em;
  padding: 0.2em 0.4em; font-size: 0.9rem; line-height: 1;
  opacity: 0;
}
#memories li:hover .delete, #memories li:focus-within .delete { opacity: 0.35; }
#memories .delete:hover, #memories .delete:focus-visible { opacity: 0.9; }
#memories .empty { padding: 0.6em 0; opacity: 0.5; font-size: 0.85rem; line-height: 1.5; }
/* a question in place of a row */
#memories .ask { display: flex; flex-wrap: wrap; align-items: baseline; gap: 0.2em 1.1em; padding: 0.55em 0 0.6em; }
#memories .ask .q { flex: 1 0 100%; font-size: 0.85rem; line-height: 1.5; opacity: 0.75; }
#memories .ask button { font-size: 0.74rem; letter-spacing: 0.06em; opacity: 0.7; }
#memories .ask .yes { color: color-mix(in oklab, var(--glow) 70%, var(--ink)); }
#memories .ask button:hover, #memories .ask button:focus-visible { opacity: 1; }
#memories .foot {
  display: flex; align-items: baseline; justify-content: space-between; gap: 1rem;
  margin-top: 0.6rem;
  font-size: 0.66rem; letter-spacing: 0.04em;
}
#memories .who { opacity: 0.4; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
@media (max-width: 600px) { #memories { width: 88vw; padding: 1.2rem 2.4rem 1rem 1.1rem; } }
@media (prefers-reduced-motion: reduce) { #memories { animation: none; } }

@media (max-width: 600px) { #account { right: 8px; left: 8px; width: auto; top: 3rem; max-height: 55vh; } }

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

@media (max-width: 600px) {
  /* on a phone the switches sit in a row at the bottom, just above the
     credit; the masthead stays at the very top and stacks (wordmark centred,
     the phrase beneath it, no dot) */
  #controls {
    bottom: 1.6rem; top: auto; left: 8px; right: 8px;
    flex-direction: row; justify-content: space-around; gap: 0;
  }
  #controls button { padding: 0.7em 0.5em; min-height: 40px; font-size: 0.7rem; }
  #mast { top: 14px; grid-template-columns: 1fr; row-gap: 0.25em; justify-items: center; }
  #t-account { top: 8px; left: 8px; }
  #mast .dot { display: none; }
  h1 { justify-self: center; }
  .hint { justify-self: center; text-align: center; white-space: normal; }
  .hint .phrase.out { left: 50%; transform: translateX(-50%); white-space: nowrap; }
  #meters {
    top: 4.4rem; bottom: auto; left: 8px; right: 8px; width: auto;
    padding: 0.7em 0.8em;
    border-radius: 10px;
    background: color-mix(in oklab, var(--bg) 70%, transparent);
    backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  }
  #meters .emotions { display: grid; grid-template-columns: 1fr 1fr; column-gap: 1.2em; }
  .credit { bottom: 6px; font-size: 0.6rem; }
}
}

@media (prefers-reduced-motion: reduce) {
  #caret { animation: none; }
}
