:root {
  --bg: #070708;
  --text: #f4f4ef;
  --muted: #8e8e93;
  --line: rgba(255, 255, 255, 0.1);
  --accent: #f5f5f0;
  --danger: #ff4d6a;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  margin: 0;
  height: 100%;
  height: 100svh;
  background: #000;
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", sans-serif;
  overscroll-behavior: none;
  user-select: none;
  overflow: hidden;
}

.shell {
  height: 100svh;
  display: grid;
  place-items: center;
}

.phone {
  width: 100%;
  max-width: 430px;
  height: 100svh;
  max-height: 100svh;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  padding: calc(var(--safe-top) + 10px) 18px calc(var(--safe-bottom) + 12px);
  gap: 10px;
  overflow: hidden;
}

.top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
}

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

h1 {
  margin: 2px 0 0;
  font-size: 28px;
  letter-spacing: -0.04em;
  font-weight: 700;
}

.chip {
  margin: 8px 0 0;
  padding: 6px 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.stage {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  z-index: 0;
}

.frame {
  position: absolute;
  inset: 0;
  border-radius: 28px;
  overflow: hidden;
  background: #111;
  border: 1px solid var(--line);
}

.frame video,
.frame img,
.frame canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  background: #000;
}

.photo-removes {
  position: absolute;
  inset: 0;
  z-index: 5;
  pointer-events: none;
}

.photo-removes[hidden],
.photo-remove[hidden] {
  display: none !important;
}

.photo-remove {
  position: absolute;
  pointer-events: auto;
  height: 32px;
  padding: 0 12px;
  border: 0;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font: 600 13px inherit;
  cursor: pointer;
}

.phone[data-mode="photo"] .frame {
  inset: auto;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  height: 100%;
  width: auto;
  aspect-ratio: 4 / 5;
  max-width: 100%;
}

.phone[data-mode="photo"] .frame #photoBase,
.phone[data-mode="photo"] .frame #overlayPreview,
.phone[data-mode="photo"] .frame #work {
  object-fit: cover;
}

#preview {
  z-index: 1;
  opacity: 0;
}

#photoBase {
  z-index: 1;
  display: none;
  touch-action: none;
  background: #000;
}

#overlayPreview {
  z-index: 2;
  display: none;
  pointer-events: none;
  background: transparent;
}

#work {
  z-index: 3;
  display: none;
}

.mode-gate {
  display: grid;
  grid-template-columns: 1fr;
  gap: 12px;
  width: min(100%, 280px);
}

.mode-btn {
  appearance: none;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: rgba(255, 255, 255, 0.04);
  color: var(--text);
  padding: 18px 16px;
  text-align: left;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.mode-btn:active {
  background: rgba(255, 255, 255, 0.08);
}

.mode-title {
  font-size: 18px;
  font-weight: 700;
  letter-spacing: -0.02em;
}

.mode-sub {
  font-size: 12px;
  color: var(--muted);
}

.phone[data-mode=""] .mode-gate {
  display: grid;
}

.phone:not([data-mode=""]) .mode-gate {
  display: none;
}

.phone:not([data-mode=""])[data-state="idle"] #emptyHint {
  display: block;
  margin: 0;
  font-size: 16px;
  line-height: 1.45;
}

.phone[data-mode="photo"][data-state="idle"] .empty {
  cursor: pointer;
}

.phone[data-mode=""] #emptyHint {
  display: none;
}

.phone[data-state="ready"][data-mode="video"] #preview {
  opacity: 1;
}

.phone[data-state="ready"] #overlayPreview {
  display: block;
}

.phone[data-mode="photo"] #overlayPreview {
  display: none;
}

.phone[data-state="ready"][data-mode="photo"] #photoBase {
  display: block;
}

.phone[data-state="processing"] #preview {
  opacity: 0.02;
}

.phone[data-state="processing"] #photoBase {
  opacity: 0.15;
}

.phone[data-state="processing"] #work {
  display: block;
}

.phone[data-state="done"][data-mode="video"] #preview {
  opacity: 1;
  z-index: 4;
}

.phone[data-state="done"][data-mode="photo"] #photoBase {
  display: block;
  z-index: 4;
}

.phone[data-state="done"] #overlayPreview,
.phone[data-state="done"] #work {
  display: none;
}

.phone[data-state="done"][data-mode="photo"] #photoBase {
  /* show final bake on work then swap — keep photoBase until share */
}

.empty {
  position: absolute;
  inset: 0;
  z-index: 4;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  padding: 28px;
  color: var(--muted);
  text-align: center;
  background: #111;
}

.phone:not([data-state="idle"]) .empty {
  display: none;
}

