/* =====================================================================
   Calendrier de l'Avent · KYU Associés
   Thème par défaut : « Noël KYU, blanc neigeux » (charte kyu.fr).
   Les autres thèmes surchargent les variables ci-dessous.
   ===================================================================== */

@font-face { font-family: 'Poppins'; font-weight: 400; font-display: swap; src: url(/fonts/poppins/poppins-latin-400-normal.woff2) format('woff2'); }
@font-face { font-family: 'Poppins'; font-weight: 500; font-display: swap; src: url(/fonts/poppins/poppins-latin-500-normal.woff2) format('woff2'); }
@font-face { font-family: 'Poppins'; font-weight: 700; font-display: swap; src: url(/fonts/poppins/poppins-latin-700-normal.woff2) format('woff2'); }

:root {
  /* Charte KYU */
  --kyu-navy: #080844;
  --kyu-navy-deep: #08051d;
  --kyu-coral: #ef426f;
  --kyu-teal: #14799a;
  --kyu-sky: #569ff7;
  --kyu-grey: #e6e6e6;
  --kyu-snow: #fcfcfc;
  --kyu-ink: #393939;
  --warm-gold: #f6c453;

  /* Jetons d'interface */
  --bg: var(--kyu-snow);
  --bg-accent: radial-gradient(900px 420px at 50% -120px, rgb(86 159 247 / 0.14), transparent 70%);
  --text: var(--kyu-navy);
  --text-soft: #5d6082;
  --surface: #ffffff;
  --surface-2: #f4f5f9;
  --border: var(--kyu-grey);
  --accent: var(--kyu-coral);
  --accent-strong: #d62e5b;
  --accent-text: #ffffff;
  --accent-soft: #fff5f8;
  --focus: var(--kyu-coral);
  --radius: 4px;
  --radius-lg: 6px;
  --shadow: 0 10px 24px -14px rgb(8 8 68 / 0.45);
  --shadow-lg: 0 30px 70px -24px rgb(8 8 68 / 0.45);
  --font-body: 'Poppins', system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  --font-display: 'Poppins', system-ui, sans-serif;
  --font-label: 'Poppins', system-ui, sans-serif;

  /* Cases */
  --tile-1: var(--kyu-navy);
  --tile-2: var(--kyu-coral);
  --tile-3: var(--kyu-teal);
  --tile-text: #ffffff;
  --tile-open-bg: #ffffff;
  --tile-open-text: var(--kyu-navy);

  /* Roue & confettis (lus par wheel.js et confetti.js) */
  --wheel-1: var(--kyu-navy);   --wheel-1-text: #ffffff;
  --wheel-2: var(--kyu-coral);  --wheel-2-text: #ffffff;
  --wheel-3: var(--kyu-teal);   --wheel-3-text: #ffffff;
  --wheel-4: #eef0f6;           --wheel-4-text: #080844;
  --wheel-rim: #080844;
  --wheel-rim-outer: #03032a;
  --wheel-win: #f6c453;
  --wheel-win-text: #080844;
  --wheel-win-stroke: #ffffff;
  --wheel-hub: #ffffff;
  --wheel-hub-stroke: #080844;
  --wheel-hub-mark: #ef426f;
  --wheel-pointer: #ef426f;
  --wheel-pointer-stroke: #ffffff;
  --wheel-font: Poppins, system-ui, sans-serif;
  --wheel-mark: '★';
  --confetti: #080844, #ef426f, #14799a, #569ff7, #f6c453;
  --snow: 86, 159, 247;

  color-scheme: light;
}

/* Évite d'afficher un thème puis l'autre au chargement */
.theme-pending body { opacity: 0; }
body { transition: opacity 0.25s ease; }

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  min-height: 100dvh;
  font-family: var(--font-body);
  color: var(--text);
  background: var(--bg-accent), var(--bg);
  background-attachment: fixed;
  line-height: 1.5;
}

a { color: var(--accent); }
button, input, textarea { font: inherit; }
.wrap { width: min(1100px, 100%); margin: 0 auto; padding: 0 16px; position: relative; z-index: 1; }

