:root {
  color-scheme: dark;
  --ink: #180d2b;
  --ink-deep: #0c0718;
  --paper: #fff8e7;
  --muted: #cdbfda;
  --gold: #ffd166;
  --coral: #ff6f91;
  --mint: #75e4c2;
  --violet: #9d7bff;
  --edge: rgba(255, 248, 231, 0.2);
  --safe-top: max(18px, env(safe-area-inset-top));
  --safe-right: max(18px, env(safe-area-inset-right));
  --safe-bottom: max(18px, env(safe-area-inset-bottom));
  --safe-left: max(18px, env(safe-area-inset-left));
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-width: 320px;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: var(--ink);
}

body {
  color: var(--paper);
  font-family: "Trebuchet MS", "Avenir Next", Avenir, system-ui, sans-serif;
  -webkit-font-smoothing: antialiased;
}

button,
kbd {
  font: inherit;
}

button {
  color: inherit;
}

.app {
  position: relative;
  width: 100%;
  height: 100dvh;
  min-height: 520px;
  isolation: isolate;
  overflow: hidden;
  background:
    radial-gradient(circle at 50% 47%, rgba(157, 123, 255, 0.2), transparent 27%),
    linear-gradient(145deg, #1e1034 0%, var(--ink) 55%, var(--ink-deep) 100%);
}

#world {
  position: absolute;
  inset: 0;
  z-index: -3;
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
  cursor: default;
}

.app.is-drawing #world {
  cursor: crosshair;
}

.vignette {
  position: absolute;
  inset: 0;
  z-index: -2;
  pointer-events: none;
  background:
    radial-gradient(circle at center, transparent 18%, rgba(12, 7, 24, 0.05) 50%, rgba(12, 7, 24, 0.68) 108%),
    linear-gradient(to bottom, rgba(12, 7, 24, 0.12), transparent 28%, transparent 72%, rgba(12, 7, 24, 0.48));
}

.masthead,
.footer {
  position: absolute;
  z-index: 5;
  left: var(--safe-left);
  right: var(--safe-right);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  text-transform: uppercase;
  letter-spacing: 0.13em;
  font-size: 11px;
  font-weight: 800;
}

.masthead {
  top: var(--safe-top);
}

.masthead p,
.footer p {
  margin: 0;
}

.date,
.footer {
  color: rgba(255, 248, 231, 0.62);
}

.sound {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  min-height: 44px;
  padding: 8px 2px 8px 14px;
  border: 0;
  background: transparent;
  text-transform: uppercase;
  letter-spacing: 0.12em;
  font-size: 11px;
  font-weight: 800;
  cursor: pointer;
}

.sound > span:first-child {
  display: grid;
  width: 24px;
  height: 24px;
  place-items: center;
  border: 1px solid rgba(255, 248, 231, 0.46);
  border-radius: 50%;
  color: var(--gold);
  font-size: 20px;
  transition: transform 200ms ease, background 200ms ease;
}

.sound[aria-pressed="true"] > span:first-child {
  background: var(--gold);
  color: var(--ink);
  transform: scale(0.82);
}

.panel {
  position: absolute;
  z-index: 4;
  text-align: center;
  transition: opacity 500ms ease, transform 600ms cubic-bezier(0.16, 1, 0.3, 1);
}

.panel[hidden] {
  display: block;
  visibility: hidden;
  opacity: 0;
  pointer-events: none;
  transform: translateY(16px);
}

.kicker {
  margin: 0 0 12px;
  color: var(--gold);
  text-transform: uppercase;
  letter-spacing: 0.2em;
  font-size: 11px;
  font-weight: 900;
}

.intro {
  top: 22%;
  left: max(6vw, 46px);
  width: min(460px, 36vw);
  text-align: left;
}

.intro[hidden] {
  transform: translateY(16px);
}

h1,
h2,
p {
  text-wrap: balance;
}

h1,
h2 {
  font-family: Georgia, "Times New Roman", serif;
  font-weight: 400;
}

h1 {
  margin: 0;
  font-size: clamp(44px, 5vw, 68px);
  line-height: 0.9;
  letter-spacing: -0.055em;
  text-shadow: 0 4px 30px rgba(12, 7, 24, 0.6);
}

.intro-copy {
  width: min(390px, 100%);
  margin: 22px 0 24px;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: clamp(17px, 2vw, 21px);
  line-height: 1.45;
}

.primary {
  position: relative;
  min-height: 50px;
  padding: 14px 24px;
  overflow: hidden;
  border: 1px solid var(--gold);
  border-radius: 999px;
  background: var(--gold);
  color: var(--ink-deep);
  font-weight: 900;
  letter-spacing: 0.01em;
  box-shadow: 0 10px 34px rgba(12, 7, 24, 0.3);
  cursor: pointer;
  transition: transform 160ms ease, box-shadow 160ms ease, background 160ms ease;
}

