/* Сожги письмо: a dark desk at night. One scene, no scrolling.
   Tokens first; components use the semantic layer only. */

:root {
  --base-ink-900: #0b0806;
  --base-cream-100: #f1e6d4;
  --base-cream-300: #cdbda4;
  --base-ember-500: #ff7a2e;
  --base-ballpoint-700: #1f2b6b;
  --base-ice-300: #a8d8ff;

  --background-color-primary: var(--base-ink-900);
  --text-color-primary: var(--base-cream-100);
  --text-color-secondary: var(--base-cream-300);
  --text-color-accent: var(--base-ember-500);
  --ink-color: var(--base-ballpoint-700);
  --chip-border: rgb(241 230 212 / 0.22);
  --chip-border-active: rgb(255 122 46 / 0.75);
  --text-color-ice: var(--base-ice-300);
  --chip-border-ice: rgb(168 216 255 / 0.6);
  /* calm burn: the glowing edge, the char right behind it, the scorch ahead of it */
  --calm-ember: rgb(255 150 60);
  --calm-char: rgb(40 18 8);
  --calm-scorch: rgb(120 70 30 / 0.5);
  --font-ui: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-hand: 'Caveat', 'Segoe Print', 'Bradley Hand', cursive;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overflow-x: clip;
  background: var(--background-color-primary);
  color: var(--text-color-primary);
  font-family: var(--font-ui);
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.page-wrapper,
.main-wrapper {
  position: fixed;
  inset: 0;
}

.stage_canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  touch-action: none;
}

.stage_top {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  padding: max(1rem, env(safe-area-inset-top)) 1rem 0;
  pointer-events: none;
  text-align: center;
}

.stage_hint {
  margin: 0 auto;
  max-width: 34rem;
  /* room for the mute toggle on both sides keeps the line centred */
  padding-inline: 2.5rem;
  min-height: 2.6em;
  font-size: 0.9375rem;
  line-height: 1.35;
  color: var(--text-color-secondary);
  text-wrap: balance;
}

