:root {
  --bg: #0b1a2b;
  --bg2: #112843;
  --card: #163352;
  --card2: #1d3f63;
  --line: rgba(255, 255, 255, 0.12);
  --text: #f7f3e9;
  --muted: #a9b7c6;
  --gold: #f2c94c;
  --gold2: #d4a62a;
  --red: #c8313f;
  --red2: #8f1f2c;
  --green: #3aa36b;
  --green2: #1f6d45;
  --ice: #9fd8ff;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.35);
  --radius: 18px;
  --sat: env(safe-area-inset-top, 0px);
  --sab: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  font-size: 16px; line-height: 1.4; min-height: 100vh; min-height: 100dvh;
  overscroll-behavior-y: none; -webkit-font-smoothing: antialiased;
  background: radial-gradient(1200px 600px at 50% -200px, #1a3a5f 0%, var(--bg) 60%);
}
button { font: inherit; color: inherit; }
h1, h2, h3 { font-family: Georgia, "Times New Roman", serif; font-weight: 600; letter-spacing: 0.01em; margin: 0; }
#snow { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; opacity: 0.7; }
#app { position: relative; z-index: 1; min-height: 100vh; min-height: 100dvh; }
.hidden { display: none !important; }
svg.ic { width: 1.2em; height: 1.2em; vertical-align: -0.25em; fill: none; stroke: currentColor; stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }

/* ---- boutons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 12px 20px; border-radius: 999px; border: 1px solid transparent; cursor: pointer;
  background: var(--card2); color: var(--text); font-weight: 600; min-height: 46px;
  transition: transform 0.12s ease, background 0.2s ease, opacity 0.2s;
  user-select: none; -webkit-user-select: none;
}
.btn:active { transform: scale(0.97); }
.btn.primary { background: linear-gradient(180deg, #e04656, var(--red)); box-shadow: 0 6px 18px rgba(200, 49, 63, 0.35); }
.btn.gold { background: linear-gradient(180deg, #ffd96a, var(--gold2)); color: #3a2a05; box-shadow: 0 6px 18px rgba(242, 201, 76, 0.3); }
.btn.ghost { background: transparent; border-color: var(--line); }
.btn.small { padding: 8px 14px; min-height: 36px; font-size: 14px; }
.btn.icon { width: 44px; height: 44px; padding: 0; border-radius: 50%; }
.btn[disabled] { opacity: 0.45; pointer-events: none; }
.row { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.row.center { justify-content: center; }
.spacer { flex: 1; }

/* ---- barre du haut ---- */
.topbar {
  position: sticky; top: 0; z-index: 5; display: flex; align-items: center; gap: 10px;
  padding: calc(10px + var(--sat)) 14px 10px; background: rgba(11, 26, 43, 0.85);
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px); border-bottom: 1px solid var(--line);
}
.topbar h1 { font-size: 20px; flex: 1; text-align: center; }
.topbar .sub { font-size: 12px; color: var(--muted); display: block; font-family: inherit; font-weight: 500; }
.badge {
  position: absolute; top: -4px; right: -4px; min-width: 20px; height: 20px; padding: 0 5px; border-radius: 10px;
  background: var(--gold); color: #3a2a05; font-size: 12px; font-weight: 700; display: flex; align-items: center; justify-content: center;
}
.bagbtn { position: relative; }

