:root {
  --paper: #f8f8f4;
  --ink: #11110f;
  --muted: #77766f;
  --line: #d9d8d0;
  --signal: #2457ff;
  --panel: rgba(248, 248, 244, 0.9);
}

* {
  box-sizing: border-box;
}

html {
  background: var(--paper);
}

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  overflow-x: hidden;
  color: var(--ink);
  background:
    linear-gradient(rgba(17, 17, 15, 0.018) 1px, transparent 1px),
    var(--paper);
  background-size: 100% 32px;
  font-family: "PingFang SC", "Noto Sans CJK SC", system-ui, sans-serif;
}

button,
input {
  font: inherit;
}

button {
  color: inherit;
}

button:focus-visible,
input:focus-visible {
  outline: 2px solid var(--signal);
  outline-offset: 3px;
}

.masthead {
  min-height: 104px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 28px;
  padding: 20px 30px;
  border-bottom: 1px solid var(--line);
  background: var(--panel);
  backdrop-filter: blur(14px);
  position: relative;
  z-index: 2;
}

.identity {
  display: flex;
  align-items: center;
  gap: 12px;
  flex: 0 0 auto;
}

.identity__mark {
  width: 35px;
  height: 35px;
  display: grid;
  place-items: center;
  border: 1px solid var(--ink);
  border-radius: 50%;
  font-size: 18px;
  transform: rotate(-14deg);
}

.identity h1 {
  margin: 0 0 3px;
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-size: clamp(20px, 2vw, 28px);
  font-weight: 600;
  letter-spacing: 0.06em;
}

.identity p {
  margin: 0;
  color: var(--muted);
  font-family: "Arial Narrow", "Helvetica Neue", sans-serif;
  font-size: 9px;
  font-weight: 700;
  letter-spacing: 0.18em;
}

.controls {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
}

.mode-switch {
  display: flex;
  padding: 3px;
  border: 1px solid var(--line);
  border-radius: 999px;
}

.mode-button {
  min-width: 52px;
  padding: 7px 12px;
  border: 0;
  border-radius: 999px;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 12px;
  transition: color 180ms ease, background 180ms ease;
}

.mode-button:hover {
  color: var(--ink);
}

.mode-button.is-active {
  color: var(--paper);
  background: var(--ink);
}

.dance-toggle,
.music-button,
.tuning-button {
  min-width: 126px;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 10px 14px;
  border: 1px solid var(--ink);
  border-radius: 0;
  background: transparent;
  cursor: pointer;
  font-size: 12px;
  transition: color 180ms ease, background 180ms ease;
}

.dance-toggle:hover,
.music-button:hover,
.music-button.is-active,
.tuning-button:hover,
.tuning-button[aria-expanded="true"] {
  color: var(--paper);
  background: var(--ink);
}

.music-button {
  min-width: 104px;
  border-color: var(--line);
}

.tuning-button {
  min-width: 76px;
  border-color: var(--line);
}

.tuning-button > span:first-child {
  color: var(--signal);
  font-family: Georgia, serif;
  font-size: 17px;
  line-height: 1;
}

.tuning-button[aria-expanded="true"] > span:first-child {
  color: #89a5ff;
}

.music-button__icon {
  color: var(--signal);
  font-family: Georgia, serif;
  font-size: 16px;
  line-height: 1;
  transform: scale(calc(1 + var(--audio-level, 0) * 0.35));
  transition: transform 80ms linear;
}

.music-button.is-active .music-button__icon {
  color: #89a5ff;
}

.music-button.is-paused {
  color: var(--ink);
  background: transparent;
}

.dance-toggle__dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 0 4px rgba(36, 87, 255, 0.12);
  animation: pulse 1.4s ease-in-out infinite;
}

.dance-toggle[aria-pressed="false"] .dance-toggle__dot {
  background: var(--muted);
  box-shadow: none;
  animation: none;
}

main {
  height: calc(100svh - 104px);
  min-height: 560px;
}

.stage {
  height: 100%;
  position: relative;
  overflow: hidden;
  isolation: isolate;
  cursor: crosshair;
}

#danceFloor {
  width: 100%;
  height: 100%;
  display: block;
}

.tuning-panel {
  width: 286px;
  position: absolute;
  top: 18px;
  right: 30px;
  z-index: 4;
  padding: 17px;
  border: 1px solid var(--ink);
  background: rgba(248, 248, 244, 0.96);
  box-shadow: 9px 9px 0 rgba(17, 17, 15, 0.06);
  cursor: default;
}

.tuning-panel[hidden] {
  display: none;
}

.tuning-panel__header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 19px;
  padding-bottom: 13px;
  border-bottom: 1px solid var(--line);
}

.tuning-panel__header > div {
  display: grid;
  gap: 2px;
}

.tuning-panel__header small {
  color: var(--signal);
  font-family: "Arial Narrow", "Helvetica Neue", sans-serif;
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.17em;
}

.tuning-panel__header strong {
  font-family: "Songti SC", "Noto Serif CJK SC", serif;
  font-size: 17px;
  font-weight: 600;
  letter-spacing: 0.05em;
}

.tuning-panel__header button {
  width: 28px;
  height: 28px;
  display: grid;
  place-items: center;
  padding: 0;
  border: 1px solid var(--line);
  background: transparent;
  cursor: pointer;
  font-size: 18px;
  line-height: 1;
}

