/* ============================================================
   Routine Planner — feuille de style unique (tablette d'abord)
   ============================================================ */

:root {
  --bg-a: #6fbf9a;
  --bg-b: #5fb6c9;
  --bg-c: #3f8ea3;
  --state: #6fbf9a;
  --state-tint: rgba(111, 191, 154, 0.16);
  --state-tint-soft: rgba(111, 191, 154, 0.09);
  --ink: #1f2a33;
  --ink-soft: #55636f;
  --card: rgba(255, 255, 255, 0.94);
  --card-solid: #ffffff;
  --line: rgba(31, 42, 51, 0.12);
  --accent: #2f7d6b;
  --accent-ink: #ffffff;
  --warn: #c9736b;
  --radius: 22px;
  --radius-sm: 14px;
  --shadow: 0 10px 30px rgba(20, 35, 45, 0.16);
  --shadow-soft: 0 4px 14px rgba(20, 35, 45, 0.1);
  --tap: 56px;
  --font: "Segoe UI", Roboto, "Helvetica Neue", system-ui, -apple-system, sans-serif;
  color-scheme: light;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  overscroll-behavior: none;
}

body {
  font-family: var(--font);
  color: var(--ink);
  background: linear-gradient(155deg, var(--bg-a) 0%, var(--bg-b) 55%, var(--bg-c) 100%) fixed;
  transition: background 1.6s ease;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

#app {
  display: flex;
  flex-direction: column;
  min-height: 100%;
  height: 100dvh;
}

/* ---------------- barre superieure ---------------- */

#topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 16px;
  color: #fff;
  flex: 0 0 auto;
}

#topbar.hidden { display: none; }

.brand {
  font-size: 1.15rem;
  font-weight: 700;
  letter-spacing: 0.02em;
  display: flex;
  align-items: center;
  gap: 10px;
  background: none;
  border: 0;
  color: inherit;
  font-family: inherit;
  cursor: pointer;
  padding: 6px 8px;
  border-radius: var(--radius-sm);
}

.brand:hover { background: rgba(255, 255, 255, 0.14); }
.topbar-spacer { flex: 1; }

.icon-btn {
  min-width: 48px;
  min-height: 48px;
  border-radius: 50%;
  border: 0;
  background: rgba(255, 255, 255, 0.2);
  color: #fff;
  font-size: 1.3rem;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
}

.icon-btn:active { transform: scale(0.94); }

/* ---------------- conteneur de vue ---------------- */

#view {
  flex: 1 1 auto;
  min-height: 0;
  display: flex;
  flex-direction: column;
}

.scroll {
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
}

.page {
  flex: 1;
  overflow-y: auto;
  padding: 18px clamp(14px, 3vw, 36px) 40px;
}

.page-narrow { max-width: 980px; margin: 0 auto; width: 100%; }

.card {
  background-color: var(--card);
  background-image: linear-gradient(var(--state-tint-soft), var(--state-tint-soft));
  border-radius: var(--radius);
  box-shadow: var(--shadow-soft);
  padding: 18px 20px;
  margin-bottom: 16px;
}

.card h2, .card h3 { margin: 0 0 12px; }
h1, h2, h3 { font-weight: 800; letter-spacing: -0.01em; }

.muted { color: var(--ink-soft); }
.small { font-size: 0.86rem; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 12px; flex-wrap: wrap; }
.row-tight { display: flex; align-items: center; gap: 8px; }
.spread { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 12px; }
.hidden { display: none !important; }

/* ---------------- boutons ---------------- */

.btn {
  min-height: var(--tap);
  padding: 14px 22px;
  border-radius: var(--radius-sm);
  border: 2px solid transparent;
  background: var(--card-solid);
  color: var(--ink);
  font-family: inherit;
  font-size: 1rem;
  font-weight: 700;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
  transition: transform 0.12s ease, box-shadow 0.12s ease, background 0.2s ease;
}

