/* Piano Hero — feuille unique, sans dépendance ni build. */

:root {
  --bg: #0d1017;
  --bg-soft: #161b26;
  --line: #262d3d;
  --text: #eef2f9;
  --muted: #97a1b5;
  --accent: #3ddc97;
  --accent-dark: #17a673;
  --violet: #7c5cff;
  --warn: #ffb454;
  --miss: #ff5c72;
  --radius: 14px;
}

* { box-sizing: border-box; }

html, body {
  height: 100%;
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  /* Un instrument tactile ne doit ni défiler ni zoomer. */
  overscroll-behavior: none;
  touch-action: manipulation;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
}

body { overflow: hidden; }

.screen {
  position: fixed;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.screen[hidden] { display: none; }

.error {
  position: fixed;
  z-index: 100;
  top: 0; left: 0; right: 0;
  margin: 0;
  padding: 10px 14px;
  background: var(--miss);
  color: #1a0409;
  font-weight: 600;
  text-align: center;
}

/* ---------------------------------------------------------------- menu */

.menu__inner {
  width: min(560px, 92vw);
  max-height: 100%;
  overflow-y: auto;
  text-align: center;
  padding: 18px 0;
}

.brand {
  margin: 0;
  font-size: clamp(28px, 7vw, 44px);
  letter-spacing: -0.02em;
  background: linear-gradient(90deg, var(--accent), var(--violet));
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.brand__sub { margin: 4px 0 20px; color: var(--muted); font-size: 14px; }

.card {
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  text-align: left;
}
.card--center { text-align: center; width: min(460px, 92vw); }
.card__title { margin: 0; font-size: 20px; }
.card__meta { margin: 4px 0 16px; color: var(--muted); font-size: 13px; }

.field { margin-bottom: 14px; }
.field--row { display: flex; gap: 18px; flex-wrap: wrap; }
.field__label {
  display: block;
  margin-bottom: 8px;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
}

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--muted);
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 14px;
  font-family: inherit;
  cursor: pointer;
}
.chip[aria-pressed='true'] {
  border-color: var(--accent);
  background: rgba(61, 220, 151, 0.12);
  color: var(--accent);
}

.switch { display: flex; align-items: center; gap: 8px; font-size: 14px; cursor: pointer; }
.switch input { width: 18px; height: 18px; accent-color: var(--accent); }

