:root {
  --bg: #0f172a;
  --bg-2: #1e293b;
  --surface: #ffffff;
  --text: #0c4a6e;
  --text-muted: #64748b;
  --text-on-dark: #f1f5f9;
  --primary: #0ea5e9;
  --primary-hover: #0284c7;
  --accent: #06b6d4;
  --sky-soft: #bae6fd;
  --sky-mid:  #38bdf8;
  --sky-deep: #0284c7;
  --danger: #ef4444;
  --success: #10b981;
  --warn: #f59e0b;
  --box-detected: #0ea5e9;
  --box-picked: #f59e0b;
  --radius: 16px;
  --shadow: 0 10px 30px rgba(14,165,233,0.2);
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; padding: 0; }

[hidden] { display: none !important; }

body {
  font-family: 'IBM Plex Sans Thai', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text-on-dark);
  overflow: hidden;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  -webkit-user-select: none;
}

/* HEADER */
.app-header {
  position: fixed;
  top: 0; left: 0; right: 0;
  padding: calc(12px + var(--safe-top)) 16px 12px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  z-index: 50;
  pointer-events: none;
}
.app-header > * { pointer-events: auto; }
.logo {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
  background: rgba(15,23,42,0.7);
  padding: 7px 13px;
  border-radius: 999px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  white-space: nowrap;
}
.icon-btn {
  width: 36px; height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  transition: transform 0.1s, background 0.15s;
}
.icon-btn:active { transform: scale(0.92); background: rgba(255,255,255,0.25); }
.icon-btn.muted { opacity: 0.55; }
.icon-btn.active { background: #fff; color: var(--primary-hover); }

/* Presentation mode — hide all secondary UI */
body.presentation-mode .app-header { opacity: 0.25; transition: opacity 0.3s; }
body.presentation-mode .app-header:hover { opacity: 1; }
body.presentation-mode .fab-top,
body.presentation-mode .mode-toggle,
body.presentation-mode .rank-mode,
body.presentation-mode .fab-secondary-row,
body.presentation-mode .edit-hint-fab,
body.presentation-mode .pool-chip { display: none !important; }
body.presentation-mode .fab-bottom {
  background: linear-gradient(to top, rgba(0,0,0,0.6), transparent);
  padding-top: 30px;
}
body.presentation-mode #resultCanvas { filter: brightness(0.9); }
body.presentation-mode .result-stage.zoomed #resultCanvas { filter: brightness(0.25) saturate(0.6) blur(2px); }
body.presentation-mode .btn-fab-hero {
  padding: 20px 40px;
  font-size: 22px;
}
body.presentation-mode .spotlight-ring {
  width: min(80vw, 420px);
  height: min(80vw, 420px);
}
body.presentation-mode .picked-label { font-size: 28px; padding: 14px 32px; }
.header-actions { display: flex; gap: 8px; }

/* SCREENS */
.screen {
  position: fixed;
  inset: 0;
  display: none;
  flex-direction: column;
  padding-top: calc(60px + var(--safe-top));
  padding-bottom: var(--safe-bottom);
}
.screen.active { display: flex; }

/* START SCREEN */
#screenStart {
  background: linear-gradient(170deg, #0284c7 0%, #38bdf8 45%, #bae6fd 85%, #f0f9ff 100%);
  padding: calc(60px + var(--safe-top)) 24px var(--safe-bottom);
  overflow-y: auto;
}

/* Video background */
.bg-video-wrap {
  position: absolute;
  inset: 0;
  overflow: hidden;
  pointer-events: none;
  z-index: 0;
}
.bg-video-frame {
  position: absolute;
  top: 50%;
  left: 50%;
  /* Cover: scale iframe so 16:9 content fills viewport on both axes */
  width: max(100vw, 177.78vh);
  height: max(56.25vw, 100vh);
  transform: translate(-50%, -50%);
  border: 0;
  pointer-events: none;
}
.bg-video-overlay {
  position: absolute;
  inset: 0;
  background: linear-gradient(170deg,
    rgba(2,132,199,0.55) 0%,
    rgba(56,189,248,0.45) 45%,
    rgba(186,230,253,0.55) 85%,
    rgba(240,249,255,0.7) 100%);
  backdrop-filter: saturate(1.1);
  -webkit-backdrop-filter: saturate(1.1);
}

/* Make hero content sit above the video */
#screenStart > .start-hero,
#screenStart > .tips-fab,
#screenStart > .tips-drawer {
  position: relative;
  z-index: 2;
}
#screenStart > .tips-fab { position: fixed; }
#screenStart > .tips-drawer { position: fixed; }
.start-hero {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  text-align: center;
  gap: 20px;
  padding: 40px 0;
}
.start-emoji { font-size: 80px; line-height: 1; }
.start-hero h1 {
  font-size: 32px;
  margin: 0;
  color: #fff;
  text-shadow: 0 2px 12px rgba(0,0,0,0.25);
}
.subtitle {
  font-size: 18px;
  color: rgba(255,255,255,0.92);
  margin: 0;
  line-height: 1.6;
}
.subtitle-pill {
  display: inline-block;
  margin-top: 10px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.6px;
  text-transform: uppercase;
  padding: 5px 14px;
  border-radius: 999px;
  background: #fff;
  color: var(--primary-hover);
  box-shadow: 0 4px 14px rgba(2,132,199,0.25);
}
.privacy-note {
  margin-top: 8px;
  font-size: 13px;
  color: rgba(255,255,255,0.8);
  background: rgba(0,0,0,0.2);
  padding: 8px 14px;
  border-radius: 999px;
}

