*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --brand-primary: #c8a45a;
  --brand-secondary: #f5f5f5;
  --brand-button: #c8a45a;
  --brand-button-text: #111111;
  --brand-radius: 14px;
  --brand-font: "Segoe UI", system-ui, -apple-system, BlinkMacSystemFont, sans-serif;
  --brand-bg: #0a0a0a;
  --brand-bg-image: none;
  --portrait-ar: 3 / 4;
}

html,
body {
  height: 100%;
  width: 100%;
  overflow: hidden;
  background: var(--brand-bg);
  background-image: var(--brand-bg-image);
  background-size: cover;
  background-position: center;
  color: var(--brand-secondary);
  font-family: var(--brand-font);
  -webkit-tap-highlight-color: transparent;
  touch-action: manipulation;
  user-select: none;
  -webkit-user-select: none;
}

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

.screen {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.screen[hidden] {
  display: none !important;
}

/* —— Shared gate screens (PIN / welcome / legal) —— */
.gate-screen {
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: center;
  padding:
    max(1.25rem, env(safe-area-inset-top))
    1.25rem
    max(1.25rem, env(safe-area-inset-bottom));
  background:
    radial-gradient(120% 80% at 50% 0%, #1a2433 0%, #0a0a0a 55%),
    #0a0a0a;
}

.pin-screen {
  z-index: 8;
}

.welcome-screen {
  z-index: 7;
}

.legal-screen {
  z-index: 6;
}

.pin-card,
.gate-card {
  width: min(100%, 22rem);
  text-align: center;
}

.pin-brand,
.gate-title {
  font-size: clamp(1.75rem, 6vw, 2.25rem);
  font-weight: 700;
  letter-spacing: -0.02em;
  margin-bottom: 0.5rem;
}

.pin-lead,
.gate-lead {
  font-size: 0.95rem;
  line-height: 1.4;
  color: rgba(245, 245, 245, 0.75);
  margin-bottom: 1.5rem;
}

.pin-form {
  display: flex;
  flex-direction: column;
  gap: 0.65rem;
  text-align: left;
}

.pin-label {
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: rgba(245, 245, 245, 0.65);
}

#pin-input {
  appearance: none;
  width: 100%;
  padding: 0.9rem 1rem;
  border: 1px solid rgba(255, 255, 255, 0.18);
  border-radius: 0.5rem;
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
  font-size: 1.5rem;
  font-weight: 600;
  letter-spacing: 0.35em;
  text-align: center;
  outline: none;
  user-select: text;
  -webkit-user-select: text;
}

#pin-input:focus {
  border-color: rgba(255, 255, 255, 0.45);
  background: rgba(255, 255, 255, 0.1);
}

.pin-hint {
  font-size: 0.75rem;
  color: rgba(245, 245, 245, 0.5);
  margin-top: -0.25rem;
}

.pin-error {
  margin-top: 0.85rem;
  font-size: 0.875rem;
  line-height: 1.35;
  color: #ffb4b4;
}

.pin-error[hidden] {
  display: none;
}

.welcome-steps {
  list-style: none;
  text-align: left;
  margin: 0 0 1.5rem;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
}

.welcome-steps li {
  position: relative;
  padding: 0.65rem 0.85rem 0.65rem 2.5rem;
  background: rgba(255, 255, 255, 0.06);
  border-radius: 0.5rem;
  font-size: 0.9rem;
  color: rgba(245, 245, 245, 0.9);
  counter-increment: welcome-step;
}

.welcome-steps {
  counter-reset: welcome-step;
}

.welcome-steps li::before {
  content: counter(welcome-step);
  position: absolute;
  left: 0.75rem;
  top: 50%;
  transform: translateY(-50%);
  width: 1.25rem;
  height: 1.25rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.18);
  font-size: 0.7rem;
  font-weight: 700;
  display: flex;
  align-items: center;
  justify-content: center;
  line-height: 1.25rem;
  text-align: center;
}

.gate-actions {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.legal-form {
  display: flex;
  flex-direction: column;
  gap: 1rem;
  text-align: left;
}

.legal-check {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  font-size: 0.9rem;
  line-height: 1.45;
  color: rgba(245, 245, 245, 0.9);
  cursor: pointer;
  user-select: text;
  -webkit-user-select: text;
}

.legal-check input[type="checkbox"] {
  flex: 0 0 auto;
  width: 1.2rem;
  height: 1.2rem;
  margin-top: 0.15rem;
  accent-color: #f5f5f5;
  cursor: pointer;
}

.legal-check a {
  color: #9ecbff;
  text-decoration: underline;
  text-underline-offset: 2px;
}

.legal-check a:active {
  opacity: 0.8;
}

.btn-primary,
.btn-secondary,
.btn-ghost {
  appearance: none;
  border: none;
  border-radius: 0.5rem;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  padding: 0.85rem 1rem;
  text-align: center;
}

.btn-primary {
  background: var(--brand-button);
  color: var(--brand-button-text);
  border-radius: var(--brand-radius);
}

.btn-primary:active:not(:disabled) {
  background: #e0e0e0;
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.14);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.2);
}

