/* Viseur : l'image de visée occupe tout l'écran, les commandes flottent sur des bandes sombres.
   Un seul thème sombre, volontairement (écran de visée). */
:root {
  --ink: #0b0c0e;
  --panel: rgba(16, 18, 21, .92);
  --panel-solid: #15171b;
  --raise: rgba(255, 255, 255, .08);
  --line: rgba(255, 255, 255, .13);
  --text: #edebe5;
  --dim: #979ba2;
  --frame: #f6f3ea;
  --accent: #ffbe3b;
  --accent-ink: #1a1405;
  --warn: #ff7b5c;
  --rec: #e8463e;
  --ui: 'Barlow Semi Condensed', 'Arial Narrow', system-ui, -apple-system, sans-serif;
  --mono: 'IBM Plex Mono', ui-monospace, 'SF Mono', Menlo, Consolas, monospace;
  --sat: env(safe-area-inset-top, 0px);
  --sar: env(safe-area-inset-right, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
  --sal: env(safe-area-inset-left, 0px);
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; overflow: hidden; background: var(--ink); color: var(--text); }
body {
  font: 15px/1.3 var(--ui);
  -webkit-user-select: none; user-select: none;
  -webkit-touch-callout: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
}
button, input, select { font: inherit; color: inherit; }
button { cursor: pointer; touch-action: manipulation; border: 0; background: none; padding: 0; }
button:focus-visible, input:focus-visible, select:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
[hidden] { display: none !important; }
.mono { font-family: var(--mono); font-variant-numeric: tabular-nums; }
.dim { color: var(--dim); }

#sa {
  position: fixed; inset: 0; visibility: hidden; pointer-events: none;
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
}

/* ---------- Image ---------- */
#stage { position: fixed; inset: 0; overflow: hidden; background: #000; touch-action: none; }
#video, #freeze {
  position: absolute; left: 0; top: 0;
  transform-origin: 50% 50%;
  transition: transform .2s cubic-bezier(.2, .75, .25, 1);
  will-change: transform;
}
#freeze { opacity: 0; transition: transform .2s cubic-bezier(.2, .75, .25, 1), opacity .18s; pointer-events: none; }
#freeze.on { opacity: 1; transition: none; }
#overlay { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#flash.go { animation: flash .32s ease-out; }
@keyframes flash { 0% { opacity: .75; } 100% { opacity: 0; } }

#bigfocal {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 10px 18px; border-radius: 14px; background: rgba(8, 9, 11, .55);
  opacity: 0; transition: opacity .25s; pointer-events: none;
}
#bigfocal.on { opacity: 1; transition: none; }
#bigfocal b { font: 600 44px/1 var(--ui); letter-spacing: .01em; }
#bigfocal span { font: 12px/1.2 var(--mono); color: var(--dim); }

/* ---------- Commandes ---------- */
.hud { position: fixed; z-index: 5; transition: opacity .2s; }
body.clean .hud { opacity: 0; pointer-events: none; }

#top {
  top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--sat) + 6px) calc(var(--sar) + 10px) 14px calc(var(--sal) + 10px);
  background: linear-gradient(rgba(8, 9, 11, .78), rgba(8, 9, 11, 0));
}
.spacer { flex: 1; }

