/* Téléprompteur — version web */

:root {
  --font: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  --ed-bg: #f4f4f2;
  --ed-panel: #ffffff;
  --ed-text: #1d1d1f;
  --ed-muted: #6e6e73;
  --ed-line: #d9d9de;
  --ed-accent: #0a66d8;
  --ed-accent-text: #ffffff;
  --ed-danger: #c4302b;
  --ed-hover: #ececf0;
  --ed-selected: #dce8fb;
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --ed-bg: #161618;
    --ed-panel: #1f1f22;
    --ed-text: #f2f2f4;
    --ed-muted: #9a9aa2;
    --ed-line: #34343a;
    --ed-accent: #3d8bff;
    --ed-hover: #2a2a2f;
    --ed-selected: #1f3557;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  background: var(--ed-bg);
  color: var(--ed-text);
  overflow: hidden;
}
[hidden] { display: none !important; }
kbd {
  display: inline-block; min-width: 1.5em; text-align: center;
  padding: 0 6px; border: 1px solid var(--ed-line); border-bottom-width: 2px;
  border-radius: 5px; font: 600 0.8em/1.6 var(--font); background: var(--ed-panel); color: inherit;
}

/* ---------- Boutons ---------- */
.btn {
  appearance: none; border: 1px solid var(--ed-line); background: var(--ed-panel); color: var(--ed-text);
  border-radius: 8px; padding: 10px 18px; font: 600 15px/1.2 var(--font); cursor: pointer;
}
.btn:hover { background: var(--ed-hover); }
.btn.primary { background: var(--ed-accent); border-color: var(--ed-accent); color: var(--ed-accent-text); font-size: 17px; }
.btn.primary:hover { filter: brightness(1.08); }
.btn.primary kbd { background: transparent; border-color: rgba(255,255,255,.5); color: inherit; }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 13px; }
.btn:focus-visible, .tbtn:focus-visible { outline: 2px solid var(--ed-accent); outline-offset: 2px; }

/* ---------- Éditeur ---------- */
#editor { position: fixed; inset: 0; display: flex; }
#library {
  width: 260px; flex: none; display: flex; flex-direction: column;
  border-right: 1px solid var(--ed-line); background: var(--ed-panel);
}
.lib-head { display: flex; align-items: center; justify-content: space-between; gap: 8px; padding: 16px; }
.lib-head h1 { font-size: 17px; margin: 0; }
#script-list { list-style: none; margin: 0; padding: 0 8px; overflow-y: auto; flex: 1; }
#script-list li {
  padding: 10px 12px; border-radius: 8px; cursor: pointer; margin-bottom: 2px;
}
#script-list li:hover { background: var(--ed-hover); }
#script-list li.selected { background: var(--ed-selected); }
#script-list .s-title { font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
#script-list .s-meta { color: var(--ed-muted); font-size: 12px; margin-top: 2px; }
.lib-foot { padding: 12px 16px; }

