/* Aylan — design inspiré d'Apple : réponse immédiate, matières translucides,
   typographie à pistes (tracking) adaptées à la taille, respect des préférences d'accessibilité. */

:root {
  --bg: #F7F3EE;
  --card: #FFFFFF;
  --ink: #1C1B2E;
  --ink2: #6B6A7C;
  --line: rgba(28, 27, 46, .09);
  --accent: #6C7CF0;
  --accent-soft: rgba(108, 124, 240, .12);
  --night: #3A3F7A;
  --night-soft: rgba(58, 63, 122, .12);
  --sun: #F2A93B;
  --danger: #D9453F;
  --glass: rgba(247, 243, 238, .72);
  --scrim: rgba(12, 12, 28, .38);
  --shadow: 0 1px 2px rgba(28, 27, 46, .05), 0 8px 24px rgba(28, 27, 46, .06);
  --shadow-lg: 0 -8px 40px rgba(28, 27, 46, .18);
  --tabbar-h: 58px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0D0E1A;
    --card: #171829;
    --ink: #F2F2F8;
    --ink2: #9A9AB2;
    --line: rgba(255, 255, 255, .09);
    --accent: #8896FF;
    --accent-soft: rgba(136, 150, 255, .16);
    --night: #6A75E0;
    --night-soft: rgba(106, 117, 224, .18);
    --glass: rgba(13, 14, 26, .7);
    --scrim: rgba(0, 0, 0, .55);
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 8px 24px rgba(0, 0, 0, .25);
    --shadow-lg: 0 -8px 40px rgba(0, 0, 0, .5);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html { -webkit-text-size-adjust: 100%; background: var(--bg); }
html.sheet-open, html.sheet-open body { overflow: hidden; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font: 17px/1.4 -apple-system, BlinkMacSystemFont, "SF Pro Text", system-ui, "Segoe UI", sans-serif;
  letter-spacing: 0;
  -webkit-font-smoothing: antialiased;
  min-height: 100dvh;
  overscroll-behavior-y: none;
  -webkit-touch-callout: none;
}

button, input, select { font: inherit; color: inherit; }
button { border: 0; background: none; padding: 0; cursor: pointer; -webkit-user-select: none; user-select: none; touch-action: manipulation; }
input, select { font-size: 16px; /* évite le zoom automatique d'iOS */ }

h1, h2, h3, p { margin: 0; }
h1 { font-size: 34px; line-height: 1.05; letter-spacing: -0.03em; font-weight: 700; }
h2 { font-size: 20px; line-height: 1.2; letter-spacing: -0.015em; font-weight: 650; }
.small { font-size: 13px; letter-spacing: 0.005em; color: var(--ink2); }
.sec-title { font-size: 13px; text-transform: uppercase; letter-spacing: .06em; color: var(--ink2); font-weight: 600; margin: 26px 4px 10px; }

#app { padding: calc(var(--safe-t) + 18px) 18px calc(var(--tabbar-h) + var(--safe-b) + 28px); max-width: 560px; margin: 0 auto; }
.view[hidden] { display: none; }

/* Retour immédiat au toucher (pointer-down), pas à la fin du geste */
[data-press] { transition: transform 120ms ease-out, background-color 120ms ease-out; }
[data-press]:active { transform: scale(.97); }

/* ---------- En-tête ---------- */
.head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 14px; }
.head .age { font-size: 15px; color: var(--ink2); font-weight: 500; }
.head-r { display: flex; align-items: center; gap: 12px; }
.avatar { width: 54px; height: 54px; border-radius: 50%; object-fit: cover; box-shadow: var(--shadow); border: 2px solid var(--card); flex: none; }
.avatar.sm { width: 36px; height: 36px; border-width: 1px; }
.eyebrow { font-size: 13px; color: var(--ink2); margin-bottom: 4px; }
.eyebrow::first-letter { text-transform: uppercase; }

