/* ==========================================
   SUIREN AUDIO - Design System
   Studio機材風・モダンダークテーマ
   ========================================== */

/* === CSS Custom Properties (Design Tokens) === */
:root {
    /* カラーパレット - 青緑系ダークテーマ */
    --bg-deepest: #0a1214;
    --bg-deep: #121a1c;
    --bg-panel: #1a2426;
    --bg-elevated: #222e30;
    --bg-hover: #2a3638;

    /* ボーダー */
    --border-subtle: #2a3638;
    --border-normal: #3a4648;
    --border-active: #4ecdc4;

    /* アクセントカラー */
    --accent-primary: #4ecdc4;
    --accent-glow: rgba(78, 205, 196, 0.15);
    --accent-glow-strong: rgba(78, 205, 196, 0.3);

    /* ステータスカラー */
    --status-ok: #00e5cc;
    --status-warn: #ffb347;
    --status-error: #ff6b6b;
    --status-record: #ff5252;

    /* テキスト */
    --text-primary: #e8edef;
    --text-secondary: #8a9a9e;
    --text-muted: #5a6a6e;
    --text-accent: #4ecdc4;

    /* フォント */
    --font-display: 'Outfit', 'Inter', -apple-system, BlinkMacSystemFont, sans-serif;
    --font-body: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
    --font-mono: 'JetBrains Mono', 'SF Mono', 'Consolas', monospace;
    --font-label: 'Inter', -apple-system, sans-serif;

    /* サイズ */
    --header-height: 52px;
    --audio-panel-height: 50px;
    --sidebar-width: 0px;
    --sidebar-expanded: 200px;
    --sidebar-icons-only: 56px;

    /* パネル */
    --panel-bg: #151e20;
    --panel-header: #1a2426;
    --min-panel-width: 180px;
    --min-panel-height: 140px;

    /* スプリッター */
    --splitter-size: 4px;
    --splitter-color: #2a3638;
    --splitter-hover: var(--accent-primary);

    /* スペーシング */
    --space-xs: 4px;
    --space-sm: 8px;
    --space-md: 16px;
    --space-lg: 24px;
    --space-xl: 32px;

    /* タッチターゲット */
    --touch-min: 44px;

    /* トランジション */
    --transition-fast: 120ms ease-out;
    --transition-normal: 200ms ease-out;
    --transition-slow: 300ms ease-out;

    /* シャドウ */
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.3);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.4);
    --shadow-lg: 0 8px 24px rgba(0, 0, 0, 0.5);
    --shadow-glow: 0 0 20px var(--accent-glow);

    /* ボーダー半径 */
    --radius-sm: 4px;
    --radius-md: 6px;
    --radius-lg: 10px;
    --radius-full: 9999px;
}

/* === Reset & Base === */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html,
body {
    height: 100%;
    height: 100dvh;
    /* Safari用の動的ビューポート高さ */
    overflow: hidden;
    background: var(--bg-deepest);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 14px;
    line-height: 1.5;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    /* iOS safe area対応 */
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
}

/* アニメーション軽減設定 */
@media (prefers-reduced-motion: reduce) {

    *,
    *::before,
    *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
}

/* === Typography === */
.font-display {
    font-family: var(--font-display);
    font-weight: 600;
    letter-spacing: 0.02em;
}

.font-mono {
    font-family: var(--font-mono);
    font-weight: 500;
}

/* === Header === */
.app-header {
    height: var(--header-height);
    background: linear-gradient(180deg, var(--bg-panel) 0%, var(--bg-deep) 100%);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 var(--space-md);
    flex-shrink: 0;
    position: relative;
    z-index: 100;
}

