@import url('https://fonts.googleapis.com/css2?family=Fredoka:wght@400;600;700&display=swap');

:root{
  --fg: #e5e7eb;
  --muted: rgba(229,231,235,.72);
  --accent: rgba(255,210,120,1);

  --panel: rgba(255,255,255,.06);
  --bd: rgba(255,255,255,.14);

  --r: 18px;
  --hudH: 56px;

  --whiteW: clamp(22px, 3.2vw, 46px);
  --whiteH: clamp(120px, 32vh, 200px);

  --blackW: clamp(16px, 2.2vw, 30px);
  --blackH: clamp(78px, 20vh, 126px);

  --timerSize: clamp(84px, 14vh, 128px);
  --timerStroke: 10px;

  --bgA1: hsl(210 14% 14%);
  --bgB1: hsl(280 10% 15%);
  --bgC1: hsl(160 10% 14%);

  --bgA2: hsl(230 12% 14%);
  --bgB2: hsl( 20 10% 15%);
  --bgC2: hsl(110 10% 14%);

  --bgMix: 0;
}

*{ box-sizing:border-box; }
html,body{ height:100%; margin:0; }

body{
  color: var(--fg);
  font-family: "Fredoka", system-ui,-apple-system,Segoe UI,Roboto,Arial,sans-serif;
  overflow-x: hidden;

  background:
    radial-gradient(1200px 800px at 10% 10%, rgba(255,255,255,.04), transparent 60%),
    linear-gradient(120deg, var(--bgA1), var(--bgB1), var(--bgC1));
  background-size: 180% 180%;
  animation: bgDrift 16s ease-in-out infinite;
}

body::before{
  content:"";
  position: fixed;
  inset: 0;
  pointer-events:none;
  z-index:-1;

  background:
    radial-gradient(1200px 800px at 90% 15%, rgba(255,255,255,.04), transparent 60%),
    linear-gradient(120deg, var(--bgA2), var(--bgB2), var(--bgC2));
  background-size: 180% 180%;
  animation: bgDrift 18s ease-in-out infinite reverse;

  opacity: var(--bgMix);
  transition: opacity 2.2s ease;
}

body::after{
  content:"";
  position: fixed;
  inset: 0;
  pointer-events:none;
  z-index:-1;
  background:
    repeating-linear-gradient(0deg, rgba(255,255,255,.02), rgba(255,255,255,.02) 1px, transparent 1px, transparent 4px);
  opacity: .12;
  mix-blend-mode: overlay;
}

@keyframes bgDrift{
  0%   { background-position: 0% 50%; }
  50%  { background-position: 100% 50%; }
  100% { background-position: 0% 50%; }
}

/* Écrans */
.screen{ display:none; min-height:100%; }
.screen.active{ display:block; }

#startScreen.active,
#endScreen.active{
  min-height: 100vh;
  overflow: auto;
}

#gameScreen.active{
  height: 100vh;
  overflow: hidden;
}

.container{
  max-width: 960px;
  margin: 18px auto;
  padding: 16px;
}

.titleWiggle{
  display:inline-block;
  animation: titleWiggle 3.8s ease-in-out infinite;
}
@keyframes titleWiggle{
  0%,100% { transform: rotate(-1deg) translateY(0); }
  50%     { transform: rotate( 1deg) translateY(-2px); }
}

.subtitle{ color: var(--muted); margin-top: 6px; }

/* Pseudo */
.pseudo-input-group{
  margin: 14px 0 12px;
  display:flex;
  gap:10px;
  align-items:center;
}
.pseudo-input-group label{ color: var(--muted); }
.pseudo-input-group input{
  flex: 1;
  min-width: 220px;
  padding: 10px 12px;
  border-radius: 12px;
  border: 1px solid var(--bd);
  background: rgba(255,255,255,.04);
  color: var(--fg);
  outline: none;
}

