:root {
  --couleur-fond: #1a1a2e;
  --couleur-bouton: #e94560;
  --couleur-texte: #ffffff;
  --couleur-bouton-hover: #ff6b81;
  --font-main: 'Segoe UI', system-ui, -apple-system, sans-serif;
  --radius: 16px;
  --shadow: 0 8px 32px rgba(0, 0, 0, 0.3);
}

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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: var(--font-main);
  color: var(--couleur-texte);
  background: var(--couleur-fond);
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

body.bg-image {
  background-size: cover;
  background-position: center;
  background-repeat: no-repeat;
}

#app {
  height: 100%;
  display: flex;
  flex-direction: column;
  position: relative;
}

.screen {
  display: none;
  flex: 1;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 0;
  padding: 24px;
  animation: fadeIn 0.3s ease;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

#screen-themes,
#screen-gallery {
  justify-content: flex-start;
  padding-top: 64px;
}

#screen-gallery {
  position: relative;
  width: 100%;
  align-self: stretch;
}

#screen-gallery h2 {
  flex-shrink: 0;
  margin-bottom: 16px;
}

#screen-themes .subtitle {
  margin-bottom: 16px;
}

.screen.active {
  display: flex;
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}

h1, h2 {
  font-size: clamp(1.5rem, 4vw, 2.5rem);
  text-align: center;
  margin-bottom: 8px;
}

.subtitle {
  opacity: 0.8;
  text-align: center;
  margin-bottom: 32px;
  font-size: 1.1rem;
}

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 18px 36px;
  font-size: 1.2rem;
  font-weight: 600;
  border: none;
  border-radius: var(--radius);
  background: var(--couleur-bouton);
  color: #fff;
  cursor: pointer;
  transition: transform 0.15s, background 0.2s, box-shadow 0.2s;
  box-shadow: var(--shadow);
  min-width: 280px;
  min-height: 64px;
  touch-action: manipulation;
}

.btn:active {
  transform: scale(0.96);
}

.btn:hover {
  background: var(--couleur-bouton-hover);
}

.btn-secondary {
  background: rgba(255, 255, 255, 0.15);
  backdrop-filter: blur(10px);
}

.btn-secondary:hover {
  background: rgba(255, 255, 255, 0.25);
}

.btn:disabled {
  opacity: 0.5;
  pointer-events: none;
}

.btn-group {
  display: flex;
  flex-direction: column;
  gap: 16px;
  align-items: center;
  width: 100%;
  max-width: 400px;
}

/* Code entry */
.code-input {
  display: flex;
  gap: 12px;
  margin-bottom: 24px;
}

.code-digit {
  width: 56px;
  height: 72px;
  font-size: 2rem;
  text-align: center;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.1);
  color: var(--couleur-texte);
  outline: none;
  transition: border-color 0.2s;
}

.code-digit:focus {
  border-color: var(--couleur-bouton);
}

.error-msg {
  color: #ff6b6b;
  text-align: center;
  margin-top: 12px;
  font-size: 0.95rem;
}

/* Logo */
.logo {
  width: 80px;
  height: 80px;
  margin-bottom: 24px;
  border-radius: 50%;
  object-fit: cover;
  -webkit-touch-callout: none;
  -webkit-user-select: none;
  user-select: none;
  -webkit-user-drag: none;
  pointer-events: none;
}

.logo-disconnect {
  display: inline-block;
  margin-bottom: 24px;
  cursor: pointer;
  touch-action: none;
  -webkit-touch-callout: none;
}

.logo-disconnect .logo {
  margin-bottom: 0;
  display: block;
}

.event-name {
  font-size: 1.3rem;
  opacity: 0.9;
  margin-bottom: 40px;
}

/* Gallery */
.gallery-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  grid-auto-rows: auto;
  gap: 12px;
  width: 100%;
  max-width: 800px;
  margin: 0 auto;
  padding: 0 8px 24px;
  align-self: stretch;
}

@media (min-width: 480px) {
  .gallery-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }
}

@media (min-width: 720px) {
  .gallery-grid {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }
}

.gallery-item {
  position: relative;
  aspect-ratio: 3 / 4;
  min-width: 0;
  width: 100%;
  border-radius: 12px;
  overflow: hidden;
  cursor: pointer;
  transition: transform 0.2s;
  box-shadow: var(--shadow);
  touch-action: manipulation;
}

.gallery-item:active {
  transform: scale(0.95);
}

.gallery-item img {
  position: absolute;
  inset: 0;
  display: block;
  width: 100%;
  height: 100%;
  object-fit: cover;
  pointer-events: none;
}

.gallery-empty {
  text-align: center;
  opacity: 0.7;
  padding: 40px;
}

