:root {
    color-scheme: light;
    --bg: #ffffff;
    --surface: #ffffff;
    --surface-soft: #fafafa;
    --ink: #0f0f10;
    --ink-soft: #6b6b70;
    --line: #d4d4d4;
    --line-strong: #c0c0c0;
    --accent: #2f4ad0;
    --accent-soft: #eef1fc;
    --ok: #1f9d55;
    --ok-soft: #e7f6ec;
    --bad: #c53030;
    --bad-soft: #fdecec;
    --shadow-card: 0 8px 24px -12px rgba(15, 15, 16, 0.18);
    --shadow-focus: 0 0 0 4px rgba(15, 15, 16, 0.06);
    --shadow-toplink: 0 4px 14px -6px rgba(15, 15, 16, 0.12);
    --piano-white: #f8f8f8;
    --piano-white-border: #c8c8c8;
    --piano-white-active: #d0d8f0;
    --piano-black: #1a1a1a;
    --piano-black-active: #3a3a6a;
}

[data-theme="dark"] {
    color-scheme: dark;
    --bg: #0c0c0e;
    --surface: #141418;
    --surface-soft: #1c1c21;
    --ink: #f5f5f7;
    --ink-soft: #9b9ba3;
    --line: #2e2e35;
    --line-strong: #44444c;
    --accent: #7c8fff;
    --accent-soft: #1c2244;
    --ok: #4ade80;
    --ok-soft: #102a1a;
    --bad: #f87171;
    --bad-soft: #2c1414;
    --shadow-card: 0 8px 24px -8px rgba(0, 0, 0, 0.6);
    --shadow-focus: 0 0 0 4px rgba(124, 143, 255, 0.18);
    --shadow-toplink: 0 4px 14px -6px rgba(0, 0, 0, 0.6);
    --piano-white: #e8e8e8;
    --piano-white-border: #888888;
    --piano-white-active: #4a5a8a;
    --piano-black: #222222;
    --piano-black-active: #4a4a7a;
}

*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html, body {
    height: 100%;
    overflow: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Inter", "Helvetica Neue", Helvetica, Arial, sans-serif;
    font-size: 16px;
    line-height: 1.55;
    letter-spacing: -0.005em;
    -webkit-font-smoothing: antialiased;
    background: var(--bg);
    color: var(--ink);
}

.tonejs-wrapper {
    display: flex;
    flex-direction: column;
    height: 100vh;
    width: 100%;
}

.tonejs-toolbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 52px;
    padding: 0 16px;
    background: var(--surface);
    border-bottom: 1px solid var(--line);
    flex-shrink: 0;
    z-index: 100;
}

.toolbar-back {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 600;
    color: var(--ink-soft);
    text-decoration: none;
    transition: background 0.15s, color 0.15s, border-color 0.15s;
    border: 1px solid transparent;
}

.toolbar-back:hover,
.toolbar-back:focus-visible {
    background: var(--accent-soft);
    color: var(--accent);
    border-color: var(--accent);
    outline: 0;
}

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

.toolbar-icon {
    display: inline-grid;
    place-items: center;
    width: 32px;
    height: 32px;
    border-radius: 8px;
    background: var(--accent-soft);
    color: var(--accent);
    font-size: 16px;
}

.toolbar-title {
    font-size: 18px;
    font-weight: 700;
    letter-spacing: -0.025em;
}

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

.toolbar-tag {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 4px 10px;
    border-radius: 999px;
    border: 1px solid var(--line);
    font-size: 12px;
    font-weight: 600;
    color: var(--ink-soft);
    letter-spacing: 0.02em;
}

.theme-toggle {
    display: inline-grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border: 1px solid var(--line);
    border-radius: 50%;
    background: var(--surface-soft);
    color: var(--ink);
    cursor: pointer;
    font-size: 14px;
    padding: 0;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
}

.theme-toggle:hover,
.theme-toggle:focus-visible {
    background: var(--accent-soft);
    border-color: var(--accent);
    color: var(--accent);
    outline: 0;
}

.theme-toggle-icon {
    display: none;
}

[data-theme="dark"] .theme-toggle-icon-light {
    display: inline-block;
}