#edit-pane { flex: 1; min-width: 0; display: flex; flex-direction: column; padding: 20px 28px; gap: 12px; overflow-y: auto; }
.edit-top { display: flex; align-items: baseline; gap: 16px; flex-wrap: wrap; }
#script-title {
  flex: 1; min-width: 200px; font: 700 24px/1.3 var(--font); border: none; background: transparent; color: inherit;
  border-bottom: 1px solid transparent; padding: 4px 0;
}
#script-title:focus { outline: none; border-bottom-color: var(--ed-accent); }
#script-stats { color: var(--ed-muted); font-size: 13px; }
#toolbar { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.tbtn {
  background: var(--ed-panel); color: var(--ed-text); border: 1px solid var(--ed-line);
  border-radius: 6px; padding: 6px 12px; cursor: pointer; font: 14px/1.2 var(--font);
}
.tbtn:hover { background: var(--ed-hover); }
.tbtn.danger { color: var(--ed-danger); }
.tb-sep { width: 1px; height: 22px; background: var(--ed-line); margin: 0 4px; }
#text {
  flex: 1; min-height: 240px; overflow-y: auto; outline: none;
  background: var(--ed-panel); color: var(--ed-text);
  border: 1px solid var(--ed-line); border-radius: 10px; padding: 20px 24px;
  font-size: 21px; line-height: 1.55; white-space: pre-wrap; word-wrap: break-word;
}
#text:focus { border-color: var(--ed-accent); }
#text:empty::before { content: attr(data-placeholder); color: var(--ed-muted); pointer-events: none; }
.edit-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
#browser-warning { color: var(--ed-danger); font-size: 14px; }
#help {
  background: var(--ed-panel); border: 1px solid var(--ed-line); border-radius: 10px; padding: 12px 16px;
  font-size: 14px; line-height: 1.45;
}
.help-head { display: flex; align-items: center; justify-content: space-between; }
#help h2 { font-size: 15px; margin: 0; }
.help-close { background: none; border: none; color: var(--ed-muted); font-size: 14px; cursor: pointer; padding: 2px 6px; border-radius: 6px; }
.help-close:hover { background: var(--ed-hover); color: var(--ed-text); }
.help-steps {
  margin: 8px 0 0; padding: 0; list-style: none; counter-reset: step;
  display: grid; grid-template-columns: repeat(auto-fill, minmax(220px, 1fr)); gap: 6px 16px;
}
.help-steps li { counter-increment: step; position: relative; padding-left: 26px; }
.help-steps li::before {
  content: counter(step); position: absolute; left: 0; top: 1px; width: 18px; height: 18px; border-radius: 50%;
  background: var(--ed-accent); color: var(--ed-accent-text);
  font-size: 11px; font-weight: 700; line-height: 18px; text-align: center;
}
#help details { margin-top: 10px; }
#help summary { cursor: pointer; font-weight: 500; }
#help dl {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 4px 16px; margin: 8px 0 0;
}
#help dl > div { display: grid; grid-template-columns: max-content 1fr; gap: 8px; align-items: baseline; }
#help dt { white-space: nowrap; min-width: 64px; }
#help dd { margin: 0; color: var(--ed-muted); }
#help .note { color: var(--ed-muted); font-style: italic; margin: 8px 0 0; font-size: 13px; }

@media (max-width: 760px) {
  #editor { flex-direction: column; }
  #library { width: auto; max-height: 30vh; border-right: none; border-bottom: 1px solid var(--ed-line); }
  #edit-pane { padding: 16px; }
}

/* ---------- Prompteur ---------- */
#prompter {
  --pr-bg: #000; --pr-fg: #fff;
  position: fixed; inset: 0; background: var(--pr-bg); color: var(--pr-fg); overflow: hidden;
  user-select: none; -webkit-user-select: none;
}
#stage { position: absolute; inset: 0; overflow: hidden; cursor: ns-resize; touch-action: none; }
#content {
  position: absolute; left: 0; right: 0; top: 0;
  padding-bottom: 100vh; will-change: transform; transform-origin: 50% 0;
}
#content-inner {
  position: relative; margin: 0 auto; white-space: pre-wrap; overflow-wrap: break-word;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, Ubuntu, "Helvetica Neue", Arial, sans-serif;
  font-weight: 500;
}
#content-inner * { color: inherit !important; background: none !important; font-size: inherit !important; font-family: inherit !important; }
#content-inner p, #content-inner div { margin: 0; }
#content-inner ul, #content-inner ol { margin: 0; padding-left: 1.2em; }
#content-inner .w.spoken { color: #3ddc84 !important; }

#cursor-line {
  position: absolute; left: 0; right: 0; height: 3px; margin-top: -1px;
  background: color-mix(in srgb, var(--pr-fg) 40%, transparent);
  cursor: ns-resize; z-index: 4; touch-action: none;
}
#cursor-line::before { content: ""; position: absolute; left: 0; right: 0; top: -12px; bottom: -12px; }
#cursor-line::after {
  content: "⋮⋮"; position: absolute; left: 8px; top: -15px; font-size: 14px;
  color: color-mix(in srgb, var(--pr-fg) 55%, transparent);
}