/* Lightbox */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 20px;
}

.lightbox.active {
  display: flex;
  touch-action: pan-y pinch-zoom;
}

.lightbox img {
  max-width: 100%;
  max-height: 90vh;
  border-radius: 8px;
  user-select: none;
  -webkit-user-drag: none;
}

.lightbox-close,
.lightbox-delete {
  position: absolute;
  top: 20px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.2);
  border: none;
  color: #fff;
  font-size: 1.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  touch-action: manipulation;
}

.lightbox-close {
  right: 20px;
}

.lightbox-delete {
  left: 20px;
  background: rgba(233, 69, 96, 0.85);
}

.lightbox-delete[hidden] {
  display: none !important;
}

.lightbox-delete:active {
  transform: scale(0.95);
}

/* Consent */
.consent-box {
  background: rgba(255, 255, 255, 0.1);
  border-radius: var(--radius);
  padding: 24px;
  max-width: 500px;
  margin-bottom: 24px;
  backdrop-filter: blur(10px);
}

.consent-label {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  cursor: pointer;
  font-size: 1rem;
  line-height: 1.5;
}

.consent-label input {
  width: 24px;
  height: 24px;
  margin-top: 2px;
  accent-color: var(--couleur-bouton);
}

/* Themes grid */
.themes-grid {
  display: grid;
  gap: 16px;
  width: 100%;
  max-width: 960px;
  margin: 0 auto;
  padding: 0 8px;
  grid-template-columns: repeat(2, 1fr);
}

@media (min-width: 480px) {
  .themes-grid {
    grid-template-columns: repeat(3, 1fr);
  }
}

@media (min-width: 720px) {
  .themes-grid {
    grid-template-columns: repeat(4, 1fr);
  }
}

.theme-card {
  aspect-ratio: 5 / 7;
  border-radius: var(--radius);
  overflow: hidden;
  position: relative;
  cursor: pointer;
  transition: box-shadow 0.2s, outline 0.2s;
  box-shadow: var(--shadow);
}

.theme-card.selected {
  outline: 4px solid var(--couleur-bouton);
  box-shadow: 0 0 0 2px var(--couleur-bouton), var(--shadow);
}

.theme-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.theme-card .theme-name {
  position: absolute;
  bottom: 0;
  left: 0;
  right: 0;
  padding: 12px;
  background: linear-gradient(transparent, rgba(0, 0, 0, 0.8));
  font-weight: 600;
  text-align: center;
}

.theme-card.random-card {
  background: linear-gradient(135deg, #667eea, #764ba2);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.random-icon {
  font-size: 4rem;
  margin-bottom: 12px;
}

/* Camera */
#screen-camera {
  padding-top: 48px;
  padding-bottom: 40px;
  gap: 24px;
}

#screen-camera h2 {
  margin-bottom: 0;
  flex-shrink: 0;
}

html[data-orientation="portrait"] {
  --camera-aspect: 3 / 4;
}

html[data-orientation="landscape"] {
  --camera-aspect: 4 / 3;
}

.camera-container {
  position: relative;
  flex-shrink: 1;
  min-height: 0;
  width: min(92vw, calc((100vh - 220px) * 3 / 4));
  max-height: calc(100vh - 220px);
  aspect-ratio: var(--camera-aspect, 3 / 4);
  border-radius: var(--radius);
  overflow: hidden;
  background: #000;
  box-shadow: var(--shadow);
}

html[data-orientation="landscape"] .camera-container {
  width: min(calc(100vw - 96px), calc((100vh - 180px) * 4 / 3));
  max-height: calc(100vh - 180px);
}

#camera-preview {
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
}

.camera-frame {
  position: absolute;
  inset: 10%;
  border: 3px dashed rgba(255, 255, 255, 0.5);
  border-radius: 50%;
  pointer-events: none;
}

.countdown-overlay {
  position: absolute;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  background: rgba(0, 0, 0, 0.5);
  font-size: 6rem;
  font-weight: 700;
  z-index: 10;
}

.countdown-overlay.active {
  display: flex;
  animation: pulse 0.8s ease;
}

@keyframes pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.2); }
}

.captured-preview {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: none;
}

/* Loading */
.loading-screen {
  text-align: center;
}

.spinner {
  width: 64px;
  height: 64px;
  border: 4px solid rgba(255, 255, 255, 0.2);
  border-top-color: var(--couleur-bouton);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto 24px;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.loading-text {
  font-size: 1.3rem;
  animation: blink 1.5s ease infinite;
}

@keyframes blink {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.5; }
}

/* Theater curtain reveal */
.reveal-container {
  position: relative;
  width: 100%;
  max-width: 500px;
  aspect-ratio: 3/4;
  border-radius: var(--radius);
  overflow: hidden;
  box-shadow: var(--shadow);
}