/* ---------- Carte héros ---------- */
.hero { background: var(--card); border-radius: 28px; padding: 22px 20px 20px; box-shadow: var(--shadow); text-align: center; }
.ring-wrap { position: relative; width: 220px; height: 220px; margin: 2px auto 6px; }
.ring { width: 100%; height: 100%; display: block; }
.ring-track { fill: none; stroke: var(--accent-soft); stroke-width: 14; }
.ring-bar { fill: none; stroke: var(--accent); stroke-width: 14; stroke-linecap: round; transition: stroke-dashoffset 600ms cubic-bezier(.2, .8, .2, 1); }
.ring.night .ring-track { stroke: var(--night-soft); }
.ring.night .ring-bar { stroke: var(--night); }
.ring-center { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0 34px; }
.ring-emoji { font-size: 30px; line-height: 1; margin-bottom: 6px; }
.ring-main { font-size: 26px; line-height: 1.1; letter-spacing: -0.025em; font-weight: 700; }
.ring-sub { font-size: 14px; color: var(--ink2); margin-top: 4px; }
.hero-line { font-size: 17px; letter-spacing: -0.01em; margin: 4px 6px 16px; }
.hero-line b { font-weight: 650; }
.hero-line.late b { color: var(--sun); }

.btn-primary {
  display: block; width: 100%; min-height: 56px; border-radius: 20px;
  background: var(--accent); color: #fff; font-weight: 650; font-size: 18px; letter-spacing: -0.01em;
  box-shadow: 0 6px 18px color-mix(in srgb, var(--accent) 38%, transparent);
}
.btn-primary.night { background: var(--night); box-shadow: 0 6px 18px color-mix(in srgb, var(--night) 38%, transparent); }
@media (prefers-color-scheme: dark) { .btn-primary { color: #0D0E1A; } .btn-primary.night { color: #fff; } }

.quick { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.quick button {
  background: var(--card); border-radius: 20px; min-height: 64px; box-shadow: var(--shadow);
  display: flex; align-items: center; justify-content: center; gap: 10px; font-weight: 600; font-size: 17px; letter-spacing: -0.01em;
}
.quick .em { font-size: 24px; }

/* ---------- Listes ---------- */
.list { background: var(--card); border-radius: 22px; box-shadow: var(--shadow); overflow: hidden; }
.row { display: flex; align-items: center; gap: 12px; width: 100%; padding: 13px 16px; text-align: left; min-height: 56px; }
.row + .row { border-top: 1px solid var(--line); }
.row .em { font-size: 24px; width: 30px; text-align: center; flex: none; }
.row .grow { flex: 1; min-width: 0; }
.row .t { font-weight: 600; letter-spacing: -0.01em; }
.row .s { font-size: 14px; color: var(--ink2); }
.row .time { font-variant-numeric: tabular-nums; color: var(--ink2); font-size: 15px; flex: none; }
.row.next { background: var(--accent-soft); }
.row.next .time { color: var(--accent); font-weight: 650; }
button.row:active { background: var(--accent-soft); }
.empty { padding: 22px 18px; text-align: center; color: var(--ink2); font-size: 15px; }
.tag { display: inline-block; font-size: 11px; font-weight: 650; letter-spacing: .04em; text-transform: uppercase; color: var(--accent); background: var(--accent-soft); border-radius: 999px; padding: 2px 8px; margin-left: 6px; vertical-align: 2px; }
.note { font-size: 13px; color: var(--ink2); margin: 10px 6px 0; line-height: 1.4; }

/* ---------- Stats ---------- */
.card { background: var(--card); border-radius: 22px; box-shadow: var(--shadow); padding: 18px; }
.chart { width: 100%; height: auto; display: block; }
.chart text { font: 600 11px -apple-system, system-ui, sans-serif; fill: var(--ink2); }
.chart .val { fill: var(--ink); font-size: 11px; }
.bar-night { fill: var(--night); }
.bar-nap { fill: var(--accent); }
.legend { display: flex; gap: 16px; font-size: 13px; color: var(--ink2); margin-top: 8px; }
.legend i { display: inline-block; width: 10px; height: 10px; border-radius: 3px; margin-right: 6px; }
.kpis { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 12px; }
.kpi { background: var(--card); border-radius: 20px; box-shadow: var(--shadow); padding: 14px 16px; }
.kpi .n { font-size: 26px; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.kpi .l { font-size: 13px; color: var(--ink2); margin-top: 2px; }

/* ---------- Réglages & champs ---------- */
.field-label { font-size: 13px; color: var(--ink2); font-weight: 600; margin: 16px 2px 8px; }
.field { width: 100%; min-height: 48px; padding: 0 14px; background: var(--bg); border: 1px solid var(--line); border-radius: 14px; appearance: none; -webkit-appearance: none; }
.field:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.field.hide { display: none; }
.set-row { display: flex; align-items: center; gap: 12px; padding: 12px 16px; min-height: 56px; }
.set-row + .set-row { border-top: 1px solid var(--line); }
.set-row label { flex: 1; }
.set-row .field { width: auto; min-width: 150px; text-align: right; background: transparent; border-color: transparent; padding: 0 4px; }
.btn-line { width: 100%; text-align: left; padding: 14px 16px; min-height: 52px; font-weight: 500; }
.btn-line + .btn-line, .set-row + .btn-line { border-top: 1px solid var(--line); }
.btn-line.danger { color: var(--danger); }

/* ---------- Barre d'onglets : matière translucide ---------- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  display: grid; grid-template-columns: repeat(3, 1fr);
  padding: 6px 12px calc(6px + var(--safe-b));
  background: var(--glass);
  -webkit-backdrop-filter: blur(22px) saturate(180%);
  backdrop-filter: blur(22px) saturate(180%);
  border-top: 1px solid var(--line);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; min-height: 46px; color: var(--ink2); font-size: 11px; font-weight: 600; letter-spacing: .01em; }
.tab svg { width: 24px; height: 24px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.tab.on { color: var(--accent); }

/* ---------- Toast ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--tabbar-h) + var(--safe-b) + 14px); z-index: 40;
  transform: translate(-50%, 16px); opacity: 0; pointer-events: none;
  transition: transform 260ms cubic-bezier(.2, .9, .3, 1.1), opacity 180ms ease;
  width: min(92vw, 520px);
}
#toast.show { transform: translate(-50%, 0); opacity: 1; pointer-events: auto; }
.toast-in { display: flex; align-items: center; gap: 4px; padding: 6px 6px 6px 18px; border-radius: 20px; background: rgba(28, 27, 46, .92); color: #fff; box-shadow: 0 10px 30px rgba(0, 0, 0, .25); -webkit-backdrop-filter: blur(14px); backdrop-filter: blur(14px); }
.toast-in span { flex: 1; font-size: 15px; letter-spacing: -0.005em; padding: 6px 0; }
.toast-in button { min-height: 44px; padding: 0 12px; font-weight: 650; font-size: 15px; color: #B9C1FF; border-radius: 14px; }

/* ---------- Feuille (bottom sheet) ---------- */
#sheet-root .scrim { position: fixed; inset: 0; z-index: 50; background: var(--scrim); opacity: 0; touch-action: none; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 51; max-width: 560px; margin: 0 auto;
  background: var(--card); border-radius: 28px 28px 0 0; box-shadow: var(--shadow-lg);
  max-height: 88dvh; display: flex; flex-direction: column; will-change: transform;
  padding-bottom: var(--safe-b);
}
.sheet-grab { padding: 10px 0 2px; display: flex; justify-content: center; touch-action: none; cursor: grab; }
.grabber { width: 38px; height: 5px; border-radius: 3px; background: var(--line); background: color-mix(in srgb, var(--ink) 18%, transparent); }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 4px 20px 6px; touch-action: none; }
.sheet-head h2 { letter-spacing: -0.02em; }
.icon-btn { width: 36px; height: 36px; border-radius: 50%; background: var(--bg); color: var(--ink2); font-size: 20px; line-height: 1; display: grid; place-items: center; }
.sheet-body { overflow-y: auto; overscroll-behavior: contain; padding: 0 20px 20px; -webkit-overflow-scrolling: touch; }

.seg { display: flex; gap: 4px; padding: 4px; background: var(--bg); border-radius: 14px; }
.seg button { flex: 1; min-height: 42px; border-radius: 11px; font-weight: 600; font-size: 15px; color: var(--ink2); transition: background-color 120ms, color 120ms; }
.seg button.on { background: var(--card); color: var(--ink); box-shadow: 0 1px 3px rgba(0, 0, 0, .12); }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 40px; padding: 0 14px; border-radius: 999px; background: var(--bg); border: 1px solid var(--line); font-size: 15px; font-weight: 550; }
.chip.on { background: var(--accent); border-color: var(--accent); color: #fff; }
@media (prefers-color-scheme: dark) { .chip.on { color: #0D0E1A; } }
.stepper { display: flex; align-items: center; justify-content: center; gap: 18px; margin: 6px 0 4px; }
.stepper button { width: 52px; height: 52px; border-radius: 50%; background: var(--bg); font-size: 26px; line-height: 1; }
.stepper output { min-width: 110px; text-align: center; font-size: 32px; font-weight: 700; letter-spacing: -0.03em; font-variant-numeric: tabular-nums; }
.btn-save { margin-top: 22px; }
.btn-ghost { width: 100%; margin-top: 10px; min-height: 48px; border-radius: 16px; font-weight: 600; color: var(--danger); }
.err { color: var(--danger); font-size: 14px; margin-top: 10px; }

/* ---------- Accessibilité ---------- */
@media (prefers-reduced-motion: reduce) {
  [data-press] { transition: none; }
  [data-press]:active { transform: none; opacity: .7; }
  .ring-bar { transition: none; }
  #toast { transition: opacity 150ms ease; transform: translate(-50%, 0); }
  .scrim, .sheet { transition: opacity 180ms ease; }
}
@media (prefers-reduced-transparency: reduce) {
  .tabbar { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; }
  .toast-in { background: #1C1B2E; -webkit-backdrop-filter: none; backdrop-filter: none; }
}
@media (prefers-contrast: more) {
  :root { --line: rgba(128, 128, 128, .55); --ink2: color-mix(in srgb, var(--ink) 75%, var(--bg)); }
  .tabbar { background: var(--bg); -webkit-backdrop-filter: none; backdrop-filter: none; border-top-color: var(--ink2); }
}

/* ---------- Cadran 24 h ---------- */
.dial svg { width: 100%; max-width: 300px; display: block; margin: 0 auto; }
.dial-track { fill: none; stroke: var(--accent-soft); stroke-width: 14; }
.dial-arc { fill: none; stroke-width: 14; stroke-linecap: round; }
.dial-arc.dn { stroke: var(--night); }
.dial-arc.dp { stroke: var(--accent); }
.dial-arc.dg { stroke: var(--accent); stroke-width: 12; stroke-dasharray: 2 7; opacity: .75; }
.dial-bed { fill: var(--night); }
.dial-moon { fill: #fff; font-size: 11px; }
.dial-tick { font: 600 10px -apple-system, system-ui, sans-serif; fill: var(--ink2); }
.dial-now { fill: var(--sun); stroke: var(--card); stroke-width: 3; }
.dial-big { font: 700 24px -apple-system, system-ui, sans-serif; letter-spacing: -0.03em; fill: var(--ink); }
.dial-sub { font: 500 11px -apple-system, system-ui, sans-serif; fill: var(--ink2); }
.dial .legend { justify-content: center; }

/* ---------- Mode nuit étoilée (pendant un dodo) ---------- */
.hero.sky {
  color: #F2F2FA;
  background:
    radial-gradient(1.6px 1.6px at 12% 18%, rgba(255,255,255,.85), transparent 60%),
    radial-gradient(1.2px 1.2px at 82% 12%, rgba(255,255,255,.7), transparent 60%),
    radial-gradient(1.4px 1.4px at 91% 46%, rgba(255,255,255,.6), transparent 60%),
    radial-gradient(1.2px 1.2px at 8% 62%, rgba(255,255,255,.6), transparent 60%),
    radial-gradient(1.6px 1.6px at 70% 84%, rgba(255,255,255,.7), transparent 60%),
    radial-gradient(1.2px 1.2px at 30% 90%, rgba(255,255,255,.55), transparent 60%),
    linear-gradient(180deg, #1B1F4B, #0F1130);
  transition: background-color 300ms;
}
.hero.sky .ring-track { stroke: rgba(255, 255, 255, .12); }
.hero.sky .ring-bar { stroke: #A9B3FF; }
.hero.sky .ring-sub, .hero.sky .hero-line { color: rgba(242, 242, 250, .72); }
.hero.sky .hero-line b { color: #fff; }
.hero.sky .btn-primary, .hero.sky .btn-primary.night { background: #8896FF; color: #0D0E1A; box-shadow: 0 6px 18px rgba(136, 150, 255, .35); }

/* ---------- Verrouillage par code ---------- */
.avatar.lg { width: 84px; height: 84px; border-width: 3px; }
#lock {
  position: fixed; inset: 0; z-index: 100; display: grid; place-items: center; padding: 24px; color: #F2F2FA;
  background:
    radial-gradient(1.6px 1.6px at 14% 16%, rgba(255,255,255,.8), transparent 60%),
    radial-gradient(1.3px 1.3px at 84% 10%, rgba(255,255,255,.65), transparent 60%),
    radial-gradient(1.5px 1.5px at 92% 52%, rgba(255,255,255,.55), transparent 60%),
    radial-gradient(1.2px 1.2px at 7% 70%, rgba(255,255,255,.55), transparent 60%),
    radial-gradient(1.5px 1.5px at 66% 90%, rgba(255,255,255,.6), transparent 60%),
    linear-gradient(180deg, #1B1F4B, #0D0F2B);
}
.lock-in { width: 100%; max-width: 320px; text-align: center; }
.lock-in .avatar { margin: 0 auto 12px; display: block; border-color: rgba(255,255,255,.25); }
.lock-emoji { font-size: 54px; margin-bottom: 8px; }
.lock-in h2 { color: #fff; font-size: 26px; letter-spacing: -0.025em; }
.lock-sub { color: rgba(242,242,250,.7); margin: 4px 0 18px; font-size: 15px; }
.lock-forgot { margin-top: 18px; min-height: 44px; padding: 0 14px; font-size: 14px; color: rgba(242,242,250,.65); }

.pad-dots { display: flex; justify-content: center; gap: 16px; margin: 6px 0 10px; }
.pad-dots i { width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--ink2); transition: background-color 90ms, border-color 90ms; }
.pad-dots i.on { background: var(--accent); border-color: var(--accent); }
#lock .pad-dots i { border-color: rgba(255,255,255,.6); }
#lock .pad-dots i.on { background: #fff; border-color: #fff; }
.pad-msg { min-height: 20px; font-size: 14px; color: var(--danger); margin-bottom: 8px; }
#lock .pad-msg { color: #FFB4A8; }
.pad-keys { display: grid; grid-template-columns: repeat(3, 72px); gap: 14px; justify-content: center; }
.pad-keys button { width: 72px; height: 72px; border-radius: 50%; background: var(--bg); color: var(--ink); font-size: 28px; font-weight: 500; font-variant-numeric: tabular-nums; }
#lock .pad-keys button { background: rgba(255,255,255,.12); color: #fff; }
#lock .pad-keys button:active { background: rgba(255,255,255,.28); }
.shake { animation: pad-shake 360ms cubic-bezier(.36, .07, .19, .97); }
@keyframes pad-shake { 10%, 90% { transform: translateX(-2px); } 20%, 80% { transform: translateX(4px); } 30%, 50%, 70% { transform: translateX(-7px); } 40%, 60% { transform: translateX(7px); } }
@media (prefers-reduced-motion: reduce) { .shake { animation: none; } }