.stage_mute {
  position: absolute;
  top: max(0.5rem, env(safe-area-inset-top));
  right: 0.5rem;
  display: grid;
  place-items: center;
  width: 2.5rem;
  height: 2.5rem;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: transparent;
  color: var(--text-color-secondary);
  pointer-events: auto;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.stage_mute-icon {
  width: 1.5rem;
  height: 1.5rem;
  fill: currentColor;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.stage_mute[aria-pressed='true'] .is-on,
.stage_mute[aria-pressed='false'] .is-off {
  display: none;
}

.stage_to {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  max-width: 48rem;
  margin: 0.5rem auto 0;
  pointer-events: auto;
}

.stage_to-input {
  flex: none;
  width: 8rem;
  min-height: 2.25rem;
  padding: 0.375rem 0.75rem;
  border: 1px dashed var(--chip-border);
  border-radius: 999px;
  background: rgb(11 8 6 / 0.45);
  color: var(--text-color-primary);
  font: inherit;
  /* 16px: iOS zooms the page into any smaller field */
  font-size: 1rem;
}

/* the pill grows with the name where the browser can size a field to its content */
@supports (field-sizing: content) {
  .stage_to-input {
    field-sizing: content;
    width: auto;
    min-width: 8rem;
    max-width: 14rem;
  }
}

.stage_to-input::placeholder {
  color: var(--text-color-secondary);
}

.stage_to-input:focus {
  outline: 2px solid var(--text-color-accent);
  outline-offset: 1px;
  border-style: solid;
}

.stage_to-input:not(:placeholder-shown) {
  border-style: solid;
  border-color: var(--text-color-accent);
}

.stage_chips {
  display: flex;
  gap: 0.5rem;
  overflow-x: auto;
  scrollbar-width: none;
  padding: 0.125rem;
}

/* the row scrolls on phones: fade the cut instead of slicing a chip */
@media (max-width: 44.99rem) {
  .stage_chips {
    mask-image: linear-gradient(to right, black calc(100% - 2rem), transparent);
  }
}

.stage_chips::-webkit-scrollbar {
  display: none;
}

.stage_chips[data-hidden='true'],
.stage_to:has(.stage_chips[data-hidden='true']) {
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.6s ease;
}

.chip {
  flex: none;
  min-height: 2rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--chip-border);
  border-radius: 999px;
  background: rgb(11 8 6 / 0.45);
  color: var(--text-color-primary);
  font: 500 0.8125rem/1 var(--font-ui);
  cursor: pointer;
  transition:
    border-color 0.2s ease,
    background-color 0.2s ease;
}

.chip[aria-pressed='true'] {
  border-color: var(--chip-border-active);
  background: rgb(255 122 46 / 0.14);
}

.chip:focus-visible,
.stage_box:focus-visible,
.stage_mute:focus-visible,
.breath_skip:focus-visible,
.button:focus-visible {
  outline: 2px solid var(--text-color-accent);
  outline-offset: 2px;
}

/* the sheet: laid out at reference size and scaled by JS (transform), GL paints the paper under it */
.sheet {
  position: absolute;
  top: 0;
  left: 0;
  transform-origin: 0 0;
}

.sheet_area {
  display: block;
  width: 100%;
  margin: 0;
  border: 0;
  outline: 0;
  resize: none;
  overflow: hidden;
  background: transparent;
  color: var(--ink-color);
  caret-color: var(--ink-color);
}

.sheet_area::placeholder {
  color: rgb(31 43 107 / 0.38);
}

.sheet[data-mode='gl'] {
  pointer-events: none;
}

.sheet[data-mode='gl'] .sheet_area {
  color: transparent;
  caret-color: transparent;
}

.sheet[data-mode='gl'] .sheet_area::placeholder {
  color: transparent;
}

/* the salutation line (letter.ts places it), drawn in the same ink */
.sheet_to {
  position: absolute;
  margin: 0;
  color: var(--ink-color);
  white-space: nowrap;
  overflow: hidden;
  pointer-events: none;
}

.sheet[data-mode='gl'] .sheet_to {
  color: transparent;
}

.letter_mirror {
  position: fixed;
  left: -10000px;
  top: 0;
  visibility: hidden;
  pointer-events: none;
}

.stage_box {
  position: absolute;
  padding: 0;
  border: 0;
  background: transparent;
  pointer-events: none;
  border-radius: 6px;
}

/* «Чиркни по краю» lies on the box itself (placed and turned like it, index.ts): a glint runs along the striker,
   the words sit just under the box. A label floating beside it read as unrelated to the box. */
.stage_cue {
  position: absolute;
  margin: 0;
  pointer-events: none;
}

.stage_cue-trail {
  position: absolute;
  left: 6%;
  right: 6%;
  top: 93.5%; /* the striker: the dark strip along the box's bottom edge */
  height: 0.25rem;
  translate: 0 -50%;
}

.stage_cue-trail::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 0;
  width: 40%;
  border-radius: 1rem;
  background: linear-gradient(
    90deg,
    transparent,
    var(--text-color-accent) 70%,
    var(--text-color-primary)
  );
  box-shadow: 0 0 0.5rem var(--text-color-accent);
  animation: cue-swipe 1.6s ease-in infinite;
}

.stage_cue-text {
  position: absolute;
  left: 50%;
  top: 100%;
  translate: -50% 0.5rem;
  color: var(--text-color-primary);
  font-size: 0.875rem;
  white-space: nowrap;
  text-shadow: 0 1px 6px rgb(0 0 0 / 0.8);
}

.stage_cue[data-at='above'] .stage_cue-text {
  top: auto;
  bottom: 100%;
  translate: -50% -0.5rem;
}

[data-calm='true'] .stage_cue-trail {
  display: none;
}

@keyframes cue-swipe {
  0% {
    translate: -60% 0;
    opacity: 0;
  }

  20% {
    opacity: 1;
  }

  85% {
    opacity: 1;
  }

  100% {
    translate: 210% 0;
    opacity: 0;
  }
}

/* taps on the desk props (GL draws them; these carry the pointer and the keyboard focus) */
.stage_prop {
  position: absolute;
  padding: 0;
  border: 0;
  background: transparent;
  border-radius: 8px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}

