:root {
  --bg0: #05080c;
  --bg1: #0a1219;
  --bg2: #0e1a22;
  --ink: #eaf1ef;
  --muted: #8ba39d;
  --faint: #56706a;
  --line: rgba(140, 210, 190, 0.16);
  --line-strong: rgba(140, 210, 190, 0.34);
  --teal: #58e0c0;
  --teal-dim: rgba(88, 224, 192, 0.14);
  --gold: #e8c15a;
  --panel: rgba(9, 15, 20, 0.82);
  --radius: 16px;
  --font-display: "Syne", "Avenir Next", sans-serif;
  --font-body: "Space Grotesk", "Helvetica Neue", sans-serif;
  --font-mono: "JetBrains Mono", ui-monospace, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  color: var(--ink);
  font-family: var(--font-body);
  background: var(--bg0);
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
  background:
    radial-gradient(1100px 640px at 12% -8%, rgba(40, 110, 96, 0.5) 0%, transparent 55%),
    radial-gradient(900px 620px at 96% 4%, rgba(160, 120, 40, 0.28) 0%, transparent 50%),
    radial-gradient(1200px 900px at 50% 120%, rgba(20, 70, 84, 0.5) 0%, transparent 60%),
    linear-gradient(165deg, var(--bg0), var(--bg1) 60%, #07111a);
  overflow-x: hidden;
}

.aurora {
  position: fixed;
  inset: -20%;
  z-index: 0;
  pointer-events: none;
  opacity: 0.5;
  background:
    radial-gradient(420px 320px at 20% 20%, rgba(88, 224, 192, 0.16) 0%, transparent 60%),
    radial-gradient(460px 340px at 78% 30%, rgba(232, 193, 90, 0.12) 0%, transparent 60%),
    radial-gradient(520px 420px at 55% 85%, rgba(40, 150, 170, 0.14) 0%, transparent 60%);
  filter: blur(6px);
  animation: aurora-drift 26s ease-in-out infinite alternate;
}

.noise {
  position: fixed;
  inset: 0;
  z-index: 1;
  pointer-events: none;
  opacity: 0.05;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='120' height='120'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.9' numOctaves='2'/%3E%3C/filter%3E%3Crect width='120' height='120' filter='url(%23n)'/%3E%3C/svg%3E");
}

@keyframes aurora-drift {
  0%   { transform: translate3d(0, 0, 0) rotate(0deg) scale(1); }
  50%  { transform: translate3d(3%, -2%, 0) rotate(2deg) scale(1.06); }
  100% { transform: translate3d(-3%, 3%, 0) rotate(-2deg) scale(1.02); }
}

/* ---------- header ---------- */
.top {
  position: relative;
  z-index: 5;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.8rem 1.4rem;
  border-bottom: 1px solid var(--line);
  background: rgba(5, 8, 12, 0.72);
  backdrop-filter: blur(12px);
}

.brand { display: flex; flex-direction: column; gap: 0.1rem; text-decoration: none; }
.brand-mark {
  font-family: var(--font-display);
  font-weight: 800;
  font-size: 1.12rem;
  letter-spacing: 0.16em;
  color: var(--ink);
  background: linear-gradient(90deg, var(--teal), var(--gold));
  -webkit-background-clip: text;
  background-clip: text;
  -webkit-text-fill-color: transparent;
}
.brand-sub {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  letter-spacing: 0.34em;
  color: var(--muted);
}

.top-nav a {
  font-size: 0.78rem;
  color: var(--muted);
  text-decoration: none;
  letter-spacing: 0.08em;
  transition: color 0.2s;
}
.top-nav a:hover { color: var(--teal); }

/* ---------- stage ---------- */
.stage {
  position: relative;
  z-index: 2;
  display: grid;
  grid-template-columns: 1fr 320px;
  gap: 1rem;
  padding: 1rem 1.4rem 0.6rem;
  flex: 1;
  min-height: 0;
}

.graph-col {
  display: flex;
  flex-direction: column;
  min-height: 0;
}

.graph-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 0.8rem 1rem;
  margin-bottom: 0.7rem;
}

.eyebrow {
  margin: 0 0 0.15rem;
  font-family: var(--font-mono);
  font-size: 0.62rem;
  letter-spacing: 0.22em;
  color: var(--faint);
  text-transform: uppercase;
}

.graph-title h1 {
  margin: 0;
  font-family: var(--font-display);
  font-size: clamp(1.5rem, 3.4vw, 2.2rem);
  font-weight: 700;
  line-height: 1;
}

.transport {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 0.45rem;
}

.btn {
  border: 1px solid var(--line-strong);
  background: rgba(20, 40, 40, 0.4);
  color: var(--ink);
  font: 600 0.85rem var(--font-body);
  padding: 0.5rem 0.85rem;
  border-radius: 12px;
  cursor: pointer;
  transition: border-color 0.2s, background 0.2s, transform 0.12s, box-shadow 0.2s;
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
}
.btn:hover { border-color: var(--teal); background: var(--teal-dim); }
.btn:active { transform: scale(0.96); }
.btn.icon { padding: 0.5rem 0.7rem; }
.btn.playing { border-color: var(--teal); box-shadow: 0 0 18px rgba(88, 224, 192, 0.35); }