/* Boutons */
.btn-primary{
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.18);
  background: linear-gradient(135deg, rgba(255,255,255,.10), rgba(255,255,255,.06));
  color: var(--fg);
  cursor: pointer;
  font-weight: 800;
  transition: transform .12s ease, filter .12s ease, background .12s ease;
}
.btn-primary:hover{ filter: brightness(1.08); transform: translateY(-1px); }
.btn-primary:active{ transform: translateY(0) scale(.98); }

.btnPop{ animation: btnPop 2.6s ease-in-out infinite; }
@keyframes btnPop{
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-2px); }
}

.instructions{
  margin-top: 14px;
  padding: 14px;
  border-radius: var(--r);
  border: 1px solid var(--bd);
  background: linear-gradient(135deg, rgba(255,255,255,.07), rgba(255,255,255,.04));
  backdrop-filter: blur(10px);
}
.instructions h3{ margin:0 0 10px; }
.instructions ul{ margin:0; padding-left: 18px; color: var(--muted); }
.green{ color: rgba(80,220,160,1); font-weight:800; }
.red{ color: rgba(255,120,120,1); font-weight:800; }

/* HUD */
.hud{
  position: fixed;
  top: 0; left: 0; right: 0;
  height: var(--hudH);
  z-index: 20;
  display: flex;
  gap: 10px;
  padding: 8px 10px;
  background: rgba(0,0,0,.35);
  border-bottom: 1px solid rgba(255,255,255,.08);
  backdrop-filter: blur(10px);
  align-items: center;
  overflow: hidden;
}
.hud-item{
  display:flex;
  gap: 6px;
  align-items: baseline;
  padding: 6px 9px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.10);
  background: linear-gradient(135deg, rgba(255,255,255,.06), rgba(255,255,255,.03));
  white-space: nowrap;
}
.hud .label{ color: var(--muted); font-size: 12px; }
.hud .value{ font-weight: 900; font-size: 13px; }
.chord-name{ 
  color: var(--accent); 
  font-size: 32px !important;
  font-weight: 900;
  text-shadow: 0 0 10px rgba(255,210,120,.4);
}

/* Affichage de la grille complète */
.progression-display {
  display: flex;
  gap: 12px;
  align-items: center;
  padding: 8px 12px;
  border-radius: 14px;
  border: 1px solid rgba(255,255,255,.12);
  background: linear-gradient(135deg, rgba(255,255,255,.08), rgba(255,255,255,.04));
}

.progression-display .label {
  color: var(--muted);
  font-size: 14px;
  font-weight: 700;
}

.progression-chords {
  display: flex;
  gap: 8px;
}

.progression-chord {
  font-size: 28px;
  font-weight: 900;
  color: rgba(255,255,255,.6);
  transition: all 0.2s ease;
}

.progression-chord.current {
  color: var(--accent);
  transform: scale(1.2);
  text-shadow: 0 0 15px rgba(255,210,120,.6);
}

/* Phase display */
.phase-display .value{
  color: var(--accent);
  font-weight: 900;
}

/* Bouton FR/EN */
.btn-notation{
  padding: 8px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.22);
  background: rgba(255,255,255,.08);
  color: inherit;
  cursor: pointer;
  font-weight: 700;
  transition: transform .12s ease, filter .12s ease;
}
.btn-notation:hover{ filter: brightness(1.1); transform: translateY(-1px); }
.btn-notation:active{ transform: translateY(0) scale(.98); }
.btn-notation[aria-pressed="true"]{ background: rgba(255,255,255,.16); }