.btn:active { transform: translateY(2px) scale(0.99); }
.btn[disabled] { opacity: 0.45; cursor: not-allowed; }
.btn-primary { background: var(--accent); color: var(--accent-ink); }
.btn-ghost { background: rgba(255, 255, 255, 0.22); color: #fff; box-shadow: none; border-color: rgba(255, 255, 255, 0.4); }
.btn-outline { background: transparent; border-color: var(--line); box-shadow: none; }
.btn-danger { background: #b8564d; color: #fff; }
.btn-small { min-height: 42px; padding: 8px 14px; font-size: 0.9rem; border-radius: 12px; }
.btn-block { width: 100%; }

.btn-huge {
  min-height: clamp(100px, 17vh, 175px);
  width: min(92%, 620px);
  font-size: clamp(1.6rem, 4.4vw, 2.6rem);
  font-weight: 900;
  letter-spacing: 0.02em;
  border-radius: 34px;
  background: #fff;
  color: var(--accent);
  box-shadow: 0 14px 0 rgba(0, 0, 0, 0.13), var(--shadow);
}

.btn-huge:active { transform: translateY(8px); box-shadow: 0 6px 0 rgba(0, 0, 0, 0.13); }

/* ---------------- accueil ---------------- */

.home {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: clamp(10px, 2.2vh, 26px);
  padding: 16px 20px 24px;
  overflow-y: auto;
  text-align: center;
  color: #fff;
}

.home h1 {
  font-size: clamp(1.8rem, 5vw, 3rem);
  margin: 0;
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.18);
}

.home-sub { font-size: clamp(1rem, 2.4vw, 1.3rem); opacity: 0.95; }

.home-clock {
  font-size: clamp(2.2rem, 7.5vw, 4.4rem);
  font-weight: 900;
  line-height: 1;
  text-shadow: 0 3px 14px rgba(0, 0, 0, 0.2);
}

.home-chip {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  padding: 10px 18px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.22);
  font-weight: 700;
}

.home-actions { display: flex; flex-direction: column; align-items: center; gap: 14px; width: 100%; }

.resume-banner {
  background: rgba(255, 255, 255, 0.95);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 16px 20px;
  box-shadow: var(--shadow);
  max-width: 560px;
  width: min(92%, 560px);
}

/* ---------------- ecran de routine ---------------- */

.routine {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(0, 1fr) clamp(270px, 27vw, 360px);
  gap: 22px;
  padding: clamp(16px, 2.4vh, 30px);
  min-height: 0;
  min-width: 0;
  overflow: hidden;
}

.routine-main {
  background-color: rgba(255, 255, 255, 0.62);
  background-image: linear-gradient(var(--state-tint), var(--state-tint));
  backdrop-filter: blur(7px);
  border: 2px solid rgba(255, 255, 255, 0.55);
  border-radius: 30px;
  box-shadow: 0 6px 18px rgba(20, 35, 45, 0.13);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: space-between;
  padding: 18px 20px 22px;
  min-height: 0;
  position: relative;
}

.routine-side {
  background-color: rgba(255, 255, 255, 0.46);
  background-image: linear-gradient(var(--state-tint), var(--state-tint));
  backdrop-filter: blur(7px);
  border: 2px solid rgba(255, 255, 255, 0.5);
  border-radius: 30px;
  box-shadow: 0 6px 18px rgba(20, 35, 45, 0.13);
  display: flex;
  flex-direction: column;
  padding: 16px;
  min-height: 0;
}

@media (max-width: 860px), (orientation: portrait) {
  .routine { grid-template-columns: minmax(0, 1fr); grid-template-rows: minmax(0, 68fr) minmax(0, 32fr); }
}

/* Un telephone tenu en paysage est large en pixels physiques mais dispose de
   tres peu de pixels CSS en hauteur. On conserve donc les deux panneaux cote a
   cote au lieu de les empiler, ce qui evitait les chevauchements observes. */
@media (orientation: landscape) and (max-width: 860px) {
  .routine {
    grid-template-columns: minmax(0, 1fr) minmax(230px, 34vw);
    grid-template-rows: minmax(0, 1fr);
  }
}

/* --- zone principale : tache en cours --- */

.task-head { display: flex; align-items: center; gap: 18px; width: 100%; flex: 0 0 auto; }

.task-visual {
  width: clamp(120px, 26vh, 300px);
  height: clamp(120px, 26vh, 300px);
  max-height: 30vh;
  max-width: 32vw;
  border-radius: 30px;
  background: #f2f5f4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: clamp(3.4rem, 14vh, 8rem);
  overflow: hidden;
  flex: 0 0 auto;
  box-shadow: inset 0 0 0 3px rgba(0, 0, 0, 0.05);
}

.task-visual img { width: 100%; height: 100%; object-fit: cover; }
.task-visual { background: rgba(255, 255, 255, 0.55); }