.header-left {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

/* ダウンロード進捗インジケーター */
.download-indicator {
    display: none;
    align-items: center;
    gap: 8px;
    padding: 4px 12px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    font-size: 11px;
    color: var(--text-secondary);
    white-space: nowrap;
    animation: fadeIn 0.3s ease-out;
}

.download-indicator.visible {
    display: flex;
}

.download-indicator.offline {
    border-color: var(--status-warn);
    background: rgba(255, 179, 71, 0.1);
}

.download-indicator.offline .download-text {
    color: var(--status-warn);
}

.download-indicator.complete {
    border-color: var(--status-ok);
    background: rgba(0, 229, 204, 0.1);
}

.download-indicator.complete .download-text {
    color: var(--status-ok);
}

.download-spinner {
    width: 12px;
    height: 12px;
    border: 2px solid var(--border-subtle);
    border-top-color: var(--accent-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.download-indicator.offline .download-spinner,
.download-indicator.complete .download-spinner {
    display: none;
}

.download-indicator.offline::before {
    content: '⚠️';
    font-size: 12px;
}

.download-indicator.complete::before {
    content: '✓';
    font-size: 12px;
    color: var(--status-ok);
}

.download-progress-bar {
    width: 40px;
    height: 4px;
    background: var(--bg-deep);
    border-radius: 2px;
    overflow: hidden;
}

.download-indicator.offline .download-progress-bar,
.download-indicator.complete .download-progress-bar {
    display: none;
}

.download-progress-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--accent-primary), #6ee7df);
    border-radius: 2px;
    transition: width 0.3s ease-out;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateX(-10px); }
    to { opacity: 1; transform: translateX(0); }
}

.drawer-trigger {
    width: var(--touch-min);
    height: var(--touch-min);
    background: transparent;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

.drawer-trigger:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.drawer-trigger:active {
    transform: scale(0.95);
}

.drawer-trigger svg {
    width: 20px;
    height: 20px;
}

/* メニューアイコンのアニメーション */
.menu-line {
    transition: all var(--transition-normal);
    transform-origin: center;
}

.drawer-trigger.open .menu-line-1 {
    transform: translateY(6px) rotate(45deg);
}

.drawer-trigger.open .menu-line-2 {
    opacity: 0;
    transform: scaleX(0);
}

.drawer-trigger.open .menu-line-3 {
    transform: translateY(-6px) rotate(-45deg);
}

.brand-logo {
    display: flex;
    align-items: baseline;
    gap: var(--space-xs);
    user-select: none;
}

.brand-icon {
    font-size: 1.25rem;
    margin-right: var(--space-xs);
}

.brand-name {
    font-family: var(--font-display);
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--accent-primary);
    letter-spacing: 0.08em;
}

.brand-suffix {
    font-family: var(--font-display);
    font-size: 0.7rem;
    font-weight: 500;
    color: var(--text-muted);
    letter-spacing: 0.1em;
}

.brand-version {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
    margin-left: var(--space-sm);
    padding: 2px 6px;
    background: var(--bg-deep);
    border-radius: var(--radius-sm);
    border: 1px solid var(--border-subtle);
}

.header-center {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
}

.status-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) var(--space-md);
    background: var(--bg-deep);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-normal);
    min-height: 32px;
}

.status-indicator:hover {
    border-color: var(--accent-primary);
    box-shadow: var(--shadow-glow);
}

.status-dot {
    width: 8px;
    height: 8px;
    background: var(--text-muted);
    border-radius: 50%;
    transition: all var(--transition-normal);
}

.status-indicator.mic-ready .status-dot {
    background: var(--status-ok);
    box-shadow: 0 0 8px var(--status-ok);
    animation: pulse-dot 2s infinite;
}

.status-indicator.file-mode .status-dot {
    background: var(--status-warn);
    box-shadow: 0 0 8px var(--status-warn);
}

.status-indicator.ensemble-mode .status-dot {
    background: #ff9800;
    box-shadow: 0 0 8px #ff9800;
    animation: pulse-dot 1.5s infinite;
}

@keyframes pulse-dot {

    0%,
    100% {
        opacity: 1;
        transform: scale(1);
    }

    50% {
        opacity: 0.6;
        transform: scale(0.9);
    }
}

.status-text {
    font-family: var(--font-label);
    font-size: 0.75rem;
    color: var(--text-secondary);
    white-space: nowrap;
}

.header-right {
    display: flex;
    align-items: center;
    gap: var(--space-md);
}

.mode-indicator {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: var(--bg-elevated);
    border-radius: var(--radius-md);
    font-size: 0.75rem;
}

.mode-icon {
    font-size: 1rem;
}

.mode-text {
    font-family: var(--font-label);
    color: var(--text-secondary);
}

.mode-indicator.ensemble .mode-text {
    color: #ff9800;
}

/* === Global Audio Panel === */
.global-audio-panel {
    background: var(--bg-deep);
    border-bottom: 1px solid var(--border-subtle);
    padding: var(--space-sm) var(--space-md);
    flex-shrink: 0;
    /* プリセットドロップダウン表示のため */
    overflow: visible;
    position: relative;
    z-index: 50;
}