/* Overlay feedback */
.feedbackOverlay{
  position: fixed;
  left: 50%;
  top: calc(var(--hudH) + 10px);
  transform: translateX(-50%) translateY(-10px);
  z-index: 999;
  pointer-events: none;

  padding: 10px 14px;
  border-radius: 16px;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(0,0,0,.55);
  color: var(--fg);
  font-weight: 900;
  letter-spacing: .2px;
  font-size: 15px;

  opacity: 0;
  filter: drop-shadow(0 18px 30px rgba(0,0,0,.4));
  transition: opacity .2s ease;
}
.feedbackOverlay.show{
  opacity: 1;
}
.feedbackOverlay.correct{ border-color: rgba(80,220,160,.35); }
.feedbackOverlay.wrong{ border-color: rgba(255,120,120,.35); }
.feedbackOverlay.penalty{ 
  border-color: rgba(255,120,120,.8);
  background: linear-gradient(135deg, rgba(255,120,120,.25), rgba(180,60,60,.25));
  animation: penaltyPulse 0.6s ease-in-out 3;
  font-size: 16px;
  box-shadow: 0 0 30px rgba(255,120,120,.5);
}

@keyframes penaltyPulse{
  0%, 100% { 
    transform: translateX(-50%) translateY(0) scale(1); 
    filter: brightness(1);
  }
  50% { 
    transform: translateX(-50%) translateY(-3px) scale(1.08); 
    filter: brightness(1.2);
  }
}

/* Layout centré */
.gameLayout{
  position: relative;
  padding-top: calc(var(--hudH) + 10px);
  padding-left: clamp(8px, 1.2vw, 12px);
  padding-right: clamp(8px, 1.2vw, 12px);
  padding-bottom: 10px;

  height: 100vh;
  overflow: hidden;

  display: grid;
  grid-template-columns: minmax(480px, 800px) minmax(220px, 320px);
  gap: clamp(10px, 1.4vw, 16px);

  justify-content: center;
  align-items: stretch;

  max-width: 1320px;
  margin: 0 auto;
}

.rightColumn{
  display: flex;
  flex-direction: column;
  gap: clamp(10px, 1.4vw, 16px);
}

.panel{
  border-radius: var(--r);
  border: 1px solid var(--bd);
  background: linear-gradient(135deg, rgba(255,255,255,.08), rgba(255,255,255,.04));
  padding: clamp(10px, 1.3vw, 14px);
  min-height: 0;
  backdrop-filter: blur(10px);
  animation: panelFloat 5.8s ease-in-out infinite;
}
.panel:nth-child(2){ animation-delay: .8s; }
.panel:nth-child(3){ animation-delay: 1.6s; }

@keyframes panelFloat{
  0%,100% { transform: translateY(0); }
  50%     { transform: translateY(-4px); }
}

.panelTitle{
  font-weight: 900;
  margin-bottom: 8px;
  color: rgba(255,255,255,.92);
  font-size: 14px;
}

