/* ==========================================================
   LouCam — theme « Noyer & Caramel »
   Brun noyer, caramel, sable dore, creme.
   Pensé pour être regardé dans le noir sans brûler les yeux.
   ========================================================== */

:root {
  /* --- palette Noyer & Caramel --- */
  --brun: #33241a;   /* brun noyer */
  --caramel: #8a5a33;   /* caramel cuivre */
  --sable: #d5a26a; /* sable dore */
  --creme: #f3e7d8;   /* creme : texte et reflets */

  /* --- derives pour l'interface --- */
  --bg: #1a120c;
  --bg-2: #241811;
  --surface: var(--brun);
  --surface-2: #42301f;
  --line: rgba(243, 231, 216, 0.13);
  --line-strong: rgba(213, 162, 106, 0.42);

  --text: var(--creme);
  --text-dim: #b6a08a;

  --ok: #a8c98d;
  --alarm: #e0755c;

  --radius: 18px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);

  /* FreeSans est un clone metrique d'Helvetica : on garde la meme famille
     visuelle tout en restant 100 % hors ligne. */
  --font: 'FreeSans', -apple-system, BlinkMacSystemFont, 'Helvetica Neue', Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  overscroll-behavior: none;
}

body { overflow: hidden; }

button, input, select { font-family: inherit; color: inherit; }

h1, h2, .role-title, .big-label, .stat b { font-weight: 700; letter-spacing: -0.2px; }

.hidden { display: none !important; }

/* ---------------- Ecrans ---------------- */

.screen { position: fixed; inset: 0; display: none; flex-direction: column; }
.screen.active { display: flex; }

/* ---------------- Accueil ---------------- */

#screen-home {
  overflow-y: auto;
  background:
    radial-gradient(760px 420px at 18% -6%, rgba(138, 90, 51, 0.5), transparent 62%),
    radial-gradient(680px 460px at 88% 6%, rgba(213, 162, 106, 0.24), transparent 60%),
    linear-gradient(180deg, #241811 0%, var(--bg) 55%);
}

.home-wrap {
  width: 100%;
  max-width: 460px;
  margin: 0 auto;
  padding: calc(var(--safe-t) + 34px) 20px calc(var(--safe-b) + 28px);
  display: flex;
  flex-direction: column;
  gap: 20px;
  min-height: 100%;
}

.brand { text-align: center; }

.brand-mark {
  width: 64px; height: 64px;
  margin: 0 auto 12px;
  color: var(--sable);
  filter: drop-shadow(0 6px 26px rgba(213, 162, 106, 0.55));
}
.brand-mark svg { width: 100%; height: 100%; }

.brand h1 {
  margin: 0;
  font-size: 35px;
  letter-spacing: -0.8px;
  background: linear-gradient(100deg, var(--creme) 10%, var(--sable) 62%, var(--caramel) 100%);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}

.tagline { margin: 7px 0 0; color: var(--text-dim); font-size: 15px; }

.card {
  background: linear-gradient(165deg, rgba(138, 90, 51, 0.28), var(--surface) 62%);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 8px;
  box-shadow: 0 14px 40px rgba(0, 0, 0, 0.42);
}

.field-label {
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 1.1px;
  color: var(--sable);
  font-weight: 700;
}

.code-row { display: flex; gap: 10px; }

