:root {
  --step: clamp(44px, 5.6vw, 72px);
  --paper: #fbfaf7;
  --ink: #151515;
  --muted: #6f7678;
  --line: #d8d5ce;
  --accent: #3aa8b5;
  --accent-soft: #d6eef1;
  --gold: #ffc400;
  --cyan: #00aee8;
  --selected: #f05d3a;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background: var(--paper);
  font-family:
    Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI",
    "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
select {
  font: inherit;
}

.app {
  width: min(1440px, calc(100vw - 32px));
  margin: 0 auto;
  padding: 32px 0;
}

.topbar {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 22px;
}

h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 48px);
  line-height: 1;
  letter-spacing: 0;
}

p {
  max-width: 680px;
  margin: 12px 0 0;
  color: var(--muted);
  font-size: 16px;
  line-height: 1.55;
}

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

.field {
  display: grid;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
}

select {
  min-width: 128px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0 38px 0 12px;
  color: var(--ink);
  background: white;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 8px;
  overflow: hidden;
  background: white;
}

.segmented button {
  min-width: 70px;
  border: 0;
  border-right: 1px solid var(--line);
  color: var(--muted);
  background: transparent;
  cursor: pointer;
}

.segmented button:last-child {
  border-right: 0;
}

.segmented .active {
  color: white;
  background: var(--ink);
}

.instrument {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
  overflow: hidden;
}

.scroll-shell {
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
}

.scroll-shell::-webkit-scrollbar {
  display: none;
}

.keyboard {
  position: relative;
  display: grid;
  grid-template-columns: repeat(36, var(--step));
  width: calc(var(--step) * 36);
  border-bottom: 3px solid var(--ink);
}

.key {
  position: relative;
  display: grid;
  place-items: center;
  height: clamp(188px, 20vw, 260px);
  border-right: 2px solid var(--ink);
  user-select: none;
}

.key:first-child {
  border-left: 2px solid var(--ink);
}

.key.natural {
  color: var(--ink);
  background: #fff;
}

.key.accidental {
  color: #fff;
  background: #000;
}

.key.in-scale::after {
  content: "";
  position: absolute;
  inset: 8px;
  border: 4px solid var(--selected);
  pointer-events: none;
}

.key.tonic::after {
  border-color: var(--accent);
  box-shadow: inset 0 0 0 4px rgba(58, 168, 181, 0.18);
}

.note-label {
  display: grid;
  gap: 18px;
  justify-items: center;
  font-size: clamp(28px, 4vw, 48px);
  font-weight: 600;
  line-height: 0.9;
}

.natural .note-label {
  gap: 0;
}

.degree-badge {
  position: absolute;
  right: 8px;
  top: 8px;
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  color: white;
  background: var(--selected);
  font-weight: 800;
}

.tonic .degree-badge {
  background: var(--accent);
}

.ruler-lane {
  position: relative;
  height: 236px;
  width: calc(var(--step) * 36);
  background:
    linear-gradient(90deg, rgba(21, 21, 21, 0.05) 1px, transparent 1px) 0 0 /
      var(--step) 100%,
    linear-gradient(#fff 0, #fff 69%, #fafafa 69%, #fafafa 100%);
}

.ruler {
  position: absolute;
  top: 18px;
  left: 0;
  width: calc(var(--step) * 13);
  height: 194px;
  border-radius: 8px;
  background: rgba(214, 238, 241, 0.52);
  box-shadow:
    inset 0 0 0 2px rgba(58, 168, 181, 0.4),
    0 10px 24px rgba(33, 75, 82, 0.14);
  cursor: ew-resize;
  touch-action: none;
  outline: none;
}

.ruler:active {
  cursor: ew-resize;
}

.ruler:focus-visible {
  outline: 3px solid var(--accent);
  outline-offset: 4px;
}

.ruler::before {
  content: "拖动标尺";
  position: absolute;
  left: 12px;
  top: 10px;
  z-index: 2;
  display: grid;
  place-items: center;
  min-width: 88px;
  height: 30px;
  border: 1px solid rgba(58, 168, 181, 0.65);
  border-radius: 999px;
  color: #126b76;
  background: rgba(255, 255, 255, 0.92);
  font-size: 14px;
  font-weight: 800;
  box-shadow: 0 4px 10px rgba(33, 75, 82, 0.12);
  pointer-events: none;
}

.ruler::after {
  content: "";
  position: absolute;
  right: 12px;
  top: 12px;
  z-index: 2;
  width: 30px;
  height: 26px;
  border-radius: 999px;
  background:
    radial-gradient(circle, #126b76 2px, transparent 2.5px) 7px 8px / 8px 8px,
    rgba(255, 255, 255, 0.92);
  border: 1px solid rgba(58, 168, 181, 0.65);
  box-shadow: 0 4px 10px rgba(33, 75, 82, 0.12);
  pointer-events: none;
}

.degree {
  position: absolute;
  top: 38px;
  width: var(--step);
  transform: translateX(-50%);
  text-align: center;
}

.degree-number {
  display: block;
  color: rgba(58, 168, 181, 0.72);
  font-size: clamp(42px, 5.6vw, 68px);
  font-weight: 800;
  line-height: 0.9;
}

.degree-number.octave {
  position: relative;
}

.degree-number.octave::after {
  content: "";
  position: absolute;
  right: 7%;
  top: -5px;
  width: 12px;
  height: 12px;
  border-radius: 50%;
  background: currentColor;
}

.bracket {
  position: absolute;
  top: 116px;
  height: 22px;
  border-bottom: 5px solid var(--gold);
  border-left: 5px solid var(--gold);
  border-right: 5px solid var(--gold);
  border-radius: 0 0 6px 6px;
}

.bracket.half {
  border-color: var(--cyan);
}

.interval-label {
  position: absolute;
  top: 136px;
  transform: translateX(-50%);
  color: var(--gold);
  font-size: clamp(38px, 5vw, 62px);
  font-weight: 900;
  line-height: 1;
}

.interval-label.half {
  color: var(--cyan);
}

.result {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  margin-top: 18px;
  padding: 18px 20px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.caption {
  display: block;
  margin-bottom: 5px;
  color: var(--muted);
  font-size: 13px;
}

#scaleTitle {
  font-size: 24px;
}

.scale-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
  padding: 0;
  margin: 0;
  list-style: none;
}

.scale-list li {
  display: grid;
  place-items: center;
  min-width: 54px;
  height: 54px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 22px;
  font-weight: 800;
}

.scale-list span {
  display: block;
  color: var(--muted);
  font-size: 11px;
  font-weight: 700;
}

@media (max-width: 760px) {
  .app {
    width: min(100vw - 20px, 1180px);
    padding: 20px 0;
  }

  .topbar,
  .result {
    align-items: stretch;
    flex-direction: column;
  }

  .controls,
  .scale-list {
    justify-content: flex-start;
  }

  .key {
    height: 190px;
  }

  .ruler::before {
    min-width: 72px;
    font-size: 12px;
  }
}
