* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

:root {
  --bg: #121214;
  --surface: #1e1e22;
  --surface-2: #2a2a30;
  --text: #f3f4f6;
  --muted: #9ca3af;
  --green: #22c55e;
  --green-dark: #16a34a;
  --red: #ef4444;
  --red-dark: #dc2626;
  --amber: #d97706;
  --teal: #0d9488;
  --purple: #8b5cf6;
  --blue: #2563eb;
}

html, body {
  margin: 0;
  padding: 0;
  height: 100dvh;
  width: 100%;
  overflow: hidden;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

.hidden { display: none !important; }

.view {
  height: 100dvh;
  width: 100%;
  display: flex;
  flex-direction: column;
}

/* --- LOGIN --- */
#login-view {
  align-items: center;
  justify-content: center;
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  padding: 24px;
  border-radius: 16px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.login-card h1 { margin: 0; font-size: 1.5rem; }
.subtitle { margin: 0; color: var(--muted); font-size: 0.9rem; }

.login-card label {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: 0.9rem;
  color: var(--muted);
}

.login-card input {
  padding: 12px;
  border-radius: 10px;
  border: 1px solid #333;
  background: var(--bg);
  color: var(--text);
  font-size: 1rem;
}

.error { color: #f87171; font-size: 0.85rem; margin: 0; }

.btn {
  padding: 12px 16px;
  border: none;
  border-radius: 10px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}

.btn-primary { background: var(--blue); color: white; }

/* --- TOPBAR --- */
.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 8px 10px;
  background: var(--surface);
  gap: 8px;
  flex-shrink: 0;
}

.topbar-left, .topbar-right {
  display: flex;
  align-items: center;
  gap: 6px;
}

.badge {
  font-size: 0.78rem;
  font-weight: 600;
  background: var(--surface-2);
  padding: 4px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.badge-muted { color: var(--muted); }

.icon-btn, .pill-btn {
  background: var(--surface-2);
  color: var(--text);
  border: none;
  border-radius: 8px;
  padding: 6px 10px;
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
}

.pill-btn.active {
  background: var(--blue);
  color: white;
}

.edit-banner {
  background: #854d0e;
  color: #fef08a;
  padding: 6px 12px;
  font-size: 0.85rem;
  font-weight: 600;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
}

/* --- STAGE PHOTO --- */
.stage {
  position: relative;
  flex: 1;
  min-height: 0;
  width: 100%;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
  background: #000;
  touch-action: none;
  user-select: none;
}

#photo {
  max-width: 100%;
  max-height: 100%;
  width: 100%;
  height: 100%;
  object-fit: contain;
  transform-origin: center center;
  will-change: transform;
}

.empty-state {
  text-align: center;
  padding: 20px;
  color: var(--muted);
}

.zoom-hint {
  position: absolute;
  top: 10px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.7);
  color: white;
  font-size: 0.75rem;
  padding: 4px 10px;
  border-radius: 999px;
  pointer-events: none;
}

/* --- CONTROLS --- */
.controls {
  background: var(--surface);
  padding: 10px 10px calc(10px + env(safe-area-inset-bottom));
  flex-shrink: 0;
}

.simple-row {
  display: grid;
  grid-template-columns: 1fr 0.75fr 1fr;
  gap: 8px;
}

