:root {
  --bg: #0f1f17; --panel: #18301f; --panel-2: #24432d; --line: #2f5239; --text: #f3efe6; --muted: #a9b8a8;
  --accent: #d6403a; --accent-d: #a52b26; --gold: #e8c26b; --danger: #e5533d;
  --title-font: Georgia, "Times New Roman", serif;
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--text); font: 15px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
a { color: var(--gold); }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.nowrap { white-space: nowrap; }

/* ---------------------------------------------------------- interface de création */
.topbar { display: flex; justify-content: space-between; align-items: center; gap: 12px; padding: 10px 20px; background: var(--panel); border-bottom: 1px solid var(--line); }
.brand { font-family: var(--title-font); font-weight: 700; font-size: 19px; color: var(--text); text-decoration: none; white-space: nowrap; }
.brand-star { color: var(--gold); }
.topbar-right { display: flex; gap: 8px; align-items: center; }
.topbar form { margin: 0; }
@media (max-width: 560px) { .who { display: none; } .topbar { padding: 8px 12px; } }

.container { max-width: 960px; margin: 24px auto; padding: 0 16px; }
.card { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 18px 20px; margin-bottom: 16px; }
.card h1, .card h2 { margin: 0 0 12px; font-size: 19px; font-family: var(--title-font); }
.section-title { font-family: var(--title-font); font-size: 21px; margin: 28px 0 12px; }

