:root {
    --mute-active-bg: #5b9aff;
    --control-bar-bg: #f0f0f0;
    --track-bg: #ffffff;
    --button-bg: #e0e0e0;
    --button-active-bg: #a0a0a0;
    --solo-active-bg: #ffd700;
    --text-color: #333;
    --border-color: #ccc;
    --icon-color: #555;
    --meter-bar-color-default: #4caf50;
    --meter-bg-color: #e0e0e0;
    --mobile-fader-thumb-color: #ff797f;
    --download-active-bg: #1b3c1c;
    --download-active-bg2: #4caf50;
}

.button-container {
    margin-top: 20px;
    display: flex;
    gap: 10px;
}

/* ... (省略: loading-overlay, playback-controls, waveform-container スタイルは変更なし) ... */
#loading-overlay {
    position: fixed;
    inset: 0;
    background-color: rgba(255, 255, 255, 0.9);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 2000;
    transition: opacity 0.5s ease-out;
}

#loading-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

#loading-progress {
    opacity: 0;
    width: 80%;
    max-width: 300px;
    margin-top: 10px;
}

#loading-progress.show{
    opacity: 1;
}

/* --- ミキサー --- */
#mixer {
    min-height: 408px;
    margin: 0 auto;
    padding: 5px;
    display: grid;
    grid-template-columns: repeat(auto-fit, 110px); /* ← 修正後 */
    justify-content: center; /* ← 追加（トラック全体が中央に寄ります）*/
    gap: 4px;
    
}

.track {
    max-width: 110px;
    margin: 0;
    background-color: var(--track-bg);
    border: 1px solid var(--border-color);
    border-radius: 5px;
    padding: 10px;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

.track-info {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 15px;
    text-align: center;
    min-height: 4em;
    mix-blend-mode: multiply;
}

/* ... (省略: track-icon, icon-placeholder, track-name スタイルは変更なし) ... */
.track-icon {
    display: inline-block;
    width: 90px;
    height: 90px;
    border-radius: 5px;
    vertical-align: middle;
    margin-bottom: 10px;
    fill: var(--icon-color);
}

.icon-placeholder {
    display: inline-flex;
    justify-content: center;
    align-items: center;
    width: 90px;
    height: 90px;
    border: 1px dashed #ccc;
    border-radius: 4px;
    font-size: 1.2em;
    color: #ccc;
    vertical-align: middle;
    margin-bottom: 10px;
    box-sizing: border-box;
}

.track-name {
    font-weight: bold;
    word-break: break-word;
    font-size: .8rem;
}


/* --- デスクトップ用: フェーダーとメーター重ね合わせ --- */
.track-controls {
    position: relative;
    /* 絶対配置の基準 */
    width: 100%;
    /* 幅を確保 */
    height: 150px;
    /* 高さを確保 (フェーダー回転後+α) */
    display: flex;
    justify-content: center;
    align-items: center;
    /* 中央揃え */
    margin-bottom: 15px;
}

/* レベルメーター (背景として配置) */
.level-meter {
    position: absolute;
    width: 14px;
    /* フェーダーのトラックと同じ幅 */
    height: 120px;
    /* フェーダーのトラックと同じ長さ */
    background-color: var(--meter-bg-color);
    /* 背景色 */
    border-radius: 3px;
    overflow: hidden;
    z-index: 1;
    /* フェーダーの後ろ */
}

.level-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    width: 100%;
    height: 0%;
    /* JSで高さを制御 */
    background-color: var(--meter-bar-color, var(--meter-bar-color-default));
    transition: height 0.05s linear;
}

/* フェーダー (メーターの上に配置) */
/* フェーダー (メーターの上に配置) */
.fader {
    appearance: none;
    -webkit-appearance: none;
    width: 120px; /* 長さ */
    height: 16px; /* つまみの高さに合わせる */
    cursor: pointer;
    background-color: transparent; /* 背景は透明 */
    transform-origin: center center;
    transform: rotate(-90deg); /* 横向きに回転 */
    position: absolute;
    z-index: 2; /* メーターの上 */
    margin: 0;
}

/* Webkit トラック (透明にする) */
.fader::-webkit-slider-runnable-track {
    width: 100%;
    height: 6px;
    background: transparent;
    border: none;
    border-radius: 3px;
}

