:root {
    --ink: #fff;
    --glass: rgba(0, 0, 0, .45);
    --paper: #f3ede0;
    --paper-ink: #22201c;
    --accent: #e8ff3a;
    --top: env(safe-area-inset-top, 0px);
    --bottom: env(safe-area-inset-bottom, 0px);
  }
  * { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
  html, body { margin: 0; height: 100%; overflow: hidden; background: #000; color: var(--ink);
    font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
  button { font: inherit; color: inherit; }

  #view { position: fixed; inset: 0; width: 100vw; height: 100vh; height: 100dvh; display: block; touch-action: manipulation; }
  #cam { display: none; }

  /* Barre du haut */
  .top { position: fixed; top: calc(var(--top) + 12px); left: 12px; right: 12px; z-index: 10;
    display: flex; align-items: center; justify-content: space-between; gap: 10px; pointer-events: none; }
  .icon-btn { pointer-events: auto; width: 44px; height: 44px; flex: none; border-radius: 50%; border: 0;
    background: var(--glass); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
    display: grid; place-items: center; cursor: pointer; }
  .icon-btn svg { width: 22px; height: 22px; }
  .icon-btn.on { background: var(--accent); color: #000; }
  #title { pointer-events: auto; min-width: 0; max-width: 100%; padding: 9px 16px; border-radius: 22px; border: 0;
    background: var(--glass); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
    font-size: 15px; line-height: 1.2; text-align: center; cursor: pointer;
    white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
    opacity: 0; transform: translateY(-6px); transition: opacity .25s, transform .25s; }
  #title.show { opacity: 1; transform: none; }
  #title small { opacity: .7; margin-left: 6px; }

  /* Bas */
  .bottom { position: fixed; left: 0; right: 0; bottom: calc(var(--bottom) + 22px); z-index: 10;
    display: flex; flex-direction: column; align-items: center; gap: 14px; pointer-events: none; }
  #status { font-size: 15px; text-align: center; padding: 0 70px; min-height: 20px;
    text-shadow: 0 1px 6px rgba(0,0,0,.9); transition: opacity .3s; }
  #shutter { pointer-events: auto; width: 72px; height: 72px; border-radius: 50%; background: #fff;
    border: 5px solid rgba(255,255,255,.45); background-clip: padding-box; cursor: pointer; padding: 0;
    box-shadow: 0 4px 14px rgba(0,0,0,.35); transition: transform .12s; }
  #shutter:active { transform: scale(.92); }
  #logo { position: fixed; right: 16px; bottom: calc(var(--bottom) + 26px); width: 60px; z-index: 10;
    pointer-events: none; }

  #modeBtn { position: fixed; left: 14px; bottom: calc(var(--bottom) + 40px); z-index: 10; height: 40px; padding: 0 14px 0 11px;
    border: 0; border-radius: 20px; background: var(--glass); -webkit-backdrop-filter: blur(8px); backdrop-filter: blur(8px);
    display: flex; align-items: center; gap: 7px; font-size: 14px; cursor: pointer; }
  #modeBtn svg { width: 18px; height: 18px; flex: none; }
  #modeBtn.on { background: var(--accent); color: #000; }
  body.calibrating #modeBtn { display: none !important; }

  /* Calibration */
  #calPanel { position: fixed; left: 12px; right: 12px; bottom: calc(var(--bottom) + 12px); z-index: 20;
    background: rgba(0,0,0,.72); -webkit-backdrop-filter: blur(10px); backdrop-filter: blur(10px);
    border-radius: 18px; padding: 16px; display: none; max-width: 480px; margin: 0 auto; }
  #calPanel.show { display: block; }
  #calPanel p { margin: 0 0 12px; font-size: 15px; line-height: 1.35; }
  #calPanel p b { color: #ff7ae6; }
  #calPanel label { display: block; font-size: 13px; opacity: .8; margin-bottom: 6px; }
  #calPanel input[type=range] { width: 100%; accent-color: var(--accent); }
  .row { display: flex; gap: 10px; margin-top: 14px; }
  .btn { flex: 1; border: 0; border-radius: 12px; padding: 11px 14px; background: rgba(255,255,255,.14); cursor: pointer; }
  .btn.primary { background: var(--accent); color: #000; font-weight: 600; }
  body.calibrating .bottom, body.calibrating #logo { display: none; }

  /* Couches plein écran */
  .layer { position: fixed; inset: 0; z-index: 30; display: none; }
  .layer.show { display: flex; }
  .dim { background: rgba(0,0,0,.6); align-items: center; justify-content: center; padding: 20px; }
  .card { background: #151515; border-radius: 18px; padding: 22px; max-width: 420px; width: 100%; line-height: 1.45; }
  .card h2 { margin: 0 0 12px; font-size: 19px; }
  .card ol { margin: 0 0 12px; padding-left: 20px; }
  .card li { margin-bottom: 6px; }
  .card .muted { opacity: .65; font-size: 14px; }
  .card a { color: var(--accent); }

  /* Fiche */
  #fiche { align-items: flex-end; background: rgba(0,0,0,.5); }
  .sheet { background: var(--paper); color: var(--paper-ink); width: 100%; max-width: 640px; margin: 0 auto;
    max-height: 88vh; max-height: 88dvh; border-radius: 20px 20px 0 0; overflow-y: auto; position: relative;
    padding-bottom: calc(var(--bottom) + 24px); animation: up .25s ease-out; }
  @keyframes up { from { transform: translateY(40px); opacity: 0; } }
  .sheet .media img, .sheet .media video { display: block; width: 100%; height: auto; background: #000; }
  .sheet .media.slides { display: flex; overflow-x: auto; scroll-snap-type: x mandatory; }
  .sheet .media.slides img { flex: none; scroll-snap-align: start; }
  .sheet .body { padding: 18px 20px 0; }
  .sheet h2 { margin: 0 0 4px; font-family: Georgia, "Times New Roman", serif; font-size: 24px; font-weight: normal; }
  .sheet .meta { font-size: 14px; opacity: .7; margin-bottom: 14px; }
  .sheet .text { font-family: Georgia, "Times New Roman", serif; font-size: 17px; line-height: 1.55; white-space: pre-line; }
  .close { position: absolute; top: 10px; right: 10px; z-index: 2; width: 38px; height: 38px; border-radius: 50%;
    border: 0; background: rgba(0,0,0,.55); color: #fff; font-size: 22px; line-height: 1; cursor: pointer; }

  /* Aperçu photo */
  #preview .card { text-align: center; }
  #preview img { max-width: 100%; max-height: 55vh; border-radius: 10px; display: block; margin: 0 auto 14px; }

  #flash { position: fixed; inset: 0; background: #fff; opacity: 0; pointer-events: none; z-index: 40; transition: opacity .25s; }
  #toast { position: fixed; left: 50%; top: calc(var(--top) + 70px); transform: translateX(-50%); z-index: 50;
    background: rgba(0,0,0,.8); padding: 9px 16px; border-radius: 20px; font-size: 14px;
    opacity: 0; transition: opacity .25s; pointer-events: none; max-width: 90vw; text-align: center; }
  #toast.show { opacity: 1; }

  /* Fiche : crédits */
  .sheet .credits { margin-top: 16px; font-size: 13px; opacity: .65; white-space: pre-line; }

  /* Mode régie */
  #regieBtn { position: fixed; top: calc(var(--top) + 64px); left: 12px; z-index: 35;   /* au-dessus de l'écran « caméra » */ height: 30px; padding: 0 12px;
    border: 1px solid var(--accent); border-radius: 15px; background: var(--glass); color: var(--accent); font-size: 13px; cursor: pointer; }
  body.calibrating #regieBtn { display: none !important; }
  #regie { z-index: 36; }
  .regie-card { max-height: 86vh; max-height: 86dvh; overflow-y: auto; }
  .regie-card h3 { margin: 18px 0 8px; font-size: 13px; text-transform: uppercase; letter-spacing: .06em; opacity: .7; font-weight: 600; }
  .regie-row { display: flex; gap: 10px; align-items: center; font-size: 14px; }
  .swatch { width: 28px; height: 28px; border-radius: 6px; flex: none; border: 1px solid rgba(255,255,255,.3); }
  .regie-check { display: flex; gap: 8px; align-items: center; font-size: 15px; }
  #diag { position: fixed; left: 12px; top: calc(var(--top) + 102px); z-index: 9; display: none; pointer-events: none;
    background: rgba(0,0,0,.7); color: #e8ff3a; font: 12px/1.45 ui-monospace, Menlo, monospace; padding: 8px 10px; border-radius: 8px;
    white-space: pre; max-width: calc(100vw - 24px); overflow: hidden; }
  #diag.show { display: block; }