.btn-secondary:active:not(:disabled) {
  background: rgba(255, 255, 255, 0.22);
}

.btn-ghost {
  background: transparent;
  color: rgba(245, 245, 245, 0.8);
  font-size: 0.875rem;
  padding: 0.5rem;
}

.btn-ghost:active:not(:disabled) {
  opacity: 0.7;
}

.btn-primary:disabled,
.btn-secondary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

/* —— Camera stage —— */
.camera-screen {
  z-index: 1;
}

.stage {
  position: absolute;
  inset: 0;
  z-index: 0;
  overflow: hidden;
  background: #111;
  touch-action: pan-y;
}

#camera {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  background: #111;
  z-index: 0;
  /* Keep the video layer visible under the layover */
  opacity: 1;
}

#camera.mirrored {
  transform: scaleX(-1);
}

.layover {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* contain = full brand frame always visible (matches capture aspect fit) */
  object-fit: contain;
  z-index: 1;
  pointer-events: none;
  user-select: none;
  -webkit-user-drag: none;
  /* Never paint an opaque CSS fill over the camera feed */
  background: transparent;
  background-color: transparent;
}

.layover[hidden] {
  display: none;
}

.nav-dots {
  position: absolute;
  left: 0;
  right: 0;
  bottom: calc(5.75rem + env(safe-area-inset-bottom, 0px));
  z-index: 2;
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 0.45rem;
  padding: 0.35rem;
  pointer-events: none;
}

.nav-dots[hidden] {
  display: none;
}

.nav-dot {
  width: 0.45rem;
  height: 0.45rem;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.35);
  border: none;
  padding: 0;
  pointer-events: auto;
  cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}

.nav-dot[aria-selected="true"] {
  background: #fff;
  transform: scale(1.25);
}

.status {
  position: absolute;
  top: max(1rem, env(safe-area-inset-top));
  left: 50%;
  transform: translateX(-50%);
  z-index: 2;
  max-width: min(90vw, 24rem);
  padding: 0.75rem 1rem;
  border-radius: 0.5rem;
  background: rgba(0, 0, 0, 0.72);
  color: #fff;
  font-size: 0.875rem;
  line-height: 1.35;
  text-align: center;
  pointer-events: none;
}

.status[hidden] {
  display: none;
}

.bottom-bar {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 0;
  z-index: 2;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 0.5rem;
  padding:
    0.75rem 1rem
    calc(0.75rem + env(safe-area-inset-bottom, 0px));
  background: rgba(0, 0, 0, 0.55);
  backdrop-filter: blur(8px);
  -webkit-backdrop-filter: blur(8px);
}

.btn {
  appearance: none;
  border: none;
  background: transparent;
  color: #f5f5f5;
  font: inherit;
  cursor: pointer;
  text-align: center;
}

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

.btn-side {
  flex: 1 1 0;
  min-width: 0;
  max-width: 7.5rem;
  padding: 0.5rem 0.35rem;
  font-size: 0.75rem;
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.01em;
  text-wrap: balance;
}

.btn-side:active:not(:disabled) {
  opacity: 0.7;
}

.btn-capture {
  position: relative;
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  width: 5.5rem;
  min-height: 5.5rem;
  padding: 0.25rem;
}

.btn-capture-ring {
  display: block;
  width: 4.25rem;
  height: 4.25rem;
  border-radius: 50%;
  border: 3px solid #fff;
  background: #fff;
  box-shadow: 0 0 0 3px rgba(255, 255, 255, 0.25);
  transition: transform 0.12s ease, background 0.12s ease;
}

.btn-capture:active:not(:disabled) .btn-capture-ring {
  transform: scale(0.92);
  background: #e8e8e8;
}

.btn-capture-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  white-space: nowrap;
}

/* Flash feedback on capture */
#app.flash::after {
  content: "";
  position: absolute;
  inset: 0;
  z-index: 4;
  background: #fff;
  opacity: 0.85;
  pointer-events: none;
  animation: flash 0.25s ease-out forwards;
}

@keyframes flash {
  from { opacity: 0.85; }
  to { opacity: 0; }
}

/* —— Result —— */
.result-screen {
  z-index: 3;
  display: flex;
  flex-direction: column;
  background: #0a0a0a;
}

