:root {
  --bg: #eef2ff;
  --card-bg: #ffffff;
  --text: #1e1b4b;
  --text-soft: #6b7280;
  --accent: #4f46e5;
  --danger: #dc2626;
  --ok: #16a34a;
  --border: #e5e7eb;
  --shadow: 0 4px 14px rgba(30, 27, 75, 0.08);
  font-size: 16px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14142b;
    --card-bg: #1f1f3a;
    --text: #f1f0ff;
    --text-soft: #a5a3c9;
    --border: #33335a;
    --shadow: 0 4px 14px rgba(0, 0, 0, 0.4);
  }
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  overflow: hidden; /* la page ne scrolle jamais : tout tient à l'écran */
}

body {
  margin: 0;
  display: flex;
  flex-direction: column;
  background: var(--bg);
  color: var(--text);
  font-family: "Segoe UI", system-ui, -apple-system, Roboto, sans-serif;
  -webkit-tap-highlight-color: transparent;
}

/* ---- Boutons flottants : plus de bandeau de titre, ils flottent en
   transparence par-dessus la ligne du premier enfant pour libérer
   toute la hauteur de l'écran ---- */
.topbar-actions {
  position: fixed;
  top: max(10px, env(safe-area-inset-top));
  right: max(12px, env(safe-area-inset-right));
  z-index: 20;
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn-float {
  background: color-mix(in srgb, var(--card-bg) 70%, transparent);
  backdrop-filter: blur(6px);
  -webkit-backdrop-filter: blur(6px);
  box-shadow: 0 2px 10px rgba(0, 0, 0, 0.12);
}

/* ---- Zone des lignes : occupe TOUTE la hauteur de l'écran, découpée
   en parts strictement égales selon le nombre d'enfants ---- */
.rows {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding: 10px 14px;
  width: 100%;
  max-width: 1200px;
  margin: 0 auto;
  overflow: hidden;
}

.rows.is-empty {
  justify-content: center;
  align-items: center;
}

.empty-msg {
  text-align: center;
  color: var(--text-soft);
  font-size: 18px;
  margin: 0;
}

/* ---- Ligne enfant : chaque ligne prend une part égale de la hauteur ---- */
.child-row {
  flex: 1 1 0;
  min-height: 0;
  background: var(--card-bg);
  border-radius: 20px;
  box-shadow: var(--shadow);
  padding: 10px 22px;
  display: flex;
  align-items: center;
  gap: 18px;
  border-left: 10px solid var(--child-color, var(--accent));
  transition: box-shadow .2s;
  overflow: hidden;
}

.child-row.time-up {
  animation: pulse-alert 1s infinite;
}

@keyframes pulse-alert {
  0%, 100% { box-shadow: var(--shadow); }
  50% { box-shadow: 0 0 0 6px rgba(220,38,38,0.35); }
}

.child-identity {
  display: flex;
  align-items: center;
  gap: clamp(4px, 2vw, 10px);
  flex: 1 1 60px;
  min-width: 40px; /* garantit que l'avatar reste toujours visible */
  overflow: hidden;
}

.child-avatar {
  font-size: clamp(16px, min(5vh, 6vw), 34px);
  width: clamp(26px, min(8vh, 9vw), 54px);
  height: clamp(26px, min(8vh, 9vw), 54px);
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg);
  border-radius: 50%;
  flex-shrink: 0;
}