.audio-controls-row {
    display: flex;
    align-items: center;
    gap: var(--space-md);
    /* 絶対に1行、改行禁止 */
    flex-wrap: nowrap !important;
    white-space: nowrap;
    /* 横スクロール有効 */
    overflow-x: auto;
    overflow-y: visible;
    -webkit-overflow-scrolling: touch;
    /* スクロールバー非表示 */
    scrollbar-width: none;
    -ms-overflow-style: none;
    /* プリセットドロップダウン用にパディング追加 */
    padding-bottom: 4px;
}

.audio-controls-row::-webkit-scrollbar {
    display: none;
}

/* ドロワー開閉ボタン */
.drawer-open-btn {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
    padding: var(--space-xs) var(--space-sm);
    background: var(--accent-primary);
    border: none;
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.drawer-open-btn:hover {
    background: var(--accent-hover);
    transform: scale(1.02);
}

.drawer-open-btn:active {
    transform: scale(0.98);
}

.drawer-open-icon {
    font-size: 1rem;
    font-weight: 700;
    color: var(--bg-deepest);
    line-height: 1;
}

.drawer-open-label {
    font-family: var(--font-label);
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--bg-deepest);
    letter-spacing: 0.02em;
}

.drawer-open-btn.open {
    background: var(--status-error);
}

.drawer-open-btn.open .drawer-open-icon {
    transform: rotate(45deg);
}

/* パネルセクション */
.panel-section {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    padding: var(--space-xs) 0;
    flex-shrink: 0;
}

.section-label {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.1em;
    min-width: 40px;
}

.panel-divider {
    width: 1px;
    height: 28px;
    background: var(--border-subtle);
    margin: 0 var(--space-sm);
    flex-shrink: 0;
}

/* コントロールグループ */
.control-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    flex-shrink: 0;
}

.control-item {
    display: flex;
    align-items: center;
    gap: var(--space-xs);
}

.label-text {
    font-family: var(--font-mono);
    font-size: 0.65rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* 数値入力 */
.global-audio-panel input[type="number"] {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-family: var(--font-mono);
    font-size: 0.85rem;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    width: 60px;
    text-align: center;
    transition: all var(--transition-fast);
    -moz-appearance: textfield;
    appearance: textfield;
}

.global-audio-panel input[type="number"]::-webkit-outer-spin-button,
.global-audio-panel input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}

.global-audio-panel input[type="number"]:hover {
    border-color: var(--border-normal);
}

.global-audio-panel input[type="number"]:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

/* セレクト */
.global-audio-panel select {
    background: var(--bg-panel);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    font-family: var(--font-body);
    font-size: 0.8rem;
    padding: var(--space-xs) var(--space-sm);
    padding-right: var(--space-lg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238a9a9e' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
}

.global-audio-panel select:hover {
    border-color: var(--border-normal);
}

.global-audio-panel select:focus {
    outline: none;
    border-color: var(--accent-primary);
}

/* ボタン */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-xs);
    background: var(--bg-panel);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    font-family: var(--font-label);
    font-size: 0.75rem;
    font-weight: 500;
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    white-space: nowrap;
    min-height: 32px;
    user-select: none;
}

.btn:hover {
    background: var(--bg-hover);
    border-color: var(--border-normal);
}

.btn:active {
    transform: scale(0.97);
}

.btn.active {
    background: var(--accent-primary);
    color: var(--bg-deepest);
    border-color: var(--accent-primary);
}

.icon-btn {
    width: 36px;
    height: 36px;
    padding: 0;
    font-size: 1rem;
    border-radius: var(--radius-md);
}

/* 録音ボタン */
.record-btn {
    color: var(--status-record);
    border-color: rgba(255, 82, 82, 0.3);
}

.record-btn:hover {
    background: rgba(255, 82, 82, 0.1);
    border-color: var(--status-record);
}

.record-btn.recording {
    background: rgba(255, 82, 82, 0.2);
    border-color: var(--status-record);
    animation: pulse-record 1s infinite;
}

@keyframes pulse-record {

    0%,
    100% {
        box-shadow: 0 0 0 0 rgba(255, 82, 82, 0.4);
    }

    50% {
        box-shadow: 0 0 0 8px rgba(255, 82, 82, 0);
    }
}

/* ファイルボタン */
.file-btn {
    cursor: pointer;
}

.file-btn input[type="file"] {
    display: none;
}

/* モードスイッチ */
.mode-switch {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    user-select: none;
}

