:root {
  color-scheme: dark;
  --bg: #0b0b0f;
  --panel: rgba(20, 20, 27, 0.94);
  --panel-solid: #14141b;
  --text: #f7f7fb;
  --muted: #a8a8b6;
  --line: rgba(255, 255, 255, 0.11);
  --accent: #8c7bff;
  --accent-strong: #a89cff;
  --danger: #ff6b7d;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  overscroll-behavior: none;
}

body {
  min-height: 100dvh;
  overflow: hidden;
}

button, input, label, select { font: inherit; }
button, label { -webkit-tap-highlight-color: transparent; }
button { color: inherit; }
button:disabled,
input:disabled,
select:disabled {
  cursor: not-allowed;
  opacity: 0.52;
}
select {
  color: var(--text);
  background: rgba(255,255,255,0.06);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 12px;
}
select option {
  color: #111118;
  background: #ffffff;
}
select option:checked {
  color: #111118;
  background: #9ac8ff;
}

.app-shell {
  height: 100dvh;
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  background:
    radial-gradient(circle at 50% -10%, rgba(140, 123, 255, 0.18), transparent 34%),
    var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(12px + var(--safe-top)) 18px 10px;
  z-index: 5;
  transition: opacity 180ms ease, transform 180ms ease;
}

.topbar h1 { margin: 0; font-size: 20px; letter-spacing: -0.02em; }
.topbar p { margin: 2px 0 0; color: var(--muted); font-size: 12px; }

.icon-button,
.round-button,
.play-button {
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.07);
  display: grid;
  place-items: center;
  cursor: pointer;
}

.icon-button {
  width: 42px;
  height: 42px;
  border-radius: 14px;
  font-size: 22px;
}

.viewer {
  position: relative;
  min-height: 0;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: #000;
}

.viewer::after {
  content: "";
  position: absolute;
  inset: 0;
  pointer-events: none;
  box-shadow: inset 0 0 70px rgba(0,0,0,0.32);
}

.photo-stage {
  position: absolute;
  inset: 0;
}

.stage-image {
  position: absolute;
  inset: 0;
  display: block;
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  margin: auto;
  object-fit: contain;
  object-position: center center;
  image-orientation: from-image;
  user-select: none;
  -webkit-user-drag: none;
  opacity: 0;
  transition: none;
  will-change: transform, opacity;
}

.stage-image.is-active {
  opacity: 1;
}

  to { transform: scale(1.04); }
}

.empty-state {
  max-width: 360px;
  text-align: center;
  padding: 28px;
  z-index: 2;
}

.empty-icon {
  width: 74px;
  height: 74px;
  border-radius: 24px;
  display: grid;
  place-items: center;
  margin: 0 auto 18px;
  background: rgba(140,123,255,0.14);
  border: 1px solid rgba(168,156,255,0.32);
  font-size: 38px;
}

.empty-state h2 { margin: 0; font-size: 23px; letter-spacing: -0.025em; }
.empty-state p { margin: 10px 0 20px; color: var(--muted); line-height: 1.45; font-size: 15px; }

.primary-button,
.secondary-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 44px;
  border-radius: 14px;
  border: 1px solid transparent;
  padding: 0 17px;
  text-decoration: none;
  cursor: pointer;
  font-weight: 650;
}

.primary-button {
  background: var(--accent);
  color: white;
  box-shadow: 0 9px 28px rgba(140,123,255,0.28);
}

.secondary-button {
  background: rgba(255,255,255,0.07);
  border-color: var(--line);
}

.secondary-button.danger { color: var(--danger); }

.viewer-tap-zone {
  position: absolute;
  top: 0;
  bottom: 0;
  border: 0;
  background: transparent;
  z-index: 2;
}
.viewer-tap-zone.left { left: 0; width: 24%; }
.viewer-tap-zone.center { left: 24%; width: 52%; }
.viewer-tap-zone.right { right: 0; width: 24%; }

.counter {
  position: absolute;
  right: 14px;
  bottom: 14px;
  z-index: 3;
  padding: 6px 10px;
  border-radius: 999px;
  background: rgba(0,0,0,0.58);
  color: rgba(255,255,255,0.9);
  font-size: 12px;
  backdrop-filter: blur(12px);
}