/* ---- écran de connexion ---- */
.login { min-height: 100vh; min-height: 100dvh; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 24px; text-align: center; gap: 14px; }
.login h1 { font-size: 34px; line-height: 1.1; }
.login .star { width: 72px; height: 72px; color: var(--gold); filter: drop-shadow(0 0 14px rgba(242, 201, 76, 0.6)); }
.login p { color: var(--muted); max-width: 320px; margin: 0; }
.login input {
  width: min(320px, 100%); padding: 14px 16px; border-radius: 14px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06); color: var(--text); font-size: 18px; text-align: center; outline: none;
}
.login input:focus { border-color: var(--gold); }
.login .err { color: #ff8e9a; min-height: 20px; font-size: 14px; }

/* ---- calendrier ---- */
.cal { max-width: 520px; margin: 0 auto; padding: 18px 16px calc(40px + var(--sab)); }
.cal .intro { text-align: center; color: var(--muted); font-size: 14px; margin: 4px 0 18px; }
.chain { position: relative; padding: 10px 0; }
.chain::before {
  content: ""; position: absolute; left: 50%; top: 0; bottom: 0; width: 6px; margin-left: -3px; border-radius: 3px;
  background: repeating-linear-gradient(180deg, var(--gold2) 0 10px, #7a5a12 10px 18px);
  box-shadow: 0 0 12px rgba(242, 201, 76, 0.25);
}
.daywrap { position: relative; display: flex; align-items: center; min-height: 112px; }
.daywrap.left { justify-content: flex-start; }
.daywrap.right { justify-content: flex-end; }
.daywrap::before {
  content: ""; position: absolute; top: 50%; width: 22%; height: 4px; margin-top: -2px;
  background: repeating-linear-gradient(90deg, var(--gold2) 0 8px, #7a5a12 8px 14px);
}
.daywrap.left::before { right: 50%; }
.daywrap.right::before { left: 50%; }
.day {
  position: relative; z-index: 1; width: 29%; min-width: 118px; aspect-ratio: 1; border-radius: 50%;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px;
  border: 0; cursor: pointer; color: var(--text); text-align: center; padding: 0;
  background: radial-gradient(circle at 35% 30%, #2d5a8c, var(--card) 70%);
  box-shadow: inset 0 -8px 16px rgba(0, 0, 0, 0.3), var(--shadow);
  transition: transform 0.15s;
}
.day::after {
  content: ""; position: absolute; top: -10px; left: 50%; width: 18px; height: 12px; margin-left: -9px; border-radius: 4px 4px 2px 2px;
  background: linear-gradient(180deg, #e8d49a, var(--gold2));
}
.day:active { transform: scale(0.96); }
.day .num { font-family: Georgia, serif; font-size: 34px; line-height: 1; font-weight: 700; }
.day .lbl { font-size: 11px; color: var(--muted); letter-spacing: 0.04em; text-transform: uppercase; }
.day.locked { background: radial-gradient(circle at 35% 30%, #3b4a5c, #1b2633 70%); color: #8d9aa8; }
.day.locked .lbl { color: #7b8794; }
.day.locked .lockic { position: absolute; bottom: 14px; width: 20px; height: 20px; color: #aab6c3; }
.day.locked .chainic { position: absolute; inset: 0; width: 100%; height: 100%; color: rgba(190, 200, 210, 0.55); pointer-events: none; }
.day.open { background: radial-gradient(circle at 35% 30%, #ff6b78, var(--red) 70%); animation: glow 2.2s ease-in-out infinite; }
.day.open .lbl { color: #ffe3e6; }
.day.won { background: radial-gradient(circle at 35% 30%, #5fcf92, var(--green2) 70%); }
.day.won .lbl { color: #d7f5e3; }
.day.won .checkic { position: absolute; top: 14px; right: 16px; width: 22px; height: 22px; color: var(--gold); }
.day.shake { animation: shake 0.4s; }
@keyframes glow { 0%, 100% { box-shadow: var(--shadow), 0 0 0 0 rgba(255, 107, 120, 0.5); } 50% { box-shadow: var(--shadow), 0 0 0 14px rgba(255, 107, 120, 0); } }
@keyframes shake { 0%, 100% { transform: translateX(0); } 25% { transform: translateX(-6px); } 75% { transform: translateX(6px); } }
.finale { text-align: center; padding: 20px 0 10px; color: var(--gold); }
.finale svg { width: 64px; height: 64px; filter: drop-shadow(0 0 16px rgba(242, 201, 76, 0.6)); }
.finale p { color: var(--muted); font-size: 14px; margin: 6px 0 0; }
.admin { margin-top: 24px; padding: 12px; border: 1px dashed var(--line); border-radius: 12px; font-size: 13px; color: var(--muted); }

/* ---- vue jeu ---- */
.game { max-width: 560px; margin: 0 auto; padding: 14px 14px calc(30px + var(--sab)); }
.card { background: var(--card); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); margin-bottom: 14px; }
.card h2 { font-size: 22px; margin-bottom: 4px; }
.card .sub { color: var(--muted); font-size: 14px; }
.card p { margin: 8px 0 0; color: #dfe6ee; font-size: 15px; }
.wonbar { display: flex; align-items: center; gap: 12px; background: linear-gradient(90deg, var(--green2), var(--card)); }
.wonbar .piecemini { width: 64px; height: 64px; flex: none; }
.board { display: flex; flex-direction: column; align-items: center; gap: 12px; }
.hint { color: var(--muted); font-size: 14px; text-align: center; margin: 0; }
.status { font-weight: 600; text-align: center; min-height: 22px; }
.status.bad { color: #ff8e9a; }
.status.good { color: #7ee2a8; }
.grid { display: grid; gap: 4px; touch-action: none; user-select: none; -webkit-user-select: none; }
.cell {
  display: flex; align-items: center; justify-content: center; border-radius: 8px;
  background: rgba(255, 255, 255, 0.08); font-weight: 700; aspect-ratio: 1; cursor: pointer; position: relative;
}
.pad { display: grid; grid-template-columns: repeat(3, 56px); grid-template-rows: repeat(2, 56px); gap: 8px; justify-content: center; }
.pad .btn { padding: 0; min-height: 0; height: 56px; border-radius: 14px; }
.pad .up { grid-column: 2; }
.pad .left { grid-column: 1; grid-row: 2; }
.pad .down { grid-column: 2; grid-row: 2; }
.pad .right { grid-column: 3; grid-row: 2; }
canvas.gamecanvas { max-width: 100%; border-radius: 12px; touch-action: none; display: block; }
svg.gsvg { max-width: 100%; height: auto; touch-action: none; user-select: none; -webkit-user-select: none; display: block; }
.palette { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; }
.swatch { width: 40px; height: 40px; border-radius: 50%; border: 3px solid transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 13px; text-shadow: 0 0 3px rgba(0,0,0,0.6); color: #fff; }
.swatch.sel { border-color: var(--gold); transform: scale(1.1); }
.swatch.done { opacity: 0.35; }
.keyboard { display: flex; flex-direction: column; gap: 6px; align-items: center; width: 100%; }
.keyboard .krow { display: flex; gap: 4px; justify-content: center; width: 100%; }
.key { flex: 1; max-width: 36px; height: 44px; border-radius: 8px; border: 0; background: var(--card2); color: var(--text); font-weight: 700; font-size: 14px; padding: 0; }
.key.wide { max-width: 60px; font-size: 12px; }
.key.g { background: var(--green); } .key.y { background: #d9a520; color: #2b2000; } .key.x { background: #26384d; color: #7b8794; }
.options { display: flex; flex-direction: column; gap: 8px; width: 100%; }
.opt { text-align: left; padding: 12px 14px; border-radius: 12px; background: var(--card2); border: 2px solid transparent; cursor: pointer; }
.opt.ok { border-color: var(--green); background: rgba(58, 163, 107, 0.25); }
.opt.ko { border-color: var(--red); background: rgba(200, 49, 63, 0.25); }
.scroller { width: 100%; overflow: auto; border-radius: 12px; background: rgba(0,0,0,0.25); max-height: 62vh; -webkit-overflow-scrolling: touch; }
.scroller.paint { touch-action: none; }
.scroller canvas { max-width: none; }
.card.rules h2 { cursor: pointer; display: flex; align-items: center; gap: 8px; }
.card.rules h2 .ic { margin-left: auto; transition: transform 0.2s; opacity: 0.7; }
.card.rules.closed h2 .ic { transform: rotate(-90deg); }
.card.rules.closed p, .card.rules.closed .sub { display: none; }
.traywrap { position: sticky; bottom: calc(8px + var(--sab)); z-index: 3; padding: 6px; }
.tray { display: flex; gap: 10px; overflow-x: auto; padding: 8px; width: 100%; background: rgba(0,0,0,0.25); border-radius: 12px; min-height: 88px; align-items: center; -webkit-overflow-scrolling: touch; }
.tray .ptile { flex: none; width: 76px; height: 76px; touch-action: none; cursor: grab; }
.tray .ptile svg { width: 100%; height: 100%; display: block; }
.tray .empty { color: var(--muted); font-size: 14px; padding: 0 10px; }

/* ---- puzzle ---- */
.pzboard { position: relative; background: rgba(0,0,0,0.3); border-radius: 10px; border: 2px solid rgba(242, 201, 76, 0.35); touch-action: none; overflow: visible; }
.pzboard .gridlines { position: absolute; inset: 0; pointer-events: none; opacity: 0.35; }
.pzboard .placed { position: absolute; touch-action: none; cursor: grab; }
.pzboard .placed svg { width: 100%; height: 100%; display: block; }
.dragging { position: fixed; z-index: 50; pointer-events: none; filter: drop-shadow(0 12px 16px rgba(0,0,0,0.5)); }
.dragging svg { width: 100%; height: 100%; display: block; }
.pzboard.done { border-color: var(--gold); box-shadow: 0 0 40px rgba(242, 201, 76, 0.4); }
.pzboard .fullphoto { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; border-radius: 8px; opacity: 0; transition: opacity 1.8s ease; }
.pzboard.done .fullphoto { opacity: 1; }

/* ---- overlay de victoire ---- */
.overlay { position: fixed; inset: 0; z-index: 40; background: rgba(5, 12, 22, 0.86); display: flex; align-items: center; justify-content: center; padding: 20px; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px); }
.wincard { text-align: center; max-width: 360px; width: 100%; animation: pop 0.5s cubic-bezier(0.2, 1.4, 0.4, 1); }
.wincard h2 { font-size: 30px; color: var(--gold); }
.wincard p { color: var(--muted); margin: 6px 0 14px; }
.wincard .piecebig { width: 190px; height: 190px; margin: 10px auto; position: relative; animation: pieceIn 0.9s cubic-bezier(0.2, 1.4, 0.4, 1) 0.3s both; }
.wincard .piecebig svg { width: 100%; height: 100%; filter: drop-shadow(0 0 22px rgba(242, 201, 76, 0.55)); }
.wincard .actions { display: flex; flex-direction: column; gap: 10px; margin-top: 10px; opacity: 0; animation: fade 0.5s ease 1.6s forwards; }
.sparkle { position: absolute; width: 10px; height: 10px; border-radius: 50%; background: var(--gold); opacity: 0; animation: spark 1.2s ease-out forwards; }
@keyframes pop { from { transform: scale(0.7); opacity: 0; } to { transform: scale(1); opacity: 1; } }
@keyframes pieceIn { from { transform: scale(0.2) rotate(-25deg); opacity: 0; } to { transform: scale(1) rotate(0); opacity: 1; } }
@keyframes fade { to { opacity: 1; } }
@keyframes spark { 0% { transform: translate(0, 0) scale(0.4); opacity: 1; } 100% { transform: translate(var(--dx), var(--dy)) scale(0); opacity: 0; } }
.flyer { position: fixed; z-index: 60; pointer-events: none; transition: transform 0.9s cubic-bezier(0.5, 0, 0.3, 1), opacity 0.9s; }
.flyer svg { width: 100%; height: 100%; }
.toast { position: fixed; left: 50%; bottom: calc(30px + var(--sab)); transform: translateX(-50%); z-index: 70; background: var(--gold); color: #3a2a05; padding: 10px 16px; border-radius: 999px; font-weight: 600; box-shadow: var(--shadow); max-width: 90vw; text-align: center; }

/* ---- écran final ---- */
.final { text-align: center; padding: 16px; }
.final h2 { font-size: 32px; color: var(--gold); }
.final p { color: #dfe6ee; }