.mode-switch input {
    display: none;
}

.mode-switch .slider {
    width: 36px;
    height: 20px;
    background: var(--bg-elevated);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-full);
    position: relative;
    transition: all var(--transition-normal);
}

.mode-switch .slider::after {
    content: '';
    position: absolute;
    width: 14px;
    height: 14px;
    background: var(--text-muted);
    border-radius: 50%;
    top: 2px;
    left: 3px;
    transition: all var(--transition-normal);
}

.mode-switch input:checked+.slider {
    background: var(--accent-primary);
    border-color: var(--accent-primary);
}

.mode-switch input:checked+.slider::after {
    left: 17px;
    background: var(--bg-deepest);
}

.mode-label {
    font-family: var(--font-label);
    font-size: 0.7rem;
    color: var(--text-muted);
}

/* Practice Mode Switch */
.practice-mode-switch {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    cursor: pointer;
    user-select: none;
}

.practice-mode-switch input {
    display: none;
}

.practice-mode-label {
    font-family: var(--font-label);
    font-size: 0.7rem;
    font-weight: 500;
    transition: all var(--transition-normal);
}

.practice-mode-label.solo-label {
    color: var(--accent-primary);
}

.practice-mode-label.ensemble-label {
    color: var(--text-muted);
}

.practice-mode-switch input:checked~.solo-label {
    color: var(--text-muted);
}

.practice-mode-switch input:checked~.ensemble-label {
    color: #ff9800;
}

.practice-slider {
    width: 40px;
    height: 22px;
    background: var(--accent-primary);
    border-radius: var(--radius-full);
    position: relative;
    transition: all var(--transition-normal);
}

.practice-slider::after {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    background: white;
    border-radius: 50%;
    top: 3px;
    left: 3px;
    transition: all var(--transition-normal);
    box-shadow: var(--shadow-sm);
}

.practice-mode-switch input:checked+.practice-slider {
    background: #ff9800;
}

.practice-mode-switch input:checked+.practice-slider::after {
    left: 21px;
}

/* ノイズキャリブレーション */
.noise-cal-btn {
    background: linear-gradient(135deg, var(--bg-panel) 0%, var(--bg-elevated) 100%);
    border: 1px solid var(--border-subtle);
    color: var(--text-secondary);
    font-size: 0.7rem;
    padding: var(--space-xs) var(--space-sm);
    transition: all var(--transition-fast);
}

.noise-cal-btn:hover {
    border-color: var(--accent-primary);
    color: var(--accent-primary);
}