.primary:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 38px rgba(12, 7, 24, 0.45);
  background: #ffda7f;
}

.primary:active {
  transform: translateY(1px) scale(0.98);
}

.return-note {
  margin: 12px 0 0;
  color: var(--mint);
  font-size: 12px;
}

.gesture-panel {
  top: 16%;
  left: 50%;
  width: min(520px, calc(100% - 36px));
  transform: translateX(-50%);
  pointer-events: none;
}

.gesture-panel[hidden] {
  transform: translate(-50%, 16px);
}

.gesture-panel h2,
.passage-panel h2,
.finale h2 {
  margin: 0;
  font-size: clamp(30px, 4.5vw, 55px);
  line-height: 1;
  letter-spacing: -0.04em;
}

.gesture-panel > p:not(.kicker),
.passage-panel > p:not(.kicker),
.finale > p:not(.kicker) {
  margin: 13px auto 0;
  color: var(--muted);
  font-family: Georgia, "Times New Roman", serif;
  font-size: 16px;
  line-height: 1.4;
}

.key-hint {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 5px;
  margin-top: 15px;
  color: rgba(255, 248, 231, 0.58);
  text-transform: uppercase;
  letter-spacing: 0.09em;
  font-size: 9px;
  font-weight: 900;
}

kbd {
  min-width: 24px;
  padding: 4px 6px;
  border: 1px solid rgba(255, 248, 231, 0.28);
  border-radius: 6px;
  background: rgba(255, 248, 231, 0.08);
  color: var(--paper);
  font-size: 10px;
  box-shadow: 0 2px 0 rgba(255, 248, 231, 0.12);
}

.passage-panel {
  top: 14%;
  left: 50%;
  width: min(600px, calc(100% - 40px));
  transform: translateX(-50%);
}

.passage-panel[hidden] {
  transform: translate(-50%, 16px);
}

.passage-panel .primary {
  margin-top: 20px;
}

.finale {
  top: 12%;
  left: 50%;
  width: min(650px, calc(100% - 40px));
  transform: translateX(-50%);
}

.finale[hidden] {
  transform: translate(-50%, 16px);
}

.finale h2 {
  font-size: clamp(38px, 6vw, 74px);
}

.finale > p:not(.kicker) {
  color: var(--gold);
  font-size: clamp(19px, 2.3vw, 26px);
}

.final-actions {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 10px 20px;
  margin-top: 22px;
}

.text-button {
  min-height: 44px;
  padding: 8px 4px;
  border: 0;
  border-bottom: 1px solid rgba(255, 248, 231, 0.4);
  background: transparent;
  color: var(--paper);
  font-size: 13px;
  cursor: pointer;
}

.footer {
  bottom: var(--safe-bottom);
  min-height: 32px;
}

.footer p {
  max-width: 34%;
  line-height: 1.35;
}

.generation-dots {
  position: absolute;
  left: 50%;
  display: flex;
  gap: 7px;
  transform: translateX(-50%);
}

.generation-dots span {
  width: 6px;
  height: 6px;
  border: 1px solid rgba(255, 248, 231, 0.42);
  border-radius: 50%;
  background: transparent;
  transition: background 400ms ease, transform 400ms ease;
}

.generation-dots span.is-lit {
  background: var(--coral);
  border-color: var(--coral);
  transform: scale(1.35);
}

.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0, 0, 0, 0);
  white-space: nowrap;
  border: 0;
}

:focus-visible {
  outline: 3px solid var(--mint);
  outline-offset: 4px;
}

.qa-ready .panel {
  transition: none !important;
}

@media (max-width: 720px) {
  .app {
    min-height: 480px;
  }

  .masthead,
  .footer {
    font-size: 9px;
  }

  .sound-label {
    display: none;
  }

  .intro {
    top: 14%;
    left: 50%;
    width: min(680px, calc(100% - 40px));
    text-align: center;
    transform: translateX(-50%);
  }

  .intro[hidden] {
    transform: translate(-50%, 16px);
  }

  .gesture-panel,
  .passage-panel {
    top: 12%;
  }

  .finale {
    top: 9%;
  }

  .footer > p:last-child {
    max-width: 92px;
    text-align: right;
  }

  .footer #chapter {
    max-width: 105px;
  }

  .intro-copy {
    width: min(420px, 90%);
    margin-right: auto;
    margin-left: auto;
    margin-top: 16px;
    margin-bottom: 17px;
  }

  .key-hint {
    display: none;
  }
}

@media (max-height: 650px) {
  .intro,
  .gesture-panel,
  .passage-panel,
  .finale {
    top: 10%;
  }

  .intro-copy {
    margin-top: 12px;
    margin-bottom: 13px;
  }

  h1 {
    font-size: clamp(38px, 9vh, 62px);
  }

  .gesture-panel > p:not(.kicker),
  .passage-panel > p:not(.kicker) {
    margin-top: 8px;
  }

  .key-hint {
    margin-top: 8px;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
  }
}
