/* ================= Base ================= */
:root {
  --bg-0: #10102a;
  --bg-1: #1b1450;
  --bg-2: #2b1a63;
  --panel: rgba(23, 20, 58, .92);
  --stroke: rgba(255, 255, 255, .14);
  --text: #f2f0ff;
  --muted: #a9a4d6;
  --accent: #ffd23f;
  --danger: #ff5d73;
  --ok: #45d9a5;
  --radius: 18px;
  --hud-h: 62px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  overflow: hidden;
  overscroll-behavior: none;
}

body {
  background: var(--bg-0);
  color: var(--text);
  font-family: "Nunito", "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
  -webkit-font-smoothing: antialiased;
  user-select: none;
}

#app {
  position: relative;
  display: flex;
  flex-direction: column;
  height: 100dvh;
}

/* ================= HUD ================= */
.hud {
  display: flex;
  align-items: center;
  gap: 18px;
  flex: 0 0 auto;
  height: var(--hud-h);
  padding: 0 16px;
  background: rgba(9, 8, 28, .75);
  border-bottom: 1px solid var(--stroke);
  z-index: 5;
}

.hud-block { display: flex; flex-direction: column; gap: 2px; min-width: 54px; }
.hud-grow  { flex: 1 1 auto; max-width: 420px; }
.hud-label { font-size: 11px; letter-spacing: .12em; text-transform: uppercase; color: var(--muted); }
.hud-value { font-size: 20px; font-weight: 800; font-variant-numeric: tabular-nums; line-height: 1; }

.timer-row { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; }
.timer-bar { height: 8px; border-radius: 99px; background: rgba(255,255,255,.12); overflow: hidden; margin-top: 4px; }
#timer-fill {
  height: 100%; width: 100%;
  border-radius: 99px;
  background: linear-gradient(90deg, #45d9a5, #4cc9f0);
  transition: background .3s;
}
#timer-fill.low { background: linear-gradient(90deg, #ffa552, #ff5d73); }

.hearts { display: flex; gap: 3px; font-size: 18px; line-height: 1; }
.hearts span { transition: transform .2s, opacity .2s; }
.hearts span.lost { opacity: .22; transform: scale(.8); filter: grayscale(1); }

.hud-actions { display: flex; gap: 8px; margin-left: auto; }
.icon-btn {
  width: 38px; height: 38px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,.06);
  color: var(--text);
  font-size: 17px;
  cursor: pointer;
  transition: background .15s, transform .1s;
}
.icon-btn:hover { background: rgba(255,255,255,.14); }
.icon-btn:active { transform: scale(.94); }

/* ================= Aire de jeu ================= */
#playfield {
  position: relative;
  flex: 1 1 auto;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(120% 90% at 50% 0%, var(--bg-2) 0%, var(--bg-1) 45%, var(--bg-0) 100%);
}

#stars { position: absolute; inset: 0; pointer-events: none; }
#stars i {
  position: absolute;
  width: 2px; height: 2px;
  border-radius: 50%;
  background: #fff;
  opacity: .5;
  animation: twinkle 4s ease-in-out infinite;
}
@keyframes twinkle { 0%,100% { opacity: .18; } 50% { opacity: .75; } }

#letters, #fx { position: absolute; inset: 0; pointer-events: none; }

