*{ box-sizing:border-box; }
html,body{ height:100%; margin:0; }
body{
  font-family: system-ui,-apple-system,Segoe UI,Roboto,Arial;
  background:#020617;
  color:#e5e7eb;
  overflow-x:hidden;
}

#app{ min-height:100%; display:flex; flex-direction:column; }

/* ---------------- Topbar ---------------- */
.topbar{
  padding:14px 14px;
  border-bottom:1px solid rgba(255,255,255,.08);
  display:flex;
  align-items:flex-end;
  justify-content:space-between;
  gap:14px;
  flex-wrap:wrap;
}

.brand .title{
  font-size:18px;
  font-weight:800;
  letter-spacing:.2px;
}
.brand .subtitle{
  opacity:.85;
  font-size:13px;
  margin-top:3px;
}

/* ---------------- Buttons ---------------- */
.controls{
  display:flex;
  gap:8px;
  flex-wrap:wrap;
  align-items:center;
}

.btn{
  background:rgba(255,255,255,.06);
  border:1px solid rgba(255,255,255,.18);
  color:#e5e7eb;
  padding:10px 12px;
  border-radius:12px;
  cursor:pointer;
  font-weight:650;
  transition:transform .05s ease, background .15s ease, border-color .15s ease;
  user-select:none;
}
.btn:hover{
  background:rgba(255,255,255,.09);
  border-color:rgba(255,255,255,.26);
}
.btn:active{ transform:translateY(1px); }
.btn:disabled{ opacity:.55; cursor:not-allowed; }

.btn.primary{
  background:rgba(34,197,94,.18);
  border-color:rgba(34,197,94,.45);
}
.btn.primary:hover{
  background:rgba(34,197,94,.23);
  border-color:rgba(34,197,94,.60);
}

.sep{
  width:1px;
  height:28px;
  background:rgba(255,255,255,.14);
  margin:0 4px;
}

/* ---------------- Main ---------------- */
.main{
  width:min(1180px, 100%);
  margin:0 auto;
  padding:14px;
  display:flex;
  flex-direction:column;
  gap:14px;
}

/* ---------------- HUD ---------------- */
.hud{
  display:grid;
  grid-template-columns: 1fr 1.25fr 1fr;
  gap:12px;
  align-items:stretch;
}

.scoreBox, .centerBox{
  background:rgba(255,255,255,.05);
  border:1px solid rgba(255,255,255,.10);
  border-radius:16px;
  padding:12px;
}

.scoreBox .who{
  font-weight:850;
  letter-spacing:.2px;
}
.keysHint{
  margin-top:4px;
  font-size:12px;
  opacity:.85;
}

.scoreLine{
  display:flex;
  justify-content:space-between;
  align-items:baseline;
  margin-top:10px;
  font-size:14px;
}
.scoreLine.small{
  margin-top:6px;
  font-size:13px;
  opacity:.9;
}
.value{
  font-variant-numeric: tabular-nums;
  font-weight:850;
}

.centerBox{
  display:flex;
  flex-direction:column;
  gap:12px;
  justify-content:space-between;
}
.chordLabel{ font-size:12px; opacity:.85; }
.chordName{ font-size:22px; font-weight:900; letter-spacing:.2px; margin-top:4px; }

.timerWrap{ display:flex; flex-direction:column; gap:8px; }
.timerText{ font-variant-numeric: tabular-nums; }
.muted{ opacity:.75; }

.bar{
  height:10px;
  border-radius:999px;
  background:rgba(255,255,255,.07);
  overflow:hidden;
  border:1px solid rgba(255,255,255,.10);
}
.barFill{
  height:100%;
  width:0%;
  background:rgba(59,130,246,.55);
}

.meta{
  display:flex;
  justify-content:space-between;
  font-size:12px;
  opacity:.9;
}

/* ---------------- Keyboard area ---------------- */
.kbArea{
  background:rgba(255,255,255,.04);
  border:1px solid rgba(255,255,255,.10);
  border-radius:16px;
  padding:12px;
}

