/* ═══════════════════════════════════════════════════════════════════════════
   DAWR — Esthétique maghrébine (zellige, safran, teal, ivoire)
   ═══════════════════════════════════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=Amiri:wght@400;700&family=Outfit:wght@300;400;600;700&display=swap');

:root {
  --saffron: #d4a24e;
  --saffron-light: #e8c878;
  --terracotta: #b5523a;
  --teal: #1a8a7d;
  --teal-deep: #0b6e6a;
  --burgundy: #8b2942;
  --ivory: #faf0dc;
  --cream: #f5e6c8;
  --night: #0f1923;
  --night-soft: #1a2634;
  --glass-bg: rgba(26, 38, 52, 0.65);
  --glass-border: rgba(212, 162, 78, 0.35);
  --glass-highlight: rgba(250, 240, 220, 0.12);
  --text-soft: rgba(245, 230, 200, 0.82);
  --glow-gold: 0 0 24px rgba(212, 162, 78, 0.25);
}

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

html,
body {
  width: 100%;
  height: 100%;
  overflow: hidden;
  background: var(--night);
  font-family: 'Outfit', 'Segoe UI', sans-serif;
  color: var(--ivory);
}

/* Motif zellige subtil */
body {
  background-color: var(--night);
  background-image:
    radial-gradient(ellipse at 20% 0%, rgba(26, 138, 125, 0.12) 0%, transparent 50%),
    radial-gradient(ellipse at 80% 100%, rgba(181, 82, 58, 0.1) 0%, transparent 45%),
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='56' height='56' viewBox='0 0 56 56'%3E%3Cg fill='none' stroke='%23d4a24e' stroke-opacity='0.07' stroke-width='0.6'%3E%3Cpath d='M28 4 L52 28 L28 52 L4 28 Z'/%3E%3Cpath d='M28 14 L42 28 L28 42 L14 28 Z'/%3E%3Cpath d='M28 0 L28 56 M0 28 L56 28'/%3E%3C/g%3E%3C/svg%3E");
}

.hidden {
  display: none !important;
}

#app-stage {
  position: fixed;
  inset: 0;
  z-index: 1;
  background: transparent;
}

#webcam {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: cover;
  transform: scaleX(-1);
  z-index: 0;
  filter: brightness(0.88) saturate(0.92);
}

/* Voile grisé très léger sur la webcam — améliore la lisibilité des cercles */
#app-stage::after {
  content: '';
  position: absolute;
  inset: 0;
  z-index: 0.5;
  background: rgba(8, 6, 5, 0.22);
  pointer-events: none;
}

#canvas-container {
  position: absolute;
  inset: 0;
  z-index: 1;
  pointer-events: none;
}

#canvas-container canvas {
  display: block;
  width: 100% !important;
  height: 100% !important;
}

/* ── Cadre maghrébin — liseré fin + petits coins (sans treillis) ──────────── */
.maghrebi-frame {
  position: absolute;
  inset: 14px;
  z-index: 2;
  pointer-events: none;
  border: 1px solid rgba(212, 162, 78, 0.5);
  outline: 1px solid rgba(26, 138, 125, 0.28);
  outline-offset: 3px;
  box-shadow: inset 0 0 0 1px rgba(232, 200, 120, 0.1);
}

.frame-corner {
  position: absolute;
  width: 28px;
  height: 28px;
  background: url('../assets/frame-corner-sm.svg') no-repeat;
  background-size: 28px 28px;
  opacity: 0.85;
}

.frame-corner--tl { top: -2px; left: -2px; }
.frame-corner--tr { top: -2px; right: -2px; transform: scaleX(-1); }
.frame-corner--bl { bottom: -2px; left: -2px; transform: scaleY(-1); }
.frame-corner--br { bottom: -2px; right: -2px; transform: scale(-1, -1); }

@media (max-width: 600px) {
  .maghrebi-frame {
    inset: 10px;
    outline-offset: 2px;
  }

  .frame-corner {
    width: 22px;
    height: 22px;
    background-size: 22px 22px;
  }
}

/* ── Écran d'accueil — arche de riad ─────────────────────────────────────── */
#start-screen {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 1.1rem;
  padding: 2rem;
  text-align: center;
  background: rgba(15, 25, 35, 0.55);
  backdrop-filter: blur(3px);
}

