/* ─── Reset & Base ─────────────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

:root {
  --bg-primary:   #0a0a0f;
  --bg-secondary: #12121a;
  --bg-card:      #1a1a2a;
  --bg-input:     #1e1e2e;
  --accent-blue:  #4fc3f7;
  --accent-dark:  #0288d1;
  --accent-purple:#7c4dff;
  --accent-grad-start: #7c4dff;
  --accent-grad-end:   #448aff;
  --text-primary: #e8eaf6;
  --text-muted:   #7986cb;
  --border:       #2a2a3e;
  --error:        #ef5350;
  --white-key:    #e8e8e8;
  --white-key-hl: #4fc3f7;
  --black-key:    #1a1a1a;
  --black-key-hl: #0288d1;
  --hit-line:     rgba(79, 195, 247, 0.85);
}

html, body {
  height: 100%;
}

body {
  font-family: system-ui, 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg-primary);
  color: var(--text-primary);
  line-height: 1.5;
  min-height: 100vh;
}

/* ─── App Shell ────────────────────────────────────────────────────────────── */
#app {
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem 1.5rem 3rem;
  display: flex;
  flex-direction: column;
  gap: 1.75rem;
}

/* ─── Header ───────────────────────────────────────────────────────────────── */
header {
  text-align: center;
  padding-bottom: 0.5rem;
}

header h1 {
  font-size: clamp(1.75rem, 4vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.5px;
  background: linear-gradient(135deg, var(--accent-grad-start), var(--accent-grad-end));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

header .subtitle {
  margin-top: 0.4rem;
  color: var(--text-muted);
  font-size: 1rem;
}

/* ─── Input Section ────────────────────────────────────────────────────────── */
#input-section {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.input-row {
  display: flex;
  gap: 0.75rem;
}

#url-input {
  flex: 1;
  padding: 0.7rem 1rem;
  background: var(--bg-input);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text-primary);
  font-size: 0.95rem;
  font-family: inherit;
  transition: border-color 0.2s;
  outline: none;
}

#url-input:focus {
  border-color: var(--accent-purple);
  box-shadow: 0 0 0 3px rgba(124, 77, 255, 0.15);
}

#url-input::placeholder {
  color: #444466;
}

#process-btn {
  padding: 0.7rem 1.6rem;
  background: linear-gradient(135deg, var(--accent-grad-start), var(--accent-grad-end));
  border: none;
  border-radius: 8px;
  color: #fff;
  font-size: 0.95rem;
  font-weight: 600;
  cursor: pointer;
  transition: opacity 0.2s, transform 0.1s;
  white-space: nowrap;
}

#process-btn:hover {
  opacity: 0.88;
}

#process-btn:active {
  transform: scale(0.97);
}

#process-btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.error-text {
  color: var(--error);
  font-size: 0.875rem;
  padding-left: 0.25rem;
}

/* ─── Status Section ───────────────────────────────────────────────────────── */
#status-section {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 1.25rem 1.5rem;
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

#status-section[hidden] {
  display: none;
}

.status-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 0.9rem;
}

#status-text {
  color: var(--text-muted);
}

#status-percent {
  font-weight: 600;
  color: var(--accent-blue);
}

.progress-track {
  width: 100%;
  height: 8px;
  background: var(--bg-input);
  border-radius: 99px;
  overflow: hidden;
}

#progress-bar {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--accent-grad-start), var(--accent-grad-end));
  border-radius: 99px;
  transition: width 0.4s ease;
  position: relative;
}

#progress-bar::after {
  content: '';
  position: absolute;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  background: linear-gradient(
    90deg,
    transparent 0%,
    rgba(255, 255, 255, 0.25) 50%,
    transparent 100%
  );
  animation: shimmer 1.6s infinite;
}

@keyframes shimmer {
  0%   { transform: translateX(-100%); }
  100% { transform: translateX(100%); }
}

/* ─── Player Section ───────────────────────────────────────────────────────── */
#player-section {
  display: flex;
  flex-direction: column;
  gap: 0;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
}

#player-section[hidden] {
  display: none;
}

/* ─── Controls Bar ─────────────────────────────────────────────────────────── */
#controls {
  display: flex;
  align-items: center;
  gap: 0.75rem;
  padding: 0.75rem 1rem;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}

.control-btn {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-primary);
  font-size: 1rem;
  width: 2.4rem;
  height: 2.4rem;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
  flex-shrink: 0;
}

.control-btn:hover {
  background: var(--bg-input);
  border-color: var(--accent-blue);
}

.control-btn:active {
  transform: scale(0.95);
}

.control-label {
  font-size: 0.8rem;
  color: var(--text-muted);
  white-space: nowrap;
  user-select: none;
}

.control-select {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: 7px;
  color: var(--text-primary);
  font-size: 0.875rem;
  padding: 0.3rem 0.5rem;
  cursor: pointer;
  outline: none;
  height: 2.4rem;
}

.control-select:focus {
  border-color: var(--accent-blue);
}

.control-slider {
  -webkit-appearance: none;
  appearance: none;
  width: 90px;
  height: 4px;
  border-radius: 99px;
  background: var(--bg-input);
  outline: none;
  cursor: pointer;
  flex-shrink: 0;
}

.control-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-blue);
  cursor: pointer;
  transition: transform 0.1s;
}

.control-slider::-webkit-slider-thumb:hover {
  transform: scale(1.2);
}

.control-slider::-moz-range-thumb {
  width: 14px;
  height: 14px;
  border-radius: 50%;
  background: var(--accent-blue);
  border: none;
  cursor: pointer;
}

.sound-btn {
  font-size: 1.1rem;
}

/* ─── Notes Canvas ─────────────────────────────────────────────────────────── */
#notes-canvas {
  display: block;
  width: 100%;
  height: 400px;
  background: var(--bg-primary);
}

/* ─── Piano Container ──────────────────────────────────────────────────────── */
#piano-container {
  position: relative;
  width: 100%;
  height: 140px;
  background: #111118;
  border-top: 2px solid #000;
  overflow: hidden;
  flex-shrink: 0;
}

/* Keys are created by JS — base styles for both types */
.key {
  position: absolute;
  bottom: 0;
  border-radius: 0 0 5px 5px;
  cursor: pointer;
  transition: background 0.04s;
  user-select: none;
}

.key.white {
  background: var(--white-key);
  border: 1px solid #aaa;
  border-top: none;
  height: 100%;
  z-index: 1;
}

.key.white:hover {
  background: #d4efff;
}

.key.white.active {
  background: var(--white-key-hl);
  box-shadow: 0 0 12px rgba(79, 195, 247, 0.6);
}

.key.black {
  background: var(--black-key);
  border: 1px solid #000;
  border-top: none;
  height: 62%;
  z-index: 2;
  box-shadow: 2px 4px 6px rgba(0, 0, 0, 0.6);
}

.key.black:hover {
  background: #2a2a2a;
}

.key.black.active {
  background: var(--black-key-hl);
  box-shadow: 0 0 12px rgba(2, 136, 209, 0.7);
}

/* ─── Responsive ───────────────────────────────────────────────────────────── */
@media (max-width: 640px) {
  #app {
    padding: 1.25rem 0.75rem 2rem;
  }

  .input-row {
    flex-direction: column;
  }

  #process-btn {
    width: 100%;
  }

  #controls {
    gap: 0.5rem;
  }

  .control-slider {
    width: 60px;
  }

  #notes-canvas {
    height: 260px;
  }

  #piano-container {
    height: 100px;
  }
}
