:root {
  --text: #eef3f8;
  --muted: rgba(238, 243, 248, 0.64);
  --faint: rgba(238, 243, 248, 0.38);
  --glass: rgba(12, 16, 24, 0.4);
  --glass-strong: rgba(12, 16, 24, 0.66);
  --line: rgba(255, 255, 255, 0.1);
  --accent: #b9d3ff;
  --radius: 22px;
  --ease: cubic-bezier(0.22, 1, 0.36, 1);
  --serif: 'Fraunces', 'Iowan Old Style', Georgia, serif;
  --dim: 0;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #04060a;
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button {
  font: inherit;
  color: inherit;
  background: none;
  border: 0;
  padding: 0;
  cursor: pointer;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

svg {
  display: block;
}

#stage {
  position: fixed;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.shade {
  position: fixed;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(to bottom, rgba(0, 0, 0, 0.42), transparent 20%),
    linear-gradient(to top, rgba(0, 0, 0, 0.6), transparent 40%);
  transition: opacity 1.2s var(--ease);
}

.grain {
  position: fixed;
  inset: -50%;
  pointer-events: none;
  opacity: 0.07;
  mix-blend-mode: overlay;
  background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='180' height='180'><filter id='n'><feTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='2' stitchTiles='stitch'/><feColorMatrix values='0 0 0 0 1  0 0 0 0 1  0 0 0 0 1  0 0 0 0.6 0'/></filter><rect width='100%' height='100%' filter='url(%23n)'/></svg>");
  animation: grain 1.2s steps(6) infinite;
}

@keyframes grain {
  0% { transform: translate(0, 0); }
  20% { transform: translate(-3%, 2%); }
  40% { transform: translate(2%, -3%); }
  60% { transform: translate(-2%, -1%); }
  80% { transform: translate(3%, 3%); }
  100% { transform: translate(0, 0); }
}

.dim {
  position: fixed;
  inset: 0;
  background: #000;
  opacity: var(--dim);
  pointer-events: none;
  transition: opacity 0.3s;
}

/* ---------- Auto-hiding chrome ---------- */

.ui {
  transition: opacity 1s var(--ease), transform 1s var(--ease);
}

body.idle {
  cursor: none;
}

body.idle .ui,
body.idle .hero {
  opacity: 0;
  pointer-events: none;
}

body.idle .shade {
  opacity: 0.35;
}

/* ---------- Top bar ---------- */

.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  z-index: 5;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: max(22px, env(safe-area-inset-top)) 28px 0;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand svg {
  width: 36px;
  height: 36px;
  filter: drop-shadow(0 4px 14px rgba(160, 190, 255, 0.35));
}

.brand-name {
  display: block;
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: 0.01em;
  line-height: 1.1;
}

.brand-sub {
  display: block;
  font-size: 11px;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  margin-top: 2px;
}

.top-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

.icon-btn {
  width: 44px;
  height: 44px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px) saturate(140%);
  -webkit-backdrop-filter: blur(16px) saturate(140%);
  transition: background 0.3s, border-color 0.3s, transform 0.4s var(--ease);
}

.icon-btn:hover {
  background: rgba(255, 255, 255, 0.12);
}

.icon-btn:active {
  transform: scale(0.94);
}

.icon-btn.active {
  background: rgba(185, 211, 255, 0.18);
  border-color: rgba(185, 211, 255, 0.4);
}

.icon-btn svg {
  width: 20px;
  height: 20px;
}

.icon-btn.small {
  width: 34px;
  height: 34px;
}

.icon-btn.small svg {
  width: 16px;
  height: 16px;
}

.chip {
  height: 38px;
  padding: 0 15px 0 12px;
  border-radius: 999px;
  display: inline-flex;
  gap: 8px;
  align-items: center;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 13px;
  font-weight: 500;
  font-variant-numeric: tabular-nums;
  color: var(--accent);
}

.chip[hidden] {
  display: none;
}

.chip svg {
  width: 16px;
  height: 16px;
}

/* ---------- Hero ---------- */

.hero {
  position: fixed;
  left: 0;
  right: 0;
  top: 42%;
  transform: translateY(-50%);
  z-index: 2;
  text-align: center;
  padding: 0 24px;
  pointer-events: none;
  transition: opacity 1.6s var(--ease);
}

body.playing .hero:not(.show) {
  opacity: 0;
  transition-delay: 0.4s;
}

.eyebrow {
  margin: 0 0 16px;
  font-size: 12px;
  letter-spacing: 0.3em;
  text-transform: uppercase;
  color: var(--muted);
}

.hero h1 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 300;
  font-style: italic;
  font-size: clamp(46px, 7.4vw, 104px);
  line-height: 1;
  letter-spacing: -0.015em;
  text-shadow: 0 6px 50px rgba(0, 0, 0, 0.5);
}