#start-screen::before {
  content: '';
  position: absolute;
  inset: 8% 12%;
  border-radius: 120px 120px 24px 24px;
  background: var(--glass-bg);
  border: 2px solid var(--glass-border);
  backdrop-filter: blur(20px) saturate(1.2);
  box-shadow:
    inset 0 1px 0 var(--glass-highlight),
    var(--glow-gold),
    0 24px 64px rgba(0, 0, 0, 0.45);
  z-index: -1;
}

#start-screen::after {
  content: '';
  position: absolute;
  top: calc(8% + 10px);
  left: 50%;
  transform: translateX(-50%);
  width: 22px;
  height: 22px;
  background: url('../assets/favicon.svg') no-repeat center / contain;
  opacity: 0.85;
  z-index: -1;
}

.brand-mark {
  font-family: 'Amiri', serif;
  font-size: clamp(3rem, 10vw, 4.5rem);
  font-weight: 700;
  letter-spacing: 0.12em;
  color: var(--saffron-light);
  text-shadow: 0 2px 12px rgba(212, 162, 78, 0.4);
  line-height: 1;
}

.brand-sub {
  font-family: 'Amiri', serif;
  font-size: 1rem;
  color: var(--teal);
  letter-spacing: 0.2em;
  margin-top: -0.5rem;
  opacity: 0.9;
}

#start-screen > p:not(.loading-msg) {
  max-width: 440px;
  line-height: 1.65;
  color: var(--text-soft);
  font-size: 0.98rem;
  font-weight: 300;
}

#start-btn {
  padding: 0.95rem 2.8rem;
  font-family: 'Outfit', sans-serif;
  font-size: 1rem;
  font-weight: 600;
  letter-spacing: 0.12em;
  text-transform: uppercase;
  color: var(--night);
  background: linear-gradient(180deg, var(--saffron-light), var(--saffron));
  border: 1px solid rgba(255, 220, 160, 0.5);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--glow-gold), inset 0 1px 0 rgba(255, 255, 255, 0.35);
  transition: transform 0.2s, box-shadow 0.2s;
}

#start-btn:hover:not(:disabled) {
  transform: translateY(-2px);
  box-shadow: 0 0 32px rgba(212, 162, 78, 0.45);
}

#start-btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.loading-msg {
  color: var(--saffron-light);
  font-size: 0.95rem;
}

#error-panel {
  max-width: 440px;
  padding: 1rem 1.4rem;
  background: rgba(139, 41, 66, 0.2);
  border: 1px solid rgba(181, 82, 58, 0.45);
  border-radius: 16px;
  backdrop-filter: blur(12px);
  color: #ffc8c8;
}

.file-warning {
  max-width: 480px;
  padding: 1rem 1.4rem;
  background: rgba(181, 82, 58, 0.15);
  border: 1px solid rgba(212, 162, 78, 0.3);
  border-radius: 16px;
  color: var(--cream);
  text-align: left;
}

.file-warning code {
  background: rgba(0, 0, 0, 0.3);
  padding: 0.1em 0.45em;
  border-radius: 6px;
  color: var(--saffron-light);
}

#hint-bar {
  position: fixed;
  bottom: 1rem;
  left: 50%;
  transform: translateX(-50%);
  z-index: 5;
  max-width: 92%;
  padding: 0.55rem 1.5rem;
  background: rgba(26, 38, 52, 0.75);
  border: 1px solid var(--glass-border);
  border-radius: 999px;
  backdrop-filter: blur(14px);
  box-shadow: inset 0 1px 0 var(--glass-highlight);
  text-align: center;
  font-size: 0.78rem;
  color: var(--cream);
  pointer-events: none;
}

.start-actions {
  display: flex;
  gap: 0.75rem;
  flex-wrap: wrap;
  justify-content: center;
}

.btn-secondary {
  padding: 0.9rem 1.6rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  color: var(--cream);
  background: rgba(26, 138, 125, 0.2);
  border: 1px solid rgba(26, 138, 125, 0.45);
  border-radius: 999px;
  backdrop-filter: blur(12px);
  cursor: pointer;
  transition: background 0.2s, border-color 0.2s;
}

.btn-secondary:hover {
  background: rgba(26, 138, 125, 0.35);
  border-color: var(--teal);
}

.btn-primary {
  padding: 0.75rem 1.8rem;
  font-size: 0.95rem;
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--night);
  background: linear-gradient(180deg, var(--saffron-light), var(--saffron));
  border: 1px solid rgba(255, 220, 160, 0.4);
  border-radius: 999px;
  cursor: pointer;
  box-shadow: var(--glow-gold);
}