.result-image {
  flex: 1 1 auto;
  width: 100%;
  min-height: 0;
  object-fit: contain;
  background: #111;
}

.result-bar {
  flex: 0 0 auto;
  display: flex;
  flex-direction: column;
  gap: 0.55rem;
  padding:
    0.85rem 1rem
    calc(0.85rem + env(safe-area-inset-bottom, 0px));
  background: rgba(0, 0, 0, 0.75);
}

/* —— Confetti —— */
.confetti-canvas {
  position: fixed;
  inset: 0;
  z-index: 20;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.confetti-canvas[hidden] {
  display: none;
}

@media (min-width: 480px) {
  .btn-side {
    font-size: 0.8125rem;
    max-width: 9rem;
  }

  .btn-capture-label {
    font-size: 0.75rem;
  }

  .result-bar {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  .result-bar .btn-primary,
  .result-bar .btn-secondary {
    flex: 1 1 10rem;
    max-width: 14rem;
  }

  .result-bar .btn-ghost {
    flex: 1 0 100%;
  }
}

/* —— Brandkit: PIN logo —— */
.pin-logo {
  display: block;
  width: min(42vw, 9rem);
  height: auto;
  max-height: 4.5rem;
  object-fit: contain;
  margin: 0 auto 0.85rem;
}

.pin-logo[hidden] {
  display: none !important;
}

.pin-brand {
  font-family: var(--brand-font);
  color: var(--brand-secondary);
}

.pin-screen {
  background:
    linear-gradient(rgba(0, 0, 0, 0.35), rgba(0, 0, 0, 0.55)),
    var(--brand-bg-image),
    var(--brand-bg);
  background-size: cover;
  background-position: center;
}

.pin-card .btn-primary,
.gate-card .btn-primary {
  border-radius: var(--brand-radius);
  background: var(--brand-button);
  color: var(--brand-button-text);
}

/* —— Camera event name —— */
.camera-topbar {
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  z-index: 4;
  padding:
    max(0.85rem, env(safe-area-inset-top))
    1rem
    0.5rem;
  text-align: center;
  pointer-events: none;
  background: linear-gradient(180deg, rgba(0, 0, 0, 0.55) 0%, transparent 100%);
}

.camera-event-name {
  font-family: var(--brand-font);
  font-size: clamp(1.15rem, 4.6vw, 1.65rem);
  font-weight: 700;
  letter-spacing: 0.02em;
  color: var(--brand-secondary);
  text-shadow: 0 1px 8px rgba(0, 0, 0, 0.55);
}

/* —— Icon side buttons —— */
.btn-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 3.1rem;
  padding: 0.65rem;
  color: var(--brand-primary);
  border: 1px solid color-mix(in srgb, var(--brand-primary) 45%, transparent);
  background: color-mix(in srgb, var(--brand-primary) 14%, rgba(0, 0, 0, 0.35));
  border-radius: var(--brand-radius);
}

.btn-icon svg {
  width: 1.55rem;
  height: 1.55rem;
  display: block;
}

.btn-capture-ring {
  border-color: var(--brand-primary);
}

.btn-capture-label {
  color: var(--brand-secondary);
}

/* —— Strict portrait stage —— */
.portrait-stage {
  display: flex;
  align-items: center;
  justify-content: center;
  background: #050505;
}

.portrait-stage #camera,
.portrait-stage .layover {
  position: absolute;
  inset: auto;
  top: 50%;
  left: 50%;
  width: min(100%, calc(100dvh * 0.72));
  height: auto;
  aspect-ratio: var(--portrait-ar);
  max-height: calc(100% - 0.5rem);
  transform: translate(-50%, -50%);
  object-fit: cover;
}

.portrait-stage #camera.mirrored {
  transform: translate(-50%, -50%) scaleX(-1);
}

.portrait-media {
  aspect-ratio: var(--portrait-ar);
}

/* —— Landscape lock overlay —— */
.rotate-gate {
  position: fixed;
  inset: 0;
  z-index: 9999;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: #07090e;
  color: #f5f5f5;
  text-align: center;
}

.rotate-gate[hidden] {
  display: none !important;
}

.rotate-gate-inner {
  max-width: 22rem;
}

.rotate-icon {
  width: 4.5rem;
  height: 4.5rem;
  margin: 0 auto 1rem;
  color: var(--brand-primary, #c8a45a);
}

.rotate-gate-text {
  font-size: 1.05rem;
  line-height: 1.45;
  font-weight: 600;
}

@media (orientation: landscape) {
  #app {
    visibility: hidden;
    pointer-events: none;
  }

  .rotate-gate {
    display: flex !important;
  }
}

@media (orientation: portrait) {
  .rotate-gate {
    display: none !important;
  }

  #app {
    visibility: visible;
  }
}
