:root {
  --bg: #0b131b; --surface: #142130; --surface2: #1c2d40; --border: #263c53;
  --text: #e8eef5; --muted: #8fa3b8; --accent: #ffb020; --accent-ink: #1b1200;
  --ok: #35c27a; --ko: #ff5d5d; --radius: 12px;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 16px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 1.7rem; margin: 0 0 .4rem; }
h2 { font-size: 1.15rem; margin: 0 0 .6rem; }
h3 { font-size: 1.05rem; margin: 0; }
h4 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 1rem 0 .4rem; }
.lead { color: var(--muted); font-size: 1.05rem; max-width: 60ch; margin: 0 0 1.2rem; }
.muted { color: var(--muted); }
.small { font-size: .85rem; }
[hidden] { display: none !important; }

/* ---------- Structure ---------- */
.top {
  position: sticky; top: 0; z-index: 20; display: flex; align-items: center; gap: 1rem;
  padding: calc(.5rem + env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) .5rem max(1rem, env(safe-area-inset-left)); background: rgba(11, 19, 27, .92);
  backdrop-filter: blur(8px); border-bottom: 1px solid var(--border);
}
.brand { display: flex; align-items: center; gap: .55rem; font-weight: 700; white-space: nowrap; }
.brand svg { width: 26px; height: 26px; }
.top nav { display: flex; gap: .25rem; overflow-x: auto; margin-left: auto; min-width: 0; scrollbar-width: none; }
.top nav a { padding: .55rem .8rem; border-radius: 8px; color: var(--muted); font-weight: 600; white-space: nowrap; min-height: 44px; display: flex; align-items: center; }
.top nav a.on { color: var(--accent-ink); background: var(--accent); }
main { max-width: 1240px; margin: 0 auto; padding: 1.2rem max(1rem, env(safe-area-inset-right)) calc(4rem + env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left)); }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; margin: 0 0 1rem; }
.card.accent { border-color: #7a5a14; background: linear-gradient(180deg, #1d2a33, var(--surface)); }
.row { display: flex; flex-wrap: wrap; gap: .6rem; align-items: center; margin: .6rem 0 0; }
.row.tight { margin: 0; gap: .4rem; }
.row.between { justify-content: space-between; }
.row.end { justify-content: flex-end; }
.row:first-child { margin-top: 0; }
.form { display: grid; gap: .7rem; margin-bottom: .8rem; }
.form label, label.inline { display: flex; align-items: center; gap: .6rem; }
label.check { display: flex; align-items: flex-start; gap: .6rem; }
input[type=checkbox] { width: 22px; height: 22px; accent-color: var(--accent); flex: none; }

.btn {
  font: inherit; font-weight: 600; color: var(--text); background: var(--surface2); border: 1px solid var(--border);
  border-radius: 10px; padding: .6rem 1rem; min-height: 46px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: .4rem; touch-action: manipulation;
}
.btn:hover:not(:disabled) { border-color: #3b5a7a; }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: var(--accent); }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--ko); border-color: #5b2a2a; background: transparent; }
.btn.small { min-height: 36px; padding: .3rem .7rem; font-size: .9rem; }
input[type=text], input[type=number], input[type=search], input[type=email], input[type=password], select, textarea {
  font: inherit; color: var(--text); background: #0f1a26; border: 1px solid var(--border); border-radius: 8px; padding: .5rem .6rem; min-height: 42px;
}
textarea { width: 100%; resize: vertical; }
.num { width: 5.5rem; } .num.small { width: 4rem; min-height: 36px; }
.search { flex: 1; min-width: 12rem; } .setname { min-width: 15rem; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

.meter { display: inline-block; width: 64px; height: 8px; border-radius: 4px; background: #22354a; overflow: hidden; vertical-align: middle; }
.meter i { display: block; height: 100%; }
.badge { font-size: .72rem; font-weight: 700; padding: .1rem .45rem; border-radius: 6px; }
.badge.warn { background: #4a3810; color: var(--accent); }

/* ---------- Cadre photo ---------- */
.stage { position: relative; overflow: hidden; width: 100%; aspect-ratio: var(--ar, 1.4); background: #000; border-radius: 8px; }
.stage.big { width: min(100%, calc(var(--maxh, 62vh) * var(--ar))); margin-inline: auto; }
.stage.mid { width: min(100%, calc(38vh * var(--ar))); }
.stage-inner { position: absolute; inset: 0; width: 100%; height: 100%; }
.stage-inner img { width: 100%; height: 100%; display: block; user-select: none; -webkit-user-drag: none; }
.overlay, .stage-label { position: absolute; inset: 0; width: 100%; height: 100%; pointer-events: none; }
.overlay.editable { pointer-events: auto; touch-action: none; cursor: grab; }
.ring { fill: none; stroke: #fff; filter: drop-shadow(0 0 2px rgba(0, 0, 0, .55)); }
.ring.ok { stroke: var(--ok); } .ring.ko { stroke: var(--ko); }
.ring.editing { stroke: var(--accent); }
.handle { fill: var(--accent); stroke: #000; stroke-width: 2; cursor: ew-resize; }
.marker { stroke: #fff; fill: none; filter: drop-shadow(0 0 2px #000); }
.stage-label text { fill: #fff; font-weight: 800; font-family: 'Segoe UI', system-ui, sans-serif; paint-order: stroke; stroke: rgba(0, 0, 0, .35); stroke-width: 3px; }
.stage.tappable { cursor: crosshair; touch-action: manipulation; }
.stage.veil { --maxh: 16vh; background: repeating-linear-gradient(45deg, #101c28, #101c28 14px, #132233 14px, #132233 28px); display: grid; place-items: center; }
.stage.veil span { font-size: 4rem; font-weight: 800; color: #2e4761; }
.stage.editor { --maxh: 60vh; margin-inline: auto; width: min(100%, calc(60vh * var(--ar))); }

/* ---------- Feuille d'exercice ---------- */
.tabs { display: flex; gap: .4rem; margin: 1rem 0 .8rem; flex-wrap: wrap; }
.tab { font: inherit; font-weight: 600; color: var(--muted); background: transparent; border: 1px solid var(--border); border-radius: 999px; padding: .45rem 1rem; min-height: 42px; cursor: pointer; }
.tab.on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }
.tab small { opacity: .75; }
.sheet { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 330px), 1fr)); gap: .8rem; }
.sheet.small { grid-template-columns: repeat(auto-fill, minmax(min(100%, 230px), 1fr)); }
.tile { display: block; border-radius: 8px; transition: transform .12s; }
.tile:hover { transform: translateY(-2px); }

/* ---------- Etude ---------- */
.study { display: grid; grid-template-columns: minmax(0, 1.7fr) minmax(300px, 1fr); gap: 1.2rem; align-items: start; }
@media (max-width: 900px) { .study { grid-template-columns: minmax(0, 1fr); } }
.study-main, .study-side { min-width: 0; }
.study-head { display: flex; justify-content: space-between; align-items: center; gap: .6rem; margin-bottom: .6rem; flex-wrap: wrap; }
.study-main .stage.big { --maxh: 58vh; touch-action: pan-y; }
.study .nav { justify-content: center; margin: .8rem 0; }
.strip { display: flex; gap: .4rem; overflow-x: auto; padding-bottom: .4rem; }
.thumb { flex: none; width: 92px; padding: 0; border: 2px solid transparent; border-radius: 8px; background: none; cursor: pointer; opacity: .65; }
.thumb.on { border-color: var(--accent); opacity: 1; }
.timer .timer-row { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: .5rem; }
.clock { font-size: 2rem; font-weight: 700; font-variant-numeric: tabular-nums; }
.clock.late { color: var(--ko); }
.tag-group { margin-bottom: .5rem; }
.tag-title { font-size: .75rem; color: var(--muted); margin-bottom: .25rem; }
.chips { display: flex; flex-wrap: wrap; gap: .35rem; }
.chip { font: inherit; font-size: .9rem; color: var(--text); background: #0f1a26; border: 1px solid var(--border); border-radius: 999px; padding: .35rem .8rem; min-height: 38px; cursor: pointer; touch-action: manipulation; }
.chip.on { background: #3a2c09; border-color: var(--accent); color: var(--accent); }
.tag-add { display: flex; gap: .4rem; margin-top: .6rem; } .tag-input { flex: 1; }

/* ---------- Tests ---------- */
.trial-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: .6rem; }
.timebar { height: 6px; background: #22354a; border-radius: 3px; overflow: hidden; margin-bottom: .6rem; }
.timebar i { display: block; height: 100%; width: 100%; background: var(--accent); transition-property: width; transition-timing-function: linear; }
.viewer { min-height: 120px; margin-bottom: .8rem; }
.viewer .stage.big { --maxh: 50vh; }
.answers { display: grid; grid-template-columns: repeat(auto-fill, minmax(68px, 1fr)); gap: .5rem; margin-top: .4rem; }
.answers.thumbs { grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); }
.ans { position: relative; padding: 0; font: inherit; color: var(--text); background: var(--surface2); border: 2px solid var(--border); border-radius: 10px; min-height: 56px; cursor: pointer; overflow: hidden; touch-action: manipulation; }
.ans:hover { border-color: var(--accent); }
.ans b { font-size: 1.3rem; }
.answers.thumbs .ans b { position: absolute; left: 6px; top: 4px; text-shadow: 0 0 4px #000, 0 0 2px #000; font-size: 1.25rem; }
.answers.thumbs .ans .stage { border-radius: 0; }
.ans.none { grid-column: span 2; min-height: 56px; }
.answers.thumbs .ans.none b { position: static; text-shadow: none; font-size: 1rem; }
.verdict { display: flex; align-items: baseline; gap: .5rem; font-size: 1.3rem; font-weight: 700; margin: .4rem 0 .6rem; }
.verdict.ok { color: var(--ok); } .verdict.ko { color: var(--ko); }
.reveal { display: flex; gap: 1rem; justify-content: center; flex-wrap: wrap; }
.reveal figure { margin: 0; text-align: center; flex: 1 1 260px; max-width: 520px; }
.reveal figcaption { margin-top: .4rem; color: var(--muted); }
.errors { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 420px), 1fr)); gap: 1rem; }
.err { display: grid; grid-template-columns: 1fr auto 1fr; gap: .6rem; align-items: center; }
.arrow { color: var(--muted); font-size: .8rem; text-align: center; max-width: 5rem; }
.score .big-num { font-size: 3rem; font-weight: 800; line-height: 1.1; }
.score .big-num span { font-size: 1.4rem; color: var(--accent); margin-left: 1rem; }

/* ---------- Banque, stats ---------- */
.bank-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(min(100%, 250px), 1fr)); gap: .8rem; margin-top: .8rem; }
.bank-card { font: inherit; color: var(--text); text-align: left; padding: .4rem; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; cursor: pointer; }
.bank-card:hover { border-color: var(--accent); }
.bank-meta { display: flex; align-items: center; justify-content: space-between; gap: .4rem; padding: .4rem .2rem .1rem; font-size: .85rem; color: var(--muted); }
.filters { margin: 1rem 0 0; }
.weak-meta { display: flex; justify-content: space-between; align-items: center; padding: .3rem .1rem 0; }
.table { width: 100%; border-collapse: collapse; }
.table th, .table td { text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--border); }
.table th { color: var(--muted); font-size: .8rem; font-weight: 600; }

/* ---------- Fenetres, notifications ---------- */
.modal-back { position: fixed; inset: 0; z-index: 50; background: rgba(3, 8, 13, .8); display: grid; place-items: center; padding: 1rem; overflow: auto; }
.modal { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 1.1rem; width: min(100%, 560px); max-height: 94vh; overflow: auto; }
.modal.wide { width: min(100%, 820px); }
.review > * + * { margin-top: .7rem; }
#toast { position: fixed; left: 50%; bottom: 1.2rem; transform: translate(-50%, 30px); opacity: 0; transition: .25s; background: #22384f; color: var(--text); padding: .7rem 1.1rem; border-radius: 10px; border: 1px solid var(--border); z-index: 99; pointer-events: none; max-width: 90vw; }
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Impression : planche comme en epreuve ---------- */
@media print {
  body { background: #fff; color: #000; }
  .top, .modes, .tabs, #toast { display: none !important; }
  main { padding: 0; max-width: none; }
  .sheet { grid-template-columns: repeat(2, 1fr); gap: 6px; }
  .tile { break-inside: avoid; }
  h1 { font-size: 1.1rem; }
}

/* ---------- Noms de photos ---------- */
.stage-name { position: absolute; left: 8px; top: 8px; max-width: calc(100% - 16px); padding: .1rem .55rem; border-radius: 8px; background: rgba(11, 19, 27, .8); color: #fff; font-weight: 700; font-size: clamp(.62rem, 1.5vw, 1rem); line-height: 1.35; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; pointer-events: none; }
.stage.big .stage-name { top: 12px; left: 12px; font-size: 1.1rem; padding: .2rem .7rem; }
.name-input { width: 100%; }
.name-warn { color: var(--accent); min-height: 1.3em; margin-top: .25rem; }
.answers.thumbs .ans b { font-size: .85rem; max-width: calc(100% - 10px); background: rgba(0, 0, 0, .6); padding: .05rem .45rem; border-radius: 6px; line-height: 1.3; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-shadow: none; }
.answers.names { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
.answers.names .ans { padding: .5rem .7rem; min-height: 52px; }
.answers.names .ans b { font-size: 1rem; }
.bank-name { color: var(--text); font-weight: 600; }

/* ---------- Identique ou modifiee ---------- */
.ring.zone { stroke: var(--accent); stroke-dasharray: 16 9; }
.decide { display: flex; gap: 1rem; margin-top: .5rem; }
.btn.big-choice { flex: 1; min-height: 66px; font-size: 1.25rem; }
.fig { margin: 0; }
.fig figcaption { color: var(--muted); font-size: .85rem; margin-top: .3rem; }

/* ---------- Classement des photos (derniere page de l'etude) ---------- */
.order-list { display: grid; gap: .5rem; margin: .4rem 0 1rem; }
.order-row { display: grid; grid-template-columns: auto 132px 1fr auto; gap: .7rem; align-items: center; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: .4rem .6rem .4rem .3rem; }
.order-row.shiftable { transition: transform .12s; }
.order-row.dragging { position: relative; z-index: 5; border-color: var(--accent); background: var(--surface2); box-shadow: 0 6px 18px rgba(0, 0, 0, .5); }
.order-handle { font-size: 1.7rem; line-height: 1; color: var(--muted); background: none; border: 0; padding: .3rem .55rem; min-width: 46px; min-height: 52px; cursor: grab; touch-action: none; }
.order-num { font-weight: 800; font-size: 1.3rem; color: var(--accent); text-align: center; }
.order-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.thumb.order-tile { display: grid; place-items: center; min-height: 62px; font: inherit; font-weight: 700; color: var(--accent); background: var(--surface2); border: 2px solid var(--border); }
.thumb.order-tile.on { border-color: var(--accent); }
@media (max-width: 520px) { .order-row { grid-template-columns: auto 96px 1fr; } .order-row > .row { grid-column: 1 / -1; justify-content: flex-end; } }

/* ---------- Objets identifies sur la photo ---------- */
.obj-pin { position: absolute; width: 14px; height: 14px; border-radius: 50%; background: var(--accent); border: 2px solid #000; transform: translate(-50%, -50%); pointer-events: none; box-shadow: 0 0 0 2px rgba(255, 255, 255, .7); }
.obj-tag { position: absolute; left: 14px; top: -10px; white-space: nowrap; background: rgba(11, 19, 27, .88); color: #fff; font-size: .78rem; font-weight: 600; padding: .05rem .45rem; border-radius: 6px; }
.stage.big .obj-tag { font-size: .95rem; padding: .1rem .55rem; }
.placing { display: flex; align-items: center; justify-content: space-between; gap: .6rem; background: #3a2c09; border: 1px solid var(--accent); color: var(--accent); border-radius: 10px; padding: .4rem .7rem; margin-bottom: .6rem; font-weight: 600; }
.objects { margin-bottom: .6rem; }
.obj-list { display: grid; gap: .35rem; margin-top: .6rem; }
.obj-row { display: grid; grid-template-columns: 1fr auto auto auto; gap: .4rem; align-items: center; background: #0f1a26; border: 1px solid var(--border); border-radius: 8px; padding: .3rem .5rem; }
.obj-row.active { border-color: var(--accent); }
.obj-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; }
.obj-state.ok { color: var(--ok); } .obj-state.ko { color: var(--ko); } .obj-state.todo { color: var(--accent); }
.obj-ring { position: absolute; aspect-ratio: 1; border: 2px dashed var(--accent); border-radius: 50%; transform: translate(-50%, -50%); pointer-events: none; }

/* ---------- Banque de types d'objet, objet principal ---------- */
.chip-group { display: inline-flex; align-items: stretch; }
.chip-group .chip { border-top-right-radius: 0; border-bottom-right-radius: 0; }
.chip-x { font: inherit; color: var(--muted); background: #0f1a26; border: 1px solid var(--border); border-left: 0; border-radius: 0 999px 999px 0; padding: 0 .6rem; min-height: 38px; cursor: pointer; }
.chip-x:hover { color: var(--ko); }
.main-check { font-size: .9rem; color: var(--muted); margin-bottom: .5rem; }
.name-input:disabled { opacity: .7; }
.obj-row { grid-template-columns: 1fr auto auto; row-gap: .1rem; }
.obj-row .obj-name { grid-column: 1; grid-row: 1; }
.obj-row .obj-state { grid-column: 1 / -1; grid-row: 2; }
.obj-row .btn:nth-of-type(1) { grid-column: 2; grid-row: 1; }
.obj-row .btn:nth-of-type(2) { grid-column: 3; grid-row: 1; }

/* ---------- Compte / synchronisation ---------- */
#acct { display: flex; align-items: center; flex: none; }
.acct {
  font: inherit; font-size: .85rem; font-weight: 600; color: var(--muted); background: transparent; border: 1px solid var(--border);
  border-radius: 999px; padding: .35rem .8rem; min-height: 40px; display: inline-flex; align-items: center; gap: .5rem; cursor: pointer; white-space: nowrap;
  touch-action: manipulation;
}
.acct:hover { border-color: #3b5a7a; color: var(--text); }
.dot { width: 9px; height: 9px; border-radius: 50%; background: var(--muted); flex: none; }
.dot.idle { background: var(--ok); }
.dot.syncing { background: var(--accent); animation: pulse 1s ease-in-out infinite; }
.dot.offline { background: transparent; border: 2px solid var(--muted); }
.dot.loggedout, .dot.error { background: var(--ko); }
@keyframes pulse { 50% { opacity: .3; } }
.login-wrap { max-width: 420px; margin: 7vh auto 0; text-align: center; }
.login-wrap .card, .login-wrap .lead { text-align: left; margin-inline: auto; }
.logo-big svg { width: 64px; height: 64px; }
.form.login input { width: 100%; }
.form-error { color: var(--ko); margin: 0; font-size: .92rem; }
.form-error:empty { display: none; }
progress.bar { width: 100%; height: 10px; accent-color: var(--accent); }
.acct-pw { margin: .8rem 0; }
.acct-pw summary { cursor: pointer; padding: .4rem 0; }
.modal input[type=password] { width: 100%; }
@media (max-width: 700px) { .top { flex-wrap: wrap; gap: .4rem .8rem; } .top nav { margin-left: 0; order: 3; width: 100%; } #acct { margin-left: auto; } }