.code-input, .text-input {
  flex: 1;
  min-width: 0;
  background: rgba(26, 18, 12, 0.72);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 14px 16px;
  font-size: 18px;
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}
.code-input {
  font-size: 22px;
  letter-spacing: 3.5px;
  font-weight: 700;
  text-align: center;
  color: var(--creme);
  font-variant-numeric: tabular-nums;
}
.code-input:focus, .text-input:focus {
  border-color: var(--sable);
  box-shadow: 0 0 0 3px rgba(213, 162, 106, 0.18);
}
.code-input::placeholder, .text-input::placeholder { color: #8a7660; letter-spacing: normal; }

.hint { margin: 0; font-size: 12.5px; color: var(--text-dim); line-height: 1.45; }

.role-grid { display: flex; flex-direction: column; gap: 12px; }

.role-card {
  display: grid;
  grid-template-columns: 52px 1fr;
  grid-template-rows: auto auto;
  gap: 2px 14px;
  align-items: center;
  text-align: left;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  cursor: pointer;
  transition: transform .12s, border-color .15s, box-shadow .15s;
}
.role-card:active { transform: scale(0.985); }
.role-card:hover { border-color: var(--line-strong); }
.role-card--accent {
  background: linear-gradient(150deg, rgba(138, 90, 51, 0.62), var(--surface) 72%);
  border-color: var(--line-strong);
  box-shadow: 0 10px 34px rgba(138, 90, 51, 0.3);
}
.role-emoji { grid-row: 1 / 3; font-size: 34px; text-align: center; }
.role-title { font-size: 17px; }
.role-sub { font-size: 13px; color: var(--text-dim); line-height: 1.35; }

.warn {
  margin: 0;
  padding: 13px 15px;
  background: rgba(224, 117, 92, 0.1);
  border: 1px solid rgba(224, 117, 92, 0.32);
  border-radius: 14px;
  font-size: 13px;
  line-height: 1.5;
  color: #ffd7bd;
}

.home-foot {
  margin-top: auto;
  padding-top: 12px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.dot-state { font-size: 12.5px; color: var(--text-dim); display: flex; align-items: center; gap: 7px; }
.dot-state::before {
  content: '';
  width: 8px; height: 8px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: background .2s, box-shadow .2s;
}
.dot-state.ok::before { background: var(--ok); box-shadow: 0 0 9px var(--ok); }
.dot-state.bad::before { background: var(--alarm); }

/* ---------------- Boutons generiques ---------------- */

.btn-ghost {
  background: rgba(243, 231, 216, 0.09);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 14px;
  cursor: pointer;
  backdrop-filter: blur(12px);
  transition: background .15s, border-color .15s;
}
.btn-ghost:active { background: rgba(243, 231, 216, 0.18); }
.btn-ghost:hover { border-color: var(--line-strong); }
.btn-icon { width: 44px; height: 44px; padding: 0; display: grid; place-items: center; font-size: 18px; border-radius: 50%; }
.btn-wide { width: 100%; margin-top: 12px; }

/* ---------------- Video plein cadre ---------------- */

.fill-video {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  /* contain = on voit toute l'image de la piece, quitte a avoir des bandes
     noires. cover remplissait l'ecran mais coupait les cotes. */
  object-fit: contain;
  background: #0e0906;
}

/* la vignette de ton visage reste en cover : c'est un portrait, on veut
   qu'il remplisse le petit cadre */
.self-pip { object-fit: cover; }

/* ---------------- Mode camera ---------------- */

#screen-camera { background: #0e0906; }

.parent-overlay { position: absolute; inset: 0; z-index: 5; background: #0e0906; }
.parent-overlay-tag {
  position: absolute;
  left: 50%;
  bottom: calc(var(--safe-b) + 28px);
  transform: translateX(-50%);
  background: rgba(51, 36, 26, 0.82);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 10px 20px;
  font-size: 16px;
  font-weight: 700;
  backdrop-filter: blur(14px);
}

.cam-top, .par-top {
  position: absolute;
  top: 0; left: 0; right: 0;
  z-index: 10;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: calc(var(--safe-t) + 12px) 14px 12px;
  background: linear-gradient(180deg, rgba(14, 9, 6, 0.78), transparent);
}

.cam-status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13.5px;
  font-weight: 700;
  background: rgba(51, 36, 26, 0.7);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 8px 15px;
  backdrop-filter: blur(12px);
}

.rec-dot { width: 9px; height: 9px; border-radius: 50%; background: var(--alarm); animation: pulse 1.8s infinite; }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.25; } }

.cam-meter, .par-meter { position: absolute; z-index: 10; left: 16px; right: 16px; }
.cam-meter { bottom: 150px; }
.par-meter { bottom: 14px; }

.meter-track {
  position: relative;
  height: 8px;
  background: rgba(14, 9, 6, 0.66);
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid var(--line);
}
.meter-fill {
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--caramel), var(--sable) 62%, var(--creme));
  transition: width .07s linear;
}
.meter-thresh { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--creme); opacity: .8; left: 50%; }

