* {
    box-sizing: border-box;
}

html,
body {
    margin: 0;
    padding: 0;
    width: 100%;
    min-height: 100%;
    background: #111827;
    color: #e5e7eb;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
}

body {
    overflow-x: hidden;
}

.app {
    width: 100%;
    max-width: 1500px;
    margin: 0 auto;
    padding: 24px;
}

/* =========================
   顶部导航（练习 / 测试 切换）
========================= */

.nav {
    display: flex;
    justify-content: center;
    gap: 6px;
    margin-bottom: 20px;
    padding: 5px;
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 12px;
    width: fit-content;
    margin-left: auto;
    margin-right: auto;
}

.nav a {
    display: inline-block;
    padding: 9px 26px;
    border-radius: 8px;
    color: #9ca3af;
    text-decoration: none;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.15s ease;
}

.nav a:hover {
    color: #f3f4f6;
    background: #273548;
}

.nav a.active {
    background: #2563eb;
    color: white;
}

/* =========================
   标题
========================= */

.title {
    text-align: center;
    margin-bottom: 22px;
}

.title h1 {
    margin: 0;
    font-size: 30px;
    font-weight: 700;
    color: #f9fafb;
}

.title p {
    margin: 8px 0 0;
    color: #9ca3af;
    font-size: 14px;
}

/* =========================
   控制面板
========================= */

.panel {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 14px;
    padding: 20px;
    margin-bottom: 18px;
}

.section-title {
    font-size: 15px;
    font-weight: 600;
    color: #f3f4f6;
    margin-bottom: 12px;
}

.section-title-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 12px;
}

.section-title-row .section-title {
    margin-bottom: 0;
}

.mini-btn {
    border: 1px solid #4b5563;
    background: transparent;
    color: #9ca3af;
    border-radius: 6px;
    padding: 4px 10px;
    font-size: 12px;
    cursor: pointer;
    margin-left: 6px;
}

.mini-btn:hover {
    color: #f3f4f6;
    border-color: #60a5fa;
}

/* 和弦测试页：预设组合按钮，窄屏时换行 */
.preset-row {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    gap: 6px 0;
}

/* =========================
   音程选择
========================= */

.interval-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(90px, 1fr));
    gap: 8px;
}

.interval-btn {
    border: 1px solid #4b5563;
    background: #111827;
    color: #d1d5db;
    border-radius: 8px;
    padding: 10px 6px;
    cursor: pointer;
    transition: all 0.15s ease;
    user-select: none;
}

.interval-btn:hover {
    border-color: #60a5fa;
    background: #1e293b;
}

.interval-btn.active {
    background: #2563eb;
    border-color: #60a5fa;
    color: white;
}

.interval-name {
    font-size: 14px;
    font-weight: 600;
}

.interval-semitone {
    margin-top: 3px;
    font-size: 12px;
    color: #9ca3af;
}

.interval-btn.active .interval-semitone {
    color: #dbeafe;
}

/* =========================
   上行下行 / 单选按钮组
========================= */

.direction-row {
    display: flex;
    gap: 10px;
    margin-top: 18px;
    flex-wrap: wrap;
}

.direction-btn {
    min-width: 120px;
    padding: 10px 20px;
    border-radius: 8px;
    border: 1px solid #4b5563;
    background: #111827;
    color: #d1d5db;
    cursor: pointer;
    font-size: 14px;
}

.direction-btn:hover {
    border-color: #60a5fa;
}

.direction-btn.active {
    background: #2563eb;
    color: white;
    border-color: #60a5fa;
}

/* =========================
   延迟
========================= */

.delay-row {
    margin-top: 18px;
    display: flex;
    align-items: center;
    gap: 14px;
}

.delay-row label {
    white-space: nowrap;
    font-size: 14px;
}

.delay-row input[type="range"] {
    width: 260px;
}

#delayValue {
    width: 60px;
    color: #60a5fa;
    font-weight: 600;
}

/* 和声模式下两个音同时发声，延迟不生效 */
.delay-row.disabled {
    opacity: 0.4;
}

.delay-row.disabled input[type="range"] {
    cursor: not-allowed;
}