.piece-select {
  border: 1px solid var(--line-strong);
  background: rgba(10, 18, 24, 0.9);
  color: var(--ink);
  font: 600 0.82rem var(--font-body);
  padding: 0.5rem 0.7rem;
  border-radius: 12px;
  cursor: pointer;
  max-width: 260px;
}
.piece-select:focus-visible { outline: 1px solid var(--teal); }

.speed {
  display: flex;
  align-items: center;
  gap: 0.4rem;
  font-family: var(--font-mono);
  font-size: 0.72rem;
  color: var(--muted);
}
.speed input[type="range"], .progress input[type="range"] {
  accent-color: var(--teal);
}
.speed output {
  min-width: 2.6rem;
  font-family: var(--font-mono);
  color: var(--teal);
}

.progress {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  flex: 1;
  min-width: 220px;
}
.progress input[type="range"] { flex: 1; }
#progress-label {
  font-family: var(--font-mono);
  font-size: 0.7rem;
  color: var(--muted);
  white-space: nowrap;
}

/* ---------- graph ---------- */
.graph-shell {
  position: relative;
  flex: 1;
  min-height: 380px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background:
    radial-gradient(760px 520px at 50% 42%, rgba(20, 52, 58, 0.55) 0%, transparent 62%),
    linear-gradient(180deg, rgba(9, 17, 22, 0.9), rgba(6, 11, 15, 0.95));
  box-shadow: inset 0 0 60px rgba(0, 0, 0, 0.5), 0 18px 50px rgba(0, 0, 0, 0.4);
}

#graph { position: absolute; inset: 0; }

.legend {
  position: absolute;
  left: 12px;
  top: 12px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 0.6rem;
  padding: 0.7rem 0.85rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(8, 14, 18, 0.78);
  backdrop-filter: blur(8px);
  max-width: 240px;
}

.legend-title {
  font-family: var(--font-mono);
  font-size: 0.58rem;
  letter-spacing: 0.2em;
  color: var(--faint);
  text-transform: uppercase;
}

.pc-legend {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 0.28rem 0.5rem;
}
.pc-legend span {
  display: flex;
  align-items: center;
  gap: 0.3rem;
  font-size: 0.66rem;
  font-family: var(--font-mono);
  color: var(--muted);
}
.pc-legend i {
  width: 9px;
  height: 9px;
  border-radius: 3px;
  flex: none;
  box-shadow: 0 0 8px currentColor;
}

.edge-legend { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.2rem; }
.edge-legend li {
  display: flex;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.68rem;
  font-family: var(--font-mono);
  color: var(--muted);
}
.edge-legend li input { accent-color: var(--teal); }

.legend-heat {
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 3;
  display: flex;
  flex-direction: column;
  gap: 0.35rem;
  padding: 0.6rem 0.8rem;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(8, 14, 18, 0.72);
  backdrop-filter: blur(8px);
}
.heat-scale { display: flex; gap: 3px; align-items: flex-end; height: 22px; }
.heat-scale i { width: 12px; border-radius: 3px 3px 1px 1px; }
.heat-scale i:nth-child(1){ height: 4px; background: #274b4d; }
.heat-scale i:nth-child(2){ height: 8px; background: #2e7d6f; }
.heat-scale i:nth-child(3){ height: 12px; background: #46b98f; }
.heat-scale i:nth-child(4){ height: 16px; background: #8fdc7f; }
.heat-scale i:nth-child(5){ height: 21px; background: #f4d060; }

/* ---------- side panel ---------- */
.panel {
  display: flex;
  flex-direction: column;
  gap: 0.85rem;
  min-width: 0;
  overflow-y: auto;
}

.panel-block {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--panel);
  backdrop-filter: blur(10px);
  padding: 1rem 1.05rem;
}
.panel-block h2 {
  margin: 0 0 0.7rem;
  font-family: var(--font-display);
  font-size: 0.78rem;
  letter-spacing: 0.18em;
  text-transform: uppercase;
  color: var(--teal);
}
#piece-composer {
  margin: 0;
  font-family: var(--font-display);
  font-size: 1.3rem;
  line-height: 1.1;
}
.work { margin: 0.2rem 0 0.5rem; color: var(--muted); font-size: 0.82rem; }
.meta { font-family: var(--font-mono); font-size: 0.68rem; color: var(--faint); margin: 0 0 0.6rem; }
.desc { font-size: 0.82rem; line-height: 1.55; color: var(--muted); margin: 0; }

.toggles { display: grid; gap: 0.4rem; margin-bottom: 0.7rem; }

.toggle {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  font-size: 0.8rem;
  color: var(--ink);
  cursor: pointer;
  user-select: none;
}
.toggle input { display: none; }
.toggle .knob {
  width: 34px;
  height: 18px;
  border-radius: 20px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid var(--line);
  position: relative;
  transition: background 0.2s, border-color 0.2s;
  flex: none;
}
.toggle .knob::after {
  content: "";
  position: absolute;
  top: 2px; left: 2px;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--muted);
  transition: transform 0.2s, background 0.2s;
}
.toggle input:checked + .knob { background: var(--teal-dim); border-color: var(--teal); }
.toggle input:checked + .knob::after { transform: translateX(16px); background: var(--teal); box-shadow: 0 0 10px var(--teal); }

.note-empty { color: var(--faint); font-size: 0.8rem; font-style: italic; }
.note-info .note-top { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.6rem; }
.note-big {
  font-family: var(--font-display);
  font-size: 2rem;
  font-weight: 800;
  line-height: 1;
}
.note-chip {
  font-family: var(--font-mono);
  font-size: 0.66rem;
  padding: 0.25rem 0.5rem;
  border-radius: 8px;
  border: 1px solid var(--line-strong);
}

.note-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem 0.9rem;
  margin: 0 0 0.7rem;
}
.note-grid div { display: flex; justify-content: space-between; gap: 0.5rem; border-bottom: 1px dashed var(--line); padding-bottom: 0.25rem; }
.note-grid dt { font-family: var(--font-mono); font-size: 0.64rem; color: var(--faint); text-transform: uppercase; letter-spacing: 0.1em; }
.note-grid dd { margin: 0; font-family: var(--font-mono); font-size: 0.74rem; }

.note-neighbors h3 {
  margin: 0 0 0.4rem;
  font-size: 0.68rem;
  letter-spacing: 0.16em;
  text-transform: uppercase;
  color: var(--faint);
  font-family: var(--font-mono);
}
.note-neighbors ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.22rem; }
.note-neighbors li {
  font-size: 0.72rem;
  font-family: var(--font-mono);
  color: var(--muted);
  display: flex;
  gap: 0.5rem;
  justify-content: space-between;
}
.note-neighbors li b { color: var(--ink); font-weight: 600; }
.note-neighbors li .iv { color: var(--teal); font-size: 0.62rem; }

