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

:root {
  --bg: #08080f;
  --surface: #10101c;
  --surface2: #181828;
  --surface3: #222236;
  --accent: #7c3aed;
  --accent2: #a855f7;
  --accent-glow: rgba(124, 58, 237, 0.35);
  --hit: #22c55e;
  --hit-glow: rgba(34, 197, 94, 0.6);
  --text: #eeeeff;
  --text-dim: #7777aa;
  --border: rgba(255, 255, 255, 0.07);
  --white-key: #f0ece0;
  --black-key: #141420;
}

body {
  font-family: 'Inter', sans-serif;
  background: var(--bg);
  color: var(--text);
  height: 100dvh;
  overflow: hidden;
  display: flex;
  flex-direction: column;
  user-select: none;
  -webkit-user-select: none;
}

/* HEADER */
header {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.logo {
  font-size: 1.1rem;
  font-weight: 900;
  background: linear-gradient(135deg, #a855f7, #7c3aed);
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
  white-space: nowrap;
}

.search-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  flex: 1;
  min-width: 180px;
  position: relative;
}

.search-icon {
  position: absolute;
  left: 10px;
  color: var(--text-dim);
  font-size: 0.85rem;
  pointer-events: none;
}

#songSearch {
  flex: 1;
  background: var(--surface2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 8px 14px 8px 34px;
  font-size: 0.88rem;
  font-family: 'Inter', sans-serif;
  outline: none;
  transition: border-color 0.2s, box-shadow 0.2s;
}

#songSearch:focus {
  border-color: var(--accent2);
  box-shadow: 0 0 0 3px var(--accent-glow);
}

#songSearch::placeholder {
  color: var(--text-dim);
}

/* Suggestions */
#suggestions {
  display: none;
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--surface2);
  border: 1px solid rgba(168, 85, 247, 0.2);
  border-radius: 12px;
  z-index: 50;
  box-shadow: 0 20px 40px rgba(0, 0, 0, 0.7);
  max-height: 260px;
  overflow-y: auto;
}

#suggestions.open {
  display: block;
}

.suggestion-item {
  padding: 10px 14px;
  cursor: pointer;
  font-size: 0.88rem;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: background 0.1s;
  border-bottom: 1px solid var(--border);
}

.suggestion-item:last-child {
  border-bottom: none;
}

.suggestion-item:hover,
.suggestion-item.active {
  background: var(--surface3);
}

.suggestion-item .tag {
  font-size: 0.68rem;
  padding: 2px 6px;
  border-radius: 4px;
  background: var(--accent-glow);
  color: var(--accent2);
  font-weight: 600;
  flex-shrink: 0;
}

/* Controls */
.controls {
  display: flex;
  align-items: center;
  gap: 8px;
}

.btn {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 9px 18px;
  border-radius: 10px;
  border: none;
  font-family: 'Inter', sans-serif;
  font-size: 0.88rem;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
  white-space: nowrap;
}

.btn-primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  box-shadow: 0 4px 16px var(--accent-glow);
  font-size: 1rem;
  padding: 10px 24px;
}

.btn-primary:hover {
  transform: translateY(-1px);
  box-shadow: 0 6px 24px var(--accent-glow);
}

.btn-primary:active {
  transform: translateY(0);
}

.btn-ghost {
  background: var(--surface2);
  color: var(--text-dim);
  border: 1px solid var(--border);
}

.btn-ghost:hover {
  background: var(--surface3);
  color: var(--text);
}

.wait-mode {
  display: flex;
  align-items: center;
  gap: 6px;
  font-size: 0.8rem;
  color: var(--text-dim);
  cursor: pointer;
  background: var(--surface2);
  padding: 6px 12px;
  border-radius: 8px;
  border: 1px solid var(--border);
  transition: color 0.2s, border-color 0.2s;
}

.wait-mode:hover {
  color: var(--text);
  border-color: rgba(168, 85, 247, 0.4);
}

.wait-mode input {
  accent-color: var(--accent2);
  cursor: pointer;
  width: 14px;
  height: 14px;
}

.tempo-wrap {
  display: flex;
  align-items: center;
  gap: 6px;
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 6px 10px;
}