/* =========================
   操作按钮
========================= */

.action-row {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 20px;
}

.action-btn {
    border: none;
    border-radius: 8px;
    padding: 11px 20px;
    font-size: 14px;
    cursor: pointer;
    background: #374151;
    color: #f3f4f6;
}

.action-btn:hover {
    background: #4b5563;
}

.action-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.action-btn.primary {
    background: #2563eb;
}

.action-btn.primary:hover:not(:disabled) {
    background: #1d4ed8;
}

.action-btn.green {
    background: #059669;
}

.action-btn.green:hover:not(:disabled) {
    background: #047857;
}

/* =========================
   状态
========================= */

.status {
    margin-top: 14px;
    font-size: 13px;
    color: #9ca3af;
}

.status.ready {
    color: #34d399;
}

.status.error {
    color: #f87171;
}

/* =========================
   音符显示：固定高度 + nowrap + flex
========================= */

.note-display-box {
    width: 100%;
    height: 70px;
    min-height: 70px;
    display: flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    background: #0f172a;
    border: 1px solid #374151;
    border-radius: 12px;
    margin-bottom: 18px;
}

.interval-display {
    height: 42px;
    min-height: 42px;
    display: flex;
    flex-direction: row;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 18px;
    white-space: nowrap;
    overflow: hidden;
    font-size: 25px;
    font-weight: 700;
    line-height: 1;
    color: #f9fafb;
}

.interval-display span {
    display: inline-block;
    flex: 0 0 auto;
    white-space: nowrap;
}

.interval-display .arrow {
    font-size: 25px;
    color: #60a5fa;
    line-height: 1;
}

/* =========================
   测试页：题目区
========================= */

.quiz-stage {
    background: #0f172a;
    border: 1px solid #374151;
    border-radius: 12px;
    padding: 22px;
    margin-bottom: 18px;
    text-align: center;
}

.quiz-question {
    font-size: 18px;
    color: #d1d5db;
    min-height: 26px;
}

.quiz-question .hint {
    color: #6b7280;
    font-size: 14px;
}

.quiz-feedback {
    margin-top: 12px;
    min-height: 56px;
    font-size: 22px;
    font-weight: 700;
}

.quiz-feedback.correct {
    color: #34d399;
}

.quiz-feedback.wrong {
    color: #f87171;
}

.quiz-feedback .detail {
    display: block;
    margin-top: 6px;
    font-size: 15px;
    font-weight: 500;
    color: #9ca3af;
}

.quiz-controls {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.answer-grid {
    display: grid;
    grid-template-columns: repeat(7, minmax(90px, 1fr));
    gap: 8px;
    margin-top: 18px;
}

.answer-btn {
    border: 1px solid #4b5563;
    background: #111827;
    color: #d1d5db;
    border-radius: 8px;
    padding: 12px 6px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 600;
    transition: all 0.15s ease;
    user-select: none;
}

.answer-btn:hover:not(:disabled) {
    border-color: #60a5fa;
    background: #1e293b;
}

.answer-btn:disabled {
    cursor: default;
    opacity: 0.6;
}

.answer-btn.correct {
    background: #059669;
    border-color: #34d399;
    color: white;
    opacity: 1;
}

.answer-btn.wrong {
    background: #b91c1c;
    border-color: #f87171;
    color: white;
    opacity: 1;
}

.answer-btn .key-hint {
    display: block;
    margin-top: 3px;
    font-size: 11px;
    color: #6b7280;
    font-weight: 400;
}

/* =========================
   测试页：统计
========================= */

.stats-row {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 14px;
}

.stat-card {
    flex: 1 1 120px;
    background: #111827;
    border: 1px solid #374151;
    border-radius: 10px;
    padding: 12px 16px;
}

.stat-label {
    font-size: 12px;
    color: #9ca3af;
}

.stat-value {
    margin-top: 4px;
    font-size: 24px;
    font-weight: 700;
    color: #f9fafb;
}

.stat-value.good {
    color: #34d399;
}

.stat-value.bad {
    color: #f87171;
}

.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 13px;
}

