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

html, body {
  height: 100%;
  overflow: hidden;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #1a1a2e;
  color: #eee;
  touch-action: none;
  -webkit-user-select: none;
  user-select: none;
}

/* ── Screens ── */
.screen {
  display: none;
  height: 100%;
  flex-direction: column;
}
.screen.active {
  display: flex;
}

/* ── Song Selection ── */
.selection-header {
  text-align: center;
  padding: 20px 16px 8px;
  flex-shrink: 0;
}
.selection-header h1 {
  font-size: 28px;
  color: #e94560;
}
.subtitle {
  font-size: 14px;
  color: #888;
  margin-top: 4px;
}

.song-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 16px 16px;
  -webkit-overflow-scrolling: touch;
  touch-action: pan-y;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
  gap: 8px;
}

.song-card {
  background: #16213e;
  border: 1px solid #0f3460;
  border-left: 4px solid #0f3460;
  border-radius: 8px;
  padding: 10px 14px;
  cursor: pointer;
  transition: background 0.15s;
}
.song-card:active {
  background: #0f3460;
}
.song-card[data-difficulty="easy"] {
  border-left-color: #4CAF50;
}
.song-card[data-difficulty="medium"] {
  border-left-color: #FF9800;
}
.song-card[data-difficulty="hard"] {
  border-left-color: #F44336;
}

.song-card-title {
  font-size: 15px;
  font-weight: 600;
  line-height: 1.3;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.song-card-meta {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 4px;
  font-size: 12px;
  color: #888;
}
.song-card-artist {
  color: #aaa;
}
.song-card-artist::after {
  content: '\00B7';
  margin-left: 8px;
}
.song-card-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 1px 7px;
  border-radius: 8px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.song-card[data-difficulty="easy"] .song-card-badge {
  background: rgba(76, 175, 80, 0.2);
  color: #81C784;
}
.song-card[data-difficulty="medium"] .song-card-badge {
  background: rgba(255, 152, 0, 0.2);
  color: #FFB74D;
}
.song-card[data-difficulty="hard"] .song-card-badge {
  background: rgba(244, 67, 54, 0.2);
  color: #EF5350;
}
.song-card-notes {
  color: #666;
}

/* ── Gameplay Header ── */
.gameplay-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: #16213e;
  flex-shrink: 0;
}
.header-btn {
  background: none;
  border: 1px solid #0f3460;
  color: #eee;
  font-size: 18px;
  width: 36px;
  height: 36px;
  border-radius: 8px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.header-btn:active {
  background: #0f3460;
}
#btn-demo {
  font-size: 14px;
}
#btn-demo.demo-active {
  background: #e94560;
  border-color: #e94560;
}
#btn-labels {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.5px;
}
.song-title-display {
  font-size: 14px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  min-width: 0;
}
.progress-container {
  flex: 1;
  height: 8px;
  background: #0f3460;
  border-radius: 4px;
  overflow: hidden;
  min-width: 40px;
}
.progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, #4CAF50, #81C784);
  border-radius: 4px;
  transition: width 0.25s ease;
}

/* ── Note Guide ── */
.note-guide {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  padding: 8px;
  min-height: 60px;
}
.note-name {
  font-size: 36px;
  font-weight: 700;
  color: #e94560;
  text-shadow: 0 0 12px rgba(233, 69, 96, 0.4);
}

/* ── Piano ── */
.piano {
  flex: 1;
  position: relative;
  display: flex;
  min-height: 0;
  background: #0d0d1a;
  padding: 0 2px 6px;
  border-top: 3px solid #2a2a3e;
}

