:root {
  color-scheme: dark;
  --primary: #4ad1ff;
  --primary-strong: #1aa7ff;
  --accent: #a96bff;
  --bg: #0d1017;
  --bg-soft: #141a24;
  --bg-card: rgba(255, 255, 255, 0.06);
  --text: #f4f7ff;
  --muted: rgba(244, 247, 255, 0.7);
  --success: #25e88b;
  --error: #ff5c71;
  --warning: #ffc857;
  --white-key-width: 36px;
  --white-key-height: 180px;
  --black-key-width: 22px;
  --black-key-height: 110px;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: "Noto Sans", "PingFang SC", "Microsoft YaHei", "Segoe UI",
    sans-serif;
  background: radial-gradient(circle at top, #1a2233, #0b0f18 50%, #090c12);
  color: var(--text);
}

body[dir="rtl"] {
  direction: rtl;
}

.app {
  max-width: 1200px;
  margin: 0 auto;
  padding: 24px 16px 48px;
  display: flex;
  flex-direction: column;
  gap: 24px;
}

.app-header {
  display: flex;
  flex-direction: column;
  gap: 16px;
  background: linear-gradient(120deg, rgba(74, 209, 255, 0.2), transparent);
  border-radius: 16px;
  padding: 20px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
}

.title-block h1 {
  margin: 0;
  font-size: 28px;
  letter-spacing: 1px;
}

.subtitle {
  margin: 8px 0 0;
  color: var(--muted);
  font-size: 14px;
}

.toolbar {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 16px;
}

.toolbar-section {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toolbar-label {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: var(--muted);
}

.toolbar-buttons,
.mode-buttons,
.key-buttons,
.practice-buttons,
.manual-buttons {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.toolbar-select {
  width: 100%;
  max-width: 260px;
  padding: 8px 12px;
  border-radius: 10px;
  background: rgba(18, 24, 36, 0.9);
  border: 1px solid rgba(255, 255, 255, 0.2);
  color: var(--text);
  font-size: 14px;
}

button {
  border: none;
  cursor: pointer;
  padding: 8px 12px;
  border-radius: 10px;
  font-size: 14px;
  background: var(--bg-card);
  color: var(--text);
  transition: transform 0.15s ease, box-shadow 0.2s ease,
    background 0.2s ease;
}

button:hover {
  transform: translateY(-1px);
}

button.primary {
  background: linear-gradient(135deg, var(--primary), var(--accent));
  color: #03101f;
  font-weight: 600;
  box-shadow: 0 8px 16px rgba(74, 209, 255, 0.25);
}

button.ghost {
  border: 1px solid rgba(255, 255, 255, 0.2);
  background: transparent;
}

button.active {
  box-shadow: 0 0 0 2px rgba(74, 209, 255, 0.6);
}

.theme-swatch {
  width: 26px;
  height: 26px;
  border-radius: 999px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  padding: 0;
  background: transparent;
}

.theme-swatch.active {
  box-shadow: 0 0 0 2px rgba(255, 255, 255, 0.8);
}

.controls {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 16px;
}

.control-card {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: inset 0 0 20px rgba(74, 209, 255, 0.08);
}

.control-title {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
}

.key-selector {
  margin-top: 12px;
}

.key-buttons button {
  min-width: 48px;
}

.mode-status {
  margin-top: 12px;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.tips-card ul {
  margin: 0;
  padding-left: 18px;
  color: var(--muted);
  font-size: 13px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.sheet-area {
  position: relative;
  background: linear-gradient(180deg, rgba(15, 20, 30, 0.95), rgba(8, 10, 16, 0.95));
  border-radius: 18px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  box-shadow: 0 20px 60px rgba(0, 0, 0, 0.35);
  overflow: hidden;
}

.sheet-scroll {
  position: relative;
  overflow-x: auto;
  overflow-y: hidden;
  padding: 0;
  -webkit-overflow-scrolling: touch;
}

#staff-svg {
  width: 100%;
  height: 260px;
  display: block;
}

#overlay-svg {
  position: absolute;
  left: 0;
  top: 0;
  width: 100%;
  height: 100%;
  pointer-events: none;
}

.keyboard-wrapper {
  position: relative;
  margin-top: 8px;
  padding-top: 12px;
}

#keyboard {
  position: relative;
  height: var(--white-key-height);
  display: flex;
  user-select: none;
}

#fixed-labels {
  position: relative;
  height: 28px;
  margin-top: 6px;
}

.fixed-label {
  position: absolute;
  bottom: 0;
  transform: translateX(-50%);
  font-size: 12px;
  color: rgba(244, 247, 255, 0.65);
  line-height: 1;
  white-space: nowrap;
}

.key {
  position: relative;
  display: flex;
  justify-content: center;
  align-items: flex-end;
  border-radius: 0 0 8px 8px;
  transition: transform 0.1s ease, box-shadow 0.2s ease,
    background 0.2s ease;
  touch-action: none;
}

.key.white {
  width: var(--white-key-width);
  height: var(--white-key-height);
  background: linear-gradient(#ffffff, #dfe6f4);
  border: 1px solid #b9c4da;
  z-index: 1;
}

.key.black {
  width: var(--black-key-width);
  height: var(--black-key-height);
  background: linear-gradient(#1b202d, #040508);
  border: 1px solid #030407;
  position: absolute;
  top: 0;
  z-index: 2;
  border-radius: 0 0 6px 6px;
}

.key.pressed {
  transform: translateY(4px);
  box-shadow: 0 0 18px rgba(74, 209, 255, 0.6);
}

.key.answer.white {
  background: linear-gradient(#e9fff1, #c4f4d6);
  box-shadow: 0 0 20px rgba(37, 232, 139, 0.85);
}

.key.answer.black {
  background: linear-gradient(#164734, #0b1f16);
  box-shadow: 0 0 18px rgba(37, 232, 139, 0.7);
}

.key.correct {
  box-shadow: 0 0 20px rgba(37, 232, 139, 0.8);
}

.key.wrong {
  box-shadow: 0 0 18px rgba(255, 92, 113, 0.8);
}

.key-label {
  position: absolute;
  bottom: 34%;
  left: 50%;
  transform: translateX(-50%);
  text-align: center;
  font-size: 12px;
  line-height: 1.1;
  color: #0b1320;
  min-width: 36px;
  text-shadow: 0 0 8px rgba(255, 255, 255, 0.35);
}

.key.black .key-label {
  color: #eef3ff;
  bottom: 22%;
  text-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
}

.key-label .degree {
  font-weight: 700;
  color: var(--primary-strong);
  display: block;
}

.key-label.degree-1 .degree {
  color: var(--accent);
  text-shadow: 0 0 8px rgba(169, 107, 255, 0.8);
}

.key-fixed-label {
  display: none;
}

.practice-section {
  background: var(--bg-card);
  border-radius: 16px;
  padding: 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.practice-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
}

.practice-body {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.practice-row {
  display: flex;
  flex-wrap: wrap;
  gap: 18px;
  align-items: center;
}

.practice-group,
.manual-group {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.question-display {
  flex: 1;
  min-height: 48px;
  background: rgba(9, 13, 20, 0.7);
  border-radius: 12px;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  font-size: 16px;
  display: flex;
  align-items: center;
}

.practice-actions {
  display: flex;
  gap: 12px;
}

.manual-panel {
  display: none;
  gap: 16px;
  border-top: 1px dashed rgba(255, 255, 255, 0.2);
  padding-top: 12px;
}

.manual-panel.active {
  display: flex;
}

.manual-tip {
  font-size: 12px;
  color: var(--muted);
  line-height: 1.5;
  max-width: 220px;
}

.details-section {
  display: grid;
  gap: 12px;
}

details {
  background: rgba(18, 24, 36, 0.9);
  border-radius: 12px;
  padding: 12px 16px;
  border: 1px solid rgba(255, 255, 255, 0.08);
}

details summary {
  cursor: pointer;
  font-weight: 600;
  list-style: none;
}

details summary::-webkit-details-marker {
  display: none;
}

details .detail-body {
  margin-top: 12px;
  color: var(--muted);
  line-height: 1.6;
  font-size: 13px;
}

.detail-body table {
  width: 100%;
  border-collapse: collapse;
  margin-top: 8px;
  font-size: 12px;
}

.detail-body th,
.detail-body td {
  border-bottom: 1px solid rgba(255, 255, 255, 0.08);
  padding: 6px 4px;
  text-align: left;
}

.note {
  fill: rgba(255, 255, 255, 0.05);
  stroke: #e8f1ff;
  stroke-width: 1.6;
}

.note.answer {
  stroke: var(--success);
  filter: drop-shadow(0 0 6px rgba(37, 232, 139, 0.8));
}

.note.degree-1 {
  stroke: var(--accent);
  filter: drop-shadow(0 0 6px rgba(169, 107, 255, 0.8));
}

.note-label {
  font-size: 12px;
  fill: #f0f4ff;
}

.key-signature {
  font-size: 22px;
  fill: #dfe9ff;
}

.clef {
  font-size: 34px;
  fill: #e4ecff;
}

.staff-line {
  stroke: rgba(220, 235, 255, 0.7);
  stroke-width: 1.2;
}

.ledger-line {
  stroke: rgba(220, 235, 255, 0.6);
  stroke-width: 1;
}

.link-line {
  stroke: rgba(74, 209, 255, 0.5);
  stroke-width: 1;
  stroke-dasharray: 4 4;
}

@media (max-width: 900px) {
  .app {
    padding: 16px 12px 32px;
  }

  .title-block h1 {
    font-size: 24px;
  }

  #staff-svg {
    height: 220px;
  }

  :root {
    --white-key-height: 150px;
    --black-key-height: 90px;
    --white-key-width: 32px;
    --black-key-width: 20px;
  }
}

@media (max-width: 640px) {
  .toolbar {
    grid-template-columns: 1fr;
  }

  .practice-header {
    flex-direction: column;
    align-items: flex-start;
  }

  #staff-svg {
    height: 200px;
  }

  .question-display {
    font-size: 14px;
  }

  :root {
    --white-key-height: 140px;
    --black-key-height: 82px;
    --white-key-width: 30px;
    --black-key-width: 18px;
  }
}