.stage_prop:focus-visible {
  outline: 2px solid var(--text-color-accent);
  outline-offset: 2px;
}

.breath {
  position: absolute;
  left: 0;
  right: 0;
  bottom: max(2rem, env(safe-area-inset-bottom));
  text-align: center;
}

.breath_word {
  margin: 0 0 0.75rem;
  font: 400 3rem/1 var(--font-hand);
  color: var(--text-color-primary);
  /* `scale` breathes with the phase; JS animates `translate` and opacity on each new word */
  transition:
    opacity 1.2s ease,
    scale 4s cubic-bezier(0.45, 0, 0.55, 1);
}

.breath[data-phase='in'] .breath_word {
  scale: 1.22;
}

.breath[data-phase='out'] .breath_word {
  scale: 0.86;
  transition-duration: 1.2s, 6s;
}

/* three breaths: the one now glows, the ones done stay lit */
.breath_dots {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 0 0 1.25rem;
  transition: opacity 1.2s ease;
}

.breath_dots i {
  width: 0.375rem;
  height: 0.375rem;
  border-radius: 50%;
  background: var(--text-color-secondary);
  opacity: 0.3;
  transition:
    opacity 0.8s ease,
    background-color 0.8s ease;
}

.breath_dots i[data-s='done'] {
  background: var(--text-color-accent);
  opacity: 0.8;
}

.breath_dots i[data-s='now'] {
  background: var(--text-color-accent);
  opacity: 1;
}

.breath[data-phase='done'] .breath_word,
.breath[data-phase='done'] .breath_dots {
  opacity: 0;
}

/* «В эту минуту сгорело ещё 3 письма»: shown only when someone else burned one too */
.breath_actions {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 0.5rem;
}

.breath_skip {
  min-height: 2.5rem;
  padding: 0.5rem 1rem;
  border: 1px solid var(--chip-border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-color-secondary);
  font: 500 0.875rem/1 var(--font-ui);
  cursor: pointer;
}

.breath_sub {
  margin: -0.25rem 0 0.75rem;
  font: 500 0.875rem/1.3 var(--font-ui);
  color: var(--text-color-secondary);
}

/* «Ледяное дыхание»: the guide turns ice-blue (the coal and the ring follow in GL) */
.breath[data-ice] .breath_word {
  color: var(--text-color-ice);
}

.breath[data-ice] .breath_dots i[data-s='done'],
.breath[data-ice] .breath_dots i[data-s='now'] {
  background: var(--text-color-ice);
}

/* the practice breathes every 3 s: the count pulses with it */
.breath[data-ice='run'] .breath_word {
  transition-duration: 1.2s, 1.4s;
}

.breath[data-ice='intro'] .breath_word,
.breath[data-ice='intro'] .breath_sub,
.breath[data-ice='intro'] .breath_dots {
  display: none;
}

.ice {
  width: min(26rem, calc(100% - 2rem));
  margin: 0 auto 1rem;
}

.ice_title {
  margin: 0 0 0.75rem;
  font: 400 2.5rem/1 var(--font-hand);
  color: var(--text-color-ice);
}

.ice_text {
  margin: 0 0 0.625rem;
  font: 400 0.9375rem/1.45 var(--font-ui);
  color: var(--text-color-primary);
  text-wrap: pretty;
}

.ice_text.is-note {
  font-size: 0.8125rem;
  color: var(--text-color-secondary);
}

.ice_rounds {
  display: flex;
  justify-content: center;
  gap: 0.5rem;
  margin: 1rem 0;
}

.ice .chip[aria-pressed='true'] {
  border-color: var(--chip-border-ice);
  background: rgb(168 216 255 / 0.14);
}

.button.is-ice {
  border-color: transparent;
  background: var(--text-color-ice);
  color: var(--background-color-primary);
}

.breath_skip.is-ice {
  border-color: var(--chip-border-ice);
  color: var(--text-color-ice);
}

.breath_help {
  font-size: 0.8125rem;
  color: var(--text-color-secondary);
  opacity: 0.8;
}