:root:not([data-theme="dark"]) .theme-toggle-icon-dark {
    display: inline-block;
}

.tonejs-main {
    flex: 1;
    overflow-y: auto;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 24px 16px;
}

.keyboard-container {
    width: 100%;
    max-width: 960px;
    display: flex;
    flex-direction: column;
    gap: 20px;
}

.controls {
    display: flex;
    flex-wrap: wrap;
    gap: 20px;
    padding: 16px;
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: 14px;
}

.control-group {
    display: flex;
    align-items: center;
    gap: 8px;
}

.control-label {
    font-size: 13px;
    font-weight: 600;
    color: var(--ink-soft);
    white-space: nowrap;
}

.control-select {
    height: 40px;
    padding: 0 12px;
    border: 1px solid var(--line-strong);
    border-radius: 10px;
    background: var(--surface);
    color: var(--ink);
    font: inherit;
    font-size: 14px;
    cursor: pointer;
}

.control-select:focus {
    border-color: var(--accent);
    box-shadow: var(--shadow-focus);
    outline: 0;
}

.control-slider {
    width: 100px;
    height: 6px;
    -webkit-appearance: none;
    appearance: none;
    background: var(--line);
    border-radius: 3px;
    cursor: pointer;
}

.control-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: var(--accent);
    cursor: pointer;
}

.control-value {
    font-size: 13px;
    color: var(--ink-soft);
    min-width: 50px;
}

.info-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 12px;
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 12px;
    min-height: 48px;
}

.note-display {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.025em;
    color: var(--accent);
}

.freq-display {
    font-size: 14px;
    color: var(--ink-soft);
}

.piano-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.piano {
    display: flex;
    position: relative;
    height: 220px;
    min-width: 840px;
    user-select: none;
    -webkit-user-select: none;
    background: #111;
    border-radius: 0 0 10px 10px;
    padding: 0 2px 4px 2px;
    box-shadow: 0 6px 20px rgba(0,0,0,0.3);
}

.piano .white-key {
    flex: 1;
    background: var(--piano-white);
    border: 1px solid var(--piano-white-border);
    border-top: none;
    border-radius: 0 0 6px 6px;
    cursor: pointer;
    position: relative;
    z-index: 1;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 12px;
    font-size: 11px;
    font-weight: 600;
    color: var(--ink-soft);
    transition: background 0.06s;
    margin-left: -1px;
}

.piano .white-key:first-child {
    margin-left: 0;
}

.piano .white-key:hover {
    background: var(--piano-white-active);
}

.piano .white-key.active {
    background: var(--piano-white-active);
    box-shadow: inset 0 -4px 8px rgba(0,0,0,0.08);
}

.piano .black-key {
    position: absolute;
    top: 0;
    width: 4%;
    height: 62%;
    background: var(--piano-black);
    border: 1px solid #000;
    border-top: none;
    border-radius: 0 0 5px 5px;
    cursor: pointer;
    z-index: 2;
    display: flex;
    align-items: flex-end;
    justify-content: center;
    padding-bottom: 8px;
    font-size: 9px;
    font-weight: 600;
    color: rgba(255,255,255,0.5);
    transition: background 0.06s;
    box-shadow: 0 4px 6px rgba(0,0,0,0.4), inset 0 -2px 4px rgba(0,0,0,0.3);
}

.piano .black-key:hover {
    background: var(--piano-black-active);
}

.piano .black-key.active {
    background: var(--piano-black-active);
    box-shadow: 0 2px 3px rgba(0,0,0,0.4), inset 0 1px 2px rgba(0,0,0,0.2);
    height: 60%;
}

.shortcuts-info {
    text-align: center;
    font-size: 13px;
    color: var(--ink-soft);
    padding: 8px;
}

.shortcuts-info i {
    margin-right: 4px;
}

@media (max-width: 760px) {
    .toolbar-back span {
        display: none;
    }

    .toolbar-tag {
        display: none;
    }

    .toolbar-title {
        font-size: 16px;
    }

    .controls {
        flex-direction: column;
        gap: 12px;
    }

    .control-group {
        width: 100%;
        justify-content: space-between;
    }

    .piano {
        height: 180px;
        min-width: 700px;
    }

    .shortcuts-info {
        display: none;
    }
}