/* BUTTONS */
.btn {
  font-family: inherit;
  font-weight: 600;
  font-size: 16px;
  padding: 14px 24px;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform 0.1s, background 0.15s, opacity 0.15s;
  color: #fff;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
}
.btn:active:not(:disabled) { transform: scale(0.96); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }

.btn-primary {
  background: #fff;
  color: var(--primary);
}
.btn-primary:active:not(:disabled) { background: #f1f5f9; }

#screenResult .btn-primary {
  background: var(--primary);
  color: #fff;
}
#screenResult .btn-primary:active:not(:disabled) { background: var(--primary-hover); }

.btn-ghost {
  background: rgba(255,255,255,0.15);
  color: #fff;
  backdrop-filter: blur(10px);
}
.btn-ghost:active:not(:disabled) { background: rgba(255,255,255,0.25); }

.btn-hero {
  padding: 18px 40px;
  font-size: 18px;
  font-weight: 700;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  width: 100%;
  max-width: 320px;
}
.btn-large {
  padding: 16px 32px;
  font-size: 18px;
  flex: 1;
}
.btn-link {
  background: none;
  color: rgba(255,255,255,0.7);
  font-size: 14px;
  text-decoration: underline;
  padding: 8px 12px;
}
.btn-link:active { background: rgba(255,255,255,0.05); }

.start-actions {
  display: flex;
  flex-direction: column;
  gap: 12px;
  align-items: center;
  width: 100%;
}

/* TIPS — floating tab + slide-out drawer */
.tips-fab {
  position: fixed;
  right: 0;
  top: 45%;
  transform: translateY(-50%);
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 12px 10px 12px 14px;
  border: 1px solid rgba(255,255,255,0.25);
  border-right: none;
  border-radius: 18px 0 0 18px;
  background: rgba(15,23,42,0.5);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: #fff;
  box-shadow: -4px 8px 24px rgba(0,0,0,0.25);
  cursor: pointer;
  font-family: inherit;
  animation: tipsFabPulse 3s ease-in-out infinite;
}
.tips-fab:active { transform: translateY(-50%) scale(0.95); }
.tips-fab-icon { font-size: 22px; line-height: 1; }
.tips-fab-text { font-size: 10px; font-weight: 600; letter-spacing: 0.5px; writing-mode: vertical-rl; }
@keyframes tipsFabPulse {
  0%, 100% { box-shadow: -4px 8px 24px rgba(0,0,0,0.25), 0 0 0 0 rgba(255,255,255,0.3); }
  50%      { box-shadow: -4px 8px 24px rgba(0,0,0,0.25), 0 0 0 8px rgba(255,255,255,0); }
}

.tips-drawer { position: fixed; inset: 0; z-index: 200; }

/* Hide app header while tips drawer is open OR just closed — use display:none
   so clicks can NEVER reach header buttons during/right after the transition */
body.drawer-open .app-header,
body.drawer-closing .app-header { display: none !important; }
.tips-backdrop {
  position: absolute; inset: 0;
  background: rgba(0,0,0,0.55);
  backdrop-filter: blur(4px);
  -webkit-backdrop-filter: blur(4px);
  animation: tipsBackdropIn 0.25s ease both;
}
@keyframes tipsBackdropIn { from { opacity: 0; } to { opacity: 1; } }

.tips-panel {
  position: absolute;
  right: 0; top: 0; bottom: 0;
  width: min(88vw, 380px);
  padding: calc(18px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
  background: linear-gradient(180deg, #0284c7 0%, #38bdf8 55%, #7dd3fc 100%);
  color: #fff;
  overflow-y: auto;
  box-shadow: -10px 0 40px rgba(0,0,0,0.4);
  animation: tipsPanelIn 0.35s cubic-bezier(0.32, 0.72, 0, 1) both;
  border-left: 1px solid rgba(255,255,255,0.2);
}
@keyframes tipsPanelIn {
  from { transform: translateX(100%); }
  to   { transform: translateX(0); }
}

.tips-panel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 16px;
  margin-bottom: 18px;
  border-bottom: 1px solid rgba(255,255,255,0.15);
}
.tips-panel-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.3px;
  text-transform: uppercase;
}
.tips-close {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  backdrop-filter: blur(10px);
  transition: transform 0.1s, background 0.15s;
  font-family: inherit;
}
.tips-close:active { transform: scale(0.92); background: rgba(255,255,255,0.25); }