.tempo-wrap label {
  font-size: 0.72rem;
  color: var(--text-dim);
}

.tempo-wrap input[type=range] {
  width: 70px;
  accent-color: var(--accent2);
  cursor: pointer;
}

#tempoVal {
  font-size: 0.75rem;
  color: var(--accent2);
  font-weight: 700;
  min-width: 26px;
}

.btn-midi {
  display: flex;
  align-items: center;
  gap: 5px;
  padding: 8px 12px;
  border-radius: 10px;
  border: 1px dashed rgba(168, 85, 247, 0.4);
  background: rgba(124, 58, 237, 0.08);
  color: var(--accent2);
  font-size: 0.78rem;
  font-family: 'Inter', sans-serif;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
  transition: all 0.15s;
}

.btn-midi:hover {
  background: rgba(124, 58, 237, 0.18);
}

/* BIG NOTE DISPLAY (center piece) */
#noteDisplay {
  flex-shrink: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 14px 0 8px;
  gap: 24px;
  background: var(--bg);
}

#noteNameBig {
  font-size: 5rem;
  font-weight: 900;
  line-height: 1;
  color: var(--hit);
  text-shadow: 0 0 40px var(--hit-glow);
  min-width: 160px;
  text-align: center;
  transition: color 0.15s;
  letter-spacing: -2px;
}

#noteNameBig.idle {
  color: var(--text-dim);
  text-shadow: none;
}

.note-meta {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

#progressBar2 {
  width: 200px;
  height: 6px;
  background: var(--surface3);
  border-radius: 99px;
  overflow: hidden;
}

#progressFill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--hit));
  width: 0%;
  transition: width 0.12s linear;
  border-radius: 99px;
}

#songNameDisplay {
  font-size: 0.82rem;
  color: var(--text-dim);
  font-weight: 600;
  max-width: 200px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

#noteCounter {
  font-size: 0.72rem;
  color: var(--text-dim);
}

/* Status message */
#statusMsg {
  font-size: 0.78rem;
  color: var(--text-dim);
  min-width: 120px;
  text-align: center;
}

/* PIANO WRAPPER  */
#pianoSection {
  flex: 1;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  position: relative;
  background: linear-gradient(to bottom, #0c0c18, var(--bg));
  border-top: 2px solid rgba(124, 58, 237, 0.15);
}

/* Pointer arrow above active key */
#keyPointer {
  position: absolute;
  top: -42px;
  display: flex;
  flex-direction: column;
  align-items: center;
  pointer-events: none;
  transition: left 0.18s cubic-bezier(.25, .8, .25, 1);
  opacity: 0;
  z-index: 10;
}

#keyPointer.show {
  opacity: 1;
}

#keyPointer .ptr-label {
  background: var(--hit);
  color: #000;
  font-size: 1.1rem;
  font-weight: 900;
  padding: 4px 14px;
  border-radius: 20px;
  box-shadow: 0 0 20px var(--hit-glow);
  white-space: nowrap;
}

#keyPointer .ptr-arrow {
  width: 0;
  height: 0;
  border-left: 10px solid transparent;
  border-right: 10px solid transparent;
  border-top: 14px solid var(--hit);
  filter: drop-shadow(0 3px 8px var(--hit-glow));
}

#pianoWrap {
  flex: 1;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 40px 0 16px;
  display: flex;
  align-items: flex-start;
  justify-content: center;
  scrollbar-width: thin;
  scrollbar-color: var(--surface3) transparent;
}

#piano {
  position: relative;
  display: flex;
  height: 180px;
}

/* WHITE KEYS */
.key-white {
  position: relative;
  width: 46px;
  height: 170px;
  background: var(--white-key);
  border: 1px solid #c0bbab;
  border-radius: 0 0 10px 10px;
  margin: 0 1px;
  cursor: pointer;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 9px;
  flex-shrink: 0;
  box-shadow: 0 6px 14px rgba(0, 0, 0, 0.55), inset 0 -3px 5px rgba(0, 0, 0, 0.07);
  transition: background 0.06s, transform 0.06s, box-shadow 0.06s;
}

.key-white:active,
.key-white.pressed {
  background: #ddd8f0;
  transform: translateY(2px);
}

