:root {
  --bg: #17111a;
  --surface: #221a26;
  --surface-2: #2d2332;
  --line: #3a2e40;
  --text: #f4eaf0;
  --muted: #a898ad;
  --cream: #f6ecdf;
  --ink: #2a1c22;
  --coral: #ff6b5e;
  --coral-ink: #2b0d0a;
  --wine: #8f1c40;
  --wine-deep: #4d0f2a;
  --gold: #e8b86d;
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --radius: 22px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
[hidden] { display: none !important; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.45;
  overscroll-behavior: none;
}

button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
h1, h2, h3, p { margin: 0; }

#app {
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) 0 env(safe-area-inset-left);
}

.icon { display: inline-flex; width: 22px; height: 22px; flex: none; }
.icon svg { width: 100%; height: 100%; }

/* ---------- boutons & champs ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 52px;
  padding: 0 22px;
  border-radius: 999px;
  font-weight: 650;
  transition: transform .12s, opacity .12s;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; }
.btn.primary { background: var(--coral); color: var(--coral-ink); }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.small { min-height: 40px; padding: 0 14px; font-size: 14px; }
.btn.small .icon { width: 18px; height: 18px; }
.btn.danger { color: #ff9a90; }

.icon-btn {
  width: 44px;
  height: 44px;
  display: grid;
  place-items: center;
  border-radius: 50%;
  color: var(--muted);
  flex: none;
}
.icon-btn:active { background: var(--surface-2); }

input[type="text"], input[type="password"], textarea {
  width: 100%;
  background: var(--surface);
  border: 1.500px solid var(--line);
  border-radius: 16px;
  padding: 14px 16px;
  outline: none;
  resize: none;
}
input[type="text"]:focus, input[type="password"]:focus, textarea:focus { border-color: var(--coral); }
::placeholder { color: var(--muted); }
:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }

.switch {
  appearance: none;
  width: 48px;
  height: 28px;
  border-radius: 999px;
  background: var(--line);
  position: relative;
  flex: none;
  margin: 0;
  cursor: pointer;
  transition: background .15s;
}
.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: var(--cream);
  transition: transform .15s;
}
.switch:checked { background: var(--wine); }
.switch:checked::after { transform: translateX(20px); }

.tag {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  padding: 4px 10px 4px 6px;
  border-radius: 999px;
  background: rgba(232, 184, 109, .18);
  color: var(--gold);
  font-size: 12px;
  font-weight: 700;
  letter-spacing: .04em;
  text-transform: uppercase;
}
.tag .icon { width: 15px; height: 15px; }

.fine { color: var(--muted); font-size: 13px; text-align: center; }

/* ---------- arrivée ---------- */

.onboard {
  flex: 1;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 36px;
  padding: 24px 24px calc(24px + env(safe-area-inset-bottom));
}
.onboard-hero { text-align: center; }
.onboard-logo { width: 96px; height: 96px; border-radius: 24px; }
.onboard-hero h1 { font-family: var(--serif); font-size: 40px; margin: 16px 0 10px; letter-spacing: -.01em; }
.onboard-hero p { color: var(--muted); text-wrap: balance; }
.onboard-form { display: flex; flex-direction: column; gap: 12px; }
.code-input { text-transform: uppercase; letter-spacing: .3em; text-align: center; font-weight: 700; }
.code-input::placeholder { letter-spacing: 0; font-weight: 400; text-transform: none; }

/* ---------- coquille ---------- */

.top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 10px 6px 20px;
}
.brand { display: flex; flex-direction: column; min-width: 0; }
.brand strong { font-family: var(--serif); font-size: 22px; line-height: 1.1; }
.brand span { color: var(--muted); font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.view { flex: 1; min-height: 0; overflow-y: auto; display: flex; flex-direction: column; }

.tabs {
  display: flex;
  border-top: 1px solid var(--line);
  background: var(--bg);
  padding-bottom: env(safe-area-inset-bottom);
}
.tab {
  flex: 1;
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  padding: 10px 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}
.tab.active { color: var(--coral); }
.badge {
  position: absolute;
  top: 5px;
  left: calc(50% + 6px);
  min-width: 18px;
  height: 18px;
  padding: 0 5px;
  border-radius: 9px;
  background: var(--coral);
  color: var(--coral-ink);
  font-size: 11px;
  font-style: normal;
  font-weight: 800;
  line-height: 18px;
  text-align: center;
}

/* ---------- pile de cartes ---------- */

.deck-view { flex: 1; min-height: 0; display: flex; flex-direction: column; padding: 8px 20px 14px; gap: 14px; }

.invite {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 14px;
  border-radius: 16px;
  background: var(--surface);
  border: 1px dashed var(--line);
}
.invite div { display: flex; flex-direction: column; min-width: 0; }
.invite span { color: var(--muted); font-size: 13px; }
.code-chip {
  padding: 8px 14px;
  border-radius: 12px;
  background: var(--gold);
  color: var(--ink);
  font-weight: 800;
  letter-spacing: .14em;
  flex: none;
}

.deck { flex: 1; min-height: 260px; position: relative; margin-bottom: 28px; }

.card {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  padding: 22px;
  border-radius: var(--radius);
  background: var(--cream);
  color: var(--ink);
  box-shadow: 0 14px 34px rgba(0, 0, 0, .4);
  overflow: hidden;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
  transform-origin: 50% 120%;
  transition: transform .28s cubic-bezier(.2, .9, .3, 1.15);
  will-change: transform;
}
.card.d1 { transform: translateY(8px) scale(.95); filter: brightness(.82); }
.card.d2 { transform: translateY(14px) scale(.9); filter: brightness(.66); }
.card.dragging { transition: none; cursor: grabbing; }
.card.flying { transition: transform .26s ease-in; }

.card.intimate {
  background: linear-gradient(160deg, var(--wine) 0%, var(--wine-deep) 100%);
  color: var(--cream);
}

.card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; min-height: 26px; }
.card-from { font-size: 13px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; opacity: .6; }
.card:not(.intimate) .tag { background: rgba(42, 28, 34, .1); color: var(--ink); }

