*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  background: #080B14;
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  font-family: "Press Start 2P", monospace;
  color: #fff;
  overflow-x: hidden;
  padding: 24px 16px;
}
body::before {
  content: "";
  position: fixed;
  inset: 0;
  background:
    radial-gradient(ellipse at 15% 25%, rgba(255,45,120,0.18) 0%, transparent 50%),
    radial-gradient(ellipse at 85% 75%, rgba(120,50,255,0.15) 0%, transparent 50%);
  pointer-events: none;
}
.app { position: relative; z-index: 1; display: flex; flex-direction: column; align-items: center; gap: 20px; width: 100%; }
.title { margin: 0; font-weight: inherit; font-size: clamp(16px, 3vw, 26px); color: #FF2D78; text-shadow: 0 0 18px rgba(255,45,120,0.9); letter-spacing: 4px; text-align: center; }
.subtitle { font-size: 8px; color: #8373A4; margin-top: 8px; letter-spacing: 2px; text-align: center; }
.active-notes { display: flex; gap: 6px; height: 26px; align-items: center; justify-content: center; flex-wrap: wrap; }
.note-pill { font-size: 7px; background: rgba(255,45,120,0.2); border: 1px solid rgba(255,45,120,0.6); border-radius: 4px; padding: 4px 8px; color: #FF7BAC; }
.piano-wrap { background: linear-gradient(180deg, #1E1438 0%, #160F2A 100%); border: 2px solid rgba(255,45,120,0.35); border-radius: 18px; padding: 18px 22px 26px; box-shadow: 0 0 50px rgba(255,45,120,0.18); overflow-x: auto; max-width: 100vw; }
.piano-and-wheel { display: flex; align-items: flex-start; gap: 14px; }
.pitch-wheel-wrap {
  display: flex; flex-direction: column; align-items: center; gap: 6px;
  padding-top: 24px; /* align with top of keys */
}
.pitch-wheel-label { font-size: 6px; color: #8173AB; letter-spacing: 1px; }
.pitch-wheel-track {
  position: relative; width: 28px; height: 164px;
  background: #1A1030; border: 1px solid #4A3888;
  border-radius: 14px; cursor: ns-resize;
  box-shadow: inset 0 2px 8px rgba(0,0,0,0.5);
}
.pitch-wheel-notch {
  position: absolute; left: 4px; right: 4px; height: 2px;
  background: rgba(255,45,120,0.25); top: 50%; transform: translateY(-50%);
  border-radius: 1px;
}
.pitch-wheel-thumb {
  position: absolute; left: 3px; right: 3px; height: 32px;
  background: linear-gradient(180deg, #7060C0, #4A3888);
  border-radius: 8px; top: calc(50% - 16px);
  box-shadow: 0 0 8px rgba(170,136,255,0.6);
  cursor: ns-resize; transition: background 0.1s;
  border: 1px solid #AA88FF;
}
.pitch-wheel-thumb.active { background: linear-gradient(180deg, #FF2D78, #AA2060); box-shadow: 0 0 12px rgba(255,45,120,0.8); border-color: #FF2D78; }
.pitch-wheel-val { font-size: 6px; color: #8173AB; min-width: 28px; text-align: center; }
.octave-row { display: flex; align-items: center; justify-content: center; gap: 14px; margin-bottom: 10px; }
.octave-bar { font-size: 6px; color: #8173AB; text-align: center; letter-spacing: 3px; }
/* notes sounding below / above the keys in view: change octave to see them */
.more { font-size: 9px; color: #44FF88; min-width: 4em; text-shadow: 0 0 6px rgba(68,255,136,0.8); }
#lowMore { text-align: right; }
.keyboard { position: relative; height: 164px; touch-action: none; }
.key { position: absolute; cursor: pointer; user-select: none; display: flex; flex-direction: column; justify-content: flex-end; align-items: center; padding-bottom: 7px; }
.key-note { font-size: 5px; opacity: 0.4; margin-bottom: 3px; }
.key-label { font-size: 7px; opacity: 0.55; }
.key.white { width: 44px; height: 164px; background: linear-gradient(180deg, #EDE6F8 0%, #D8CEEE 100%); border: 1px solid #9580C0; border-top: none; border-radius: 0 0 8px 8px; top: 0; z-index: 1; box-shadow: inset 0 -4px 8px rgba(0,0,0,0.08), 0 4px 6px rgba(0,0,0,0.4); }
.key.white .key-note { color: #6A50A0; }
.key.white .key-label { color: #4A387A; }
.key.white.pressed { background: linear-gradient(180deg, #FF8AAF 0%, #FF5585 100%); box-shadow: 0 0 16px rgba(255,85,133,0.9); transform: translateY(2px); }
.key.white.pressed .key-label, .key.white.pressed .key-note { color: #fff; opacity: 0.9; }
.key.black { width: 28px; height: 100px; background: linear-gradient(180deg, #241650 0%, #160C38 60%, #100828 100%); border: 1px solid #4A3888; border-radius: 0 0 6px 6px; top: 0; z-index: 2; padding-bottom: 6px; box-shadow: 0 5px 10px rgba(0,0,0,0.6); }
.key.black .key-note { color: #7060B0; font-size: 4px; }
.key.black .key-label { color: #8070C0; font-size: 6px; }
.key.black.pressed { background: linear-gradient(180deg, #FF2D78 0%, #C40055 100%); box-shadow: 0 0 14px rgba(255,45,120,1); transform: translateY(1px); }
.key.black.pressed .key-label, .key.black.pressed .key-note { color: #fff; opacity: 0.9; }
.controls { display: flex; flex-direction: column; gap: 10px; align-items: center; }
.ctl-group { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: center; }
.btn { font-family: "Press Start 2P", monospace; font-size: 8px; padding: 10px 14px; border: 2px solid; border-radius: 8px; cursor: pointer; background: transparent; }
.btn:active { transform: scale(0.96); }
.btn-record { color: #FF5555; border-color: #FF5555; }
.btn-record.active { background: #FF5555; color: #fff; animation: recPulse 0.9s ease-in-out infinite; }
@keyframes recPulse { 0%,100% { box-shadow: 0 0 6px rgba(255,85,85,0.7); } 50% { box-shadow: 0 0 22px rgba(255,85,85,1); } }
.btn-play { color: #44FF88; border-color: #44FF88; }
.btn-play.active { background: #44FF88; color: #080B14; }
.btn-play:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-loop { color: #88AAFF; border-color: #88AAFF; font-size: 7px; }
.btn-loop:disabled { opacity: 0.3; cursor: not-allowed; }
.btn-loop.active { background: #88AAFF; color: #080B14; }
.btn-stop { color: #FFAA44; border-color: #FFAA44; }
.btn-clear { color: #8173AB; border-color: #8173AB; font-size: 7px; }
.btn-share { color: #FFE066; border-color: #FFE066; font-size: 7px; }
.btn-share:disabled { opacity: 0.3; cursor: not-allowed; }
.pop-wrap { position: relative; display: inline-flex; }
.toast { position: absolute; bottom: calc(100% + 12px); left: 50%; transform: translate(-50%, 6px) scale(0.85);
  white-space: nowrap; font-family: "Press Start 2P", monospace; font-size: 9px; color: #080B14; background: #FFE066;
  padding: 9px 12px; border-radius: 8px; box-shadow: 0 0 18px rgba(255,224,102,0.75); pointer-events: none;
  opacity: 0; transition: opacity .2s, transform .2s cubic-bezier(.3,1.6,.5,1); z-index: 5; }
.toast::after { content: ""; position: absolute; top: 100%; left: 50%; margin-left: -6px; border: 6px solid transparent; border-top-color: #FFE066; }
.toast.show { opacity: 1; transform: translate(-50%, 0) scale(1); }
/* the last button: open leftward so it stays on screen */
.toast-end { left: auto; right: 0; transform: translateY(6px) scale(0.85); transform-origin: bottom right; }
.toast-end.show { transform: none; }
.toast-end::after { left: auto; right: 22px; margin-left: 0; }
.toast-play { background: #44FF88; box-shadow: 0 0 18px rgba(68,255,136,0.75); }
.toast-play::after { border-top-color: #44FF88; }
.btn-play.ready { animation: playReady 1.1s ease-in-out infinite; }
@keyframes playReady { 0%,100% { box-shadow: 0 0 4px rgba(68,255,136,0.5); } 50% { box-shadow: 0 0 22px rgba(68,255,136,1); background: rgba(68,255,136,0.15); } }
@media (prefers-reduced-motion: reduce) { .btn-play.ready { animation: none; box-shadow: 0 0 14px rgba(68,255,136,0.9); } }
@media (prefers-reduced-motion: reduce) { .toast { transition: opacity .2s; transform: translate(-50%, 0); } }
@media (prefers-reduced-motion: reduce) { .toast-end { transform: none; } }
.status { font-size: 8px; color: #8373A4; min-height: 16px; text-align: center; }
.status.recording { color: #FF5555; animation: blink 0.9s step-end infinite; }
.status.playing { color: #44FF88; }
/* the seek bar: shows whenever there's a song; drag or click to move, arrow keys when focused */
.seek { -webkit-appearance: none; appearance: none; width: min(420px, 86vw); height: 18px; margin: -8px 0 0; background: transparent; cursor: pointer; --fill: 0%; }
.seek::-webkit-slider-runnable-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, #44FF88 var(--fill), rgba(68,255,136,0.15) var(--fill)); }
.seek::-moz-range-track { height: 4px; border-radius: 2px; background: linear-gradient(90deg, #44FF88 var(--fill), rgba(68,255,136,0.15) var(--fill)); }
.seek::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4px; border-radius: 50%; background: #44FF88; box-shadow: 0 0 8px rgba(68,255,136,0.9); }
.seek::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: #44FF88; box-shadow: 0 0 8px rgba(68,255,136,0.9); }
.seek:focus-visible { outline: 2px solid #44FF88; outline-offset: 4px; border-radius: 4px; }
.key.white.played { background: linear-gradient(180deg, #9CFFC0 0%, #44E080 100%); box-shadow: 0 0 16px rgba(68,255,136,0.9); transform: translateY(2px); }
.key.black.played { background: linear-gradient(180deg, #44FF88 0%, #10A050 100%); box-shadow: 0 0 14px rgba(68,255,136,1); transform: translateY(1px); }
.key.played .key-label, .key.played .key-note { color: #080B14; opacity: 0.8; }
.pitch-wheel-thumb.playback { background: linear-gradient(180deg, #44FF88, #10A050); box-shadow: 0 0 12px rgba(68,255,136,0.8); border-color: #44FF88; }
@keyframes blink { 0%,100%{opacity:1} 50%{opacity:0} }
.key-guide { font-size: 7px; color: #8173AB; text-align: center; line-height: 2; letter-spacing: 1px; }
.key-guide span { color: #A99AD0; }
#waveCanvas { border: 1px solid rgba(255,45,120,0.2); border-radius: 8px; background: rgba(255,45,120,0.04); }
#loopCanvas { width: 100%; border: 1px solid rgba(170,136,255,0.2); border-radius: 6px; background: rgba(30,20,56,0.8); display: block; }
.cat-float { position: fixed; pointer-events: none; z-index: 0; animation: floatUp linear infinite; opacity: 0; }
@keyframes floatUp { 0% { transform: translateY(110vh); opacity: 0; } 8% { opacity: 0.07; } 92% { opacity: 0.07; } 100% { transform: translateY(-120px); opacity: 0; } }

/* ── Version badge ───────────────────────────────────────────────── */
.version-label {
  position: fixed;
  bottom: 10px;
  right: 14px;
  font-size: 6px;
  color: #8173AB;
  letter-spacing: 1px;
  pointer-events: none;
  z-index: 1;
}

/* ── Piano + settings side-by-side layout ─────────────────────────── */
.piano-settings-row {
  display: flex;
  align-items: center;   /* vertically center all children at keyboard level */
  gap: 0;
  justify-content: center;
  flex-wrap: wrap;
  width: 100%;
}
.piano-wrap {
  flex-shrink: 0;
}
/* Tab button that sits flush against the right edge of the piano box */
.settings-tab {
  font-family: "Press Start 2P", monospace;
  font-size: 9px;
  padding: 14px 8px;
  background: rgba(170,136,255,0.06);
  border: 2px solid rgba(170,136,255,0.35);
  border-left: none;
  border-radius: 0 10px 10px 0;
  color: #AA88FF;
  cursor: pointer;
  flex-shrink: 0;
  align-self: center;
}
.settings-tab:active { opacity: 0.7; }
.settings-panel {
  display: flex;
  flex-direction: column;
  gap: 10px;
  background: linear-gradient(180deg, #1E1438 0%, #160F2A 100%);
  border: 2px solid rgba(170,136,255,0.35);
  border-radius: 0 14px 14px 14px;
  padding: 14px 16px 18px;
  box-shadow: 0 0 30px rgba(170,136,255,0.08);
  min-width: 220px;
  max-width: 300px;
  overflow: visible;
  margin-left: 2px;
}

/* ── Mobile / small-screen overrides ─────────────────────────────── */
@media (max-width: 600px) {
  /* Smaller keys so the keyboard fits without horizontal scroll */
  .key.white {
    width: 32px;
    height: 120px;
  }
  .key.black {
    width: 20px;
    height: 74px;
  }
  .keyboard {
    height: 120px;
  }
  .key-note  { font-size: 4px; }
  .key-label { font-size: 5px; }
  .key.black .key-note  { font-size: 3px; }
  .key.black .key-label { font-size: 4px; }

  /* Settings panel drops below the keyboard instead of opening to the right */
  .piano-settings-row {
    flex-direction: column;
    align-items: center;
  }
  .settings-tab {
    border-left: 2px solid rgba(170,136,255,0.35);
    border-top: none;
    border-radius: 0 0 10px 10px;
    padding: 8px 20px;
    align-self: flex-end;
    margin-right: 0;
  }
  .settings-panel {
    border-radius: 14px 14px 14px 14px;
    margin-left: 0;
    margin-top: 2px;
    width: 100%;
    max-width: 480px;
  }
}

.credit { font-size: 8px; line-height: 1.8; color: #8373A4; margin-top: 16px; text-align: center; letter-spacing: 1px; }
.credit a { color: #8A7AAA; }

/* opening and saving MIDI files */
.btn-open { color: #44DDFF; border-color: #44DDFF; font-size: 7px; }
.parts { border: 2px solid #2A1F44; border-radius: 8px; padding: 6px 12px 8px; margin: 0; max-width: min(640px, 92vw); }
.parts legend { font-family: "Press Start 2P", monospace; font-size: 6px; color: #8173AB; letter-spacing: 1px; padding: 0 6px; }
#partList { display: flex; flex-wrap: wrap; gap: 6px 14px; justify-content: center; }
#partList label { font-family: "Press Start 2P", monospace; font-size: 7px; color: #BB99FF; display: inline-flex; align-items: center; gap: 6px; cursor: pointer; }
#partList input { accent-color: #44FF88; margin: 0; }
#partList .count { color: #8373A4; }
.btn-midiin { color: #44DDFF; border-color: #44DDFF; font-size: 7px; }
.btn-midiin[aria-pressed="true"] { background: #44DDFF; color: #080B14; box-shadow: 0 0 12px rgba(68,221,255,0.7); }
.btn-skip { color: #44FF88; border-color: #44FF88; font-size: 7px; }
.btn-skip:disabled, .btn-open:disabled { opacity: 0.3; cursor: not-allowed; }
.toast.toast-save { background: #44DDFF; box-shadow: 0 0 18px rgba(68,221,255,0.75); }
.toast.toast-save::after { border-top-color: #44DDFF; }
/* the song's name: shown with a song, click to type one */
.song-name { font-family: "Press Start 2P", monospace; font-size: 8px; color: #BB99FF; background: transparent; border: 0;
  border-bottom: 1px dashed transparent; text-align: center; width: min(420px, 86vw); padding: 4px 0; margin: -6px 0 -4px; }
.song-name::placeholder { color: #5A4C80; }
.song-name:hover { border-bottom-color: #5A4C80; }
.song-name:focus { outline: none; border-bottom-color: #BB99FF; color: #fff; }
/* help: always in the top corner */
.btn-help { position: absolute; z-index: 2; top: calc(14px + env(safe-area-inset-top, 0px)); right: max(14px, env(safe-area-inset-right, 0px));
  color: #FFE066; border-color: #FFE066; text-decoration: none; font-size: 9px; padding: 10px 12px; box-shadow: 0 0 10px rgba(255,224,102,0.35); }
.btn-help:hover, .btn-help:focus-visible { background: #FFE066; color: #080B14; outline: none; }
@media (max-width: 600px) { .btn-help { font-size: 7px; padding: 8px 9px; top: calc(8px + env(safe-area-inset-top, 0px)); right: max(8px, env(safe-area-inset-right, 0px)); } }

/* Touchscreens: until the keys are playable, a button over them turns the sound on (js/sound-button.js) */
.sound-host { position: relative; max-width: 100vw; }
.sound-on { position: absolute; inset: 0; z-index: 5; margin: 0; border: 2px solid rgba(255,45,120,0.6); border-radius: 18px;
  background: rgba(22, 15, 42, 0.86); color: #FFE066; font: 12px/1.4 'Press Start 2P', monospace; cursor: pointer;
  touch-action: manipulation; }
.sound-on[hidden] { display: none; }
