* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

:root {
  --bar-bg: rgba(246, 246, 246, 0.94);
  --hairline: rgba(60, 60, 67, 0.29);
  --accent: #0a7cff;
  --field-border: #c9c9ce;
  --field-bg: #ffffff;
  --round-bg: #e9e9eb;
  --round-ink: #6f6f74;
  --pad-bg: #d1d4db;
  --key-bg: #ffffff;
  --key-fn: #abb0bb;
  --key-ink: #000000;
  --key-shadow: rgba(0, 0, 0, 0.3);
  --suit-red: #d91a2a;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bar-bg: rgba(22, 22, 23, 0.94);
    --hairline: rgba(84, 84, 88, 0.65);
    --field-border: #3a3a3c;
    --field-bg: #000000;
    --round-bg: #2c2c2e;
    --round-ink: #a1a1a6;
    --pad-bg: #2b2b2d;
    --key-bg: #6b6b6f;
    --key-fn: #474749;
    --key-ink: #ffffff;
    --key-shadow: rgba(0, 0, 0, 0.6);
    --suit-red: #ff7a7a;
  }
}

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  overscroll-behavior: none;
  background: var(--c-bg);
  color: var(--c-text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-text-size-adjust: 100%;
}
button { font: inherit; color: inherit; }

#app {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: 100%;
  max-width: 760px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  background: var(--c-bg);
}

/* En-tête du contact */
.topbar {
  flex: none;
  z-index: 2;
  display: grid;
  grid-template-columns: 56px 1fr 56px;
  align-items: center;
  padding: calc(env(safe-area-inset-top, 0px) + 8px) 10px 7px;
  background: var(--bar-bg);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 0.5px solid var(--hairline);
}
.back { justify-self: start; display: block; width: 12px; height: 21px; margin-left: 6px; color: var(--accent); }
.facetime { justify-self: end; display: block; width: 28px; height: 19px; margin-right: 6px; color: var(--accent); }
.back svg, .facetime svg { display: block; width: 100%; height: 100%; }
.contact { display: flex; flex-direction: column; align-items: center; gap: 4px; min-width: 0; }
.avatar {
  width: 46px;
  height: 46px;
  border-radius: 50%;
  display: grid;
  place-items: center;
  overflow: hidden;
  background: linear-gradient(180deg, #a7acb7 0%, #858a95 100%);
  color: #ffffff;
  font-size: 25px;
  line-height: 1;
}
.name { display: inline-flex; align-items: center; gap: 3px; max-width: 100%; font-size: 12px; line-height: 14px; }
.name span { overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.name svg { flex: none; width: 6px; height: 10px; color: var(--c-muted); }

.offline { flex: none; padding: 4px; text-align: center; font-size: 12px; color: var(--c-muted); background: var(--bar-bg); }
.offline[hidden] { display: none; }

.thread { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; overscroll-behavior: contain; padding-bottom: 14px; }

/* Barre de saisie */
.composer { flex: none; padding: 6px 12px calc(env(safe-area-inset-bottom, 0px) + 8px); background: var(--c-bg); }
.composer.pad-open { padding-bottom: 0; }
.bar { display: flex; align-items: flex-end; gap: 8px; }
.bar[hidden] { display: none; }

.round-btn {
  flex: none;
  display: grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-bottom: 1px;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--round-bg);
  color: var(--round-ink);
  cursor: pointer;
}
.round-btn svg { width: 19px; height: 19px; }
.round-btn.cards-toggle { background: var(--accent); color: #ffffff; }

.field {
  flex: 1;
  min-width: 0;
  display: flex;
  align-items: flex-end;
  min-height: 36px;
  padding: 0 3px 0 13px;
  border: 1px solid var(--field-border);
  border-radius: 18px;
  background: var(--field-bg);
}
.field textarea {
  flex: 1;
  min-width: 0;
  max-height: 132px;
  margin: 0;
  padding: 6px 0;
  border: 0;
  outline: 0;
  resize: none;
  background: transparent;
  color: var(--c-text);
  font: inherit;
  font-size: 17px;
  line-height: 22px;
}
.field textarea::placeholder { color: var(--c-muted); }

.send {
  flex: none;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  margin: 2px 0;
  padding: 0;
  border: 0;
  border-radius: 50%;
  background: var(--accent);
  color: #ffffff;
  cursor: pointer;
}
.send svg { width: 18px; height: 18px; }
.send[hidden] { display: none; }
.send:disabled { background: var(--round-bg); color: var(--round-ink); cursor: default; }

/* Saisie de la suite de cartes */
.cardfield { align-items: center; flex-wrap: wrap; gap: 6px; min-height: 60px; padding: 6px 10px; }
.cardfield .placeholder { color: var(--c-muted); font-size: 16px; }
.cardfield .card.ghost { opacity: 0.6; box-shadow: 0 0 0 1.5px var(--accent); }
#cardBar .send { align-self: center; width: 34px; height: 34px; }

.cardpad {
  display: grid;
  gap: 11px;
  margin: 8px -12px 0;
  padding: 9px 3px calc(env(safe-area-inset-bottom, 0px) + 9px);
  background: var(--pad-bg);
  -webkit-user-select: none;
  user-select: none;
}
.cardpad[hidden] { display: none; }
.pad-hint { margin: -2px 0 -4px; text-align: center; font-size: 12px; color: var(--c-muted); }
.keys { display: grid; grid-template-columns: repeat(7, 1fr); gap: 6px; padding: 0 3px; }
.keys.suits { grid-template-columns: 1.3fr repeat(4, 1fr); }
.key {
  display: grid;
  place-items: center;
  height: 44px;
  padding: 0;
  border: 0;
  border-radius: 6px;
  background: var(--key-bg);
  color: var(--key-ink);
  box-shadow: 0 1px 0 var(--key-shadow);
  font: 400 22px/1 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, sans-serif;
  cursor: pointer;
  touch-action: manipulation;
}
.key:active { filter: brightness(0.82); }
.key:disabled { opacity: 0.45; }
.key.fn { background: var(--key-fn); font-size: 16px; }
.key.fn svg { width: 24px; height: 24px; }
.key.suit svg { width: 25px; height: 25px; fill: currentColor; }
.key.suit.red { color: var(--suit-red); }
.key.sel,
.key.suit.sel { background: var(--accent); color: #ffffff; }
