/* ===================== CopaBooth ===================== */
:root {
  --green: #009b3a;
  --yellow: #ffdf00;
  --blue: #002776;
  --gold: #caa24a;
  --ink: #0a1f12;
  --bg: #07140c;
  --panel: rgba(0, 0, 0, .35);
  --radius: 22px;
  --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%;
  overflow: hidden;
  background: var(--bg);
  color: #fff;
  font-family: "Inter", system-ui, -apple-system, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  overscroll-behavior: none;
  touch-action: manipulation;
}

#app {
  position: fixed;
  inset: 0;
  background:
    radial-gradient(circle at 20% 0%, rgba(0, 155, 58, .35), transparent 55%),
    radial-gradient(circle at 90% 100%, rgba(255, 223, 0, .22), transparent 50%),
    var(--bg);
}

/* ---------- screen routing ---------- */
.screen {
  position: absolute;
  inset: 0;
  display: none;
  flex-direction: column;
  padding: var(--safe-top) 0 var(--safe-bottom);
}
.screen.active { display: flex; }

/* ---------- buttons ---------- */
.btn {
  font-family: "Inter", sans-serif;
  font-weight: 800;
  border: none;
  border-radius: 999px;
  cursor: pointer;
  transition: transform .08s ease, filter .15s ease, opacity .15s;
  color: #fff;
}
.btn:active { transform: scale(.95); }
.btn:disabled { opacity: .55; }
.btn-primary {
  background: linear-gradient(135deg, var(--green), #00b347);
  box-shadow: 0 10px 24px rgba(0, 155, 58, .4);
}
.btn-secondary {
  background: linear-gradient(135deg, #1f6feb, var(--blue));
  box-shadow: 0 10px 24px rgba(0, 39, 118, .4);
}
.btn-ghost {
  background: rgba(255, 255, 255, .12);
  border: 1px solid rgba(255, 255, 255, .25);
}
.btn-xl { font-size: 26px; padding: 22px 46px; }
.btn-lg { font-size: 18px; padding: 16px 22px; }

/* ---------- START screen ---------- */
.start-card {
  margin: auto;
  text-align: center;
  padding: 28px;
  max-width: 560px;
}
.start-logo { font-size: 72px; line-height: 1; }
.start-title {
  font-family: "Anton", sans-serif;
  font-size: clamp(56px, 12vw, 110px);
  margin: 8px 0 0;
  letter-spacing: 1px;
  background: linear-gradient(135deg, var(--yellow), #fff 60%, var(--green));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 4px 12px rgba(0, 0, 0, .5));
}
.start-sub {
  font-family: "Playfair Display", serif;
  font-weight: 700;
  font-size: clamp(18px, 4vw, 28px);
  color: var(--gold);
  margin: 4px 0 2px;
}
.start-meta {
  font-weight: 700;
  letter-spacing: 1px;
  opacity: .85;
  margin: 0 0 30px;
  text-transform: uppercase;
  font-size: 14px;
}
.start-hint { opacity: .6; font-size: 14px; margin-top: 22px; }
.start-error {
  color: #ffd0d0;
  background: rgba(193, 39, 45, .35);
  border: 1px solid rgba(255, 120, 120, .5);
  padding: 12px 16px;
  border-radius: 14px;
  margin-top: 22px;
  font-weight: 600;
}

/* ---------- top bar ---------- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 22px;
  flex: 0 0 auto;
}
.topbar-brand {
  font-family: "Anton", sans-serif;
  font-size: 26px;
  letter-spacing: .5px;
}
.topbar-tag {
  font-weight: 800;
  font-size: 13px;
  letter-spacing: 1px;
  color: var(--yellow);
  background: rgba(0, 0, 0, .3);
  padding: 6px 12px;
  border-radius: 999px;
}

/* ---------- camera stage ---------- */
.stage-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 4px 16px;
}
.stage {
  position: relative;
  aspect-ratio: 3 / 4; /* portrait-locked booth */
  height: 100%;
  max-height: 100%;
  max-width: 100%;
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
}
#video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
}
.overlay {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

/* countdown */
.countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, .25);
  z-index: 5;
}
.countdown[hidden] { display: none; }
#count-num {
  font-family: "Archivo Black", sans-serif;
  font-size: clamp(120px, 38vmin, 320px);
  color: #fff;
  text-shadow: 0 0 40px rgba(0, 0, 0, .8), 0 8px 24px rgba(0, 0, 0, .6);
}
#count-num.pulse { animation: pop .8s ease-out; }
@keyframes pop {
  0% { transform: scale(.3); opacity: 0; }
  35% { transform: scale(1.15); opacity: 1; }
  100% { transform: scale(1); opacity: 1; }
}

/* shutter flash */
.flash {
  position: absolute;
  inset: 0;
  background: #fff;
  opacity: 0;
  pointer-events: none;
  z-index: 6;
}
.flash.fire { animation: flash .35s ease-out; }
@keyframes flash {
  0% { opacity: 0; }
  10% { opacity: .95; }
  100% { opacity: 0; }
}

/* ---------- skin picker ---------- */
.skin-picker {
  flex: 0 0 auto;
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding: 14px 18px 6px;
  scroll-snap-type: x mandatory;
  -webkit-overflow-scrolling: touch;
}
.skin-picker::-webkit-scrollbar { display: none; }
.skin-thumb {
  flex: 0 0 auto;
  background: transparent;
  border: 3px solid transparent;
  border-radius: 16px;
  padding: 0;
  cursor: pointer;
  position: relative;
  scroll-snap-align: center;
  transition: transform .1s ease, border-color .15s ease;
  overflow: hidden;
}
.skin-thumb canvas {
  display: block;
  border-radius: 12px;
}
.skin-thumb.selected {
  border-color: var(--yellow);
  transform: translateY(-2px);
}
.skin-name {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  font-size: 11px;
  font-weight: 800;
  text-align: center;
  padding: 14px 4px 5px;
  background: linear-gradient(to top, rgba(0, 0, 0, .85), transparent);
  text-transform: uppercase;
  letter-spacing: .4px;
}