/* Webkit つまみ */
.fader::-webkit-slider-thumb {
    appearance: none;
    -webkit-appearance: none;
    width: 20px; /* つまみの幅 */
    height: 20px; /* つまみの高さ */
    background: linear-gradient(to bottom, #e0e0e0, #c0c0c0); /* フラットなグラデーション */
    border: 2px solid #888; /* 外枠 */
    border-radius: 50%; /* 丸い形状 */
    cursor: pointer;
    margin-top: -7px; /* トラック中央に配置 */
}

/* Firefox トラック (透明にする) */
.fader::-moz-range-track {
    width: 100%;
    height: 6px;
    background: transparent;
    border: none;
    border-radius: 3px;
}

/* Firefox つまみ */
.fader::-moz-range-thumb {
    width: 20px; /* つまみの幅 */
    height: 20px; /* つまみの高さ */
    background: linear-gradient(to bottom, #e0e0e0, #c0c0c0); /* フラットなグラデーション */
    border: 2px solid #888; /* 外枠 */
    border-radius: 50%; /* 丸い形状 */
    cursor: pointer;
}

/* --- ボタン --- */
.buttons {
    display: flex;
    gap: 10px;
    /* margin-top は .track-controls で設定 */
}

/* ... (省略: ボタンのスタイルは変更なし) ... */
.solo-button,
.mute-button,
.download-button {
    border: 1px solid var(--border-color);
    background-color: var(--button-bg);
    border-radius: 4px;
    font-weight: bold;
    cursor: pointer;
    width: 40px;
    height: 30px;
    display: flex;
    justify-content: center;
    align-items: center;
}

.download-button{
    width: 90px;
    height: 30px;
    margin: 10px 0 0 0;
}

.solo-button:hover,
.mute-button:hover,
.download-button:hover {
    scale: 1.2;
    background-color: #d0d0d0;
    box-shadow: 1px 2px 1px rgba(0, 0, 0, 0.3);
}

.download-button.downloaded{
    background-color: var(--icon-color);
    color: #aaa;
    border-color: var(--icon-color);
}

.download-button.downloaded:hover {
    background-color: var(--download-active-bg2);
    color: #fff;
}

.download-button.downloaded2:hover{
    background-color: #fff;
    color: var(--icon-color);
    border-color: var(--icon-color);
}

.solo-button[aria-pressed="true"] {
    background-color: var(--solo-active-bg);
    color: #fff;
    border-color: var(--solo-active-bg);
    box-shadow: none;
}

.mute-button[aria-pressed="true"] {
    background-color: var(--mute-active-bg);
    color: #fff;
    border-color: var(--mute-active-bg);
    box-shadow: none;
}

#goTermas{
    text-align: center;
}

#goTermas a{
    font-size: 0.8em;
    color: crimson;
    text-decoration: underline;
}

#goTermas a:hover{
    font-size: 1em;
    color: #fff;
    background-color: crimson;
    text-decoration: underline;
    padding: 2px 0px 2px 7px;
}


