/*
  Hearth styles, v4c "Almanac" (design/DESIGN.md). Every state sits on night with grain and a soft
  vignette. Playing keeps Dream Recorder's dark strip and slow fades, adapted from Dream Recorder by
  Modem, github.com/modem-works/dream-recorder (MIT).
  Sizes inside the strip are in --u (1% of strip height, 4px at the default 1280x400 strip), so a
  recalibrated strip scales everything. Outside the strip is black except the lamp spot.
*/

@font-face {
  font-family: 'MT Serif';
  src: url('fonts/InstrumentSerif-Regular.ttf') format('truetype');
  font-style: normal;
  font-weight: 400;
  font-display: swap;
}
@font-face {
  font-family: 'MT Sans';
  src: url('fonts/Inter-Variable.ttf') format('truetype');
  font-style: normal;
  font-weight: 100 900;
  font-display: swap;
}

:root {
  --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
  --enter: 500ms;
  --exit: 250ms;

  --cream: #ECE6DC;
  --fog: #8E8A84;
  --night: #0B0B0A;
  --rec: #B23A2E;
  --rec-label: #C9584B;
  --lamp: #F6E7C8;
  --lamp-hi: #FFF8EA;
  --cell: #1C1B19;

  --serif: 'MT Serif', 'Instrument Serif', 'New York', Georgia, serif;
  --sans: 'MT Sans', 'Inter', -apple-system, system-ui, sans-serif;
  --grain: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='240' height='240'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='.8' numOctaves='3' stitchTiles='stitch'/><feColorMatrix type='saturate' values='0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");

  /* Button zone in percent of the full screen. calibrate.js overrides these. */
  --bx: 82;
  --by: 81;
  --bw: 12;
  --bh: 13;

  /* Visible strip (the shell window) in percent of the full screen. calibrate.js overrides these. */
  --sx: 0;
  --sy: 25;
  --sw: 100;
  --sh: 50;

  /* Mic level 0..1, written by main.js while recording. */
  --level: 0;
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #000;
  color: var(--cream);
  font-family: var(--sans);
  cursor: none;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
  scrollbar-width: none;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}
::-webkit-scrollbar { display: none; }
img { -webkit-user-drag: none; }

/* Everything outside the strip sits behind the shell, so it stays black. */
#hearth {
  position: fixed;
  inset: 0;
  background: #000;
  overflow: hidden;
}

/* Lamp light: the only thing outside the strip that shows, through the button cap. */
.spot {
  position: absolute;
  left: calc((var(--bx) + var(--bw) / 2) * 1% - 8vw);
  top: calc((var(--by) + var(--bh) / 2) * 1% - 8vw);
  width: 16vw;
  height: 16vw;
  pointer-events: none;
  z-index: 20;
}
.glow, .glow-breathe {
  position: absolute;
  inset: 0;
  opacity: 0;
  transition: opacity var(--exit) var(--ease-out);
  will-change: opacity;
}
.spot .glow {
  background: radial-gradient(closest-side, var(--lamp-hi) 0%, var(--lamp) 42%, rgba(246, 231, 200, 0.35) 72%, rgba(246, 231, 200, 0) 100%);
}
.glow-breathe > .glow { opacity: 1; animation: lamp 7s ease-in-out infinite alternate; }

@keyframes lamp {
  from { opacity: 0.35; }
  to { opacity: 0.8; }
}

[data-state="clock"] .spot > .glow { opacity: 0.12; transition-duration: var(--enter); }
[data-state="waiting"] .spot > .glow-breathe { opacity: 1; transition-duration: 2s; }
/* Pressed cap: dark-dim, with a faint trace of the mic level. */
[data-state="recording"] .spot > .glow { opacity: calc(0.05 + var(--level) * 0.12); transition: opacity 90ms linear; }
[data-state="sending"] .spot > .glow,
[data-state="playing"] .spot > .glow { opacity: 0.05; transition-duration: var(--enter); }
[data-state="error"] .spot > .glow,
[data-state="saved"] .spot > .glow { opacity: 0.12; transition-duration: var(--enter); }

/* Hold to record: the ring sits in the middle of the strip, fills over the 3 s hold (input.js HOLD_MS) and snaps back on release. */
.ring {
  position: absolute;
  left: 50%;
  top: 50%;
  width: calc(60 * var(--u));
  height: calc(60 * var(--u));
  margin: calc(-30 * var(--u)) 0 0 calc(-30 * var(--u));
  z-index: 45;
  pointer-events: none;
  transform: rotate(-90deg);
  opacity: 0;
  transition: opacity 200ms var(--ease-out);
}
.ring circle {
  fill: none;
  stroke: var(--lamp);
  stroke-width: 2.5;
  stroke-linecap: round;
  stroke-dasharray: 100;
  stroke-dashoffset: 100;
  transition: stroke-dashoffset 200ms var(--ease-out);
}
[data-hold] .ring { opacity: 1; transition-duration: 120ms; }
[data-hold] .ring circle { stroke-dashoffset: 0; transition: stroke-dashoffset 3s linear; }
.hint-reply, [data-reply] .hint-story { display: none; }
[data-reply] .hint-reply { display: block; }