/* ---------- camera controls ---------- */
.controls {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 36px 24px;
}
.btn-spacer, .btn-flip-spacer { width: 58px; }
#btn-flip {
  width: 58px; height: 58px;
  font-size: 26px;
  display: flex; align-items: center; justify-content: center;
}
.btn-capture {
  width: 86px; height: 86px;
  border-radius: 50%;
  background: #fff;
  display: flex; align-items: center; justify-content: center;
  box-shadow: 0 0 0 4px rgba(255, 255, 255, .25), 0 12px 30px rgba(0, 0, 0, .5);
  padding: 0;
}
.shutter-ring {
  width: 70px; height: 70px;
  border-radius: 50%;
  background: linear-gradient(135deg, var(--green), var(--yellow));
  border: 4px solid #fff;
}

/* ---------- result ---------- */
.result-wrap {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 6px 16px;
}
.result-img {
  max-height: 100%;
  max-width: 100%;
  border-radius: var(--radius);
  box-shadow: 0 18px 50px rgba(0, 0, 0, .55);
  object-fit: contain;
}
.result-actions {
  flex: 0 0 auto;
  display: flex;
  gap: 12px;
  justify-content: center;
  flex-wrap: wrap;
  padding: 12px 18px 6px;
}
.result-msg {
  text-align: center;
  min-height: 22px;
  margin: 4px 0 16px;
  font-weight: 600;
  color: var(--yellow);
  padding: 0 18px;
}

/* =========================================================================
   LANDSCAPE (iPad held horizontally) — stage left, control rail right
   ========================================================================= */
@media (orientation: landscape) {
  #screen-camera.active {
    display: grid;
    grid-template-columns: 1fr clamp(180px, 22vw, 240px);
    grid-template-rows: auto auto 1fr;
    grid-template-areas:
      "top    top"
      "stage  controls"
      "stage  picker";
    column-gap: 6px;
  }
  .topbar { grid-area: top; }
  .stage-wrap { grid-area: stage; padding: 4px 6px 10px 14px; }

  /* control rail */
  .controls {
    grid-area: controls;
    flex-direction: column;
    gap: 14px;
    padding: 6px 16px 4px 6px;
    align-items: center;
  }
  .controls .btn-spacer { display: none; }
  #btn-flip { order: 2; }
  .btn-capture { order: 1; }

  /* thumbnails stack vertically and scroll */
  .skin-picker {
    grid-area: picker;
    flex-direction: column;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 4px 16px 10px 6px;
    scroll-snap-type: y proximity;
    align-items: center;
  }

  /* result screen: image left, actions right */
  #screen-result.active {
    display: grid;
    grid-template-columns: 1fr clamp(200px, 26vw, 300px);
    grid-template-rows: auto 1fr auto;
    grid-template-areas:
      "top   top"
      "img   actions"
      "img   msg";
    column-gap: 6px;
  }
  #screen-result .topbar { grid-area: top; }
  .result-wrap { grid-area: img; }
  .result-actions {
    grid-area: actions;
    flex-direction: column;
    align-content: center;
    justify-content: center;
    padding: 6px 18px;
  }
  .result-actions .btn { width: 100%; }
  .result-msg { grid-area: msg; }
}

/* portrait — vertical photo + stacked layout (base flex layout applies) */
@media (orientation: portrait) {
  .stage { aspect-ratio: 3 / 4; }
}

/* =========================================================================
   ROTATE WARNING — booth is portrait-only; cover the screen in landscape
   ========================================================================= */
#rotate-warn { display: none; }
@media (orientation: landscape) {
  #rotate-warn {
    display: flex;
    position: fixed;
    inset: 0;
    z-index: 99999;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 24px;
    background:
      radial-gradient(circle at 30% 20%, rgba(0, 155, 58, .4), transparent 55%),
      radial-gradient(circle at 80% 90%, rgba(255, 223, 0, .25), transparent 50%),
      var(--bg);
  }
  /* keep the underlying app from showing through / being usable sideways */
  #app { filter: blur(2px); }
}
.rotate-card { max-width: 460px; }
.rotate-icon {
  font-size: clamp(60px, 16vw, 110px);
  line-height: 1;
  display: inline-block;
  transform-origin: center;
  animation: tip 1.8s ease-in-out infinite;
}
@keyframes tip {
  0%, 60%, 100% { transform: rotate(-90deg); }
  30% { transform: rotate(0deg); }
}
#rotate-warn h2 {
  font-family: "Anton", sans-serif;
  font-size: clamp(28px, 6vw, 44px);
  margin: 18px 0 8px;
  color: var(--yellow);
}
#rotate-warn p { font-size: clamp(16px, 3.5vw, 20px); margin: 4px 0; font-weight: 700; }
#rotate-warn .rotate-sub { opacity: .7; font-weight: 500; }

/* very short landscape (phones) — shrink the shutter a touch */
@media (orientation: landscape) and (max-height: 480px) {
  .btn-capture { width: 66px; height: 66px; }
  .shutter-ring { width: 52px; height: 52px; }
}
