/* ============================================================
   プレイリストエディタ (PlaylistEditor)
   ※すべてのスタイルを playlist-editor 配下に限定
   ============================================================ */

#tab-playlist .playlist-editor-component {
    display: flex;
    flex-direction: column;
    border: 1px solid var(--border-color);
    border-radius: 12px;
    padding: 16px;
    background-color: var(--bg-secondary);
    overflow-y: hidden;
    transition: background-color 0.3s, border-color 0.3s;
}

#tab-playlist .playlist-editor-component #playlist-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex-grow: 1;
    margin-top: 10px;
    overflow-y: auto;
    min-height: 0;
    padding-right: 4px;
}


#tab-playlist .playlist-editor-component .playlist-editor-container {
    display: flex;
    flex-direction: column;
    gap: 12px;
}


#tab-playlist .playlist-editor-component .input-area {
    display: flex;
    gap: 8px;
    align-items: center;
    width: 100%;
}

#tab-playlist .playlist-editor-component #playlist-url-input {
    flex-grow: 1;
    padding: 8px 12px;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 14px;
    background-color: var(--bg-card);
    color: var(--text-color);
}

playlist-editor #playlist-add-url-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

playlist-editor #playlist-status {
    font-size: 12px;
    color: var(--text-muted-color);
    min-height: 1.2em;
    margin-left: 8px;
}

/* --- コントロールエリア --- */
playlist-editor .controls-area {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: nowrap;
}

playlist-editor #playlist-play-all-btn {
    flex-shrink: 0;
    white-space: nowrap;
}
playlist-editor #playlist-play-all-btn.playing {
    background-color: var(--danger-color);
    color: white;
}

/* ズームコントロール */
playlist-editor #timeline-zoom-slider-container {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 12px;
    color: var(--text-muted-color);
    margin-left: auto;
}

playlist-editor #timeline-zoom-slider-container label {
    white-space: nowrap;
}

playlist-editor #timeline-zoom-input {
    width: 50px !important;
    padding: 4px 6px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    text-align: center;
    background-color: var(--bg-card);
    color: var(--text-color);
}

/* 高度な設定トグル */
playlist-editor .advanced-settings-toggle {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 14px;
    color: var(--text-muted-color);
    flex-shrink: 0;
    white-space: nowrap;
}
playlist-editor .advanced-settings-toggle label {
    cursor: pointer;
    user-select: none;
    color: var(--text-muted-color);
}

/* --- タイムラインエリア --- */
playlist-editor #playlist-timeline-wrapper {
    overflow-x: auto;
    padding: 10px 0;
    border: 2px solid var(--border-color); 
    background-color: var(--bg-card);
    border-radius: 8px;
    position: relative;
    scroll-behavior: smooth;
    transition: background-color 0.3s, border-color 0.3s;
    margin-bottom: 0;
}

playlist-editor #playlist-timeline {
    position: relative;
    min-height: 65px;
}

/* ▼▼▼ 修正: ここから下も全て playlist-editor を付与してスコープ化 ▼▼▼ */

playlist-editor .timeline-track {
    position: absolute;
    display: flex;
    flex-direction: column;
    border-radius: 4px;
    cursor: grab;
    overflow: hidden;
    height: 60px !important; 
    border: 1px solid var(--border-color);
}
playlist-editor .timeline-track:active {
    cursor: grabbing;
    z-index: 10;
    border-color: var(--primary-color);
}

playlist-editor .waveform-container {
    height: 40px;
    background-color: var(--bg-hover);
    transition: background-color 0.3s;
}

playlist-editor .track-text-block {
    height: 20px;
    background-color: var(--primary-color);
    color: white;
    padding: 0 8px;
    font-size: 11px;
    display: flex;
    align-items: center;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex-shrink: 0;
}

/* --- メモリ & 再生ヘッド --- */
playlist-editor #timeline-ruler { 
    height: 20px; 
    margin-bottom: 5px; 
    font-size: 10px; 
    color: var(--text-muted-color); 
    user-select: none; 
}

playlist-editor .ruler-tick { 
    position: absolute; 
    top: 0; 
    width: 1px; 
    background: #aaa; 
}
playlist-editor .ruler-tick.major { 
    height: 10px; 
    background: var(--text-color); 
}
playlist-editor .ruler-label { 
    position: absolute; 
    top: 8px; 
    transform: translateX(-50%); 
    color: var(--text-muted-color);
}

playlist-editor #timeline-playhead { 
    position: absolute; 
    top: 0; 
    left: 0; 
    width: 2px; 
    height: 100%; 
    background: rgba(255,0,0,0.7); 
    z-index: 100; 
    pointer-events: none; 
    display: none; 
}

/* --- プレースホルダー --- */
playlist-editor #playlist-placeholder {
    text-align: center;
    padding: 2rem;
    border: 2px dashed var(--border-color);
    border-radius: 8px;
    color: var(--text-muted-color);
    background-color: transparent;
}