.noise-cal-btn.calibrating {
    background: linear-gradient(135deg, #f72585 0%, #b5179e 100%);
    border-color: #f72585;
    color: #fff;
    animation: pulse-noise 1s infinite;
}

.noise-cal-btn.active {
    background: linear-gradient(135deg, #4361ee 0%, #3a0ca3 100%);
    border-color: #4361ee;
    color: #fff;
}

@keyframes pulse-noise {

    0%,
    100% {
        opacity: 1;
    }

    50% {
        opacity: 0.6;
    }
}

.noise-status {
    font-family: var(--font-mono);
    font-size: 0.6rem;
    padding: 2px 6px;
    border-radius: var(--radius-sm);
    background: rgba(255, 100, 100, 0.15);
    color: #ff6b6b;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

.noise-status.active {
    background: rgba(100, 255, 100, 0.15);
    color: #51cf66;
}

/* 楽器選択 */
.instrument-select {
    background: var(--bg-panel);
    color: var(--text-primary);
    border: 1px solid var(--border-subtle);
    font-family: var(--font-body);
    font-size: 0.75rem;
    padding: var(--space-xs) var(--space-sm);
    padding-right: var(--space-lg);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 12 12'%3E%3Cpath fill='%238a9a9e' d='M6 8L2 4h8z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 8px center;
    min-width: 110px;
}

.instrument-select:hover {
    border-color: var(--accent-primary);
}

.instrument-select:focus {
    outline: none;
    border-color: var(--accent-primary);
    box-shadow: 0 0 0 2px var(--accent-glow);
}

.instrument-select optgroup {
    font-weight: 600;
    color: var(--text-muted);
    background: var(--bg-deep);
}

.instrument-select option {
    background: var(--bg-panel);
    color: var(--text-primary);
    padding: 4px 8px;
}

/* プレーヤー */
.player-compact {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    margin-left: auto;
    flex-shrink: 0;
    padding-left: var(--space-md);
    border-left: 1px solid var(--border-subtle);
}

.player-compact.disabled {
    opacity: 0.4;
    pointer-events: none;
}

.icon-btn-sm {
    width: 30px;
    height: 30px;
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    border-radius: 50%;
    font-size: 0.75rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all var(--transition-fast);
}

.icon-btn-sm:hover {
    background: var(--bg-hover);
    border-color: var(--accent-primary);
}

.time-sm {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    color: var(--text-muted);
    min-width: 36px;
    text-align: center;
}

/* レンジスライダー */
.global-audio-panel input[type="range"] {
    -webkit-appearance: none;
    appearance: none;
    height: 4px;
    background: var(--bg-elevated);
    border-radius: 2px;
    cursor: pointer;
    flex: 1;
    min-width: 80px;
    max-width: 150px;
}

.global-audio-panel input[type="range"]::-webkit-slider-thumb {
    -webkit-appearance: none;
    width: 14px;
    height: 14px;
    background: var(--text-primary);
    border-radius: 50%;
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-sm);
}

.global-audio-panel input[type="range"]::-webkit-slider-thumb:hover {
    transform: scale(1.1);
    background: var(--accent-primary);
}

.global-audio-panel input[type="range"]::-moz-range-thumb {
    width: 14px;
    height: 14px;
    background: var(--text-primary);
    border: none;
    border-radius: 50%;
    cursor: pointer;
}

.volume-sm {
    width: 60px !important;
    min-width: 60px !important;
}

.rate-sm {
    width: 55px;
    font-size: 0.7rem !important;
    padding: 2px 4px !important;
}

/* === Preset System === */
.preset-group {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    position: relative;
}

.preset-name-input {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.75rem;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    width: 100px;
    transition: all var(--transition-fast);
}

.preset-name-input::placeholder {
    color: var(--text-muted);
}

.preset-name-input:focus {
    outline: none;
    border-color: var(--accent-primary);
}

.preset-dropdown {
    position: relative;
}

.preset-list {
    display: none;
    position: fixed;
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    min-width: 220px;
    max-height: 300px;
    overflow-y: auto;
    z-index: 9999;
    box-shadow: var(--shadow-lg);
}

.preset-list.open {
    display: block;
}

.preset-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: var(--space-sm) var(--space-md);
    border-bottom: 1px solid var(--border-subtle);
    transition: background var(--transition-fast);
}

.preset-item:last-child {
    border-bottom: none;
}

.preset-item:hover {
    background: var(--bg-hover);
}

.preset-item-name {
    font-family: var(--font-body);
    font-size: 0.8rem;
    color: var(--text-primary);
    cursor: pointer;
    flex: 1;
    padding: var(--space-xs) 0;
    transition: color var(--transition-fast);
}

.preset-item-name:hover {
    color: var(--accent-primary);
}

.preset-item-delete {
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    font-size: 0.75rem;
    padding: var(--space-xs) var(--space-sm);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.preset-item-delete:hover {
    background: rgba(255, 82, 82, 0.15);
    color: var(--status-error);
}

.preset-empty {
    padding: var(--space-md);
    text-align: center;
    color: var(--text-muted);
    font-size: 0.75rem;
}

/* === Main Layout === */
.app-body {
    display: flex;
    flex: 1;
    overflow: hidden;
    /* ヘッダーとオーディオパネルの高さを引いた正確な高さ */
    height: calc(100vh - var(--header-height) - var(--audio-panel-height, 50px));
    min-height: 0;
    position: relative;
}

/* === Module Drawer（オーバーレイ表示） === */
.module-drawer {
    position: absolute;
    top: 0;
    left: 0;
    bottom: 0;
    width: 0;
    min-width: 0;
    background: var(--bg-deep);
    border-right: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    transition: width var(--transition-slow), opacity var(--transition-fast);
    z-index: 150;
    overflow: hidden;
    box-shadow: var(--shadow-lg);
}

.module-drawer.icons-only {
    width: var(--sidebar-icons-only);
    min-width: var(--sidebar-icons-only);
}

.module-drawer.expanded {
    width: var(--sidebar-expanded);
    min-width: var(--sidebar-expanded);
}

/* ドラッグ中はドロワーを非表示 */
.module-drawer.hide-on-drag {
    opacity: 0;
    pointer-events: none;
}

.drawer-toggle {
    position: absolute;
    right: -12px;
    top: 50%;
    transform: translateY(-50%);
    width: 24px;
    height: 48px;
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-left: none;
    border-radius: 0 var(--radius-md) var(--radius-md) 0;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 151;
    transition: all var(--transition-fast);
}

.drawer-toggle:hover {
    background: var(--bg-hover);
}

.toggle-icon {
    font-size: 0.6rem;
    color: var(--text-muted);
    transition: transform var(--transition-slow);
}

.module-drawer.expanded .toggle-icon {
    transform: rotate(180deg);
}

.module-drawer.icons-only .toggle-icon {
    transform: rotate(180deg);
}

/* ドロワーが完全に閉じた状態 */
.module-drawer:not(.expanded):not(.icons-only) .drawer-toggle {
    right: -12px;
}

.module-drawer:not(.expanded):not(.icons-only) .drawer-content {
    opacity: 0;
    visibility: hidden;
}

.drawer-content {
    display: flex;
    flex-direction: column;
    height: 100%;
    overflow: hidden;
    opacity: 1;
    visibility: visible;
    transition: opacity var(--transition-normal), visibility var(--transition-normal);
}

.drawer-header {
    padding: var(--space-md) var(--space-sm);
    font-family: var(--font-mono);
    font-size: 0.6rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.15em;
    border-bottom: 1px solid var(--border-subtle);
    opacity: 0;
    transition: opacity var(--transition-normal);
    text-align: center;
}

.module-drawer.expanded .drawer-header {
    opacity: 1;
}

.module-list {
    padding: var(--space-sm);
    display: flex;
    flex-direction: column;
    gap: var(--space-xs);
    overflow-y: auto;
}

.module-card {
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-sm) var(--space-md);
    cursor: grab;
    transition: all var(--transition-fast);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    min-height: var(--touch-min);
}

.module-card:hover {
    border-color: var(--accent-primary);
    background: var(--bg-hover);
    box-shadow: var(--shadow-glow);
}

.module-card:active {
    cursor: grabbing;
    transform: scale(0.98);
}

.module-card.dragging {
    opacity: 0.5;
}

.module-icon {
    font-size: 1.3rem;
    flex-shrink: 0;
}

.module-name {
    font-family: var(--font-label);
    font-size: 0.8rem;
    color: var(--text-primary);
    white-space: nowrap;
    opacity: 0;
    transition: opacity var(--transition-normal);
    overflow: hidden;
    text-overflow: ellipsis;
}

.module-drawer.expanded .module-name {
    opacity: 1;
}

/* === Workspace === */
.workspace {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: var(--bg-deepest);
}

.layout-root {
    width: 100%;
    height: 100%;
    display: flex;
}

.workspace-empty {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    text-align: center;
    color: var(--text-muted);
    pointer-events: none;
    z-index: 5;
}

.workspace-empty.hidden {
    display: none;
}

.empty-icon {
    font-size: 4rem;
    opacity: 0.2;
    margin-bottom: var(--space-md);
}

.empty-text {
    font-family: var(--font-body);
    font-size: 0.9rem;
    opacity: 0.6;
}

/* === Drop Zones === */
.drop-zones {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 100;
    display: none;
}

.drop-zones.active {
    display: block;
    pointer-events: auto;
}

/* ワークスペースが空の時の全体ドロップエリア */
.drop-zone.zone-center {
    position: absolute;
    inset: 24px;
    /* エッジゾーンの分を除く */
    background: transparent;
    transition: all var(--transition-fast);
}

.drop-zone.zone-center.highlight {
    background: var(--accent-glow-strong);
    border: 2px dashed var(--accent-primary);
    border-radius: var(--radius-lg);
}

/* エッジドロップゾーン（当たり判定は大きく、表示はライン） */
.drop-zone.zone-edge {
    position: absolute;
    background: transparent;
    transition: all var(--transition-fast);
}

.drop-zone.zone-edge.highlight {
    background: linear-gradient(var(--accent-primary), var(--accent-primary));
    box-shadow: 0 0 16px var(--accent-primary), 0 0 32px var(--accent-glow);
}

/* エッジゾーンのサイズ（当たり判定は大きく） */
.zone-top {
    top: 0;
    left: 0;
    right: 0;
    height: 24px;
}

.zone-top.highlight {
    height: 6px;
}

.zone-bottom {
    bottom: 0;
    left: 0;
    right: 0;
    height: 24px;
}

.zone-bottom.highlight {
    height: 6px;
}

.zone-left {
    top: 0;
    bottom: 0;
    left: 0;
    width: 24px;
}

.zone-left.highlight {
    width: 6px;
}

.zone-right {
    top: 0;
    bottom: 0;
    right: 0;
    width: 24px;
}

.zone-right.highlight {
    width: 6px;
}

/* ワークスペースが空の時のセンターゾーン */
.zone-center {
    inset: 5%;
    border-radius: var(--radius-lg);
}

/* === Split Container === */
.split-container {
    display: flex;
    flex: 1;
    min-width: 0;
    min-height: 0;
}

.split-container.horizontal {
    flex-direction: row;
}

.split-container.vertical {
    flex-direction: column;
}

/* === Splitter === */
.splitter {
    background: var(--splitter-color);
    flex-shrink: 0;
    transition: background var(--transition-fast), box-shadow var(--transition-fast);
    position: relative;
    z-index: 10;
}

.splitter:hover,
.splitter.active {
    background: var(--splitter-hover);
}

/* スプリッターがドロップターゲットの時 */
.splitter.drop-target {
    background: var(--accent-primary);
    box-shadow: 0 0 16px var(--accent-primary);
    z-index: 101;
}

.splitter.horizontal {
    width: var(--splitter-size);
    cursor: col-resize;
}

.splitter.vertical {
    height: var(--splitter-size);
    cursor: row-resize;
}

/* === Module Panel === */
.module-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-subtle);
    display: flex;
    flex-direction: column;
    position: relative;
    min-width: var(--min-panel-width);
    min-height: var(--min-panel-height);
    flex: 1;
    overflow: hidden;
    border-radius: var(--radius-sm);
    transition: opacity var(--transition-normal), transform var(--transition-normal);
}

