/* ============================================================
   Your Face Puzzle — neon-cyan theme on a black stage.
   ============================================================ */

:root {
  --cyan: #43f4ff;
  --cyan-dim: #1bc6d2;
  --bg: #000;
  --text: #ffffff;
  --text-dim: #a8b3c2;
  --danger: #ff6a85;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  /* On mobile Safari `100vh` includes the URL bar and pushes content
     offscreen. `100dvh` (dynamic viewport height) updates as the bar
     hides/shows. The fallbacks cover older browsers. */
  height: 100%;
  height: -webkit-fill-available;
  height: 100dvh;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: "Inter", "SF Pro Text", system-ui, -apple-system, "Segoe UI",
    Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  -webkit-user-select: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  /* Stop pull-to-refresh and rubber-band scrolling. */
  overscroll-behavior: none;
  /* The whole page is gestural; never let the browser intercept. */
  touch-action: none;
}

#webcam {
  position: fixed;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
  top: 0;
  left: 0;
}

#app {
  position: relative;
  width: 100%;
  height: 100%;
}

#stage {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  display: block;
  background: #000;
  touch-action: none;
}

/* ----------------------------- Status pill ----------------------------- */
.status-pill {
  position: absolute;
  /* Respect the iPhone notch / Dynamic Island. */
  top: max(18px, calc(env(safe-area-inset-top) + 10px));
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(67, 244, 255, 0.45);
  color: var(--text);
  padding: 8px 18px;
  border-radius: 999px;
  font-size: 13px;
  letter-spacing: 0.04em;
  z-index: 5;
  white-space: nowrap;
  max-width: calc(100vw - 32px);
  text-align: center;
  text-overflow: ellipsis;
  overflow: hidden;
  transition: opacity 0.25s ease;
}

.status-pill.hidden {
  opacity: 0;
  pointer-events: none;
}

/* ----------------------------- Control panel ----------------------------- */
.control-panel {
  position: absolute;
  bottom: max(16px, calc(env(safe-area-inset-bottom) + 12px));
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px;
  background: rgba(0, 0, 0, 0.55);
  -webkit-backdrop-filter: blur(10px);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(67, 244, 255, 0.45);
  border-radius: 999px;
  box-shadow: 0 0 24px rgba(67, 244, 255, 0.12);
  z-index: 6;
  max-width: calc(100vw - 24px);
  transition: opacity 0.25s ease, transform 0.25s ease;
}

.control-panel.hidden {
  opacity: 0;
  transform: translate(-50%, 18px);
  pointer-events: none;
}

/* Difficulty segmented control */
.seg {
  display: flex;
  gap: 2px;
  padding: 2px;
  background: rgba(255, 255, 255, 0.04);
  border-radius: 999px;
}

.seg-btn {
  appearance: none;
  border: none;
  background: transparent;
  color: var(--text-dim);
  padding: 8px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  font-variant-numeric: tabular-nums;
  min-width: 44px;
  min-height: 36px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, color 0.15s ease;
}

.seg-btn:hover,
.seg-btn:focus-visible {
  outline: none;
  color: var(--text);
  background: rgba(255, 255, 255, 0.06);
}

.seg-btn.active {
  color: #08111c;
  background: var(--cyan);
  box-shadow: 0 0 14px rgba(67, 244, 255, 0.55);
}

/* Vertical divider between segments and actions */
.ctrl-divider {
  width: 1px;
  height: 24px;
  background: rgba(255, 255, 255, 0.18);
  margin: 0 4px;
}

/* Action buttons (Shuffle / Reset) */
.ctrl-action {
  appearance: none;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  border: 1px solid rgba(67, 244, 255, 0.45);
  background: rgba(0, 0, 0, 0.35);
  color: var(--text);
  padding: 7px 12px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  min-height: 36px;
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
  transition: background 0.15s ease, transform 0.12s ease, opacity 0.2s ease;
}

.ctrl-action:hover:not(:disabled),
.ctrl-action:focus-visible:not(:disabled) {
  outline: none;
  background: rgba(67, 244, 255, 0.14);
  transform: translateY(-1px);
}

.ctrl-action:active:not(:disabled) {
  transform: translateY(0);
}

.ctrl-action:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.ctrl-action .icn {
  font-size: 14px;
  line-height: 1;
  display: inline-block;
  transform: translateY(-1px);
}

/* ----------------------------- Overlays ----------------------------- */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.65);
  -webkit-backdrop-filter: blur(8px);
  backdrop-filter: blur(8px);
  z-index: 10;
  padding: max(16px, env(safe-area-inset-top)) max(16px, env(safe-area-inset-right))
    max(16px, env(safe-area-inset-bottom)) max(16px, env(safe-area-inset-left));
  animation: fadeIn 0.35s ease both;
}

.overlay.hidden {
  display: none;
}

@keyframes fadeIn {
  from {
    opacity: 0;
  }
  to {
    opacity: 1;
  }
}

/* ----------------------------- Start card ----------------------------- */
.start-card {
  text-align: center;
  width: 100%;
  max-width: 380px;
  padding: 36px 28px;
  border-radius: 18px;
  background: rgba(10, 14, 22, 0.85);
  border: 1px solid rgba(67, 244, 255, 0.35);
  box-shadow: 0 0 60px rgba(67, 244, 255, 0.15);
}

.title-emoji {
  font-size: 48px;
  line-height: 1;
  margin-bottom: 8px;
}