.empty svg {
  width: 48px;
  height: 48px;
  color: #d8d8d2;
}

.empty p {
  margin: 0;
  font-size: 14px;
  line-height: 1.45;
}

.progress {
  position: absolute;
  inset: 0;
  z-index: 5;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-end;
  gap: 8px;
  padding: 24px;
  background: linear-gradient(to top, rgba(0, 0, 0, 0.72), transparent 46%);
}

.progress[hidden] {
  display: none;
}

.progress-ring {
  width: 72px;
  height: 72px;
  border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, 0.16);
  display: grid;
  place-items: center;
  background: rgba(0, 0, 0, 0.35);
  backdrop-filter: blur(12px);
}

#progressPct {
  font-variant-numeric: tabular-nums;
  font-size: 15px;
  font-weight: 600;
}

#progressText {
  margin: 0;
  font-size: 13px;
  color: #f4f4ef;
}

.meta {
  min-height: 18px;
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.dock {
  position: relative;
  z-index: 30;
  display: flex;
  flex-direction: column;
  gap: 8px;
  flex-shrink: 0;
}

.pick-wrap {
  position: relative;
  height: 54px;
}

.pick-wrap .btn {
  pointer-events: none;
}

.file-overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  font-size: 48px;
  cursor: pointer;
}

.pick-wrap[hidden] {
  display: none;
}

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

.pick {
  position: relative;
  height: 84px;
  padding: 8px 8px 6px;
  border: 1px solid var(--line);
  border-radius: 14px;
  overflow: hidden;
  background: #111;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: stretch;
  gap: 6px;
}

.pick-logo-wrap {
  flex: 1 1 auto;
  min-height: 0;
  display: grid;
  place-items: center;
  border-radius: 10px;
  background: #000;
  padding: 8px 10px;
}

.pick-logo {
  width: 100%;
  height: 100%;
  max-height: 36px;
  object-fit: contain;
  object-position: center;
  display: block;
  filter: brightness(0) invert(1);
}

.pick-label {
  flex: 0 0 auto;
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  text-align: center;
  line-height: 1.1;
}

.pick.is-on {
  border-color: #f5f5f0;
  box-shadow: inset 0 0 0 2px #f5f5f0;
  background: #161616;
}

.pick:disabled {
  opacity: 0.45;
}

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

.layouts[hidden],
.photo-fields[hidden],
.picks[hidden] {
  display: none !important;
}

.layout {
  appearance: none;
  height: 58px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text);
  font-size: 12px;
  font-weight: 650;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 0;
}

.layout-ico {
  width: 22px;
  height: 22px;
  display: block;
}

.layout-ico rect {
  fill: none;
  stroke: currentColor;
  stroke-width: 1.75;
}

.layout.is-on {
  background: #f5f5f0;
  color: #111;
  border-color: #f5f5f0;
}

.layout:disabled {
  opacity: 0.45;
}

.photo-fields {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.photo-fields input {
  width: 100%;
  height: 44px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: #111;
  color: #fff;
  padding: 0 12px;
  font-size: 16px;
  font-family: inherit;
  user-select: text;
  -webkit-user-select: text;
}

.slot-file {
  position: fixed;
  left: 0;
  top: 0;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.photo-fields input::placeholder {
  color: #8e8e93;
}

.date-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.hint {
  margin: 0 2px 4px;
  color: var(--muted);
  font-size: 12px;
  line-height: 1.4;
  text-align: center;
}

.hint.error {
  color: var(--danger);
}

#updateNow {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  z-index: 80;
  height: 54px;
  border: 0;
  border-radius: 16px;
  background: #f5f5f0;
  color: #111;
  font-size: 16px;
  font-weight: 700;
  cursor: pointer;
}

.save-row {
  display: flex;
  gap: 8px;
}

.save-row:not(:has(.btn:not([hidden]))) {
  display: none;
}

.save-row .btn {
  flex: 1;
  width: auto;
  min-width: 0;
}

.btn {
  appearance: none;
  border: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  height: 54px;
  border-radius: 16px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  width: 100%;
}

.btn.primary {
  background: var(--accent);
  color: #111;
}

.btn.ghost {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--line);
}

.btn[hidden],
label.btn[hidden] {
  display: none;
}

.btn:disabled {
  opacity: 0.45;
}

.file {
  display: none;
}

@media (min-width: 760px) {
  body {
    background: #111;
  }

  .phone {
    height: min(860px, 96dvh);
    border-radius: 40px;
    border: 1px solid var(--line);
    box-shadow: 0 40px 80px rgba(0, 0, 0, 0.45);
    padding-top: 28px;
    padding-bottom: 22px;
  }
}
