/* Starlight Piano Styles (revised) */
:root {
  --bg: #0b0f15;
  --panel: #121823;
  --ink: #e8eefc;
  --muted: #96a1b2;
  --accent: #6fd3ff;
  --danger: #ff5a7a;
  --ok: #7aff9f;
  --shadow: rgba(0,0,0,0.4);
}

* { box-sizing: border-box; }
html, body { 
  height: 100%; 
  margin: 0; 
  background: var(--bg); 
  color: var(--ink); 
  font-family: ui-sans-serif, system-ui, Segoe UI, Roboto, Helvetica, Arial, Apple Color Emoji, Segoe UI Emoji;
  overflow: hidden;
}

.hidden { display: none !important; }

.topbar {
  height: 54px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 12px;
  background: linear-gradient(180deg, rgba(18,24,35,0.9), rgba(18,24,35,0.6));
  box-shadow: 0 2px 8px var(--shadow);
  position: relative;
  z-index: 10;
  backdrop-filter: blur(8px);
  overflow-x: hidden;
}

.brand { font-weight: 700; letter-spacing: .4px; font-size: 14px; }
.controls { display: flex; align-items: center; gap: 6px; flex-wrap: nowrap; }

@media (max-width: 768px) {
  .topbar { overflow-x: auto; -webkit-overflow-scrolling: touch; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,0.2) transparent; }
  .topbar::-webkit-scrollbar { height: 4px; }
  .topbar::-webkit-scrollbar-track { background: transparent; }
  .topbar::-webkit-scrollbar-thumb { background: rgba(255,255,255,0.2); border-radius: 2px; }
  .topbar::-webkit-scrollbar-thumb:hover { background: rgba(255,255,255,0.3); }
  .controls { padding-right: 12px; min-width: max-content; }
  .brand { flex-shrink: 0; margin-right: 12px; }
  .controls .pill { min-width: 44px; min-height: 32px; padding: 6px 10px; }
  .controls input[type="range"] { width: 60px; }
  @media (max-width: 400px) { #metronome-vol, label[for="metronome-vol"] { display: none; } }
}

.controls label { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); margin-right: 4px; font-size: 13px; }
.controls input[type="range"] { vertical-align: middle; width: 80px; }
.pill { border: 1px solid rgba(255,255,255,0.15); background: transparent; color: var(--ink); padding: 8px 12px; border-radius: 16px; cursor: pointer; font-size: 13px; width: 100%; margin-top: 10px; }
.pill:active { transform: translateY(1px); }
.pill:disabled { opacity: 0.5; cursor: not-allowed; }
.pill.danger { border-color: var(--danger); color: var(--danger); }
.inline { display: inline-flex; align-items: center; gap: 4px; }
.divider { width: 1px; height: 26px; background: rgba(255,255,255,0.1); margin: 0 2px; }

main { display: grid; grid-template-rows: 1fr 208px; height: calc(100% - 54px); }
#stage-container { position: relative; overflow: hidden; }
#stage, #post { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#post { pointer-events: none; }
#overlay { position: absolute; inset: 0; pointer-events: none; }