/* ---------- keyboard ---------- */
.keyboard-zone {
  position: relative;
  z-index: 2;
  margin: 0 1.4rem 1.2rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: rgba(8, 14, 18, 0.8);
  backdrop-filter: blur(10px);
  overflow: hidden;
}
.kbd-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0.5rem 0.9rem;
  font-family: var(--font-mono);
  font-size: 0.68rem;
  letter-spacing: 0.14em;
  color: var(--faint);
  border-bottom: 1px solid var(--line);
  text-transform: uppercase;
}
.kbd-head b { color: var(--muted); font-weight: 600; }
.play-state { color: var(--faint); transition: color 0.3s; }
.play-state.live { color: var(--teal); }

.piano {
  display: flex;
  padding: 0.9rem 0.9rem 1.1rem;
  overflow-x: auto;
  min-height: 132px;
}
.piano .key {
  position: relative;
  flex: 1 1 0;
  min-width: 0;
  height: 96px;
  border-radius: 4px 4px 8px 8px;
  border: 1px solid rgba(0, 0, 0, 0.55);
  background: linear-gradient(180deg, #f4f7f5, #c9d2cd);
  cursor: pointer;
  transition: box-shadow 0.15s, background 0.15s, transform 0.06s;
}
.piano .key.black {
  flex: none;
  width: 11px;
  height: 58px;
  margin-left: -5px;
  margin-right: -5px;
  z-index: 2;
  background: linear-gradient(180deg, #1b2327, #0a0f12);
  border-radius: 0 0 5px 5px;
}
.piano .key:hover { box-shadow: 0 0 10px rgba(88, 224, 192, 0.5); }
.piano .key.playing-white { background: linear-gradient(180deg, #ffffff, #b8e8d8); }
.piano .key.playing-black { background: linear-gradient(180deg, #2f423c, #10221c); box-shadow: 0 0 14px var(--glow, rgba(88,224,192,0.8)); }
.piano .key.playing-white { box-shadow: 0 0 14px var(--glow, rgba(88,224,192,0.8)); }
.piano .key .klabel {
  position: absolute;
  bottom: 4px;
  left: 50%;
  transform: translateX(-50%);
  font-family: var(--font-mono);
  font-size: 0.52rem;
  color: rgba(40, 55, 55, 0.5);
}

/* ---------- responsive ---------- */
@media (max-width: 980px) {
  .stage { grid-template-columns: 1fr; }
  .graph-shell { min-height: 420px; }
  .panel { display: grid; grid-template-columns: 1fr 1fr; }
  .legend { display: none; }
}

@media (max-width: 640px) {
  .top { padding: 0.7rem 0.9rem; }
  .stage { padding: 0.8rem 0.9rem 0.4rem; }
  .graph-shell { min-height: 340px; }
  .panel { grid-template-columns: 1fr; }
  .keyboard-zone { margin: 0 0.9rem 1rem; }
  .graph-head { flex-direction: column; align-items: stretch; }
  .transport { justify-content: space-between; }
}
