:root {
  color-scheme: dark;
  --bg: #070604;
  --surface: #15110c;
  --surface-strong: #21190e;
  --text: #fff8ea;
  --muted: #b8aa91;
  --line: rgba(234, 190, 90, 0.28);
  --gold: #d6a43d;
  --gold-strong: #f0c76a;
  --white: #fffaf0;
  --shadow: 0 18px 60px rgba(0, 0, 0, 0.38);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "Noto Sans TC", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  min-height: 100%;
  margin: 0;
  overflow-x: hidden;
  color: var(--text);
  background:
    linear-gradient(145deg, rgba(214, 164, 61, 0.1), transparent 34%),
    linear-gradient(180deg, #050403 0%, #100d09 58%, #070604 100%);
  letter-spacing: 0;
}

@keyframes screen-enter {
  from {
    opacity: 0;
    transform: translateY(10px) scale(0.992);
  }

  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

@keyframes logo-breathe {
  0%,
  100% {
    filter:
      drop-shadow(0 22px 42px rgba(0, 0, 0, 0.55))
      drop-shadow(0 0 16px rgba(240, 199, 106, 0.14));
    transform: translateY(0) scale(1);
  }

  50% {
    filter:
      drop-shadow(0 26px 50px rgba(0, 0, 0, 0.62))
      drop-shadow(0 0 28px rgba(240, 199, 106, 0.28));
    transform: translateY(-3px) scale(1.015);
  }
}

@keyframes icon-pulse {
  0%,
  100% {
    box-shadow: 0 0 0 0 rgba(240, 199, 106, 0);
    transform: translateY(0);
  }

  45% {
    box-shadow: 0 0 0 7px rgba(240, 199, 106, 0.08);
    transform: translateY(-1px);
  }
}

@keyframes primary-glow {
  0%,
  100% {
    filter: brightness(1);
  }

  45% {
    filter: brightness(1.06);
  }
}

button,
input {
  font: inherit;
}

button {
  border: 0;
}

svg {
  width: 1.08rem;
  height: 1.08rem;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 2;
}

h1,
h2,
p {
  margin: 0;
}

.visually-hidden {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
  white-space: nowrap;
}

h1 {
  font-size: clamp(2.55rem, 12vw, 4.1rem);
  line-height: 0.96;
  font-weight: 900;
}

h2 {
  font-size: clamp(1.7rem, 7vw, 2.4rem);
  line-height: 1.08;
  font-weight: 900;
}

.app-shell {
  display: flex;
  flex-direction: column;
  width: min(430px, 100%);
  height: 100dvh;
  max-height: 100dvh;
  margin: 0 auto;
  overflow: hidden;
  padding: max(14px, env(safe-area-inset-top)) 14px max(16px, env(safe-area-inset-bottom));
}

.app-topbar {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr) 42px;
  align-items: center;
  gap: 8px;
  min-height: 44px;
  margin-bottom: 18px;
}

.back-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  color: var(--text);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.045);
}

.app-shell[data-step="1"] .back-button,
.app-shell[data-step="2"] .back-button {
  pointer-events: none;
  visibility: hidden;
}

.topbar-spacer {
  display: block;
  grid-column: 3;
  width: 42px;
  height: 42px;
}

.app-screen {
  display: none;
  flex: 1;
  min-height: 0;
}

.app-screen.is-active {
  display: flex;
  flex-direction: column;
  gap: 14px;
  overflow-y: auto;
  overscroll-behavior: contain;
  animation: screen-enter 360ms cubic-bezier(0.22, 1, 0.36, 1) both;
}

.finish-screen.is-active {
  overflow: hidden;
}

.frame-screen.is-active {
  overflow: hidden;
}

.intro-screen {
  justify-content: center;
  padding-bottom: 8px;
}

.intro-hero {
  display: grid;
  gap: 18px;
  justify-items: center;
  text-align: center;
}

.event-logo {
  display: block;
  width: min(72vw, 250px);
  max-height: min(34dvh, 330px);
  object-fit: contain;
  animation: logo-breathe 6.8s ease-in-out infinite;
  filter:
    drop-shadow(0 22px 42px rgba(0, 0, 0, 0.55))
    drop-shadow(0 0 20px rgba(240, 199, 106, 0.2));
}

.intro-copy {
  display: grid;
  gap: 10px;
}