#side-panel {
  position: absolute; left: 8px; top: 12px; bottom: 80px; width: 120px; z-index: 5;
  display: flex; flex-direction: column; gap: 10px; pointer-events: none;
}
#side-panel > * { pointer-events: auto; }
#big-timer {
  background: color-mix(in srgb, var(--pr-fg) 10%, transparent); border-radius: 10px;
  padding: 10px 8px; text-align: center; font-variant-numeric: tabular-nums;
}
#big-timer hr { border: none; border-top: 1px solid color-mix(in srgb, var(--pr-fg) 35%, transparent); margin: 6px 0; }
.t-play { font-weight: 800; font-size: 15px; }
.t-play[data-state="play"] { color: #34c759; }
.t-play[data-state="pause"] { color: #ff9f0a; }
.t-play[data-state="ready"] { color: #32ade6; }
.t-voice { font-size: 12px; font-weight: 700; margin-top: 3px; opacity: .8; }
.t-voice[data-state="on"] { color: #34c759; opacity: 1; }
.t-voice[data-state="hold"] { color: #ff9f0a; opacity: 1; }
.t-voice[data-state="error"] { color: #ff453a; opacity: 1; }
.t-rec { color: #ff453a; font-size: 12px; font-weight: 800; margin-top: 3px; animation: blink 1.4s infinite; }
@keyframes blink { 50% { opacity: .45; } }
.t-label { font-size: 10px; letter-spacing: .06em; opacity: .7; margin-top: 4px; }
.t-value { font-size: 22px; font-weight: 700; }
#minimap { position: relative; flex: 1; min-height: 60px; cursor: pointer; touch-action: none; overflow: hidden; }
#minimap canvas { display: block; width: 100%; }
.mm-view {
  position: absolute; left: 0; right: 0; top: 0; border-radius: 3px;
  background: color-mix(in srgb, var(--pr-fg) 14%, transparent);
  border: 1px solid color-mix(in srgb, var(--pr-fg) 40%, transparent);
}
.mm-marker { position: absolute; left: 0; right: 0; top: 0; height: 2px; background: #ff9f0a; }

#heard {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%); z-index: 6;
  max-width: min(80vw, 900px); display: flex; gap: 14px; align-items: baseline;
  background: color-mix(in srgb, var(--pr-fg) 12%, transparent); border-radius: 8px; padding: 6px 14px;
  font-size: 14px; white-space: nowrap; overflow: hidden; pointer-events: none;
}
#heard .h-words { overflow: hidden; text-overflow: ellipsis; opacity: .9; }
#heard .h-marker { color: #ff9f0a; font-weight: 700; flex: none; }
#heard.error .h-words { color: #ff453a; }

#sim-box { position: absolute; bottom: 190px; left: 50%; transform: translateX(-50%); z-index: 7; width: min(90vw, 720px); }
#sim-box input {
  width: 100%; padding: 10px 14px; font-size: 16px; border-radius: 8px; border: 2px solid #ff9f0a;
  background: #111; color: #fff;
}

#camera {
  position: absolute; z-index: 8; border-radius: 10px; overflow: hidden; background: #000;
  box-shadow: 0 4px 20px rgba(0,0,0,.5); cursor: grab; touch-action: none;
  border: 1px solid rgba(255,255,255,.25);
}
#camera.full { cursor: zoom-out; border-radius: 6px; }
#camera video { width: 100%; height: 100%; object-fit: cover; transform: scaleX(-1); display: block; pointer-events: none; }

#hud {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 9;
  background: color-mix(in srgb, var(--pr-bg) 82%, transparent);
  border-top: 1px solid color-mix(in srgb, var(--pr-fg) 18%, transparent);
  padding: 8px 12px calc(8px + env(safe-area-inset-bottom)); text-align: center;
  transition: opacity .3s;
}
#hud[data-mode="hidden"] { opacity: 0; pointer-events: none; }
#hud[data-mode="hidden"].peek { opacity: 1; }
#hud-state { font-size: 15px; margin-bottom: 6px; }
#hud[data-mode="small"] #hud-state { font-size: 13px; margin-bottom: 4px; }
.st-play, .st-on { color: #34c759; }
.st-pause, .st-hold { color: #ff9f0a; }
.st-ready { color: #32ade6; }
.st-error, .st-rec { color: #ff453a; }
.st-off { opacity: .7; }
#hud-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 6px; }
#hud-buttons button {
  appearance: none; min-width: 52px; padding: 6px 8px; border-radius: 8px; cursor: pointer;
  border: 1px solid color-mix(in srgb, var(--pr-fg) 22%, transparent);
  background: color-mix(in srgb, var(--pr-fg) 8%, transparent); color: var(--pr-fg);
  font: 600 18px/1.1 var(--font); display: inline-flex; flex-direction: column; align-items: center; gap: 2px;
}
#hud-buttons button span { font-size: 10px; font-weight: 500; opacity: .65; }
#hud-buttons button:hover { background: color-mix(in srgb, var(--pr-fg) 16%, transparent); }
#hud-buttons button.on { background: color-mix(in srgb, #34c759 35%, transparent); border-color: #34c759; }
#hud-buttons button[data-act="record"].on { background: color-mix(in srgb, #ff453a 45%, transparent); border-color: #ff453a; }
#hud[data-mode="small"] #hud-buttons button { min-width: 38px; padding: 4px 6px; font-size: 15px; }
#hud[data-mode="small"] #hud-buttons button span { display: none; }

#toast {
  position: absolute; left: 50%; bottom: 120px; transform: translateX(-50%); z-index: 10;
  background: color-mix(in srgb, var(--pr-fg) 16%, var(--pr-bg)); color: var(--pr-fg);
  border-radius: 8px; padding: 8px 16px; font-size: 15px; opacity: 0; transition: opacity .3s; pointer-events: none;
  max-width: 90vw; text-align: center;
}
#toast.show { opacity: 1; }

/* ---------- Réglages ---------- */
dialog#settings {
  width: min(640px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0;
  border: 1px solid var(--ed-line); border-radius: 14px; background: var(--ed-panel); color: var(--ed-text);
}
dialog#settings::backdrop { background: rgba(0,0,0,.45); }
dialog#settings form { padding: 0 20px 20px; }
dialog#settings header {
  position: sticky; top: 0; background: var(--ed-panel); display: flex; justify-content: space-between;
  align-items: center; padding: 16px 0 8px; z-index: 1;
}
dialog#settings h2 { margin: 0; font-size: 19px; }
fieldset { border: 1px solid var(--ed-line); border-radius: 10px; margin: 12px 0 0; padding: 12px 16px 16px; }
legend { font-weight: 700; padding: 0 6px; }
fieldset label { display: block; margin-top: 10px; font-size: 14px; }
fieldset label select, fieldset label input[type="range"] { display: block; width: 100%; margin-top: 4px; }
fieldset select { padding: 6px 8px; border-radius: 6px; border: 1px solid var(--ed-line); background: var(--ed-bg); color: inherit; font: inherit; }
fieldset label.check { display: flex; gap: 8px; align-items: flex-start; }
fieldset label.check input { margin-top: 3px; }
fieldset output { float: right; color: var(--ed-muted); font-variant-numeric: tabular-nums; }
fieldset .row { display: flex; gap: 24px; flex-wrap: wrap; }
.hint { color: var(--ed-muted); font-size: 12.5px; margin: 6px 0 0; line-height: 1.4; }
fieldset .btn { margin-top: 12px; }