/* --- プレイリスト内音声カード --- */
playlist-editor .player-card {
    position: relative;
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 12px;
    background-color: var(--bg-card);
    display: flex;
    flex-direction: column;
    gap: 10px;
    transition: background-color 0.3s, border-color 0.3s;
    text-align: left;
    align-items: stretch;
}

playlist-editor .card-owner-info {
    display: flex;
    justify-content: space-between;
    font-size: 0.85em;
    color: var(--text-muted-color);
}
playlist-editor .card-owner-info .model-name {
    font-weight: bold;
}

playlist-editor .card-text {
    margin: 8px 0;
    color: var(--text-color);
    word-break: break-all;
    font-size: 0.95em;
}

playlist-editor .custom-audio-player {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    height: auto;
    min-height: 32px;
    padding-bottom: 2px;
}

playlist-editor .play-pause-btn {
    width: 28px !important;
    height: 28px !important;
}

playlist-editor .play-pause-btn svg {
    width: 16px;
    height: 16px;
}

playlist-editor .time-display {
    font-size: 11px;
    min-width: 55px;
}

playlist-editor .volume-control,
playlist-editor .start-time-control {
    gap: 4px;
}

playlist-editor .volume-control svg,
playlist-editor .start-time-control svg {
    width: 16px;
    height: 16px;
    fill: var(--text-muted-color);
}

playlist-editor .volume-slider {
    width: 100px !important;
}

playlist-editor .btn-delete {
    position: static;
    width: 24px !important;
    height: 24px !important;
    font-size: 14px;
    padding: 0;
    display: flex;
    align-items: center;
    justify-content: center;
}

playlist-editor .play-pause-btn {
    background: var(--bg-hover);
    border: 1px solid var(--border-color);
    border-radius: 50%;
    width: 36px !important;
    height: 36px !important;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    padding: 0;
    flex-shrink: 0;
    transition: background-color 0.2s;
}
playlist-editor .play-pause-btn:hover {
    background-color: var(--bg-secondary);
}
playlist-editor .play-pause-btn svg { width: 20px; height: 20px; }
playlist-editor .play-icon, playlist-editor .pause-icon { fill: var(--text-color); }

playlist-editor .progress-wrapper {
    flex-grow: 1;
    height: 8px;
    background-color: var(--bg-secondary);
    border-radius: 4px;
    cursor: pointer;
    overflow: hidden;
    min-width: 40px;
    border: 1px solid var(--border-color);
}
playlist-editor .progress-bar {
    width: 0%;
    height: 100%;
    background-color: var(--primary-color);
    border-radius: 4px;
    transition: width 0.1s linear;
}

playlist-editor .time-display {
    font-size: 0.8em;
    color: var(--text-muted-color);
    min-width: 65px;
    text-align: center;
    flex-shrink: 0;
}

playlist-editor .volume-control, 
playlist-editor .start-time-control {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.85em;
    color: var(--text-muted-color);
}

/* 数値入力のスピンボタンを非表示 */
playlist-editor input[type="number"]::-webkit-outer-spin-button,
playlist-editor input[type="number"]::-webkit-inner-spin-button {
    -webkit-appearance: none;
    margin: 0;
}
playlist-editor input[type="number"] {
    -moz-appearance: textfield;
}

playlist-editor .volume-control input[type="number"] {
    width: 48px !important;
    padding: 2px 4px;
    border-radius: 4px;
    text-align: center;
    border: 1px solid var(--border-color);
    background-color: var(--bg-card);
    color: var(--text-color);
    font-size: 14px;
    font-weight: 500;
}

playlist-editor .start-time-control input {
     width: 52px !important;
     padding: 2px 4px;
     border-radius: 4px;
     background-color: var(--bg-card);
     color: var(--text-color);
     border: 1px solid var(--border-color);
     text-align: center;
     font-size: 14px;
    font-weight: 500;
}

playlist-editor .btn-delete {
    position: absolute;
    top: 8px;
    right: 8px;
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.1rem;
    padding: 4px;
    color: var(--text-muted-color);
    width: auto !important;
}
playlist-editor .btn-delete:hover {
    color: var(--danger-color);
}

/* 表示制御クラス */
playlist-editor .playlist-editor-container.hide-advanced #playlist-timeline-wrapper,
playlist-editor .playlist-editor-container.hide-advanced .start-time-control,
playlist-editor .playlist-editor-container.hide-advanced #timeline-zoom-slider-container {
    display: none;
}

/* 再生/停止アイコン切り替え */
playlist-editor .play-pause-btn .play-icon { display: block; }
playlist-editor .play-pause-btn .pause-icon { display: none; }
playlist-editor .play-pause-btn.is-playing .play-icon { display: none; }
playlist-editor .play-pause-btn.is-playing .pause-icon { display: block; }

/* ダークモードでの微調整 (変数が効かない箇所のみ) */
body.dark-mode playlist-editor .ruler-tick {
    background: #666;
}
body.dark-mode playlist-editor .ruler-tick.major {
    background: #ccc;
}