.key-white {
  flex: 1;
  background: linear-gradient(to bottom, #f8f8f8 0%, #fff 6%, #fff 85%, #eee 92%, #ddd 100%);
  border: 1px solid #bbb;
  border-top: none;
  border-radius: 0 0 7px 7px;
  cursor: pointer;
  position: relative;
  z-index: 1;
  touch-action: none;
  margin: 0 1px;
  box-shadow:
    -1px 0 0 rgba(0,0,0,0.08),
    1px 0 0 rgba(0,0,0,0.08),
    0 4px 3px rgba(0,0,0,0.3),
    0 1px 0 #ccc,
    inset 0 -1px 2px rgba(0,0,0,0.1);
  transition: box-shadow 0.06s, background 0.06s, transform 0.06s;
}
.key-white:active:not(.highlight-green):not(.highlight-yellow):not(.highlight-red) {
  background: linear-gradient(to bottom, #eee 0%, #f5f5f5 6%, #f5f5f5 85%, #e0e0e0 92%, #d0d0d0 100%);
  box-shadow:
    -1px 0 0 rgba(0,0,0,0.08),
    1px 0 0 rgba(0,0,0,0.08),
    0 2px 2px rgba(0,0,0,0.2),
    inset 0 -1px 2px rgba(0,0,0,0.1);
  transform: translateY(2px);
}

.key-black {
  position: absolute;
  top: 0;
  width: 5.5%;
  height: 60%;
  background: linear-gradient(to bottom, #1a1a1a 0%, #2a2a2a 40%, #1a1a1a 95%, #333 100%);
  border: 1px solid #000;
  border-top: none;
  border-radius: 0 0 4px 4px;
  z-index: 2;
  cursor: pointer;
  touch-action: none;
  box-shadow:
    -2px 0 2px rgba(0,0,0,0.4),
    2px 0 2px rgba(0,0,0,0.4),
    0 6px 4px rgba(0,0,0,0.6),
    inset 0 -3px 3px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.1);
  transition: box-shadow 0.06s, background 0.06s, transform 0.06s, height 0.06s;
}
.key-black:active:not(.highlight-green):not(.highlight-yellow):not(.highlight-red) {
  height: 58%;
  background: linear-gradient(to bottom, #111 0%, #222 40%, #111 95%, #2a2a2a 100%);
  box-shadow:
    -1px 0 1px rgba(0,0,0,0.3),
    1px 0 1px rgba(0,0,0,0.3),
    0 3px 2px rgba(0,0,0,0.4),
    inset 0 -2px 2px rgba(0,0,0,0.5);
  transform: translateY(2px);
}

/* ── Key Labels (Solfège) ── */
.key-label {
  position: absolute;
  left: 50%;
  transform: translateX(-50%);
  font-weight: 600;
  pointer-events: none;
  user-select: none;
  line-height: 1;
}
.key-white .key-label {
  bottom: 8px;
  font-size: 11px;
  color: #333;
}
.key-black .key-label {
  bottom: 6px;
  font-size: 8px;
  color: #ddd;
}
.piano.hide-labels .key-label {
  display: none;
}

/* Highlight colors */
.highlight-green {
  background: linear-gradient(to bottom, #66BB6A 0%, #4CAF50 50%, #388E3C 100%) !important;
  box-shadow: 0 6px 12px rgba(76, 175, 80, 0.6), inset 0 1px 0 rgba(255,255,255,0.3) !important;
}
.highlight-yellow {
  background: linear-gradient(to bottom, #FFD54F 0%, #FFC107 50%, #FFA000 100%) !important;
  box-shadow: 0 6px 12px rgba(255, 193, 7, 0.6), inset 0 1px 0 rgba(255,255,255,0.3) !important;
}
.highlight-red {
  background: linear-gradient(to bottom, #EF5350 0%, #F44336 50%, #D32F2F 100%) !important;
  box-shadow: 0 6px 12px rgba(244, 67, 54, 0.6), inset 0 1px 0 rgba(255,255,255,0.3) !important;
}

/* ── Overlays ── */
.overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.8);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.overlay.hidden {
  display: none;
}
.overlay-content {
  background: #16213e;
  border: 1px solid #0f3460;
  border-radius: 16px;
  padding: 32px 40px;
  text-align: center;
  min-width: 260px;
}
.overlay-content h2 {
  font-size: 28px;
  margin-bottom: 16px;
  color: #e94560;
}
.overlay-btn {
  display: block;
  width: 100%;
  padding: 12px;
  margin-top: 10px;
  font-size: 16px;
  font-weight: 600;
  background: #0f3460;
  color: #eee;
  border: none;
  border-radius: 8px;
  cursor: pointer;
  transition: background 0.15s;
}
.overlay-btn:active {
  background: #e94560;
}
.complete-message {
  font-size: 16px;
  color: #aaa;
  margin-bottom: 8px;
}

/* ── Free Play Mode ── */
.free-play-only {
  display: none !important;
}
#screen-gameplay.free-play .free-play-only {
  display: flex !important;
}
#screen-gameplay.free-play .song-only {
  display: none !important;
}
#btn-record.recording-active {
  background: #e94560;
  border-color: #e94560;
}
.free-play-card {
  border-left-color: #2196F3 !important;
}
.free-play-card .song-card-artist::after {
  display: none;
}

/* ── Responsive ── */
@media (max-height: 500px) {
  .selection-header { padding: 6px 16px 4px; }
  .selection-header h1 { font-size: 20px; }
  .subtitle { display: none; }
  .song-list { gap: 6px; padding: 6px 16px 10px; }
  .song-card { padding: 8px 12px; }
  .song-card-title { font-size: 13px; }
  .note-guide { min-height: 40px; padding: 4px; }
  .note-name { font-size: 28px; }
  .gameplay-header { padding: 4px 8px; }
}

@media (max-width: 480px) {
  .song-list { grid-template-columns: 1fr; }
  .overlay-content { padding: 24px 28px; min-width: 220px; }
}
