:root {
  --ink: #101a24;        /* fond */
  --lagoon: #1a2c3b;     /* zone de saisie */
  --line: #2a3f51;
  --paper: #f1eee6;      /* texte */
  --mute: #91a5b5;
  --brass: #e3b455;      /* dernières minutes */
  --coral: #f0705f;      /* dernière minute */
  --sage: #8cbf9f;       /* synchronisé */
  --violet: #b18cf0;     /* dernières minutes */
  color-scheme: dark;
}

* { box-sizing: border-box; }

html {
  /* Empêche l'agrandissement automatique du texte qui force certains
     navigateurs mobiles à élargir la page au-delà de l'écran. */
  -webkit-text-size-adjust: 100%;
  text-size-adjust: 100%;
}

html, body {
  height: 100%;
  width: 100%;
  margin: 0;
  overflow-x: hidden;   /* filet de sécurité : jamais de défilement horizontal */
  background: var(--ink);
  color: var(--paper);
  font-family: "Roboto Flex", Roboto, "Segoe UI", system-ui, sans-serif;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}

.hidden { display: none !important; }

#app {
  height: 100dvh;
  display: grid;
  grid-template-rows: 1fr 1fr;
}

/* ---------- Moitié haute ---------- */

.top {
  display: grid;
  grid-template-rows: auto auto 1fr auto;
  row-gap: 0.3rem;
  padding: calc(env(safe-area-inset-top, 0px) + 12px) 16px 10px;
  text-align: center;
  border-bottom: 1px solid var(--line);
  min-height: 0;
  min-width: 0;
}

.date {
  font-size: clamp(0.85rem, 3.6vw, 1.05rem);
  font-weight: 500;
  color: var(--mute);
  text-transform: capitalize;
}

.title-row {
  display: flex;
  align-items: baseline;
  justify-content: center;
  gap: 0.5rem;
  min-width: 0;
}

.top h1 {
  margin: 0;
  min-width: 0;
  font-size: clamp(1.1rem, 5.2vw, 1.7rem);
  font-weight: 600;
  line-height: 1.25;
  letter-spacing: 0.01em;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.counter {
  flex: none;
  padding: 2px 10px;
  border: 1.5px solid var(--mute);
  border-radius: 999px;
  font-size: 0.9rem;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  color: var(--paper);
  white-space: nowrap;
}

.clock {
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 0;
  font-size: min(24vw, 20dvh);
  font-weight: 300;
  line-height: 1;
  letter-spacing: -0.02em;
  font-variant-numeric: tabular-nums;
}

.countdown {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 2px;
  min-height: 3.2rem;
}

.cd-label {
  font-size: 0.9rem;
  color: var(--mute);
  min-height: 1.2em;
}

.cd {
  font-size: clamp(1.4rem, 7.6vw, 2.3rem);
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  transition: color 0.4s;
}

.cd.warn { color: var(--brass); }
.cd.alert { color: var(--violet); }

/* ---------- Moitié basse ---------- */

.bottom {
  display: flex;
  flex-direction: column;
  min-height: 0;
  padding: 10px 12px calc(env(safe-area-inset-bottom, 0px) + 12px);
  gap: 8px;
}

.groupbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
}

.group-btn {
  flex: 1 1 auto;
  min-width: 0;
  padding: 8px 4px;
  border: 0;
  background: none;
  color: var(--paper);
  font: inherit;
  font-size: 1.1rem;
  font-weight: 600;
  text-align: left;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.group-btn::after { content: "  \25BE"; color: var(--mute); }
.group-btn.missing { color: var(--brass); }

.sync {
  flex: none;
  font-size: 0.8rem;
  color: var(--mute);
  white-space: nowrap;
}

.sync::before {
  content: "";
  display: inline-block;
  width: 0.6em;
  height: 0.6em;
  margin-right: 0.45em;
  border-radius: 50%;
  background: var(--mute);
}

.sync[data-state="ok"]::before { background: var(--sage); }
.sync[data-state="warn"]::before { background: var(--brass); }
.sync[data-state="bad"]::before { background: var(--coral); }

textarea,
.participants-scroll {
  flex: 1;
  min-height: 0;
  width: 100%;
  min-width: 0;
  border: 1px solid var(--line);
  border-radius: 14px;
  background: var(--lagoon);
}

textarea {
  padding: 14px;
  resize: none;
  color: var(--paper);
  font: inherit;
  font-size: 1.3rem;
  line-height: 1.55;
}

textarea:focus-visible,
button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--brass);
  outline-offset: 2px;
}

textarea:disabled { opacity: 0.5; }
textarea::placeholder { color: var(--mute); }

/* Le défilement vertical se fait sur ce conteneur, à hauteur fixée par la mise en page. */
.participants-scroll {
  overflow-x: hidden;
  overflow-y: auto;
  cursor: text;
}

.participants-scroll.disabled {
  opacity: 0.5;
  cursor: default;
}

/* La mise en colonnes se fait sur l'élément interne, à hauteur libre : c'est ce qui
   évite le bug des navigateurs qui ajoutent une 3e colonne pour tout faire tenir
   au lieu de laisser défiler (column-count + overflow sur un même élément à hauteur
   contrainte). Ici, seul le conteneur au-dessus défile ; ce texte s'étire librement,
   toujours sur 2 colonnes au maximum. */
.participants-view {
  padding: 14px;
  color: var(--paper);
  font: inherit;
  font-size: 1.3rem;
  line-height: 1.55;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.participants-view.cols {
  column-count: 2;
  column-gap: 1.4rem;
  column-rule: 1px solid var(--line);
}

.participants-view:empty::before {
  content: attr(data-placeholder);
  color: var(--mute);
}

/* ---------- Boîtes de dialogue ---------- */

dialog {
  width: min(92vw, 26rem);
  max-height: 80dvh;
  padding: 18px;
  border: 1px solid var(--line);
  border-radius: 18px;
  background: var(--lagoon);
  color: var(--paper);
}

dialog::backdrop { background: rgba(6, 10, 14, 0.7); }

dialog h2 { margin: 0 0 8px; font-size: 1.2rem; }
dialog p { margin: 0 0 12px; color: var(--mute); }

dialog input {
  width: 100%;
  margin-bottom: 12px;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--ink);
  color: var(--paper);
  font: inherit;
  font-size: 1.1rem;
}

dialog button {
  padding: 10px 14px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: transparent;
  color: var(--paper);
  font: inherit;
}

dialog button.primary {
  width: 100%;
  border-color: var(--paper);
  background: var(--paper);
  color: var(--ink);
  font-weight: 600;
}

.pick-list {
  display: flex;
  flex-direction: column;
  gap: 6px;
  max-height: 52dvh;
  margin-bottom: 12px;
  overflow-y: auto;
}

.pick-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  text-align: left;
}

.pick-hint { color: var(--brass); font-size: 0.85rem; }

.pick-actions { display: flex; justify-content: flex-end; gap: 8px; }

@media (prefers-reduced-motion: reduce) {
  .cd { transition: none; }
}

/* Téléphone en paysage : horloge un peu plus compacte */
@media (orientation: landscape) and (max-height: 500px) {
  #app { grid-template-rows: 1fr; grid-template-columns: 1fr 1fr; }
  .top { border-bottom: 0; border-right: 1px solid var(--line); }
  .clock { font-size: min(15vw, 28dvh); }
}
