:root {
  color-scheme: dark;
  --bg: #1a1716;
  --panel: rgba(28, 23, 22, 0.84);
  --panel-border: rgba(255, 240, 231, 0.14);
  --text: #f6ede7;
  --muted: rgba(246, 237, 231, 0.74);
  --accent: #f3d7c2;
  --shadow: rgba(0, 0, 0, 0.34);
  --button: rgba(255, 245, 240, 0.08);
  --focus-x: 50%;
  --focus-y: 40%;
  --orbit-shift: 0px;
  --orbit-tilt: -5deg;
  --fragment-scale: 1;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  overflow-y: auto;
  background:
    radial-gradient(circle at top, rgba(255, 219, 188, 0.14), transparent 32%),
    linear-gradient(180deg, #2e2724 0%, #181413 58%, #100d0d 100%);
  font-family: "Georgia", "Times New Roman", serif;
  color: var(--text);
}

body {
  touch-action: none;
}

button,
canvas,
.stage {
  touch-action: none;
}

.app-shell {
  position: relative;
  width: 100vw;
  min-height: 100vh;
  min-height: 100svh;
  min-height: calc(var(--app-height, 1vh) * 100);
}

.stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: rgba(10, 8, 8, 0.7);
  isolation: isolate;
}

.fragment-layer,
.draw-layer,
.vignette {
  position: absolute;
  inset: 0;
}

.fragment-layer {
  background-repeat: no-repeat;
  background-color: #160f0e;
  filter: saturate(0.92) contrast(1.06) brightness(0.98);
  transform: scale(var(--fragment-scale));
  transition:
    transform 320ms ease,
    opacity 320ms ease,
    filter 320ms ease;
}

.fragment-layer.fragment-swap {
  transform: scale(1.018);
  opacity: 0.9;
  filter: saturate(0.84) contrast(1.1) brightness(0.95);
}

.draw-layer {
  width: 100%;
  height: 100%;
}

.poem-orbit {
  display: none;
  position: absolute;
  left: clamp(1rem, 3vw, 2.5rem);
  top: clamp(1rem, 6vh, 4rem);
  z-index: 2;
  width: min(24rem, calc(100vw - 2.5rem));
  padding: 1rem 1.1rem;
  border: 1px solid rgba(255, 239, 228, 0.14);
  border-radius: 1.4rem;
  background:
    linear-gradient(135deg, rgba(24, 17, 16, 0.78), rgba(24, 17, 16, 0.28)),
    rgba(17, 11, 10, 0.22);
  backdrop-filter: blur(18px);
  box-shadow: 0 18px 46px rgba(0, 0, 0, 0.2);
  transform: translate3d(var(--orbit-shift), 0, 0) rotate(var(--orbit-tilt));
  animation: orbitFloat 11s ease-in-out infinite;
}

.poem-line,
.poem-counter {
  margin: 0;
}

.poem-line {
  font-size: clamp(1rem, 2vw, 1.28rem);
  line-height: 1.35;
  color: rgba(255, 244, 236, 0.92);
  text-wrap: balance;
}

.poem-counter {
  display: inline-flex;
  margin-top: 0.75rem;
  padding: 0.3rem 0.7rem;
  border-radius: 999px;
  background: rgba(255, 244, 236, 0.08);
  color: rgba(255, 233, 220, 0.78);
  font-size: 0.72rem;
  letter-spacing: 0.12em;
  text-transform: uppercase;
}

.vignette {
  pointer-events: none;
  z-index: 3;
  background:
    linear-gradient(180deg, rgba(0, 0, 0, 0.24), transparent 20%, transparent 72%, rgba(0, 0, 0, 0.24)),
    radial-gradient(circle at var(--focus-x) var(--focus-y), transparent 42%, rgba(0, 0, 0, 0.24) 100%);
}

.hud {
  display: none;
  position: absolute;
  left: max(1rem, env(safe-area-inset-left));
  right: max(1rem, env(safe-area-inset-right));
  bottom: max(1rem, env(safe-area-inset-bottom));
  width: min(28rem, calc(100vw - 2rem));
  padding: 1rem 1rem 1.1rem;
  border: 1px solid var(--panel-border);
  border-radius: 1.5rem;
  background: var(--panel);
  backdrop-filter: blur(18px);
  box-shadow: 0 20px 50px var(--shadow);
}

.eyebrow,
.instructions,
.note,
.label {
  color: var(--muted);
}

.eyebrow {
  margin: 0 0 0.35rem;
  font-size: 0.78rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
}

h1 {
  margin: 0;
  font-size: clamp(1.6rem, 4vw, 2.2rem);
  font-weight: 500;
  line-height: 0.95;
}

.instructions,
.note {
  margin: 0.8rem 0 0;
  font-size: 0.94rem;
  line-height: 1.45;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 0.7rem 1rem;
  margin-top: 1rem;
}

.status-grid strong,
.label {
  display: block;
}

.label {
  margin-bottom: 0.2rem;
  font-size: 0.74rem;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.status-grid strong {
  font-size: 1rem;
  font-weight: 500;
}

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 0.65rem;
  margin-top: 1rem;
}

button {
  appearance: none;
  border: 1px solid rgba(255, 245, 240, 0.16);
  border-radius: 999px;
  background: var(--button);
  color: var(--text);
  padding: 0.75rem 1rem;
  font: inherit;
  font-size: 0.94rem;
  cursor: pointer;
  transition:
    transform 120ms ease,
    background 120ms ease,
    border-color 120ms ease;
}

button:hover,
button:focus-visible {
  transform: translateY(-1px);
  background: rgba(255, 245, 240, 0.14);
  border-color: rgba(255, 245, 240, 0.34);
  outline: none;
}

button[aria-pressed="true"] {
  background: rgba(243, 215, 194, 0.18);
  border-color: rgba(243, 215, 194, 0.4);
}

code {
  font-family: "SF Mono", "Menlo", monospace;
  font-size: 0.88em;
}

@media (max-width: 700px) {
  .poem-orbit {
    left: 0.8rem;
    top: 0.8rem;
    width: min(19rem, calc(100vw - 1.6rem));
    padding: 0.9rem 0.95rem;
    border-radius: 1.15rem;
  }

  .poem-line {
    font-size: 0.94rem;
  }

  .hud {
    width: auto;
    border-radius: 1.2rem;
    padding: 0.9rem;
  }

  .instructions,
  .note {
    font-size: 0.88rem;
  }

  .controls {
    gap: 0.5rem;
  }

  button {
    flex: 1 1 9rem;
    min-height: 2.8rem;
  }
}

@keyframes orbitFloat {
  0%,
  100% {
    transform: translate3d(var(--orbit-shift), 0, 0) rotate(var(--orbit-tilt));
  }

  50% {
    transform: translate3d(calc(var(--orbit-shift) * -0.55), -10px, 0)
      rotate(calc(var(--orbit-tilt) * -0.4));
  }
}