/* ---------- Neige ---------- */
canvas.snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }

/* ---------- En-tête ---------- */
.site-header { padding: 26px 16px 6px; text-align: center; }
.brand { display: flex; justify-content: center; }
.logo { height: 40px; width: auto; display: block; }
.logo-light { display: none; }

.site-header h1 {
  font-family: var(--font-display);
  font-weight: 700;
  font-size: clamp(1.8rem, 5.6vw, 3rem);
  letter-spacing: -0.01em;
  line-height: 1.15;
  margin: 6px 0 0;
}
.site-header h1 .year { color: var(--accent); }
.subtitle { margin: 6px 0 0; color: var(--text-soft); }

/* Guirlande : un fil et des ampoules qui scintillent doucement */
.garland {
  position: relative; height: 34px; margin: 10px auto 0; width: min(640px, 100%);
  display: flex; justify-content: space-between; align-items: flex-start; padding: 0 6px;
}
.garland::before {
  content: ''; position: absolute; left: 0; right: 0; top: -14px; height: 30px;
  border-bottom: 1.5px solid rgb(8 8 68 / 0.3); border-radius: 0 0 50% 50% / 0 0 100% 100%;
}
.bulb {
  position: relative; width: 9px; height: 13px; border-radius: 50% 50% 45% 45%;
  animation: twinkle 2.6s ease-in-out infinite; animation-delay: calc(var(--i) * -0.37s);
}
.bulb::before { content: ''; position: absolute; top: -4px; left: 2px; width: 5px; height: 4px; background: #9aa0b8; border-radius: 1px; }
.bulb.b0 { background: var(--kyu-coral); --glow: rgb(239 66 111 / 0.7); }
.bulb.b1 { background: var(--warm-gold); --glow: rgb(246 196 83 / 0.8); }
.bulb.b2 { background: var(--kyu-teal); --glow: rgb(20 121 154 / 0.7); }
.bulb.b3 { background: var(--kyu-sky); --glow: rgb(86 159 247 / 0.7); }
@keyframes twinkle {
  0%, 100% { box-shadow: 0 0 10px 2px var(--glow); opacity: 1; }
  50% { box-shadow: 0 0 2px 0 var(--glow); opacity: 0.55; }
}

.admin-bar {
  display: flex; flex-wrap: wrap; gap: 8px 12px; align-items: center; justify-content: center;
  margin: 14px auto 0; padding: 8px 14px; width: fit-content; max-width: 100%;
  border: 1px solid var(--border); border-radius: var(--radius);
  background: var(--surface); font-size: 0.88rem; box-shadow: var(--shadow);
}
.admin-bar strong { color: var(--accent); }

/* ---------- Boutons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 44px; padding: 0 18px; border-radius: var(--radius); border: 0;
  font-weight: 500; cursor: pointer; text-decoration: none;
  background: var(--accent); color: var(--accent-text);
  transition: transform 0.12s ease, background 0.2s ease, opacity 0.2s;
}
.btn:hover { background: var(--accent-strong); }
.btn:active { transform: scale(0.97); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }
.btn:focus-visible, .day:focus-visible, .link-btn:focus-visible, .tabs button:focus-visible { outline: 3px solid var(--focus); outline-offset: 3px; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--border); }
.btn.ghost:hover { background: var(--surface-2); }
.btn.danger { background: var(--accent); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 0.86rem; }
.link-btn { background: none; border: 0; color: var(--accent); cursor: pointer; padding: 4px; text-decoration: underline; min-height: 44px; }

/* ---------- Calendrier ---------- */
#theme-hero:empty { display: none; }
main { padding-bottom: 40px; }

.week { margin-top: 28px; }
.week-head {
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  margin: 0 2px 10px; border-bottom: 1px solid var(--border); padding-bottom: 6px;
}
.week-head h2 { font-family: var(--font-display); font-weight: 700; font-size: 1.08rem; margin: 0; }
.week-head span { color: var(--kyu-teal); font-size: 0.82rem; font-weight: 500; }

.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }

