:root {
  --bg: #0c0e11;
  --rail: #121519;
  --surface: #181c21;
  --surface-2: #20252c;
  --line: #2a3038;
  --text: #eef1f4;
  --muted: #8b95a1;
  --accent: #7fd4c1;
  --accent-ink: #062019;
  --danger: #ff6b5e;
  --tile: 132px;          /* taille du logo, ajustée par les réglages */
  --radius: 28px;
  --gap: 28px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", sans-serif;
  color-scheme: dark;
}
body[data-size="m"]  { --tile: 104px; --gap: 22px; }
body[data-size="xl"] { --tile: 168px; --gap: 34px; }

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overflow: hidden; user-select: none; -webkit-user-select: none; }
button { font: inherit; color: inherit; background: none; border: 0; cursor: pointer; }
svg { width: 26px; height: 26px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; flex: none; }

.app { display: grid; grid-template-columns: 300px 1fr; height: 100dvh; }

/* ---------- colonne des catégories ---------- */
.rail { min-width: 0; background: var(--rail); border-right: 1px solid var(--line); display: flex; flex-direction: column; padding: 28px 16px 20px; min-height: 0; }
.clock { padding: 0 14px 26px; }
.clock span { display: block; font-size: 56px; font-weight: 300; letter-spacing: -1px; line-height: 1; font-variant-numeric: tabular-nums; }
.clock small { display: block; margin-top: 8px; color: var(--muted); font-size: 17px; text-transform: capitalize; }
.cats { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 6px; scrollbar-width: none; }
.cat { display: flex; align-items: center; gap: 16px; width: 100%; min-height: 68px; padding: 0 18px; border-radius: 18px; color: var(--muted); font-size: 19px; text-align: left; transition: background .2s, color .2s; }
.cat .name { flex: 1; line-height: 1.2; }
.cat .count { font-size: 15px; font-variant-numeric: tabular-nums; opacity: .7; }
.cat:active { background: var(--surface-2); }
.cat.on { background: var(--surface-2); color: var(--text); }
.cat.on svg { color: var(--accent); }
.rail-actions { padding-top: 14px; border-top: 1px solid var(--line); }
.rail-btn { display: flex; align-items: center; gap: 16px; width: 100%; min-height: 60px; padding: 0 18px; border-radius: 18px; color: var(--muted); font-size: 18px; }
.rail-btn:active { background: var(--surface-2); }
body.editing .rail-btn { color: var(--accent); }

/* ---------- grille ---------- */
.main { display: flex; flex-direction: column; min-width: 0; min-height: 0; }
.top { display: flex; align-items: center; gap: 16px; padding: 34px 48px 8px; min-height: 104px; }
.top h1 { margin: 0; font-size: 34px; font-weight: 600; letter-spacing: -.3px; flex: 1; }
.top-tools { display: flex; gap: 10px; }
.edit-only { display: none !important; }
body.editing .edit-only { display: flex !important; }
.edit-only.tile { display: none !important; }
body.editing .edit-only.tile { display: flex !important; }

.grid { flex: 1; overflow-y: auto; padding: 24px 48px 56px; display: grid; grid-template-columns: repeat(auto-fill, minmax(calc(var(--tile) + 36px), 1fr)); gap: var(--gap) 12px; align-content: start; touch-action: pan-y; }
.grid.slide-l { animation: in-l .28s ease-out; }
.grid.slide-r { animation: in-r .28s ease-out; }
@keyframes in-l { from { opacity: 0; transform: translateX(40px); } }
@keyframes in-r { from { opacity: 0; transform: translateX(-40px); } }