/* --- tuile lettre --- */
.letter {
  position: absolute;
  top: 0; left: 0;
  width: 62px; height: 62px;
  display: grid;
  place-items: center;
  border-radius: 16px;
  font-size: 34px;
  font-weight: 900;
  color: #17143a;
  background: var(--c, #ffd23f);
  box-shadow:
    0 0 0 3px rgba(255,255,255,.22) inset,
    0 8px 0 rgba(0,0,0,.28),
    0 0 26px -4px var(--c, #ffd23f);
  will-change: transform;
  animation: drop-in .22s ease-out;
}
@keyframes drop-in { from { transform: scale(.5); opacity: 0; } }

.letter.danger { animation: shake .45s ease-in-out infinite; }
@keyframes shake {
  0%,100% { margin-left: 0; }
  25% { margin-left: -3px; }
  75% { margin-left: 3px; }
}

/* --- sol --- */
#ground {
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 68px;
  background: linear-gradient(0deg, rgba(255,93,115,.28), transparent);
  pointer-events: none;
}
.ground-line {
  position: absolute; top: 0; left: 0; right: 0;
  height: 3px;
  background: linear-gradient(90deg, transparent, rgba(255,93,115,.9), transparent);
  box-shadow: 0 0 14px rgba(255,93,115,.7);
}

/* --- effets --- */
#flash { position: absolute; inset: 0; pointer-events: none; opacity: 0; background: rgba(255,93,115,.35); }
#flash.hit { animation: flash .35s ease-out; }
@keyframes flash { from { opacity: 1; } to { opacity: 0; } }

.pop {
  position: absolute;
  width: 62px; height: 62px;
  border-radius: 50%;
  border: 4px solid var(--c, #fff);
  animation: pop .42s ease-out forwards;
}
@keyframes pop { to { transform: scale(2.1); opacity: 0; } }

.float-score {
  position: absolute;
  font-weight: 900;
  font-size: 20px;
  color: var(--c, #fff);
  text-shadow: 0 2px 8px rgba(0,0,0,.5);
  animation: floatup .8s ease-out forwards;
}
@keyframes floatup { to { transform: translateY(-52px); opacity: 0; } }

/* ================= Clavier guide ================= */
#keyboard-wrap {
  flex: 0 0 auto;
  padding: 6px 12px 14px;
  background: rgba(9, 8, 28, .78);
  border-top: 1px solid var(--stroke);
}
#keyboard-wrap.hidden { display: none; }

.finger-hint {
  margin: 0 0 8px;
  text-align: center;
  font-size: 15px;
  font-weight: 800;
  letter-spacing: .04em;
  color: var(--muted);
  min-height: 21px;
  transition: color .15s;
}

.keyboard { display: flex; flex-direction: column; align-items: center; gap: 5px; }
.krow { display: flex; gap: 5px; }
.krow[data-row="1"] { padding-left: 22px; }
.krow[data-row="2"] { padding-left: 48px; }

.key {
  width: 46px; height: 40px;
  display: grid; place-items: center;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.10);
  background: rgba(255,255,255,.05);
  color: rgba(255,255,255,.30);
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .08s, background .15s, color .15s, box-shadow .15s;
}
.key.in-pool {
  color: #12112e;
  background: color-mix(in srgb, var(--c) 65%, transparent);
  border-color: color-mix(in srgb, var(--c) 80%, transparent);
}
.key.target {
  background: var(--c);
  color: #12112e;
  box-shadow: 0 0 0 2px rgba(255,255,255,.5), 0 0 18px -2px var(--c);
  transform: translateY(-3px);
}
.key.homekey::after {
  content: "";
  position: absolute;
  margin-top: 15px;
  width: 12px; height: 2px;
  border-radius: 2px;
  background: currentColor;
  opacity: .55;
}
.key { position: relative; }
.key.pressed  { animation: kpress .18s ease-out; }
.key.wrong    { animation: kwrong .3s ease-out; }
@keyframes kpress { 0% { transform: scale(.86); } 100% { transform: scale(1); } }
@keyframes kwrong {
  0%,100% { transform: translateX(0); background: rgba(255,93,115,.6); }
  33% { transform: translateX(-4px); }
  66% { transform: translateX(4px); }
}

/* ================= Overlay / panneaux ================= */
.overlay {
  position: absolute;
  inset: 0;
  display: none;
  place-items: center;
  padding: 20px;
  background: rgba(8, 7, 24, .82);
  backdrop-filter: blur(7px);
  z-index: 20;
}
.overlay.show { display: grid; }

.panel {
  display: none;
  width: min(520px, 100%);
  max-height: 88dvh;
  overflow-y: auto;
  padding: 26px 28px;
  border-radius: 24px;
  border: 1px solid var(--stroke);
  background: var(--panel);
  box-shadow: 0 24px 70px -20px #000;
  animation: rise .25s ease-out;
}
.panel.active { display: block; }
.panel-bare { background: none; border: none; box-shadow: none; text-align: center; }
@keyframes rise { from { transform: translateY(14px); opacity: 0; } }

.title {
  margin: 0 0 4px;
  font-size: 46px;
  font-weight: 900;
  letter-spacing: -.02em;
  text-align: center;
  background: linear-gradient(100deg, #ffd23f, #ff7a8a 45%, #7b8cff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.title-accent { color: var(--accent); -webkit-text-fill-color: var(--accent); }
.panel-title { margin: 0 0 10px; font-size: 27px; font-weight: 900; text-align: center; }
.subtitle { margin: 0 0 18px; text-align: center; color: var(--muted); font-size: 15px; line-height: 1.5; }

.menu-stats {
  display: flex; gap: 10px;
  margin: 0 0 18px;
}
.menu-stats > div {
  flex: 1;
  padding: 10px 12px;
  border-radius: 14px;
  background: rgba(255,255,255,.06);
  text-align: center;
}
.menu-stats .k { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .1em; color: var(--muted); }
.menu-stats b { font-size: 22px; font-weight: 900; }

.field { display: block; margin: 0 0 16px; }
.field > span { display: block; margin-bottom: 7px; font-size: 13px; font-weight: 700; color: var(--muted); }
.field > span b { color: var(--text); font-variant-numeric: tabular-nums; }

input[type="number"] {
  width: 100%;
  padding: 11px 13px;
  border-radius: 12px;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,.06);
  color: var(--text);
  font: inherit;
  font-weight: 800;
}
input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
  height: 22px;
}

.chip-row { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  padding: 9px 15px;
  border-radius: 99px;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,.05);
  color: var(--text);
  font: inherit;
  font-size: 14px;
  font-weight: 700;
  cursor: pointer;
  transition: all .15s;
}
.chip:hover { background: rgba(255,255,255,.12); }
.chip.on { background: var(--accent); border-color: var(--accent); color: #17143a; }

.toggles { display: flex; flex-direction: column; gap: 11px; }
.toggle { display: flex; align-items: center; gap: 10px; font-size: 14px; font-weight: 600; cursor: pointer; }
.toggle input { width: 18px; height: 18px; accent-color: var(--accent); }

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; justify-content: center; margin-top: 20px; }
.btn {
  padding: 13px 22px;
  border-radius: 14px;
  border: 1px solid var(--stroke);
  background: rgba(255,255,255,.08);
  color: var(--text);
  font: inherit;
  font-size: 15px;
  font-weight: 800;
  cursor: pointer;
  transition: transform .1s, background .15s;
}
.btn:hover { background: rgba(255,255,255,.16); }
.btn:active { transform: scale(.96); }
.btn-primary {
  background: linear-gradient(100deg, #ffd23f, #ffa552);
  border-color: transparent;
  color: #17143a;
}
.btn-primary:hover { filter: brightness(1.08); background: linear-gradient(100deg, #ffd23f, #ffa552); }
.btn-ghost { background: none; }

.help { margin-top: 18px; font-size: 14px; color: var(--muted); }
.help summary { cursor: pointer; font-weight: 700; padding: 6px 0; }
.help ul { margin: 8px 0 0; padding-left: 20px; line-height: 1.7; }
.help b { color: var(--text); }

.result-stats {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 9px;
  margin: 16px 0 6px;
}
.result-stats div {
  padding: 11px 13px;
  border-radius: 13px;
  background: rgba(255,255,255,.06);
}
.result-stats span { display: block; font-size: 11px; text-transform: uppercase; letter-spacing: .09em; color: var(--muted); }
.result-stats b { font-size: 20px; font-weight: 900; }

.stars-row { display: flex; justify-content: center; gap: 10px; font-size: 46px; margin: 4px 0 2px; }
.stars-row span { opacity: .2; filter: grayscale(1); }
.stars-row span.on { opacity: 1; filter: none; animation: starpop .45s cubic-bezier(.2,1.6,.4,1) backwards; }
.stars-row span.on:nth-child(2) { animation-delay: .14s; }
.stars-row span.on:nth-child(3) { animation-delay: .28s; }
@keyframes starpop { from { transform: scale(0) rotate(-40deg); } }

.countdown {
  font-size: 120px;
  font-weight: 900;
  line-height: 1;
  color: var(--accent);
  text-shadow: 0 8px 40px rgba(255,210,63,.5);
  animation: cd .6s ease-out;
}
@keyframes cd { from { transform: scale(1.7); opacity: 0; } }

/* ================= Responsive ================= */
@media (max-width: 720px) {
  .hud { gap: 10px; padding: 0 10px; }
  .hud-block { min-width: 42px; }
  .hud-value { font-size: 16px; }
  .key { width: 34px; height: 34px; font-size: 13px; }
  .krow[data-row="1"] { padding-left: 14px; }
  .krow[data-row="2"] { padding-left: 30px; }
  .letter { width: 52px; height: 52px; font-size: 28px; }
  .title { font-size: 36px; }
}
@media (max-width: 460px) {
  .key { width: 28px; height: 30px; font-size: 12px; }
  .result-stats { grid-template-columns: 1fr 1fr; }
}