/* Visible strip, sized to the shell window. */
.strip {
  --u: calc(var(--sh) * 1vh / 100);
  position: absolute;
  left: calc(var(--sx) * 1%);
  top: calc(var(--sy) * 1%);
  width: calc(var(--sw) * 1%);
  height: calc(var(--sh) * 1%);
  overflow: hidden;
  isolation: isolate;
  background: var(--night);
  margin: 0;
  z-index: 30;
}

.vignette, .grain {
  position: absolute;
  inset: 0;
  pointer-events: none;
}
.vignette { z-index: 30; background: radial-gradient(120% 90% at 50% 40%, transparent 55%, rgba(0, 0, 0, 0.5)); }
.grain { z-index: 50; background-image: var(--grain); background-size: 240px; mix-blend-mode: overlay; opacity: 0.5; }

.layer {
  position: absolute;
  inset: 0;
  margin: 0;
  box-sizing: border-box;
  opacity: 0;
  transition: opacity var(--exit) var(--ease-out);
  will-change: opacity;
  pointer-events: none;
}
[data-state="clock"] .clock,
[data-state="waiting"] .waiting,
[data-state="recording"] .rec,
[data-state="saved"] .saved,
[data-state="error"] .err { opacity: 1; transition-duration: var(--enter); }

.headline {
  margin: 0;
  font: 400 calc(28 * var(--u))/1 var(--serif);
  letter-spacing: -0.02em;
  color: var(--cream);
  text-wrap: balance;
}
.sub {
  margin: 0;
  font: 400 calc(11.5 * var(--u))/1.1 var(--serif);
  color: var(--fog);
  text-wrap: balance;
}
.sub:empty { display: none; }
/* Sentence case for lines that the scripts and the demo data write in lower case. */
.headline::first-letter, .sub::first-letter, .play-stamp::first-letter, .status::first-letter { text-transform: uppercase; }

.en { display: none; }
[data-subs="en"] .en {
  display: block;
  margin: calc(2.5 * var(--u)) 0 0;
  font: 400 calc(8 * var(--u))/1.15 var(--serif);
  color: rgba(142, 138, 132, 0.85);
  text-wrap: balance;
}
[data-subs="en"] .en:empty { display: none; }

.col {
  display: flex;
  flex-direction: column;
  justify-content: center;
  align-items: flex-start;
  padding: 0 calc(30 * var(--u));
}
.col .headline { margin-top: calc(5.5 * var(--u)); }
.col > .headline:first-child { margin-top: 0; }
.col .sub { margin-top: calc(4 * var(--u)); }