.pill {
  display: grid; grid-template-columns: auto; text-align: left;
  min-width: 0; max-width: 34vw;
  padding: 4px 10px 5px; border-radius: 10px;
  background: var(--raise); border: 1px solid var(--line);
  line-height: 1.15;
}
.pill:active { background: rgba(255, 255, 255, .16); }
.pill .k { font-size: 9.5px; letter-spacing: .12em; text-transform: uppercase; color: var(--dim); }
.pill .v { font-weight: 600; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill .s { font-size: 11.5px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.pill-small { max-width: none; }

#readout { display: grid; gap: 1px; padding: 0 6px; font-size: 11.5px; line-height: 1.3; white-space: nowrap; min-width: 0; overflow: hidden; }
#readout span { overflow: hidden; text-overflow: ellipsis; }

/* Paysage sur téléphone : barre du haut plus basse pour laisser la place au cadre */
@media (orientation: landscape) and (max-height: 500px) {
  .pill .k { display: none; }
  .pill { padding: 4px 10px; }
  #top { padding-bottom: 8px; }
  .icon { width: 36px; height: 36px; }
}

.icon {
  width: 40px; height: 40px; border-radius: 10px; display: grid; place-items: center;
  background: var(--raise); border: 1px solid var(--line); font-size: 20px; line-height: 1;
}
.icon svg { width: 22px; height: 22px; fill: none; stroke: currentColor; stroke-width: 1.6; stroke-linecap: round; }
.icon:active { background: rgba(255, 255, 255, .16); }
#btn-display.on { color: var(--accent); border-color: rgba(255, 190, 59, .5); }

#warn {
  left: 50%; transform: translateX(-50%);
  top: calc(var(--sat) + 62px);
  max-width: min(92vw, 560px);
  padding: 6px 12px; border-radius: 8px;
  background: rgba(40, 14, 8, .82); color: #ffd2c5; border: 1px solid rgba(255, 123, 92, .45);
  font-size: 13px; text-align: center;
}

#focals {
  left: calc(var(--sal) + 10px); right: calc(var(--sar) + 110px);
  bottom: calc(var(--sab) + 8px);
  display: grid; gap: 6px; justify-items: center;
}
#chips {
  display: flex; gap: 5px; max-width: 100%;
  overflow-x: auto; scrollbar-width: none; padding: 2px 4px;
  -webkit-overflow-scrolling: touch;
}
#chips::-webkit-scrollbar { display: none; }
.chip {
  flex: none; min-width: 42px; height: 34px; padding: 0 10px; border-radius: 17px;
  background: rgba(10, 11, 13, .62); border: 1px solid var(--line);
  font: 500 14px/1 var(--mono); font-variant-numeric: tabular-nums;
}
.chip.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
#zoom { width: min(520px, 100%); accent-color: var(--accent); }

#side {
  top: 0; bottom: 0; right: calc(var(--sar) + 10px); width: 92px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px;
}
.thumb { display: grid; justify-items: center; gap: 4px; }
.thumb img {
  width: 52px; height: 52px; border-radius: 10px; object-fit: cover;
  background: #222 linear-gradient(135deg, #262a30, #15171b); border: 1px solid var(--line);
}
.thumb span { max-width: 88px; font-size: 11px; color: var(--dim); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#shutter {
  width: 74px; height: 74px; border-radius: 50%;
  border: 4px solid var(--frame); display: grid; place-items: center;
  background: rgba(0, 0, 0, .2);
}
#shutter span { width: 58px; height: 58px; border-radius: 50%; background: var(--frame); transition: transform .12s, background .12s; }
#shutter:active span { transform: scale(.88); background: var(--accent); }
.phone { text-align: center; }

/* Portrait : commandes en bas */
@media (orientation: portrait) {
  #top { flex-wrap: wrap; row-gap: 6px; }
  #top .pill { max-width: 46vw; }
  #readout { order: 10; flex-basis: 100%; grid-auto-flow: column; justify-content: start; gap: 12px; padding: 0 2px; }
  #warn { top: calc(var(--sat) + 112px); }
  #focals { left: calc(var(--sal) + 8px); right: calc(var(--sar) + 8px); bottom: calc(var(--sab) + 112px); }
  #side {
    top: auto; left: 0; right: 0; bottom: calc(var(--sab) + 14px); width: auto; height: 90px;
    flex-direction: row; justify-content: space-around; padding: 0 calc(var(--sar) + 12px) 0 calc(var(--sal) + 12px);
    background: none;
  }
}

