/* Card สำหรับ Sidebar (มืด) */
.premium-card { 
    background-color: #060b14; 
    border: 1px solid rgba(255,255,255,0.05); 
    border-radius: 1.5rem; 
    box-shadow: 0 15px 40px rgba(0,0,0,0.6); 
    overflow: hidden; 
}

/* Card สำหรับตารางผลคะแนน (สว่าง เรียบหรู) */
.results-card {
    background-color: #ffffff;
    border-radius: 1.5rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.4); 
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.1);
}
  
.twmc-table { 
    width: 100%; 
    border-collapse: separate; 
    border-spacing: 0; 
    min-width: 750px; 
}

/* 1. หัวตาราง (Place, ID, Team Name) */
.twmc-table th { 
    padding: 0.85rem 0.5rem; 
    text-align: center; 
    font-weight: 900; 
    text-transform: uppercase; 
    letter-spacing: 0.05em; 
    font-size: 0.75rem; 
    color: #f8fafc; 
    background-color: #0f172a; 
    border-bottom: 2px solid #1e293b; 
    position: relative;
    z-index: 10;
}

/* 2. แถบ Category (Subheader สีดำ) */
td.twmc-subheader,
.twmc-table tbody tr.category-row td.twmc-subheader { 
    position: relative;
    background: linear-gradient(90deg, #020617 0%, #1e293b 100%) !important; 
    color: #EAB308 !important; 
    font-weight: 900 !important; 
    font-size: 0.85rem !important; 
    text-transform: uppercase !important; 
    letter-spacing: 0.05em !important;
    text-align: left !important; 
    padding: 0.75rem 1.25rem !important; 
    border-left: 4px solid #EAB308 !important; 
    border-bottom: 1px solid #1e293b !important;
    box-shadow: inset 0 2px 5px rgba(0,0,0,0.6) !important; 
    text-shadow: 0 2px 4px rgba(0,0,0,0.5) !important;
    z-index: 1;
}

/* 3. ข้อมูลตารางพื้นขาว */
.twmc-table td { 
    padding: 0.45rem 0.5rem; 
    text-align: center; 
    font-size: 0.875rem; 
    color: #1e293b; 
    border-bottom: 1px solid #f1f5f9; 
    background-color: #ffffff; 
    transition: all 0.2s ease; 
}
.twmc-table tr:last-child td { border-bottom: none; }
.twmc-table tr.data-row:hover td { background-color: #f8fafc; color: #000; }
.twmc-table .text-left { text-align: left; display: flex; align-items: center; gap: 8px;}

/* 4. แถบ View Recap */
.recap-row td {
    background-color: #f5f3dc !important; 
    border-bottom: 1px solid #fde047 !important;
    padding: 0.35rem 0.5rem !important; 
}
.recap-row a { color: #b45309; font-size: 0.75rem; font-weight: 800; display: block; width: 100%; text-align: center; transition: 0.3s;}
.recap-row a:hover { color: #0f172a; }

/* กล่องคะแนน และ ID */
.score-badge { background-color: #0f172a; color: #fff; padding: 0.25rem 0; border-radius: 0.5rem; font-weight: 900; font-size: 0.85rem; box-shadow: 0 2px 4px rgba(0, 0, 0, 0.15); letter-spacing: 0; display: inline-flex; justify-content: center; align-items: center; width: 72px; }
.id-badge { background-color: #f8fafc; border: 1px solid #cbd5e1; padding: 0.1rem 0; border-radius: 0.25rem; color: #475569; font-size: 0.7rem; font-weight: 600; font-family: monospace; letter-spacing: 0; display: inline-flex; justify-content: center; align-items: center; width: 44px; }

/* ธงชาติ */
.twmc-table td img[src*="flag"] {
    width: 28px !important; 
    height: 18px !important;
    object-fit: contain !important; 
    border-radius: 2px !important;
    background-color: #f8fafc;
    box-shadow: 0 0 2px rgba(0,0,0,0.2);
}

/* นับอันดับ */
tbody.category-group { counter-reset: placeNum; }
.twmc-table tr.data-row { counter-increment: placeNum; }
.twmc-table tr.data-row td:first-child:empty::before { content: counter(placeNum); font-weight: 900; font-size: 1.25rem; color: #334155; }

/* ========================================= */
/* ลายน้ำ SEMI FINALS จางๆ บนพื้นขาวของแต่ละรุ่น */
/* ========================================= */
.is-semifinals .results-card > div:first-child {
    position: relative;
    overflow: hidden; /* ป้องกันลายน้ำล้นขอบการ์ด */
}
.is-semifinals .results-card > div:first-child::after {
    content: "SEMI\A FINALS"; /* ใช้ \A เพื่อบังคับขึ้น 2 บรรทัด */
    white-space: pre; /* ต้องเปิดใช้ pre เพื่อให้ \A ทำงาน */
    text-align: right;
    line-height: 0.85; /* บีบระยะห่างบรรทัดให้กระชับขึ้น */
    position: absolute;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 2.8rem; /* ปรับขนาดให้เล็กลงพอดีๆ */
    font-weight: 900;
    color: rgba(148, 163, 184, 0.15); /* สีเทาจางๆ */
    letter-spacing: 0.05em;
    pointer-events: none;
    z-index: 0;
}
/* ดันเนื้อหา (โลโก้, ตัวหนังสือ) ให้ลอยอยู่เหนือลายน้ำเสมอ */
.is-semifinals .results-card > div:first-child > * {
    position: relative;
    z-index: 10;
}

/* ========================================= */
/* ลายน้ำ FINALS จางๆ บนพื้นขาวของแต่ละรุ่น */
/* ========================================= */
.is-finals .results-card > div:first-child {
    position: relative;
    overflow: hidden; /* ป้องกันลายน้ำล้นขอบการ์ด */
}
.is-finals .results-card > div:first-child::after {
    content: "FINALS"; 
    white-space: pre; 
    text-align: right;
    line-height: 0.85; 
    position: absolute;
    right: 2rem;
    top: 50%;
    transform: translateY(-50%);
    font-size: 3.5rem; /* ปรับขนาดให้ใหญ่ขึ้นกว่า Semi เล็กน้อยเพราะมีบรรทัดเดียว */
    font-weight: 900;
    color: rgba(148, 163, 184, 0.15); /* สีเทาจางๆ */
    letter-spacing: 0.05em;
    pointer-events: none;
    z-index: 0;
}
/* ดันเนื้อหา (โลโก้, ตัวหนังสือ) ให้ลอยอยู่เหนือลายน้ำเสมอ */
.is-finals .results-card > div:first-child > * {
    position: relative;
    z-index: 10;
}

/* ========================================= */
/* Mobile Layout */
/* ========================================= */
@media (max-width: 768px) {
    .overflow-x-auto { overflow: visible !important; }
    .twmc-table { min-width: 100% !important; display: block; border-collapse: block; }
    .twmc-table thead { display: none; }
    .twmc-table tbody { display: block; width: 100%; margin-bottom: 1rem; }
    
    .twmc-table tr.category-row { 
        display: block; margin: 1.5rem 16px 0.5rem 16px; 
        border-left: none !important; padding: 0 !important; background: transparent !important;
    }
    .twmc-table tr.category-row td.twmc-subheader { 
        border-radius: 8px; text-align: left !important; border-left: 4px solid #EAB308 !important; padding: 0.35rem 1rem !important;
    }

    /* ปรับขนาดลายน้ำเวลาดูบนมือถือ (ให้อยู่ขวาเหมือนเดิมแต่เล็กหน่อย) */
    .is-semifinals .results-card > div:first-child::after {
        font-size: 1.5rem;
        right: 1rem;
        color: rgba(148, 163, 184, 0.12); /* จางลงนิดนึงเวลาอยู่บนมือถือ */
    }

    .is-finals .results-card > div:first-child::after {
        font-size: 2.2rem;
        right: 1rem;
        color: rgba(148, 163, 184, 0.12);
    }

    .twmc-table tr.data-row {
        display: grid !important;
        grid-template-columns: 50px max-content 1fr auto auto auto; 
        grid-template-areas: "place id name name name name" "place . . score level info";
        gap: 6px 10px; padding: 8px 12px; background-color: #ffffff; border: 1px solid #e2e8f0; border-radius: 12px; margin: 0 16px 10px 16px; box-shadow: 0 3px 6px -2px rgba(0,0,0,0.05); align-items: center;
    }
    .twmc-table tr.data-row:hover { background-color: #f8fafc; }
    .twmc-table tr.data-row td { border: none !important; padding: 0 !important; background: transparent !important; display: flex; align-items: center; }
    
    .twmc-table tr.data-row td:nth-child(1) { grid-area: place; justify-content: center; align-self: center;} 
    .twmc-table tr.data-row td:nth-child(1):empty::before { font-size: 1.4rem; color: #1e293b; }
    .twmc-table tr.data-row td:nth-child(2) { grid-area: id; justify-content: flex-start; } 
    .twmc-table tr.data-row td:nth-child(3) { grid-area: name; justify-content: flex-start; text-align: left; line-height: 1.3; font-size: 0.85rem; word-wrap: break-word; white-space: normal;} 
    .twmc-table tr.data-row td:nth-child(4) { grid-area: score; justify-content: flex-end; margin-top: 6px;} 
    .twmc-table tr.data-row td:nth-child(5) { grid-area: level; justify-content: flex-end; padding-left: 6px !important; margin-top: 6px;} 
    .twmc-table tr.data-row td:nth-child(6) { grid-area: info; justify-content: flex-end; padding-left: 6px !important; margin-top: 6px;} 

    #mmb .twmc-table tr.battle-row { grid-template-columns: 50px max-content 1fr auto; grid-template-areas: "place id name name" "place . . info"; }
    #mmb .twmc-table tr.battle-row td:nth-child(4) { grid-area: info; justify-content: flex-end; margin-top: 6px;}

    .twmc-table tr.recap-row { display: block; border: none; margin: 0 16px 24px 16px; padding: 0; background: transparent !important; box-shadow: none; }
    .twmc-table tr.recap-row td { background: transparent !important; padding: 0 !important; border: none !important; box-shadow: none !important; }
    .twmc-table tr.recap-row a { display: block; background: #f5f3dc; border: 1px solid #fde047; border-radius: 8px; padding: 8px; text-align: center; box-shadow: 0 2px 4px rgba(0,0,0,0.02); color: #b45309; font-weight: 800; font-size: 0.75rem; }
}