:root {
  --bg: #f5f5f7; --cell: #ebebef; --text: #111114; --muted: #8a8a93; --accent: #5b5bf6;
  --com: #8b5cf6; --dev: #10b981; --sys: #0ea5e9; --ev: #ec4899; --work: #f59e0b;
}
:root { color-scheme: light; }
:root[data-theme="dark"] { --bg: #000; --cell: #121216; --text: #f2f2f5; --muted: #6f6f78; --accent: #8080ff; color-scheme: dark; }
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) { --bg: #000; --cell: #121216; --text: #f2f2f5; --muted: #6f6f78; --accent: #8080ff; color-scheme: dark; }
}
* { box-sizing: border-box; margin: 0; -webkit-tap-highlight-color: transparent; }
html, body { height: 100%; background: var(--bg); color: var(--text); overscroll-behavior: none; }
body { font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", system-ui, sans-serif; -webkit-font-smoothing: antialiased; -webkit-user-select: none; user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }

#app {
  height: 100dvh; max-width: 640px; margin: 0 auto; display: flex; flex-direction: column;
  padding: calc(env(safe-area-inset-top) + 10px) 10px calc(env(safe-area-inset-bottom) + 10px);
}

header { display: flex; align-items: center; justify-content: space-between; padding: 4px 4px 14px; }
.title { font-size: 24px; font-weight: 800; letter-spacing: -.02em; display: flex; align-items: center; gap: 8px; }
.title i { width: 7px; height: 7px; border-radius: 50%; background: var(--accent); }
.nav { display: flex; gap: 6px; }
.nav button { width: 38px; height: 38px; border-radius: 50%; background: var(--cell); display: grid; place-items: center; }
.nav button:active { transform: scale(.92); }
.nav svg { width: 18px; height: 18px; fill: none; stroke: currentColor; stroke-width: 2.2; stroke-linecap: round; stroke-linejoin: round; }

.cal {
  flex: 1; min-height: 0; display: grid; gap: 4px;
  grid-template-columns: 30px repeat(5, minmax(0, 1fr));
  grid-template-rows: auto 1fr 1fr 6px 1fr 1fr;
}

.dh { grid-row: 1; text-align: center; padding: 2px 0 8px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.dh small { font-size: 11px; font-weight: 600; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.dh b { font-size: 17px; font-weight: 700; width: 32px; height: 32px; line-height: 32px; border-radius: 50%; }
.dh.today small { color: var(--accent); }
.dh.today b { background: var(--accent); color: #fff; }

.hr { grid-column: 1; font-size: 10.5px; font-weight: 600; color: var(--muted); padding-top: 2px; font-variant-numeric: tabular-nums; }

.bg { background: var(--cell); border-radius: 10px; opacity: .55; }

.blk {
  border-radius: 10px; padding: 7px 6px; overflow: hidden; z-index: 1;
  background: color-mix(in srgb, var(--c) 22%, var(--bg));
  border-top: 3px solid var(--c);
  display: flex; flex-direction: column; gap: 3px;
}
.blk b { font-size: 12.5px; font-weight: 800; color: var(--c); letter-spacing: .01em; }
.blk span { font-size: 11px; line-height: 1.25; font-weight: 500; overflow-wrap: break-word; -webkit-hyphens: auto; hyphens: auto; }
.blk.work { --c: var(--work); background: color-mix(in srgb, var(--work) 12%, var(--bg)); align-items: center; justify-content: center; }
.blk.work b, .blk.off b { writing-mode: vertical-rl; transform: rotate(180deg); font-size: 13px; letter-spacing: .08em; }
.blk.off { --c: var(--muted); background: transparent; border: 1.5px dashed var(--cell); align-items: center; justify-content: center; }

/* Jours en Y : jours en lignes, créneaux en colonnes */
.cal.y { grid-template-columns: 40px 1fr 1fr 6px 1fr 1fr; grid-template-rows: auto repeat(5, minmax(0, 1fr)); }
.cal.y .dh { padding: 0; justify-content: center; }
.cal.y .hr { padding: 0 0 6px 2px; }
.cal.y .blk.work b, .cal.y .blk.off b { writing-mode: horizontal-tb; transform: none; }
.cal.y .blk { border-top: 0; border-left: 3px solid var(--c); }
.cal.y .blk.off { border: 1.5px dashed var(--cell); }
.blk em { font-style: normal; font-size: 10.5px; font-weight: 600; color: var(--muted); margin-top: auto; font-variant-numeric: tabular-nums; }

/* --- Proportions : en-tête plus présent, liste plus compacte --- */
header { padding: 6px 2px 18px; }
.title { font-size: 28px; }
.nav { gap: 8px; }
.nav button { width: 48px; height: 48px; }
.nav svg { width: 22px; height: 22px; }
.title i { width: 8px; height: 8px; }

.cal.y { grid-template-rows: auto repeat(5, 84px); align-content: start; gap: 6px 4px; }
.cal.y .dh small { font-size: 10px; }
.cal.y .dh b { font-size: 15px; width: 28px; height: 28px; line-height: 28px; }
.cal.y .hr { font-size: 11px; }
.cal.y .blk { padding: 6px 7px; gap: 1px; }
.cal.y .blk b { font-size: 11.5px; }
.cal.y .blk span { font-size: 10.5px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.cal.y .blk em { font-size: 10px; }
.cal.y .blk.work b, .cal.y .blk.off b { font-size: 12px; }
.blk em { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.cal.y .blk { padding: 6px 5px 6px 6px; } .cal.y .blk em { letter-spacing: -.03em; }

/* --- Responsive : l'en-tête tient sur une ligne quelle que soit la largeur --- */
header { gap: 10px; }
.title { font-size: clamp(19px, 6.4vw, 28px); white-space: nowrap; min-width: 0; overflow: hidden; text-overflow: ellipsis; }
.nav { flex: none; gap: clamp(5px, 1.6vw, 8px); }
.nav button { width: clamp(38px, 11.5vw, 48px); height: clamp(38px, 11.5vw, 48px); }
.nav svg { width: clamp(18px, 5.5vw, 22px); height: clamp(18px, 5.5vw, 22px); }
.cal.y { grid-template-columns: 36px 1fr 1fr 4px 1fr 1fr; }

/* --- Paramètres (feuille du bas) --- */
.scrim { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 10; }
.scrim.anim { animation: fade .2s; }
.sheet.anim { animation: up .25s cubic-bezier(.2, .8, .2, 1); }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11; max-width: 640px; margin: 0 auto;
  background: var(--bg); border-radius: 24px 24px 0 0; box-shadow: 0 -10px 40px rgba(0, 0, 0, .25);
  padding: 10px 18px calc(env(safe-area-inset-bottom) + 18px);
}
.grab { width: 38px; height: 5px; border-radius: 3px; background: var(--muted); opacity: .4; margin: 0 auto 14px; }
.sheet h2 { font-size: 20px; font-weight: 800; margin-bottom: 14px; }
.sheet label { display: block; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); margin: 14px 2px 8px; }
.seg { display: flex; background: var(--cell); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; text-align: center; padding: 10px 4px; border-radius: 9px; font-size: 14px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--bg); color: var(--text); box-shadow: 0 1px 4px rgba(0, 0, 0, .15); }
.done { display: block; width: 100%; margin-top: 22px; padding: 14px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 700; font-size: 16px; text-align: center; }
@keyframes up { from { transform: translateY(100%); } }
@keyframes fade { from { opacity: 0; } }
.nav button svg circle { fill: none; }
