:root {
  color-scheme: dark;
  font-family: "SF Pro Display", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --stage-bg: #060318;
  --keyboard-height: clamp(218px, 31vh, 340px);
  --cyan: #75f8ff;
  --violet: #b68cff;
  --pink: #ff6bd6;
  --gold: #ffd778;
}

* {
  box-sizing: border-box;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #03020c;
}

body {
  -webkit-tap-highlight-color: transparent;
  user-select: none;
}

button,
a {
  -webkit-tap-highlight-color: transparent;
}

button:focus-visible,
a:focus-visible,
.piano-key:focus-visible {
  outline: 2px solid rgba(117, 248, 255, 0.9);
  outline-offset: 3px;
}

.experience {
  position: fixed;
  inset: 0;
  display: grid;
  grid-template-rows: minmax(0, 1fr) var(--keyboard-height);
  isolation: isolate;
  background: #050316;
}

.light-stage {
  position: relative;
  min-height: 0;
  overflow: hidden;
  background:
    radial-gradient(circle at 72% 30%, rgba(94, 45, 164, 0.19), transparent 31%),
    radial-gradient(circle at 20% 62%, rgba(12, 92, 138, 0.16), transparent 37%),
    linear-gradient(180deg, #08051d 0%, #050318 62%, #08041d 100%);
}

#particle-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.stage-vignette {
  position: absolute;
  inset: 0;
  pointer-events: none;
  background:
    linear-gradient(180deg, rgba(2, 1, 8, 0.45), transparent 20%, transparent 72%, rgba(7, 2, 24, 0.5)),
    radial-gradient(ellipse at center, transparent 36%, rgba(1, 0, 8, 0.42) 100%);
  z-index: 2;
}

.stage-header {
  position: absolute;
  z-index: 5;
  top: max(24px, env(safe-area-inset-top));
  left: clamp(22px, 4vw, 72px);
  right: clamp(22px, 4vw, 72px);
  display: flex;
  align-items: center;
  justify-content: space-between;
  pointer-events: none;
}

.brand,
.stage-actions {
  pointer-events: auto;
}

.brand {
  display: inline-flex;
  align-items: center;
  gap: 12px;
  color: #fff;
  text-decoration: none;
}

.brand__mark {
  position: relative;
  display: grid;
  place-items: center;
  width: 39px;
  height: 39px;
  border: 1px solid rgba(255, 255, 255, 0.15);
  border-radius: 13px;
  overflow: hidden;
  font-family: Georgia, serif;
  font-size: 25px;
  font-weight: 600;
  text-shadow: 0 0 16px var(--cyan);
  background:
    linear-gradient(135deg, rgba(117, 248, 255, 0.18), rgba(182, 140, 255, 0.1)),
    rgba(255, 255, 255, 0.03);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.13), 0 10px 40px rgba(47, 12, 104, 0.28);
}

.brand__mark::after {
  content: "";
  position: absolute;
  width: 30px;
  height: 10px;
  left: -9px;
  top: 4px;
  background: rgba(117, 248, 255, 0.56);
  filter: blur(9px);
  transform: rotate(-35deg);
}

.brand__copy {
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.brand__copy strong {
  font-size: 18px;
  line-height: 1;
  letter-spacing: 0.12em;
  font-weight: 650;
}

.brand__copy small {
  color: rgba(224, 220, 255, 0.48);
  font-size: 8px;
  font-weight: 650;
  letter-spacing: 0.23em;
}

.stage-actions {
  display: flex;
  align-items: center;
  gap: 10px;
}

.icon-button,
.connect-button {
  position: relative;
  border: 1px solid rgba(255, 255, 255, 0.13);
  color: rgba(255, 255, 255, 0.86);
  background: rgba(14, 10, 35, 0.46);
  box-shadow: inset 0 1px rgba(255, 255, 255, 0.08), 0 12px 30px rgba(0, 0, 0, 0.18);
  backdrop-filter: blur(18px) saturate(125%);
  cursor: pointer;
  transition: border-color 180ms ease, background 180ms ease, transform 180ms ease;
}

.icon-button:hover,
.connect-button:hover {
  border-color: rgba(117, 248, 255, 0.36);
  background: rgba(25, 18, 55, 0.62);
  transform: translateY(-1px);
}

.icon-button:active,
.connect-button:active {
  transform: translateY(1px) scale(0.98);
}

.icon-button {
  display: grid;
  place-items: center;
  width: 40px;
  height: 40px;
  padding: 10px;
  border-radius: 14px;
}

.icon-button svg {
  width: 100%;
  height: 100%;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.65;
}

#sound-toggle svg path:first-child {
  fill: currentColor;
  stroke: none;
}

