:root {
  --bg: #0f1720; --panel: #17212c; --panel2: #1e2a37; --line: #2a3847; --text: #e8eef4; --muted: #8fa1b3;
  --accent: #f5a524; --ok: #31c48d; --bad: #f05252; --radius: 16px;
}
* { box-sizing: border-box; }
[hidden] { display: none !important; }
html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text);
  font: 16px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
input, select { background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; min-width: 0; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
h1, h2 { margin: 0; }
h2 { font-size: 1.05rem; }
.muted { color: var(--muted); }
.small-text { font-size: .8rem; }
.error { color: #ffb4b4; background: rgba(240,82,82,.15); padding: 8px 12px; border-radius: 10px; margin: 0; }
.screen { display: none; min-height: 100vh; min-height: 100dvh; }
.screen.active { display: flex; }

/* Boutons */
.btn { background: var(--panel2); border-radius: 12px; padding: 10px 16px; text-align: center; }
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .45; cursor: not-allowed; }
.btn.primary { background: var(--accent); color: #111; font-weight: 600; }
.btn.ghost { background: transparent; color: var(--muted); }
.btn.danger { background: rgba(240,82,82,.18); color: #ffb4b4; }
.btn.small { padding: 6px 12px; font-size: .9rem; }
.btn.big { width: 100%; padding: 16px; font-size: 1.1rem; border-radius: var(--radius); }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.row.center { justify-content: center; }

/* Accueil et pages */
#home, .page { flex-direction: column; align-items: stretch; padding: 24px 16px max(24px, env(safe-area-inset-bottom)); gap: 16px; max-width: 640px; margin: 0 auto; width: 100%; }
#home { justify-content: center; }
.brand { display: flex; align-items: center; justify-content: center; gap: 14px; }
.brand img { width: 56px; height: 56px; }
.brand h1 { font-size: 2.2rem; letter-spacing: -.02em; }
.tagline { color: var(--muted); margin: 0; text-align: center; }
.card { background: var(--panel); border-radius: var(--radius); padding: 16px; display: flex; flex-direction: column; gap: 12px; }
.card.warn { border: 1px solid var(--accent); }
.card p { margin: 0; }
.form { display: flex; flex-direction: column; gap: 12px; }
.form.disabled > :not(:first-child) { opacity: .5; }
.page-head { display: flex; align-items: center; gap: 12px; }
.page-head h1 { font-size: 1.4rem; }
.field { display: flex; flex-direction: column; gap: 6px; color: var(--muted); font-size: .9rem; width: 100%; }
.field input, .field select { color: var(--text); font-size: 1rem; }
.field.small { flex-direction: row; align-items: center; gap: 12px; width: auto; flex: 1; }
.field.small input[type=range] { flex: 1; accent-color: var(--accent); padding: 0; }
.code-row { display: flex; gap: 8px; }
.code-row input { flex: 1; }
#roomCode { font-size: 1.8rem; letter-spacing: .3em; text-align: center; padding: 10px; }
.roles { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.role { background: var(--panel2); border-radius: var(--radius); padding: 20px 12px; display: flex; flex-direction: column;
  align-items: center; gap: 4px; border: 2px solid transparent; transition: border-color .15s, transform .1s; }
.role:hover { border-color: var(--accent); }
.role:active { transform: scale(.98); }
.role-icon { font-size: 2.2rem; }
.role strong { font-size: 1.1rem; }
.role small { color: var(--muted); text-align: center; }
.hint { color: var(--muted); font-size: .85rem; text-align: center; margin: 0; }
.hint.left { text-align: left; }
.cam-list { display: flex; flex-direction: column; gap: 8px; }
.cam-list .empty { color: var(--muted); margin: 0; font-size: .9rem; }
.cam-item { display: flex; align-items: center; gap: 12px; background: var(--panel2); border-radius: 12px; padding: 14px; text-align: left; }
.cam-item:hover { filter: brightness(1.15); }
.cam-name { flex: 1; font-weight: 600; }
.cam-name small { color: var(--muted); font-weight: normal; }
.cam-state { color: var(--muted); font-size: .85rem; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); display: inline-block; flex: none; }
.dot.on { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.dot.off { background: var(--bad); }

/* Vidéo plein écran (caméra, scanner) */
#camera, #scan, .stage { position: relative; background: #000; overflow: hidden; }
#camera, #scan { height: 100vh; height: 100dvh; width: 100%; }
video { width: 100%; height: 100%; object-fit: contain; background: #000; display: block; }
.overlay { position: absolute; left: 0; right: 0; display: flex; gap: 8px; padding: 12px; flex-wrap: wrap; z-index: 3; pointer-events: none; }
.overlay > * { pointer-events: auto; }
.overlay.top { top: 0; padding-top: max(12px, env(safe-area-inset-top)); }
.overlay.bottom { bottom: 0; justify-content: center; align-items: center; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.pill { background: rgba(0,0,0,.6); backdrop-filter: blur(6px); padding: 6px 12px; border-radius: 999px; font-size: .85rem;
  display: inline-flex; align-items: center; gap: 6px; margin: 0; }
.pill:empty { display: none; }
.pill .dot { width: 8px; height: 8px; box-shadow: none; }
.pill.on .dot { background: var(--ok); box-shadow: 0 0 8px var(--ok); }
.pill.off .dot { background: var(--bad); }
.pill.rec { color: #fff; background: rgba(240,82,82,.85); }
.pill.talk { color: #111; background: var(--accent); }
.ctl { background: var(--panel2); padding: 10px 14px; border-radius: 12px; white-space: nowrap; display: inline-flex; flex-direction: column; align-items: center; gap: 2px; min-width: 64px; }
.ctl i { font-style: normal; font-size: 1.2rem; }
.ctl span { font-size: .75rem; color: var(--muted); }
.overlay .ctl { background: rgba(0,0,0,.6); backdrop-filter: blur(6px); flex-direction: row; gap: 6px; }
.ctl:hover { filter: brightness(1.2); }
.ctl.active { background: var(--accent); color: #111; }
.ctl.active span { color: #111; }
.ctl.danger { background: rgba(240,82,82,.2); color: #ffb4b4; }
.ctl:disabled { opacity: .4; cursor: not-allowed; }
.motion-flash { position: absolute; inset: 0; border: 6px solid var(--bad); opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 2; }
.motion-flash.show { opacity: 1; }
#dimmer { position: fixed; inset: 0; background: #000; z-index: 10; display: flex; align-items: flex-end; justify-content: center; }
#dimmer p { color: #333; margin-bottom: 40px; }
.cam-tip { position: absolute; left: 12px; right: 12px; bottom: max(84px, calc(env(safe-area-inset-bottom) + 72px)); margin: 0; text-align: center; font-size: .85rem; color: var(--muted); z-index: 3; pointer-events: none; }
.scan-frame { position: absolute; inset: 0; margin: auto; width: min(70vw, 70vh); height: min(70vw, 70vh); border: 3px solid var(--accent); border-radius: 24px; box-shadow: 0 0 0 100vmax rgba(0,0,0,.45); pointer-events: none; }

/* Feuilles modales */
.sheet { position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.7); display: flex; align-items: center; justify-content: center; padding: 16px; }
.sheet-card { background: var(--panel); border-radius: var(--radius); padding: 20px; display: flex; flex-direction: column; gap: 12px; align-items: center; text-align: center; max-width: 420px; width: 100%; max-height: 100%; overflow: auto; }
.sheet-card.wide { max-width: 860px; }
.sheet-card p { margin: 0; }
#qrImg { width: min(260px, 70vw); image-rendering: pixelated; background: #fff; border-radius: 12px; padding: 6px; }
.link { font-size: .75rem; color: var(--muted); word-break: break-all; }
#playerVideo { width: 100%; max-height: 60vh; border-radius: 12px; background: #000; object-fit: contain; }

/* Visionneuse */
#viewer { flex-direction: column; }
.stage { aspect-ratio: 16 / 9; max-height: 62vh; width: 100%; touch-action: none; user-select: none; }
#view { position: absolute; inset: 0; transform-origin: center center; }
#relayImg { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
#boxCanvas { position: absolute; pointer-events: none; z-index: 1; }
#zoneEditor { position: absolute; z-index: 2; display: grid; grid-auto-rows: 1fr; }
.zcell { border: 1px solid rgba(255,255,255,.25); background: rgba(0,0,0,.55); border-radius: 0; touch-action: none; }
.zcell.on { background: rgba(245,165,36,.25); border-color: rgba(245,165,36,.6); }
.waiting { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 12px; color: var(--muted); text-align: center; padding: 16px; z-index: 2; }
#pausedOverlay { background: rgba(0,0,0,.75); z-index: 4; }
.waiting.hide { display: none; }
.spinner { width: 40px; height: 40px; border: 4px solid var(--panel2); border-top-color: var(--accent); border-radius: 50%; animation: spin 1s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.toolbar { display: flex; gap: 8px; padding: 10px 16px; overflow-x: auto; background: var(--panel); scrollbar-width: thin; }
.panel { padding: 12px 16px max(16px, env(safe-area-inset-bottom)); display: flex; flex-direction: column; gap: 12px; }
.tabs { display: flex; gap: 4px; background: var(--panel); border-radius: 12px; padding: 4px; }
.tab { flex: 1; padding: 8px; border-radius: 9px; color: var(--muted); }
.tab.active { background: var(--panel2); color: var(--text); }
.tab small { color: var(--muted); }
.pane { display: flex; flex-direction: column; gap: 12px; }
.chips { display: flex; gap: 6px; flex-wrap: wrap; }
.chip { background: var(--panel2); border-radius: 999px; padding: 6px 12px; font-size: .9rem; }
.chip.active { background: var(--accent); color: #111; }
.chips.days label { position: relative; }
.chips.days input { position: absolute; opacity: 0; }
.chips.days span { display: inline-block; width: 36px; height: 36px; line-height: 36px; text-align: center; border-radius: 50%; background: var(--panel2); cursor: pointer; }
.chips.days input:checked + span { background: var(--accent); color: #111; }
.events { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.events .empty { color: var(--muted); grid-column: 1 / -1; margin: 0; }
.event { background: var(--panel); border-radius: 12px; overflow: hidden; text-align: left; padding: 0; border: 2px solid transparent; }
.event.selected { border-color: var(--accent); }
.event img { width: 100%; display: block; aspect-ratio: 4/3; object-fit: cover; background: #000; }
.event span { display: block; padding: 4px 10px; font-size: .8rem; }
.ev-kind { font-weight: 600; padding-top: 6px !important; }
.ev-kind.k-person { color: var(--ok); }
.ev-kind.k-sound { color: #7cb7ff; }
.ev-time { color: var(--muted); padding-bottom: 8px !important; }
.switch { position: relative; width: 50px; height: 28px; flex: none; }
.switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.switch span { position: absolute; inset: 0; background: var(--panel2); border-radius: 999px; transition: .2s; cursor: pointer; }
.switch span::before { content: ""; position: absolute; width: 22px; height: 22px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .2s; }
.switch input:checked + span { background: var(--ok); }
.switch input:checked + span::before { transform: translateX(22px); }
.switch input:disabled + span { opacity: .4; }
.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #fff; color: #111; padding: 10px 18px;
  border-radius: 12px; z-index: 30; max-width: calc(100% - 32px); box-shadow: 0 6px 24px rgba(0,0,0,.4); }

@media (min-width: 1000px) {
  #viewer { flex-direction: row; flex-wrap: wrap; align-content: flex-start; }
  #viewer .stage { flex: 1 1 60%; max-height: none; aspect-ratio: auto; height: calc(100vh - 78px); }
  #viewer .panel { flex: 0 0 380px; height: calc(100vh - 78px); overflow-y: auto; }
  #viewer .toolbar { order: 2; flex-basis: 100%; }
}
@media (max-width: 480px) { .roles { grid-template-columns: 1fr; } #roomCode { font-size: 1.5rem; } }