.controls {
  padding: 14px 18px calc(12px + var(--safe-bottom));
  background: var(--panel);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(22px);
  z-index: 5;
  max-height: 45dvh;
  overflow-y: auto;
  transition: opacity 180ms ease, transform 180ms ease, max-height 180ms ease, padding 180ms ease;
}

.app-shell.controls-hidden .controls {
  opacity: 0;
  transform: translateY(100%);
  pointer-events: none;
  max-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  border-top-color: transparent;
}

.app-shell.controls-hidden .topbar {
  opacity: 0;
  transform: translateY(-100%);
  pointer-events: none;
}

.transport-row {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 22px;
}

.round-button {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  font-size: 32px;
  line-height: 1;
}

.play-button {
  width: 66px;
  height: 66px;
  border-radius: 50%;
  background: var(--accent);
  border-color: transparent;
  font-size: 23px;
  box-shadow: 0 10px 30px rgba(140,123,255,0.31);
}

.play-button:active,
.primary-button:active,
.secondary-button:active,
.round-button:active,
.icon-button:active { transform: scale(0.97); }

.speed-panel {
  margin: 14px auto 0;
  max-width: 600px;
}

.speed-heading {
  display: flex;
  justify-content: space-between;
  align-items: baseline;
  margin-bottom: 8px;
  color: var(--muted);
  font-size: 13px;
}

.speed-heading output {
  color: var(--text);
  font-weight: 700;
  font-size: 15px;
}

#speedRange { width: 100%; accent-color: var(--accent); }

.speed-presets {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 7px;
  margin-top: 8px;
}

.speed-presets button {
  border: 1px solid var(--line);
  border-radius: 10px;
  min-height: 34px;
  background: rgba(255,255,255,0.05);
  cursor: pointer;
}
.speed-presets button.active {
  border-color: var(--accent-strong);
  background: rgba(140,123,255,0.18);
}

.options-row,
.library-row {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 12px;
  margin-top: 12px;
}

.library-row-wrap,
.options-row {
  flex-wrap: wrap;
}

.switch-row {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  min-height: 40px;
  padding: 0 13px;
  border: 1px solid var(--line);
  background: rgba(255,255,255,0.05);
  border-radius: 12px;
  color: var(--muted);
  cursor: pointer;
}
.switch-row input { accent-color: var(--accent); }

.privacy-note {
  margin: 10px 0 0;
  color: var(--muted);
  text-align: center;
  font-size: 11px;
}

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

dialog {
  width: min(88vw, 400px);
  border: 1px solid var(--line);
  border-radius: 22px;
  color: var(--text);
  background: var(--panel-solid);
  box-shadow: 0 24px 80px rgba(0,0,0,0.5);
}
dialog::backdrop { background: rgba(0,0,0,0.7); backdrop-filter: blur(5px); }
dialog h2 { margin-top: 0; }
dialog p { color: var(--muted); line-height: 1.4; }
.dialog-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 20px; flex-wrap: wrap; }

.export-form .field {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.export-form .field span,
.dialog-note {
  color: var(--muted);
  font-size: 13px;
}

@media (orientation: landscape) and (max-height: 540px) {
  .app-shell { grid-template-columns: minmax(0, 1fr) 320px; grid-template-rows: auto minmax(0, 1fr); }
  .topbar { grid-column: 1; grid-row: 1; }
  .viewer { grid-column: 1; grid-row: 2; }
  .controls { grid-column: 2; grid-row: 1 / span 2; max-height: none; border-top: 0; border-left: 1px solid var(--line); padding-top: calc(14px + var(--safe-top)); }
  .app-shell.controls-hidden { grid-template-columns: minmax(0, 1fr) 0; }
}

.app-shell.fill-mode .stage-image {
  width: 100%;
  height: 100%;
  max-width: none;
  max-height: none;
  object-fit: cover;
}

.viewer-status {
  position: absolute;
  left: 50%;
  bottom: 54px;
  z-index: 6;
  transform: translateX(-50%);
  max-width: calc(100% - 36px);
  padding: 9px 13px;
  border-radius: 999px;
  background: rgba(20, 20, 27, 0.88);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 12px;
  text-align: center;
  white-space: nowrap;
  backdrop-filter: blur(14px);
}

.export-overlay {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: grid;
  place-items: center;
  padding: calc(24px + var(--safe-top)) 22px calc(24px + var(--safe-bottom));
  background: rgba(3, 3, 7, 0.78);
  backdrop-filter: blur(18px) saturate(1.18);
  opacity: 1;
  transform: translateZ(0);
}

.export-overlay[hidden] {
  display: none !important;
}

.export-panel {
  width: min(420px, 100%);
  min-height: 318px;
  display: grid;
  align-content: center;
  justify-items: center;
  gap: 18px;
  padding: 34px 26px;
  border: 1px solid rgba(255,255,255,0.13);
  border-radius: 28px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.09), rgba(255,255,255,0.035)),
    rgba(15, 15, 22, 0.92);
  box-shadow:
    0 36px 110px rgba(0,0,0,0.62),
    inset 0 1px 0 rgba(255,255,255,0.12);
  text-align: center;
}

