/* PickleVisor Photo Booth — camera-first layout, landscape and portrait */

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: #000;
  color: #fff;
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-text-size-adjust: 100%;
}
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
}

.pvb {
  --red: #B22234;
  --red-down: #8E1B2A;
  --navy: #13235B;
  --glass: rgba(255, 255, 255, 0.15);
  --glass-down: rgba(255, 255, 255, 0.3);
  --btn-h: 60px;
  --rail-w: 170px;
  position: fixed;
  inset: 0;
  height: var(--app-h, 100%);
  display: grid;
  box-sizing: border-box;
  padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
}

/* ---------- Landscape: frames left, camera centre, shutter right ---------- */

.pvb.is-landscape {
  grid-template-columns: var(--rail-w) var(--stage-w) var(--rail-w);
  grid-template-rows: auto 1fr;
  grid-template-areas:
    "exit  stage right"
    "left  stage right";
  justify-content: center;
  column-gap: 12px;
  padding-left: calc(10px + env(safe-area-inset-left, 0px));
  padding-right: calc(10px + env(safe-area-inset-right, 0px));
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}
.is-landscape .pvb-stage { grid-area: stage; align-self: center; }
.is-landscape .pvb-exit { grid-area: exit; width: 100%; }
.is-landscape .pvb-frames { grid-area: left; align-self: center; display: flex; flex-direction: column; gap: 8px; }
.is-landscape .pvb-retake-wrap { grid-area: left; align-self: center; }
.is-landscape .pvb-capture { grid-area: right; align-self: center; }
.is-landscape .pvb-after { grid-area: right; align-self: center; flex-direction: column; }

/* ---------- Portrait: camera top, frames and shutter below ---------- */

.pvb.is-portrait {
  grid-template-columns: 1fr;
  grid-template-rows: auto auto auto 1fr;
  grid-template-areas: "exit" "stage" "frames" "capture";
  justify-items: center;
  row-gap: 12px;
  padding-top: calc(8px + env(safe-area-inset-top, 0px));
  padding-bottom: calc(8px + env(safe-area-inset-bottom, 0px));
}
.is-portrait .pvb-exit { grid-area: exit; justify-self: start; margin-left: 12px; }
.is-portrait .pvb-stage { grid-area: stage; }
.is-portrait .pvb-frames {
  grid-area: frames;
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  width: min(calc(100vw - 24px), 560px);
}
.is-portrait .pvb-after { grid-area: frames; flex-direction: row; width: min(calc(100vw - 24px), 560px); }
.is-portrait .pvb-after .pvb-btn { flex: 1; }
.is-portrait .pvb-capture { grid-area: capture; align-self: center; }
.is-portrait .pvb-retake-wrap { grid-area: capture; align-self: start; width: min(calc(100vw - 24px), 560px); }
.is-portrait .pvb-retake-wrap .pvb-btn { width: 100%; }

/* ---------- Stage ---------- */

