:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #6b6b70;
  --tile: #ececef;
  --bar: rgba(255, 255, 255, .82);
  --accent: #0a7cff;
  --gap: 2px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  color-scheme: light dark;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #000000;
    --fg: #f2f2f4;
    --muted: #8e8e93;
    --tile: #1c1c1e;
    --bar: rgba(0, 0, 0, .78);
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--fg); }
body {
  font: 16px/1.35 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  overscroll-behavior-y: none;
}
button { font: inherit; color: inherit; background: none; border: 0; padding: 0; cursor: pointer; }
[hidden] { display: none !important; }

/* Connexion */
#login { min-height: 100dvh; display: grid; place-items: center; padding: 24px; }
#loginForm { width: min(320px, 100%); display: grid; gap: 14px; justify-items: center; }
#loginForm .logo { width: 84px; height: 84px; border-radius: 20px; margin-bottom: 10px; }
#loginForm input {
  width: 100%; font-size: 18px; padding: 14px 16px; border-radius: 14px;
  border: 1px solid color-mix(in srgb, var(--fg) 15%, transparent); background: var(--tile); color: var(--fg);
  text-align: center; outline: none;
}
#loginForm input:focus { border-color: var(--accent); }
#loginForm button[type=submit] {
  width: 100%; padding: 14px; border-radius: 14px; background: var(--accent); color: #fff; font-weight: 600; font-size: 17px;
}
#loginErr { color: #e5484d; margin: 0; min-height: 1.4em; font-size: 15px; }

/* En-tête */
#top {
  position: fixed; inset: 0 0 auto 0; z-index: 20;
  padding: calc(var(--safe-t) + 8px) 12px 8px 16px;
  display: flex; align-items: center; gap: 8px;
  background: var(--bar);
  -webkit-backdrop-filter: saturate(180%) blur(20px); backdrop-filter: saturate(180%) blur(20px);
}
#curLabel { flex: 1; font-weight: 700; font-size: 20px; letter-spacing: -.01em; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#menuBtn { width: 40px; height: 40px; display: grid; place-items: center; border-radius: 20px; fill: var(--fg); }
#menuBtn:active { background: var(--tile); }

#tl { padding-top: calc(var(--safe-t) + 56px); padding-bottom: calc(var(--safe-b) + 40px); }

/* Ce jour-là */
#otd { padding: 6px 0 18px; }
#otd h2, .m h2 { font-size: 17px; font-weight: 700; margin: 0; padding: 10px 16px 8px; }
#otdStrip { display: flex; gap: 10px; overflow-x: auto; padding: 0 16px; scroll-snap-type: x mandatory; scrollbar-width: none; }
#otdStrip::-webkit-scrollbar { display: none; }
.otdCard {
  flex: 0 0 auto; width: 150px; height: 190px; border-radius: 14px; overflow: hidden; position: relative;
  background: var(--tile); scroll-snap-align: start;
}
.otdCard img { width: 100%; height: 100%; object-fit: cover; display: block; }
.otdCard span {
  position: absolute; inset: auto 0 0 0; padding: 26px 10px 9px; color: #fff; font-weight: 700; font-size: 15px; text-align: left;
  background: linear-gradient(transparent, rgba(0, 0, 0, .65));
}
.otdCard span small { display: block; font-weight: 500; font-size: 12px; opacity: .85; }

