/* FreeSnap : deux thèmes sur les mêmes composants.
   "menthe" (par défaut) : aplats de couleur, formes rondes.
   "sticker" : contours noirs épais, ombres dures, éléments inclinés.
   La couleur d'accent (--accent) est posée par app.js selon le choix de la personne. */

:root {
  --accent: #2BEFA0;
  --ink: #0B1F18;
  --bg: #FFFFFF;
  --muted: #4B5A54;
  --line: #D5DDD9;
  --dark: #0F1916;
  --cam: #1E2D28;
  --danger: #B3261E;
  --tint: color-mix(in srgb, var(--accent) 18%, #FFFFFF);
  --font: ui-rounded, "SF Pro Rounded", "Outfit", "Nunito", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r-btn: 24px;
  --r-card: 20px;
  --r-field: 16px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}

[data-theme="sticker"] {
  --ink: #111111;
  --muted: #3D3D3D;
  --line: #111111;
  --dark: #111111;
  --cam: #2B2522;
  --tint: #FFFFFF;
  --font: "Bricolage Grotesque", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --r-btn: 14px;
  --r-card: 14px;
  --r-field: 14px;
}

*, *::before, *::after { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: var(--font);
  color: var(--ink);
  background: var(--cam);
  overflow: hidden;
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  touch-action: manipulation;
  -webkit-user-select: none; user-select: none;
}
input, .linkbox, .code { -webkit-user-select: text; user-select: text; }
button, input { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3, p { margin: 0; }
[hidden] { display: none !important; }
:focus-visible { outline: 3px solid var(--ink); outline-offset: 3px; }
.dark :focus-visible { outline-color: #FFFFFF; }
.visually-hidden { position: absolute; width: 1px; height: 1px; opacity: 0; overflow: hidden; pointer-events: none; }

.ico { display: inline-flex; }
.ico svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
[data-theme="sticker"] .ico svg { stroke-width: 2.5; }

#app { position: fixed; inset: 0; overflow: hidden; }

/* ---------- boutons et champs ---------- */

.round {
  width: 48px; height: 48px; flex: none;
  border-radius: var(--r-btn);
  background: var(--dark); color: #FFFFFF;
  display: inline-flex; align-items: center; justify-content: center;
}
.round.on { background: var(--accent); color: var(--ink); }
[data-theme="sticker"] .round {
  background: #FFFFFF; color: var(--ink);
  border: 2.5px solid var(--ink); box-shadow: 3px 3px 0 var(--ink);
}
[data-theme="sticker"] .round.on { background: var(--accent); }

.primary, .ghost {
  min-height: 54px; padding: 0 22px;
  border-radius: 27px;
  font-size: 17px; font-weight: 800;
  display: inline-flex; align-items: center; justify-content: center; gap: 10px;
}
.primary { background: var(--accent); color: var(--ink); }
.primary:disabled { background: var(--line); color: var(--muted); }
.ghost { background: var(--bg); color: var(--ink); border: 2px solid var(--ink); }
.ghost.danger { color: var(--danger); border-color: var(--danger); }
.small { min-height: 44px; padding: 0 16px; font-size: 15px; border-radius: 22px; }
.wide { width: 100%; }
[data-theme="sticker"] .primary, [data-theme="sticker"] .ghost {
  border: 2.5px solid var(--ink); border-radius: var(--r-btn); box-shadow: 3px 3px 0 var(--ink);
}
[data-theme="sticker"] .primary:disabled { background: #E6E6E6; box-shadow: none; }
[data-theme="sticker"] .ghost.danger { border-color: var(--danger); box-shadow: 3px 3px 0 var(--danger); }

.field {
  width: 100%; height: 54px; padding: 0 16px;
  border: 2px solid var(--ink); border-radius: var(--r-field);
  background: #FFFFFF; color: var(--ink); font-size: 17px;
}
[data-theme="sticker"] .field { border-width: 2.5px; }
.field::placeholder { color: var(--muted); opacity: 1; }
label.lbl, p.lbl { font-size: 14px; font-weight: 700; color: var(--muted); }

/* ---------- écrans principaux ---------- */

.view { position: absolute; inset: 0; display: none; flex-direction: column; }
.view.active { display: flex; }
.scroll { overflow-y: auto; -webkit-overflow-scrolling: touch; background: var(--bg); padding-bottom: calc(110px + var(--sab)); }

.tabbar {
  position: absolute; z-index: 5;
  left: 20px; right: 20px; bottom: calc(16px + var(--sab));
  display: flex; gap: 6px; padding: 6px;
  border-radius: 32px; background: var(--dark);
}
.tabbar button {
  position: relative; flex: 1; height: 52px; border-radius: 26px;
  color: #FFFFFF; font-size: 15px; font-weight: 600;
  display: flex; align-items: center; justify-content: center; gap: 8px;
}
.tabbar .ico svg { width: 20px; height: 20px; }
.tabbar button[aria-current="page"] { background: var(--accent); color: var(--ink); font-weight: 800; }
.tabbar button[aria-current="page"] .pip { display: none; }
.tabbar .pip {
  position: absolute; top: 8px; right: 14px; width: 10px; height: 10px;
  border-radius: 5px; background: var(--accent); border: 2px solid var(--dark);
}
[data-theme="sticker"] .tabbar {
  right: 24px; background: #FFFFFF; border: 2.5px solid var(--ink);
  border-radius: 18px; box-shadow: 4px 4px 0 var(--ink);
}
[data-theme="sticker"] .tabbar button { height: 50px; border-radius: 12px; color: var(--ink); border: 2.5px solid transparent; font-weight: 500; }
[data-theme="sticker"] .tabbar button[aria-current="page"] { border-color: var(--ink); font-weight: 800; }
[data-theme="sticker"] .tabbar .pip { background: var(--ink); border-color: #FFFFFF; }

/* ---------- caméra ---------- */

#view-camera { background: var(--cam); color: #FFFFFF; }
#cam { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; background: var(--cam); }
#cam.mirror { transform: scaleX(-1); }
.flash-fx { position: absolute; inset: 0; background: #FFFFFF; opacity: 0; pointer-events: none; transition: opacity .15s; }
.flash .flash-fx { opacity: .8; transition: none; }

.cam-top {
  position: absolute; z-index: 2; top: calc(16px + var(--sat)); left: 20px; right: 20px;
  display: flex; justify-content: space-between; align-items: flex-start;
}
[data-theme="sticker"] .cam-top { right: 24px; }
.wordmark {
  height: 48px; padding: 0 20px; display: flex; align-items: center;
  border-radius: 24px; background: var(--accent); color: var(--ink);
  font-weight: 800; font-size: 19px; letter-spacing: -0.01em;
}
[data-theme="sticker"] .wordmark {
  border: 2.5px solid var(--ink); border-radius: 14px; box-shadow: 3px 3px 0 var(--ink);
  transform: rotate(-3deg); font-size: 21px; letter-spacing: -0.02em; padding: 0 16px;
}
.cam-tools { display: flex; flex-direction: column; gap: 12px; }

.cam-bottom {
  position: absolute; z-index: 2; left: 20px; right: 20px;
  bottom: calc(16px + var(--sab) + 64px + 20px);
  display: flex; flex-direction: column; align-items: center; gap: 14px;
}
.hint, .target {
  padding: 7px 14px; border-radius: 18px;
  background: var(--dark); color: #FFFFFF; font-size: 14px; font-weight: 600;
}
.target { display: inline-flex; align-items: center; gap: 6px; background: var(--accent); color: var(--ink); font-weight: 800; padding: 0 4px 0 14px; }
.target button { width: 44px; height: 44px; display: inline-flex; align-items: center; justify-content: center; }
.target .ico svg { width: 18px; height: 18px; }
[data-theme="sticker"] .hint, [data-theme="sticker"] .target {
  border: 2.5px solid var(--ink); border-radius: 10px; font-weight: 800;
}
[data-theme="sticker"] .hint { background: #FFFFFF; color: var(--ink); transform: rotate(2deg); }

.shutter-row { width: 100%; display: grid; grid-template-columns: 1fr auto 1fr; align-items: center; }
.shutter-row > :first-child { justify-self: end; margin-right: 28px; }
.shutter {
  position: relative; width: 88px; height: 88px; border-radius: 50%;
  border: 6px solid #FFFFFF; background: var(--accent);
  touch-action: none; user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  transition: transform .15s;
}
[data-theme="sticker"] .shutter { width: 84px; height: 84px; border: 4px solid var(--ink); box-shadow: 0 0 0 5px #FFFFFF; }
.shutter .ring { position: absolute; inset: -16px; width: calc(100% + 32px); height: calc(100% + 32px); transform: rotate(-90deg); opacity: 0; pointer-events: none; }
.shutter .ring circle { fill: none; stroke: #FF5A5A; stroke-width: 6; stroke-linecap: round; stroke-dasharray: 327; stroke-dashoffset: 327; }
.recording .shutter { transform: scale(1.1); background: #FF5A5A; }
.recording .shutter .ring { opacity: 1; }
.recording .shutter .ring circle { animation: rec var(--rec-ms, 30000ms) linear forwards; }
@keyframes rec { to { stroke-dashoffset: 0; } }
.recording .tabbar, .recording .cam-top, .recording .shutter-row > :first-child, .recording .hint, .recording .target { visibility: hidden; }

.cam-fallback {
  position: absolute; inset: 0; display: none; flex-direction: column;
  align-items: center; justify-content: center; gap: 18px; padding: 0 36px; text-align: center;
}
.cam-fallback p { font-size: 16px; line-height: 1.4; color: #E4EBE8; }
.no-cam .cam-fallback { display: flex; }
.no-cam #cam, .no-cam .shutter, .no-cam .hint { display: none; }
.no-cam .shutter-row { display: flex; justify-content: center; }
.no-cam .shutter-row > :first-child { margin: 0; }

/* ---------- amis et stories ---------- */

.head {
  padding: calc(16px + var(--sat)) 20px 18px;
  display: flex; justify-content: space-between; align-items: center; gap: 12px;
  border-radius: 0 0 28px 28px; background: var(--accent);
}
.head h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; line-height: 48px; }
.head .actions { display: flex; gap: 10px; }
.head .round { background: var(--ink); }
[data-theme="sticker"] .head { background: transparent; border-radius: 0; padding-right: 24px; }
[data-theme="sticker"] .head h1 {
  padding: 0 12px; border: 2.5px solid var(--ink); border-radius: 14px;
  background: var(--accent); box-shadow: 3px 3px 0 var(--ink); transform: rotate(-2deg); letter-spacing: -0.03em;
}
[data-theme="sticker"] .head .round { background: #FFFFFF; }
[data-theme="sticker"] .head .actions { gap: 12px; }

.section-title { padding: 18px 20px 0; font-size: 14px; font-weight: 700; color: var(--muted); }
[data-theme="sticker"] .section-title { font-size: 15px; font-weight: 800; color: var(--ink); }

.strip { display: flex; gap: 14px; padding: 10px 20px 6px; overflow-x: auto; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.chip { flex: none; width: 64px; display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; }
.chip .bubble {
  width: 60px; height: 60px; border-radius: 30px;
  display: flex; align-items: center; justify-content: center;
  font-size: 20px; font-weight: 800;
  border: 4px solid var(--line); background: #EEF2F0; color: var(--ink);
}
.chip.unseen .bubble { border-color: var(--accent); background: var(--ink); color: #FFFFFF; }
.chip.add .bubble { border: 2px dashed var(--ink); background: var(--bg); }
.chip span.name { max-width: 64px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
[data-theme="sticker"] .chip .bubble { border: 2.5px solid var(--ink); background: #FFFFFF; font-size: 22px; }
[data-theme="sticker"] .chip.unseen .bubble { background: var(--accent); color: var(--ink); box-shadow: 3px 3px 0 var(--ink); }
[data-theme="sticker"] .chip.add .bubble { border-style: dashed; }

.list { display: flex; flex-direction: column; padding: 8px 12px; }
.row {
  min-height: 68px; padding: 8px; text-align: left; width: 100%;
  display: flex; align-items: center; gap: 14px; border-radius: var(--r-card);
}
.row .avatar {
  width: 48px; height: 48px; flex: none; border-radius: 24px; background: var(--tint);
  display: flex; align-items: center; justify-content: center; font-size: 18px; font-weight: 800;
}
.row .body { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row .name { font-size: 17px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row .status { display: flex; align-items: center; gap: 8px; font-size: 14px; color: var(--muted); }
.row .dot { width: 14px; height: 14px; flex: none; border-radius: 4px; border: 2px solid var(--muted); }
.row.new .name { font-weight: 800; }
.row.new .status { color: var(--ink); font-weight: 700; }
.row.new .dot { border-color: var(--ink); background: var(--accent); }
.row .ico { color: var(--muted); }
[data-theme="sticker"] .list { gap: 10px; padding: 12px 24px 12px 20px; }
[data-theme="sticker"] .row { min-height: 60px; padding: 6px 14px 6px 10px; border: 2.5px solid var(--ink); background: #FFFFFF; gap: 12px; }
[data-theme="sticker"] .row.new { background: var(--accent); box-shadow: 3px 3px 0 var(--ink); }
[data-theme="sticker"] .row .avatar { width: 40px; height: 40px; border: 2.5px solid var(--ink); background: #FFFFFF; }
[data-theme="sticker"] .row .name { font-size: 18px; font-weight: 800; }
[data-theme="sticker"] .row .status { color: var(--ink); font-weight: 500; }
[data-theme="sticker"] .row .dot { border-color: var(--ink); border-radius: 7px; }
[data-theme="sticker"] .row.new .dot { background: var(--ink); }

.empty { padding: 28px 28px; display: flex; flex-direction: column; align-items: center; gap: 16px; text-align: center; color: var(--muted); font-size: 16px; line-height: 1.45; }
.banner {
  margin: 14px 20px 0; padding: 14px 16px; border-radius: var(--r-card);
  background: var(--tint); display: flex; flex-direction: column; gap: 10px; font-size: 15px; line-height: 1.4;
}
[data-theme="sticker"] .banner { border: 2.5px solid var(--ink); margin-right: 24px; }
.banner .line { display: flex; gap: 10px; flex-wrap: wrap; }
.page-body .banner { margin: 0; }

/* ---------- superpositions ---------- */

.overlay { position: absolute; inset: 0; z-index: 20; display: none; flex-direction: column; }
.overlay.open { display: flex; }
.overlay.dark { background: #000000; color: #FFFFFF; }
.media { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000000; }
.media.cover { object-fit: cover; }

.pv-top { position: absolute; z-index: 2; top: calc(16px + var(--sat)); left: 20px; }
.pv-bottom {
  position: absolute; z-index: 2; left: 20px; right: 20px; bottom: calc(20px + var(--sab));
  display: flex; flex-direction: column; gap: 12px;
}
[data-theme="sticker"] .pv-bottom { right: 24px; }
.caption-input {
  width: 100%; height: 50px; padding: 0 16px; border: 0; border-radius: 16px;
  background: rgba(0, 0, 0, .72); color: #FFFFFF; font-size: 17px; text-align: center;
}
.caption-input::placeholder { color: #D6DDDA; opacity: 1; }
.pv-actions { display: flex; gap: 10px; align-items: center; }
.pv-actions .primary { flex: 1; min-width: 0; }
.pv-actions .primary span.lbl { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.sheet {
  position: absolute; z-index: 5; left: 0; right: 0; bottom: 0; max-height: 78%;
  display: none; flex-direction: column; gap: 14px;
  padding: 20px 20px calc(20px + var(--sab));
  border-radius: 28px 28px 0 0; background: var(--bg); color: var(--ink);
}
.sheet.open { display: flex; }
[data-theme="sticker"] .sheet { border: 2.5px solid var(--ink); border-bottom: 0; border-radius: 18px 18px 0 0; padding-right: 24px; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; }
.sheet-head h2 { font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
.sheet-head .round { background: var(--ink); }
[data-theme="sticker"] .sheet-head .round { background: #FFFFFF; }
.sheet .list { padding: 0; overflow-y: auto; }
[data-theme="sticker"] .sheet .list { padding: 2px 4px 4px 0; }
.pick { cursor: pointer; }
.pick input { position: absolute; opacity: 0; width: 1px; height: 1px; }
.pick .box {
  width: 28px; height: 28px; flex: none; border-radius: 14px; border: 2px solid var(--ink);
  display: flex; align-items: center; justify-content: center; color: transparent;
}
.pick .box svg { width: 18px; height: 18px; stroke-width: 3; }
.pick input:checked ~ .box { background: var(--accent); color: var(--ink); }
.pick input:focus-visible ~ .box { outline: 3px solid var(--ink); outline-offset: 3px; }
[data-theme="sticker"] .pick .box { border-width: 2.5px; border-radius: 8px; }

/* visionneuse */
.vw-progress { position: absolute; z-index: 3; top: calc(10px + var(--sat)); left: 12px; right: 12px; display: flex; gap: 4px; }
.vw-progress .seg { flex: 1; height: 4px; border-radius: 2px; background: rgba(255, 255, 255, .35); overflow: hidden; }
.vw-progress .seg i { display: block; height: 100%; width: 0; background: #FFFFFF; }
.vw-head {
  position: absolute; z-index: 3; top: calc(24px + var(--sat)); left: 16px; right: 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.vw-who { display: flex; flex-direction: column; padding: 6px 12px; border-radius: 14px; background: rgba(0, 0, 0, .6); }
.vw-who b { font-size: 16px; font-weight: 800; }
.vw-who span { font-size: 13px; color: #E4EBE8; }
.vw-caption {
  position: absolute; z-index: 3; left: 0; right: 0; bottom: 22%;
  padding: 10px 16px; background: rgba(0, 0, 0, .72); text-align: center; font-size: 18px; font-weight: 600; line-height: 1.3;
  overflow-wrap: anywhere;
}
.vw-foot {
  position: absolute; z-index: 3; left: 16px; right: 16px; bottom: calc(20px + var(--sab));
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.vw-foot p { padding: 8px 12px; border-radius: 14px; background: rgba(0, 0, 0, .6); font-size: 14px; line-height: 1.35; }
.vw-sound { position: absolute; z-index: 3; left: 50%; bottom: calc(96px + var(--sab)); transform: translateX(-50%); display: none; }
.muted .vw-sound { display: inline-flex; }
.spinner {
  position: absolute; z-index: 2; top: 50%; left: 50%; width: 44px; height: 44px; margin: -22px 0 0 -22px;
  border-radius: 50%; border: 4px solid rgba(255, 255, 255, .3); border-top-color: #FFFFFF; display: none;
}
.loading .spinner { display: block; animation: spin 0.8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@media (prefers-reduced-motion: reduce) { .loading .spinner { animation-duration: 2.4s; } }

/* réglages */
.page { background: var(--bg); overflow-y: auto; -webkit-overflow-scrolling: touch; }
.page .head { position: sticky; top: 0; z-index: 2; }
[data-theme="sticker"] .page .head { background: var(--bg); }
.page-body { padding: 8px 20px calc(40px + var(--sab)); display: flex; flex-direction: column; gap: 28px; }
[data-theme="sticker"] .page-body { padding-right: 24px; }
.block { display: flex; flex-direction: column; gap: 12px; }
.block h2 { font-size: 20px; font-weight: 800; letter-spacing: -0.01em; }
.block p { font-size: 15px; line-height: 1.45; color: var(--muted); }
.block .line { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.block .line .field { flex: 1; min-width: 0; }
.segmented { display: flex; gap: 6px; padding: 6px; border-radius: 28px; background: var(--tint); }
.segmented button { flex: 1; min-height: 44px; border-radius: 22px; font-size: 16px; font-weight: 600; }
.segmented button[aria-pressed="true"] { background: var(--ink); color: #FFFFFF; font-weight: 800; }
[data-theme="sticker"] .segmented { border: 2.5px solid var(--ink); border-radius: 14px; }
[data-theme="sticker"] .segmented button { border-radius: 8px; }
.swatches { display: flex; flex-wrap: wrap; gap: 12px; }
.swatch { width: 48px; height: 48px; border-radius: 24px; border: 2px solid var(--ink); display: flex; align-items: center; justify-content: center; color: transparent; }
.swatch[aria-pressed="true"] { color: var(--ink); box-shadow: 0 0 0 3px var(--bg), 0 0 0 6px var(--ink); }
.swatch svg { stroke-width: 3; }
[data-theme="sticker"] .swatch { border-width: 2.5px; border-radius: 12px; }
.code { font-size: 30px; font-weight: 800; letter-spacing: 0.12em; font-variant-numeric: tabular-nums; }
.linkbox { width: 100%; padding: 12px 14px; border-radius: var(--r-field); border: 2px dashed var(--ink); font-size: 14px; overflow-wrap: anywhere; }
.member { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; padding: 10px 0; border-top: 1px solid var(--line); }
.member b { flex-basis: 100%; font-size: 17px; }
.about { font-size: 13px; color: var(--muted); }

/* accueil (invitation / connexion) */
.gate {
  position: absolute; inset: 0; overflow-y: auto; background: var(--accent); color: var(--ink);
  display: flex; flex-direction: column; justify-content: center; gap: 20px;
  padding: calc(32px + var(--sat)) 24px calc(32px + var(--sab));
}
.gate .logo { align-self: flex-start; height: 56px; padding: 0 22px; display: flex; align-items: center; border-radius: 28px; background: var(--ink); color: #FFFFFF; font-size: 24px; font-weight: 800; letter-spacing: -0.02em; }
[data-theme="sticker"] .gate .logo { background: #FFFFFF; color: var(--ink); border: 2.5px solid var(--ink); border-radius: 14px; box-shadow: 4px 4px 0 var(--ink); transform: rotate(-3deg); }
.gate h1 { font-size: 34px; font-weight: 800; letter-spacing: -0.02em; line-height: 1.1; }
.gate p { font-size: 17px; line-height: 1.45; }
.gate form { display: flex; flex-direction: column; gap: 12px; }
.gate .primary { background: var(--ink); color: #FFFFFF; }
[data-theme="sticker"] .gate .primary { background: #FFFFFF; color: var(--ink); }
.gate .err { font-weight: 700; }

.toast {
  position: absolute; z-index: 50; left: 50%; top: calc(76px + var(--sat)); transform: translateX(-50%);
  max-width: calc(100% - 40px); padding: 12px 18px; border-radius: 22px;
  background: var(--dark); color: #FFFFFF; font-size: 15px; font-weight: 600; text-align: center;
  border: 2px solid #FFFFFF;
}
[data-theme="sticker"] .toast { border-radius: 12px; }
