/* ── Reset & base ── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

:root {
  /* Polaris tokens */
  --p-bg:          #f6f6f7;
  --p-surface:     #ffffff;
  --p-border:      #e3e3e3;
  --p-text:        #303030;
  --p-text-sub:    #616161;
  --p-green:       #008060;
  --p-green-dark:  #006e52;
  --p-radius-sm:   6px;
  --p-radius-md:   12px;
  --p-radius-lg:   16px;
  --p-shadow:      0 1px 3px rgba(0,0,0,0.10), 0 1px 2px rgba(0,0,0,0.06);
  --p-shadow-md:   0 4px 16px rgba(0,0,0,0.08);

  /* Camera/viewer overrides */
  --cam-bg:   #000;
  --view-bg:  #f6f6f7;

  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bot: env(safe-area-inset-bottom, 0px);
}

html, body {
  height: 100%;
  overflow: hidden;
  background: var(--p-bg);
  color: var(--p-text);
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
  -webkit-font-smoothing: antialiased;
  font-size: 14px;
}

/* ── Screens ── */
.screen {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow-y: auto;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 0.22s ease, transform 0.22s ease;
  background: var(--p-bg);
}
.screen.active {
  opacity: 1;
  pointer-events: all;
  transform: translateY(0);
}

/* ── Polaris buttons ── */
.btn-primary {
  width: 100%;
  max-width: 340px;
  padding: 14px 20px;
  border-radius: var(--p-radius-sm);
  border: none;
  background: var(--p-green);
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  transition: background 0.15s;
  display: block;
  text-align: center;
}
.btn-primary:active { background: var(--p-green-dark); }

.btn-ghost {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  color: var(--p-text);
  padding: 13px 20px;
  border-radius: var(--p-radius-sm);
  font-family: inherit;
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  width: 100%;
  max-width: 340px;
  display: block;
  text-align: center;
  transition: background 0.12s;
}
.btn-ghost:active { background: var(--p-bg); }

/* ════════════════════════════
   HOME SCREEN
═══════════════════════════ */
#home {
  justify-content: center;
  padding: calc(var(--safe-top) + 24px) 20px calc(var(--safe-bot) + 32px);
}

.home-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.brand-icon {
  width: 64px;
  height: 64px;
  padding: 10px;
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius-md);
  box-shadow: var(--p-shadow);
}
.brand-icon svg { width: 100%; height: 100%; }

.logo-text {
  font-size: 28px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--p-text);
}
.logo-text span { color: var(--p-green); }

.tagline {
  font-size: 15px;
  color: var(--p-text-sub);
  line-height: 1.6;
}

/* Frame picker */
.frame-picker {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.picker-label {
  font-size: 12px;
  color: var(--p-text-sub);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  font-weight: 500;
}
.picker-options {
  display: flex;
  gap: 8px;
  width: 100%;
  max-width: 340px;
}
.pick {
  flex: 1;
  padding: 10px 8px;
  border-radius: var(--p-radius-sm);
  border: 1px solid var(--p-border);
  background: var(--p-surface);
  color: var(--p-text-sub);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  transition: all 0.15s;
  box-shadow: var(--p-shadow);
}
.pick small { font-size: 11px; font-weight: 400; }
.pick.active {
  border-color: var(--p-green);
  color: var(--p-green);
  background: #f0faf7;
}

.tip {
  font-size: 12px;
  color: var(--p-text-sub);
}

/* ════════════════════════════
   GUIDE SCREEN
═══════════════════════════ */
#guide {
  padding: calc(var(--safe-top) + 32px) 20px calc(var(--safe-bot) + 32px);
  justify-content: center;
}

.guide-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 20px;
  width: 100%;
  max-width: 400px;
}

.guide-inner h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.01em;
  align-self: flex-start;
}

.steps { display: flex; flex-direction: column; gap: 10px; width: 100%; }