#sound-toggle[aria-pressed="false"] .sound-wave {
  opacity: 0;
}

.connect-button {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 152px;
  height: 40px;
  padding: 0 17px;
  border-radius: 14px;
  justify-content: center;
  font: inherit;
  font-size: 12px;
  font-weight: 580;
  letter-spacing: 0.06em;
}

.connect-button__pulse {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--cyan);
  box-shadow: 0 0 10px var(--cyan), 0 0 22px rgba(117, 248, 255, 0.46);
  animation: status-pulse 1.8s ease-in-out infinite;
}

.connect-button.is-connected {
  border-color: rgba(117, 248, 255, 0.3);
  color: #d4fdff;
  background: rgba(10, 45, 58, 0.45);
}

.connect-button.is-busy .connect-button__pulse {
  background: var(--gold);
  box-shadow: 0 0 12px var(--gold);
}

@keyframes status-pulse {
  0%, 100% { opacity: 0.55; transform: scale(0.8); }
  50% { opacity: 1; transform: scale(1.25); }
}

.stage-copy {
  position: absolute;
  z-index: 3;
  top: 49%;
  left: 50%;
  width: min(680px, 82vw);
  text-align: center;
  transform: translate(-50%, -50%);
  pointer-events: none;
  transition: opacity 650ms ease, transform 650ms cubic-bezier(0.2, 0.8, 0.2, 1);
}

.stage-copy.is-playing {
  opacity: 0.08;
  transform: translate(-50%, -44%) scale(0.96);
}

.stage-copy__eyebrow {
  margin: 0 0 16px;
  color: rgba(193, 237, 255, 0.58);
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.46em;
}

.stage-copy h1 {
  margin: 0;
  color: rgba(255, 255, 255, 0.9);
  font-size: clamp(34px, 5.6vw, 74px);
  line-height: 1.12;
  letter-spacing: 0.05em;
  font-weight: 260;
  text-shadow: 0 6px 42px rgba(31, 4, 92, 0.65);
}

