:root {
  --piano-black: #1e293b;
  --piano-white: #ffffff;
  --piano-white-active: #f1f5f9;
  --piano-black-active: #0f172a;
}

[data-theme="dark"] {
  --piano-black: #000000;
  --piano-white: #ffffff;
  --piano-white-active: #e2e8f0;
  --piano-black-active: #171717;
}

body {
  /* Background and color handled by shared.css */
  overflow-x: hidden;
  touch-action: manipulation;
}

.container {
  /* Inherits flex column and 100vh from shared.css */
  max-width: 100vw;
  padding: 1.5rem;
  width: 100%;
}

.piano-wrapper {
  width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0.75rem 0;
  margin-bottom: 1.5rem;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: thin;
  scrollbar-color: #222 #000;
}

.piano-wrapper::-webkit-scrollbar {
  height: 6px;
}

.piano-wrapper::-webkit-scrollbar-track {
  background: #000;
}

.piano-wrapper::-webkit-scrollbar-thumb {
  background: var(--border-subtle);
  border-radius: 3px;
}

.piano-wrapper::-webkit-scrollbar-thumb:hover {
  background: var(--text-tertiary);
}

.piano {
  position: relative;
  display: flex;
  height: 260px;
  margin: 0 auto;
  width: fit-content;
  user-select: none;
  -webkit-user-select: none;
  touch-action: none;
}

.key {
  position: relative;
  cursor: pointer;
  transition: all 0.05s cubic-bezier(0.4, 0, 0.2, 1);
  border: none;
  outline: none;
}

.key.white {
  width: 48px;
  height: 100%;
  background: var(--piano-white);
  border: 1px solid var(--border-subtle);
  border-radius: 0 0 4px 4px;
  z-index: 1;
  box-shadow: inset 0 -2px 3px rgba(0, 0, 0, 0.08);
}

.key.black {
  position: absolute;
  width: 32px;
  height: 58%;
  background: var(--piano-black);
  border: 1px solid var(--border-subtle);
  border-radius: 0 0 3px 3px;
  z-index: 2;
  box-shadow: 0 3px 6px rgba(0, 0, 0, 0.2);
}

.key.white:active,
.key.white.active {
  background: var(--piano-white-active);
  box-shadow: inset 0 3px 10px rgba(0, 0, 0, 0.1);
  transform: translateY(1px);
}

.key.black:active,
.key.black.active {
  background: var(--piano-black-active);
  box-shadow: inset 0 3px 8px rgba(0, 0, 0, 0.3);
  transform: translateY(1px);
}

.key-note {
  position: absolute;
  bottom: 10px;
  left: 50%;
  transform: translateX(-50%);
  font-size: 0.65rem;
  font-weight: 500;
  color: #999;
  pointer-events: none;
  letter-spacing: -0.01em;
  opacity: 0.7;
}

.key.black .key-note {
  color: #555;
  bottom: 6px;
  font-size: 0.6rem;
}

.key.active .key-note {
  color: #000;
  opacity: 1;
}

.key.black.active .key-note {
  color: #ccc;
}

.controls {
  display: flex;
  justify-content: center;
  align-items: center;
  gap: 1.5rem;
  padding: 1.25rem 1rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 1.5rem;
  margin-bottom: 1.25rem;
  flex-wrap: wrap;
  box-shadow: 0 4px 12px var(--shadow-md);
}

.control-item {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.sustain-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 0.25rem;
  padding: 0.625rem 1.25rem;
  background: var(--bg-body);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 0.75rem;
  cursor: pointer;
  transition: all 0.2s;
  min-width: 72px;
  touch-action: manipulation;
}

.sustain-btn .sustain-icon {
  stroke: currentColor;
}

.sustain-btn:hover,
.sustain-btn:active {
  background: var(--bg-card);
  border-color: var(--accent);
  color: var(--accent);
}

.sustain-btn.active {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
  transform: scale(0.98);
}

.sustain-label {
  font-size: 0.7rem;
  font-weight: 600;
  letter-spacing: 0.03em;
  text-transform: uppercase;
}

