/* errr.in/chat. colours are ramp steps of the visit's preset, set by chat.js as --c-*; until then (and without
   webgl) the preset's own fallback colours (--map-*) carry the page, like the main site */
@font-face {
  font-family: "Fraunces Chat";
  src: url("/chat/fonts/fraunces-chat.woff2?v=1") format("woff2");
  font-weight: 300 600;
  font-display: block;
}

:root {
  --u: calc(1rem / 14);
  --col: min(calc(560 * var(--u)), 100% - 48px);
  --c-bg: var(--map-bg, #2f2a2e);
  --c-her: var(--map-ink, #fdd9e1);
  --c-you: var(--map-ink, #fdd9e1);
  --c-tag: var(--map-ink, #fdd9e1);
  --c-faint: var(--map-ink, #fdd9e1);
  --c-halo: var(--map-halo, #282529);
  --vvh: 100dvh;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html { font-size: clamp(100%, 0.55rem + 0.5vw, 150%); background: var(--c-bg); height: 100%; overflow: hidden; overscroll-behavior: none; }
body {
  height: 100%; overflow: hidden; overscroll-behavior: none; background: var(--c-bg); color: var(--c-her);
  font-family: "Fraunces Chat", Georgia, "Hiragino Sans", "Apple Symbols", system-ui, serif; font-synthesis: none;
  -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent;
}
.sr { position: absolute; width: 1px; height: 1px; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }

/* the water fills the large viewport and never resizes with the keyboard (that would reset the sim) */
.water { position: fixed; left: 0; top: 0; width: 100vw; height: 100vh; height: 100lvh; pointer-events: none; opacity: 0; transition: opacity 0.3s; }
.gl .water { opacity: 1; }

.app {
  position: fixed; left: 0; top: 0; width: 100%; height: var(--vvh);
  display: flex; flex-direction: column; align-items: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.top {
  width: var(--col); flex: none; display: flex; justify-content: space-between; align-items: baseline;
  padding: calc(18 * var(--u)) 0 calc(10 * var(--u));
  font-size: calc(12 * var(--u)); letter-spacing: 0.04em; line-height: 1.6; color: var(--c-tag);
  font-variant-numeric: tabular-nums;
}
.top a { color: inherit; text-decoration: none; }
.top a:focus-visible { outline: 1px solid currentColor; outline-offset: 3px; }
.top .right { display: flex; gap: calc(14 * var(--u)); align-items: baseline; }
.reset { font: inherit; letter-spacing: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
.reset:hover, .reset.armed { color: var(--c-you); }
.reset:focus-visible { outline: 1px solid currentColor; outline-offset: 3px; }
.clock { min-width: 4ch; text-align: right; transition: color 0.4s; }
.clock.low { color: var(--c-you); }

.scroller {
  width: var(--col); flex: 1; min-height: 0; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  scrollbar-width: none; -webkit-mask-image: none;
}
.scroller::-webkit-scrollbar { display: none; }
.log { list-style: none; min-height: 100%; display: flex; flex-direction: column; justify-content: flex-end; padding: calc(24 * var(--u)) 0 calc(12 * var(--u)); }

.msg .line { width: fit-content; max-width: 100%; white-space: pre-wrap; overflow-wrap: anywhere; text-wrap: pretty; }
.msg[data-from="erin"] { padding-left: calc(12 * var(--u)); max-width: 34em; }
.msg[data-from="erin"] .line { font-size: calc(16 * var(--u)); line-height: 1.4; font-weight: 400; color: var(--c-her); }
.msg[data-from="you"] { max-width: 40em; }
.msg[data-from="you"] .line { font-size: calc(14 * var(--u)); line-height: 1.5; font-weight: 400; color: var(--c-you); }
/* rhythm: lines of one burst sit close; a change of speaker breathes */
.msg + .msg { margin-top: calc(3 * var(--u)); }
.msg[data-from="erin"] + .msg[data-from="you"], .msg[data-from="erin"] + .ghost + .msg[data-from="you"] { margin-top: calc(22 * var(--u)); }
.msg[data-from="you"] + .msg[data-from="erin"], .msg[data-from="you"] + .ghost, .note + .msg[data-from="erin"], .note + .ghost { margin-top: calc(12 * var(--u)); }

.tag { font-size: calc(12 * var(--u)); letter-spacing: 0.04em; color: var(--c-tag); cursor: text; border-radius: 3px; }
.tag:focus-visible { outline: 1px solid var(--c-tag); outline-offset: 2px; }
.tag-edit {
  font: inherit; font-size: calc(12 * var(--u)); letter-spacing: 0.04em; color: var(--c-you); background: transparent;
  border: 0; border-bottom: 1px solid var(--c-tag); outline: none; padding: 0; width: 10ch; max-width: 24ch;
}
@media (pointer: coarse) { .tag-edit { font-size: 16px; } }

/* webgl paints the conversation from this same layout; the real text stays for selection and screen readers */
.gl .msg .line, .gl .msg .tag { color: transparent; transition: color 0.3s; }
/* a line the gl layer couldn't draw this frame (atlas full, mid re-raster) shows its real dom text instead of vanishing */
.gl .msg.raw[data-from="erin"] .line { color: var(--c-her); transition: none; }
.gl .msg.raw[data-from="you"] .line { color: var(--c-you); transition: none; }
.gl .msg.raw .tag { color: var(--c-tag); transition: none; }
.gl .msg .line::selection, .gl .msg .tag::selection { color: var(--c-you); background: color-mix(in srgb, var(--c-you) 22%, transparent); }
.gl .msg[data-from="erin"] .line::selection { color: var(--c-her); background: color-mix(in srgb, var(--c-her) 22%, transparent); }
.gl .msg .tag.editing { color: var(--c-you); }
/* without webgl: the preset's own fallback look, the halo as a text glow */
html:not(.gl) .msg[data-from="erin"] .line { text-shadow: 0 0 calc(var(--halo-size, 22px) * 0.5) var(--c-halo); }

.note {
  list-style: none; margin-top: calc(4 * var(--u)); font-size: calc(12 * var(--u)); letter-spacing: 0.04em; line-height: 1.6;
  color: var(--c-tag); cursor: pointer; width: fit-content;
}
.note:focus-visible { outline: 1px solid var(--c-tag); outline-offset: 2px; }
.ghost { list-style: none; height: calc(16 * var(--u) * 1.4); margin-left: calc(12 * var(--u)); }

.dock {
  width: var(--col); flex: none; display: flex; align-items: flex-end; gap: calc(10 * var(--u));
  padding: calc(8 * var(--u)) 0 calc(18 * var(--u));
}
.dock textarea {
  flex: 1; resize: none; border: 0; border-bottom: 1px solid color-mix(in srgb, var(--c-tag) 45%, transparent); border-radius: 0;
  background: transparent; color: var(--c-you); caret-color: var(--c-you);
  font: inherit; font-size: max(16px, calc(14 * var(--u))); line-height: 1.5; padding: calc(6 * var(--u)) 0; outline: none;
  max-height: calc(4 * 1.5em + 12px); overflow-y: auto; scrollbar-width: none;
}
.dock textarea::placeholder { color: var(--c-faint); opacity: 1; }
.dock textarea:focus { border-bottom-color: var(--c-tag); }
.dock textarea:disabled { opacity: 0.4; }
.send {
  flex: none; width: calc(28 * var(--u)); height: calc(28 * var(--u)); margin-bottom: calc(4 * var(--u));
  border: 0; background: none; color: var(--c-tag); font: inherit; font-size: calc(20 * var(--u)); line-height: 1; cursor: pointer;
  transition: color 0.2s, opacity 0.2s;
}
.send:hover, .send:focus-visible { color: var(--c-you); outline: none; }
.send[aria-disabled="true"] { opacity: 0.35; }

/* the edge print: makes any crop that keeps the right edge self-attributing */
.edge {
  position: fixed; right: max(6px, env(safe-area-inset-right)); bottom: calc(96px + env(safe-area-inset-bottom));
  writing-mode: vertical-rl; font-size: 9px; letter-spacing: 0.18em; color: var(--c-faint); pointer-events: none; user-select: none;
}
@media (min-width: 700px) { .edge { right: calc((100vw - var(--col)) / 2 - 28px); bottom: calc(110px + env(safe-area-inset-bottom)); } }

.ended { position: fixed; inset: 0; display: grid; place-items: center; pointer-events: none; }
.ended[hidden] { display: none; }
.ended p { font-size: calc(15 * var(--u)); letter-spacing: 0.01em; color: var(--c-her); opacity: 0; transition: opacity 0.8s; }
.ended.on p { opacity: 1; }
.nojs { position: fixed; inset: 0; display: grid; place-items: center; font-size: 15px; color: var(--c-her); }

@media (prefers-reduced-motion: reduce) {
  .water, .gl .msg .line, .clock, .ended p { transition: none; }
}

/* no webgl: the typing dots in plain css */
html:not(.gl) .ghost::before { content: '\2022\2009\2022\2009\2022'; color: var(--c-her); letter-spacing: 0.1em; animation: dots 1.2s ease-in-out infinite; }
@keyframes dots { 0%, 100% { opacity: 0.35; } 50% { opacity: 0.9; } }
@media (prefers-reduced-motion: reduce) { html:not(.gl) .ghost::before { animation: none; opacity: 0.6; } }