.intro-kicker {
  color: var(--gold-strong);
  font-size: 0.88rem;
  font-weight: 900;
}

.intro-title {
  color: var(--text);
  font-size: clamp(1.85rem, 8vw, 2.65rem);
  font-weight: 900;
  line-height: 1.12;
}

.intro-text,
.status-message {
  color: var(--muted);
  font-size: 0.92rem;
  line-height: 1.55;
}

.hero-frame,
.preview-card {
  flex: 0 0 auto;
  width: 100%;
  aspect-ratio: var(--preview-aspect, 4 / 3);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.finish-screen .final-preview {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  justify-content: center;
  min-height: 0;
  aspect-ratio: auto;
  border: 0;
  background: transparent;
  box-shadow: none;
  touch-action: none;
}

.hero-frame img,
.rendered-preview,
#previewCanvas {
  display: block;
  width: 100%;
}

.hero-frame img,
.rendered-preview {
  height: 100%;
  object-fit: cover;
}

.finish-screen .rendered-preview {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  box-shadow: var(--shadow);
  cursor: grab;
  touch-action: none;
  user-select: none;
  -webkit-user-drag: none;
}

.finish-screen .final-preview.is-adjusting .rendered-preview {
  cursor: grabbing;
}

#previewCanvas {
  height: auto;
  aspect-ratio: var(--preview-aspect, 4 / 3);
}

.status-message {
  display: none;
}

.status-message.is-visible {
  display: block;
}

.app-shell:not(.has-photo) .photo-workspace,
.app-shell:not(.has-photo) .photo-tools,
.app-shell:not(.has-photo) .photo-next-action {
  display: none;
}

.app-shell.has-photo .photo-empty-card {
  display: none;
}

.app-shell:not(.has-photo)[data-step="2"] .photo-screen {
  justify-content: center;
}

.app-shell.has-photo[data-step="2"] .photo-screen {
  overflow: hidden;
}

.app-shell.has-photo[data-step="2"] .photo-workspace {
  display: flex;
  flex: 1 1 0;
  align-items: center;
  justify-content: center;
  min-height: 0;
  aspect-ratio: auto;
  border: 0;
  background: transparent;
  box-shadow: none;
}

.app-shell.has-photo[data-step="2"] #previewCanvas {
  width: auto;
  height: auto;
  max-width: 100%;
  max-height: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--white);
  box-shadow: var(--shadow);
}

.photo-empty-card {
  display: grid;
  gap: 13px;
  align-content: center;
  justify-items: center;
  min-height: min(52dvh, 430px);
  padding: 24px 18px;
  border: 1px solid rgba(234, 190, 90, 0.2);
  border-radius: 8px;
  background:
    radial-gradient(circle at 50% 0%, rgba(240, 199, 106, 0.14), transparent 48%),
    rgba(21, 17, 12, 0.78);
  text-align: center;
  box-shadow: var(--shadow);
  transition:
    border-color 180ms ease,
    transform 180ms ease,
    box-shadow 180ms ease;
}

.empty-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 58px;
  height: 58px;
  color: var(--gold-strong);
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 250, 240, 0.06);
  animation: icon-pulse 3.8s ease-in-out infinite;
}

.empty-icon svg {
  width: 1.55rem;
  height: 1.55rem;
}

.empty-title {
  color: var(--text);
  font-size: 1.22rem;
  font-weight: 900;
  line-height: 1.28;
}

.empty-text {
  max-width: 18rem;
  color: var(--muted);
  font-size: 0.9rem;
  line-height: 1.55;
}

.photo-empty-card .upload-button {
  margin-top: 4px;
}

.tool-stack {
  display: grid;
  gap: 11px;
  padding: 12px;
  border: 1px solid rgba(234, 190, 90, 0.18);
  border-radius: 8px;
  background: rgba(21, 17, 12, 0.78);
}

#photoInput {
  position: absolute;
  width: 1px;
  height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  clip-path: inset(50%);
}

.primary-action,
.secondary-action,
.upload-button {
  position: relative;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 48px;
  padding: 0 16px;
  border-radius: 8px;
  font-size: 0.95rem;
  font-weight: 900;
  overflow: hidden;
  text-decoration: none;
  transition:
    transform 150ms ease,
    border-color 150ms ease,
    background 150ms ease,
    color 150ms ease,
    opacity 150ms ease;
}