.day {
  position: relative;
  display: flex; flex-direction: column; align-items: stretch;
  min-height: 150px; padding: 12px; border-radius: var(--radius);
  border: 0; text-align: left; cursor: pointer; color: var(--tile-text);
  box-shadow: var(--shadow); overflow: hidden;
  transition: transform 0.18s ease, box-shadow 0.18s ease;
}
.day:hover { transform: translateY(-3px); box-shadow: 0 16px 28px -14px rgb(8 8 68 / 0.55); }
.day.tone-0 { background: var(--tile-1); }
.day.tone-1 { background: var(--tile-2); }
.day.tone-2 { background: var(--tile-3); }

/* Ruban : une bande verticale et une horizontale, avec le carré diagonal du logo KYU en guise de nœud */
.day:not(.open)::before {
  content: ''; position: absolute; inset: 0; pointer-events: none; opacity: 0.32;
  background:
    linear-gradient(#ffffff, #ffffff) 74% 0 / 6px 100% no-repeat,
    linear-gradient(#ffffff, #ffffff) 0 62% / 100% 6px no-repeat;
}
.day:not(.open)::after {
  content: ''; position: absolute; width: 18px; height: 18px; pointer-events: none;
  left: calc(74% - 6px); top: calc(62% - 6px);
  background: linear-gradient(135deg, #ffffff 0 50%, rgb(255 255 255 / 0.5) 50% 100%);
  box-shadow: 0 2px 6px rgb(0 0 0 / 0.25);
}

.day-kicker { font-family: var(--font-label); font-size: 0.7rem; letter-spacing: 0.12em; opacity: 0.85; position: relative; z-index: 1; }
.day-num { font-family: var(--font-display); font-weight: 700; font-size: 2.5rem; line-height: 1; position: relative; z-index: 1; }
.day-dow { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.1em; opacity: 0.85; position: relative; z-index: 1; margin-top: 4px; }
.day-foot { margin-top: auto; position: relative; z-index: 1; display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.day .pill {
  font-size: 0.72rem; font-weight: 500; padding: 3px 9px; border-radius: var(--radius);
  background: rgb(255 255 255 / 0.18); color: inherit;
}
.day .pill.go { background: #ffffff; color: var(--kyu-navy); }

.day.today { outline: 3px solid var(--warm-gold); outline-offset: 3px; }

.day.open {
  background: var(--tile-open-bg); color: var(--tile-open-text);
  border: 1px solid var(--border); border-left: 4px solid var(--accent);
}
.day.open .day-num { color: var(--accent); }
.day.open .day-dow { color: var(--text-soft); opacity: 1; }
.day.open .pill { background: var(--surface-2); color: var(--text); }
.winners-preview { list-style: none; margin: 8px 0 0; padding: 0; font-size: 0.84rem; display: grid; gap: 2px; font-weight: 500; }
.winners-preview li { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.winners-preview li::before { content: '★ '; color: var(--warm-gold); }

@media (max-width: 520px) {
  .grid { grid-template-columns: repeat(3, 1fr); gap: 8px; }
  .day { min-height: 96px; padding: 8px; }
  .day-num { font-size: 1.8rem; }
  .day-dow { font-size: 0.62rem; }
  .winners-preview { display: none; }
  .day .pill { font-size: 0.66rem; padding: 2px 6px; }
  .week { margin-top: 22px; }
  .week-head h2 { font-size: 0.98rem; }
  .week-head span { font-size: 0.74rem; white-space: nowrap; }
}

/* ---------- Modal ---------- */
dialog.modal {
  width: min(560px, calc(100% - 24px)); max-height: calc(100dvh - 24px);
  padding: 0; border: 0; border-radius: var(--radius-lg);
  background: var(--surface); color: var(--text);
  box-shadow: var(--shadow-lg);
}
dialog.modal::backdrop { background: rgb(8 8 68 / 0.55); backdrop-filter: blur(3px); }
.modal-head {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 18px 20px 12px; border-bottom: 1px solid var(--border);
}
.modal-head h2 { font-family: var(--font-display); margin: 0; font-size: 1.35rem; font-weight: 700; }
.modal-head h2::first-letter { text-transform: uppercase; }
.modal-head p { margin: 2px 0 0; font-size: 0.85rem; color: var(--text-soft); }
.close-btn {
  width: 44px; height: 44px; border-radius: var(--radius); border: 0; cursor: pointer;
  background: var(--surface-2); color: var(--text); font-size: 1.4rem; line-height: 1; flex: none;
}
.modal-body { padding: 16px 20px 20px; }
.modal-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-top: 16px; }
.modal-actions .hint { color: var(--text-soft); font-size: 0.88rem; }

.lots { list-style: none; margin: 0; padding: 0; display: grid; gap: 10px; }
.lot {
  display: grid; grid-template-columns: 40px 1fr; gap: 2px 12px; align-items: center;
  padding: 12px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border);
  transition: border-color 0.3s, background 0.3s;
}
.lot-badge {
  grid-row: span 2; width: 40px; height: 40px; border-radius: var(--radius);
  display: grid; place-items: center; font-weight: 700;
  background: var(--surface-2); color: var(--text); font-family: var(--font-display);
}
.lot-label { font-size: 0.84rem; color: var(--text-soft); }
.lot-winner { font-weight: 700; font-size: 1.12rem; min-height: 1.6em; overflow: hidden; }
.lot-winner.pending { color: var(--border); }
.lot.rolling { border-color: var(--warm-gold); }
.lot.rolling .lot-winner { color: var(--text-soft); }
.lot.revealed { border-color: var(--accent); background: var(--accent-soft); }
.lot.revealed .lot-badge { background: var(--accent); color: var(--accent-text); }
.lot.revealed .lot-winner { animation: pop 0.5s cubic-bezier(.2,1.6,.4,1); color: var(--text); }

@keyframes pop { 0% { transform: scale(0.6); opacity: 0; } 100% { transform: scale(1); opacity: 1; } }

/* ---------- Roue ---------- */
dialog.modal.drawing { width: min(980px, calc(100% - 24px)); }
.draw-layout { display: grid; gap: 16px; align-items: center; }
.wheel-wrap { display: grid; justify-items: center; gap: 6px; }
.wheel { width: min(100%, 440px); aspect-ratio: 1; display: block; }
.wheel-caption { margin: 0; min-height: 1.5em; font-weight: 700; color: var(--accent); text-align: center; font-family: var(--font-display); font-size: 1.1rem; }
.modal.drawing .lot { padding: 10px 12px; }
@media (min-width: 760px) {
  .draw-layout { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); }
}
@media (max-width: 759px) {
  .wheel { width: min(100%, 340px); }
  .modal.drawing .lots { gap: 6px; }
  .modal.drawing .lot { grid-template-columns: 32px 1fr; padding: 8px 10px; }
  .modal.drawing .lot-badge { width: 32px; height: 32px; }
  .modal.drawing .lot-winner { font-size: 1rem; }
}

/* ---------- Confettis ---------- */
#confetti { position: fixed; inset: 0; pointer-events: none; z-index: 1000; width: 100%; height: 100%; }

/* ---------- Divers ---------- */
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%);
  background: var(--kyu-navy); color: #fff; padding: 12px 18px; border-radius: var(--radius);
  box-shadow: var(--shadow-lg); z-index: 2000; max-width: calc(100% - 32px);
  animation: pop 0.25s ease-out;
}
.toast.error { background: var(--accent-strong); }
.site-footer { text-align: center; color: var(--text-soft); font-size: 0.84rem; padding: 16px 16px 36px; position: relative; z-index: 1; }
.site-footer p { margin: 0 0 6px; }
.empty { text-align: center; color: var(--text-soft); padding: 32px 0; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- Admin ---------- */
.panel {
  background: var(--surface); color: var(--text); border-radius: var(--radius-lg);
  padding: 18px; margin-top: 18px; box-shadow: var(--shadow); border: 1px solid var(--border);
}
.panel h2 { font-family: var(--font-display); margin: 0 0 4px; font-weight: 700; }
.panel h3 { font-family: var(--font-display); margin: 18px 0 8px; font-size: 1rem; }
.panel .sub { color: var(--text-soft); margin: 0 0 14px; font-size: 0.9rem; }
.panel input[type=text], .panel input[type=password], .panel textarea {
  width: 100%; min-height: 44px; padding: 10px 12px; border-radius: var(--radius);
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
}
.panel input:focus, .panel textarea:focus { outline: 2px solid var(--focus); border-color: transparent; }
.panel textarea { min-height: 120px; resize: vertical; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row > input { flex: 1 1 200px; }

.tabs { display: flex; gap: 6px; margin-top: 18px; overflow-x: auto; }
.tabs button {
  min-height: 44px; padding: 0 16px; border-radius: var(--radius); border: 1px solid var(--border);
  background: var(--surface); color: var(--text); cursor: pointer; font-weight: 500; white-space: nowrap;
}
.tabs button[aria-selected=true] { background: var(--text); color: var(--surface); border-color: var(--text); }

.people { list-style: none; margin: 14px 0 0; padding: 0; display: grid; gap: 6px; }
.person {
  display: grid; grid-template-columns: 1fr auto; gap: 6px 10px; align-items: center;
  padding: 8px 10px; border-radius: var(--radius); background: var(--surface); border: 1px solid var(--border);
}
.person.inactive { opacity: 0.55; }
.person input[type=text] { min-height: 38px; padding: 6px 10px; border-color: transparent; background: transparent; font-weight: 500; }
.person input[type=text]:hover { border-color: var(--border); }
.person .meta { grid-column: 1 / -1; font-size: 0.8rem; color: var(--text-soft); display: flex; gap: 6px; flex-wrap: wrap; }
.person .actions { display: flex; gap: 6px; }
.tag { padding: 2px 8px; border-radius: var(--radius); background: var(--surface-2); font-size: 0.76rem; }
.tag.week { background: var(--accent-soft); color: var(--accent-strong); font-weight: 500; }

.saved { color: var(--kyu-teal); font-size: 0.85rem; font-weight: 500; }

.draws-table { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
.draws-table th, .draws-table td { text-align: left; padding: 8px 6px; border-bottom: 1px solid var(--border); vertical-align: top; }
.draws-table th { font-size: 0.76rem; text-transform: uppercase; letter-spacing: 0.05em; color: var(--text-soft); }
.draws-table .wk td { background: var(--surface-2); font-weight: 700; }

.lots-form { display: grid; gap: 10px; max-width: 560px; }
.lot-field { display: grid; grid-template-columns: 40px 1fr; gap: 10px; align-items: center; }
.lot-field .lot-badge { grid-row: auto; }

.theme-choices { display: grid; gap: 8px; margin: 10px 0 14px; max-width: 560px; }
.theme-choice {
  display: flex; gap: 10px; align-items: center; padding: 10px 12px; min-height: 44px;
  border: 1px solid var(--border); border-radius: var(--radius); cursor: pointer;
}
.theme-choice input { accent-color: var(--accent); width: 18px; height: 18px; }
.theme-choice:has(input:checked) { border-color: var(--accent); background: var(--accent-soft); }
.schedule { margin: 0; padding: 0; list-style: none; display: grid; gap: 6px; font-size: 0.9rem; max-width: 560px; }
.schedule li { display: flex; justify-content: space-between; gap: 12px; flex-wrap: wrap; border-bottom: 1px dashed var(--border); padding-bottom: 6px; }
.schedule time { font-weight: 500; }
.state-badge { display: inline-block; padding: 2px 10px; border-radius: var(--radius); background: var(--text); color: var(--surface); font-weight: 500; font-size: 0.85rem; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { transition-duration: 0.01ms !important; animation-duration: 0.01ms !important; }
}