#stage-container::before { content: ""; position: absolute; bottom: 0; left: 0; right: 0; height: 8.33%; background: linear-gradient(90deg, rgba(255, 255, 255, 0.4) 0%, rgba(230, 230, 240, 0.3) 10%, rgba(255, 255, 255, 0.5) 20%, rgba(220, 220, 235, 0.3) 30%, rgba(255, 255, 255, 0.45) 40%, rgba(210, 210, 230, 0.3) 50%, rgba(255, 255, 255, 0.4) 60%, rgba(200, 200, 220, 0.3) 70%, rgba(255, 255, 255, 0.5) 80%, rgba(230, 230, 240, 0.3) 90%, rgba(255, 255, 255, 0.4) 100%); pointer-events: none; z-index: 3; animation: bladeShine 3s linear infinite; filter: brightness(1.3) contrast(1.2); mask-image: linear-gradient(to bottom, black 0%, black 70%, rgba(0,0,0,0.8) 85%, rgba(0,0,0,0.4) 95%, transparent 100%); }
#stage-container::after { content: ""; position: absolute; bottom: 0; left: -100%; right: 100%; height: 8.33%; background: linear-gradient(105deg, transparent 35%, rgba(255, 255, 255, 0.1) 40%, rgba(255, 255, 255, 0.8) 50%, rgba(255, 255, 255, 0.1) 60%, transparent 65%); pointer-events: none; z-index: 4; animation: bladeSweep 4s ease-in-out infinite; mix-blend-mode: overlay; }
.gradient-overlay { position: absolute; bottom: 0; left: 0; right: 0; height: 8.33%; background: linear-gradient(110deg, rgba(138, 43, 226, 0.25) 0%, rgba(72, 61, 139, 0.2) 15%, rgba(30, 144, 255, 0.25) 30%, rgba(64, 224, 208, 0.3) 45%, rgba(0, 206, 209, 0.25) 60%, rgba(123, 104, 238, 0.2) 75%, rgba(147, 112, 219, 0.25) 90%, rgba(138, 43, 226, 0.25) 100%); pointer-events: none; z-index: 5; animation: purpleTurquoiseFlow 5s ease-in-out infinite; mix-blend-mode: overlay; background-size: 200% 100%; }
@keyframes purpleTurquoiseFlow { 0%, 100% { background-position: 0% 50%; opacity: 0.6; } 50% { background-position: 100% 50%; opacity: 0.9; } }
@keyframes bladeShine { 0%, 100% { background-position: 0% 50%; filter: brightness(1.3) contrast(1.2); } 50% { background-position: 100% 50%; filter: brightness(1.5) contrast(1.3); } }
@keyframes bladeSweep { 0%, 100% { transform: translateX(0); opacity: 0; } 50% { transform: translateX(100%) scaleX(1.5); opacity: 1; } }

