:root {
  --bg: #fef9f0;
  --panel: #fff8ed;
  --accent1: #ff6b6b;
  --accent2: #ffd93d;
  --accent3: #6bcb77;
  --accent4: #4d96ff;
  --accent5: #c77dff;
  --shadow: rgba(0,0,0,0.12);
  --white-key: #fffdf7;
  --black-key: #2d2a26;
  --border-key: #d4cfc5;
  --text: #3a3028;
  --ghost: rgba(77,150,255,0.18);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  background: var(--bg);
  font-family: 'Nunito', sans-serif;
  color: var(--text);
  height: 100dvh;
  height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  overflow: hidden;
  background-image:
    radial-gradient(circle at 15% 20%, rgba(255,107,107,0.08) 0%, transparent 50%),
    radial-gradient(circle at 85% 80%, rgba(77,150,255,0.08) 0%, transparent 50%),
    radial-gradient(circle at 50% 50%, rgba(255,217,61,0.05) 0%, transparent 70%);
}

/* ── HEADER ── */
header {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 4px 8px;
  width: 100%;
  flex-shrink: 0;
  box-sizing: border-box;
}

h1 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.6rem;
  background: linear-gradient(135deg, var(--accent1), var(--accent4));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: 1px;
  white-space: nowrap;
  flex-shrink: 0;
}
body.is-touch h1 { font-size: 1rem; }

.score-bar {
  display: flex;
  gap: 5px;
  margin-left: auto;
  align-items: center;
  flex-shrink: 0;
}

.score-box {
  background: var(--panel);
  border-radius: 10px;
  padding: 2px 7px;
  text-align: center;
  box-shadow: 0 2px 8px var(--shadow);
  border: 2px solid #ede8dc;
}

.score-box .label {
  font-size: 0.52rem;
  text-transform: uppercase;
  letter-spacing: 1px;
  color: #999;
  font-weight: 800;
}

.score-box .val {
  font-family: 'Fredoka One', cursive;
  font-size: 0.95rem;
  color: var(--accent1);
  line-height: 1;
}

#level-badge {
  background: linear-gradient(135deg, var(--accent2), var(--accent1));
  color: white;
  font-family: 'Fredoka One', cursive;
  font-size: 0.8rem;
  padding: 3px 9px;
  border-radius: 14px;
  box-shadow: 0 3px 10px rgba(255,107,107,0.3);
  white-space: nowrap;
  flex-shrink: 0;
}

/* ── FULLSCREEN BTN ── */
#fullscreen-btn {
  display: none;
  background: linear-gradient(135deg, var(--accent4), var(--accent5));
  border: none;
  border-radius: 12px;
  width: 44px;
  height: 44px;
  font-size: 1.3rem;
  cursor: pointer;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  -webkit-tap-highlight-color: transparent;
  color: white;
  box-shadow: 0 4px 14px rgba(77,150,255,0.55), 0 0 0 3px rgba(77,150,255,0.2);
  transition: transform 0.12s, box-shadow 0.12s;
  animation: fs-pulse 2s ease-in-out infinite;
}
@keyframes fs-pulse {
  0%, 100% { box-shadow: 0 4px 14px rgba(77,150,255,0.55), 0 0 0 3px rgba(77,150,255,0.2); }
  50%       { box-shadow: 0 4px 20px rgba(77,150,255,0.85), 0 0 0 6px rgba(77,150,255,0.35); }
}
#fullscreen-btn:active {
  transform: scale(0.92);
  box-shadow: 0 2px 8px rgba(77,150,255,0.4);
  animation: none;
}
body.is-touch #fullscreen-btn { display: flex; }

/* ── MOBILE CONTROLS ── */
#mobile-controls {
  display: none;
  gap: 3px;
  flex-shrink: 0;
}

.mob-btn {
  background: var(--panel);
  border: 2px solid #ede8dc;
  border-radius: 8px;
  width: 34px;
  height: 30px;
  font-size: 0.9rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.1s;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}
.mob-btn:active { background: var(--accent2); }
body.is-touch #mobile-controls { display: flex; }

/* ── GAME AREA ── */
#game-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;
  width: 100%;
  overflow: hidden;
  min-height: 0;
}