.kbTitle{
  font-weight:800;
  margin-bottom:10px;
  opacity:.95;
}

#keyboardWrap{
  position:relative;
  width:100%;
}

.keyboard{
  position:relative;
  width:100%;
  height:190px;
  border-radius:14px;
  border:1px solid rgba(255,255,255,.10);
  background:rgba(255,255,255,.02);
  overflow:hidden;
}

/* Split line (entre B3 et C4) */
#splitLine{
  position:absolute;
  top:0;
  bottom:0;
  width:4px;
  background:#ff2b2b;
  opacity:.95;
  pointer-events:none;
  z-index:50;
  border-radius:2px;
  box-shadow:0 0 0 1px rgba(0,0,0,.35);
}

.legend{
  margin-top:10px;
  font-size:12px;
  opacity:.9;
  display:flex;
  align-items:center;
  gap:10px;
  flex-wrap:wrap;
}
.sepSmall{
  width:1px;
  height:12px;
  background:rgba(255,255,255,.18);
  display:inline-block;
}
.dot{
  width:10px;
  height:10px;
  border-radius:999px;
  display:inline-block;
}
.dotL{ background:#19e6d7; }
.dotR{ background:#7fd6ff; }

/* ---------------- Keys ---------------- */
.key{
  position:absolute;
  top:0;               /* IMPORTANT : noirs alignés en haut des blancs */
  bottom:0;
  border:1px solid rgba(0,0,0,.55);
  user-select:none;
}

.key.white{
  background:rgba(255,255,255,.92);
  z-index:1;
}

.key.black{
  background:rgba(0,0,0,.88);
  z-index:3;
  border:1px solid rgba(255,255,255,.08);
}

.key .label{
  position:absolute;
  left:0;
  right:0;
  bottom:6px;
  text-align:center;
  font-size:12px;
  font-weight:750;
  color:rgba(0,0,0,.65);
  pointer-events:none;
}

.key.black .label{
  color:rgba(255,255,255,.55);
}

/* Masquage des labels après 1 minute */
body.hideKeyLabels .key.white .label{
  opacity:0;
}

/* ---------------- Validations couleurs ---------------- */
/* Joueur gauche (turquoise) */
.key.validOkL{
  background:#19e6d7 !important;
  box-shadow: 0 0 0 2px rgba(25,230,215,.35) inset, 0 0 14px rgba(25,230,215,.22);
}
.key.black.validOkL{ background:#12bfb2 !important; }

.key.validBadL{
  background: rgba(25,230,215,.22) !important;
  box-shadow: 0 0 0 2px rgba(25,230,215,.18) inset;
}
.key.black.validBadL{ background: rgba(25,230,215,.14) !important; }

/* Joueur droite (bleu ciel) — plein remplissage comme L */
.key.validOkR{
  background:#7fd6ff !important;
  box-shadow: 0 0 0 2px rgba(127,214,255,.35) inset, 0 0 14px rgba(127,214,255,.20);
}
.key.black.validOkR{ background:#4fbef5 !important; }

.key.validBadR{
  background: rgba(127,214,255,.22) !important;
  box-shadow: 0 0 0 2px rgba(127,214,255,.18) inset;
}
.key.black.validBadR{ background: rgba(127,214,255,.14) !important; }

/* ---------------- Touch controls (fallback) ---------------- */
.touchControls{
  position:fixed;
  inset:0;
  pointer-events:none;
  z-index:80;
}
.touchControls.hidden{ display:none; }

.touchRow{
  position:absolute;
  display:flex;
  gap:10px;
  pointer-events:auto;
}
.touchRow.topRow{
  top:18%;
  right:6%;
}
.touchRow.bottomRow{
  bottom:10%;
  left:6%;
}

.touchBtn{
  width:64px;
  height:64px;
  border-radius:18px;
  border:1px solid rgba(255,255,255,.18);
  background:rgba(255,255,255,.07);
  color:rgba(255,255,255,.92);
  font-size:22px;
  font-weight:900;
  backdrop-filter: blur(6px);
}

/* ---------------- Overlay ---------------- */
.overlay{
  position:fixed;
  inset:0;
  display:flex;
  align-items:center;
  justify-content:center;
  background:rgba(0,0,0,.60);
  z-index:90;
  padding:16px;
}
.overlay.hidden{ display:none; }

.panel{
  width:min(520px, 100%);
  background:rgba(15,23,42,.96);
  border:1px solid rgba(255,255,255,.12);
  border-radius:18px;
  padding:14px;
  box-shadow: 0 18px 55px rgba(0,0,0,.45);
}

.panelTitle{
  font-weight:900;
  font-size:16px;
}
.panelText{
  margin-top:8px;
  opacity:.92;
  line-height:1.35;
  font-size:13px;
}
.panelActions{
  margin-top:12px;
  display:flex;
  justify-content:flex-end;
  gap:8px;
}
.panelList{
  margin-top:10px;
  display:flex;
  flex-direction:column;
  gap:10px;
}

/* ---------------- Bonus renversement (overlay joyeux, gauche/droite) ---------------- */
.bonusPop{
  position:fixed;
  top: clamp(86px, 14vh, 160px);
  z-index:96;
  pointer-events:none;

  padding:12px 16px;
  border-radius:18px;
  font-weight:950;
  letter-spacing:.2px;
  font-size:16px;

  color:rgba(255,255,255,.96);
  text-shadow:0 2px 10px rgba(0,0,0,.35);

  background: radial-gradient(circle at 25% 30%,
    rgba(34,197,94,.92),
    rgba(59,130,246,.62)
  );
  border:1px solid rgba(255,255,255,.22);
  box-shadow: 0 18px 55px rgba(0,0,0,.45);

  opacity:0;
  transform: translateY(-10px) scale(.95);
}

.bonusPop.left{ left:14px; }
.bonusPop.right{ right:14px; }

.bonusPop.run{
  animation: bonusPopAnim 900ms ease-out both;
}

.bonusPop::before{
  content:"";
  position:absolute;
  inset:-10px;
  border-radius:22px;
  background: conic-gradient(
    from 180deg,
    rgba(255,255,255,.25),
    rgba(255,255,255,0),
    rgba(255,255,255,.18),
    rgba(255,255,255,0)
  );
  filter: blur(10px);
  opacity:.45;
  z-index:-1;
}

@keyframes bonusPopAnim{
  0%   { opacity:0; transform: translateY(-12px) scale(.90) rotate(-2deg); }
  18%  { opacity:1; transform: translateY(0)     scale(1.06) rotate(0deg); }
  55%  { opacity:1; transform: translateY(0)     scale(1.00) rotate(0deg); }
  100% { opacity:0; transform: translateY(-8px)  scale(.98) rotate(1deg); }
}

/* ---------------- Toast ---------------- */
.toast{
  position:fixed;
  left:50%;
  bottom:18px;
  transform:translateX(-50%);
  background:rgba(0,0,0,.78);
  border:1px solid rgba(255,255,255,.16);
  color:rgba(255,255,255,.92);
  padding:10px 12px;
  border-radius:999px;
  font-size:13px;
  z-index:95;
  max-width:min(92vw, 720px);
  text-align:center;
}
.toast.hidden{ display:none; }

/* ---------------- Responsive ---------------- */
@media (max-width: 980px){
  .hud{ grid-template-columns:1fr; }
  .keyboard{ height:170px; }
  .touchRow.topRow{ top:20%; right:5%; }
  .touchRow.bottomRow{ bottom:10%; left:5%; }
}

@media (max-width: 520px){
  .keyboard{ height:155px; }
  .btn{ padding:9px 11px; border-radius:12px; }
  .touchBtn{ width:58px; height:58px; border-radius:16px; }
}