.clock {
  display: flex;
  align-items: center;
  gap: calc(10 * var(--u));
  padding: 0 calc(30 * var(--u)) 0 calc(27.5 * var(--u));
  font-family: var(--serif);
  font-variant-numeric: tabular-nums;
}
.day-num {
  font: 400 calc(72.5 * var(--u))/0.8 var(--serif);
  letter-spacing: -0.04em;
  color: #8A867F;
}
.day-wd {
  padding-top: calc(3 * var(--u));
  font-size: calc(16 * var(--u));
  line-height: 1;
  color: #85817A;
  text-transform: capitalize;
  white-space: nowrap;
}
.day-mo {
  display: block;
  margin-top: calc(3 * var(--u));
  font-size: calc(11.5 * var(--u));
  color: #7F7B74;
}
[data-subs="en"] .day-wd .en { margin-top: calc(4.5 * var(--u)); font-size: calc(8 * var(--u)); color: #4E4B47; }
.clk {
  margin-left: auto;
  font-size: calc(27.5 * var(--u));
  line-height: 1;
  color: #7F7B74;
  white-space: nowrap;
}
.colon { transition: opacity 300ms ease; }
.hint {
  position: absolute;
  top: calc(8 * var(--u));
  right: calc(30 * var(--u));
  margin: 0;
  text-align: right;
  font: 400 calc(8 * var(--u))/1.15 var(--serif);
  color: var(--fog);
}
.hint .en { margin-top: 0; }
.colon.off { opacity: 0.4; }
.family-code {
  position: absolute;
  right: calc(30 * var(--u));
  bottom: calc(8 * var(--u));
  margin: 0;
  font: 400 calc(8 * var(--u))/1 var(--serif);
  color: #57544F;
}
.family-code span:empty, .family-code-en { display: none; }
[data-subs="en"] .family-code-en:not(:empty) { display: inline; margin-left: calc(3 * var(--u)); color: #4E4B47; }

.rec {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: calc(10 * var(--u));
  padding: 0 calc(30 * var(--u)) calc(1.5 * var(--u));
}
.rec-text { min-width: 0; }
.rec .headline { font-size: calc(29 * var(--u)); }
.rec .sub { margin-top: calc(4.5 * var(--u)); font-size: calc(11 * var(--u)); }
.rec-side {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: calc(6.5 * var(--u));
  flex: none;
}
.rec-label {
  display: inline-flex;
  align-items: center;
  gap: calc(4 * var(--u));
  font: 500 calc(6 * var(--u))/1 var(--sans);
  letter-spacing: 0.12em;
  color: var(--rec-label);
}
.rec-label::before {
  content: '';
  width: calc(5.5 * var(--u));
  height: calc(5.5 * var(--u));
  border-radius: 50%;
  background: var(--rec);
}
.counter {
  display: inline-flex;
  align-items: center;
  gap: calc(1.5 * var(--u));
  font: 400 calc(13 * var(--u))/1 var(--sans);
  font-variant-numeric: tabular-nums;
  color: var(--cream);
}
.counter i {
  font-style: normal;
  display: grid;
  place-items: center;
  width: calc(13 * var(--u));
  height: calc(19 * var(--u));
  border-radius: calc(2 * var(--u));
  background: var(--cell);
  box-shadow: inset 0 2px 6px rgba(0, 0, 0, 0.7), 0 1px 0 rgba(255, 255, 255, 0.06);
}
.counter s { text-decoration: none; color: var(--fog); padding: 0 1px; }

/* Sending shows no spinner. */
[data-state="sending"] .send { opacity: 1; transition-duration: var(--enter); }
.send .headline { font-size: calc(29 * var(--u)); }
[data-state="sending"] .send .headline { animation: send 2.4s ease-in-out infinite alternate; }
@keyframes send {
  from { opacity: 1; }
  to { opacity: 0.55; }
}

/* The oxblood ribbon marks the new entry, as it does on paper. */
.saved .headline { font-size: calc(24 * var(--u)); }
.ribbon {
  position: absolute;
  top: 0;
  left: calc(30 * var(--u));
  width: calc(4.25 * var(--u));
  height: calc(16 * var(--u));
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.28), transparent calc(3.5 * var(--u))),
    linear-gradient(90deg, rgba(0, 0, 0, 0.14), transparent 25%, transparent 75%, rgba(0, 0, 0, 0.14)),
    #82342C;
  clip-path: polygon(0 0, 100% 0, 100% 100%, 50% calc(100% - 2.25 * var(--u)), 0 100%);
}

.err .headline { font-size: calc(22 * var(--u)); max-width: 100%; }

.media { overflow: hidden; background: var(--night); transition-duration: 500ms; }
.media > * { position: absolute; inset: 0; width: 100%; height: 100%; }
[data-state="playing"] .media { opacity: 1; transition: opacity 2s ease-out; }

.warm {
  background:
    radial-gradient(45% 80% at 30% 60%, rgba(214, 160, 110, 0.55), rgba(214, 160, 110, 0) 70%),
    radial-gradient(40% 70% at 72% 40%, rgba(150, 70, 52, 0.55), rgba(150, 70, 52, 0) 70%),
    radial-gradient(60% 90% at 55% 100%, rgba(236, 210, 170, 0.35), rgba(236, 210, 170, 0) 70%),
    linear-gradient(120deg, #1a0f09, #2e1810 45%, #120a06);
  transform: scale(1.02);
  transition: transform 600ms var(--ease-out);
}
[data-state="playing"] .warm { transform: scale(1.14) translate(-2%, 1%); transition: transform 24s linear; }

.kb img, #video { filter: saturate(0.85) brightness(0.82); }
.kb { transition: opacity 600ms var(--ease-out); }
.kb img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  transform: scale(1.03);
  transition: opacity 500ms var(--ease-out), transform 0s linear 500ms;
}
.kb img.on {
  opacity: 1;
  transform: scale(1.10) translate(var(--kx), var(--ky));
  transition: opacity 700ms var(--ease-out), transform 14s linear;
}

#video { object-fit: cover; opacity: 0; transition: opacity 600ms var(--ease-out); }
.media[data-kind="video"] #video { opacity: 1; }
.media[data-kind="video"] .kb { opacity: 0; }