.child-name {
  font-size: clamp(12px, min(4vh, 4.2vw), 24px);
  font-weight: 700;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.child-sub {
  font-size: clamp(10px, 2vh, 13px);
  color: var(--text-soft);
  white-space: nowrap;
}

.timer-display {
  font-size: clamp(15px, min(7vh, 7.5vw), 44px);
  font-weight: 800;
  font-variant-numeric: tabular-nums;
  min-width: clamp(46px, 16vw, 130px);
  text-align: center;
  flex: 1 1 auto;
  overflow: hidden;
  color: var(--child-color, var(--accent));
}

.timer-display.time-up {
  color: var(--danger);
}

.row-actions {
  display: flex;
  align-items: center;
  gap: clamp(3px, min(1.2vh, 1.5vw), 10px);
  flex-wrap: nowrap;
  flex: 0 0 auto;
  justify-content: flex-end;
}

.btn {
  border: none;
  border-radius: 14px;
  padding: 12px 18px;
  font-size: 16px;
  font-weight: 600;
  cursor: pointer;
  background: var(--bg);
  color: var(--text);
  transition: transform .08s, filter .15s;
  touch-action: manipulation;
}
.btn:active { transform: scale(0.94); }
.btn:hover { filter: brightness(0.96); }

.btn-play {
  font-size: clamp(14px, min(5vh, 6vw), 28px);
  width: clamp(30px, min(10vh, 12vw), 66px);
  height: clamp(30px, min(10vh, 12vw), 66px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--ok);
  color: white;
  box-shadow: 0 3px 8px rgba(22,163,74,.4);
  flex-shrink: 0;
}
.btn-play.running {
  background: var(--danger);
  box-shadow: 0 3px 8px rgba(220,38,38,.4);
}

.btn-icon {
  font-size: clamp(12px, min(3.5vh, 4.5vw), 22px);
  width: clamp(24px, min(8vh, 9vw), 50px);
  height: clamp(24px, min(8vh, 9vw), 50px);
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
  background: var(--bg);
  flex-shrink: 0;
}

.btn-primary { background: var(--accent); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-add { background: var(--accent); color: white; }

.btn-quick { min-width: 90px; }
.btn-plus { background: #dcfce7; color: #166534; }
.btn-minus { background: #fee2e2; color: #991b1b; }

/* ---- Modales ---- */
.modal {
  border: none;
  border-radius: 20px;
  padding: 0;
  box-shadow: 0 10px 40px rgba(0,0,0,.25);
  background: var(--card-bg);
  color: var(--text);
  width: min(480px, 92vw);
}
.modal::backdrop { background: rgba(0,0,0,.45); }

.modal-card {
  padding: 24px;
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.modal-card h2 { margin: 0; font-size: 22px; }
.modal-sub { margin: 0; color: var(--text-soft); font-size: 14px; }

.modal-card label {
  font-size: 14px;
  font-weight: 600;
  color: var(--text-soft);
}

.modal-card input[type="text"],
.modal-card input[type="number"] {
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 16px;
}

.modal-row {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.modal-row input[type="color"] {
  width: 44px;
  height: 44px;
  border: none;
  border-radius: 10px;
  background: none;
  cursor: pointer;
}

.modal-row select {
  padding: 10px;
  border-radius: 10px;
  border: 1px solid var(--border);
  font-size: 18px;
}

.days-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
  gap: 10px;
}

.day-field {
  display: flex;
  flex-direction: column;
  gap: 4px;
  background: var(--bg);
  border-radius: 12px;
  padding: 8px 10px;
}

.day-field label { font-size: 12px; }

.day-field input {
  width: 100%;
  padding: 8px;
  border-radius: 8px;
  border: 1px solid var(--border);
  font-size: 15px;
  background: var(--card-bg);
  color: var(--text);
}

.modal-actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 8px;
  flex-wrap: wrap;
}

.modal-actions-right {
  display: flex;
  gap: 10px;
  margin-left: auto;
}

.quick-buttons {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

@media (max-width: 560px) {
  /* on garde une seule ligne horizontale (pas d'empilement) pour ne jamais
     dépasser la part de hauteur allouée à chaque enfant */
  .child-sub { display: none; }
  .row-actions { gap: 4px; }
  .child-row { padding: 8px 12px; gap: 6px; }
}

/* ---- Clavier PIN ---- */
.pin-dots {
  display: flex;
  justify-content: center;
  gap: 14px;
  margin: 6px 0;
}

.pin-dots span {
  width: 16px;
  height: 16px;
  border-radius: 50%;
  border: 2px solid var(--accent);
  background: transparent;
}

.pin-dots span.filled {
  background: var(--accent);
}

.pin-keypad {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.pin-key {
  font-size: 22px;
  padding: 16px 0;
}

.pin-key-ok {
  background: var(--accent);
  color: white;
}

.pin-key-clear {
  background: #fee2e2;
  color: #991b1b;
}

/* ---- Calendrier de statistiques ---- */
.modal-wide {
  width: min(560px, 94vw);
}

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

.stats-header select {
  padding: 10px 12px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-size: 15px;
  font-weight: 600;
}

.stats-month-nav {
  display: flex;
  align-items: center;
  gap: 8px;
}

.stats-month-label {
  font-weight: 700;
  min-width: 130px;
  text-align: center;
}

.stats-weekdays {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
  text-align: center;
  font-size: 12px;
  color: var(--text-soft);
  font-weight: 600;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(7, 1fr);
  gap: 4px;
}

.stats-day {
  aspect-ratio: 1;
  border-radius: 10px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-size: 11px;
  gap: 2px;
  background: var(--bg);
  color: var(--text-soft);
}

.stats-day.stats-empty {
  visibility: hidden;
}

.stats-day .stats-day-num {
  font-weight: 700;
  font-size: 13px;
  color: var(--text);
}

.stats-day .stats-day-min {
  font-variant-numeric: tabular-nums;
}

.stats-day.stats-ok {
  background: #dcfce7;
}
.stats-day.stats-ok .stats-day-num { color: #166534; }

.stats-day.stats-over {
  background: #fee2e2;
}
.stats-day.stats-over .stats-day-num { color: #991b1b; }

.stats-day.stats-today {
  outline: 2px solid var(--accent);
  outline-offset: -2px;
}

.stats-legend {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  font-size: 12px;
  color: var(--text-soft);
  align-items: center;
}

.stats-dot {
  display: inline-block;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  margin-right: 4px;
  vertical-align: middle;
}
.stats-dot-ok { background: #22c55e; }
.stats-dot-over { background: #ef4444; }
.stats-dot-none { background: var(--bg); border: 1px solid var(--border); }
