@font-face {
  font-family: "Glitch New Roman";
  src: url("./assets/GlitchNewRoman.otf") format("opentype");
  font-style: normal;
  font-weight: 400;
  font-display: block;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  overflow: hidden;
  overscroll-behavior: none;
}

html {
  background: #fff;
  color: #666;
}

body {
  margin: 0;
  min-width: 240px;
}

main {
  position: fixed;
  inset: 0;
  display: grid;
  place-items: center;
  height: 100dvh;
  /* The intact flyer sits inside the safe area. Loose glyphs can paint across it. */
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px)
    env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
  grid-template: minmax(0, 1fr) / minmax(0, 1fr);
  touch-action: pinch-zoom;
}

main, main * {
  -webkit-user-select: none;
  user-select: none;
  -webkit-touch-callout: none;
}

#surface {
  position: relative;
  width: min(100%, 70.474dvh);
  height: 100%;
  translate: 0.65% 0;
}

#flyer {
  display: block;
  width: 100%;
  height: 100%;
  overflow: visible;
}

#lettering {
  pointer-events: none;
  font-variant-ligatures: none;
  font-feature-settings: "liga" 0, "clig" 0, "kern" 0;
}

#opening-card {
  position: fixed;
  inset: 0;
  padding: inherit;
  place-content: center;
  text-align: center;
  font: clamp(20px, 4.1vw, 66px)/1.08 "Glitch New Roman", serif;
  opacity: 0;
  pointer-events: none;
  user-select: none;
  -webkit-user-select: none;
}

#opening-card:not([hidden]) {
  display: grid;
}

#opening-card > div {
  white-space: nowrap;
}

@media (max-width: 600px) {
  #opening-card {
    /* The longer title line occupies about 15 em in Glitch New Roman. */
    font-size: calc((100vw - 24px) / 15);
  }
}

#listen-button {
  justify-self: center;
  margin: 0;
  padding: 0;
  border: 0;
  background: transparent;
  color: #a0c6ee;
  font: inherit;
  text-decoration: none;
  white-space: nowrap;
  cursor: inherit;
  -webkit-appearance: none;
  appearance: none;
}

#opening-card.waiting-to-listen {
  pointer-events: auto;
  cursor: pointer;
}

@media (hover: hover) {
  #listen-button:enabled:hover {
    opacity: 0.65;
  }
}

#motion-toggle {
  position: fixed;
  z-index: 1;
  top: max(4px, env(safe-area-inset-top));
  right: max(4px, env(safe-area-inset-right));
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 0;
  background: transparent;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

#motion-toggle[hidden],
#opening-card:not([hidden]) ~ #motion-toggle {
  display: none;
}

#motion-toggle::before {
  content: "";
  width: 11px;
  height: 11px;
  border-radius: 50%;
  background: #a0c6ee;
}

#motion-toggle:disabled {
  opacity: 0.5;
  cursor: default;
}

#motion-toggle:focus-visible {
  outline: none;
}

#motion-toggle:focus-visible::before {
  background: #486e97;
}


html.toolbar-swipe {
  --swipe-page-height: calc(100lvh + 160px);
  overflow-y: auto;
  scrollbar-width: none;
}
.toolbar-swipe body {
  position: relative;
  min-height: var(--swipe-page-height);
}
.toolbar-swipe main { touch-action: pan-y pinch-zoom; }
.toolbar-swipe #surface { touch-action: pinch-zoom; }
.toolbar-swipe main::before,
.toolbar-swipe main::after {
  content: "";
  position: fixed;
  inset-inline: 0;
  z-index: 1;
  height: 22px;
}
.toolbar-swipe main::before { top: 0; }
.toolbar-swipe main::after { bottom: 0; }

.loose-ink {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100dvh;
  pointer-events: none;
}