.desc {
  max-width: 520px;
  margin: 20px auto 0;
  font-size: 16px;
  font-weight: 300;
  line-height: 1.65;
  color: var(--muted);
  text-shadow: 0 2px 20px rgba(0, 0, 0, 0.6);
}

.hint {
  margin: 28px 0 0;
  font-size: 12px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: var(--faint);
  animation: pulse 3.4s ease-in-out infinite;
}

body.started .hint {
  display: none;
}

.hero.swap .eyebrow,
.hero.swap h1,
.hero.swap .desc {
  animation: rise 1.4s var(--ease) both;
}

.hero.swap h1 {
  animation-delay: 0.08s;
}

.hero.swap .desc {
  animation-delay: 0.18s;
}

@keyframes rise {
  from {
    opacity: 0;
    transform: translateY(16px);
    filter: blur(8px);
  }
  to {
    opacity: 1;
    transform: none;
    filter: none;
  }
}

@keyframes pulse {
  0%, 100% { opacity: 0.5; }
  50% { opacity: 1; }
}

/* ---------- Dock ---------- */

.dock {
  position: fixed;
  left: 50%;
  bottom: max(22px, env(safe-area-inset-bottom));
  transform: translateX(-50%);
  z-index: 5;
  width: min(940px, calc(100% - 24px));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.scenes {
  display: flex;
  gap: 12px;
  max-width: 100%;
  overflow-x: auto;
  padding: 8px 6px 6px;
  scroll-snap-type: x mandatory;
  scrollbar-width: none;
}

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

.scene-card {
  flex: 0 0 auto;
  width: 132px;
  display: flex;
  flex-direction: column;
  gap: 9px;
  text-align: left;
  scroll-snap-align: center;
  opacity: 0.7;
  transition: opacity 0.4s, transform 0.5s var(--ease);
}

.scene-card .thumb {
  display: block;
  height: 80px;
  border-radius: 14px;
  background: linear-gradient(160deg, #1b2430, #0b0f14) center / cover no-repeat;
  border: 1px solid var(--line);
  box-shadow: 0 12px 30px rgba(0, 0, 0, 0.4);
  transition: border-color 0.4s, box-shadow 0.4s;
}

.scene-card .label {
  padding-left: 2px;
  font-size: 12.5px;
  font-weight: 500;
  color: var(--muted);
  white-space: nowrap;
  transition: color 0.4s;
}

.scene-card:hover {
  opacity: 1;
  transform: translateY(-3px);
}

.scene-card.active {
  opacity: 1;
}

.scene-card.active .thumb {
  border-color: rgba(185, 211, 255, 0.8);
  box-shadow: 0 0 0 3px rgba(185, 211, 255, 0.16), 0 14px 34px rgba(0, 0, 0, 0.5);
}

.scene-card.active .label {
  color: var(--text);
}

.controls {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 9px;
  border-radius: 999px;
  background: var(--glass);
  border: 1px solid var(--line);
  backdrop-filter: blur(22px) saturate(150%);
  -webkit-backdrop-filter: blur(22px) saturate(150%);
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.35);
}

.controls .icon-btn {
  background: transparent;
  border-color: transparent;
  backdrop-filter: none;
  -webkit-backdrop-filter: none;
}

.controls .icon-btn:hover {
  background: rgba(255, 255, 255, 0.1);
}

.controls .icon-btn.active {
  background: rgba(185, 211, 255, 0.18);
}

.play {
  position: relative;
  width: 64px;
  height: 64px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  color: #0b1220;
  background: radial-gradient(circle at 35% 30%, #fff, #dfe8f6);
  box-shadow: 0 10px 40px rgba(170, 200, 255, 0.28), inset 0 -2px 6px rgba(0, 0, 0, 0.08);
  transition: transform 0.45s var(--ease), box-shadow 0.45s;
}

.play:hover {
  transform: scale(1.05);
  box-shadow: 0 12px 50px rgba(170, 200, 255, 0.4);
}

.play:active {
  transform: scale(0.96);
}

.play svg {
  width: 24px;
  height: 24px;
  transition: opacity 0.2s;
}

.play .i-play {
  margin-left: 2px;
}

.play .i-pause,
body.playing .play .i-play {
  display: none;
}

body.playing .play .i-pause {
  display: block;
}

.play::before {
  content: '';
  position: absolute;
  inset: -9px;
  border-radius: 50%;
  border: 1px solid rgba(255, 255, 255, 0.4);
  opacity: 0;
  pointer-events: none;
}

body.playing .play::before {
  animation: breathe 10s ease-in-out infinite;
}

@keyframes breathe {
  0%, 100% { transform: scale(0.9); opacity: 0.08; }
  40% { transform: scale(1.22); opacity: 0.55; }
}

.spinner {
  position: absolute;
  inset: 18px;
  border-radius: 50%;
  border: 2px solid rgba(11, 18, 32, 0.15);
  border-top-color: #0b1220;
  opacity: 0;
}

.play.loading svg {
  opacity: 0;
}

.play.loading .spinner {
  opacity: 1;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

/* ---------- Panels ---------- */

.panel {
  position: fixed;
  left: 50%;
  bottom: calc(var(--dock-h, 200px) + max(22px, env(safe-area-inset-bottom)) + 14px);
  z-index: 6;
  width: min(360px, calc(100% - 24px));
  max-height: calc(100dvh - var(--dock-h, 200px) - 120px);
  overflow-y: auto;
  padding: 20px 22px 18px;
  border-radius: var(--radius);
  background: var(--glass-strong);
  border: 1px solid var(--line);
  backdrop-filter: blur(30px) saturate(160%);
  -webkit-backdrop-filter: blur(30px) saturate(160%);
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.5);
  opacity: 0;
  transform: translate(-50%, 14px) scale(0.98);
  pointer-events: none;
  transition: opacity 0.45s var(--ease), transform 0.45s var(--ease);
  scrollbar-width: thin;
}

.panel.open {
  opacity: 1;
  transform: translate(-50%, 0);
  pointer-events: auto;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}

.panel h2 {
  margin: 0;
  font-family: var(--serif);
  font-weight: 400;
  font-size: 21px;
}

.group-label {
  margin: 18px 0 12px;
  font-size: 10.5px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: var(--faint);
}

.field {
  margin-bottom: 14px;
}

.field-row {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 7px;
  font-size: 13.5px;
}

.field-row b {
  font-weight: 500;
}

.field-row span {
  font-size: 12px;
  color: var(--faint);
  font-variant-numeric: tabular-nums;
}

input[type='range'] {
  --fill: 50%;
  -webkit-appearance: none;
  appearance: none;
  display: block;
  width: 100%;
  height: 22px;
  margin: 0;
  background: transparent;
  cursor: pointer;
}

input[type='range']::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 4px;
  background: linear-gradient(to right, var(--accent) 0 var(--fill), rgba(255, 255, 255, 0.14) var(--fill) 100%);
}

input[type='range']::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 18px;
  height: 18px;
  margin-top: -7px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45), 0 0 0 4px rgba(185, 211, 255, 0.14);
  transition: transform 0.2s var(--ease);
}