/* パネルがドラッグ中の時 */
.module-panel.dragging {
    opacity: 0.3;
    transform: scale(0.98);
    pointer-events: none;
}

.panel-header {
    background: var(--panel-header);
    padding: var(--space-sm) var(--space-md);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid var(--border-subtle);
    flex-shrink: 0;
    min-height: 36px;
    gap: var(--space-sm);
}

.panel-drag-handle {
    color: var(--text-muted);
    font-size: 0.9rem;
    cursor: grab;
    padding: var(--space-xs);
    letter-spacing: -2px;
    transition: color var(--transition-fast);
}

.panel-drag-handle:hover {
    color: var(--text-secondary);
}

.panel-drag-handle:active {
    cursor: grabbing;
}

.panel-title {
    font-family: var(--font-display);
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-primary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    flex: 1;
    letter-spacing: 0.02em;
}

.panel-menu-btn {
    width: 28px;
    height: 28px;
    background: transparent;
    border: none;
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-sm);
    font-size: 1rem;
    transition: all var(--transition-fast);
}

.panel-menu-btn:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

.panel-menu-btn.dragging {
    opacity: 0.5;
}

.panel-content {
    flex: 1;
    overflow: hidden;
    position: relative;
    min-height: 0;
    background: var(--bg-deepest);
}