/* ---------- Feuilles ---------- */
#backdrop { position: fixed; inset: 0; z-index: 19; background: rgba(0, 0, 0, .45); }
.sheet {
  position: fixed; z-index: 20; display: flex; flex-direction: column;
  background: var(--panel-solid); border: 1px solid var(--line);
  top: 0; bottom: 0; right: 0; width: min(440px, 64vw);
  padding: calc(var(--sat) + 8px) calc(var(--sar) + 14px) calc(var(--sab) + 8px) 14px;
  transform: translateX(105%); transition: transform .26s cubic-bezier(.2, .75, .25, 1);
  -webkit-user-select: text; user-select: text;
}
.sheet.open { transform: none; }
@media (orientation: portrait) {
  .sheet {
    top: auto; left: 0; width: auto; max-height: 76vh; border-radius: 16px 16px 0 0;
    padding: 10px calc(var(--sar) + 14px) calc(var(--sab) + 10px) calc(var(--sal) + 14px);
    transform: translateY(105%);
  }
  .sheet-tall { max-height: 90vh; }
}
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 0 8px; }
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 600; letter-spacing: .01em; }
.close { width: 36px; height: 36px; border-radius: 50%; background: var(--raise); font-size: 15px; }
.sheet-body { overflow-y: auto; -webkit-overflow-scrolling: touch; padding-bottom: 12px; min-height: 0; }
.sheet h3 {
  margin: 18px 0 8px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); font-weight: 500;
}
.help { color: var(--dim); font-size: 13px; line-height: 1.4; margin: 6px 0 10px; }
.search {
  width: 100%; margin-bottom: 8px; padding: 9px 12px; border-radius: 10px;
  background: var(--raise); border: 1px solid var(--line); outline: none;
}

.group-title {
  position: sticky; top: 0; z-index: 1; background: var(--panel-solid);
  padding: 12px 2px 6px; font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--dim);
}
.item {
  display: grid; grid-template-columns: 1fr auto; align-items: center; gap: 2px 10px;
  width: 100%; padding: 10px 10px; border-radius: 10px; text-align: left;
}
.item:active, .item.open { background: var(--raise); }
.item.cur { box-shadow: inset 3px 0 0 var(--accent); background: rgba(255, 190, 59, .07); }
.item b { font-weight: 600; font-size: 15px; }
.item small { grid-column: 1 / -1; color: var(--dim); font-size: 12.5px; }
.tags { display: flex; gap: 4px; flex-wrap: wrap; justify-content: flex-end; }
.tag { font: 500 10.5px/1 var(--mono); padding: 3px 5px; border-radius: 4px; background: var(--raise); color: var(--dim); }
.tag.ana { color: var(--accent); background: rgba(255, 190, 59, .12); }
.modes { display: grid; gap: 2px; padding: 2px 0 8px 10px; }
.mode {
  display: grid; grid-template-columns: 1fr auto; gap: 8px; align-items: baseline;
  padding: 8px 10px; border-radius: 8px; text-align: left; font-size: 14px;
}
.mode span { font: 11.5px var(--mono); color: var(--dim); }
.mode.cur { background: var(--accent); color: var(--accent-ink); }
.mode.cur span { color: var(--accent-ink); }
.custom { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; padding: 8px 10px; }
.custom input { width: 72px; padding: 7px 8px; border-radius: 8px; background: var(--raise); border: 1px solid var(--line); }

.chips-grid { display: flex; flex-wrap: wrap; gap: 6px; }
.chips-grid button {
  padding: 8px 12px; border-radius: 18px; background: var(--raise); border: 1px solid var(--line);
  font: 500 13.5px/1 var(--mono);
}
.chips-grid button.on { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }

