*, *::before, *::after {
  box-sizing: border-box; margin: 0; padding: 0;
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
  touch-action: none;
}

:root {
  --bg: #0e0c0a;
  --gold: #c8a96e;
  --gold-light: #e2c98a;
  --cream: #f5f0e8;
  --white-key: #f0ebe0;
  --white-key-pressed: #d4c9a8;
  --black-key: #1a1410;
  --black-key-pressed: #3a2e20;
}

html, body {
  height: 100%; width: 100%;
  overflow: hidden;
  background: var(--bg);
  font-family: 'Playfair Display', serif;
  touch-action: none;
  user-select: none;
  -webkit-user-select: none;
}

body { display: flex; flex-direction: column; }

/* ── Header ── */
.header {
  flex-shrink: 0;
  display: flex; align-items: center; justify-content: space-between;
  padding: calc(14px + env(safe-area-inset-top, 0px)) 20px 10px;
  position: relative; z-index: 10;
}
.logo {
  font-size: 22px; font-weight: 700;
  color: var(--gold); letter-spacing: 0.08em; text-transform: uppercase;
}
.logo span { color: var(--cream); font-weight: 400; }

@media (orientation: landscape) {
  .header { padding: calc(5px + env(safe-area-inset-top, 0px)) 20px 4px; }
  .logo { font-size: 15px; }
}

.header-right {
  display: flex; align-items: center; gap: 14px;
}

.volume-control {
  display: flex; align-items: center; gap: 5px;
}
.volume-icon {
  fill: var(--gold); stroke: var(--gold);
  flex-shrink: 0;
}
.volume-slider {
  -webkit-appearance: none; appearance: none;
  width: 72px; height: 2px;
  background: rgba(200,169,110,0.35);
  border-radius: 2px; outline: none; cursor: pointer;
  touch-action: auto;
}
.volume-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 12px; height: 12px; border-radius: 50%;
  background: var(--gold); cursor: pointer;
}
.volume-slider::-moz-range-thumb {
  width: 12px; height: 12px; border-radius: 50%; border: none;
  background: var(--gold); cursor: pointer;
}

.transpose-controls {
  display: flex; align-items: center; gap: 2px;
  font-family: 'Courier Prime', monospace;
  font-size: 11px; color: var(--gold);
}
.transpose-btn {
  background: none; border: none; color: var(--gold);
  font-family: 'Courier Prime', monospace; font-size: 14px;
  cursor: pointer; padding: 2px 5px; line-height: 1;
  touch-action: auto;
}
.transpose-btn:disabled { opacity: 0.2; cursor: default; }
.transpose-value {
  min-width: 2.5ch; text-align: center; letter-spacing: 0.1em;
}

.pr-badge {
  font-family: 'Courier Prime', monospace;
  font-size: 11px; color: var(--gold);
  opacity: 0.4; letter-spacing: 0.1em;
}

/* ── Piano wrapper ── */
.piano-wrapper {
  flex: 1; overflow: hidden;
  display: flex; flex-direction: column;
}

.lid {
  flex-shrink: 0; height: 18px;
  background: linear-gradient(180deg, #0a0806 0%, #2a221a 60%, transparent 100%);
  position: relative; z-index: 5;
}
.lid::after {
  content: ''; position: absolute; bottom: 0; left: 0; right: 0; height: 2px;
  background: linear-gradient(90deg, transparent, var(--gold), transparent);
  opacity: 0.4;
}

.keyboard-scroll {
  flex: 1;
  max-height: 300px;
  overflow-x: auto; overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  scrollbar-width: none;
  background: linear-gradient(180deg, #1a1612 0%, #100e0b 100%);
}
.keyboard-scroll::-webkit-scrollbar { display: none; }

.keyboard {
  position: relative; height: 100%;
  display: inline-flex; padding: 0 12px;
}

.key-white {
  position: relative;
  width: 47px; height: 100%;
  background: linear-gradient(180deg, var(--white-key) 0%, #e8e2d0 60%, #d8d2c0 100%);
  border-left: 1px solid #b0a890;
  border-right: 1px solid #b0a890;
  border-bottom: 4px solid #8a7f68;
  border-radius: 0 0 8px 8px;
  cursor: pointer; flex-shrink: 0;
  box-shadow: inset 0 -4px 8px rgba(0,0,0,0.15), inset 0 1px 0 rgba(255,255,255,0.9);
  transition: background 0.04s, transform 0.04s;
}
.key-white.pressed {
  background: linear-gradient(180deg, var(--white-key-pressed) 0%, #c4ba98 60%, #b4aa88 100%);
  transform: translateY(2px);
}
.key-white .label {
  position: absolute; bottom: 10px; left: 50%; transform: translateX(-50%);
  font-family: 'Courier Prime', monospace; font-size: 9px;
  color: #8a7f68; pointer-events: none;
}

.black-keys-layer {
  position: absolute; top: 0; left: 0;
  height: 62%; pointer-events: none;
}
.key-black {
  position: absolute; width: 31px; height: 100%;
  background: linear-gradient(180deg, #2a2218 0%, var(--black-key) 40%);
  border-radius: 0 0 5px 5px;
  cursor: pointer; pointer-events: all;
  transform: translateX(-50%);
  box-shadow: 0 6px 12px rgba(0,0,0,0.7), inset 0 1px 0 rgba(255,255,255,0.08);
  transition: background 0.04s, transform 0.04s;
  z-index: 2;
}
.key-black.pressed {
  background: linear-gradient(180deg, #3a2e20 0%, var(--black-key-pressed) 40%);
  transform: translateX(-50%) translateY(2px);
}

.rail {
  flex-shrink: 0;
  height: calc(60px + env(safe-area-inset-bottom, 0px));
  background: linear-gradient(180deg, #1a1410, #0a0806);
  display: flex; align-items: center;
  padding: 0 20px env(safe-area-inset-bottom, 0px);
}

@media (orientation: landscape) {
  .rail { height: calc(44px + env(safe-area-inset-bottom, 0px)); }
}

.scroll-slider {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 3px;
  background: rgba(200,169,110,0.2);
  border-radius: 2px; outline: none; cursor: pointer;
  touch-action: auto;
}
.scroll-slider::-webkit-slider-thumb {
  -webkit-appearance: none; appearance: none;
  width: 28px; height: 28px; border-radius: 50%;
  background: var(--gold); cursor: pointer;
  box-shadow: 0 0 8px rgba(200,169,110,0.5);
}
.scroll-slider::-moz-range-thumb {
  width: 28px; height: 28px; border-radius: 50%; border: none;
  background: var(--gold); cursor: pointer;
  box-shadow: 0 0 8px rgba(200,169,110,0.5);
}

/* ── Desktop enhancements ── */
@media (min-width: 900px) {
  .logo { font-size: 30px; }
  .header { padding: 20px 28px 16px; }
}

@media (min-width: 1420px) {
  .rail { display: none; }
}
@media (min-width: 1420px) {
  .keyboard-scroll { display: flex; justify-content: center; }
}
@media (min-width: 1420px) {
  .header {
    padding-left: max(28px, calc((100vw - var(--keyboard-width, 1387px)) / 2));
    padding-right: max(28px, calc((100vw - var(--keyboard-width, 1387px)) / 2));
  }
}