.panel-menu {
    position: absolute;
    top: 40px;
    right: var(--space-sm);
    background: var(--bg-panel);
    border: 1px solid var(--border-subtle);
    border-radius: var(--radius-md);
    padding: var(--space-xs);
    z-index: 200;
    display: none;
    box-shadow: var(--shadow-lg);
    min-width: 140px;
}

.panel-menu.open {
    display: block;
}

.menu-item {
    display: flex;
    align-items: center;
    gap: var(--space-sm);
    width: 100%;
    padding: var(--space-sm) var(--space-md);
    background: none;
    border: none;
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.75rem;
    text-align: left;
    cursor: pointer;
    border-radius: var(--radius-sm);
    white-space: nowrap;
    transition: background var(--transition-fast);
}

.menu-item:hover {
    background: var(--bg-hover);
}

.menu-icon {
    width: 16px;
    text-align: center;
}

.delete-item:hover {
    background: rgba(255, 82, 82, 0.15);
    color: var(--status-error);
}

.delete-progress {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 2px;
    background: var(--status-error);
    width: 0;
    transition: width 0.8s linear;
}

.delete-item.deleting .delete-progress {
    width: 100%;
}

/* === Panel Drop Zones === */
.panel-drop-zones {
    position: absolute;
    inset: 0;
    pointer-events: none;
    z-index: 50;
    display: none;
}