/* Mois */
.m h2 { display: flex; align-items: baseline; gap: 8px; }
.m h2 .yr { color: var(--muted); font-weight: 600; }
.m h2 .mh { margin-left: auto; font-size: 13px; font-weight: 600; color: var(--accent); padding: 4px 0 4px 10px; }
.g {
  display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: var(--gap);
  align-content: start; contain: layout paint;
}
.c { position: relative; aspect-ratio: 1; background: var(--tile); overflow: hidden; display: block; }
.c img { width: 100%; height: 100%; object-fit: cover; display: block; opacity: 0; transition: opacity .18s; }
.c img.ok { opacity: 1; }
.c .vid {
  position: absolute; right: 5px; bottom: 4px; color: #fff; font-size: 11px; font-weight: 700;
  text-shadow: 0 1px 3px rgba(0,0,0,.7); pointer-events: none;
}
.c .vid svg { width: 14px; height: 14px; vertical-align: -2px; fill: #fff; filter: drop-shadow(0 1px 2px rgba(0,0,0,.6)); }
.c.vnone::after {
  content: ""; position: absolute; inset: 0; margin: auto; width: 34px; height: 34px; border-radius: 50%;
  background: rgba(0,0,0,.45) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M9 7l9 5-9 5z' fill='white'/%3E%3C/svg%3E") center/20px no-repeat;
}
.c.hid img { opacity: .28; }
.c.hid::before {
  content: ""; position: absolute; left: 5px; top: 5px; width: 18px; height: 18px; z-index: 1;
  background: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M3 3l18 18M10.6 5.1A10.4 10.4 0 0112 5c6.5 0 10 7 10 7a17 17 0 01-3.2 4.1M6.6 6.6C3.7 8.5 2 12 2 12s3.5 7 10 7c1.8 0 3.4-.5 4.7-1.3' fill='none' stroke='white' stroke-width='2.4' stroke-linecap='round'/%3E%3C/svg%3E") center/contain no-repeat;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,.8));
}
#empty { text-align: center; color: var(--muted); padding: 80px 20px; }

/* Défilement rapide */
#scrubHandle {
  position: fixed; right: 0; top: 0; z-index: 25; width: 44px; height: 52px;
  display: grid; place-items: center end; padding-right: 3px;
  opacity: 0; transition: opacity .35s; touch-action: none; pointer-events: none;
}
#scrubHandle.on { opacity: 1; pointer-events: auto; }
#scrubHandle span {
  width: 30px; height: 40px; border-radius: 15px; background: var(--bar);
  box-shadow: 0 1px 6px rgba(0,0,0,.25);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M7 9l5-5 5 5M7 15l5 5 5-5' fill='none' stroke='%23888' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: center; background-size: 18px;
}
#bubble {
  position: fixed; right: 54px; z-index: 26; padding: 8px 14px; border-radius: 12px;
  background: var(--bar); font-weight: 700; font-size: 16px; white-space: nowrap;
  box-shadow: 0 2px 12px rgba(0,0,0,.2);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  transform: translateY(-50%); pointer-events: none;
}

/* Plein écran */
#viewer {
  position: fixed; inset: 0; z-index: 50; background: #000; color: #fff;
  touch-action: none; overflow: hidden; user-select: none; -webkit-user-select: none;
}
#viewer.drag { background: transparent; }
#vTrack { position: absolute; inset: 0; }
.slide { position: absolute; inset: 0; display: grid; place-items: center; will-change: transform; }
.zoom { position: absolute; inset: 0; display: grid; place-items: center; transform-origin: 0 0; will-change: transform; }
.zoom img, .zoom video {
  position: absolute; inset: 0; width: 100%; height: 100%;
  object-fit: contain; display: block; -webkit-user-drag: none;
}
.play {
  position: absolute; width: 72px; height: 72px; border-radius: 50%; background: rgba(0,0,0,.5);
  display: grid; place-items: center; z-index: 2;
}
.play svg { width: 34px; height: 34px; fill: #fff; margin-left: 4px; }
.vbar {
  position: absolute; left: 0; right: 0; z-index: 3; display: flex; align-items: center; gap: 6px;
  padding: 8px 10px; transition: opacity .2s;
}
#vTop { top: 0; padding-top: calc(var(--safe-t) + 6px); background: linear-gradient(rgba(0,0,0,.55), transparent); }
#vBottom { bottom: 0; padding-bottom: calc(var(--safe-b) + 10px); justify-content: space-around; background: linear-gradient(transparent, rgba(0,0,0,.55)); }
#viewer.bare .vbar { opacity: 0; pointer-events: none; }
.vbar button { width: 46px; height: 46px; display: grid; place-items: center; border-radius: 23px; }
.vbar button:active { background: rgba(255,255,255,.15); }
#vDate { flex: 1; text-align: center; line-height: 1.2; }
#vDate b { display: block; font-size: 15px; }
#vDate span { font-size: 12px; opacity: .8; }
.vbar .sp { width: 46px; }
#vHide .eyeoff { display: none; }
#vHide.on .eye { display: none; }
#vHide.on .eyeoff { display: block; }
#vHide.on { color: #ffb020; }

/* Feuille d'actions */
#sheet { position: fixed; inset: 0; z-index: 60; background: rgba(0,0,0,.35); display: flex; align-items: flex-end; justify-content: center; }
#sheetBox {
  width: min(480px, 100%); margin: 0 8px calc(var(--safe-b) + 8px); display: grid; gap: 8px;
}
#sheetBox .grp { background: var(--bg); border-radius: 14px; overflow: hidden; }
#sheetBox button { display: block; width: 100%; padding: 16px; font-size: 17px; text-align: center; color: var(--accent); }
#sheetBox .grp button + button { border-top: 1px solid color-mix(in srgb, var(--fg) 10%, transparent); }
#sheetBox button.danger { color: #e5484d; }
#sheetBox button.cancel { font-weight: 600; }

#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 90px); transform: translateX(-50%); z-index: 70;
  background: rgba(30,30,32,.92); color: #fff; padding: 10px 16px; border-radius: 12px; font-size: 15px;
}