.stage-copy h1 em {
  color: transparent;
  font-style: normal;
  font-weight: 540;
  background: linear-gradient(98deg, #fefaff 8%, #adf8ff 33%, #c0a2ff 62%, #ffb5e6 88%);
  -webkit-background-clip: text;
  background-clip: text;
  filter: drop-shadow(0 0 22px rgba(151, 121, 255, 0.28));
}

.stage-copy__hint {
  margin: 21px 0 0;
  color: rgba(226, 224, 248, 0.44);
  font-size: clamp(11px, 1.2vw, 14px);
  letter-spacing: 0.12em;
}

.ambient-note {
  position: absolute;
  z-index: 1;
  top: 43%;
  left: 50%;
  width: min(28vw, 310px);
  aspect-ratio: 1;
  transform: translate(-50%, -50%);
  display: grid;
  place-items: center;
  opacity: 0.2;
  pointer-events: none;
  animation: ambient-float 8s ease-in-out infinite;
  transition: opacity 500ms ease;
}

.light-stage.is-awake .ambient-note {
  opacity: 0.04;
}

.ambient-note::before {
  content: "";
  position: absolute;
  inset: 19%;
  border-radius: 50%;
  background: radial-gradient(circle, rgba(132, 245, 255, 0.22), rgba(155, 95, 255, 0.08) 34%, transparent 69%);
  filter: blur(13px);
}

.ambient-note__glyph {
  font-family: Georgia, serif;
  font-size: clamp(90px, 11vw, 150px);
  color: rgba(216, 250, 255, 0.19);
  text-shadow: 0 0 24px rgba(117, 248, 255, 0.35), 0 0 70px rgba(150, 87, 255, 0.3);
}

.ambient-note__orbit {
  position: absolute;
  inset: 11%;
  border: 1px solid rgba(142, 214, 255, 0.18);
  border-radius: 50%;
  transform: rotate(-18deg) scaleY(0.38);
  box-shadow: 0 0 22px rgba(114, 235, 255, 0.07);
}

.ambient-note__orbit--two {
  inset: 2%;
  border-color: rgba(210, 145, 255, 0.13);
  transform: rotate(32deg) scaleY(0.53);
}

@keyframes ambient-float {
  0%, 100% { transform: translate(-50%, -50%) rotate(-1.5deg); }
  50% { transform: translate(-50%, calc(-50% - 12px)) rotate(1.5deg); }
}

.midi-status {
  position: absolute;
  z-index: 5;
  left: clamp(22px, 4vw, 72px);
  bottom: 22px;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  color: rgba(219, 216, 242, 0.48);
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.17em;
  text-transform: uppercase;
  pointer-events: none;
}

.midi-status__dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #aa8dff;
  box-shadow: 0 0 10px rgba(170, 141, 255, 0.9);
}

.midi-status.is-connected .midi-status__dot {
  background: #6dffd9;
  box-shadow: 0 0 10px rgba(109, 255, 217, 0.95);
}

.midi-status.is-error .midi-status__dot {
  background: #ff8dba;
  box-shadow: 0 0 10px rgba(255, 109, 175, 0.8);
}

.stage-origin {
  position: absolute;
  z-index: 2;
  left: 6%;
  right: 6%;
  bottom: -1px;
  height: 1px;
  pointer-events: none;
  background: linear-gradient(90deg, transparent, rgba(143, 228, 255, 0.3) 20%, rgba(255, 255, 255, 0.46) 50%, rgba(212, 127, 255, 0.3) 80%, transparent);
  box-shadow: 0 -3px 25px rgba(111, 210, 255, 0.2);
}