.module-panel.drag-over .panel-drop-zones {
    display: block;
    pointer-events: auto;
}

.panel-drop-zone {
    position: absolute;
    background: transparent;
    transition: background var(--transition-fast);
}

.panel-drop-zone.highlight {
    background: var(--accent-primary);
    box-shadow: 0 0 12px var(--accent-primary);
}

/* パネル内ドロップゾーン - 当たり判定は大きく、ハイライト時はライン表示 */
.pdz-top {
    top: 0;
    left: 0;
    right: 0;
    height: 20px;
}

.pdz-top.highlight {
    height: 6px;
}

.pdz-bottom {
    bottom: 0;
    left: 0;
    right: 0;
    height: 20px;
}

.pdz-bottom.highlight {
    height: 6px;
}

.pdz-left {
    top: 0;
    bottom: 0;
    left: 0;
    width: 20px;
}

.pdz-left.highlight {
    width: 6px;
}

.pdz-right {
    top: 0;
    bottom: 0;
    right: 0;
    width: 20px;
}

.pdz-right.highlight {
    width: 6px;
}

/* === Legacy header support (元のHTML用) === */
header:not(.app-header) {
    height: var(--header-height);
    background: linear-gradient(180deg, var(--bg-panel) 0%, var(--bg-deep) 100%);
    border-bottom: 1px solid var(--border-subtle);
    display: flex;
    align-items: center;
    padding: 0 var(--space-md);
    justify-content: space-between;
    flex-shrink: 0;
}

header:not(.app-header) .brand {
    font-family: var(--font-display);
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--accent-primary);
    display: flex;
    align-items: center;
    gap: var(--space-sm);
}

header:not(.app-header) .menu-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    cursor: pointer;
    width: var(--touch-min);
    height: var(--touch-min);
    border-radius: var(--radius-md);
    transition: all var(--transition-fast);
}

header:not(.app-header) .menu-toggle:hover {
    background: var(--bg-hover);
    color: var(--text-primary);
}

header:not(.app-header) .status-badge {
    font-family: var(--font-label);
    font-size: 0.7rem;
    color: var(--text-muted);
    border: 1px solid var(--border-subtle);
    padding: var(--space-xs) var(--space-md);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all var(--transition-normal);
}

header:not(.app-header) .status-badge:hover {
    border-color: var(--accent-primary);
}

header:not(.app-header) .status-badge.mic-ready {
    color: var(--status-ok);
    border-color: var(--status-ok);
}

header:not(.app-header) .status-badge.file-mode {
    color: var(--status-warn);
    border-color: var(--status-warn);
}

header:not(.app-header) .status-badge.ensemble-mode {
    color: #ff9800;
    border-color: #ff9800;
}

/* === Mobile === */
@media (max-width: 768px) {
    .module-drawer {
        position: fixed;
        left: 0;
        top: var(--header-height);
        height: calc(100% - var(--header-height));
        transform: translateX(-100%);
        z-index: 100;
        box-shadow: var(--shadow-lg);
    }

    .module-drawer.expanded,
    .module-drawer.icons-only {
        transform: translateX(0);
    }

    header:not(.app-header) .menu-toggle,
    .drawer-trigger {
        display: flex;
    }

    .audio-controls-row {
        flex-wrap: wrap;
        gap: var(--space-sm);
    }

    .panel-divider {
        display: none;
    }

    .player-compact {
        width: 100%;
        margin-left: 0;
        padding-left: 0;
        border-left: none;
        padding-top: var(--space-sm);
        border-top: 1px solid var(--border-subtle);
    }
}

/* === Touch Device Enhancements === */
@media (pointer: coarse) {
    .splitter.horizontal {
        width: 8px;
    }

    .splitter.vertical {
        height: 8px;
    }

    .panel-menu-btn {
        width: var(--touch-min);
        height: var(--touch-min);
        font-size: 1.1rem;
    }

    .module-card {
        padding: var(--space-md);
        min-height: 52px;
    }

    .panel-drop-zone.pdz-top,
    .panel-drop-zone.pdz-bottom {
        height: 35%;
    }

    .panel-drop-zone.pdz-left,
    .panel-drop-zone.pdz-right {
        width: 35%;
    }

    .btn {
        min-height: var(--touch-min);
        padding: var(--space-sm) var(--space-md);
    }

    .icon-btn {
        width: var(--touch-min);
        height: var(--touch-min);
    }

    .preset-name-input {
        min-height: var(--touch-min);
    }
}