.tuning-panel__header button:hover {
  color: var(--paper);
  background: var(--ink);
}

.tuning-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 7px 12px;
  margin-top: 15px;
  color: var(--ink);
  font-size: 11px;
}

.tuning-row output {
  color: var(--signal);
  font-family: "Arial Narrow", "Helvetica Neue", sans-serif;
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}

.tuning-row input {
  grid-column: 1 / -1;
  width: 100%;
  height: 2px;
  appearance: none;
  border: 0;
  border-radius: 10px;
  background: var(--line);
  cursor: ew-resize;
}

.tuning-row input::-webkit-slider-thumb {
  width: 13px;
  height: 13px;
  appearance: none;
  border: 2px solid var(--paper);
  border-radius: 50%;
  background: var(--signal);
  box-shadow: 0 0 0 1px var(--signal);
}

.tuning-row i {
  grid-column: 1 / -1;
  display: flex;
  justify-content: space-between;
  color: var(--muted);
  font-size: 8px;
  font-style: normal;
  letter-spacing: 0.04em;
}

.reshuffle-button {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 20px;
  padding: 10px 11px;
  border: 1px solid var(--ink);
  background: transparent;
  cursor: pointer;
  font-size: 11px;
}

.reshuffle-button:hover {
  color: var(--paper);
  background: var(--ink);
}

.reshuffle-button span {
  color: var(--signal);
  font-size: 16px;
}

.reshuffle-button.is-spinning span {
  animation: reshuffle-spin 420ms ease-out;
}

.stage__loading {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  background: var(--paper);
  font-family: "Songti SC", serif;
  font-size: 14px;
  letter-spacing: 0.2em;
  transition: opacity 500ms ease, visibility 500ms ease;
}

.stage__loading.is-hidden {
  opacity: 0;
  visibility: hidden;
}

.stage__guide {
  position: absolute;
  left: 30px;
  bottom: 22px;
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  pointer-events: none;
  font-size: 10px;
  letter-spacing: 0.1em;
}

.stage__guide i {
  width: 24px;
  height: 1px;
  background: var(--line);
}

.stage__counter {
  position: absolute;
  right: 30px;
  bottom: 20px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  pointer-events: none;
  font-family: "Arial Narrow", "Helvetica Neue", sans-serif;
}

.stage__counter span {
  font-size: 22px;
  font-variant-numeric: tabular-nums;
  letter-spacing: 0.04em;
}

.stage__counter small {
  color: var(--signal);
  font-size: 8px;
  font-weight: 800;
  letter-spacing: 0.18em;
}

.stage__solo {
  position: absolute;
  top: 20px;
  left: 30px;
  display: flex;
  align-items: baseline;
  gap: 8px;
  padding: 7px 9px 6px;
  border-left: 2px solid var(--signal);
  color: var(--muted);
  background: rgba(248, 248, 244, 0.78);
  pointer-events: none;
  opacity: 0;
  transform: translateY(-5px);
  transition: opacity 180ms ease, transform 180ms ease;
  font-family: "Arial Narrow", "Helvetica Neue", sans-serif;
  font-size: 8px;
  letter-spacing: 0.18em;
}

.stage__solo.is-visible {
  opacity: 1;
  transform: translateY(0);
}

.stage__solo strong {
  color: var(--ink);
  font-size: 15px;
  font-weight: 500;
  letter-spacing: 0.04em;
}

@keyframes pulse {
  0%, 100% { transform: scale(0.82); opacity: 0.65; }
  50% { transform: scale(1); opacity: 1; }
}

@keyframes reshuffle-spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

@media (max-width: 820px) {
  .masthead {
    align-items: flex-start;
    flex-direction: column;
    gap: 16px;
    padding: 18px 18px 14px;
  }

  .controls {
    width: 100%;
    justify-content: space-between;
    gap: 10px;
  }

  .dance-toggle {
    min-width: 40px;
    padding-inline: 10px;
  }

  .dance-toggle__label {
    display: none;
  }

  .music-button {
    min-width: 40px;
    padding-inline: 10px;
  }

  .music-button__label {
    display: none;
  }

  .tuning-button {
    min-width: 40px;
    padding-inline: 10px;
  }

  .tuning-button > span:last-child {
    display: none;
  }

  .tuning-panel {
    width: auto;
    top: 12px;
    right: 18px;
    left: 18px;
  }

  main {
    height: calc(100svh - 160px);
    min-height: 520px;
  }

  .stage__guide {
    left: 18px;
    bottom: 14px;
  }

  .stage__guide span:last-child,
  .stage__guide i {
    display: none;
  }

  .stage__counter {
    right: 18px;
    bottom: 12px;
  }

  .stage__solo {
    top: 12px;
    right: 18px;
    left: auto;
  }
}

@media (max-width: 430px) {
  .mode-button {
    min-width: 38px;
    padding-inline: 7px;
  }

  .dance-toggle {
    min-width: auto;
    padding-inline: 11px;
  }
}

@media (prefers-reduced-motion: reduce) {
  .dance-toggle__dot {
    animation: none;
  }

  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    transition-duration: 0.01ms !important;
  }
}