.task-title {
  font-size: clamp(1.6rem, 4.6vh, 3rem);
  font-weight: 900;
  line-height: 1.05;
  margin: 0;
  min-width: 0;
  overflow-wrap: anywhere;
}

.task-sub { color: var(--ink-soft); font-weight: 600; margin-top: 6px; }

.timer-zone {
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
  align-items: center;
  justify-items: center;
  gap: clamp(8px, 2vw, 32px);
  width: 100%;
  flex: 1 1 auto;
  min-height: 0;
  padding: 6px 0;
}

/* Colonnes de largeur fixe : les chiffres qui changent ne deplacent plus le sablier.
   Le sablier se colle a droite de sa colonne et le compteur a gauche de la sienne :
   les deux elements se lisent comme un seul bloc centre dans la page. */
.timer-zone > .hourglass-wrap { justify-self: end; }

.timer-zone > .center {
  justify-self: start;
  text-align: left;
  min-width: 0;
  max-width: 100%;
}

.timer-zone > .center .countdown-label,
.timer-zone > .center #over-note { text-align: left; justify-content: flex-start; }

.countdown {
  font-variant-numeric: tabular-nums;
  font-size: clamp(2.8rem, 11vh, 6.5rem);
  font-weight: 900;
  line-height: 1;
  letter-spacing: -0.03em;
  white-space: nowrap;
}

.countdown.over { color: var(--warn); }
.countdown-label { font-weight: 700; color: var(--ink-soft); text-transform: uppercase; letter-spacing: 0.08em; font-size: 0.8rem; }

#over-note {
  min-height: 2.6em;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
}

.hourglass-wrap {
  position: relative;
  display: flex;
  flex-direction: column;
  align-items: center;
  min-height: 0;
  flex: 0 1 auto;
  padding-bottom: clamp(24px, 3.4vh, 38px); /* place reservee a la legende */
}

.hourglass { height: clamp(150px, 42vh, 500px); max-height: 100%; width: auto; flex: 0 1 auto; }

/* Legende hors flux : sa largeur ne peut donc jamais deplacer le sablier. */
.hourglass-caption {
  position: absolute;
  left: 0;
  right: 0;
  bottom: 2px;
  text-align: center;
  white-space: nowrap;
  font-size: clamp(0.85rem, 1.8vh, 1.15rem);
  font-weight: 800;
  color: var(--ink-soft);
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.01em;
}