.card-text {
  flex: 1;
  display: flex;
  align-items: center;
  font-family: var(--serif);
  font-size: 30px;
  line-height: 1.22;
  text-wrap: balance;
  overflow-wrap: anywhere;
  transition: filter .2s;
}
.card-text.medium { font-size: 24px; }
.card-text.small { font-size: 19px; line-height: 1.32; }
.card.veiled .card-text { filter: blur(16px); }

.veil {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  font-family: var(--serif);
  font-size: 24px;
  pointer-events: none;
}
.veil .icon { width: 40px; height: 40px; color: var(--gold); margin-bottom: 6px; }
.veil small { font-family: var(--sans); font-size: 13px; opacity: .7; }

.card-note { display: flex; align-items: center; gap: 6px; font-size: 13px; font-weight: 600; opacity: .72; margin-bottom: 10px; }
.card-note .icon { width: 16px; height: 16px; }
.card.veiled .card-note { visibility: hidden; }

.notice {
  display: flex;
  align-items: flex-start;
  gap: 10px;
  padding: 12px 14px;
  border-radius: 14px;
  background: rgba(232, 184, 109, .12);
  color: var(--gold);
  font-size: 14px;
}
.notice .icon { width: 20px; height: 20px; margin-top: 1px; }
.notice.strong { font-size: 15px; border: 1px solid rgba(232, 184, 109, .4); }
.notice strong { display: block; color: var(--cream); }

.point { display: flex; align-items: flex-start; gap: 12px; }
.point > span:last-child { display: flex; flex-direction: column; gap: 2px; }
.point small { color: var(--muted); font-size: 14px; }

.card-foot { display: flex; justify-content: space-between; font-size: 12px; opacity: .5; }