.key-white.highlight {
  background: linear-gradient(to bottom, #86efac, #16a34a);
  box-shadow: 0 0 30px var(--hit-glow), 0 6px 12px rgba(0, 0, 0, 0.3);
  animation: keyPop 0.2s ease;
}

.key-white.highlight-next {
  background: linear-gradient(to bottom, #fde047, #eab308);
  box-shadow: 0 6px 12px rgba(234, 179, 8, 0.4);
}

.key-label {
  font-size: 0.65rem;
  font-weight: 700;
  color: #bbb;
  letter-spacing: -0.3px;
}

.key-white.highlight .key-label {
  color: #052e16;
  font-size: 0.7rem;
}

.key-white.highlight-next .key-label {
  color: #422006;
}

/* BLACK KEYS */
.key-black {
  position: absolute;
  width: 32px;
  height: 108px;
  background: var(--black-key);
  border-radius: 0 0 6px 6px;
  cursor: pointer;
  z-index: 2;
  box-shadow: 0 7px 14px rgba(0, 0, 0, 0.85), inset 0 -2px 4px rgba(255, 255, 255, 0.04);
  transition: background 0.06s, transform 0.06s;
}

.key-black:active,
.key-black.pressed {
  background: #333;
  transform: translateY(2px);
}

.key-black.highlight {
  background: linear-gradient(to bottom, #16a34a, #22c55e);
  box-shadow: 0 0 20px var(--hit-glow);
  animation: keyPop 0.2s ease;
}

.key-black.highlight-next {
  background: linear-gradient(to bottom, #eab308, #facc15);
  box-shadow: 0 0 16px rgba(234, 179, 8, 0.4);
}

@keyframes keyPop {
  0% {
    transform: scale(1);
  }

  40% {
    transform: scaleY(0.97) translateY(2px);
  }

  100% {
    transform: scale(1);
  }
}

/* BOTTOM STATUS */
#statusBar {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 18px;
  padding: 6px 20px;
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.legend {
  display: flex;
  align-items: center;
  gap: 10px;
}

.legend-item {
  display: flex;
  align-items: center;
  gap: 5px;
  font-size: 0.72rem;
  color: var(--text-dim);
}

.legend-dot {
  width: 11px;
  height: 11px;
  border-radius: 3px;
}

/* MODAL */
#modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.88);
  backdrop-filter: blur(12px);
  z-index: 100;
  align-items: center;
  justify-content: center;
}

#modal.open {
  display: flex;
}

.modal-box {
  background: var(--surface);
  border: 1px solid rgba(168, 85, 247, 0.2);
  border-radius: 22px;
  padding: 32px;
  max-width: 440px;
  width: 92%;
  text-align: center;
  box-shadow: 0 30px 80px rgba(0, 0, 0, 0.7), 0 0 60px var(--accent-glow);
}

.modal-emoji {
  font-size: 2.8rem;
  margin-bottom: 12px;
}

.modal-box h3 {
  font-size: 1.5rem;
  font-weight: 900;
  margin-bottom: 10px;
}

.modal-box p {
  color: var(--text-dim);
  font-size: 0.9rem;
  line-height: 1.6;
  margin-bottom: 22px;
}

.modal-box .btn {
  width: 100%;
  justify-content: center;
}

/* Drag-drop overlay */
#dropOverlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(124, 58, 237, 0.15);
  border: 3px dashed var(--accent2);
  z-index: 200;
  align-items: center;
  justify-content: center;
  font-size: 1.5rem;
  font-weight: 900;
  color: var(--accent2);
  backdrop-filter: blur(4px);
}

#dropOverlay.show {
  display: flex;
}

#loadingBar {
  position: fixed;
  top: 0;
  left: 0;
  height: 3px;
  background: linear-gradient(90deg, var(--accent), var(--hit));
  width: 0%;
  transition: width 0.3s;
  z-index: 200;
  box-shadow: 0 0 10px var(--accent2);
}

::-webkit-scrollbar {
  width: 5px;
  height: 5px;
}

::-webkit-scrollbar-track {
  background: transparent;
}

::-webkit-scrollbar-thumb {
  background: var(--surface3);
  border-radius: 99px;
}