.meter-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11.5px;
  color: var(--text-dim);
  margin-top: 6px;
  font-variant-numeric: tabular-nums;
}

.cam-bottom {
  position: absolute;
  z-index: 10;
  left: 0; right: 0; bottom: 0;
  padding: 16px 16px calc(var(--safe-b) + 16px);
  background: linear-gradient(0deg, rgba(14, 9, 6, 0.88), transparent);
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.cam-sens { display: flex; align-items: center; gap: 10px; font-size: 12.5px; color: var(--text-dim); }
.cam-sens label { white-space: nowrap; }
.cam-sens input[type=range] { flex: 1; accent-color: var(--sable); min-width: 60px; }
.cam-sens span { font-variant-numeric: tabular-nums; min-width: 54px; text-align: right; color: var(--sable); }

.cam-peers { font-size: 12.5px; color: var(--text-dim); }

/* ---------------- Mode parent ---------------- */

#screen-parent { background: var(--bg); }

.parent-stage { position: relative; flex: 1; min-height: 0; background: #0e0906; overflow: hidden; }

.multicam-grid {
  position: absolute;
  inset: 0;
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
  grid-auto-rows: minmax(0, 1fr);
  gap: 5px;
  padding: 5px;
  background: #0e0906;
}

.multicam-grid:has(.camera-tile:only-child) { padding: 0; }

.camera-tile {
  position: relative;
  min-width: 0;
  min-height: 0;
  overflow: hidden;
  border: 2px solid transparent;
  border-radius: 12px;
  padding: 0;
  background: #160e09;
  color: #fff;
  cursor: pointer;
}

.camera-tile.active {
  border-color: var(--sable);
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.22);
}

.camera-tile video {
  width: 100%;
  height: 100%;
  display: block;
  /* Cadre complet en tout temps : aucune caméra n'est recadrée ou zoomée. */
  object-fit: contain;
  object-position: center;
  background: #000;
}

.camera-tile-label {
  position: absolute;
  left: 9px;
  bottom: 9px;
  max-width: calc(100% - 18px);
  border-radius: 999px;
  padding: 6px 10px;
  background: rgba(20, 12, 7, .76);
  backdrop-filter: blur(8px);
  font-size: 12px;
  font-weight: 800;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.camera-tile-status {
  position: absolute;
  top: 9px;
  right: 9px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: #d7a45e;
  box-shadow: 0 0 0 3px rgba(14,9,6,.55);
}

.camera-tile.connected .camera-tile-status { background: #62d889; }
.camera-tile.failed .camera-tile-status { background: #e36c64; }

@media (max-width: 620px) {
  .multicam-grid { grid-template-columns: 1fr; }
  .camera-tile { border-radius: 9px; }
}

/* Multicam vertical + commandes compactes : garde le plus de hauteur
   possible pour les deux images sur iPhone et iPad. */
#screen-parent .multicam-grid {
  grid-template-columns: 1fr !important;
  grid-auto-rows: minmax(0, 1fr);
}
#screen-parent .par-controls {
  gap: 7px;
  padding: 7px 10px 0;
}
#screen-parent .big-btn {
  min-height: 54px;
  padding: 7px 8px !important;
  border-radius: 18px !important;
}
#screen-parent .big-emoji { font-size: 19px; }
#screen-parent .big-label { font-size: 13px; }
#screen-parent .big-hint { font-size: 9.5px; }
#screen-parent .par-tools {
  gap: 5px;
  padding: 7px 10px calc(var(--safe-b) + 8px);
}
#screen-parent .tool-btn {
  min-height: 42px;
  padding: 5px 2px !important;
  border-width: 2px !important;
  font-size: 9px;
  gap: 2px;
}
#screen-parent .tool-btn span:first-child { font-size: 14px; }

.stage-placeholder {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  color: var(--text-dim);
  font-size: 15px;
  text-align: center;
  padding: 24px;
  background:
    radial-gradient(520px 320px at 50% 42%, rgba(138, 90, 51, 0.34), transparent 68%),
    var(--bg-2);
}

