* { margin: 0; padding: 0; box-sizing: border-box; }
html, body { height: 100%; }

body {
  font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
  background: #0a0a0c;
  color: #e0e0e0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  outline: none;
  background-image:
    radial-gradient(ellipse 700px 500px at 12% 18%, rgba(168, 85, 247, 0.18), transparent),
    radial-gradient(ellipse 600px 600px at 88% 12%, rgba(59, 130, 246, 0.14), transparent),
    radial-gradient(ellipse 500px 400px at 50% 90%, rgba(236, 72, 153, 0.10), transparent);
  background-attachment: fixed;
  overflow: hidden;
}

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.08); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.15); }

header {
  padding: 0.9rem 2rem;
  border-bottom: 1px solid rgba(255,255,255,0.06);
  display: flex;
  justify-content: space-between;
  align-items: center;
  backdrop-filter: blur(20px);
  flex-shrink: 0;
  background: rgba(10,10,12,0.6);
  z-index: 10;
}
.header-logo { height: 28px; }
.header-right { display: flex; gap: 0.5rem; align-items: center; }

/* Multiplayer peers strip lives between the logo and the status pills.
   Scrolls horizontally if the room gets crowded. */
.peers-strip {
  flex: 1 1 auto;
  display: flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0 1rem;
  overflow-x: auto;
  min-width: 0;
  scrollbar-width: none;
}
.peers-strip::-webkit-scrollbar { display: none; }
.peer-pill {
  display: inline-flex;
  align-items: center;
  gap: 0.45rem;
  padding: 0.3rem 0.65rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  font-size: 0.72rem;
  color: #ccc;
  white-space: nowrap;
  flex-shrink: 0;
  transition: background 0.12s, border-color 0.12s;
}
.peer-pill .peer-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--peer-color, #888);
  box-shadow: 0 0 8px var(--peer-color, #888);
  flex-shrink: 0;
}
.peer-pill .peer-name { font-weight: 600; color: #eee; }
.peer-pill .peer-sound {
  color: #888;
  font-size: 0.66rem;
  padding-left: 0.35rem;
  border-left: 1px solid rgba(255,255,255,0.08);
  margin-left: 0.1rem;
}
.peer-pill.self {
  cursor: pointer;
  border-color: var(--peer-color, rgba(168,85,247,0.4));
  background: rgba(255,255,255,0.06);
}
.peer-pill.self:hover { background: rgba(255,255,255,0.1); }
.peer-pill .peer-rename {
  background: transparent;
  border: 1px dashed rgba(255,255,255,0.2);
  border-radius: 4px;
  padding: 0.05rem 0.3rem;
  color: #fff;
  font-family: inherit;
  font-size: 0.72rem;
  font-weight: 600;
  width: 9rem;
  outline: none;
}
.peer-pill .peer-rename:focus { border-color: var(--peer-color, rgba(168,85,247,0.6)); background: rgba(168,85,247,0.08); }

/* Remote peer cursors — fixed-position overlay, never blocks pointer events. */
#cursors-layer {
  position: fixed;
  inset: 0;
  pointer-events: none;
  z-index: 999;
  overflow: hidden;
}
.peer-cursor {
  position: absolute;
  top: 0; left: 0;
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 2px;
  transform: translate(0px, 0px);
  transition: transform 0.07s linear;
  will-change: transform;
}
.peer-cursor svg {
  display: block;
  filter: drop-shadow(0 1px 2px rgba(0,0,0,0.6));
}
.peer-cursor .peer-cursor-name {
  margin-left: 14px;
  background: var(--peer-color, #888);
  color: #fff;
  font-size: 0.62rem;
  font-weight: 600;
  padding: 1px 6px;
  border-radius: 3px;
  white-space: nowrap;
  box-shadow: 0 1px 4px rgba(0,0,0,0.4);
}

.status-pill {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.35rem 0.8rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 999px;
  font-size: 0.75rem;
  color: #aaa;
  font-family: inherit;
  max-width: 240px;
}
.status-pill.clickable { cursor: pointer; transition: all 0.15s; }
.status-pill.clickable:hover { background: rgba(255,255,255,0.07); border-color: rgba(255,255,255,0.15); color: #ddd; }
.status-pill #midi-text, .status-pill #audio-text {
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  max-width: 200px;
}
.status-dot {
  width: 7px; height: 7px; border-radius: 50%;
  background: #555;
  flex-shrink: 0;
  transition: background 0.15s;
}
.status-pill.ok .status-dot { background: #22c55e; box-shadow: 0 0 10px #22c55e; }
.status-pill.warn .status-dot { background: #f5a623; box-shadow: 0 0 8px #f5a623; }

main {
  flex: 1;
  padding: 1.5rem 2rem 0;
  display: flex;
  flex-direction: column;
  gap: 1rem;
  overflow: hidden;
  position: relative;
  min-height: 0;
}

.controls {
  background: rgba(255,255,255,0.025);
  border: 1px solid rgba(255,255,255,0.06);
  border-radius: 14px;
  padding: 0.9rem 1.4rem;
  display: flex;
  align-items: center;
  gap: 1.5rem;
  backdrop-filter: blur(10px);
  flex-wrap: wrap;
  flex-shrink: 0;
}

.control { display: flex; flex-direction: column; gap: 0.35rem; }
.control label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
  font-weight: 500;
}
.control input[type="range"] { width: 130px; accent-color: #a855f7; }
.control-wide { min-width: 280px; flex: 0 1 320px; }
.select {
  height: 34px;
  padding: 0 0.7rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 8px;
  color: #e0e0e0;
  font-family: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all 0.15s;
}
.select:hover { background: rgba(255,255,255,0.07); border-color: rgba(168,85,247,0.4); }
.select:focus { outline: none; border-color: rgba(168,85,247,0.6); }
.select option { background: #161618; color: #e0e0e0; }

.oct-row, .metro-row { display: flex; align-items: center; gap: 0.5rem; }
.metro-bpm {
  width: 60px;
  height: 28px;
  padding: 0 0.4rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 7px;
  color: #e0e0e0;
  font-family: inherit;
  font-size: 0.85rem;
  text-align: center;
}
.metro-bpm:focus { outline: none; border-color: rgba(168,85,247,0.5); }

.toggle-btn {
  height: 28px;
  padding: 0 0.7rem;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 7px;
  color: #ccc;
  font-family: inherit;
  font-size: 0.78rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.12s;
}
.toggle-btn:hover { background: rgba(255,255,255,0.08); }
.toggle-btn.on {
  background: linear-gradient(135deg, rgba(168,85,247,0.3), rgba(59,130,246,0.3));
  border-color: rgba(168,85,247,0.5);
  color: #fff;
}

/* Per-instrument param sliders (Reverb, Cutoff, ADSR, etc.) — appear/disappear
   based on the current instrument's category. .hidden + display:none keeps them
   out of layout. We make synth sliders narrower so they fit in the controls bar. */
.param-controls { display: contents; }
.param-control.hidden { display: none; }
.param-control input[type="range"] { width: 80px; }

.select optgroup { font-style: normal; font-weight: 700; color: #a855f7; background: #161618; }
.select option   { padding-left: 0.6rem; }

.oct-btn {
  width: 28px; height: 28px;
  background: rgba(255,255,255,0.04);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 7px;
  color: #ccc;
  font-weight: 700;
  cursor: pointer;
  transition: all 0.15s;
}
.oct-btn:hover { background: rgba(255,255,255,0.08); }
#oct-label {
  min-width: 24px; text-align: center;
  font-variant-numeric: tabular-nums;
  font-weight: 600;
  color: #fff;
}

/* Trail (Synthesia-style rising notes) */
.trail-wrap {
  flex: 1 1 auto;
  min-height: 100px;
  position: relative;
  overflow: hidden;
  margin: 0 -2rem;
  background:
    radial-gradient(ellipse 80% 60% at 50% 100%, rgba(168, 85, 247, 0.08), transparent 70%),
    linear-gradient(to bottom, #0a0a0c 0%, #060608 100%);
}
.trail-wrap::after {
  content: "";
  position: absolute;
  left: 0; right: 0; bottom: 0;
  height: 30px;
  background: linear-gradient(to top, rgba(0,0,0,0.55), transparent);
  pointer-events: none;
  z-index: 2;
}
#trail {
  position: absolute;
  top: 0; left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

/* Piano */
.piano-wrap {
  display: flex;
  align-items: flex-start;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0;
  flex-shrink: 0;
  margin: 0 -2rem;
  position: relative;
  z-index: 3;
  box-shadow: 0 -4px 20px rgba(0,0,0,0.45);
}

.piano {
  position: relative;
  display: flex;
  height: 200px;
  min-width: 100%;
  user-select: none;
  -webkit-user-select: none;
}

.key {
  position: relative;
  cursor: pointer;
  transition: filter 0.04s, transform 0.04s, background 0.08s;
}

.key.white {
  background: linear-gradient(to bottom, #fafafa 0%, #e8e8e8 60%, #cccccc 100%);
  border-left: 1px solid rgba(0,0,0,0.55);
  border-right: 1px solid rgba(0,0,0,0.55);
  border-top: 1px solid rgba(255,255,255,0.4);
  border-bottom-left-radius: 6px;
  border-bottom-right-radius: 6px;
  flex: 1 1 0;
  min-width: 18px;
  display: flex;
  align-items: flex-end;
  justify-content: center;
  padding-bottom: 0.4rem;
  box-shadow:
    inset 0 -4px 6px rgba(0,0,0,0.15),
    inset 0 1px 0 rgba(255,255,255,0.7);
}
.key.white .label {
  font-size: 0.55rem;
  color: #888;
  font-weight: 500;
  pointer-events: none;
  opacity: 0;
}
.key.white.octave-c .label { color: #a855f7; font-weight: 700; opacity: 1; }

.key.black {
  position: absolute;
  top: 0;
  background: linear-gradient(to bottom, #2a2a30 0%, #0d0d10 60%, #050507 100%);
  border: 1px solid #000;
  border-radius: 0 0 6px 6px;
  height: 62%;
  z-index: 2;
  box-shadow:
    inset 0 -4px 6px rgba(0,0,0,0.7),
    inset 0 1px 0 rgba(255,255,255,0.12),
    0 4px 8px rgba(0,0,0,0.5);
}

.key.white.active {
  background: linear-gradient(to bottom, #ede5fb 0%, #c4b1ee 60%, #9b7ce0 100%);
  transform: translateY(2px);
  box-shadow:
    inset 0 -2px 4px rgba(70,30,150,0.35),
    inset 0 1px 0 rgba(255,255,255,0.7),
    0 0 18px rgba(168,85,247,0.55);
}
.key.black.active {
  background: linear-gradient(to bottom, #b88dff 0%, #6e3fc7 60%, #3b82f6 100%);
  transform: translateY(2px);
  box-shadow:
    inset 0 -2px 4px rgba(0,0,0,0.5),
    inset 0 1px 0 rgba(255,255,255,0.4),
    0 0 22px rgba(139,92,246,0.7);
}

/* Popover for MIDI devices */
.popover {
  position: absolute;
  top: 4.2rem;
  right: 2rem;
  width: 320px;
  background: rgba(20,20,24,0.95);
  border: 1px solid rgba(255,255,255,0.1);
  border-radius: 12px;
  backdrop-filter: blur(20px);
  box-shadow: 0 10px 40px rgba(0,0,0,0.6);
  padding: 0.75rem 0;
  z-index: 100;
  animation: pop-in 0.15s cubic-bezier(0.16, 1, 0.3, 1);
}
.popover.hidden { display: none; }
@keyframes pop-in { from { opacity: 0; transform: translateY(-4px); } to { opacity: 1; transform: translateY(0); } }

.popover-header {
  font-size: 0.7rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: #888;
  padding: 0 1rem 0.5rem;
  font-weight: 600;
}
.popover-footer {
  font-size: 0.65rem;
  color: #666;
  padding: 0.4rem 1rem 0;
  border-top: 1px solid rgba(255,255,255,0.05);
  margin-top: 0.4rem;
  font-style: italic;
}

.midi-list { display: flex; flex-direction: column; }
.midi-item {
  padding: 0.55rem 1rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  cursor: pointer;
  transition: background 0.1s;
}
.midi-item:hover { background: rgba(255,255,255,0.04); }
.midi-item .midi-dot { width: 7px; height: 7px; border-radius: 50%; background: #22c55e; flex-shrink: 0; }
.midi-item input.midi-rename {
  flex: 1;
  background: transparent;
  border: 1px dashed transparent;
  border-radius: 4px;
  padding: 0.2rem 0.4rem;
  color: #fff;
  font-family: inherit;
  font-size: 0.85rem;
}
.midi-item input.midi-rename:hover { border-color: rgba(255,255,255,0.1); }
.midi-item input.midi-rename:focus { outline: none; border-color: rgba(168,85,247,0.5); background: rgba(168,85,247,0.08); }
.midi-list-empty {
  padding: 0.6rem 1rem;
  font-size: 0.8rem;
  color: #777;
  font-style: italic;
}

/* Splash: first-gesture gate. Required because browsers block AudioContext
   until a real user gesture, and keyboard focus is often on the URL bar after
   page load. The splash captures the first key/click for both. */
.splash {
  position: fixed;
  inset: 0;
  z-index: 1000;
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(10,10,12,0.78);
  backdrop-filter: blur(8px);
  cursor: pointer;
  transition: opacity 0.35s ease;
}
.splash.hidden { opacity: 0; pointer-events: none; }
.splash-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 1.1rem;
  padding: 2.2rem 3rem;
  background: rgba(20,20,24,0.7);
  border: 1px solid rgba(255,255,255,0.08);
  border-radius: 16px;
  backdrop-filter: blur(20px);
  text-align: center;
  animation: splash-pop 0.4s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes splash-pop {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}
.splash-logo { height: 36px; }
.splash-text {
  font-size: 0.95rem;
  font-weight: 600;
  color: #e0e0e0;
}
.splash-hint {
  font-size: 0.75rem;
  color: #777;
}

@media (max-width: 720px) {
  main { padding: 1rem 1rem 0; gap: 0.7rem; }
  .controls { padding: 0.6rem 0.8rem; gap: 0.7rem; }
  .key.white { min-width: 28px; }
  .trail-wrap, .piano-wrap { margin: 0 -1rem; }
  .popover { right: 1rem; width: calc(100vw - 2rem); }
}