/* Dimensions 100% gérées par JS resizeCanvas() */
#canvas-container {
  position: relative;
  background: var(--panel);
  border-radius: 16px;
  box-shadow: 0 8px 32px var(--shadow), inset 0 1px 0 rgba(255,255,255,0.8);
  border: 3px solid #ede8dc;
  overflow: hidden;
  flex-shrink: 0;
}
body.is-touch #canvas-container {
  border-radius: 10px;
  border-width: 2px;
}

canvas { display: block; }

/* ── CONTROLS HINT (desktop uniquement) ── */
#controls-hint {
  margin-top: 8px;
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
  padding-bottom: 6px;
}
body.is-touch #controls-hint { display: none; }

.key-hint {
  background: var(--panel);
  border: 2px solid #ede8dc;
  border-radius: 10px;
  padding: 4px 10px;
  font-size: 0.75rem;
  font-weight: 800;
  color: #777;
  display: flex;
  align-items: center;
  gap: 5px;
}

.key-hint kbd {
  background: #fff;
  border: 2px solid #ccc;
  border-bottom: 3px solid #aaa;
  border-radius: 5px;
  padding: 1px 6px;
  font-family: 'Fredoka One', cursive;
  font-size: 0.8rem;
  color: var(--text);
}

/* ── OVERLAYS ── */
.overlay {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: flex-start;   /* pas center : évite le dépassement en bas */
  background: rgba(254,249,240,0.93);
  backdrop-filter: blur(6px);
  border-radius: 14px;
  z-index: 100;
  gap: 8px;
  padding: 12px 16px;
  overflow-y: auto;              /* scroll si vraiment trop petit */
}

/* Centrage vertical quand le contenu rentre */
.overlay::before {
  content: '';
  flex: 1;
  max-height: 20px;
}
.overlay::after {
  content: '';
  flex: 1;
  max-height: 20px;
}

.overlay h2 {
  font-family: 'Fredoka One', cursive;
  font-size: 1.5rem;
  background: linear-gradient(135deg, var(--accent1), var(--accent4));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  text-align: center;
  flex-shrink: 0;
}

.overlay p {
  font-size: 0.8rem;
  color: #888;
  text-align: center;
  line-height: 1.35;
  flex-shrink: 0;
}

.btn {
  background: linear-gradient(135deg, var(--accent4), var(--accent5));
  color: white;
  border: none;
  border-radius: 50px;
  padding: 9px 24px;
  font-family: 'Fredoka One', cursive;
  font-size: 1.05rem;
  cursor: pointer;
  box-shadow: 0 5px 18px rgba(77,150,255,0.35);
  transition: transform 0.12s, box-shadow 0.12s;
  flex-shrink: 0;
}
.btn:hover  { transform: translateY(-2px); box-shadow: 0 8px 24px rgba(77,150,255,0.45); }
.btn:active { transform: translateY(0); }

.final-score {
  font-family: 'Fredoka One', cursive;
  font-size: 2.2rem;
  color: var(--accent1);
  flex-shrink: 0;
}

/* ── PARTICLE CANVAS ── */
#particle-canvas {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 14px;
  z-index: 50;
}

/* ── FLASH ── */
#flash {
  position: absolute;
  inset: 0;
  pointer-events: none;
  border-radius: 14px;
  z-index: 60;
  opacity: 0;
  background: white;
  transition: opacity 0.05s;
}

/* ── PORTRAIT WARNING (display:flex activé par JS) ── */
#portrait-warning {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 999;
  background: var(--bg);
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  padding: 30px;
  text-align: center;
}
#portrait-warning .pw-icon {
  font-size: 3.5rem;
  animation: rotate90 1.4s ease-in-out infinite alternate;
}
@keyframes rotate90 { from { transform: rotate(0deg); } to { transform: rotate(90deg); } }
#portrait-warning h2 { font-family: 'Fredoka One', cursive; font-size: 1.6rem; color: var(--accent1); }
#portrait-warning p  { font-size: 0.95rem; color: #888; line-height: 1.5; }

/* ── RHYTHM DISC ── */
#rhythm-disc {
  position: absolute;
  z-index: 80;
  pointer-events: auto;
  display: none;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
  user-select: none;
  bottom: 12px;
  right: 12px;
}

#rhythm-disc .disc-inner {
  width: 60px;
  height: 60px;
  border-radius: 50%;
  background: radial-gradient(circle at 35% 30%, #fff6e0, #ffb830 60%, #e07000);
  box-shadow: 0 0 0 4px rgba(255,180,0,0.35), 0 6px 20px rgba(200,100,0,0.4);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1.7rem;
  transition: transform 0.07s, box-shadow 0.07s;
  position: relative;
}