.pvb-stage {
  position: relative;
  width: var(--stage-w, 60vw);
  height: var(--stage-h, 34vw);
  background: #1a1f2e;
  border-radius: 14px;
  overflow: hidden;
}
.pvb-stage video,
.pvb-stage canvas,
.pvb-stage .pvb-result {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}
.pvb-stage video { object-fit: cover; object-position: center; }
.pvb-result { object-fit: contain; display: none; background: #000; -webkit-user-select: auto; user-select: auto; -webkit-touch-callout: default; }
.pvb-guide { pointer-events: none; }

.pvb[data-state="captured"] .pvb-result { display: block; }
.pvb[data-state="captured"] video,
.pvb[data-state="captured"] .pvb-frame,
.pvb[data-state="captured"] .pvb-guide { visibility: hidden; }
.pvb[data-state="error"] video { visibility: hidden; }

.pvb-loading {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  font-size: 20px;
  font-weight: 700;
  text-shadow: 0 1px 6px rgba(0, 0, 0, 0.7);
}
.pvb[data-state="starting"] .pvb-loading { display: flex; }

.pvb-msg {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 16px 22px;
  text-align: center;
  background: rgba(10, 16, 40, 0.88);
  box-sizing: border-box;
}
.pvb-msg[hidden] { display: none; }
.pvb-msg h2 { margin: 0; font-size: 24px; line-height: 1.15; }
.pvb-msg p { margin: 0 0 4px; max-width: 30em; font-size: 18px; line-height: 1.35; color: rgba(255, 255, 255, 0.92); }
.pvb-msg-actions { display: flex; flex-wrap: wrap; gap: 12px; justify-content: center; }
.pvb-msg .pvb-btn { min-width: 150px; }

.pvb-flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
.pvb-flash.is-on { animation: pvb-flash 0.35s ease-out; }
@keyframes pvb-flash { from { opacity: 0.9; } to { opacity: 0; } }

/* ---------- Buttons ---------- */

.pvb button {
  font: inherit;
  color: #fff;
  cursor: pointer;
  -webkit-appearance: none;
  appearance: none;
  border: 0;
  margin: 0;
}
.pvb button:focus-visible { outline: 3px solid #fff; outline-offset: 3px; }
.pvb button[hidden] { display: none !important; }

.pvb-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  height: 64px;
  padding: 0 22px;
  border-radius: 16px;
  background: var(--glass);
  font-size: 21px;
  font-weight: 700;
  line-height: 1.1;
  box-sizing: border-box;
  white-space: nowrap;
}
.pvb-btn:active { background: var(--glass-down); }
.pvb-btn svg { width: 28px; height: 28px; flex: none; }
.pvb-btn-primary { background: var(--red); }
.pvb-btn-primary:active { background: var(--red-down); }
.pvb .pvb-btn-light { background: #fff; color: var(--navy); }
.pvb .pvb-btn-light:active { background: #dde1ea; }

.pvb-exit { height: 52px; font-size: 19px; padding: 0 18px; }
.pvb-exit svg { width: 22px; height: 22px; }

/* Frame choices */
.pvb-frame-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  height: var(--btn-h);
  padding: 0 10px;
  border-radius: 14px;
  background: var(--glass);
  font-size: 20px;
  font-weight: 700;
  line-height: 1.05;
  text-align: center;
  box-sizing: border-box;
}
.pvb-frame-btn:active { background: var(--glass-down); }
.pvb .pvb-frame-btn.is-on { background: #fff; color: var(--navy); }
.pvb-check { width: 22px; height: 22px; flex: none; fill: none; stroke: currentColor; stroke-width: 3.2; stroke-linecap: round; stroke-linejoin: round; display: none; }
.pvb-frame-btn.is-on .pvb-check { display: block; }

/* Shutter */
.pvb-capture { display: flex; flex-direction: column; align-items: center; gap: 8px; }
.pvb-shutter {
  width: 100px;
  height: 100px;
  border-radius: 50%;
  border: 6px solid #fff !important;
  background: transparent;
  padding: 6px;
  flex: none;
  box-sizing: border-box;
}
.pvb-shutter span { display: block; width: 100%; height: 100%; border-radius: 50%; background: #fff; transition: transform 0.08s; }
.pvb-shutter:active span { transform: scale(0.88); background: #e6e6e6; }
.pvb-shutter-label { font-size: 20px; font-weight: 700; }
.pvb[data-state="paused"] .pvb-shutter,
.pvb[data-state="starting"] .pvb-shutter { opacity: 0.4; }

/* After the photo */
.pvb-after { display: none; gap: 12px; align-items: stretch; }
.pvb-after .pvb-btn { width: 100%; }
.pvb-retake-wrap { display: none; width: 100%; }
.pvb-retake-wrap .pvb-btn { width: 100%; }
.pvb[data-state="captured"] .pvb-frames,
.pvb[data-state="captured"] .pvb-capture { display: none; }
.pvb[data-state="captured"] .pvb-after { display: flex; }
.pvb[data-state="captured"] .pvb-retake-wrap { display: block; }
.pvb:not(.can-share) #pvb-share { display: none; }

.pvb.is-compact .pvb-shutter { width: 84px; height: 84px; }
.pvb.is-compact .pvb-shutter-label { display: none; }
.pvb.is-portrait .pvb-toast { top: calc(70px + env(safe-area-inset-top, 0px)); bottom: auto; }

/* Short landscape screens */
@media (max-height: 360px) and (orientation: landscape) {
  .pvb-frame-btn { font-size: 18px; }
  .pvb-shutter { width: 88px; height: 88px; }
  .pvb-btn { height: 56px; font-size: 19px; }
  .pvb-exit { height: 46px; }
}

/* Toast */
.pvb-toast {
  position: fixed;
  left: 50%;
  bottom: calc(18px + env(safe-area-inset-bottom, 0px));
  transform: translateX(-50%);
  max-width: 80vw;
  padding: 12px 20px;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.96);
  color: #13235B;
  font-size: 18px;
  font-weight: 700;
  text-align: center;
  z-index: 20;
}
.pvb-toast[hidden] { display: none; }

@media (prefers-reduced-motion: reduce) {
  .pvb-shutter span { transition: none; }
}