.film-vignette { background: linear-gradient(to top, rgba(0, 0, 0, 0.62) 0%, rgba(0, 0, 0, 0.28) 38%, transparent 62%), linear-gradient(to bottom, rgba(0, 0, 0, 0.4), transparent 30%), radial-gradient(90% 120% at 50% 50%, transparent 45%, rgba(0, 0, 0, 0.7)); }
/* Caption scrim: dark enough under the text to hold cream at 3:1 over a white still. */
[data-state="playing"] .film-vignette { background: linear-gradient(to top, rgba(0, 0, 0, 0.72) 0%, rgba(0, 0, 0, 0.55) 35%, rgba(0, 0, 0, 0.38) 65%, rgba(0, 0, 0, 0.15) 85%, transparent), linear-gradient(to bottom, rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.32) 25%, transparent 45%), radial-gradient(90% 120% at 50% 50%, transparent 45%, rgba(0, 0, 0, 0.7)); }

.play-stamp, .play-cap { z-index: 35; inset: auto; text-shadow: 0 1px 2px rgba(0, 0, 0, 0.55), 0 0 18px rgba(0, 0, 0, 0.35); }
.play-stamp {
  left: calc(30 * var(--u));
  top: calc(14 * var(--u));
  font: 400 calc(11 * var(--u))/1 var(--serif);
  color: rgba(236, 230, 220, 0.82);
  white-space: nowrap;
}
.play-cap {
  left: calc(30 * var(--u));
  right: calc(40 * var(--u));
  bottom: calc(15 * var(--u));
  font: 400 calc(14 * var(--u))/1.1 var(--serif);
  color: var(--cream);
  text-shadow: 0 2px 30px rgba(0, 0, 0, 0.6);
  text-wrap: balance;
  /* Long beats step down a size (js fitCaption) and never pass 3 lines. */
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}
/* With an English line, each language clamps on its own, Spanish on top. */
.play-cap[data-two] { display: block; -webkit-line-clamp: none; line-clamp: none; overflow: visible; }
.play-cap[data-two] > * {
  text-wrap: balance;
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 3;
  line-clamp: 3;
  overflow: hidden;
}
.play-cap[data-two] > :empty { display: none; }
/* English caption: the same serif, smaller and dimmer so the Spanish leads. */
.play-cap[data-two] .cap-en {
  margin-top: 0.3em;
  font: 400 max(0.62em, calc(8 * var(--u)))/1.15 var(--serif);
  color: rgba(236, 230, 220, 0.85);
}
.play-cap[data-two] .cap-en:empty { display: none; }
[data-subs="en"] .play-stamp .en { display: inline; margin: 0 0 0 calc(4 * var(--u)); vertical-align: 0.15em; color: rgba(236, 230, 220, 0.6); }
.play-cap[data-size="m"] { font-size: calc(11 * var(--u)); }
.play-cap[data-size="s"] { font-size: calc(9.5 * var(--u)); }
.play-cap[data-size="xs"] { font-size: calc(8.5 * var(--u)); text-wrap: pretty; }
.play-cap[data-size="xxs"] { font-size: calc(7.5 * var(--u)); text-wrap: pretty; }
.play-cap[data-two][data-size="xs"] > *, .play-cap[data-two][data-size="xxs"] > * { text-wrap: pretty; }
[data-state="playing"] .play-stamp:not(:empty) { opacity: 1; transition: opacity 1200ms ease-out 900ms; }
[data-state="playing"] .play-cap:not(:empty) { opacity: 1; transition: opacity 1200ms ease-out 200ms; }
.play-cap[data-pending] .cap-en { display: block; }

/* Small status note (offline, not configured), bottom left. */
.status {
  position: absolute;
  left: calc(30 * var(--u));
  bottom: calc(8 * var(--u));
  margin: 0;
  font: 400 calc(8 * var(--u))/1 var(--serif);
  white-space: nowrap;
  color: var(--fog);
  opacity: 0;
  transition: opacity var(--enter) var(--ease-out);
  z-index: 40;
}
.status:not(:empty) { opacity: 1; }
[data-state="saved"] .status { opacity: 0; }

@media (prefers-reduced-motion: reduce) {
  .glow-breathe > .glow { animation: none; opacity: 0.7; }
  .ring circle, [data-hold] .ring circle { stroke-dashoffset: 0; transition: none; }
  [data-hold] .ring { transition: opacity 3s linear; }
  [data-state="sending"] .send .headline { animation: none; }
  .kb img, .kb img.on, [data-state="playing"] .warm { transform: none; }
}