.step {
  display: flex;
  align-items: flex-start;
  gap: 14px;
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  border-radius: var(--p-radius-md);
  padding: 14px;
  box-shadow: var(--p-shadow);
}
.step-icon {
  font-size: 20px;
  flex-shrink: 0;
  width: 40px;
  height: 40px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--p-bg);
  border-radius: var(--p-radius-sm);
  border: 1px solid var(--p-border);
}
.step strong { display: block; font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.step p      { font-size: 13px; color: var(--p-text-sub); line-height: 1.5; }

.cam-error {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  background: #fff4f4;
  border: 1px solid #fecaca;
  border-radius: var(--p-radius-md);
  padding: 14px 16px;
  text-align: center;
  width: 100%;
  max-width: 340px;
}
.cam-error.visible { display: flex; }
.cam-error-icon { font-size: 22px; }
.cam-error strong { font-size: 14px; color: #991b1b; }
.cam-error p      { font-size: 13px; color: var(--p-text-sub); line-height: 1.5; }

/* ════════════════════════════
   CAPTURE SCREEN
═══════════════════════════ */
#capture { padding: 0; background: #000; overflow: hidden; }

#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}

/* Start-frame overlay — warm amber tint */
#startOverlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.3s;
  filter: sepia(1) hue-rotate(10deg) saturate(8) brightness(1.05);
  mix-blend-mode: screen;
}

/* Start-frame corner thumbnail */
.start-thumb-wrap {
  display: none;
  flex-direction: column;
  align-items: center;
  gap: 5px;
}
.start-thumb-wrap.visible { display: flex; }
.start-thumb-wrap img {
  width: 72px;
  height: 96px;
  object-fit: cover;
  border-radius: 10px;
  opacity: 0.72;
  border: 2px solid rgba(255,255,255,0.25);
}
.start-thumb-wrap span {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  text-transform: uppercase;
  color: rgba(255,255,255,0.5);
}

/* Ghost overlay — Sobel edge outlines, center crop only */
#ghostOverlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  opacity: 0;
  pointer-events: none;
}
#ghostOverlay.visible { opacity: 0.7; }

.capture-ui {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 20px) 20px calc(var(--safe-bot) + 36px);
  background:
    linear-gradient(to bottom, rgba(0,0,0,0.5) 0%, transparent 25%),
    linear-gradient(to top,  rgba(0,0,0,0.65) 0%, transparent 35%);
}

/* Top bar */
.capture-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.start-toast {
  display: none;
  background: rgba(0,0,0,0.6);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: var(--p-radius-md);
  padding: 10px 16px;
  font-size: 13px;
  color: rgba(255,255,255,0.8);
  text-align: center;
  max-width: 260px;
  align-self: center;
}
.start-toast.visible {
  display: block;
  animation: toastOut 0.4s ease 3.5s forwards;
}
@keyframes toastOut { to { opacity: 0; pointer-events: none; } }

.quit-btn {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(255,255,255,0.12);
  border: none;
  color: #fff;
  font-size: 15px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(8px);
  flex-shrink: 0;
}