#rhythm-disc .disc-inner::after {
  content: '';
  position: absolute;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: radial-gradient(circle at 40% 35%, #fff, #d4a000);
  box-shadow: 0 1px 4px rgba(0,0,0,0.35);
}

#rhythm-disc .disc-label {
  font-family: 'Fredoka One', cursive;
  font-size: 0.6rem;
  color: #c06000;
  margin-top: 3px;
  text-align: center;
  line-height: 1.2;
}

#rhythm-disc.beat-flash .disc-inner {
  transform: scale(1.18);
  box-shadow: 0 0 0 8px rgba(255,200,0,0.5), 0 8px 28px rgba(200,100,0,0.55);
}

#rhythm-dots {
  display: flex;
  gap: 4px;
  margin-top: 3px;
}

.rdot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: #ffe0a0;
  border: 2px solid #ffb830;
  transition: background 0.1s;
}
.rdot.filled { background: #ff8c00; border-color: #c05000; }

#rhythm-feedback {
  position: absolute;
  bottom: 85px;
  right: 10px;
  font-family: 'Fredoka One', cursive;
  font-size: 0.95rem;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.3s;
  z-index: 90;
}

/* ── TUTO OVERLAY ── */
.tuto-overlay {
  z-index: 110;
  /* Centrage strict, sans les pseudo-éléments du .overlay parent */
  justify-content: center !important;
  gap: 6px !important;
  padding: 8px !important;
}
.tuto-overlay::before,
.tuto-overlay::after { display: none !important; }

#tuto-stage {
  background: #fff;
  border: 2px solid #ede8dc;
  border-radius: 12px;
  padding: 6px;
  box-shadow: 0 4px 16px var(--shadow);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  flex-shrink: 1;
  min-height: 0;
  max-width: 100%;
}

#tuto-canvas {
  display: block;
  border-radius: 8px;
  background: var(--panel);
  width: 280px;
  max-width: 100%;
  height: auto;
  /* En cas d'écran très court, on borne aussi en hauteur */
  max-height: 35vh;
  object-fit: contain;
}

.tuto-caption {
  font-family: 'Fredoka One', cursive;
  font-size: 0.78rem;
  color: var(--text);
  text-align: center;
  line-height: 1.2;
  padding: 0 4px;
  min-height: 1.2em;
}

.tuto-dots {
  display: flex;
  gap: 8px;
  flex-shrink: 0;
}

.tdot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #ede8dc;
  border: 2px solid #d4cfc5;
  transition: background 0.2s, transform 0.2s;
}
.tdot.active {
  background: var(--accent1);
  border-color: var(--accent1);
  transform: scale(1.2);
}

.tuto-overlay .btn {
  padding: 7px 18px;
  font-size: 0.95rem;
}

.btn-secondary {
  background: linear-gradient(135deg, #c8c1b3, #a8a294) !important;
  box-shadow: 0 4px 14px rgba(120,110,100,0.3) !important;
}
.btn-secondary:hover { box-shadow: 0 6px 18px rgba(120,110,100,0.4) !important; }

/* Écrans très courts (paysage smartphone) : on compacte encore */
@media (max-height: 380px) {
  .tuto-overlay h2 { font-size: 1rem !important; }
  #tuto-canvas { max-height: 30vh; }
  .tuto-caption { font-size: 0.72rem; }
  .tuto-overlay .btn { padding: 5px 14px; font-size: 0.85rem; }
}

/* ── RATE BUTTON ── */
.btn-rate {
  background: linear-gradient(135deg, #ffc845, #ff8c00) !important;
  box-shadow: 0 4px 14px rgba(255,140,0,0.4) !important;
  font-size: 0.9rem !important;
  padding: 8px 18px !important;
  margin-top: 4px;
  animation: rate-glow 2.4s ease-in-out infinite;
}
@keyframes rate-glow {
  0%, 100% { box-shadow: 0 4px 14px rgba(255,140,0,0.4); }
  50%       { box-shadow: 0 4px 22px rgba(255,140,0,0.7); }
}
.btn-rate:hover  { transform: translateY(-2px); }
.btn-rate:active { transform: translateY(0); animation: none; }