.spinner {
  width: 34px; height: 34px;
  border: 3px solid rgba(213, 162, 106, 0.2);
  border-top-color: var(--sable);
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.self-pip {
  position: absolute;
  z-index: 12;
  right: 14px;
  bottom: 34px;
  width: 96px;
  height: 128px;
  object-fit: cover;
  border-radius: 14px;
  border: 2px solid var(--sable);
  box-shadow: 0 8px 26px rgba(0, 0, 0, 0.7);
  transform: scaleX(-1);
}

.cam-picker { flex: 1; min-width: 0; }
#par-camera-select {
  width: 100%;
  background: rgba(51, 36, 26, 0.78);
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 11px 16px;
  font-size: 14px;
  font-weight: 700;
  appearance: none;
  text-align: center;
  text-align-last: center;
  backdrop-filter: blur(12px);
}

.par-controls {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
  padding: 14px 14px 0;
}

.big-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 3px;
  padding: 18px 10px;
  border-radius: 20px;
  border: 1px solid var(--line);
  background: var(--surface);
  cursor: pointer;
  user-select: none;
  -webkit-user-select: none;
  touch-action: manipulation;
  transition: transform .1s, background .15s, box-shadow .15s, border-color .15s;
}
.big-btn:hover { border-color: var(--line-strong); }
.big-emoji { font-size: 27px; line-height: 1; }
.big-label { font-size: 15.5px; }
.big-hint { font-size: 11.5px; color: var(--text-dim); }

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