.tips-title-icon {
  font-size: 18px;
  animation: tipSparkle 2.4s ease-in-out infinite;
  display: inline-block;
}
@keyframes tipSparkle {
  0%, 100% { transform: scale(1) rotate(0); opacity: 1; }
  50%      { transform: scale(1.25) rotate(15deg); opacity: 0.85; }
}

.tips-steps {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tips-step {
  position: relative;
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,0.08);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 14px;
  padding: 10px 12px 10px 10px;
  animation: stepIn 0.5s cubic-bezier(0.34, 1.4, 0.64, 1) both;
  animation-delay: calc(var(--i, 0) * 70ms + 150ms);
}
@keyframes stepIn {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.step-num {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: linear-gradient(135deg, #f59e0b, #ef4444);
  color: #fff;
  font-size: 11px;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 3px 8px rgba(245,158,11,0.4);
}

.step-icon {
  flex-shrink: 0;
  width: 42px;
  height: 42px;
  border-radius: 12px;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
}

.step-body {
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}
.step-title {
  font-weight: 600;
  font-size: 15px;
  color: #fff;
}
.step-sub {
  font-size: 12.5px;
  color: rgba(255,255,255,0.7);
  margin-top: 2px;
}

/* CAMERA */
#screenCamera { padding: 0; background: #000; }
.camera-wrap {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
}
#video, #overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
#overlay { pointer-events: none; }

.camera-badge {
  position: absolute;
  top: calc(16px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15,23,42,0.85);
  color: #fff;
  padding: 8px 16px;
  border-radius: 999px;
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  z-index: 10;
}
.dot {
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--success);
  animation: pulse 1.5s infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50% { opacity: 0.5; transform: scale(1.3); }
}

.camera-controls {
  position: absolute;
  bottom: calc(24px + var(--safe-bottom));
  left: 0; right: 0;
  display: flex;
  align-items: center;
  justify-content: space-around;
  padding: 0 24px;
  z-index: 10;
}
.btn-capture {
  width: 78px; height: 78px;
  border-radius: 50%;
  background: #fff;
  padding: 0;
  position: relative;
}
.btn-capture:disabled { background: #94a3b8; }
.capture-ring {
  position: absolute;
  inset: 6px;
  border-radius: 50%;
  border: 3px solid var(--primary);
  transition: transform 0.15s;
}
.btn-capture:active:not(:disabled) .capture-ring { transform: scale(0.85); }

/* RESULT — fullscreen stage */
#screenResult {
  background: #000;
  padding: 0;
}

.result-stage {
  position: absolute;
  inset: 0;
  overflow: hidden;
  background: #000;
}
#resultCanvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: 0 0;
  transition: filter 0.5s ease;
  will-change: transform, filter;
  cursor: crosshair;
  display: block;
  touch-action: none;
}
/* In edit mode give the canvas a short transition on zoom reset (dblclick),
   but pointer gestures override with direct style writes = instant */
body.edit-mode #resultCanvas { cursor: grab; }
body.edit-mode #resultCanvas:active { cursor: grabbing; }
.stage-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background: radial-gradient(ellipse at center,
    transparent 40%,
    rgba(0,0,0,0.35) 85%,
    rgba(0,0,0,0.7) 100%);
  opacity: 0;
  transition: opacity 0.6s ease;
}
.result-stage.zoomed .stage-vignette { opacity: 1; }