.start-card h1 {
  font-size: 28px;
  margin: 0 0 10px;
  letter-spacing: -0.01em;
}

.start-card p {
  margin: 0 0 22px;
  color: var(--text-dim);
  font-size: 14px;
  line-height: 1.5;
}

.error {
  color: var(--danger);
  margin-top: 12px;
  font-size: 13px;
  min-height: 18px;
}

/* ----------------------------- Win card (SELESAI) ----------------------------- */
.win-card {
  width: min(300px, 78vw);
  background: rgba(10, 14, 22, 0.92);
  border: 2px solid var(--cyan);
  border-radius: 12px;
  padding: 18px 18px 22px;
  text-align: center;
  box-shadow:
    0 0 0 4px rgba(67, 244, 255, 0.10),
    0 0 60px rgba(67, 244, 255, 0.35),
    0 30px 80px rgba(0, 0, 0, 0.55);
  animation: popIn 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28) both;
}

@keyframes popIn {
  from {
    opacity: 0;
    transform: scale(0.7);
  }
  to {
    opacity: 1;
    transform: scale(1);
  }
}

.neon-title {
  margin: 6px 0 14px;
  font-size: 32px;
  letter-spacing: 0.06em;
  color: var(--cyan);
  text-shadow:
    0 0 6px rgba(67, 244, 255, 0.85),
    0 0 16px rgba(67, 244, 255, 0.55),
    0 0 32px rgba(67, 244, 255, 0.35);
  font-weight: 800;
}

.win-photo {
  width: 70%;
  margin: 0 auto 14px;
  aspect-ratio: 1 / 1;
  border-radius: 8px;
  overflow: hidden;
  background: #111;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.win-photo img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.waktu {
  font-weight: 800;
  letter-spacing: 0.08em;
  font-size: 16px;
  color: var(--cyan);
  margin-bottom: 14px;
  text-shadow: 0 0 8px rgba(67, 244, 255, 0.45);
  font-variant-numeric: tabular-nums;
}

/* ----------------------------- Buttons ----------------------------- */
.neon-btn {
  display: inline-block;
  /* iOS recommends ≥44px hit targets — 12px vertical padding + line-height
     gets us comfortably above that. */
  padding: 12px 28px;
  min-height: 44px;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.10em;
  color: var(--text);
  background: rgba(0, 0, 0, 0.55);
  border: 1.5px solid var(--cyan);
  border-radius: 999px;
  cursor: pointer;
  font-family: inherit;
  transition: transform 0.15s ease, box-shadow 0.2s ease,
    background 0.2s ease;
  box-shadow: 0 0 0 0 rgba(67, 244, 255, 0);
  touch-action: manipulation;
  -webkit-tap-highlight-color: transparent;
}

.neon-btn:hover,
.neon-btn:focus-visible {
  outline: none;
  transform: translateY(-1px);
  background: rgba(67, 244, 255, 0.12);
  box-shadow: 0 0 18px rgba(67, 244, 255, 0.55);
}

.neon-btn:active {
  transform: translateY(0);
}

.neon-btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
  box-shadow: none;
}

/* ============================================================
   Responsive
   ============================================================ */

/* Most phones in portrait (≤480px wide). */
@media (max-width: 480px) {
  .start-card {
    padding: 28px 22px;
    border-radius: 16px;
  }

  .title-emoji {
    font-size: 40px;
  }

  .start-card h1 {
    font-size: 24px;
  }

  .start-card p {
    font-size: 13.5px;
  }

  .status-pill {
    font-size: 12px;
    padding: 7px 14px;
  }

  .neon-title {
    font-size: 28px;
  }

  .waktu {
    font-size: 15px;
  }

  .win-card {
    width: min(280px, calc(100vw - 32px));
    padding: 16px 16px 18px;
  }

  /* Tap-only — disable hover lift to avoid sticky-hover on touch. */
  .neon-btn:hover,
  .neon-btn:focus-visible {
    transform: none;
    box-shadow: 0 0 12px rgba(67, 244, 255, 0.4);
  }

  /* Compact control panel on phones — icon-only actions, smaller seg. */
  .control-panel {
    gap: 6px;
    padding: 5px;
  }
  .seg-btn {
    padding: 7px 9px;
    font-size: 11px;
    min-width: 38px;
    min-height: 34px;
  }
  .ctrl-action {
    padding: 7px 10px;
    min-height: 34px;
  }
  .ctrl-action .lbl {
    display: none;
  }
  .ctrl-action .icn {
    font-size: 16px;
    transform: none;
  }
  .ctrl-divider {
    height: 20px;
    margin: 0 2px;
  }
}

/* Short / landscape phones — keep the card compact vertically. */
@media (max-height: 520px) and (orientation: landscape) {
  .start-card {
    padding: 18px 22px;
  }
  .title-emoji {
    font-size: 32px;
    margin-bottom: 4px;
  }
  .start-card h1 {
    font-size: 20px;
    margin-bottom: 6px;
  }
  .start-card p {
    margin-bottom: 14px;
    font-size: 13px;
  }
  .win-card {
    padding: 12px 14px 16px;
  }
  .win-photo {
    width: 50%;
  }
  .neon-title {
    font-size: 24px;
    margin: 2px 0 8px;
  }
}

/* Older browsers without backdrop-filter support — solid fallback. */
@supports not ((backdrop-filter: blur(1px)) or (-webkit-backdrop-filter: blur(1px))) {
  .status-pill,
  .overlay {
    background: rgba(0, 0, 0, 0.85);
  }
}