.volume-control {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.volume-icon {
  stroke: #666;
  flex-shrink: 0;
}

#volume {
  width: 100px;
  height: 3px;
  background: #222;
  border-radius: 1.5px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
  cursor: pointer;
}

#volume::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 12px;
  height: 12px;
  background: #fff;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

#volume::-webkit-slider-thumb:hover,
#volume::-webkit-slider-thumb:active {
  transform: scale(1.2);
  box-shadow: 0 2px 8px rgba(255, 255, 255, 0.3);
}

#volume::-moz-range-thumb {
  width: 12px;
  height: 12px;
  background: #fff;
  border: none;
  border-radius: 50%;
  cursor: pointer;
  transition: all 0.2s;
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.5);
}

#volume::-moz-range-thumb:hover,
#volume::-moz-range-thumb:active {
  transform: scale(1.2);
  box-shadow: 0 2px 8px rgba(255, 255, 255, 0.3);
}

#volume-value {
  font-size: 0.8rem;
  font-weight: 600;
  color: #666;
  min-width: 35px;
  font-variant-numeric: tabular-nums;
}

.octave-control {
  display: flex;
  align-items: center;
  gap: 0.625rem;
}

.octave-btn {
  width: 32px;
  height: 32px;
  background: var(--bg-body);
  color: var(--text-secondary);
  border: 1px solid var(--border-subtle);
  border-radius: 0.5rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all 0.2s;
  padding: 0;
  touch-action: manipulation;
}

.octave-btn svg {
  stroke: currentColor;
}

.octave-btn:hover,
.octave-btn:active {
  background: var(--bg-card);
  border-color: var(--accent);
  color: var(--accent);
}

#octave-display {
  font-size: 0.875rem;
  font-weight: 600;
  color: #999;
  min-width: 28px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.instructions {
  text-align: center;
  padding: 0.875rem;
  background: var(--bg-card);
  border: 1px solid var(--border-subtle);
  border-radius: 1rem;
}

.instructions p {
  font-size: 0.8rem;
  color: #555;
  line-height: 1.5;
  letter-spacing: 0.01em;
}

@media (max-width: 768px) {
  .container {
    padding: 1rem;
  }

  .piano {
    height: 240px;
  }

  .key.white {
    width: 44px;
  }

  .key.black {
    width: 30px;
  }

  .controls {
    gap: 1.25rem;
    padding: 1rem 0.75rem;
  }

  .control-item {
    gap: 0.5rem;
  }

  .sustain-btn {
    min-width: 68px;
    padding: 0.5rem 1rem;
  }

  #volume {
    width: 90px;
  }

  .instructions p {
    font-size: 0.75rem;
  }
}

@media (max-width: 480px) {
  .piano {
    height: 220px;
  }

  .key.white {
    width: 40px;
  }

  .key.black {
    width: 28px;
  }

  .controls {
    gap: 1rem;
    padding: 0.875rem 0.625rem;
  }

  .sustain-btn {
    min-width: 64px;
    padding: 0.5rem 0.875rem;
  }

  .sustain-btn svg {
    width: 20px;
    height: 20px;
  }

  .volume-icon {
    width: 18px;
    height: 18px;
  }

  #volume {
    width: 75px;
  }

  .octave-btn {
    width: 30px;
    height: 30px;
  }

  .octave-btn svg {
    width: 14px;
    height: 14px;
  }

  #octave-display {
    font-size: 0.8125rem;
    min-width: 24px;
  }

  .instructions {
    padding: 0.75rem;
  }

  .instructions p {
    font-size: 0.7rem;
  }
}

@media (hover: none) and (pointer: coarse) {
  .key.white:hover {
    background: #fff;
  }

  .key.black:hover {
    background: #000;
  }
}

@media (max-height: 700px) {
  .piano {
    height: 200px;
  }

  .container {
    padding: 0.75rem;
  }

  .controls {
    margin-bottom: 1rem;
  }
}