.stats-table th,
.stats-table td {
    padding: 7px 10px;
    text-align: left;
    border-bottom: 1px solid #374151;
}

.stats-table th {
    color: #9ca3af;
    font-weight: 600;
}

.stats-table .num {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.stats-table .bar {
    height: 6px;
    background: #374151;
    border-radius: 3px;
    overflow: hidden;
    min-width: 80px;
}

.stats-table .bar > div {
    height: 100%;
    background: #2563eb;
}

/* =========================
   钢琴容器
========================= */

.piano-panel {
    background: #1f2937;
    border: 1px solid #374151;
    border-radius: 14px;
    padding: 18px;
}

.piano-title {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.piano-title-left {
    font-size: 15px;
    font-weight: 600;
}

.piano-title-right {
    color: #9ca3af;
    font-size: 12px;
}

/* =========================
   钢琴键盘
========================= */

.piano-scroll {
    width: 100%;
    overflow-x: auto;
    overflow-y: hidden;
    padding-bottom: 8px;
}

.piano {
    position: relative;
    display: flex;
    align-items: flex-start;
    height: 250px;
    min-width: 1250px;
    user-select: none;
    -webkit-user-select: none;
    touch-action: none;
}

.white-key {
    position: relative;
    flex: 1 1 0;
    height: 250px;
    min-width: 13px;
    background: linear-gradient(to right, #f9fafb 0%, #ffffff 45%, #e5e7eb 100%);
    border-left: 1px solid #9ca3af;
    border-bottom: 3px solid #9ca3af;
    border-radius: 0 0 5px 5px;
    cursor: pointer;
    transition: background 0.05s, transform 0.05s;
}

.white-key:last-child {
    border-right: 1px solid #9ca3af;
}

.white-key:hover {
    background: #e5e7eb;
}

.white-key.active {
    background: linear-gradient(to bottom, #bfdbfe, #60a5fa);
    transform: translateY(2px);
    border-bottom-width: 1px;
}

.white-key-label {
    position: absolute;
    bottom: 9px;
    left: 50%;
    transform: translateX(-50%);
    color: #374151;
    font-size: 10px;
    pointer-events: none;
    white-space: nowrap;
}

.white-key-label.octave {
    font-weight: 700;
    color: #111827;
}

/* 黑键位置由 JS 按白键真实几何计算 */
.black-key {
    position: absolute;
    top: 0;
    height: 155px;
    background: linear-gradient(to right, #111111 0%, #303030 45%, #080808 100%);
    border: 1px solid #050505;
    border-top: none;
    border-radius: 0 0 5px 5px;
    z-index: 10;
    cursor: pointer;
    box-shadow: 0 4px 5px rgba(0, 0, 0, 0.55);
    transition: background 0.05s, transform 0.05s;
}

.black-key:hover {
    background: linear-gradient(to right, #222, #444, #111);
}

.black-key.active {
    background: linear-gradient(to right, #2563eb, #60a5fa, #1d4ed8);
    transform: translateY(2px);
    box-shadow: 0 2px 3px rgba(0, 0, 0, 0.45);
}

/* =========================
   快捷键提示
========================= */

.keyboard-help {
    margin-top: 15px;
    color: #9ca3af;
    font-size: 12px;
    line-height: 1.8;
}

kbd {
    display: inline-block;
    padding: 1px 6px;
    margin: 0 2px;
    border: 1px solid #4b5563;
    border-radius: 4px;
    background: #111827;
    color: #d1d5db;
    font-family: monospace;
}

/* =========================
   响应式
========================= */

@media (max-width: 900px) {
    .app {
        padding: 12px;
    }

    .interval-grid,
    .answer-grid {
        grid-template-columns: repeat(4, 1fr);
    }

    .title h1 {
        font-size: 24px;
    }
}

@media (max-width: 550px) {
    .interval-grid,
    .answer-grid {
        grid-template-columns: repeat(3, 1fr);
    }

    .direction-row {
        width: 100%;
    }

    .direction-btn {
        flex: 1;
    }

    .delay-row {
        flex-wrap: wrap;
    }

    .delay-row input[type="range"] {
        width: 100%;
    }
}