.keyboard-zone {
  position: relative;
  z-index: 6;
  min-height: 0;
  padding: 14px clamp(16px, 3.4vw, 58px) max(12px, env(safe-area-inset-bottom));
  overflow: hidden;
  background:
    radial-gradient(ellipse at 50% 0%, rgba(89, 51, 162, 0.22), transparent 53%),
    linear-gradient(180deg, #0c081d 0%, #070510 100%);
  border-top: 1px solid rgba(198, 168, 255, 0.13);
  box-shadow: 0 -20px 60px rgba(4, 1, 17, 0.55);
}

.keyboard-aura {
  position: absolute;
  inset: -40px 9% auto;
  height: 70px;
  opacity: 0.5;
  background: radial-gradient(ellipse, rgba(135, 93, 255, 0.22), transparent 68%);
  filter: blur(16px);
  pointer-events: none;
}

.keyboard-shell {
  position: relative;
  width: min(100%, 1500px);
  height: 100%;
  margin: 0 auto;
  padding: 11px 13px 13px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  border-radius: 18px;
  overflow: hidden;
  background:
    linear-gradient(103deg, rgba(255, 255, 255, 0.055), transparent 22%, rgba(159, 110, 255, 0.035) 78%, rgba(255, 255, 255, 0.045)),
    linear-gradient(180deg, #171226 0%, #0a0712 42%, #05040a 100%);
  box-shadow:
    inset 0 1px rgba(255, 255, 255, 0.09),
    inset 0 -20px 30px rgba(0, 0, 0, 0.3),
    0 22px 45px rgba(0, 0, 0, 0.42);
}

.keyboard-shell::before {
  content: "";
  position: absolute;
  left: 5%;
  right: 5%;
  top: 0;
  height: 1px;
  background: linear-gradient(90deg, transparent, rgba(160, 236, 255, 0.28), rgba(234, 173, 255, 0.28), transparent);
}

.keyboard-topline {
  height: 32px;
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: start;
  color: rgba(221, 218, 245, 0.33);
}

.performance-indicator {
  display: flex;
  gap: 4px;
  padding: 5px 0 0 4px;
}

.performance-indicator span {
  display: block;
  width: 3px;
  height: 3px;
  border-radius: 50%;
  background: rgba(112, 243, 255, 0.45);
  box-shadow: 0 0 8px rgba(112, 243, 255, 0.55);
}

.performance-indicator span:nth-child(2) { opacity: 0.45; }
.performance-indicator span:nth-child(3) { opacity: 0.2; }

.keyboard-topline p {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  line-height: 1;
}

.keyboard-topline p span {
  color: rgba(235, 248, 255, 0.55);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 9px;
  font-weight: 650;
  letter-spacing: 0.15em;
}

.keyboard-topline p small {
  color: rgba(202, 191, 232, 0.23);
  font-family: ui-monospace, "SFMono-Regular", Menlo, monospace;
  font-size: 7px;
  letter-spacing: 0.12em;
}

.keyboard-wordmark {
  justify-self: end;
  padding: 2px 4px 0 0;
  font-size: 7px;
  font-weight: 700;
  letter-spacing: 0.16em;
}

.keyboard-wordmark span {
  color: var(--cyan);
  font-family: Georgia, serif;
  font-size: 12px;
  text-shadow: 0 0 10px rgba(117, 248, 255, 0.5);
}

.keyboard {
  position: relative;
  height: calc(100% - 32px);
  min-height: 130px;
  overflow: visible;
  touch-action: none;
  filter: drop-shadow(0 13px 12px rgba(0, 0, 0, 0.38));
}

.piano-key {
  position: absolute;
  top: 0;
  padding: 0;
  border: 0;
  cursor: pointer;
  touch-action: none;
  transition: transform 55ms ease-out, filter 90ms ease, background 100ms ease;
}

.piano-key--white {
  z-index: 1;
  width: calc(100% / 21 - 1px);
  height: 100%;
  border: 1px solid rgba(6, 4, 16, 0.7);
  border-top: 0;
  border-radius: 0 0 7px 7px;
  background:
    linear-gradient(90deg, rgba(94, 80, 121, 0.11), transparent 15%, transparent 72%, rgba(55, 44, 77, 0.14)),
    linear-gradient(180deg, #f9f8ff 0%, #d9d7e3 76%, #b8b4c6 100%);
  box-shadow:
    inset 0 -9px 12px rgba(28, 19, 48, 0.15),
    inset 0 2px 3px rgba(255, 255, 255, 0.8),
    0 3px 0 #858091;
}

.piano-key--white::before {
  content: "";
  position: absolute;
  inset: 55% 6px 7px;
  border-radius: 50% 50% 5px 5px;
  opacity: 0;
  background: linear-gradient(180deg, transparent, hsla(var(--key-hue), 92%, 61%, 0.75));
  filter: blur(4px);
  transition: opacity 100ms ease;
}

.piano-key--black {
  z-index: 3;
  width: calc(100% / 21 * 0.61);
  height: 62%;
  border: 1px solid rgba(255, 255, 255, 0.07);
  border-radius: 0 0 6px 6px;
  background:
    linear-gradient(90deg, rgba(255, 255, 255, 0.07), transparent 17%, transparent 67%, rgba(0, 0, 0, 0.34)),
    linear-gradient(180deg, #282336 0%, #100d19 72%, #050409 100%);
  box-shadow:
    inset 0 -7px 8px rgba(0, 0, 0, 0.65),
    inset 0 1px rgba(255, 255, 255, 0.11),
    0 8px 7px rgba(0, 0, 0, 0.42);
}

.piano-key--black::before {
  content: "";
  position: absolute;
  left: 10%;
  right: 10%;
  bottom: 4px;
  height: 38%;
  opacity: 0;
  border-radius: 50% 50% 4px 4px;
  background: linear-gradient(180deg, transparent, hsla(var(--key-hue), 95%, 65%, 0.78));
  filter: blur(3px);
  transition: opacity 100ms ease;
}

.piano-key.is-active {
  transform: translateY(3px) scaleY(0.987);
  filter: drop-shadow(0 0 7px hsla(var(--key-hue), 100%, 66%, 0.75));
}

.piano-key.is-active::before {
  opacity: 1;
}

.piano-key--white.is-active {
  background:
    linear-gradient(180deg, hsla(var(--key-hue), 80%, 97%, 0.95), hsla(var(--key-hue), 56%, 78%, 0.96)),
    #ece9f3;
}

.piano-key--black.is-active {
  background:
    linear-gradient(180deg, hsla(var(--key-hue), 47%, 32%, 0.95), hsla(var(--key-hue), 73%, 12%, 1)),
    #100d19;
}

.piano-key__label {
  position: absolute;
  left: 50%;
  bottom: 7px;
  color: rgba(27, 20, 42, 0.3);
  font: 600 7px/1 ui-monospace, "SFMono-Regular", Menlo, monospace;
  letter-spacing: 0.05em;
  transform: translateX(-50%);
  pointer-events: none;
}

.piano-key--black .piano-key__label {
  bottom: 5px;
  color: rgba(255, 255, 255, 0.18);
}

@media (max-width: 700px) {
  :root {
    --keyboard-height: clamp(190px, 30vh, 250px);
  }

  .experience {
    grid-template-rows: minmax(0, 1fr) var(--keyboard-height);
  }

  .stage-header {
    top: max(14px, env(safe-area-inset-top));
    left: 15px;
    right: 15px;
  }

  .brand__mark {
    width: 34px;
    height: 34px;
    border-radius: 11px;
    font-size: 22px;
  }

  .brand__copy strong { font-size: 14px; }
  .brand__copy small { font-size: 6px; }
  .connect-button { min-width: 40px; width: 40px; padding: 0; }
  .connect-button #connect-label { display: none; }
  .stage-actions { gap: 6px; }
  .icon-button, .connect-button { width: 36px; height: 36px; border-radius: 12px; }

  .stage-copy {
    top: 48%;
  }

  .stage-copy__eyebrow { margin-bottom: 10px; }
  .stage-copy__hint { line-height: 1.6; }

  .midi-status {
    left: 17px;
    bottom: 13px;
  }

  .keyboard-zone {
    padding: 9px 7px max(7px, env(safe-area-inset-bottom));
  }

  .keyboard-shell {
    padding: 8px 4px 7px;
    border-radius: 12px;
  }

  .keyboard-topline {
    height: 25px;
  }

  .keyboard {
    height: calc(100% - 25px);
  }

  .keyboard-topline p small,
  .keyboard-wordmark {
    display: none;
  }

  .piano-key--white {
    width: calc(100% / 21 - 0.5px);
    border-radius: 0 0 4px 4px;
  }

  .piano-key__label {
    display: none;
  }
}

@media (max-height: 620px) and (orientation: landscape) {
  :root {
    --keyboard-height: 37vh;
  }

  .stage-copy__hint,
  .ambient-note,
  .midi-status {
    display: none;
  }

  .stage-copy {
    top: 54%;
  }

  .stage-copy h1 {
    font-size: clamp(26px, 6.5vh, 44px);
  }

  .stage-copy__eyebrow { margin-bottom: 6px; }
  .stage-header { top: 10px; }
}

@media (prefers-reduced-motion: reduce) {
  .ambient-note,
  .connect-button__pulse {
    animation: none;
  }

  .stage-copy,
  .piano-key,
  .icon-button,
  .connect-button {
    transition-duration: 0.01ms;
  }
}