/* Top floating bar */
.fab-top {
  position: fixed;
  top: calc(12px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  z-index: 40;
  pointer-events: none;
  max-width: calc(100vw - 24px);
}
.fab-top > * { pointer-events: auto; }
.fab-icon {
  width: 42px; height: 42px;
  border-radius: 50%;
  border: none;
  background: rgba(15,23,42,0.7);
  color: #fff;
  font-size: 18px;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
  flex: 0 0 auto;
  transition: transform 0.1s, background 0.15s;
}
.fab-icon:active { transform: scale(0.92); background: rgba(15,23,42,0.9); }
.result-count-chip {
  background: rgba(15,23,42,0.7);
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  color: #fff;
  padding: 9px 14px;
  border-radius: 999px;
  font-size: 14px;
  font-weight: 600;
  flex: 0 0 auto;
  box-shadow: 0 4px 16px rgba(0,0,0,0.3);
}

/* Shot nav */
.shot-nav {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 2px;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  flex: 0 1 auto;
  min-width: 0;
}
.shot-nav::-webkit-scrollbar { display: none; }
.shot-chip {
  flex: 0 0 auto;
  background: rgba(15,23,42,0.7);
  color: #fff;
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 12px;
  border: 1.5px solid transparent;
  cursor: pointer;
  white-space: nowrap;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-family: inherit;
}
.shot-chip.active {
  background: var(--primary);
  border-color: rgba(255,255,255,0.4);
}
.shot-chip .del {
  margin-left: 4px;
  opacity: 0.7;
  font-size: 13px;
}

/* Edit hint */
.edit-hint-fab {
  position: fixed;
  top: calc(64px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(245,158,11,0.95);
  color: #1e1b4b;
  font-size: 13px;
  font-weight: 700;
  padding: 7px 14px;
  border-radius: 999px;
  pointer-events: none;
  z-index: 35;
  box-shadow: 0 6px 24px rgba(245,158,11,0.4);
  animation: hintPulse 1.8s ease-in-out infinite;
}
@keyframes hintPulse {
  0%, 100% { transform: translateX(-50%) scale(1); }
  50%      { transform: translateX(-50%) scale(1.05); }
}

/* Face popover (edit mode context menu) */
.face-popover {
  position: fixed;
  z-index: 55;
  display: flex;
  flex-direction: column;
  gap: 2px;
  padding: 4px;
  background: rgba(15,23,42,0.95);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 12px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 14px 40px rgba(0,0,0,0.5);
  animation: popoverIn 0.18s cubic-bezier(0.34, 1.56, 0.64, 1);
}
@keyframes popoverIn {
  from { opacity: 0; transform: scale(0.85) translateY(-4px); }
  to   { opacity: 1; transform: scale(1) translateY(0); }
}
.face-popover-btn {
  background: transparent;
  border: none;
  color: #fff;
  font-family: inherit;
  font-size: 14px;
  padding: 10px 16px;
  cursor: pointer;
  text-align: left;
  border-radius: 8px;
  white-space: nowrap;
  transition: background 0.12s;
}
.face-popover-btn:hover,
.face-popover-btn:active { background: rgba(255,255,255,0.15); }
.face-popover-btn[data-action="delete"] { color: #fca5a5; }

/* Confetti overlay */
.confetti-canvas {
  position: fixed;
  inset: 0;
  width: 100vw;
  height: 100vh;
  pointer-events: none;
  z-index: 47;
}

/* Slot reel (vertical) overlay */
.slot-stage {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: calc(70px + var(--safe-top)) 16px calc(220px + var(--safe-bottom));
  z-index: 41;
  pointer-events: none;
}
.slot-window {
  position: relative;
  width: min(320px, 82vw);
  height: min(520px, 66vh);
  overflow: hidden;
  border-radius: 26px;
  background:
    linear-gradient(180deg,
      rgba(255,255,255,0.08) 0%,
      rgba(255,255,255,0.02) 50%,
      rgba(255,255,255,0.08) 100%),
    rgba(15,23,42,0.5);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
  border: 3px solid rgba(255,255,255,0.28);
  box-shadow:
    0 22px 60px rgba(0,0,0,0.55),
    inset 0 0 0 1px rgba(255,255,255,0.1),
    inset 0 10px 30px rgba(0,0,0,0.35),
    inset 0 -10px 30px rgba(0,0,0,0.35);
}
/* Fade mask at top/bottom so items partially visible blur out */
.slot-window::before, .slot-window::after {
  content: '';
  position: absolute;
  left: 0; right: 0;
  height: 34%;
  pointer-events: none;
  z-index: 3;
}
.slot-window::before {
  top: 0;
  background: linear-gradient(to bottom, rgba(0,0,0,0.7), rgba(0,0,0,0) 100%);
}
.slot-window::after {
  bottom: 0;
  background: linear-gradient(to top, rgba(0,0,0,0.7), rgba(0,0,0,0) 100%);
}

.slot-track {
  display: flex;
  flex-direction: column;
  transform: translateY(0);
  will-change: transform;
}
.slot-item {
  height: 120px;
  min-height: 120px;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 0 20px;
  color: #fff;
  border-bottom: 1px solid rgba(255,255,255,0.1);
}
.slot-item:nth-child(odd)  { background: rgba(14,165,233,0.18); }
.slot-item:nth-child(even) { background: rgba(2,132,199,0.22); }
.slot-avatar {
  width: 78px;
  height: 78px;
  border-radius: 50%;
  border: 2.5px solid rgba(255,255,255,0.85);
  background: #0f172a;
  flex-shrink: 0;
  box-shadow: 0 4px 14px rgba(0,0,0,0.4);
}
.slot-label {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}
.slot-name {
  font-size: 18px;
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.slot-sub {
  font-size: 12px;
  opacity: 0.75;
}

/* Pointer arrows + center highlight line */
.slot-pointer {
  position: absolute;
  top: 50%;
  transform: translateY(-50%);
  color: #ef4444;
  font-size: 34px;
  z-index: 4;
  filter: drop-shadow(0 0 12px rgba(239,68,68,0.7));
  pointer-events: none;
}
.slot-pointer-left  { left: -6px; }
.slot-pointer-right { right: -6px; }
.slot-center-line {
  position: absolute;
  top: 50%;
  left: 8px;
  right: 8px;
  height: 120px;
  transform: translateY(-50%);
  border-top: 2px solid rgba(239,68,68,0.7);
  border-bottom: 2px solid rgba(239,68,68,0.7);
  pointer-events: none;
  z-index: 2;
  box-shadow: 0 0 18px rgba(239,68,68,0.35);
}

/* In slot mode, lift fab-bottom above the slot window so the spin button is visible */
body.wheel-mode .fab-bottom { z-index: 50; }

/* When wheel mode is active: dim the photo canvas, hide its boxes distraction */
body.wheel-mode #resultCanvas {
  filter: brightness(0.25) saturate(0.6) blur(6px);
  opacity: 0.6;
}
body.wheel-mode .edit-hint-fab { display: none; }

/* Mode toggle (ลำดับ / กลุ่ม) */
.mode-toggle {
  display: inline-flex;
  gap: 2px;
  padding: 3px;
  background: rgba(15,23,42,0.65);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}
.mode-toggle button {
  padding: 7px 16px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.7);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, transform 0.1s;
  white-space: nowrap;
}
.mode-toggle button:active { transform: scale(0.95); }
.mode-toggle button.active {
  background: linear-gradient(135deg, #0ea5e9, #06b6d4);
  color: #fff;
  box-shadow: 0 3px 10px rgba(14,165,233,0.5);
}

/* Rank mode segmented control */
.rank-mode {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  background: rgba(15,23,42,0.65);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 999px;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  box-shadow: 0 6px 18px rgba(0,0,0,0.25);
}
.rank-mode-label {
  color: rgba(255,255,255,0.85);
  font-size: 12px;
  font-weight: 600;
  padding: 0 4px;
  letter-spacing: 0.2px;
}
.rank-mode button {
  min-width: 34px;
  padding: 6px 4px;
  border: none;
  background: transparent;
  color: rgba(255,255,255,0.7);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s, color 0.15s, transform 0.1s;
}
.rank-mode button:active { transform: scale(0.92); }
.rank-mode button.active {
  background: linear-gradient(135deg, #0ea5e9, #06b6d4);
  color: #fff;
  box-shadow: 0 3px 10px rgba(14,165,233,0.5);
}

.count-custom-input {
  width: 62px;
  padding: 6px 6px;
  border: 1.5px dashed rgba(255,255,255,0.4);
  background: transparent;
  color: rgba(255,255,255,0.9);
  border-radius: 999px;
  font-size: 13px;
  font-weight: 700;
  text-align: center;
  font-family: inherit;
  outline: none;
  transition: background 0.15s, border-color 0.15s, box-shadow 0.15s;
}
.count-custom-input::placeholder { color: rgba(255,255,255,0.55); font-weight: 500; }
.count-custom-input:focus {
  border-color: #fff;
  background: rgba(255,255,255,0.12);
  color: #fff;
}
.count-custom-input.active {
  background: linear-gradient(135deg, #0ea5e9, #06b6d4);
  color: #fff;
  border-style: solid;
  border-color: rgba(255,255,255,0.3);
  box-shadow: 0 3px 10px rgba(14,165,233,0.5);
}
.count-custom-input::-webkit-inner-spin-button,
.count-custom-input::-webkit-outer-spin-button { -webkit-appearance: none; margin: 0; }
.count-custom-input { -moz-appearance: textfield; appearance: textfield; }

/* Results list overlay (multi-rank) */
.results-overlay {
  position: fixed;
  inset: 0;
  z-index: 48;
}
.results-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,0.65);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  animation: tipsBackdropIn 0.3s ease both;
}
.results-panel {
  position: absolute;
  left: 50%; top: 50%;
  transform: translate(-50%, -50%);
  width: min(94vw, 460px);
  max-height: min(86vh, 720px);
  padding: calc(18px + var(--safe-top)) 18px calc(18px + var(--safe-bottom));
  background: linear-gradient(180deg, #0284c7 0%, #38bdf8 60%, #7dd3fc 100%);
  border: 1.5px solid rgba(255,255,255,0.25);
  border-radius: 24px;
  color: #fff;
  display: flex;
  flex-direction: column;
  box-shadow: 0 30px 80px rgba(0,0,0,0.5), inset 0 1px 0 rgba(255,255,255,0.15);
  animation: resultsPanelIn 0.5s cubic-bezier(0.34, 1.5, 0.64, 1) both;
  overflow: hidden;
}
@keyframes resultsPanelIn {
  0%   { transform: translate(-50%, -50%) scale(0.6); opacity: 0; }
  60%  { transform: translate(-50%, -50%) scale(1.04); opacity: 1; }
  100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
}

.results-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding-bottom: 12px;
  margin-bottom: 14px;
  border-bottom: 1px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
}
.results-title {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 18px;
  font-weight: 800;
  letter-spacing: 0.3px;
}
.results-title-emoji {
  font-size: 22px;
  animation: tipSparkle 1.8s ease-in-out infinite;
  display: inline-block;
}

.results-grid {
  flex: 1 1 auto;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 2px;
}
.results-grid::-webkit-scrollbar { width: 4px; }
.results-grid::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 2px; }

.result-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,0.14);
  border: 1px solid rgba(255,255,255,0.18);
  border-radius: 14px;
  padding: 10px 12px;
  animation: resultItemIn 0.5s cubic-bezier(0.34, 1.4, 0.64, 1) both;
  animation-delay: calc(var(--i, 0) * 85ms + 200ms);
}
.result-item.rank-1 {
  background: linear-gradient(135deg, rgba(245,158,11,0.55) 0%, rgba(239,68,68,0.35) 100%);
  border-color: #fbbf24;
  box-shadow: 0 6px 24px rgba(245,158,11,0.35);
}
.result-item.rank-2 {
  background: linear-gradient(135deg, rgba(203,213,225,0.5) 0%, rgba(148,163,184,0.3) 100%);
  border-color: #e2e8f0;
}
.result-item.rank-3 {
  background: linear-gradient(135deg, rgba(217,119,6,0.45) 0%, rgba(180,83,9,0.3) 100%);
  border-color: #fb923c;
}