.hourglass-caption.over { color: var(--warn); }
.hourglass .glass { fill: none; stroke: rgba(31, 42, 51, 0.22); stroke-width: 2.5; stroke-linejoin: round; }
.hourglass .glass-fill { fill: rgba(255, 255, 255, 0.6); }
.hourglass .sand { fill: var(--sand-color, #2aa876); transition: fill 0.45s linear; }
.hourglass .frame { fill: #8a6a4f; }
.hourglass .drop { fill: var(--sand-color, #2aa876); transition: fill 0.45s linear; }

.task-progress {
  width: 100%;
  height: 16px;
  border-radius: 999px;
  background: rgba(31, 42, 51, 0.1);
  overflow: hidden;
}

.task-progress > span {
  display: block;
  height: 100%;
  border-radius: 999px;
  background: linear-gradient(90deg, var(--bg-a), var(--bg-b));
  transition: width 0.25s linear;
}

.done-btn {
  width: min(96%, 640px);
  min-height: clamp(74px, 12vh, 124px);
  flex: 0 0 auto;
  font-size: clamp(1.4rem, 3.6vh, 2.2rem);
  font-weight: 900;
  border-radius: 28px;
  border: 0;
  background: linear-gradient(180deg, #4fbf8b, #2f9d6d);
  color: #fff;
  cursor: pointer;
  box-shadow: 0 12px 0 #26765a, var(--shadow);
  font-family: inherit;
  letter-spacing: 0.04em;
  transition: transform 0.1s ease, box-shadow 0.1s ease;
}

.done-btn:active { transform: translateY(8px); box-shadow: 0 4px 0 #26765a; }

/* Pause courte après un appui : evite les validations en rafale. */
.done-btn.cooling {
  opacity: 0.5;
  transform: translateY(6px);
  box-shadow: 0 5px 0 #26765a;
  cursor: default;
}

.adult-btn {
  background: rgba(31, 42, 51, 0.08);
  color: var(--ink-soft);
}

.paused-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255, 255, 255, 0.84);
  border-radius: 28px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  z-index: 5;
  font-size: 1.6rem;
  font-weight: 800;
}

/* --- zone secondaire --- */

.side-head { display: flex; flex-direction: column; gap: 6px; margin-bottom: 10px; }

.state-chip {
  align-self: flex-start;
  padding: 8px 14px;
  border-radius: 999px;
  font-weight: 800;
  font-size: 0.95rem;
  color: #fff;
  background: var(--bg-a);
  transition: background 1.2s ease;
}

.side-metric { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.side-metric b { font-size: 1.25rem; font-variant-numeric: tabular-nums; }

.global-progress {
  height: 12px;
  border-radius: 999px;
  background: rgba(31, 42, 51, 0.1);
  overflow: hidden;
  margin: 10px 0 6px;
}

.global-progress > span {
  display: block;
  height: 100%;
  background: var(--accent);
  transition: width 0.4s ease;
}

.task-list { list-style: none; margin: 6px 0 0; padding: 0 2px; overflow-y: auto; overflow-x: hidden; flex: 1; min-height: 0; }

.task-list li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 12px;
  border-radius: 14px;
  margin-bottom: 6px;
  background: rgba(31, 42, 51, 0.04);
  font-weight: 600;
  transition: background 0.25s ease, transform 0.25s ease;
}

.task-list li .li-emoji { font-size: 1.3rem; width: 26px; text-align: center; flex: 0 0 auto; }
.task-list li .li-name { display: block; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.task-list li .grow { min-width: 0; }
.task-list li .li-time { font-variant-numeric: tabular-nums; color: var(--ink-soft); font-size: 0.82rem; white-space: nowrap; }
.task-list li .li-time.over { color: var(--warn); font-weight: 800; }
.task-list li .li-sub { display: block; font-size: 0.74rem; color: var(--ink-soft); font-weight: 600; }
.task-list li.is-done { opacity: 0.55; }
.task-list li.is-done .li-name { text-decoration: line-through; }
.task-list li.is-skipped { opacity: 0.45; font-style: italic; }

.task-list li.is-active {
  background: #fff;
  box-shadow: 0 4px 14px rgba(20, 35, 45, 0.16);
  transform: scale(1.02);
  border-left: 6px solid var(--accent);
}

/* ---------------- adaptation telephone ---------------- */

@media (orientation: portrait) and (max-width: 600px) {
  .routine {
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: minmax(0, 7fr) minmax(150px, 3fr);
    gap: 8px;
    padding:
      max(8px, env(safe-area-inset-top))
      max(8px, env(safe-area-inset-right))
      max(8px, env(safe-area-inset-bottom))
      max(8px, env(safe-area-inset-left));
  }

  .routine-main,
  .routine-side { border-radius: 20px; }

  .routine-main { padding: 10px 12px 12px; }
  .routine-side { padding: 10px 12px; }

  .task-head { gap: 10px; }
  .task-visual {
    width: clamp(62px, 20vw, 88px);
    height: clamp(62px, 20vw, 88px);
    max-width: none;
    max-height: none;
    border-radius: 18px;
    font-size: clamp(2.2rem, 11vw, 3.4rem);
  }
  .task-title { font-size: clamp(1.25rem, 6.5vw, 1.8rem); }
  .task-title {
    display: -webkit-box;
    -webkit-box-orient: vertical;
    -webkit-line-clamp: 2;
    overflow: hidden;
  }
  .task-sub { margin-top: 3px; font-size: 0.76rem; }

  .timer-zone {
    grid-template-columns: minmax(82px, 0.85fr) minmax(150px, 1.15fr);
    gap: 6px;
    padding: 2px 0;
  }
  .hourglass { height: clamp(105px, 23vh, 190px); }
  .hourglass-wrap { padding-bottom: 22px; }
  .hourglass-caption { font-size: clamp(0.68rem, 3vw, 0.86rem); }
  .countdown { font-size: clamp(2.35rem, 13vw, 4.2rem); }
  .countdown.is-long { font-size: clamp(1.85rem, 9.5vw, 3.2rem); }
  .countdown-label { font-size: 0.66rem; letter-spacing: 0.05em; }
  #over-note { min-height: 1.4em; font-size: 0.7rem; }
  .task-progress { height: 9px; }
  .done-btn {
    width: 100%;
    min-height: clamp(58px, 9vh, 76px);
    border-radius: 19px;
    font-size: clamp(1.2rem, 6vw, 1.6rem);
    box-shadow: 0 7px 0 #26765a, var(--shadow-soft);
  }
  .done-btn:active { transform: translateY(5px); box-shadow: 0 2px 0 #26765a; }

  .side-head {
    display: grid;
    grid-template-columns: minmax(0, 1fr) minmax(0, 1fr);
    column-gap: 14px;
    row-gap: 3px;
    margin-bottom: 4px;
  }
  .state-chip,
  .global-progress,
  .side-head .small { grid-column: 1 / -1; }
  .state-chip { padding: 6px 10px; font-size: 0.78rem; }
  .side-metric { font-size: 0.72rem; }
  .side-metric b { font-size: 0.9rem; }
  .global-progress { height: 7px; margin: 4px 0 2px; }
  #progress-note { font-size: 0.67rem; }
  .list-hint { display: none; }
  .task-list { margin-top: 3px; }
  .task-list li { gap: 5px; padding: 5px 7px; margin-bottom: 3px; border-radius: 9px; font-size: 0.74rem; }
  .task-list li .li-emoji { width: 19px; font-size: 0.95rem; }
  .task-list li .li-time { font-size: 0.65rem; }
}

@media (orientation: landscape) and (max-height: 560px) {
  .routine {
    grid-template-columns: minmax(0, 1fr) minmax(180px, 31vw);
    grid-template-rows: minmax(0, 1fr);
    gap: 8px;
    padding:
      max(6px, env(safe-area-inset-top))
      max(6px, env(safe-area-inset-right))
      max(6px, env(safe-area-inset-bottom))
      max(6px, env(safe-area-inset-left));
  }

  .routine-main,
  .routine-side { border-radius: 18px; }

  .routine-main { padding: 7px 9px 9px; }
  .routine-side { padding: 7px 8px; }

  .task-head { gap: 8px; }
  .task-visual {
    width: clamp(46px, 17vh, 76px);
    height: clamp(46px, 17vh, 76px);
    max-width: none;
    max-height: none;
    border-radius: 13px;
    font-size: clamp(1.8rem, 11vh, 3rem);
    box-shadow: inset 0 0 0 2px rgba(0, 0, 0, 0.05);
  }
  .task-title { font-size: clamp(1.05rem, 7vh, 1.65rem); }
  .task-title,
  .task-sub { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .task-sub { margin-top: 1px; font-size: clamp(0.62rem, 2.7vh, 0.75rem); }

  .timer-zone {
    grid-template-columns: minmax(66px, 0.82fr) minmax(118px, 1.18fr);
    gap: 4px;
    padding: 0;
  }
  .hourglass { height: clamp(72px, 35vh, 122px); }
  .hourglass-wrap { padding-bottom: clamp(15px, 6vh, 21px); }
  .hourglass-caption { bottom: 0; font-size: clamp(0.58rem, 2.8vh, 0.76rem); }
  .countdown { font-size: clamp(1.9rem, 15vh, 3.6rem); }
  .countdown.is-long { font-size: clamp(1.55rem, 10.5vh, 2.7rem); }
  .countdown-label { font-size: clamp(0.52rem, 2.5vh, 0.66rem); letter-spacing: 0.04em; }
  #over-note { min-height: 1.15em; font-size: clamp(0.56rem, 2.6vh, 0.7rem); }
  .task-progress { height: 7px; }
  .done-btn {
    width: 100%;
    min-height: clamp(44px, 17vh, 60px);
    border-radius: 15px;
    font-size: clamp(1rem, 6.5vh, 1.45rem);
    box-shadow: 0 5px 0 #26765a, var(--shadow-soft);
  }
  .done-btn:active { transform: translateY(3px); box-shadow: 0 2px 0 #26765a; }

  .side-head { gap: 1px; margin-bottom: 2px; }
  .state-chip { padding: 4px 8px; font-size: clamp(0.62rem, 2.8vh, 0.74rem); }
  .side-metric { font-size: clamp(0.6rem, 2.6vh, 0.72rem); }
  .side-metric b { font-size: clamp(0.72rem, 3.5vh, 0.9rem); }
  .global-progress { height: 6px; margin: 3px 0 1px; }
  #progress-note { font-size: clamp(0.56rem, 2.5vh, 0.66rem); }
  .list-hint { display: none; }
  .task-list { margin-top: 2px; }
  .task-list li { gap: 4px; padding: 3px 5px; margin-bottom: 2px; border-radius: 7px; border-left-width: 3px; font-size: clamp(0.6rem, 2.7vh, 0.72rem); }
  .task-list li .li-emoji { width: 17px; font-size: 0.8rem; }
  .task-list li .li-time { font-size: 0.58rem; }
  .task-list li .li-sub { font-size: 0.56rem; }
  .display-only-note { padding: 5px; font-size: 0.62rem; }
}

/* ---------------- ecran de fin ---------------- */

.end-screen {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 18px;
  color: #fff;
  text-align: center;
  padding: 24px;
}

.end-screen .big { font-size: clamp(2rem, 7vw, 3.6rem); font-weight: 900; }
.end-screen .result { font-size: clamp(1.4rem, 4vw, 2.2rem); font-weight: 800; }

.end-card {
  background: var(--card);
  color: var(--ink);
  border-radius: var(--radius);
  padding: 18px 22px;
  box-shadow: var(--shadow);
  width: min(94%, 620px);
  text-align: left;
}

.confetti { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 40; }
.confetti i {
  position: absolute;
  width: 10px;
  height: 16px;
  border-radius: 3px;
  opacity: 0.9;
  animation: fall linear forwards;
}

@keyframes fall {
  from { transform: translateY(-10vh) rotate(0deg); }
  to { transform: translateY(110vh) rotate(720deg); }
}

/* ---------------- formulaires ---------------- */

label { display: block; font-weight: 700; margin-bottom: 6px; font-size: 0.92rem; }

input[type="text"], input[type="number"], input[type="time"], input[type="search"], select, textarea {
  width: 100%;
  min-height: 48px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 2px solid var(--line);
  background: #fff;
  font-family: inherit;
  font-size: 1rem;
  color: var(--ink);
}

input:focus, select:focus, textarea:focus { outline: 3px solid rgba(47, 125, 107, 0.35); border-color: var(--accent); }
textarea { min-height: 80px; resize: vertical; }
input[type="range"] { width: 100%; height: 40px; }

.field { margin-bottom: 14px; }
.field-inline { display: flex; gap: 12px; flex-wrap: wrap; }
.field-inline > .field { flex: 1 1 160px; margin-bottom: 0; }

.switch { display: flex; align-items: center; gap: 10px; font-weight: 700; cursor: pointer; min-height: 44px; }
.switch input { width: 26px; height: 26px; accent-color: var(--accent); }

.chip {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 6px 12px;
  border-radius: 999px;
  background: rgba(47, 125, 107, 0.12);
  color: var(--accent);
  font-weight: 700;
  font-size: 0.84rem;
}

.chip.warn { background: rgba(201, 115, 107, 0.16); color: #a4534b; }
.chip.neutral { background: rgba(31, 42, 51, 0.08); color: var(--ink-soft); }

/* ---------------- listes de configuration ---------------- */

.list { list-style: none; margin: 0; padding: 0; }

.list-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px;
  border-radius: var(--radius-sm);
  background: #fff;
  box-shadow: var(--shadow-soft);
  margin-bottom: 10px;
  touch-action: pan-y;
}

.list-item.dragging { opacity: 0.94; box-shadow: var(--shadow); }
.list-item.sort-dragging {
  cursor: grabbing;
  pointer-events: none;
  transition: none;
}

.sort-placeholder {
  list-style: none;
  border: 3px dashed var(--accent);
  border-radius: var(--radius-sm);
  background: rgba(47, 125, 107, 0.1);
  margin-bottom: 10px;
}

body.is-sorting, body.is-sorting * { cursor: grabbing !important; }
.list-item.drag-over { outline: 3px dashed var(--accent); }

.drag-handle {
  font-size: 1.5rem;
  color: var(--ink-soft);
  cursor: grab;
  padding: 6px 10px;
  touch-action: none;
  flex: 0 0 auto;
}

.drag-handle:focus-visible { outline: 3px solid rgba(47, 125, 107, 0.4); border-radius: 10px; }

.thumb {
  width: 56px;
  height: 56px;
  border-radius: 14px;
  background: #f2f5f4;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.8rem;
  overflow: hidden;
  flex: 0 0 auto;
}

.thumb img { width: 100%; height: 100%; object-fit: cover; }

.tabs { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 16px; }

.tab {
  padding: 10px 16px;
  border-radius: 999px;
  border: 0;
  background: rgba(255, 255, 255, 0.55);
  font-weight: 700;
  font-family: inherit;
  font-size: 0.95rem;
  cursor: pointer;
  min-height: 46px;
}

.tab.active { background: #fff; box-shadow: var(--shadow-soft); color: var(--accent); }

table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
th, td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--line); }
th { font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--ink-soft); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(140px, 1fr)); gap: 12px; }
.stat-box { background: rgba(31, 42, 51, 0.04); border-radius: var(--radius-sm); padding: 12px; }
.stat-box b { display: block; font-size: 1.4rem; font-variant-numeric: tabular-nums; }
.stat-box span { font-size: 0.8rem; color: var(--ink-soft); }

/* ---------------- modale et notifications ---------------- */

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(16, 26, 33, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 60;
  animation: fade 0.15s ease;
}

.modal {
  background: var(--card-solid);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  width: min(96%, 620px);
  max-height: 92dvh;
  overflow-y: auto;
  padding: 20px;
  animation: pop 0.18s ease;
}

.modal h2 { margin-top: 0; }
.modal-actions { display: flex; gap: 10px; justify-content: flex-end; flex-wrap: wrap; margin-top: 18px; }

.sheet { width: min(96%, 520px); }
.sheet .btn { width: 100%; text-align: left; }

@keyframes fade { from { opacity: 0; } to { opacity: 1; } }
@keyframes pop { from { opacity: 0; transform: translateY(14px) scale(0.98); } to { opacity: 1; transform: none; } }

#toasts {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: 8px;
  z-index: 80;
  pointer-events: none;
  width: min(94%, 520px);
}

.toast {
  background: rgba(23, 34, 42, 0.94);
  color: #fff;
  padding: 12px 18px;
  border-radius: 14px;
  font-weight: 600;
  box-shadow: var(--shadow);
  animation: pop 0.18s ease;
}

.toast.warn { background: #a4534b; }
.toast.ok { background: #2f7d6b; }

.audio-flag {
  position: fixed;
  right: 12px;
  bottom: 12px;
  background: rgba(23, 34, 42, 0.7);
  color: #fff;
  border-radius: 999px;
  padding: 6px 12px;
  font-size: 0.78rem;
  z-index: 30;
}

/* ---------------- routine personnalisee ---------------- */

.mode-switch { display: flex; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }

.mode-btn {
  flex: 1 1 180px;
  min-height: 76px;
  border-radius: var(--radius-sm);
  border: 3px solid transparent;
  background: #fff;
  font-family: inherit;
  font-weight: 800;
  font-size: 1rem;
  cursor: pointer;
  box-shadow: var(--shadow-soft);
}

.mode-btn.active { border-color: var(--accent); color: var(--accent); }

.quick-durations { display: flex; gap: 8px; flex-wrap: wrap; }
.quick-durations .btn { flex: 1 1 90px; }

.session-task .li-check { width: 30px; height: 30px; accent-color: var(--accent); flex: 0 0 auto; }
.session-task.excluded { opacity: 0.45; }

.summary-line {
  display: flex;
  justify-content: space-between;
  padding: 10px 0;
  font-weight: 700;
  border-top: 1px solid var(--line);
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  background: linear-gradient(180deg, rgba(255, 255, 255, 0), var(--card) 40%);
  padding-top: 20px;
  padding-bottom: 8px;
}

/* ---------------- divers ---------------- */

.empty {
  text-align: center;
  padding: 30px 20px;
  color: var(--ink-soft);
  font-weight: 600;
}

.badge-ok { color: #2f7d6b; font-weight: 800; }
.badge-late { color: #a4534b; font-weight: 800; }

.sync-state {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 12px;
  color: var(--ink-soft);
  font-size: 0.86rem;
  font-weight: 700;
}

.sync-dot {
  width: 10px;
  height: 10px;
  flex: 0 0 10px;
  border-radius: 50%;
  background: #aab4b2;
}

.sync-state.is-online .sync-dot { background: #2f9b75; box-shadow: 0 0 0 4px rgba(47, 155, 117, 0.14); }
.sync-state.is-offline .sync-dot { background: var(--warn); box-shadow: 0 0 0 4px rgba(164, 83, 75, 0.12); }

.routine.is-display-only .adult-btn,
.routine.is-display-only .done-btn,
.routine.is-display-only #resume-btn { display: none; }

.routine.is-display-only .task-list li { cursor: default; }
.routine.is-display-only .task-list li:active { transform: none; }

.display-only-note {
  text-align: center;
  padding: 12px;
  border-radius: var(--radius-small);
  background: rgba(255, 255, 255, 0.64);
  color: var(--ink-soft);
  font-size: 0.82rem;
  font-weight: 700;
}

.test-pass { color: #2f7d6b; }
.test-fail { color: #a4534b; font-weight: 800; }

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.01ms !important; transition-duration: 0.01ms !important; }
}

/* ---------------- liste latérale interactive ---------------- */

.list-hint {
  font-size: 0.76rem;
  color: var(--ink-soft);
  text-transform: uppercase;
  letter-spacing: 0.06em;
  font-weight: 700;
  margin: 4px 0 2px;
  opacity: 0.75;
}

.task-list li {
  cursor: pointer;
  border-left: 6px solid transparent;
}

.task-list li:active { transform: scale(0.985); }

/* Tâche commencée puis quittée : son temps est conservé. */
.task-list li.is-started {
  border-left-color: var(--state);
  background: rgba(255, 255, 255, 0.75);
}

.task-list li.is-started .li-time { color: var(--ink); font-weight: 700; }

.task-list li.is-unstructured {
  border: 2px dashed rgba(47, 125, 107, 0.42);
  background: rgba(220, 239, 242, 0.82);
  opacity: 1;
}

.task-list li.is-unstructured .li-name {
  font-weight: 850;
  text-decoration: none;
}

.task-list li.is-unstructured.is-unavailable {
  cursor: not-allowed;
  border-color: rgba(92, 105, 112, 0.35);
  background: rgba(220, 224, 226, 0.76);
  color: #69747a;
  opacity: 0.72;
}

.task-list li.is-unstructured.is-unavailable:active { transform: none; }
.task-list li.is-unstructured.is-unavailable .li-time { color: #8f3e38; font-weight: 800; }

.routine.is-unstructured-expired .countdown-label,
.routine.is-unstructured-expired #over-note {
  color: #9f302b;
  font-weight: 900;
}

.routine.is-unstructured-expired .done-btn {
  background: linear-gradient(180deg, #e46258, #b83d35);
  box-shadow: 0 12px 0 #842d28, var(--shadow);
  animation: imperative-pulse 1s ease-in-out infinite;
}

@keyframes imperative-pulse {
  0%, 100% { transform: scale(1); }
  50% { transform: scale(1.025); }
}

/* Ambiance : quelques accents suivent la couleur d'avance/retard. */
.global-progress > span { background: var(--state); }
.chip { background: color-mix(in srgb, var(--state) 18%, transparent); }

/* Tâche et commandes partagent la même ligne sans se superposer. */
.task-head { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; align-items: start; }
.task-head > .grow { align-self: center; }

.routine-controls {
  display: flex;
  justify-content: flex-end;
  align-items: center;
  gap: 8px;
  width: auto;
  flex: 0 0 auto;
  position: relative;
  z-index: 2;
  margin: 0;
}
.pause-btn { min-height: 64px; min-width: 120px; font-size: clamp(1.1rem, 2.4vw, 1.6rem); font-weight: 800; }
.routine-controls .pause-btn {
  min-height: 48px;
  min-width: 112px;
  padding: 8px 14px;
  font-size: 1.05rem;
  background: #fff4d5;
  color: #674709;
  border: 2px solid #bc943b;
}
.routine-controls .adult-btn { min-width: 48px; min-height: 48px; flex: 0 0 48px; font-size: 1.6rem; }
.routine-controls button { touch-action: manipulation; }
.routine.is-display-only .routine-controls { display: none; }
@media (max-height: 500px) and (orientation: landscape) {
  .pause-btn { min-height: 48px; }

}

@media (orientation: portrait) and (max-width: 600px) {
  .task-head { grid-template-columns: auto minmax(0, 1fr); }
  .task-head .task-visual { grid-row: 1 / 3; }
  .task-head .routine-controls { grid-column: 2; justify-self: end; }
}
/* Le flou de ces panneaux est décoratif : éviter une couche composée au-dessus
   des commandes dans les navigateurs mobiles en plein écran. */
.routine-main { backdrop-filter: none; }
