/* --- Base Player Layout --- */
.midnight-player {
    position: fixed;
    bottom: 0;
    left: 0;
    width: 100%;
    background: #1a1a1a;
    color: #e0e0e0;
    z-index: 9999;
    border-top: 1px solid rgba(255, 183, 77, 0.1);
    box-shadow: 0 -5px 20px rgba(0,0,0,0.5);
    display: none;
}

.m-content {
    max-width: 900px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    padding: 12px 20px;
    gap: 15px;
}

.m-track-info { flex: 1; overflow: hidden; }
.m-title {
    font-size: 0.9rem;
    color: #ffb74d;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    margin-bottom: 4px;
}

/* --- Progress Bar ชุดหลัก --- */
.m-progress-group { display: flex; align-items: center; gap: 10px; }
.m-slider {
    flex: 1;
    height: 4px;
    background: #333;
    border-radius: 2px;
    position: relative;
    cursor: pointer;
}
.m-fill { height: 100%; background: #ffb74d; border-radius: 2px; width: 0; }
.m-time { font-size: 0.7rem; color: #888; min-width: 35px; }

/* --- ปุ่มควบคุมหลัก --- */
.m-play-btn {
    background: #ffb74d;
    color: #1a1a1a;
    border: none;
    width: 44px; height: 44px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    box-shadow: 0 4px 10px rgba(255, 183, 77, 0.3);
}

/* --- Full Screen Queue Panel --- */
.m-queue-panel {
    position: fixed;
    bottom: -100%;
    left: 0;
    width: 100%;
    height: 100%; /* เปิดเต็มหน้าจอ */
    background: #121212;
    z-index: 10000;
    transition: bottom 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
}

.m-queue-panel.show { bottom: 0; }

.m-queue-header {
    padding: 20px;
    display: flex; justify-content: space-between; align-items: center;
    background: #1a1a1a;
    color: #ffb74d;
}

.m-queue-list { flex: 1; overflow-y: auto; padding: 10px 0; }

/* --- แผงควบคุมในคิว (ออกแบบใหม่ตามต้องการ) --- */
.m-queue-player-ui {
    background: #1a1a1a;
    padding: 30px 20px;
    padding-bottom: calc(30px + env(safe-area-inset-bottom));
}

.m-q-progress-container { margin-bottom: 25px; }

.m-q-time-row {
    display: flex; justify-content: space-between;
    font-size: 12px; color: #ffb74d; margin-bottom: 10px;
}

.m-q-slider {
    width: 100%; height: 6px; background: #333;
    border-radius: 3px; position: relative; cursor: pointer;
}

.m-q-fill { height: 100%; background: #ffb74d; border-radius: 3px; }

.m-q-thumb {
    width: 14px; height: 14px; background: #fff;
    border: 2px solid #ffb74d; border-radius: 50%;
    position: absolute; top: 50%; transform: translate(-50%, -50%);
}

.m-q-slider {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
}

.m-q-fill { height: 100%; background: #ffb74d; border-radius: 3px; }

.m-q-thumb {
    cursor: grab;
    transition: transform 0.1s ease; 
}

.m-q-thumb:active {
    cursor: grabbing;
    transform: translate(-50%, -50%) scale(1.3); 
}
/* กล่องแสดงเวลาตอนลาก (Tooltip) */
.m-q-tooltip {
    position: absolute;
    bottom: 40px; /* ลอยเหนือนิ้ว/ปุ่ม Thumb */
    left: 0;
    transform: translateX(-50%);
    background: #ffb74d;
    color: #1a1a1a;
    padding: 4px 10px;
    border-radius: 6px;
    font-size: 14px;
    font-weight: bold;
    display: none; /* ซ่อนไว้ก่อน */
    pointer-events: none;
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    z-index: 10001;
}

/* เพิ่มสามเหลี่ยมชี้ลงด้านล่าง */
.m-q-tooltip::after {
    content: "";
    position: absolute;
    top: 100%;
    left: 50%;
    transform: translateX(-50%);
    border-width: 6px;
    border-style: solid;
    border-color: #ffb74d transparent transparent transparent;
}

/* ปรับให้ Thumb ขยายใหญ่ขึ้นเล็กน้อยขณะลากเพื่อความเด่น */
.m-q-thumb.dragging {
    transform: translate(-50%, -50%) scale(1.4);
    background: #ffb74d;
}

.m-q-controls {
    display: flex; 
    justify-content: space-between;
    align-items: center; 
    max-width: 360px; /* เพิ่มความกว้างเล็กน้อยเพื่อให้ 4 ปุ่มไม่เบียดกัน */
    margin: 0 auto;
    gap: 10px;
}

/* แก้ไอคอนเบี้ยวด้วยการใช้ปุ่มข้อความสไตล์ Minimal */
.m-btn-text {
    background: rgba(255, 255, 255, 0.05);
    color: #fff;
    border: 1px solid #333;
    padding: 10px 18px;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    min-width: 80px;
    text-align: center;
    transition: 0.2s;
}

.m-btn-text:hover { background: #333; border-color: #ffb74d; }

.m-speed-tag {
    background: #ffb74d;
    color: #1a1a1a;
    border: none;
    padding: 6px 14px; /* ลดจาก 10px 25px */
    border-radius: 20px;
    font-size: 0.85rem; /* ลดขนาดตัวอักษรเล็กน้อย */
    font-weight: bold;
    cursor: pointer;
    min-width: 55px;
}

/* --- ส่วนที่เพิ่ม/แก้ไขเพื่อจัดการสีไอคอน --- */

/* บังคับสีทองให้กับปุ่มไอคอนที่กำหนดคลาส m-btn-gold */
.m-btn-gold.material-symbols-outlined {
    color: #ffb74d !important; /* สีทองตามธีม */
    background: none;
    border: none;
    cursor: pointer;
    transition: transform 0.2s ease, opacity 0.2s ease;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ปุ่มเปิดคิวในหน้าหลัก */
.m-icon-btn.m-btn-gold {
    font-size: 28px; /* ขนาดพอดีกับแถบด้านล่าง */
}

/* ปุ่มพับคิวในหน้าเต็มจอ */
.m-close-btn.m-btn-gold {
    font-size: 36px; /* ใหญ่ขึ้นเล็กน้อยเพื่อให้กดง่ายในโหมดเต็มจอ */
    padding: 0;
    margin: 0;
}

/* เอฟเฟกต์เมื่อ Hover */
.m-btn-gold:hover {
    opacity: 0.8;
    transform: scale(1.1);
}

.m-btn-gold:active {
    transform: scale(0.95);
}

/* ปรับปรุง Header ของหน้าต่างคิว */
.m-queue-header {
    padding: 15px 20px;
    display: flex; 
    justify-content: space-between; 
    align-items: center;
    background: #1a1a1a;
    color: #ffb74d;
    border-bottom: 1px solid rgba(255, 183, 77, 0.1); /* เส้นแบ่งจางๆ สีทอง */
}

.m-queue-header span {
    font-size: 1.1rem;
    font-weight: bold;
}

/* ปุ่มข้อความในแผงควบคุมคิว (ปรับสีตัวหนังสือเป็นสีทองเพื่อให้เข้าธีมมากขึ้น) */
.m-btn-text {
    background: rgba(255, 255, 255, 0.05);
    color: #ffb74d; /* เปลี่ยนจากขาวเป็นทอง */
    border: 1px solid rgba(255, 183, 77, 0.2);
    padding: 10px 18px;
    border-radius: 12px;
    font-weight: bold;
    cursor: pointer;
    min-width: 80px;
    text-align: center;
    transition: 0.2s;
}

.m-btn-text:hover {
    background: rgba(255, 183, 77, 0.1);
    border-color: #ffb74d;
}

/* --- สิ้นสุดส่วนที่เพิ่ม/แก้ไข --- */

/* --- สไตล์ของรายการในคิว --- */
.m-queue-item {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    gap: 15px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    position: relative;
    overflow: hidden;
}

.m-queue-progress-bar {
    position: absolute;
    bottom: 0;
    left: 0;
    height: 3px;
    background: #007bff;
    border-radius: 0 2px 0 0;
    transition: width 0.5s linear;
    pointer-events: none;
}

.m-queue-item:hover {
    background: rgba(255, 183, 77, 0.05);
}

/* ลำดับตัวเลข */
.m-item-index {
    font-size: 14px;
    color: #555;
    min-width: 20px;
    font-family: monospace;
}

/* ข้อมูลเพลง */
.m-item-info {
    flex: 1; /* กินพื้นที่ตรงกลางทั้งหมด */
    display: flex;
    flex-direction: column;
}

.m-item-right {
    display: flex;
    align-items: center;
    gap: 8px;
    text-align: right;
}

.m-item-title {
    font-size: 0.95rem;
    color: #e0e0e0;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.m-item-sale-type {
    font-size: 0.75rem;
    color: #ffb74d; /* สีส้มทองให้เด่น */
    font-weight: bold;
    min-width: auto; /* กันเนื้อหาขยับไปมา */
}

.m-status-icon:empty {
    display: none;
}

.m-item-meta {
    font-size: 0.7rem;
    color: #666;
}

/* สถานะไอคอน */
.m-status-icon {
    font-size: 20px !important;
    min-width: 24px;
}

/* สถานะกำลังเล่น (Active) */
.m-queue-item.active {
    background: rgba(255, 183, 77, 0.1);
}

.m-queue-item.active .m-item-title,
.m-queue-item.active .m-item-index,
.m-queue-item.active .m-status-icon {
    color: #ffb74d !important; /* สีส้มทอง */
}

/* สถานะล็อค */
.m-queue-item.locked {
    opacity: 0.6;
}

.m-queue-item.locked .m-item-meta {
    color: #ffb74d; /* เน้นราคาสีทอง */
}


/* --- สถานะ Loading สำหรับปุ่มเล่น --- */
.m-play-btn.loading {
    position: relative;
    pointer-events: none; /* ป้องกันการกดซ้ำขณะโหลด */
}

/* สร้างวงแหวนหมุนรอบขอบปุ่ม */
.m-play-btn.loading::after {
    content: "";
    position: absolute;
    top: -5px;   /* ขยับออกมานอกปุ่มเล็กน้อย */
    left: -5px;
    right: -5px;
    bottom: -5px;
    border: 3px solid rgba(255, 183, 77, 0.1); /* สีจางๆ เป็นฐาน */
    border-top: 3px solid #ffb74d;            /* สีทองเข้มสำหรับส่วนที่หมุน */
    border-radius: 50%;
    animation: m-spin 0.8s linear infinite;
}

/* แอนิเมชันการหมุน */
@keyframes m-spin {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

/* คอนเทนเนอร์สำหรับแท่ง Equalizer */
.eq-animation {
    display: flex;
    align-items: flex-end;
    gap: 2px;
    width: 20px;
    height: 18px;
}

/* สไตล์ของแต่ละแท่ง */
.eq-bar {
    background: #ffb74d;
    width: 3px;
    height: 100%;
    animation: eq-bounce 0.8s ease-in-out infinite;
}

/* กำหนดความหน่วงเพื่อให้แต่ละแท่งขยับไม่พร้อมกัน */
.eq-bar:nth-child(1) { animation-delay: -0.4s; }
.eq-bar:nth-child(2) { animation-delay: -0.2s; }
.eq-bar:nth-child(3) { animation-delay: -0.6s; }

/* แอนิเมชันการขยับ */
@keyframes eq-bounce {
    0%, 100% { height: 4px; }
    50% { height: 18px; }
}

/* หยุดขยับเมื่อเพลงหยุด (Paused) */
.m-queue-item.active.paused .eq-bar {
    animation-play-state: paused;
    height: 4px;
}

/* จัดการกล่องข้อมูลตอนในคิว */
.m-item-info {
    flex: 1;
    min-width: 0; /* สำคัญมาก: เพื่อให้ flex-child ยอมหดตัว */
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

/* แก้ไขชื่อตอนให้ตัดคำด้วยจุดไข่ปลา */
.m-item-title {
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: block;
    width: 100%;
    font-size: 0.9rem;
}

/* --- Speed Picker Popup --- */
.m-speed-picker {
    display: none;
    flex-wrap: wrap;
    justify-content: center;
    gap: 8px;
    padding: 14px 10px;
    margin-bottom: 16px;
    background: #222;
    border-radius: 14px;
    border: 1px solid rgba(255, 183, 77, 0.2);
    animation: m-fade-in 0.15s ease;
}

@keyframes m-fade-in {
    from { opacity: 0; transform: translateY(6px); }
    to   { opacity: 1; transform: translateY(0); }
}

.m-speed-option {
    background: rgba(255, 255, 255, 0.05);
    color: #ccc;
    border: 1px solid #333;
    padding: 8px 14px;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: bold;
    cursor: pointer;
    transition: 0.15s;
    min-width: 58px;
    text-align: center;
}

.m-speed-option:hover {
    background: rgba(255, 183, 77, 0.15);
    border-color: #ffb74d;
    color: #ffb74d;
}

.m-speed-option.active {
    background: #ffb74d;
    color: #1a1a1a;
    border-color: #ffb74d;
}

/* ป้องกันรายการคิวดีดตัวออกนอกกรอบ */
.m-queue-item {
    display: flex;
    align-items: center;
    gap: 10px;
    width: 100%;
    box-sizing: border-box;
    overflow: hidden; /* ป้องกันเนื้อหาภายในดัน Layout */
}