/* Bottom */
.capture-bottom {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.shot-counter {
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 50px;
  padding: 7px 18px;
  font-size: 15px;
  font-weight: 700;
  color: rgba(255,255,255,0.8);
  letter-spacing: 0.02em;
}
.shot-sep { font-weight: 400; opacity: 0.45; }

.shutter {
  width: 80px;
  height: 80px;
  border-radius: 50%;
  border: 4px solid rgba(255,255,255,0.35);
  background: transparent;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: transform 0.1s;
  position: relative;
}
.shutter::after {
  content: '';
  width: 64px;
  height: 64px;
  border-radius: 50%;
  background: #fff;
  position: absolute;
  transition: transform 0.1s;
}
.shutter:active { transform: scale(0.91); }
.shutter.done::after { background: var(--p-green); }
.shutter.ready { border-color: #4ade80; }

/* ════════════════════════════
   PROCESSING SCREEN
═══════════════════════════ */
#processing { justify-content: center; gap: 16px; background: var(--p-surface); }

.processing-inner {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
  text-align: center;
}

.proc-spinner {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: 3px solid var(--p-border);
  border-top-color: var(--p-green);
  animation: spin 0.75s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.processing-inner h2 { font-size: 22px; font-weight: 700; line-height: 1.3; color: var(--p-text); }
.processing-inner p  { color: var(--p-text-sub); }

/* ════════════════════════════
   VIEWER SCREEN
═══════════════════════════ */
#viewer { padding: 0; overflow: hidden; background: var(--p-bg); }

.viewer-wrap {
  display: flex;
  flex-direction: column;
  width: 100%;
  height: 100%;
}

.viewer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: calc(var(--safe-top) + 14px) 16px 12px;
  background: var(--p-surface);
  border-bottom: 1px solid var(--p-border);
  flex-shrink: 0;
}

.viewer-logo {
  font-size: 18px;
  font-weight: 800;
  letter-spacing: -0.02em;
  color: var(--p-text);
}
.viewer-logo span { color: var(--p-green); }

.btn-new {
  background: var(--p-surface);
  border: 1px solid var(--p-border);
  color: var(--p-text);
  padding: 7px 14px;
  border-radius: var(--p-radius-sm);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  box-shadow: var(--p-shadow);
}

/* Stage */
.viewer-stage {
  flex: 1;
  position: relative;
  overflow: hidden;
  cursor: grab;
  background: var(--p-surface);
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
}
.viewer-stage:active { cursor: grabbing; }

#viewerImg {
  width: 100%;
  height: 100%;
  object-fit: contain;
  user-select: none;
  -webkit-user-select: none;
  pointer-events: none;
}

/* 360° intro badge */
.badge-360 {
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  font-size: 36px;
  font-weight: 800;
  color: #fff;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  border-radius: 14px;
  padding: 10px 22px;
  pointer-events: none;
  opacity: 0;
  letter-spacing: -0.02em;
}
.badge-360.show { animation: badge360 1.6s ease forwards; }
@keyframes badge360 {
  0%   { opacity: 0; transform: translate(-50%,-50%) scale(0.85); }
  20%  { opacity: 1; transform: translate(-50%,-50%) scale(1); }
  70%  { opacity: 1; }
  100% { opacity: 0; transform: translate(-50%,-50%) scale(1); }
}

.drag-hint {
  position: absolute;
  bottom: 14px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 6px;
  background: rgba(0,0,0,0.45);
  backdrop-filter: blur(8px);
  border-radius: 50px;
  padding: 6px 14px;
  font-size: 12px;
  color: rgba(255,255,255,0.8);
  pointer-events: none;
  transition: opacity 0.4s;
  white-space: nowrap;
}
.drag-hint.hidden { opacity: 0; }

/* Frame scrubber */
.frame-bar { padding: 10px 16px; flex-shrink: 0; background: var(--p-surface); border-top: 1px solid var(--p-border); }
.frame-track { height: 3px; background: var(--p-border); border-radius: 99px; position: relative; overflow: hidden; }
.frame-thumb  { height: 100%; width: 0%; background: var(--p-green); border-radius: 99px; transition: width 0.05s; }

/* Actions */
.viewer-actions {
  display: flex;
  flex-direction: column;
  gap: 8px;
  padding: 12px 16px calc(var(--safe-bot) + 16px);
  background: var(--p-surface);
  flex-shrink: 0;
}

.spin-btn {
  width: 100%;
  padding: 13px;
  border-radius: var(--p-radius-sm);
  border: 1px solid var(--p-border);
  background: var(--p-surface);
  color: var(--p-text);
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: all 0.15s;
  box-shadow: var(--p-shadow);
}
.spin-btn.active {
  background: var(--p-green);
  border-color: var(--p-green);
  color: #fff;
}

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

.action-btn {
  flex: 1;
  padding: 13px 10px;
  border-radius: var(--p-radius-sm);
  border: 1px solid var(--p-border);
  background: var(--p-surface);
  color: var(--p-text);
  font-family: inherit;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  box-shadow: var(--p-shadow);
  transition: background 0.12s;
}
.action-btn:active { background: var(--p-bg); }