#keyboard { position: relative; height: 208px; background: #0c111b; border-top: 1px solid rgba(255,255,255,0.08); user-select: none; }
#keyboard .white-keys, #keyboard .black-keys { position: absolute; left: 0; right: 0; height: 100%; display: grid; gap: 0; }
#keyboard .white-keys { grid-template-columns: repeat(52, 1fr); z-index: 1; }
#keyboard .black-keys { z-index: 2; pointer-events: none; }
#keyboard .black-keys .key { pointer-events: auto; }
.key { position: relative; border-left: 1px solid rgba(255,255,255,0.04); border-right: 1px solid rgba(0,0,0,0.4); background: linear-gradient(180deg, #f5f8ff, #d6dceb); box-shadow: inset 0 -3px 0 rgba(0,0,0,0.25); transition: transform 0.02s ease, filter 0.02s ease; height: 100%; }
.key.black { background: linear-gradient(180deg, #171b24, #0e1219); box-shadow: inset 0 -3px 0 rgba(0,0,0,0.6); height: 60%; width: 60%; justify-self: center; border-left: none; border-right: none; border-radius: 0 0 4px 4px; }
.key.pressed { transform: translateY(2px); filter: brightness(0.92); }
.key .label { position: absolute; bottom: 6px; left: 50%; transform: translateX(-50%); font-size: 11px; color: var(--muted); }
.key.black .label { color: #c9d0e2; font-size: 10px; bottom: -16px; }
.key .trail { position: absolute; inset: 0; pointer-events: none; mix-blend-mode: screen; }

.panel { position: fixed; right: 12px; top: 70px; width: 360px; max-height: calc(100% - 90px); background: var(--panel); border: 1px solid rgba(255,255,255,0.08); border-radius: 10px; box-shadow: 0 10px 30px rgba(0,0,0,0.6); padding: 14px; overflow: auto; z-index: 20; }
.panel.hidden { display: none; }
.panel h2 { margin: 0 0 8px; }
.panel section { padding: 14px 0; border-top: 1px solid rgba(255,255,255,0.08); }
.panel section label { display: flex; align-items: center; gap: 6px; margin: 6px 0; }
.panel .close { width: 100%; padding: 10px; background: #1a2231; border: 1px solid rgba(255,255,255,0.12); color: var(--ink); border-radius: 8px; cursor: pointer; }

.subgrid { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#overlay:after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 120px; background: linear-gradient(180deg, rgba(11,15,21,0), rgba(11,15,21,1) 60%); pointer-events: none; }

/* --- Video Jam UI --- */
.arrow-button.fixed { position: fixed; top: 70px; left: 15px; z-index: 1001; transition: transform 0.3s ease-in-out; }
.arrow-button { width: 32px; height: 32px; cursor: pointer; border: 1px solid rgba(255,255,255,0.2); border-radius: 50%; display: flex; align-items: center; justify-content: center; background: rgba(18,24,35,0.5); backdrop-filter: blur(4px); transition: background 0.2s; }
.arrow-button:hover { background: rgba(18,24,35,0.8); }
.arrow-button::after { content: ''; width: 8px; height: 8px; border-top: 2px solid var(--ink); border-right: 2px solid var(--ink); }
.arrow-button.right::after { transform: translateX(-1px) rotate(45deg); }
.arrow-button.left::after { transform: translateX(1px) rotate(-135deg); }

.side-panel.left { position: fixed; top: 54px; left: 0; width: 280px; height: calc(100% - 54px); background-color: rgba(18, 24, 35, 0.9); backdrop-filter: blur(10px); border-right: 1px solid rgba(255, 255, 255, 0.1); padding: 1.2rem; z-index: 1000; transform: translateX(0); transition: transform 0.3s ease-in-out; }
.side-panel.left.hidden { transform: translateX(-100%); }
.side-panel.left.hidden ~ .arrow-button.fixed.left { transform: translateX(0); }
.arrow-button.fixed.left { transform: translateX(280px); }

.side-panel h2 { margin-top: 0; }
.side-panel p { font-size: 14px; color: var(--muted); }
.side-panel input { width: 100%; padding: 10px; margin: 5px 0 12px; background: #0b0f15; border: 1px solid rgba(255,255,255,0.2); color: var(--ink); border-radius: 5px; }
.error-message { color: var(--danger); min-height: 1.2em; font-size: 13px; margin-top: 5px; margin-bottom: 10px; }
#user-list { list-style: none; padding: 0; margin: 10px 0; max-height: 40vh; overflow-y: auto; border: 1px solid rgba(255,255,255,0.1); border-radius: 5px; }
#user-list li { padding: 10px; border-bottom: 1px solid rgba(255,255,255,0.1); display: flex; justify-content: space-between; align-items: center; }
#user-list li:last-child { border-bottom: none; }
#user-list li button { width: auto; margin-top: 0; padding: 4px 10px; }

#video-container { position: absolute; top: 15px; right: 15px; display: flex; gap: 10px; z-index: 50; flex-direction: column; align-items: flex-end; }
.video-wrapper { position: relative; transition: all 0.3s ease; }
.video-wrapper.hidden { display: none; }
.video-wrapper video { width: 240px; height: 180px; border: 2px solid var(--accent); background-color: #000; object-fit: cover; transition: all 0.3s ease; }
.video-wrapper .video-controls { position: absolute; top: 5px; right: 5px; opacity: 0; transition: opacity 0.2s; cursor: pointer; }
.video-wrapper:hover .video-controls { opacity: 1; }
.video-wrapper .minimize-btn { background: rgba(0,0,0,0.5) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' viewBox='0 0 16 16'%3E%3Cpath fill-rule='evenodd' d='M5 8a.5.5 0 0 1 .5-.5h5a.5.5 0 0 1 0 1h-5A.5.5 0 0 1 5 8z'/%3E%3C/svg%3E") center no-repeat; width: 24px; height: 24px; border-radius: 50%; border: none; }
.video-wrapper.minimized { cursor: pointer; }
.video-wrapper.minimized video { width: 160px; height: 30px; object-fit: cover; border-color: var(--muted); }
.video-wrapper.minimized .video-controls .minimize-btn { background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='white' viewBox='0 0 16 16'%3E%3Cpath d='M3.5 3.5a.5.5 0 0 1 .5-.5h8a.5.5 0 0 1 .5.5v8a.5.5 0 0 1-.5.5h-8a.5.5 0 0 1-.5-.5v-8zM4 4v8h8V4H4z'/%3E%3C/svg%3E"); }