/* Info panel */
.infoContent{
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.phase-info{
  margin: 0;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.4;
}

.score-breakdown{
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.breakdown-item{
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
}

.breakdown-label{
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.breakdown-value{
  font-weight: 900;
  font-size: 14px;
  color: var(--accent);
}

/* Stats panel */
.statsContent{
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.stat-item{
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 6px 10px;
  border-radius: 10px;
  background: rgba(255,255,255,.04);
  border: 1px solid rgba(255,255,255,.08);
}

.stat-label{
  color: var(--muted);
  font-size: 12px;
  font-weight: 700;
}

.stat-value{
  font-weight: 900;
  font-size: 14px;
}

/* Piano */
.pianoPanel{
  display: flex;
  flex-direction: column;
  min-height: 0;
  overflow: hidden;
}
.piano{
  position: relative;
  width: calc(var(--whiteW) * 14);
  height: var(--whiteH);
  margin: 6px auto 0;
}
.piano-key{ user-select:none; cursor: pointer; }
.white-key{
  position: relative;
  display: inline-flex;
  width: var(--whiteW);
  height: var(--whiteH);
  border: 1px solid rgba(0,0,0,.55);
  background: rgba(255,255,255,.92);
  color: #0b1020;
  border-bottom-left-radius: 10px;
  border-bottom-right-radius: 10px;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 8px;
  box-shadow: inset 0 -6px 10px rgba(0,0,0,.10);
  transition: transform .08s ease, filter .08s ease;
}
.white-key:active{ transform: translateY(1px); filter: brightness(.98); }
.black-key{
  position: absolute;
  top: 0;
  width: var(--blackW);
  height: var(--blackH);
  background: rgba(0,0,0,.92);
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.10);
  z-index: 5;
  box-shadow: 0 10px 18px rgba(0,0,0,.35);
  cursor: pointer;
}
.key-label{
  font-size: clamp(12px, 1.3vw, 14px);
  font-weight: 900;
  opacity: .92;
}

.piano-key.playing{
  outline: 6px solid rgba(80,220,160,.95);
  outline-offset: -4px;
  box-shadow: 
    0 0 20px rgba(80,220,160,.8),
    0 0 40px rgba(80,220,160,.5),
    inset 0 0 20px rgba(80,220,160,.3);
  animation: keyPlaying .3s ease-in-out;
  z-index: 10;
}

@keyframes keyPlaying{
  0%,100% { 
    filter: brightness(1.1);
    transform: scale(1.03);
  }
  50%     { 
    filter: brightness(1.2);
    transform: scale(1.05);
  }
}

/* Loading overlay */
.loadingOverlay{
  position: fixed;
  inset: 0;
  display: none;
  align-items: center;
  justify-content: center;
  z-index: 1000;
  background: rgba(0,0,0,.45);
  backdrop-filter: blur(8px);
}
.loadingOverlay.show{ display:flex; }
.loadingCard{
  width: min(520px, 92vw);
  border-radius: 18px;
  border: 1px solid rgba(255,255,255,.18);
  background: linear-gradient(135deg, rgba(255,255,255,.10), rgba(255,255,255,.05));
  box-shadow: 0 24px 60px rgba(0,0,0,.35);
  padding: 16px 16px 14px;
}
.loadingText{
  font-weight: 900;
  margin-bottom: 10px;
}
.loadingBar{
  width: 100%;
  height: 12px;
  border-radius: 999px;
  overflow: hidden;
  border: 1px solid rgba(255,255,255,.16);
  background: rgba(0,0,0,.22);
}
.loadingBarFill{
  height: 100%;
  width: 0%;
  border-radius: 999px;
  background: linear-gradient(90deg, rgba(255,210,120,.95), rgba(120,190,255,.90));
  transition: width .18s ease;
}
.loadingPercent{
  margin-top: 8px;
  color: rgba(229,231,235,.88);
  font-weight: 800;
}

/* Final stats */
.final-stats{
  margin: 20px 0;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.stat{
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 16px;
  border-radius: 14px;
  border: 1px solid var(--bd);
  background: linear-gradient(135deg, rgba(255,255,255,.08), rgba(255,255,255,.04));
}

.stat-label{
  color: var(--muted);
  font-weight: 700;
}

.stat-value{
  font-weight: 900;
  font-size: 18px;
  color: var(--accent);
}

/* Smartphone / CPU */
.is-mobile .panel{ animation: none; }
.is-mobile .titleWiggle{ animation: none; }
.is-mobile body{ animation-duration: 24s; }
.is-mobile body::before{ animation-duration: 26s; }

@media (orientation: landscape) and (max-width: 980px){
  :root{
    --hudH: 52px;
    --whiteW: clamp(22px, 3.6vw, 44px);
    --whiteH: clamp(120px, 34vh, 190px);
    --blackW: clamp(16px, 2.6vw, 30px);
    --blackH: clamp(78px, 22vh, 120px);
    --timerSize: clamp(84px, 14vh, 120px);
  }
  .hud{ gap: 8px; padding: 7px 8px; }
  .hud-item{ padding: 5px 8px; }
  .hud .label{ font-size: 11px; }
  .hud .value{ font-size: 12px; }
}

@media (max-width: 820px){
  #gameScreen.active{
    height: auto;
    overflow: auto;
  }
  .gameLayout{
    height: auto;
    overflow: visible;
    grid-template-columns: 1fr;
    max-width: 720px;
  }
}

/* ============================================================
   ORIENTATION BANNER (smartphone portrait → demande paysage)
============================================================ */
#orientationBanner {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 9999;
  background: rgba(11, 16, 32, 0.97);
  backdrop-filter: blur(20px);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  text-align: center;
  padding: 24px;
  animation: fadeInBanner 0.3s ease;
}

#orientationBanner.show {
  display: flex;
}

@keyframes fadeInBanner {
  from { opacity: 0; transform: scale(0.95); }
  to   { opacity: 1; transform: scale(1); }
}

.orientation-icon {
  font-size: 64px;
  animation: rotateIcon 1.8s ease-in-out infinite;
}

@keyframes rotateIcon {
  0%,100% { transform: rotate(0deg); }
  30%     { transform: rotate(-90deg); }
  60%     { transform: rotate(-90deg); }
  90%     { transform: rotate(0deg); }
}

.orientation-title {
  font-size: 22px;
  font-weight: 900;
  color: var(--accent);
  margin: 0;
}

.orientation-text {
  font-size: 14px;
  color: var(--muted);
  max-width: 280px;
  line-height: 1.5;
  margin: 0;
}

.orientation-skip {
  margin-top: 8px;
  padding: 10px 20px;
  border-radius: 12px;
  border: 1px solid rgba(255,255,255,.18);
  background: rgba(255,255,255,.08);
  color: var(--muted);
  cursor: pointer;
  font-size: 13px;
  font-weight: 700;
  font-family: inherit;
  transition: filter .15s;
}
.orientation-skip:hover { filter: brightness(1.2); }

/* ============================================================
   QUALITY INDICATOR (niveau de qualité audio adaptatif)
============================================================ */
#qualityIndicator {
  display: none;
  position: fixed;
  bottom: 10px;
  right: 10px;
  z-index: 500;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid rgba(255,255,255,.12);
  background: rgba(0,0,0,.55);
  backdrop-filter: blur(8px);
  font-size: 11px;
  font-weight: 800;
  gap: 6px;
  align-items: center;
  transition: all 0.4s ease;
}

