:root {
  --night: #0f2a3d;
  --night-2: #16384f;
  --ice: #eef4f8;
  --card: #ffffff;
  --ink: #17232e;
  --muted: #5b6b78;
  --red: #c8102e;
  --red-dark: #9c0c24;
  --gold: #e3b341;
  --green: #1f6b45;
  --tile-bg: #e8edf1;
  --tile-border: #c5d0d8;
  --radius: 14px;
  color-scheme: light;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  min-height: 100vh;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  color: var(--ink);
  background: linear-gradient(180deg, var(--night) 0%, var(--night-2) 55%, #1d4560 100%) fixed;
  padding-bottom: env(safe-area-inset-bottom);
}
.hidden { display: none !important; }

/* Flocons */
.snow { position: fixed; inset: 0; pointer-events: none; overflow: hidden; z-index: 0; }
.snow i {
  position: absolute; top: -10px; width: var(--s, 4px); height: var(--s, 4px);
  background: #fff; border-radius: 50%;
  animation: fall linear infinite;
}
@keyframes fall {
  to { transform: translate3d(30px, 105vh, 0); }
}

/* En-tête */
.top { position: relative; z-index: 1; color: #fff; padding: 0 16px 8px; max-width: 640px; margin: 0 auto; }
.garland { display: block; width: 100%; height: 22px; }
.brand { display: flex; align-items: center; gap: 12px; padding-top: 4px; }
.tree { width: 34px; height: 42px; flex: none; }
.brand h1 { margin: 0; font-size: 1.45rem; letter-spacing: .02em; }
.sub { margin: 0; font-size: .85rem; opacity: .75; }
#logoutBtn { position: absolute; right: 16px; top: 30px; }

/* Onglets */
.tabs {
  position: sticky; top: 0; z-index: 2; display: flex; gap: 4px;
  max-width: 640px; margin: 0 auto; padding: 6px 12px;
  background: rgba(15, 42, 61, .92); backdrop-filter: blur(6px);
}
.tabs button {
  flex: 1; padding: 10px 6px; border: 0; border-radius: 10px; cursor: pointer;
  background: transparent; color: #cfe0ea; font: inherit; font-weight: 600;
}
.tabs button[aria-selected="true"] { background: #fff; color: var(--night); }
.tabs button:focus-visible { outline: 3px solid var(--gold); outline-offset: 1px; }

/* Contenu */
.view { position: relative; z-index: 1; max-width: 640px; margin: 0 auto; padding: 10px 16px 24px; }
.card {
  background: var(--card); border-radius: var(--radius); padding: 18px 18px;
  margin: 10px 0; box-shadow: 0 6px 24px rgba(0, 0, 0, .18);
}
.card.narrow { max-width: 440px; margin-left: auto; margin-right: auto; }
.card.center { text-align: center; }
.muted-card { background: rgba(255, 255, 255, .9); font-size: .95rem; }
h2 { margin: 0 0 10px; font-size: 1.3rem; }
h3 { margin: 18px 0 6px; font-size: 1.05rem; color: var(--night); }
.card > h3:first-child { margin-top: 0; }
p { line-height: 1.5; }
.small { font-size: .88rem; color: var(--muted); }
.error { color: var(--red-dark); font-weight: 600; min-height: 1.2em; }
a { color: var(--red-dark); }
code { background: var(--ice); padding: 1px 6px; border-radius: 6px; font-weight: 700; }

label { display: block; font-weight: 600; margin-bottom: 6px; }
input[type="text"], input:not([type]) {
  width: 100%; padding: 14px 14px; font-size: 1.25rem; letter-spacing: .12em; text-transform: uppercase;
  border: 2px solid var(--tile-border); border-radius: 10px; font-family: ui-monospace, Menlo, Consolas, monospace;
}
input:focus { outline: none; border-color: var(--night); }
.hint { font-size: .88rem; color: var(--muted); margin: 8px 0; }

.btn {
  display: inline-block; padding: 12px 20px; margin: 6px 4px; border-radius: 10px; cursor: pointer;
  border: 2px solid var(--night); background: #fff; color: var(--night); font: inherit; font-weight: 700;
}
.btn.primary { background: var(--red); border-color: var(--red); color: #fff; }
.btn.primary:hover { background: var(--red-dark); }
#loginForm .btn { width: 100%; margin: 6px 0 0; font-size: 1.1rem; }
.link { background: none; border: 0; color: #fff; text-decoration: underline; cursor: pointer; font: inherit; }
.link.small { font-size: .85rem; opacity: .85; }

/* Jeu */
.play-head { display: flex; align-items: center; gap: 10px; color: #fff; margin: 4px 2px 8px; flex-wrap: wrap; }
.play-head .day { font-weight: 700; }
.play-head .meta { opacity: .75; font-size: .9rem; }
.play-head .timer { margin-left: auto; font-variant-numeric: tabular-nums; opacity: .8; font-size: .9rem; }
.big-letter { font-size: 1.4rem; color: var(--red); }
.countdown { font-size: 1.5rem; font-weight: 800; font-variant-numeric: tabular-nums; color: var(--night); }

.grid { display: flex; flex-direction: column; gap: 5px; align-items: center; margin: 4px auto 8px; }
.row {
  display: grid; grid-template-columns: repeat(var(--cols), 1fr); gap: 5px;
  width: min(100%, calc(var(--cols) * 54px));
}
.tile {
  position: relative; aspect-ratio: 1; display: flex; align-items: center; justify-content: center;
  background: var(--tile-bg); border: 2px solid var(--tile-border); border-radius: 6px;
  font-weight: 800; font-size: clamp(1rem, 5.2vw, 1.6rem); color: var(--ink); user-select: none;
}
.tile > span { position: relative; z-index: 1; }
.tile.empty { background: rgba(255, 255, 255, .1); border-color: rgba(255, 255, 255, .28); }
.tile.typed { background: #fff; border-color: var(--night); }
/* Lettre déjà validée, pré-remplie et non modifiable dans la ligne en cours */
.tile.fixed { background: #fbe4e8; border-color: #e7a7b2; color: var(--red-dark); }
/* Prochaine case à remplir */
.tile.cursor { border-color: var(--gold); box-shadow: inset 0 -4px 0 var(--gold); }
.row.current .tile { box-shadow: 0 0 0 1px rgba(255,255,255,.4); }
/* Bien placée : carré plein rouge */
.tile.correct { background: var(--red); border-color: var(--red-dark); color: #fff; }
/* Mal placée : cercle doré */
.tile.present { background: #fff; border-color: var(--tile-border); }
.tile.present::before {
  content: ""; position: absolute; inset: 9%; border-radius: 50%; background: var(--gold);
  border: 2px solid #b8891c;
}
/* Absente : case vide, gris neutre */
.tile.absent { background: #d6dde3; border-color: #d6dde3; color: #55636e; }

.shake { animation: shake .35s; }
@keyframes shake { 20%, 60% { transform: translateX(-6px); } 40%, 80% { transform: translateX(6px); } }

.attempts { text-align: center; color: #fff; margin: 4px 0 8px; font-size: .95rem; }

.keyboard { display: flex; flex-direction: column; gap: 6px; margin: 4px auto 0; max-width: 560px; user-select: none; }
.krow { display: flex; gap: 5px; justify-content: center; }
.key {
  position: relative; flex: 1; max-width: 46px; height: 52px; border: 0; border-radius: 7px; cursor: pointer;
  background: #f4f7f9; color: var(--ink); font: inherit; font-weight: 700; font-size: 1.05rem;
  display: flex; align-items: center; justify-content: center; touch-action: manipulation;
}
.key > span { position: relative; z-index: 1; }
.key.wide { flex: 1.6; max-width: 76px; font-size: .9rem; }
.key.enter { background: var(--green); color: #fff; }
.key.correct { background: var(--red); color: #fff; }
.key.present::before { content: ""; position: absolute; width: 32px; height: 32px; max-width: 80%; border-radius: 50%; background: var(--gold); }
.key.absent { background: #5f7180; color: #b9c5ce; }
.key:active { transform: translateY(1px); }
.key:focus-visible { outline: 3px solid var(--gold); }

.prev-word { background: #fdf6e3; border: 2px solid var(--gold); }
.prev-label { margin: 0; color: var(--muted); font-weight: 600; }
.prev-value { margin: 4px 0 0; font-size: clamp(1.8rem, 9vw, 2.6rem); font-weight: 800; letter-spacing: .14em; color: var(--red); word-break: break-all; }
.result .bravo { color: var(--red); font-size: 1.6rem; }
.points { margin: 12px auto; padding: 12px; background: var(--ice); border-radius: 12px; max-width: 320px; }
.points .pv { display: block; font-size: 2.4rem; font-weight: 800; color: var(--red); line-height: 1.1; }
.points .pl { font-size: .9rem; color: var(--muted); }
.pdetail { font-size: .85rem; color: var(--muted); margin-top: 4px; }
.hushed { font-style: italic; }

/* Classement */
.pos-label { margin: 0; color: var(--muted); }
.pos { margin: 0; font-size: 2.6rem; font-weight: 800; color: var(--night); }
.total { margin: 4px 0 0; font-size: 1.1rem; }
.scores { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
.scores th, .scores td { padding: 7px 10px; text-align: left; border-bottom: 1px solid #e3e9ee; }
.scores tr.me td { background: #fdf1d0; font-weight: 800; }
.you { color: var(--red); font-weight: 700; }
.mydays { list-style: none; margin: 0; padding: 0; }
.mydays li { display: grid; grid-template-columns: 4.5em 6.5em 1fr auto; gap: 6px; padding: 7px 0; border-bottom: 1px solid #edf1f4; font-size: .92rem; align-items: center; }
.mydays .dd { color: var(--muted); }
.mydays .dp { font-weight: 700; font-variant-numeric: tabular-nums; }
.mydays li.solved .ds { color: var(--green); }
.mydays li.missed .ds, .mydays li.failed .ds, .mydays li.unfinished .ds { color: var(--muted); }
.mydays li.todo .ds, .mydays li.inprogress .ds { color: var(--red); font-weight: 600; }

/* Règles */
.rules ul { padding-left: 1.2em; }
.rules li { margin: 4px 0; line-height: 1.45; }
.legend { display: grid; gap: 8px; margin: 8px 0; }
.legend > div { display: flex; align-items: center; gap: 10px; }
.legend .tile { width: 40px; flex: none; font-size: 1.2rem; }
.scale { border-collapse: collapse; margin: 6px 0; min-width: 220px; }
.scale th, .scale td { padding: 5px 14px; border-bottom: 1px solid #e3e9ee; text-align: left; }
.prize { font-size: 1.15rem; font-weight: 700; color: var(--red); }

/* Notification */
.toast {
  position: fixed; left: 50%; top: 18px; transform: translate(-50%, -150%); z-index: 10;
  background: var(--ink); color: #fff; padding: 12px 18px; border-radius: 10px; font-weight: 600;
  max-width: calc(100% - 32px); text-align: center; transition: transform .25s; box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.toast.show { transform: translate(-50%, 0); }

@media (max-width: 380px) {
  .key { height: 46px; font-size: .95rem; }
  .krow { gap: 4px; }
  .card { padding: 14px; }
}
@media (prefers-reduced-motion: reduce) {
  .shake { animation: none; }
  .toast { transition: none; }
}