input[type='range']:active::-webkit-slider-thumb {
  transform: scale(1.18);
}

input[type='range']::-moz-range-track {
  height: 4px;
  border-radius: 4px;
  background: rgba(255, 255, 255, 0.14);
}

input[type='range']::-moz-range-progress {
  height: 4px;
  border-radius: 4px;
  background: var(--accent);
}

input[type='range']::-moz-range-thumb {
  width: 18px;
  height: 18px;
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.45), 0 0 0 4px rgba(185, 211, 255, 0.14);
}

.keys {
  margin: 18px 0 0;
  font-size: 11px;
  line-height: 1.6;
  color: var(--faint);
  text-align: center;
}

.muted {
  margin: 8px 0 18px;
  font-size: 13.5px;
  line-height: 1.6;
  color: var(--muted);
}

.timer-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.timer-grid button {
  padding: 14px 0;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line);
  font-size: 14px;
  font-weight: 500;
  transition: background 0.3s, border-color 0.3s;
}

.timer-grid button:hover {
  background: rgba(255, 255, 255, 0.11);
}

.timer-grid button.active {
  background: rgba(185, 211, 255, 0.18);
  border-color: rgba(185, 211, 255, 0.55);
  color: var(--accent);
}

.timer-grid button small {
  display: block;
  margin-top: 2px;
  font-size: 10.5px;
  font-weight: 400;
  color: var(--faint);
}