.export-phase {
  min-height: 30px;
  font-size: 25px;
  font-weight: 750;
  letter-spacing: 0;
}

.export-prep,
.export-progress,
.export-complete,
.export-message {
  width: 100%;
  display: grid;
  justify-items: center;
  gap: 13px;
}

.export-spinner {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  border: 3px solid rgba(255,255,255,0.18);
  border-top-color: var(--text);
  animation: export-spin 820ms linear infinite;
}

.export-prep-text,
.export-time,
.export-keep-open,
.export-message {
  color: var(--muted);
  font-size: 15px;
  line-height: 1.35;
}

.export-progress-track {
  width: min(330px, 100%);
  height: 16px;
  overflow: hidden;
  border-radius: 999px;
  background: rgba(255,255,255,0.13);
  box-shadow:
    inset 0 1px 2px rgba(0,0,0,0.45),
    0 0 0 1px rgba(255,255,255,0.08);
}

.export-progress-fill {
  width: 0%;
  height: 100%;
  border-radius: inherit;
  background:
    linear-gradient(90deg, #7cc8ff, #a89cff 48%, #ffffff);
  box-shadow: 0 0 24px rgba(168,156,255,0.38);
  transition: width 120ms linear;
  will-change: width;
}

.export-percent {
  min-height: 58px;
  font-size: 52px;
  font-weight: 760;
  line-height: 1;
  letter-spacing: 0;
}

.export-frame {
  min-height: 24px;
  color: var(--text);
  font-size: 18px;
  font-weight: 650;
}

.export-time,
.export-keep-open {
  min-height: 20px;
}

.export-check {
  width: 78px;
  height: 78px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  background: rgba(70, 211, 146, 0.16);
  border: 1px solid rgba(112, 239, 177, 0.42);
  color: #8ff5bd;
  font-size: 48px;
  font-weight: 760;
  animation: export-ready-pop 360ms cubic-bezier(.2, .9, .2, 1.2) both;
}

.export-ready {
  min-height: 31px;
  font-size: 26px;
  font-weight: 750;
  letter-spacing: 0;
}

.export-message {
  min-height: 118px;
  align-content: center;
  color: var(--text);
  font-size: 22px;
  font-weight: 720;
  line-height: 1.28;
  white-space: pre-line;
}

.export-share-button {
  min-width: 190px;
}

.app-shell.is-exporting {
  pointer-events: none;
  user-select: none;
}

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

@keyframes export-ready-pop {
  from {
    opacity: 0;
    transform: scale(0.84);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.app-shell.controls-hidden {
  grid-template-rows: 0 minmax(0, 1fr) 0;
}

.app-shell.controls-hidden .topbar {
  height: 0;
  min-height: 0;
  padding-top: 0;
  padding-bottom: 0;
  overflow: hidden;
}

@media (orientation: landscape) and (max-height: 540px) {
  .app-shell.controls-hidden {
    grid-template-columns: minmax(0, 1fr) 0;
    grid-template-rows: 0 minmax(0, 1fr);
  }
}


/* Version 5: keep the empty-state picker above all invisible viewer controls. */
.empty-state {
  position: relative;
  z-index: 4;
}

.viewer-tap-zone[hidden] {
  display: none !important;
}