.btn { background: var(--panel-2); color: var(--text); border: 0; border-radius: 8px; padding: 9px 15px; font: inherit; font-weight: 600; cursor: pointer; text-decoration: none; display: inline-block; white-space: nowrap; }
.btn:hover { filter: brightness(1.15); }
.btn:disabled { opacity: .6; cursor: wait; }
.btn-primary { background: var(--accent); color: #fff; box-shadow: 0 3px 0 var(--accent-d); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-sm { padding: 5px 11px; font-size: 13px; box-shadow: none; }
.btn-block { display: block; width: 100%; text-align: center; }

input, select, textarea { display: block; width: 100%; margin-top: 4px; padding: 9px 10px; border-radius: 8px; border: 1px solid var(--line); background: #0b1610; color: var(--text); font: inherit; }
textarea { resize: vertical; }
input[type=checkbox] { display: inline; width: auto; margin: 0 6px 0 0; accent-color: var(--accent); }
input[type=file] { padding: 6px; font-size: 13px; }
label { font-size: 13px; color: var(--muted); }
label.check { display: flex; align-items: center; color: var(--text); font-size: 14px; }
.stack { display: grid; gap: 12px; }
.two { display: grid; grid-template-columns: 2fr 1fr; gap: 12px; }
.alert { background: #5a1f1a; color: #ffd8d2; padding: 8px 12px; border-radius: 8px; }
.info { background: #22412b; border: 1px solid var(--line); padding: 9px 13px; border-radius: 8px; }

.login-card { max-width: 400px; margin: 70px auto; text-align: center; }
.login-card .stack, .login-card details { text-align: left; }
.login-star { font-size: 42px; color: var(--gold); line-height: 1; margin-bottom: 8px; }
.local-login { margin-top: 14px; }
.local-login summary { cursor: pointer; margin-bottom: 10px; }

.new-form { display: grid; grid-template-columns: 2fr 1fr auto; gap: 12px; align-items: end; }
.cal-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 14px; }
.cal-tile { display: grid; gap: 4px; padding: 18px; border-radius: 12px; text-decoration: none; color: var(--t-text); background: var(--t-bg); border: 1px solid rgba(255,255,255,.12); min-height: 120px; align-content: start; }
.cal-tile strong { font-family: var(--title-font); font-size: 18px; }
.cal-tile:hover { transform: translateY(-2px); transition: transform .15s; }

.editor-head { display: flex; justify-content: space-between; align-items: flex-end; gap: 12px; margin-bottom: 16px; }
.editor-head h1 { font-family: var(--title-font); margin: 4px 0 0; font-size: 26px; }
.editor-head p { margin: 0; }
.share-row { display: flex; gap: 8px; }
.share-row input { margin: 0; }
.share-actions { display: flex; flex-wrap: wrap; gap: 10px; align-items: end; margin-top: 14px; }
.share-actions form { margin: 0; }
.inline-form { display: flex; gap: 8px; align-items: end; }
.settings-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 16px; }
.settings-grid .wide { grid-column: 1 / -1; }
.bg-row { display: flex; flex-wrap: wrap; align-items: center; gap: 10px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.bg-row form { margin: 0; }
.bg-row .label { font-size: 13px; color: var(--muted); }
.bg-thumb { height: 48px; border-radius: 6px; }
.upload-form { display: flex; gap: 8px; align-items: end; flex-wrap: wrap; }
.upload-form label { flex: 1; min-width: 200px; }

.door-forms { display: grid; gap: 10px; }
.door-form { padding: 0; margin: 0; }
.door-form summary { display: flex; align-items: center; gap: 12px; padding: 12px 16px; cursor: pointer; list-style: none; }
.door-form summary::-webkit-details-marker { display: none; }
.door-form[open] summary { border-bottom: 1px solid var(--line); }
.door-form > form, .door-form > .media-row { padding: 14px 16px; }
.door-num { flex: none; width: 38px; height: 38px; border-radius: 8px; background: var(--accent); color: #fff; font-weight: 800; font-family: var(--title-font); display: flex; align-items: center; justify-content: center; font-size: 18px; }
.door-sum { flex: 1; display: grid; min-width: 0; }
.door-sum strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pill { background: #2c5a37; border-radius: 99px; padding: 2px 10px; font-size: 12px; }
.pill-empty { background: var(--panel-2); color: var(--muted); }
.media-row { display: flex; flex-wrap: wrap; align-items: center; gap: 12px; border-top: 1px dashed var(--line); }
.media-row form { margin: 0; }
.media-thumb { max-height: 110px; max-width: 200px; border-radius: 8px; }
.danger-zone { margin-top: 30px; border-color: #5a2a24; }

.table-wrap { overflow-x: auto; }
table.users { width: 100%; border-collapse: collapse; }
.users th { text-align: left; font-size: 12px; text-transform: uppercase; color: var(--muted); padding: 6px 8px; }
.users td { padding: 8px; border-top: 1px solid var(--line); }
.users form { margin: 0; }

@media (max-width: 700px) {
  .new-form, .settings-grid, .two { grid-template-columns: 1fr; }
  .editor-head { flex-direction: column; align-items: stretch; }
  .inline-form { flex-direction: column; align-items: stretch; }
  .card { padding: 16px; }
}

/* ---------------------------------------------------------- thèmes */
.theme-sapin  { --t-bg: radial-gradient(circle at 50% 0%, #1f5b37, #0c2416 70%); --t-text: #fff8ec; --t-door: #b5302b; --t-door-2: #8f211d; --t-num: #fff1d6; --t-open: #f2e3c4; --t-accent: #e8c26b; }
.theme-nuit   { --t-bg: radial-gradient(circle at 50% 0%, #21346b, #0a1027 70%); --t-text: #f4ecd6; --t-door: #1b2a57; --t-door-2: #111c3d; --t-num: #e8c26b; --t-open: #f0e2b8; --t-accent: #e8c26b; }
.theme-neige  { --t-bg: linear-gradient(180deg, #e9f2fb, #c8dcef); --t-text: #1f3550; --t-door: #ffffff; --t-door-2: #dce8f4; --t-num: #2c5f93; --t-open: #fdfdfd; --t-accent: #2c5f93; }
.theme-bonbon { --t-bg: repeating-linear-gradient(135deg, #fbe4ea 0 26px, #f7d0da 26px 52px); --t-text: #6b1027; --t-door: #d72e4f; --t-door-2: #a91c3a; --t-num: #ffffff; --t-open: #fff3f6; --t-accent: #d72e4f; }
.theme-kraft  { --t-bg: linear-gradient(180deg, #c9a57a, #b08a5c); --t-text: #3b2614; --t-door: #e9d6b9; --t-door-2: #d6bc95; --t-num: #7b2d1d; --t-open: #fff8ec; --t-accent: #7b2d1d; }

/* ---------------------------------------------------------- calendrier partagé */
body.shared { background: var(--t-bg); background-attachment: fixed; color: var(--t-text); min-height: 100vh; }
.page-bg { position: fixed; inset: 0; background-size: cover; background-position: center; z-index: -1; }
.page-bg::after { content: ""; position: absolute; inset: 0; background: rgba(0,0,0,.28); }
body.has-bg { --t-text: #fff; }
body.has-bg .cal-head { text-shadow: 0 2px 8px rgba(0,0,0,.55); }

.calendar-page { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; position: relative; }
.preview-bar { background: rgba(0,0,0,.55); color: #fff; padding: 8px 14px; border-radius: 10px; font-size: 13px; text-align: center; margin-bottom: 8px; }
.cal-head { text-align: center; margin: 18px 0 28px; }
.cal-head h1 { font-family: var(--title-font); font-size: clamp(30px, 6vw, 56px); margin: 0; line-height: 1.1; }
.cal-for { font-family: var(--title-font); font-style: italic; font-size: 20px; margin: 6px 0 0; color: var(--t-accent); }
body.has-bg .cal-for { color: #ffe7a8; }
.cal-message { max-width: 620px; margin: 14px auto 0; white-space: pre-line; opacity: .92; }

.door-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 14px; }
@media (max-width: 520px) { .door-grid { grid-template-columns: repeat(3, 1fr); gap: 10px; } }
.door { position: relative; aspect-ratio: 1; padding: 0; border: 0; background: none; cursor: pointer; perspective: 700px; font: inherit; color: inherit; }
.door-inner { position: absolute; inset: 0; transform-style: preserve-3d; transition: transform .55s cubic-bezier(.3,.7,.3,1); transform-origin: left center; }
.door-front, .door-back { position: absolute; inset: 0; backface-visibility: hidden; -webkit-backface-visibility: hidden; display: flex; align-items: center; justify-content: center; border-radius: var(--radius, 8px); }
.door-front { background: linear-gradient(145deg, var(--t-door), var(--t-door-2)); box-shadow: 0 6px 14px rgba(0,0,0,.28), inset 0 0 0 2px rgba(255,255,255,.14); }
.door-inside { position: absolute; inset: 0; border-radius: var(--radius, 8px); background: var(--t-open); box-shadow: inset 0 4px 14px rgba(0,0,0,.35); display: flex; flex-direction: column; align-items: center; justify-content: center; color: var(--t-accent); }
.inside-star { font-size: clamp(26px, 4vw, 38px); line-height: 1; }
.inside-num { font-family: var(--title-font); font-weight: 700; font-size: 15px; opacity: .7; }
.door-back { background: var(--t-open); color: var(--t-accent); font-size: 34px; transform: rotateY(180deg); box-shadow: inset 0 0 0 2px rgba(0,0,0,.08); }
.door-number { font-family: var(--title-font); font-weight: 700; font-size: clamp(28px, 5vw, 42px); color: var(--t-num); text-shadow: 0 2px 0 rgba(0,0,0,.18); }
.door-lock { position: absolute; bottom: 8px; right: 10px; font-size: 13px; opacity: .55; }
.door.is-open .door-front::after { content: ""; position: absolute; top: 9px; right: 9px; width: 9px; height: 9px; border-radius: 50%; background: var(--t-accent); box-shadow: 0 0 0 3px rgba(255,255,255,.25); animation: pulse 2s infinite; }
.door.was-opened .door-front::after { display: none; }
.door.was-opened .door-inner, .door.flipping .door-inner { transform: rotateY(-75deg); }
.door.was-opened .door-back { filter: brightness(.85); }
.door:hover .door-front { filter: brightness(1.08); }
.door.is-locked { cursor: not-allowed; }
.door.is-locked .door-front { filter: saturate(.75); }
.door:focus-visible { outline: 3px solid var(--t-accent); outline-offset: 4px; border-radius: 10px; }
.door.shake { animation: shake .45s; }

.shape-arrondi { --radius: 22px; }
.shape-rond { --radius: 50%; }
.shape-cadeau .door-front { border-radius: 6px; background:
  linear-gradient(90deg, transparent 43%, var(--t-accent) 43% 57%, transparent 57%),
  linear-gradient(0deg, transparent 43%, var(--t-accent) 43% 57%, transparent 57%),
  linear-gradient(145deg, var(--t-door), var(--t-door-2)); }
.shape-cadeau .door-number { background: var(--t-door-2); border-radius: 50%; width: 1.6em; height: 1.6em; display: flex; align-items: center; justify-content: center; font-size: clamp(20px, 3.4vw, 30px); }
.shape-cadeau .door-back { border-radius: 6px; }

@keyframes shake { 0%,100% { transform: translateX(0); } 20%,60% { transform: translateX(-6px); } 40%,80% { transform: translateX(6px); } }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }

.modal { position: fixed; inset: 0; background: rgba(0,0,0,.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 20; animation: fade .2s; }
.modal-box { position: relative; background: #fffaf1; color: #2b2118; width: min(620px, 100%); max-height: calc(100vh - 32px); overflow-y: auto; border-radius: 16px; padding: 26px 24px 24px; box-shadow: 0 20px 60px rgba(0,0,0,.45); animation: pop .3s cubic-bezier(.3,1.4,.5,1); }
.modal-close { position: absolute; top: 8px; right: 10px; background: none; border: 0; font-size: 30px; line-height: 1; color: #8a7b6c; cursor: pointer; padding: 4px 8px; }
.modal-day { margin: 0; text-transform: uppercase; letter-spacing: .12em; font-size: 12px; font-weight: 700; color: #b5302b; }
.modal-box h2 { font-family: var(--title-font); margin: 4px 0 14px; font-size: 26px; line-height: 1.2; }
.modal-box h2:empty { display: none; }
.modal-media { display: block; width: 100%; max-height: 60vh; object-fit: contain; border-radius: 10px; margin-bottom: 14px; background: #000; }
img.modal-media { background: none; }
.modal-audio { width: 100%; margin-bottom: 14px; }
.video-wrap { position: relative; aspect-ratio: 16 / 9; margin-bottom: 14px; }
.video-wrap iframe { position: absolute; inset: 0; width: 100%; height: 100%; border: 0; border-radius: 10px; }
.modal-text { white-space: pre-line; font-size: 17px; line-height: 1.6; margin: 0 0 14px; overflow-wrap: anywhere; }
.modal-link { margin-top: 4px; }
@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { transform: scale(.85); opacity: 0; } }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: rgba(20,20,20,.88); color: #fff; padding: 10px 18px; border-radius: 99px; z-index: 30; font-size: 14px; max-width: calc(100% - 32px); text-align: center; }

.snow { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 10; }
.flake { position: absolute; top: -20px; color: #fff; animation: fall linear infinite; text-shadow: 0 0 4px rgba(255,255,255,.6); }
.theme-neige .flake, .theme-bonbon .flake, .theme-kraft .flake { color: #fff; text-shadow: 0 0 3px rgba(0,0,0,.25); }
@keyframes fall { to { transform: translate(var(--drift, 0), 105vh); } }

.unlock-page { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; }
.unlock-card { background: rgba(255,250,241,.96); color: #2b2118; border-radius: 16px; padding: 28px 24px; width: min(380px, 100%); text-align: center; box-shadow: 0 20px 60px rgba(0,0,0,.35); }
.unlock-card h1 { font-family: var(--title-font); margin: 0; }
.unlock-card .stack { text-align: left; margin-top: 16px; }
.unlock-card input { background: #fff; color: #2b2118; border-color: #d8cbb8; }
.unlock-card label { color: #6c5d4f; }

@media (prefers-reduced-motion: reduce) {
  .door-inner, .modal, .modal-box { transition: none; animation: none; }
}