.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 3px; border-radius: 10px; background: var(--raise); }
.seg button { padding: 8px; border-radius: 8px; font-weight: 500; }
.seg button.on { background: var(--frame); color: #111; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 10px 2px; border-bottom: 1px solid var(--line); }
.row.col { flex-direction: column; align-items: stretch; gap: 6px; }
.row select { padding: 9px 10px; border-radius: 10px; background: var(--raise); border: 1px solid var(--line); }
.row input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); }
.row input[type=range] { width: 46%; accent-color: var(--accent); }
.wide { width: 100%; margin-top: 10px; padding: 11px; border-radius: 10px; background: var(--raise); border: 1px solid var(--line); font-weight: 600; }
.lens-row { display: grid; gap: 4px; padding: 10px; border-radius: 10px; border: 1px solid var(--line); margin-bottom: 6px; }
.lens-row.cur { border-color: rgba(255, 190, 59, .5); background: rgba(255, 190, 59, .05); }
.lr-top { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.lr-top b { font-weight: 600; }
.lr-top span { font-size: 12px; color: var(--dim); white-space: nowrap; }
.lens-row small { color: var(--dim); font-size: 12px; overflow-wrap: anywhere; }
.lr-actions { display: flex; gap: 6px; margin-top: 4px; }
.lr-actions select { flex: 1; min-width: 0; padding: 7px 8px; border-radius: 8px; background: var(--raise); border: 1px solid var(--line); }
.lr-actions button:not(.primary) { padding: 7px 10px; border-radius: 8px; background: var(--raise); border: 1px solid var(--line); }
.lr-actions .primary { padding: 7px 10px; }
.start-phone { display: grid; gap: 6px; width: 100%; margin-top: 10px; text-align: left; }
.start-phone span { font-size: 11px; letter-spacing: .14em; text-transform: uppercase; color: var(--dim); }
.start-phone select { width: 100%; padding: 11px 12px; border-radius: 10px; background: var(--raise); border: 1px solid var(--line); font-size: 16px; }
#start-phone-note { margin: 0; min-height: 0; }
#start-phone-note:empty { display: none; }

.primary { background: var(--accent); color: var(--accent-ink); font-weight: 600; border-radius: 10px; padding: 10px 14px; }
.danger { background: rgba(255, 123, 92, .14); color: var(--warn); border: 1px solid rgba(255, 123, 92, .4); border-radius: 10px; padding: 10px 14px; font-weight: 600; }
.danger.armed { background: var(--warn); color: #1a0703; }

/* Projets */
.proj-list { display: grid; gap: 4px; }
.proj-row { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; padding: 10px; border-radius: 10px; text-align: left; }
.proj-row.cur { background: rgba(255, 190, 59, .09); box-shadow: inset 3px 0 0 var(--accent); }
.proj-row b { font-weight: 600; }
.proj-row span { color: var(--dim); font-size: 12.5px; }
.new-proj { display: flex; gap: 6px; margin: 10px 0 4px; }
.new-proj input { flex: 1; min-width: 0; padding: 9px 12px; border-radius: 10px; background: var(--raise); border: 1px solid var(--line); }
.proj-head { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; margin-top: 18px; }
.proj-head h3 { margin: 0 auto 0 0; font-size: 17px; letter-spacing: 0; text-transform: none; color: var(--text); font-weight: 600; }
.proj-head button { padding: 7px 10px; border-radius: 8px; background: var(--raise); border: 1px solid var(--line); font-size: 13px; }
.shots { display: grid; grid-template-columns: repeat(auto-fill, minmax(120px, 1fr)); gap: 8px; margin-top: 10px; }
.shot { display: grid; gap: 4px; text-align: left; }
.shot img { width: 100%; aspect-ratio: 16 / 9; object-fit: contain; background: #000; border-radius: 6px; border: 1px solid var(--line); }
.shot span { font: 11.5px var(--mono); color: var(--dim); }
.empty { color: var(--dim); font-size: 14px; padding: 18px 4px; line-height: 1.45; }

/* Visionneuse */
#viewer {
  position: fixed; inset: 0; z-index: 30; background: #050506;
  display: grid; grid-template-columns: 1fr min(360px, 40vw);
  padding: var(--sat) var(--sar) var(--sab) var(--sal);
}
.viewer-img { display: grid; place-items: center; min-width: 0; min-height: 0; padding: 10px; }
.viewer-img img { max-width: 100%; max-height: 100%; object-fit: contain; }
.viewer-side { display: flex; flex-direction: column; gap: 10px; padding: 10px 14px; background: var(--panel-solid); overflow-y: auto; -webkit-user-select: text; user-select: text; }
.viewer-top { display: flex; align-items: center; gap: 6px; }
.viewer-top b { flex: 1; font-size: 17px; font-weight: 600; text-align: center; }
#v-note { padding: 9px 12px; border-radius: 10px; background: var(--raise); border: 1px solid var(--line); }
#v-meta { display: grid; grid-template-columns: auto 1fr; gap: 4px 10px; margin: 0; font-size: 12px; }
#v-meta dt { color: var(--dim); }
#v-meta dd { margin: 0; overflow-wrap: anywhere; }
.viewer-actions { display: grid; gap: 8px; margin-top: auto; }
@media (orientation: portrait) {
  #viewer { grid-template-columns: 1fr; grid-template-rows: minmax(0, 1fr) auto; }
  .viewer-side { max-height: 52vh; }
}

/* Calibration */
#calib {
  position: fixed; z-index: 25; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--sab) + 10px); width: min(560px, calc(100vw - 20px));
  padding: 12px 14px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line);
  -webkit-user-select: text; user-select: text;
}
#calib h2 { margin: 0 0 4px; font-size: 16px; font-weight: 600; }
#calib .help { margin: 0 0 8px; font-size: 12.5px; }
.cal-fields { display: flex; gap: 12px; flex-wrap: wrap; margin-bottom: 8px; }
.cal-fields label { display: grid; gap: 3px; font-size: 12px; color: var(--dim); }
.cal-fields input { width: 70px; padding: 6px 8px; border-radius: 8px; background: var(--raise); border: 1px solid var(--line); color: var(--text); }
#cal-result { margin: 8px 0; font-size: 13px; }
.cal-actions { display: flex; gap: 6px; justify-content: flex-end; flex-wrap: wrap; }
.cal-actions button:not(.primary) { padding: 9px 12px; border-radius: 10px; background: var(--raise); border: 1px solid var(--line); }
@media (orientation: landscape) and (max-height: 500px) {
  #calib { left: auto; right: calc(var(--sar) + 10px); transform: none; top: calc(var(--sat) + 10px); bottom: calc(var(--sab) + 10px); width: min(330px, 42vw); overflow-y: auto; }
}