html.document-ink {
  overflow: hidden;
  overscroll-behavior: none;
  touch-action: pinch-zoom;
}
.document-ink body {
  position: relative;
  overflow: visible;
  /* Safari sizes its bottom clip using document content height. Give the
     loose ink real paper below the controls while the root stays locked. */
  min-height: calc(100lvh + var(--ink-runway, 0px) + 192px);
}
.document-ink main {
  position: absolute;
  inset: var(--ink-runway, 0px) 0 auto;
  overflow-x: clip;
}
.document-ink #opening-card, .document-ink #motion-toggle {
  position: absolute;
}
.ink-sheet {
  position: absolute;
  width: 100%;
  pointer-events: none;
  z-index: 1;
}
.ink-sheet > .loose-ink { position: absolute; height: 100%; }

.edge-probe:not(.document-ink) body { min-height: 100lvh; }
.edge-probe body::after {
  content: "";
  position: absolute;
  z-index: 2;
  top: 0;
  left: 14px;
  width: 4px;
  height: 100lvh;
  background: repeating-linear-gradient(to bottom, #466a94 0 6px, transparent 6px 12px);
  pointer-events: none;
}
.edge-probe.document-ink body::after { top: -180px; bottom: 0; height: auto; }

.phone-setup {
  position: fixed;
  inset: 0;
  z-index: 5;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: clamp(6px, 1.2dvh, 14px);
  padding: max(24px, env(safe-area-inset-top)) max(50px, env(safe-area-inset-right))
    max(24px, env(safe-area-inset-bottom)) max(50px, env(safe-area-inset-left));
  background: white;
  color: #466a94;
  text-align: center;
  font: clamp(22px, 5.8vmin, 38px)/1.08 "Glitch New Roman", serif;
  -webkit-user-select: none;
  user-select: none;
}
.phone-setup[hidden] { display: none; }
.phone-setup p { margin: 0; max-width: 15em; text-wrap: balance; }
.phone-setup p:empty, .phone-setup > div:empty { display: none; }
.phone-qr { display: block; }
.phone-qr svg { display: block; width: min(58vw, 250px, 47dvh); height: auto; }
.phone-setup button {
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  border-radius: 0;
  background: transparent;
  font: inherit;
  padding: .4em;
  cursor: pointer;
  color: #547aa6;
}
.phone-setup :is(button, a):focus-visible, #listen-button:focus-visible {
  outline: 1px solid #547aa6;
  outline-offset: 2px;
}
.phone-setup .phone-edge {
  position: absolute;
  padding: 0;
  font-size: clamp(15px, 3.8vmin, 20px);
}
.edge-left, .edge-right { width: 48px; top: 48px; bottom: 48px; writing-mode: vertical-rl; }
.edge-left { left: env(safe-area-inset-left, 0px); transform: rotate(180deg); }
.edge-right { right: env(safe-area-inset-right, 0px); }
.edge-top, .edge-bottom { height: 48px; left: 48px; right: 48px; }
.edge-top { top: env(safe-area-inset-top, 0px); }
.edge-bottom { bottom: env(safe-area-inset-bottom, 0px); }
.phone-setup button:active { color: #36597e; }
@media (hover: hover) {
  .phone-setup button:hover { color: #36597e; }
}

.flyer-navigation {
  position: fixed;
  z-index: 10;
  top: max(8px, env(safe-area-inset-top, 0px));
  right: max(8px, env(safe-area-inset-right, 0px));
  left: max(8px, env(safe-area-inset-left, 0px));
  display: flex;
  justify-content: space-between;
  pointer-events: none;
  align-items: center;
  gap: 8px;
  color: #466a94;
  font: 18px/1.1 "Glitch New Roman", serif;
}
.flyer-navigation a, .flyer-navigation button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  padding: 0 8px;
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
  text-decoration: none;
  cursor: pointer;
  pointer-events: auto;
}
.flyer-navigation .phone-dot { width: 44px; padding: 0; margin-left: auto; }
.phone-dot::before {
  content: '';
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: currentColor;
}
.flyer-navigation :is(a, button):focus-visible {
  outline: 1px solid currentColor;
  outline-offset: 2px;
}

.flyer-navigation .phone-dot {
  opacity: 0;
  visibility: hidden;
  transition: opacity .45s ease, visibility 0s linear .45s;
}
html.flyer-loaded.paragraph-ready .phone-dot {
  opacity: 1;
  visibility: visible;
  transition-delay: 0s;
}
@media (prefers-reduced-motion: reduce) {
  .flyer-navigation .phone-dot { transition: none; }
}

.reading-controls {
  position: absolute;
  z-index: 3;
  top: var(--reading-controls-y, 17%);
  left: max(8%, env(safe-area-inset-left));
  right: max(8%, env(safe-area-inset-right));
  transform: translateY(-50%);
  display: none;
  grid-template-columns: 1fr 1fr 1fr;
  align-items: center;
  pointer-events: none;
}
.flyer-loaded.paragraph-ready .reading-controls { display: grid; }
.reading-controls button {
  justify-self: center;
  pointer-events: auto;
  color: #b5daff;
  background: none;
  border: 0;
  min-width: 44px;
  min-height: 44px;
  padding: 0 .12em;
  font: clamp(24px, 4.6vmin, 56px)/1 "Glitch New Roman", serif;
  cursor: pointer;
  transition: color .22s ease;
}
.reading-controls button:first-child { justify-self: start; }
.reading-controls button:last-child { justify-self: end; }
.reading-controls button[aria-pressed=true], .reading-controls button:hover { color: #567fa8; }
.reading-controls button:focus-visible { outline: 1px solid currentColor; outline-offset: 2px; }

@media (hover: hover) and (pointer: fine) {
  .reading-controls button { font-size: clamp(20px, 3.7vmin, 45px); }
}

.reading-controls button span { display: inline-block; }
.reading-controls button span[hidden] { display: none; }
.reading-controls[data-morphing] button span { opacity: 0; transform: translateY(-.12em); }
@media (prefers-reduced-motion: no-preference) {
  .flyer-loaded.paragraph-ready .reading-controls:not([data-morphing]) button span {
    animation: reading-entrance .48s ease-out calc(var(--order) * 95ms) backwards;
  }
  @keyframes reading-entrance {
    from { opacity: 0; transform: translateY(.14em); }
    to { opacity: 1; transform: none; }
  }
}

.lid-controls {
  display: none;
  position: fixed;
  z-index: 6;
  top: max(10px, env(safe-area-inset-top));
  right: max(14px, env(safe-area-inset-right));
  color: #456e98;
  font: 1rem/1.25 "Glitch New Roman", serif;
  text-align: right;
}
.flyer-loaded .lid-controls { display: block; }
.lid-controls .lid-debug { display: grid; gap: .45em; padding: .6em .8em; background: white; box-shadow: 0 1px 10px #567fa824; }
.lid-controls button { font: inherit; color: inherit; background: transparent; border: 0; padding: .4em 0; cursor: pointer; text-align: right; }
.lid-controls [data-mic] { opacity: .7; text-decoration: none; }
.lid-controls [data-mic][aria-pressed="true"] { opacity: 1; }
.lid-controls input { width: 7em; accent-color: #739cc3; vertical-align: middle; }
.lid-controls output { display: inline-block; min-width: 2.2em; }
.lid-controls small { display: block; max-width: 17em; justify-self: end; }
.lid-controls [hidden] { display: none; }

.morph-path-overlay {
  position: fixed; inset: 0; width: 100%; height: 100%;
  z-index: 3; pointer-events: none; opacity: 0;
  transition: opacity .72s ease-out;
}
.morph-path-overlay.tracking-active { opacity: 1; transition-duration: .12s; }
@media (prefers-reduced-motion: reduce) {
  .morph-path-overlay { display: none; }
}