.result-rank {
  flex-shrink: 0;
  width: 38px;
  height: 38px;
  border-radius: 50%;
  background: rgba(0,0,0,0.25);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  border: 1.5px solid rgba(255,255,255,0.3);
}
.result-item.rank-1 .result-rank { background: rgba(0,0,0,0.35); font-size: 26px; }
.result-avatar {
  flex-shrink: 0;
  width: 54px;
  height: 54px;
  border-radius: 50%;
  border: 2px solid rgba(255,255,255,0.9);
  background: #0f172a;
  display: block;
}
.result-item.rank-1 .result-avatar {
  width: 68px; height: 68px;
  border-color: #fbbf24;
  box-shadow: 0 0 20px rgba(245,158,11,0.6);
}
.result-label {
  flex: 1;
  min-width: 0;
  line-height: 1.3;
}
.result-rank-num {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}
.result-item.rank-1 .result-rank-num { font-size: 17px; font-weight: 800; }
.result-person {
  font-size: 12.5px;
  color: rgba(255,255,255,0.85);
  margin-top: 1px;
}

.results-actions {
  display: flex;
  gap: 10px;
  padding-top: 14px;
  margin-top: 12px;
  border-top: 1px solid rgba(255,255,255,0.2);
  flex-shrink: 0;
}
.results-actions .btn-fab-hero {
  flex: 1;
  font-size: 16px;
  padding: 13px 20px;
  background: #fff;
  color: var(--primary-hover);
  box-shadow: 0 6px 20px rgba(0,0,0,0.25);
}
.results-actions .btn-fab-chip {
  flex: 0 0 auto;
  padding: 13px 16px;
  font-size: 13px;
  background: rgba(15,23,42,0.4);
  border: 1px solid rgba(255,255,255,0.3);
  color: #fff;
}