#qualityIndicator.show {
  display: flex;
}

.quality-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  transition: background 0.4s ease;
}

#qualityIndicator.quality-high  .quality-dot { background: rgba(80, 220, 160, 1); }
#qualityIndicator.quality-med   .quality-dot { background: rgba(255, 210, 120, 1); }
#qualityIndicator.quality-low   .quality-dot { background: rgba(255, 100, 100, 1); }

#qualityIndicator.quality-high  { border-color: rgba(80, 220, 160, .3); }
#qualityIndicator.quality-med   { border-color: rgba(255, 210, 120, .3); }
#qualityIndicator.quality-low   { border-color: rgba(255, 100, 100, .3); }

.quality-label {
  color: var(--muted);
}

/* Alerte CPU visible */
#cpuAlert {
  display: none;
  position: fixed;
  top: calc(var(--hudH) + 8px);
  left: 50%;
  transform: translateX(-50%);
  z-index: 600;
  padding: 8px 14px;
  border-radius: 12px;
  border: 1px solid rgba(255,100,100,.4);
  background: linear-gradient(135deg, rgba(255,100,100,.2), rgba(180,50,50,.2));
  backdrop-filter: blur(10px);
  font-size: 12px;
  font-weight: 800;
  color: rgba(255,160,160,1);
  gap: 6px;
  align-items: center;
  white-space: nowrap;
  transition: opacity 0.4s;
}
#cpuAlert.show { display: flex; }

/* Mode LOW quality : désactiver les animations coûteuses */
.quality-low-mode .panel { animation: none !important; }
.quality-low-mode .titleWiggle { animation: none !important; }
.quality-low-mode .btnPop { animation: none !important; }
.quality-low-mode body { animation: none !important; }
.quality-low-mode body::before { animation: none !important; }