/* --- スマホ向けスタイル --- */
@media (max-width: 768px) {

    .container{
        flex-direction: column;
    }

    #readArea{
        width: 100%;
        margin: 3rem auto 0 auto;
    }

    #mixer {
        margin: 55px auto 0 auto;
        display: flex;
        flex-direction: column;
        gap: 10px;
        padding: 0;
        min-height: 0;
        height: fit-content;
    }

    /* --- モバイル用 トラックレイアウト --- */
    .track {
        max-width: 100%;
        margin: 0;
        display: flex;
        flex-direction: row;
        justify-content: space-between;
        align-items: center;
        padding: 10px 15px 10px 10px;
        position: relative;
        /* 子要素の絶対配置基準 */
        min-height: 44px;
        /* 最小高さを確保 */
        gap: 15px;
        /* 要素間のスペース */
        border: 1px solid var(--border-color);
        /* 画像に合わせて枠線を表示 */
        border-radius: 5px;
        /* 画像に合わせて角丸 */
        background-color: transparent;
        /* 画像に合わせて背景色を設定 */
    }

    .track-info {
        display: flex;
        /* 維持 */
        flex-direction: row;
        align-items: center;
        margin-bottom: 0;
        text-align: left;
        /* flex-grow: 1; ←削除 */
        margin-right: 0;
        /* gapで管理するため削除 */
        min-height: initial;
        /* order指定は不要 */
        position: relative;
        /* z-indexを使う場合 */
        z-index: 2;
        /* コントロール類より手前 */
    }

    .track-icon {
        width: 46px;
        height: 46px;
        margin-bottom: 0;
        margin-right: 10px;
    }

    .icon-placeholder {
        width: 46px;
        height: 46px;
        margin-bottom: 0;
        margin-right: 10px;
        font-size: 1em;
    }

    .track-name {
        font-weight: bold;
        word-break: break-word;
        font-size: 1rem;
        margin-top: 5px;
    }


    /* --- モバイル用: コントロール（メーターとフェーダー）エリア --- */
    .track-controls {
        position: absolute;
        top: 0;
        left: 0;
        width: 100%;
        /* 親要素いっぱいの幅 */
        height: 100%;
        /* トラックの高さに合わせるか、固定値を設定 */
        flex-grow: 1;
        /* 利用可能なスペースを埋める */
        margin-bottom: 0;
        /* マージンリセット */
        overflow: hidden;
        /* z-index, pointer-events は削除（子要素で制御） */
        /* top, left は不要 */
    }

    /* レベルメーター (横向き、背景として) */
    .level-meter {
        position: absolute;
        /* .track-controls 内で絶対配置 */
        top: 50%;
        left: 0;
        width: 100%;
        /* 親要素(.track-controls)いっぱいの幅 */
        background-color: var(--track-bg);
        /* 背景色 */
        border-radius: 3px;
        /* 角丸 */
        overflow: hidden;
        z-index: -1;
        /* フェーダーより後ろ */
        pointer-events: none;
        /* クリック等のイベントを無効化 */
        transform: translateY(-50%);
        /* background-color: var(--track-bg); ← 削除 */
    }

    /* レベルバー (横向き) */
    .level-bar {
        position: absolute;
        /* 維持 */
        bottom: auto;
        top: 0;
        left: 0;
        /* 維持 */
        width: 0%;
        /* JSで幅を制御 */
        height: 100%;
        /* メーターの高さに合わせる */
        background-color: var(--meter-bar-color, var(--meter-bar-color-default));
        /* 維持 */
        transition: width 0.05s linear;
        /* 維持 */
    }

    /* フェーダー (横向き、メーターの上に重ねる透明な操作レイヤー) */
    .fader {
        appearance: none;
        -webkit-appearance: none;
        /* 維持 */
        display: block;
        /* 維持 */
        position: absolute;
        /* .track-controls 内で絶対配置 */
        top: 0;
        left: 0;
        width: 100%;
        /* 親要素(.track-controls)いっぱいの幅 */
        height: 100%;
        /* 親要素(.track-controls)いっぱいの高さ（操作領域）*/
        transform: rotate(0deg);
        /* 回転解除 */
        background-color: transparent;
        /* 背景は透明に */
        z-index: 2;
        /* レベルメーターより手前 */
        pointer-events: auto;
        /* 操作可能にする */
        margin: 0;
        /* マージンリセット */
        cursor: pointer;
        /* カーソル形状 */
        /* order: 2; ←削除 */
    }

    /* モバイル用 フェーダー トラック (透明にする) */
    .fader::-webkit-slider-runnable-track {
        width: 100%;
        height: 100%;
        /* 高さいっぱいにして操作しやすく */
        background: transparent;
        /* 透明 */
        border: none;
        border-radius: 0;
    }

    .fader::-moz-range-track {
        width: 100%;
        height: 100%;
        background: transparent;
        border: none;
        border-radius: 0;
    }

    /* モバイル用 フェーダー つまみ (赤い縦線) */
    .fader::-webkit-slider-thumb {
        appearance: none;
        -webkit-appearance: none;
        /* 維持 */
        width: 7px;
        /* 細い幅 */
        height: 100px;
        /* 高さを指定（親要素より高くても可）*/
        background: var(--mobile-fader-thumb-color);
        /* 赤色 */
        border: none;
        border-radius: 0;
        /* 四角く */
        cursor: pointer;
        /* 維持 */
        /* 垂直中央揃えのためのマージン調整 */
        /* margin-top: -7px; の代わりに以下を試す */
        position: relative;
        /* margin相殺のため */
        top: 50%;
        transform: translateY(-50%);
        /* つまみ自身の高さの中央を親要素の中央に合わせる */
    }

    .fader::-moz-range-thumb {
        width: 7px;
        height: 100px;
        background: var(--mobile-fader-thumb-color);
        border: none;
        border-radius: 0;
        cursor: pointer;
        /* Firefoxは通常、垂直中央揃えは不要なことが多い */
    }


    /* ボタン */
    .buttons {
        display: flex;
        /* 維持 */
        gap: 8px;
        /* 維持 */
        margin-top: 0;
        /* 維持 */
        /* order: 3; ←削除 */
        position: relative;
        /* z-indexのため */
        z-index: 2;
        /* 情報エリアやフェーダーと同等かそれ以上 */
    }

    .solo-button,
    .mute-button {
        width: 40px;
        height: 40px;
        font-size: 0.9em;
        /* pointer-events: auto; (デフォルト) */
    }

    .download-button {
        display: none;
    }

    #goTermas{
        display: none;
    }
}