.stamp {
  position: absolute;
  top: 58px;
  padding: 6px 12px;
  border: 3px solid;
  border-radius: 10px;
  font-weight: 800;
  font-size: 18px;
  letter-spacing: .06em;
  text-transform: uppercase;
  opacity: 0;
  pointer-events: none;
  background: var(--cream);
}
.stamp.left { right: 20px; color: #6d5a62; transform: rotate(10deg); }
.stamp.right { left: 20px; color: #d43a2c; transform: rotate(-10deg); }

.deck-actions { display: flex; align-items: center; justify-content: space-between; padding: 0 18px; }
.deck-count { color: var(--muted); font-size: 13px; text-align: center; }
.round {
  width: 62px;
  height: 62px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  transition: transform .12s;
}
.round:active { transform: scale(.92); }
.round .icon { width: 26px; height: 26px; }
.round.later { background: var(--surface-2); color: var(--muted); }
.round.answer { background: var(--coral); color: var(--coral-ink); }

.empty {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px;
  text-align: center;
}
.empty > .icon { width: 48px; height: 48px; color: var(--line); }
.empty h2 { font-family: var(--serif); font-size: 24px; }
.empty p { color: var(--muted); text-wrap: balance; margin-bottom: 10px; }

/* ---------- listes ---------- */

.list { display: flex; flex-direction: column; gap: 10px; padding: 8px 20px 24px; }
.list-intro { color: var(--muted); font-size: 14px; margin-bottom: 4px; }

.row {
  display: flex;
  align-items: center;
  gap: 12px;
  width: 100%;
  padding: 14px;
  border-radius: 16px;
  background: var(--surface);
  text-align: left;
  border-left: 4px solid transparent;
}
.row.intimate { border-left-color: var(--wine); }
.row-icon { width: 42px; height: 42px; border-radius: 50%; display: grid; place-items: center; background: var(--surface-2); color: var(--gold); flex: none; }
.row-main { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 2px; }
.row-main strong { font-weight: 600; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.row-main small { color: var(--muted); font-size: 13px; }
.row-cta { color: var(--coral); font-weight: 700; font-size: 14px; flex: none; }
.answer-row:active { background: var(--surface-2); }

/* ---------- composer ---------- */

.composer { display: flex; flex-direction: column; gap: 12px; margin-bottom: 14px; }
.composer h2 { font-family: var(--serif); font-size: 24px; }
.composer textarea { font-family: var(--serif); font-size: 20px; }
.composer-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-weight: 600; min-height: 44px; cursor: pointer; }
.toggle .icon { color: var(--gold); width: 20px; height: 20px; margin-right: -4px; }
.sent { display: flex; flex-direction: column; gap: 10px; }
.sent h3 { color: var(--muted); font-size: 13px; letter-spacing: .05em; text-transform: uppercase; margin-top: 6px; }

/* ---------- feuilles ---------- */

.sheet {
  position: fixed;
  inset: 0;
  z-index: 10;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  background: rgba(10, 6, 12, 0);
  transition: background .2s;
}
.sheet.open { background: rgba(10, 6, 12, .72); }
.sheet-panel {
  position: relative;
  width: 100%;
  max-width: 480px;
  max-height: 92dvh;
  overflow-y: auto;
  display: flex;
  flex-direction: column;
  gap: 14px;
  padding: 26px 20px calc(20px + env(safe-area-inset-bottom));
  border-radius: 26px 26px 0 0;
  background: var(--surface);
  transform: translateY(100%);
  transition: transform .26s cubic-bezier(.2, .9, .3, 1);
}
.sheet-panel.tall { min-height: 70dvh; }
.sheet.open .sheet-panel { transform: none; }
.sheet-panel h2 { font-family: var(--serif); font-size: 24px; }
.sheet-close { position: absolute; top: 10px; right: 10px; width: 44px; height: 44px; display: grid; place-items: center; color: var(--muted); border-radius: 50%; }

.sheet-q { display: flex; flex-direction: column; align-items: flex-start; gap: 8px; padding-right: 40px; }
.sheet-q p { font-family: var(--serif); font-size: 21px; line-height: 1.25; overflow-wrap: anywhere; }

.segs { display: flex; gap: 6px; padding: 4px; border-radius: 16px; background: var(--bg); }
.seg {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  min-height: 44px;
  border-radius: 12px;
  color: var(--muted);
  font-weight: 600;
  font-size: 14px;
}
.seg .icon { width: 18px; height: 18px; }
.seg.active { background: var(--surface-2); color: var(--text); }

.answer-body { min-height: 150px; display: flex; flex-direction: column; }
.answer-body textarea { flex: 1; background: var(--bg); }
.drop {
  flex: 1;
  min-height: 150px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  border: 1.500px dashed var(--line);
  border-radius: 16px;
  color: var(--muted);
  font-weight: 600;
}
.drop .icon { width: 36px; height: 36px; color: var(--coral); }
.preview { display: flex; flex-direction: column; gap: 10px; align-items: stretch; }
.preview img { width: 100%; max-height: 42dvh; object-fit: contain; border-radius: 16px; background: var(--bg); }
audio { width: 100%; }

.rec { flex: 1; display: flex; align-items: center; justify-content: center; gap: 14px; }
.rec-dot { width: 14px; height: 14px; border-radius: 50%; background: var(--coral); animation: pulse 1s infinite; }
.rec-time { font-size: 30px; font-variant-numeric: tabular-nums; font-weight: 700; min-width: 3.200ch; }
@keyframes pulse { 50% { opacity: .25; } }

.viewer-content { flex: 1; display: flex; flex-direction: column; justify-content: center; gap: 12px; }
.viewer-content img { width: 100%; max-height: 58dvh; object-fit: contain; border-radius: 16px; background: var(--bg); }
.viewer-text {
  padding: 22px;
  border-radius: var(--radius);
  background: var(--cream);
  color: var(--ink);
  font-family: var(--serif);
  font-size: 22px;
  line-height: 1.35;
  white-space: pre-wrap;
  overflow-wrap: anywhere;
}

.setting { display: flex; align-items: center; justify-content: space-between; gap: 14px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.setting span { display: flex; flex-direction: column; gap: 2px; }
.setting small { color: var(--muted); font-size: 13px; }

/* ---------- toast ---------- */

#toast {
  position: fixed;
  left: 50%;
  bottom: calc(92px + env(safe-area-inset-bottom));
  z-index: 20;
  max-width: min(88vw, 420px);
  padding: 12px 18px;
  border-radius: 14px;
  background: var(--cream);
  color: var(--ink);
  font-size: 14px;
  font-weight: 600;
  text-align: center;
  opacity: 0;
  transform: translate(-50%, 12px);
  pointer-events: none;
  transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

@media (prefers-reduced-motion: reduce) {
  * { transition-duration: .01ms !important; animation: none !important; }
}