@keyframes resultItemIn {
  from { opacity: 0; transform: translateX(-24px); }
  to   { opacity: 1; transform: translateX(0); }
}

/* Group sections (team split results) */
.group-section {
  background: rgba(255,255,255,0.06);
  border: 2px solid var(--g-color, rgba(255,255,255,0.2));
  border-radius: 14px;
  padding: 0;
  overflow: hidden;
  flex-shrink: 0;
  animation: resultItemIn 0.5s cubic-bezier(0.34, 1.4, 0.64, 1) both;
  animation-delay: calc(var(--i, 0) * 110ms + 250ms);
  box-shadow: 0 0 0 1px rgba(0,0,0,0.25);
}
.result-item { flex-shrink: 0; }
.group-header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  background: var(--g-color, #0284c7);
  color: #fff;
  font-size: 15px;
  font-weight: 800;
  text-shadow: 0 1px 2px rgba(0,0,0,0.35);
}
.group-num-badge {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: rgba(0,0,0,0.35);
  border: 2px solid #fff;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 900;
  flex-shrink: 0;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
}
.group-name { flex: 1; min-width: 0; font-weight: 800; }
.group-count {
  font-size: 12px;
  font-weight: 700;
  background: rgba(0,0,0,0.35);
  padding: 4px 10px;
  border-radius: 999px;
  letter-spacing: 0.3px;
}
.group-avatars {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(68px, 1fr));
  gap: 10px;
  padding: 12px;
}
.group-avatars::-webkit-scrollbar { width: 4px; }
.group-avatars::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.3); border-radius: 2px; }
.group-avatar-wrap {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  min-width: 0;
}
.group-avatar {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  border: 2.5px solid var(--g-color, #fff);
  background: #0f172a;
  box-shadow: 0 4px 12px rgba(0,0,0,0.35);
}
.group-avatar-name {
  font-size: 11px;
  font-weight: 600;
  color: #fff;
  max-width: 100%;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  text-align: center;
}

/* Expand results panel for group grids */
.results-panel:has(.group-section) { width: min(94vw, 520px); }

/* Spotlight backdrop dim — clickable to dismiss */
.spotlight-backdrop {
  position: fixed;
  inset: 0;
  background: radial-gradient(circle at center,
    rgba(0,0,0,0.55) 0%,
    rgba(0,0,0,0.88) 70%);
  z-index: 42;
  cursor: pointer;
  animation: backdropFade 0.5s ease both;
}
@keyframes backdropFade { from { opacity: 0; } to { opacity: 1; } }

/* Face crop spotlight */
.picked-spotlight {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  z-index: 46;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 18px;
  max-width: 92vw;
  margin-top: -3vh;
}
.spotlight-ring {
  position: relative;
  width: min(64vw, 320px);
  height: min(64vw, 320px);
  border-radius: 50%;
  padding: 4px;
  background: linear-gradient(135deg, #f59e0b 0%, #ef4444 60%, #d946ef 100%);
  box-shadow:
    0 0 0 1.5px rgba(255,255,255,0.85),
    0 18px 50px rgba(0,0,0,0.65),
    0 0 90px rgba(245,158,11,0.5),
    0 0 160px rgba(217,70,239,0.3);
  animation: spotlightPop 0.85s cubic-bezier(0.34, 1.56, 0.64, 1) both,
             spotlightGlow 2.6s ease-in-out 0.85s infinite;
}
.spotlight-ring::before {
  content: '';
  position: absolute;
  inset: -8px;
  border-radius: 50%;
  border: 1px dashed rgba(255,255,255,0.3);
  animation: spin 14s linear infinite;
  pointer-events: none;
}
#pickedFaceCanvas {
  display: block;
  width: 100%;
  height: 100%;
  border-radius: 50%;
  background: #0f172a;
  object-fit: cover;
}
.picked-label {
  background: linear-gradient(135deg, #f59e0b 0%, #ef4444 100%);
  color: #fff;
  padding: 12px 26px;
  border-radius: 999px;
  font-size: 22px;
  font-weight: 700;
  box-shadow: 0 10px 30px rgba(245,158,11,0.55),
              0 0 0 3px rgba(255,255,255,0.2);
  letter-spacing: 0.5px;
  animation: labelUp 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.25s both;
}
.picked-sub {
  font-size: 13px;
  color: rgba(255,255,255,0.85);
  background: rgba(15,23,42,0.7);
  padding: 5px 14px;
  border-radius: 999px;
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  animation: labelUp 0.6s cubic-bezier(0.34, 1.56, 0.64, 1) 0.35s both;
}
.picked-sub:empty { display: none; }

.spotlight-close {
  position: absolute;
  top: -52px;
  right: -6px;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1.5px solid rgba(255,255,255,0.4);
  background: rgba(15,23,42,0.8);
  color: #fff;
  font-size: 16px;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  pointer-events: auto;
  transition: transform 0.1s, background 0.15s;
  font-family: inherit;
  box-shadow: 0 6px 20px rgba(0,0,0,0.4);
  animation: labelUp 0.5s cubic-bezier(0.34, 1.56, 0.64, 1) 0.4s both;
}
.spotlight-close:active { transform: scale(0.9); background: rgba(15,23,42,0.95); }
@media (max-width: 400px) {
  .spotlight-close { top: -48px; right: 50%; transform: translateX(50%); }
}

@keyframes spotlightPop {
  0%   { transform: scale(0.2) rotate(-8deg); opacity: 0; }
  55%  { transform: scale(1.08) rotate(2deg); opacity: 1; }
  100% { transform: scale(1) rotate(0); opacity: 1; }
}
@keyframes spotlightGlow {
  0%, 100% { filter: brightness(1); }
  50%      { filter: brightness(1.15); }
}
@keyframes labelUp {
  from { transform: translateY(18px); opacity: 0; }
  to   { transform: translateY(0); opacity: 1; }
}

/* When spotlight is shown, dim the main canvas */
.result-stage.zoomed #resultCanvas {
  filter: brightness(0.35) saturate(0.7) blur(1px);
}

/* Bottom floating controls */
.fab-bottom {
  position: fixed;
  left: 0; right: 0;
  bottom: 0;
  padding: 16px 16px calc(16px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 10px;
  z-index: 40;
  background: linear-gradient(to top, rgba(0,0,0,0.85) 0%, rgba(0,0,0,0.4) 60%, transparent 100%);
  pointer-events: none;
}
.fab-bottom > * { pointer-events: auto; }
.fab-primary-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
  max-width: 500px;
  justify-content: center;
}
.btn-fab-hero {
  flex: 1;
  max-width: 360px;
  padding: 16px 28px;
  font-size: 18px;
  font-weight: 700;
  border: none;
  border-radius: 999px;
  background: linear-gradient(135deg, #0ea5e9 0%, #06b6d4 100%);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 10px 30px rgba(14,165,233,0.5), 0 0 0 3px rgba(255,255,255,0.15);
  font-family: inherit;
  transition: transform 0.1s, box-shadow 0.2s;
}
.btn-fab-hero:active:not(:disabled) { transform: scale(0.96); box-shadow: 0 6px 20px rgba(14,165,233,0.4); }
.btn-fab-hero:disabled { opacity: 0.7; cursor: wait; }

.fab-secondary-row {
  display: flex;
  gap: 8px;
  justify-content: center;
  flex-wrap: wrap;
}
.btn-fab-chip {
  background: rgba(255,255,255,0.12);
  border: 1px solid rgba(255,255,255,0.15);
  color: #fff;
  padding: 9px 16px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  backdrop-filter: blur(14px);
  -webkit-backdrop-filter: blur(14px);
  font-family: inherit;
  transition: transform 0.1s, background 0.15s;
}
.btn-fab-chip:active { transform: scale(0.95); background: rgba(255,255,255,0.2); }
.btn-fab-chip.active {
  background: #f59e0b;
  color: #1e1b4b;
  border-color: #fff;
  font-weight: 700;
}
.btn-fab-chip.active:active { background: #d97706; }

.pool-chip {
  background: rgba(15,23,42,0.8);
  color: rgba(255,255,255,0.9);
  padding: 6px 14px;
  border-radius: 999px;
  font-size: 12px;
  backdrop-filter: blur(10px);
}

.camera-hint {
  position: absolute;
  top: calc(64px + var(--safe-top));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(245,158,11,0.95);
  color: #1e1b4b;
  padding: 8px 14px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  max-width: 90vw;
  z-index: 10;
}

/* Very small screens */
@media (max-height: 640px) {
  .picked-badge { bottom: calc(180px + var(--safe-bottom)); }
  .picked-label { font-size: 20px; padding: 10px 22px; }
  .btn-fab-hero { padding: 14px 24px; font-size: 16px; }
}
.result-info {
  text-align: center;
  display: flex;
  flex-direction: column;
  gap: 6px;
}
.result-count {
  font-size: 15px;
  color: var(--text-muted);
}
.result-picked {
  font-size: 22px;
  font-weight: 700;
  color: var(--warn);
  min-height: 30px;
}
.result-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}
.pool-info {
  text-align: center;
  font-size: 13px;
  color: var(--text-muted);
  padding: 8px;
}

/* MODAL */
.modal {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.7);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
  backdrop-filter: blur(4px);
}
.modal-content {
  background: #fff;
  color: var(--text);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 420px;
  width: 100%;
  max-height: 85vh;
  overflow-y: auto;
}
.modal-content h2 { margin-top: 0; }
.modal-content h3 { margin-top: 20px; font-size: 16px; }
.modal-content ul { padding-left: 20px; line-height: 1.7; }
.modal-content .btn { width: 100%; margin-top: 20px; }

/* LOADING */
.loading-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.75);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  z-index: 200;
  color: #fff;
  font-size: 15px;
}
.loader {
  width: 48px;
  height: 48px;
  border: 4px solid rgba(255,255,255,0.2);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* TOAST */
.toast {
  position: fixed;
  bottom: calc(100px + var(--safe-bottom));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(15,23,42,0.95);
  color: #fff;
  padding: 12px 20px;
  border-radius: 999px;
  font-size: 14px;
  z-index: 150;
  box-shadow: var(--shadow);
  animation: toastIn 0.2s;
}
@keyframes toastIn {
  from { opacity: 0; transform: translate(-50%, 10px); }
  to { opacity: 1; transform: translate(-50%, 0); }
}

/* Small screens */
@media (max-height: 640px) {
  .start-emoji { font-size: 60px; }
  .start-hero h1 { font-size: 26px; }
  .subtitle { font-size: 16px; }
}