/* Parler à Lou → lavande */
.big-btn--talk.on {
  background: linear-gradient(158deg, var(--sable), #b08a5e);
  border-color: var(--sable);
  color: #241811;
  transform: scale(0.97);
  box-shadow: 0 0 0 6px rgba(213, 162, 106, 0.2);
}
.big-btn--talk.on .big-hint { color: rgba(36, 24, 17, 0.74); }

/* Lou me voit → caramel cuivre */
.big-btn--show.on {
  background: linear-gradient(158deg, #a06a3c, var(--caramel));
  border-color: #c08a4e;
  color: var(--creme);
  box-shadow: 0 0 0 6px rgba(138, 90, 51, 0.26);
}
.big-btn--show.on .big-hint { color: rgba(243, 231, 216, 0.76); }

.par-tools {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 7px;
  padding: 12px 14px calc(var(--safe-b) + 14px);
}

.tool-btn {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px 2px;
  font-size: 10.5px;
  font-weight: 700;
  cursor: pointer;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 5px;
  transition: background .15s, border-color .15s, color .15s;
}
.tool-btn:hover { border-color: var(--line-strong); }
.tool-btn span:first-child { font-size: 18px; }
.tool-btn.on {
  background: rgba(213, 162, 106, 0.22);
  border-color: var(--sable);
  color: var(--sable);
}
#btn-light.on {
  background: rgba(243, 231, 216, 0.2);
  border-color: var(--creme);
  color: var(--creme);
}

/* ---------------- Veilleuse (l'ecran de la station fait la lampe) ------ */

.lamp {
  position: absolute;
  inset: 0;
  z-index: 8;
  pointer-events: none;
  background: #fff4e0; /* lumiere chaude : meilleure pour l'oeil du chien la nuit */
  opacity: 0;
  transition: opacity .35s ease;
}
.lamp.on { opacity: var(--lamp-level, 0.7); }

/* ---------------- Toast + alerte ---------------- */

.toast {
  position: absolute;
  z-index: 40;
  left: 50%;
  top: calc(var(--safe-t) + 72px);
  transform: translateX(-50%);
  background: rgba(51, 36, 26, 0.95);
  border: 1px solid var(--line-strong);
  border-radius: 999px;
  padding: 11px 20px;
  font-size: 13.5px;
  max-width: 88%;
  text-align: center;
  backdrop-filter: blur(16px);
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
  animation: toast-in .22s ease;
}
@keyframes toast-in { from { opacity: 0; transform: translate(-50%, -8px); } }

.bark-alert {
  position: absolute;
  z-index: 41;
  left: 50%;
  top: calc(var(--safe-t) + 72px);
  transform: translateX(-50%);
  background: linear-gradient(150deg, var(--sable), var(--caramel));
  color: var(--creme);
  font-weight: 700;
  border-radius: 999px;
  padding: 12px 24px;
  font-size: 15px;
  box-shadow: 0 10px 34px rgba(138, 90, 51, 0.6);
  animation: bark-pop .3s cubic-bezier(.2, 1.4, .5, 1);
}
@keyframes bark-pop { from { opacity: 0; transform: translate(-50%, -14px) scale(.85); } }

/* ---------------- Panneau activite ---------------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 60;
  background: rgba(14, 9, 6, 0.68);
  display: flex;
  align-items: flex-end;
  backdrop-filter: blur(4px);
}

.sheet-panel {
  width: 100%;
  max-height: 88vh;
  overflow-y: auto;
  background: linear-gradient(180deg, #2c2016, var(--bg-2) 42%);
  border-top: 1px solid var(--line-strong);
  border-radius: 24px 24px 0 0;
  padding: 18px 18px calc(var(--safe-b) + 22px);
  animation: sheet-up .26s cubic-bezier(.2, .9, .3, 1);
}
@keyframes sheet-up { from { transform: translateY(100%); } }

.sheet-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.sheet-head h2 { margin: 0; font-size: 19px; }

.stats-row { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; margin-bottom: 16px; }
.stat {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 13px 8px;
  text-align: center;
}
.stat b { display: block; font-size: 21px; color: var(--sable); font-variant-numeric: tabular-nums; }
.stat span { font-size: 11px; color: var(--text-dim); }

.chart-wrap { background: var(--surface); border: 1px solid var(--line); border-radius: 14px; padding: 12px; }
#activity-chart { width: 100%; height: 130px; display: block; }
.chart-legend { display: flex; justify-content: space-between; font-size: 11px; color: var(--text-dim); margin-top: 6px; }

.alert-toggle { margin: 16px 0 10px; }
.switch { display: flex; align-items: center; gap: 11px; font-size: 14px; cursor: pointer; }
.switch input { position: absolute; opacity: 0; pointer-events: none; }
.switch-track {
  width: 46px; height: 27px;
  flex: none;
  border-radius: 999px;
  background: var(--surface-2);
  border: 1px solid var(--line);
  position: relative;
  transition: background .18s, border-color .18s;
}
.switch-track::after {
  content: '';
  position: absolute;
  top: 3px; left: 3px;
  width: 19px; height: 19px;
  border-radius: 50%;
  background: var(--text-dim);
  transition: transform .18s, background .18s;
}
.switch input:checked + .switch-track { background: rgba(213, 162, 106, 0.32); border-color: var(--sable); }
.switch input:checked + .switch-track::after { transform: translateX(19px); background: var(--sable); }
.switch input:focus-visible + .switch-track { box-shadow: 0 0 0 3px rgba(213, 162, 106, 0.3); }

.event-list { list-style: none; margin: 12px 0 0; padding: 0; display: flex; flex-direction: column; gap: 6px; }
.event-list li {
  display: flex;
  align-items: center;
  gap: 11px;
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 11px 14px;
  font-size: 13px;
}
.event-list .ev-time { color: var(--text-dim); font-variant-numeric: tabular-nums; min-width: 52px; }
.event-list .ev-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.event-list .ev-lvl { color: var(--sable); font-weight: 700; font-variant-numeric: tabular-nums; }
.event-list .empty { justify-content: center; color: var(--text-dim); }

/* ---------------- Accessibilite ---------------- */

:focus-visible { outline: 2px solid var(--sable); outline-offset: 2px; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
  .rec-dot { animation: none; }
}

/* ---------------- Ecran large ---------------- */

@media (min-width: 780px) {
  .par-controls, .par-tools { max-width: 620px; margin: 0 auto; }
  .self-pip { width: 132px; height: 176px; }
  .sheet-panel { max-width: 720px; margin: 0 auto; border-radius: 24px 24px 0 0; }
}