.tile { position: relative; display: flex; flex-direction: column; align-items: center; gap: 14px; text-decoration: none; color: var(--text); padding: 6px 0; }
.plate { width: var(--tile); height: var(--tile); border-radius: var(--radius); background: var(--surface); display: grid; place-items: center; overflow: hidden; transition: transform .15s ease; box-shadow: inset 0 0 0 1px rgba(255,255,255,.06); }
.plate img { width: 62%; height: 62%; object-fit: contain; border-radius: 14%; }
.plate.full img { width: 100%; height: 100%; border-radius: 0; object-fit: cover; }
.plate .letter { font-size: calc(var(--tile) * .42); font-weight: 600; color: var(--text); }
.tile:active .plate { transform: scale(.93); }
.tile .label { font-size: 18px; max-width: calc(var(--tile) + 30px); text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: #d7dce2; }

.tile.add .plate { background: transparent; box-shadow: inset 0 0 0 2px var(--line); color: var(--muted); }
.tile.add svg { width: 44px; height: 44px; }

/* actions en mode édition */
.tile .tools { display: none; position: absolute; top: -6px; left: 50%; transform: translateX(-50%); width: calc(var(--tile) + 20px); justify-content: space-between; }
body.editing .tile .tools { display: flex; }
body.editing .tile:not(.add) .plate { animation: wobble .5s ease-in-out infinite alternate; }
@keyframes wobble { from { transform: rotate(-1.2deg); } to { transform: rotate(1.2deg); } }
.tools button { width: 44px; height: 44px; border-radius: 50%; background: #2c333c; display: grid; place-items: center; box-shadow: 0 2px 8px rgba(0,0,0,.5); }
.tools button svg { width: 20px; height: 20px; }
.tools .t-del { background: var(--danger); color: #fff; }
.tile .move { display: none; gap: 8px; }
body.editing .tile .move { display: flex; }
.move button { width: 52px; height: 40px; border-radius: 12px; background: var(--surface-2); display: grid; place-items: center; }
.move button svg { width: 20px; height: 20px; }
.move button:disabled { opacity: .25; }

.empty { grid-column: 1 / -1; color: var(--muted); font-size: 19px; padding: 40px 0; }

/* ---------- boutons ---------- */
.pill { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 52px; padding: 0 22px; border-radius: 16px; background: var(--surface-2); font-size: 17px; white-space: nowrap; }
.pill:active { filter: brightness(1.2); }
.pill.accent { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.pill.danger { background: transparent; color: var(--danger); box-shadow: inset 0 0 0 1.5px currentColor; }
.pill:disabled { opacity: .5; }

/* ---------- fenêtres ---------- */
dialog.sheet { width: min(720px, 94vw); max-height: 90dvh; border: 1px solid var(--line); border-radius: 26px; background: var(--surface); color: var(--text); padding: 30px 32px 26px; }
dialog.sheet.small { width: min(560px, 94vw); }
dialog::backdrop { background: rgba(4,6,8,.7); backdrop-filter: blur(4px); }
dialog[open] { animation: pop .18s ease-out; }
@keyframes pop { from { opacity: 0; transform: translateY(12px); } }
dialog h2 { margin: 0 0 22px; font-size: 26px; font-weight: 600; }
dialog label, .field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; font-size: 15px; color: var(--muted); }
input, select { font: inherit; font-size: 19px; color: var(--text); background: var(--bg); border: 1px solid var(--line); border-radius: 14px; min-height: 56px; padding: 0 16px; width: 100%; user-select: text; }
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
details { margin-bottom: 18px; color: var(--muted); }
summary { cursor: pointer; min-height: 40px; font-size: 16px; }
details label { margin-top: 10px; }
.hint { margin: 0; font-size: 15px; color: var(--muted); min-height: 1.2em; }
.link-preview { display: flex; gap: 22px; align-items: flex-start; margin-bottom: 4px; }
.plate.big { --tile: 132px; flex: none; }
.lp-side { flex: 1; display: flex; flex-direction: column; gap: 10px; }
.lp-side label { margin-bottom: 0; }
.lp-side .pill { align-self: flex-start; }
.dlg-actions { display: flex; gap: 10px; align-items: center; margin-top: 8px; flex-wrap: wrap; }
.grow { flex: 1; }
.row { display: flex; gap: 10px; flex-wrap: wrap; }
.check { flex-direction: row !important; align-items: center; gap: 14px !important; font-size: 18px !important; color: var(--text) !important; min-height: 56px; }
.check input { width: 26px; height: 26px; min-height: 0; accent-color: var(--accent); }
.pill.file { margin: 0; color: var(--text); font-size: 17px; flex-direction: row; }
.seg { display: flex; background: var(--bg); border-radius: 16px; padding: 4px; border: 1px solid var(--line); }
.seg button { flex: 1; min-height: 50px; border-radius: 12px; font-size: 17px; color: var(--muted); }
.seg button.on { background: var(--surface-2); color: var(--text); }

.cat-list { list-style: none; margin: 0 0 14px; padding: 0; display: flex; flex-direction: column; gap: 8px; max-height: 56dvh; overflow-y: auto; }
.cat-list li { display: flex; align-items: center; gap: 8px; background: var(--bg); border: 1px solid var(--line); border-radius: 16px; padding: 6px; }
.cat-list input { border: 0; background: transparent; min-height: 52px; flex: 1; }
.icon-btn { width: 52px; height: 52px; border-radius: 12px; display: grid; place-items: center; background: var(--surface-2); flex: none; }
.icon-btn:disabled { opacity: .25; }
.icon-btn.danger { color: var(--danger); background: transparent; }
.icon-pick { display: grid; grid-template-columns: repeat(auto-fill, minmax(72px, 1fr)); gap: 10px; margin-bottom: 14px; }
.icon-pick button { height: 72px; border-radius: 16px; background: var(--bg); border: 1px solid var(--line); display: grid; place-items: center; }
.icon-pick button.on { border-color: var(--accent); color: var(--accent); }
.icon-pick svg { width: 32px; height: 32px; }

.toast { position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 30px); background: #2c333c; color: var(--text); padding: 16px 26px; border-radius: 16px; font-size: 18px; opacity: 0; pointer-events: none; transition: .25s; }
.toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- écrans étroits (téléphone pour préparer le menu) ---------- */
@media (max-width: 820px) {
  .app { grid-template-columns: minmax(0,1fr); grid-template-rows: auto 1fr; }
  .rail { flex-direction: row; align-items: center; padding: 10px 12px; border-right: 0; border-bottom: 1px solid var(--line); gap: 8px; }
  .clock { display: none; }
  .cats { flex-direction: row; overflow-x: auto; overflow-y: hidden; }
  .cat { flex: none; width: auto; min-height: 52px; font-size: 16px; gap: 10px; }
  .cat .count { display: none; }
  .rail-actions { border: 0; padding: 0; }
  .rail-btn span { display: none; }
  .rail-btn { width: 52px; padding: 0; justify-content: center; }
  .top { padding: 18px 20px 0; min-height: 0; flex-wrap: wrap; }
  .top h1 { font-size: 26px; }
  .grid { padding: 18px 20px 40px; --tile: 84px; --radius: 22px; gap: 22px 8px; }
  .tile .label { font-size: 15px; }
  .link-preview { flex-direction: column; }
}

.alts { display: flex; gap: 10px; overflow-x: auto; padding: 2px 2px 6px; min-height: 8px; scrollbar-width: thin; }
.alts button { flex: none; width: 72px; height: 72px; border-radius: 18px; overflow: hidden; box-shadow: inset 0 0 0 1px var(--line); }
.alts button img { width: 100%; height: 100%; object-fit: cover; display: block; }
.alts button.on { outline: 3px solid var(--accent); outline-offset: 2px; }
.row input { flex: 1; min-width: 180px; }