.btn-icon {
  background: rgba(255, 255, 255, 0.06);
  border: 1px solid var(--glass-border);
  border-radius: 10px;
  color: var(--saffron-light);
  font-size: 1.1rem;
  cursor: pointer;
  padding: 0.35rem 0.55rem;
}

.btn-icon:hover {
  background: rgba(212, 162, 78, 0.15);
}

.fab-settings {
  position: fixed;
  top: 1rem;
  right: 1rem;
  z-index: 9;
  width: 50px;
  height: 50px;
  border-radius: 50%;
  border: 1px solid var(--glass-border);
  background: rgba(26, 38, 52, 0.8);
  backdrop-filter: blur(14px);
  color: var(--saffron-light);
  font-size: 1.3rem;
  cursor: pointer;
  pointer-events: auto;
  box-shadow: var(--glow-gold), inset 0 1px 0 var(--glass-highlight);
  transition: transform 0.2s, background 0.2s;
}

.fab-settings:hover {
  transform: scale(1.06);
  background: rgba(26, 138, 125, 0.35);
  color: var(--ivory);
}

/* ── Paramètres ─────────────────────────────────────────────────────────── */
#settings-panel {
  position: fixed;
  inset: 0;
  z-index: 100;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 1rem;
}

#settings-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(15, 25, 35, 0.6);
  backdrop-filter: blur(6px);
}

.settings-dialog {
  position: relative;
  z-index: 1;
  width: min(520px, 100%);
  max-height: min(90vh, 720px);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  background: rgba(26, 38, 52, 0.88);
  border: 2px solid var(--glass-border);
  border-radius: 20px 20px 12px 12px;
  backdrop-filter: blur(24px);
  box-shadow: var(--glow-gold), 0 32px 80px rgba(0, 0, 0, 0.5);
}

.settings-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 1.1rem 1.35rem;
  border-bottom: 1px solid rgba(212, 162, 78, 0.2);
  background: linear-gradient(180deg, rgba(212, 162, 78, 0.1), transparent);
}

.settings-header h2 {
  font-family: 'Amiri', serif;
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--saffron-light);
}

.settings-body {
  overflow-y: auto;
  padding: 0.25rem 1.35rem 1rem;
}

.settings-body::-webkit-scrollbar {
  width: 6px;
}

.settings-body::-webkit-scrollbar-thumb {
  background: rgba(212, 162, 78, 0.35);
  border-radius: 99px;
}

.settings-section {
  padding: 1rem 0;
  border-bottom: 1px solid rgba(212, 162, 78, 0.1);
}

.settings-section:last-of-type {
  border-bottom: none;
}

.settings-section h3 {
  font-family: 'Amiri', serif;
  font-size: 1.05rem;
  font-weight: 700;
  color: var(--teal);
  margin-bottom: 0.85rem;
}

.field-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.75rem;
}

.field-wide {
  grid-column: 1 / -1;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 0.4rem;
  font-size: 0.88rem;
  color: var(--text-soft);
}

.field span strong {
  color: var(--saffron-light);
}

.field select,
.field input[type='range'] {
  width: 100%;
}

.field select {
  padding: 0.55rem 0.65rem;
  border-radius: 10px;
  border: 1px solid rgba(212, 162, 78, 0.25);
  background: rgba(15, 25, 35, 0.7);
  color: var(--ivory);
  font-family: 'Outfit', sans-serif;
  font-size: 0.88rem;
}

.field select:focus {
  outline: none;
  border-color: var(--saffron);
}

.field input[type='range'] {
  accent-color: var(--saffron);
}

.field-check {
  display: flex;
  align-items: flex-start;
  gap: 0.65rem;
  margin-bottom: 0.55rem;
  font-size: 0.88rem;
  color: var(--text-soft);
  cursor: pointer;
}

.field-check input {
  accent-color: var(--teal);
}

.field-hint {
  margin-top: 0.6rem;
  font-size: 0.78rem;
  color: rgba(245, 230, 200, 0.55);
  line-height: 1.5;
}

.settings-footer {
  display: flex;
  justify-content: flex-end;
  gap: 0.65rem;
  padding: 1rem 0 0.5rem;
  position: sticky;
  bottom: 0;
  background: linear-gradient(to top, rgba(26, 38, 52, 0.95) 65%, transparent);
}

body.settings-open {
  overflow: hidden;
}