.primary-action {
  color: #1b1204;
  background: linear-gradient(180deg, #f5cf72 0%, #ca8e21 100%);
  animation: primary-glow 4.8s ease-in-out infinite;
}

.secondary-action,
.upload-button {
  color: var(--text);
  border: 1px solid var(--line);
  background: rgba(255, 250, 240, 0.06);
}

.wide-action,
.upload-button {
  width: 100%;
}

.bottom-action {
  margin-top: auto;
  position: sticky;
  bottom: 0;
  z-index: 4;
  box-shadow: 0 -16px 28px rgba(7, 6, 4, 0.72);
}

.primary-action:active,
.secondary-action:active,
.upload-button:active,
.back-button:active {
  transform: translateY(1px);
}

button:disabled,
input:disabled + label {
  cursor: not-allowed;
  opacity: 0.45;
}

.switch-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 14px;
  padding: 12px;
  border: 1px solid rgba(255, 250, 240, 0.08);
  border-radius: 8px;
  background: rgba(255, 250, 240, 0.035);
}

.switch-row strong {
  font-size: 0.9rem;
  line-height: 1.3;
}

.switch-row small {
  display: block;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  line-height: 1.35;
}

.switch-row input {
  width: 48px;
  height: 28px;
  margin: 0;
  accent-color: var(--gold);
}

.frame-list {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-template-rows: minmax(0, 0.82fr) minmax(0, 1fr);
  flex: 1 1 auto;
  min-height: 0;
  align-items: stretch;
  gap: 10px;
  padding-bottom: 0;
}

.frame-option {
  display: grid;
  grid-template-rows: minmax(0, 1fr) auto;
  gap: 6px;
  width: 100%;
  height: 100%;
  min-width: 0;
  min-height: 0;
  padding: 4px;
  color: var(--text);
  border: 1px solid transparent;
  border-radius: 8px;
  background: transparent;
  text-align: center;
  break-inside: avoid;
  transition:
    border-color 160ms ease,
    transform 160ms ease;
}

.frame-option[data-orientation="landscape"] {
  grid-column: 1 / -1;
}

.frame-option[aria-selected="true"] {
  border-color: var(--gold-strong);
}

.frame-option-preview {
  display: block;
  width: 100%;
  height: 100%;
  min-height: 0;
  object-fit: contain;
  border-radius: 6px;
  background: transparent;
}

.frame-option-meta {
  display: grid;
  justify-items: center;
  padding: 0 2px 1px;
}

.frame-option strong {
  display: block;
  overflow: hidden;
  font-size: 0.84rem;
  line-height: 1.2;
  text-align: center;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.action-stack {
  display: grid;
  gap: 10px;
}

.finish-screen .bottom-action {
  position: static;
  margin-top: 0;
  box-shadow: none;
}

@media (hover: hover) {
  .primary-action:hover,
  .secondary-action:hover,
  .upload-button:hover,
  .frame-option:hover,
  .back-button:hover {
    border-color: rgba(240, 199, 106, 0.72);
  }

  .photo-empty-card:hover,
  .frame-option:hover {
    transform: translateY(-2px);
  }
}

@media (min-width: 720px) {
  body {
    background:
      radial-gradient(circle at 50% 0%, rgba(214, 164, 61, 0.13), transparent 34%),
      #050403;
  }

  .app-shell {
    margin-block: 18px;
    height: calc(100dvh - 36px);
    max-height: calc(100dvh - 36px);
    border: 1px solid rgba(234, 190, 90, 0.12);
    border-radius: 18px;
    background: rgba(7, 6, 4, 0.7);
  }
}

@media (max-height: 720px) {
  .app-screen.is-active {
    gap: 10px;
  }

  .frame-list {
    gap: 8px;
  }

  .frame-option {
    gap: 4px;
    padding: 3px;
  }

  .intro-screen {
    justify-content: flex-start;
  }

  .intro-hero {
    gap: 12px;
  }

  .event-logo {
    width: min(58vw, 210px);
    max-height: 28dvh;
  }

  h1 {
    font-size: 2.45rem;
  }

  h2 {
    font-size: 1.55rem;
  }

  .tool-stack {
    gap: 9px;
    padding: 10px;
  }
}

@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;
  }
}