/* Démarrage */
#start {
  position: fixed; inset: 0; z-index: 40; display: grid; place-items: center;
  padding: max(16px, var(--sat)) max(16px, var(--sar)) max(16px, var(--sab)) max(16px, var(--sal));
  background:
    radial-gradient(120% 80% at 50% 120%, rgba(255, 190, 59, .10), transparent 60%),
    var(--ink);
}
.start-card { display: grid; justify-items: center; gap: 12px; max-width: 360px; text-align: center; }
.start-card h1 { margin: 0; font: 600 34px/1 var(--ui); letter-spacing: .32em; text-transform: uppercase; padding-left: .32em; }
.start-card p { margin: 0; color: var(--dim); line-height: 1.45; }
.mark {
  width: 120px; height: 52px; border: 1.5px solid var(--frame); border-radius: 2px; position: relative; margin-bottom: 6px;
}
.mark::before, .mark::after { content: ""; position: absolute; background: var(--accent); }
.mark::before { left: 50%; top: 50%; width: 16px; height: 1.5px; transform: translate(-50%, -50%); }
.mark::after { left: 50%; top: 50%; width: 1.5px; height: 16px; transform: translate(-50%, -50%); }
.mark span { position: absolute; inset: -7px -10px; border: 1px dashed rgba(246, 243, 234, .35); }
.big { padding: 13px 22px; font-size: 17px; border-radius: 12px; margin-top: 8px; }
.link { color: var(--dim); text-decoration: underline; text-underline-offset: 3px; padding: 6px; }

#toast {
  position: fixed; z-index: 50; left: 50%; bottom: calc(var(--sab) + 24px); transform: translate(-50%, 20px);
  max-width: min(90vw, 480px); padding: 9px 14px; border-radius: 10px;
  background: rgba(20, 22, 26, .94); border: 1px solid var(--line); font-size: 14px; text-align: center;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.on { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  #video, #freeze, .sheet, #toast { transition: none !important; }
}