.reveal-container img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.rideau {
  position: absolute;
  top: 0;
  height: 100%;
  width: 50%;
  background: repeating-linear-gradient(90deg, #7a0d0d, #9b1212 12px, #7a0d0d 24px);
  transition: transform 0.9s ease-in-out;
  z-index: 5;
  box-shadow: inset 0 0 30px rgba(0, 0, 0, 0.5);
}

.rideau-gauche { left: 0; }
.rideau-droit { right: 0; }

.reveal-container.ouvert .rideau-gauche { transform: translateX(-100%); }
.reveal-container.ouvert .rideau-droit { transform: translateX(100%); }

.reveal-countdown {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 5rem;
  font-weight: 700;
  z-index: 10;
  text-shadow: 0 4px 20px rgba(0, 0, 0, 0.8);
}

/* Result screen */
#screen-result h2 {
  flex-shrink: 0;
  margin-bottom: 12px;
}

.result-image {
  max-width: min(100%, calc(78vh * 3 / 4));
  max-height: calc(100vh - 240px);
  width: auto;
  height: auto;
  object-fit: contain;
  border-radius: 16px;
  box-shadow: var(--shadow);
  cursor: pointer;
  flex-shrink: 0;
  touch-action: manipulation;
}

.result-image:active {
  opacity: 0.92;
}

/* Result footer */
.result-footer {
  display: flex;
  flex-direction: column;
  gap: 12px;
  width: 100%;
  max-width: 400px;
  margin-top: 24px;
}

.email-form {
  display: flex;
  gap: 8px;
  width: 100%;
}

.email-form input {
  flex: 1;
  padding: 14px 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-radius: var(--radius);
  background: rgba(255, 255, 255, 0.1);
  color: var(--couleur-texte);
  font-size: 1rem;
  outline: none;
}

.email-form input:focus {
  border-color: var(--couleur-bouton);
}

.quota-info {
  text-align: center;
  opacity: 0.8;
  font-size: 0.9rem;
  margin-top: 8px;
}

/* Back button */
.back-btn {
  position: absolute;
  top: 16px;
  left: 16px;
  width: 48px;
  height: 48px;
  border-radius: 50%;
  background: rgba(255, 255, 255, 0.15);
  border: none;
  color: var(--couleur-texte);
  font-size: 1.5rem;
  cursor: pointer;
  z-index: 50;
  display: flex;
  align-items: center;
  justify-content: center;
  backdrop-filter: blur(10px);
}

/* Admin disconnect - long press logo */
.admin-hint {
  position: fixed;
  bottom: 8px;
  right: 8px;
  font-size: 0.7rem;
  opacity: 0.3;
}

@media (orientation: landscape) {
  .screen {
    padding: 16px 24px;
  }

  .btn {
    min-width: 240px;
    min-height: 56px;
    padding: 14px 28px;
  }

  h1, h2 {
    margin-bottom: 4px;
  }

  .subtitle {
    margin-bottom: 20px;
  }

  #screen-home .btn-group {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
    max-width: 720px;
  }

  #screen-consent .btn-group {
    flex-direction: row;
    flex-wrap: wrap;
    justify-content: center;
  }

  #screen-themes,
  #screen-gallery {
    padding-top: 56px;
  }

  .themes-grid {
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    max-width: 100%;
  }

  .gallery-grid {
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    max-width: 100%;
  }

  #screen-camera {
    flex-direction: row;
    flex-wrap: wrap;
    align-content: center;
    justify-content: center;
    column-gap: 32px;
    row-gap: 20px;
    padding: 40px 24px 32px 72px;
  }

  #screen-camera h2 {
    flex: 0 0 100%;
    margin-bottom: 0;
  }

  #screen-camera .camera-container {
    margin: 0;
  }

  #screen-camera #btn-capture {
    align-self: center;
    margin-top: 0;
  }

  .reveal-container {
    aspect-ratio: 3 / 4;
  }

  #screen-result {
    flex-direction: row;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    column-gap: 32px;
    row-gap: 16px;
  }

  #screen-result h2 {
    flex: 0 0 100%;
  }

  #screen-result .result-image {
    max-width: min(52vw, calc(82vh * 3 / 4));
    max-height: 82vh;
    flex: 0 1 auto;
  }

  #screen-result .result-footer {
    flex: 1 1 280px;
    max-width: 420px;
    margin-top: 0;
  }

  .reveal-container {
    width: auto;
    height: min(calc(100vh - 80px), calc((100vw - 48px) * 0.6));
    max-width: calc((100vh - 80px) * 3 / 4);
  }
}