.timer-status {
  margin: 16px 0 2px;
  font-size: 12.5px;
  color: var(--faint);
  text-align: center;
}

/* ---------- Sleep screen & toast ---------- */

.sleep-screen {
  position: fixed;
  inset: 0;
  z-index: 20;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  background: #000;
  opacity: 0;
  pointer-events: none;
  transition: opacity 5s ease;
}

.sleep-screen.on {
  opacity: 1;
  pointer-events: auto;
  cursor: none;
}

.sleep-screen p {
  margin: 0;
  font-family: var(--serif);
  font-style: italic;
  font-weight: 300;
  font-size: 38px;
  color: rgba(255, 255, 255, 0.22);
}

.sleep-screen span {
  font-size: 11px;
  letter-spacing: 0.22em;
  text-transform: uppercase;
  color: rgba(255, 255, 255, 0.14);
}

.toast {
  position: fixed;
  top: max(88px, calc(env(safe-area-inset-top) + 70px));
  left: 50%;
  z-index: 10;
  padding: 10px 18px;
  border-radius: 999px;
  background: var(--glass-strong);
  border: 1px solid var(--line);
  backdrop-filter: blur(16px);
  -webkit-backdrop-filter: blur(16px);
  font-size: 13px;
  white-space: nowrap;
  opacity: 0;
  transform: translate(-50%, -8px);
  transition: opacity 0.5s var(--ease), transform 0.5s var(--ease);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

/* ---------- Responsive ---------- */

@media (max-width: 640px) {
  .topbar {
    padding: max(14px, env(safe-area-inset-top)) 16px 0;
  }

  .brand-sub {
    display: none;
  }

  .scene-card {
    width: 104px;
  }

  .scene-card .thumb {
    height: 64px;
  }

  .controls {
    gap: 6px;
  }

  .desc {
    font-size: 14px;
  }

  .hero {
    top: 38%;
  }
}

@media (max-height: 600px) {
  .scenes,
  .desc {
    display: none;
  }
}

@media (prefers-reduced-motion: reduce) {
  .grain,
  .hint,
  body.playing .play::before {
    animation: none;
  }
}