.actions { display: flex; gap: 10px; margin-top: 18px; }
.btn {
  flex: 1;
  border: 0;
  border-radius: 10px;
  padding: 14px 18px;
  font-size: 16px;
  font-weight: 600;
  font-family: inherit;
  cursor: pointer;
}
.btn--primary { background: linear-gradient(135deg, var(--accent), var(--accent-dark)); color: #04140d; }
.btn--ghost { background: transparent; border: 1px solid var(--line); color: var(--text); }

.hint { margin-top: 16px; color: var(--muted); font-size: 12.5px; line-height: 1.5; }

/* ---------------------------------------------------------------- jeu */

.screen--game { flex-direction: column; align-items: stretch; padding: 0; }

.hud {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 6px 10px;
  padding-top: max(6px, env(safe-area-inset-top));
  background: rgba(13, 16, 23, 0.9);
  border-bottom: 1px solid var(--line);
}
.hud__quit {
  background: transparent;
  border: 1px solid var(--line);
  color: var(--muted);
  border-radius: 8px;
  width: 32px; height: 32px;
  font-size: 15px;
  cursor: pointer;
}
.hud__score { font-size: 20px; font-weight: 700; font-variant-numeric: tabular-nums; }
.hud__score small { margin-left: 8px; color: var(--accent); font-size: 14px; }
.hud__progress { flex: 1; height: 5px; background: var(--line); border-radius: 3px; overflow: hidden; }
.hud__progress > div {
  height: 100%;
  width: 0;
  background: linear-gradient(90deg, var(--accent), var(--violet));
}

.stage {
  position: relative;
  flex: 1;
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.falling { flex: 1; width: 100%; min-height: 0; display: block; }

/* Le clavier occupe une part fixe de la hauteur : assez haut pour poser cinq doigts. */
.keyboard {
  position: relative;
  width: 100%;
  height: clamp(120px, 42%, 230px);
  flex: none;
  background: #05070b;
  border-top: 1px solid var(--line);
  touch-action: none;
}

.key {
  position: absolute;
  top: 0;
  height: 100%;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  border-radius: 0 0 7px 7px;
  transition: filter 60ms linear;
}

.key--white {
  background: linear-gradient(180deg, #fbfcfe 0%, #e6e9ef 88%, #cfd4de 100%);
  border: 1px solid #2b3242;
  border-top: 0;
  color: #5b6478;
  z-index: 1;
}

.key--black {
  background: linear-gradient(180deg, #2b3242 0%, #10141d 90%);
  border: 1px solid #05070b;
  border-top: 0;
  color: #98a2b8;
  z-index: 2;
  box-shadow: 0 4px 8px rgba(0, 0, 0, 0.55);
}

.key__label { display: none; font-size: 11px; font-weight: 600; pointer-events: none; }
.keyboard--labels .key--white .key__label { display: block; }

.key--down.key--white { background: linear-gradient(180deg, #d8dde7 0%, #c2c8d4 100%); filter: brightness(0.97); }
.key--down.key--black { background: linear-gradient(180deg, #3a4257 0%, #1b2130 100%); }

.key--hint.key--white { background: linear-gradient(180deg, #dcfff0 0%, #a9f0d1 100%); }
.key--hint.key--black { background: linear-gradient(180deg, #4b3f8f 0%, #2c2456 100%); }

.key--perfect { animation: flash-perfect 240ms ease-out; }
.key--good { animation: flash-good 240ms ease-out; }
.key--miss { animation: flash-miss 240ms ease-out; }

@keyframes flash-perfect { from { box-shadow: inset 0 0 0 3px var(--accent); } to { box-shadow: none; } }
@keyframes flash-good { from { box-shadow: inset 0 0 0 3px var(--warn); } to { box-shadow: none; } }
@keyframes flash-miss { from { box-shadow: inset 0 0 0 3px var(--miss); } to { box-shadow: none; } }

.judgement {
  position: absolute;
  left: 50%;
  top: 34%;
  transform: translate(-50%, 0) scale(0.9);
  font-size: clamp(20px, 5vw, 30px);
  font-weight: 800;
  letter-spacing: -0.01em;
  opacity: 0;
  pointer-events: none;
  transition: opacity 120ms ease, transform 120ms ease;
}
.judgement--visible { opacity: 1; transform: translate(-50%, -8px) scale(1); }
.judgement--perfect { color: var(--accent); }
.judgement--good { color: var(--warn); }
.judgement--miss { color: var(--miss); }

.countdown {
  position: absolute;
  left: 50%;
  top: 30%;
  transform: translateX(-50%);
  font-size: clamp(46px, 12vw, 92px);
  font-weight: 800;
  color: var(--text);
  pointer-events: none;
}
.countdown[hidden] { display: none; }

/* ---------------------------------------------------------------- bilan */

.stars { margin: 0 0 8px; font-size: 40px; letter-spacing: 6px; color: var(--warn); }
.end__score { margin: 0 0 14px; font-size: 18px; font-weight: 600; }
.end__detail { display: flex; flex-wrap: wrap; gap: 8px; justify-content: center; margin: 0 0 14px; }
.tally {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
  color: var(--muted);
}
.tally--perfect { border-color: var(--accent); color: var(--accent); }
.tally--good { border-color: var(--warn); color: var(--warn); }
.tally--miss { border-color: var(--miss); color: var(--miss); }
.end__advice { margin: 0; color: var(--muted); font-size: 13.5px; line-height: 1.55; }

/* Un téléphone en paysage n'offre que ~390 px de haut : le menu doit tenir sans défilement. */
@media (max-height: 500px) {
  .menu__inner { padding: 8px 0; }
  .brand { font-size: clamp(20px, 6vh, 30px); }
  .brand__sub { margin: 2px 0 10px; font-size: 12px; }
  .card { padding: 12px 14px; }
  .card__title { font-size: 17px; }
  .card__meta { margin: 2px 0 10px; font-size: 11.5px; }
  .field { margin-bottom: 9px; }
  .field__label { margin-bottom: 5px; font-size: 11px; }
  .chip { padding: 6px 14px; font-size: 13px; }
  .switch { font-size: 13px; }
  .actions { margin-top: 12px; }
  .btn { padding: 10px 16px; font-size: 15px; }
  .hint { margin-top: 9px; font-size: 11.5px; }
  .stars { font-size: 30px; margin-bottom: 4px; }
  .end__score { font-size: 16px; margin-bottom: 8px; }
  .end__detail { margin-bottom: 8px; }
}

/* ------------------------------------------------------- rotation */

.rotate-hint { display: none; }

@media (orientation: portrait) and (max-width: 900px) {
  .screen--game { display: none; }
  .rotate-hint {
    position: fixed;
    inset: 0;
    z-index: 50;
    display: none;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 14px;
    background: var(--bg);
    color: var(--muted);
  }
  /* Affichée seulement quand la partie est lancée. */
  .screen--game:not([hidden]) ~ .rotate-hint { display: flex; }
  .rotate-hint__icon { font-size: 52px; color: var(--accent); }
}