.card {
  position: absolute;
  left: 50%;
  bottom: max(2rem, env(safe-area-inset-bottom));
  width: min(26.5rem, calc(100% - 2rem));
  transform: translateX(-50%);
  padding: 1.5rem;
  border: 1px solid var(--chip-border);
  border-radius: 14px;
  background: rgb(11 8 6 / 0.72);
  backdrop-filter: blur(8px);
  text-align: center;
  /* never taller than the screen: the picture gives way to the lines and the buttons (320×568 with a number,
     a personal count and today's line ran 17 px over the top) */
  display: flex;
  flex-direction: column;
  max-height: calc(100svh - max(2rem, env(safe-area-inset-bottom)) - 0.75rem);
  overflow-y: auto;
}

.card > * {
  flex-shrink: 0;
}

.card_img {
  display: block;
  /* as tall as the screen allows, never wider than the panel (at 390 px the height alone made it 351 px
     wide in a 310 px panel) */
  width: min(100%, calc(min(50svh, 30rem) * 0.8));
  height: auto;
  aspect-ratio: 4 / 5;
  margin: 0 auto 1rem;
  border-radius: 8px;
  flex-shrink: 1;
  min-height: 7rem;
  object-fit: contain;
}

/* 320×568: the panel ran 25 px over the top with a half-screen picture */
@media (max-height: 37.5rem) {
  .card_img {
    width: min(100%, calc(40svh * 0.8));
  }
}

.card_no {
  margin: -0.25rem 0 0.25rem;
  color: var(--text-color-primary);
  font-size: 1rem;
  line-height: 1.4;
}

.card_mine {
  color: inherit;
  text-decoration-line: underline;
  text-decoration-style: dotted;
  text-decoration-color: var(--text-color-secondary);
  text-underline-offset: 0.2em;
}

.card_mine:focus-visible {
  outline: 2px solid var(--text-color-accent);
  outline-offset: 2px;
}

.card_no:not([hidden]) + .card_count {
  margin-top: 0;
}

.card_count {
  margin: -0.25rem 0 1rem;
  color: var(--text-color-secondary);
  font-size: 0.875rem;
  line-height: 1.4;
}

.card_actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 0.5rem;
}

.button {
  min-height: 3rem;
  padding: 0.5rem 1.5rem;
  border: 1px solid var(--chip-border);
  border-radius: 999px;
  background: transparent;
  color: var(--text-color-primary);
  font: 600 0.9375rem/1 var(--font-ui);
  cursor: pointer;
}

.button.is-primary {
  border-color: transparent;
  background: var(--text-color-accent);
  color: var(--background-color-primary);
}

/* calm version (no WebGL2, or «reduce motion»): the desk is a photo, the sheet is its own paper canvas,
   and the burn is a ring that grows from the touch (JS sets --bx/--by/--r in sheet px) */
[data-calm='true'] .main-wrapper {
  background: var(--background-color-primary) url('img/desk.webp') center / 77rem auto repeat;
}

[data-calm='true'] .stage_canvas {
  display: none;
}

[data-calm='true'] .sheet {
  background-size: 100% 100%;
  filter: drop-shadow(0.25rem 0.5rem 0.75rem rgb(0 0 0 / 0.55));
}

[data-calm='true'] .stage_box {
  background: url('img/matchbox.webp') center / contain no-repeat;
  pointer-events: auto;
  cursor: pointer;
}

[data-calm='true'] .sheet[data-burn] {
  mask-image: radial-gradient(
    circle at var(--bx) var(--by),
    transparent var(--r, 0),
    black calc(var(--r, 0) + 0.5rem)
  );
}

[data-calm='true'] .sheet[data-burn]::before {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  background: radial-gradient(
    circle at var(--bx) var(--by),
    var(--calm-ember) var(--r, 0),
    var(--calm-char) calc(var(--r, 0) + 1rem),
    var(--calm-scorch) calc(var(--r, 0) + 4rem),
    transparent calc(var(--r, 0) + 9rem)
  );
}

[hidden] {
  display: none !important;
}

@media (prefers-reduced-motion: reduce) {
  .stage_cue-trail::after {
    width: 100%;
    opacity: 0.55;
    animation: none;
  }

  .breath_word {
    transition: none;
    scale: none !important;
  }
}