.btn-no { background: #dc2626; }
.btn-invalid {
  background: #52525b;
  font-size: 0.95rem;
  padding: 16px 6px;
}
.btn-yes { background: #16a34a; }

.vote-btn {
  padding: 16px;
  border: none;
  border-radius: 14px;
  font-size: 1.25rem;
  font-weight: 700;
  color: white;
  cursor: pointer;
}

.vote-btn:active, .adv-btn:active { transform: scale(0.97); }
.btn-no { background: var(--red); }
.btn-yes { background: var(--green-dark); }

/* --- MODE AVANCÉ --- */
.advanced-wrap {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.tags-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  justify-content: center;
}

.tag-chip {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid #3f3f46;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.78rem;
  font-weight: 600;
  cursor: pointer;
}

.tag-chip.active {
  background: var(--blue);
  border-color: var(--blue);
  color: white;
}

.adv-groups {
  display: flex;
  flex-direction: column;
  gap: 6px;
}

.adv-group {
  display: flex;
  align-items: stretch;
  gap: 6px;
  background: rgba(255, 255, 255, 0.03);
  padding: 5px;
  border-radius: 10px;
}

.group-title {
  writing-mode: vertical-rl;
  transform: rotate(180deg);
  font-size: 0.7rem;
  font-weight: 800;
  text-transform: uppercase;
  text-align: center;
  padding: 2px 4px;
  border-radius: 6px;
}

.group-yes .group-title { color: #86efac; background: rgba(34, 197, 94, 0.15); }
.group-no .group-title { color: #fca5a5; background: rgba(239, 68, 68, 0.15); }

.adv-btns {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}

.adv-btn {
  border: none;
  border-radius: 9px;
  padding: 10px 6px;
  color: white;
  font-size: 0.82rem;
  font-weight: 700;
  line-height: 1.15;
  cursor: pointer;
}

/* Groupe Oui (nuances de vert) */
.yes-1 { background: #15803d; } /* Parfait */
.yes-2 { background: #16a34a; } /* Parfait, pas pour moi */
.yes-3 { background: #059669; } /* Objectivement ça va */

/* Groupe Non (nuances de rouge) */
.no-1 { background: #ef4444; }  /* Medium */
.no-2 { background: #b91c1c; }  /* Non */
.no-inv { background: #52525b; } /* Invalide */

/* --- HISTORIQUE --- */
.drawer {
  position: fixed;
  inset: 0;
  background: var(--bg);
  z-index: 50;
  display: flex;
  flex-direction: column;
}

.drawer-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 14px;
  background: var(--surface);
}

.drawer-header h2 { margin: 0; font-size: 1.1rem; }
.drawer-actions { display: flex; gap: 8px; align-items: center; }

.filter-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 12px;
  background: var(--surface);
  border-top: 1px solid #2a2a30;
  flex-shrink: 0;
}

.filter-chip {
  background: var(--surface-2);
  color: var(--muted);
  border: none;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.8rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.filter-chip.active { background: var(--blue); color: white; }

.history-grid {
  flex: 1;
  overflow-y: auto;
  padding: 10px;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 8px;
  align-content: start;
}

.hist-card {
  position: relative;
  aspect-ratio: 3 / 4;
  border-radius: 10px;
  overflow: hidden;
  background: #000;
  cursor: pointer;
}

.hist-card img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.hist-label {
  position: absolute;
  bottom: 4px;
  left: 4px;
  right: 4px;
  font-size: 0.7rem;
  font-weight: 700;
  text-align: center;
  padding: 3px 4px;
  border-radius: 6px;
  background: rgba(0, 0, 0, 0.75);
  color: white;
}

/* --- TOAST --- */
.toast {
  position: fixed;
  top: 56px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(20, 20, 24, 0.92);
  color: white;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 0.85rem;
  z-index: 100;
}

/* --- SÉLECTEUR D'UTILISATEUR & LECTURE SEULE --- */
.user-bar {
  display: flex;
  gap: 6px;
  overflow-x: auto;
  padding: 8px 12px 4px;
  background: var(--surface);
  flex-shrink: 0;
}

.user-chip {
  background: var(--surface-2);
  color: var(--muted);
  border: 1px solid #3f3f46;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.82rem;
  font-weight: 600;
  white-space: nowrap;
  cursor: pointer;
}

.user-chip.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

.edit-banner.readonly {
  background: #1e3a5f;
  color: #bfdbfe;
}

.readonly-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 4px 2px;
}

.readonly-info {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 6px;
}

.readonly-badge {
  background: var(--surface-2);
  color: var(--text);
  font-weight: 700;
  font-size: 0.9rem;
  padding: 6px 12px;
  border-radius: 8px;
}

.readonly-tags {
  font-size: 0.8rem;
  color: var(--muted);
}