* {
    box-sizing: border-box;
}

html, body {
    max-width: 100vw;
    overflow-x: hidden !important; /* ล็อคหน้าจอหลักเด็ดขาด */
    margin: 0;
    padding: 0;
    width: 100%;
}


:root {
    --bg-dark: #0d0d12;
    --box-bg: #1a1a24;
    --text-light: #e0e0e0;
    --neon-purple: #b829ff;
    --neon-purple-glow: 0 0 5px #b829ff, 0 0 15px #b829ff, 0 0 30px #b829ff;
    
    --c-yellow: #f1c40f;
    --c-blue: #00e5ff;
    --c-orange: #ff3d00;
    --c-gray: #b0bec5;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: var(--bg-dark);
    color: var(--text-light);
    padding: 15px; /* ลดขอบสำหรับมือถือ */
    width: 100%;
}

/* ปุ่มย้อนกลับ */
.btn-back-home {
    display: inline-flex;
    align-items: center;
    padding: 10px 20px;
    background-color: var(--box-bg);
    color: #fff;
    text-decoration: none;
    font-size: 1rem;
    font-weight: 600;
    border: 1px solid var(--neon-purple);
    border-radius: 30px;
    margin-bottom: 20px;
    transition: all 0.3s ease;
    box-shadow: 0 0 5px rgba(184, 41, 255, 0.4);
    max-width: 100%;
    white-space: normal; /* ให้ปุ่มตัดคำได้ถ้าจอเล็ก */
}

.btn-back-home:hover {
    background-color: var(--neon-purple);
    color: #fff;
    box-shadow: var(--neon-purple-glow);
    transform: translateY(-2px);
}

h1 {
    text-align: center;
    color: #ffffff;
    text-shadow: var(--neon-purple-glow);
    margin-bottom: 30px;
    margin-top: 10px;
    word-wrap: break-word; /* บังคับให้ตัดคำยาวๆ ไม่ให้ล้นจอ */
    overflow-wrap: break-word; /* บังคับให้ตัดคำยาวๆ ไม่ให้ล้นจอ */
    line-height: 1.4;
    padding: 0 10px;
}

.plan-container {
    display: flex;
    gap: 20px;
    position: relative;
    overflow-x: auto; /* ให้กล่องนี้เลื่อนได้ */
    padding-bottom: 50px;
    width: 100%;
    max-width: 100%; /* สำคัญ: บังคับไม่ให้กรอบตารางใหญ่เกินจอ */
    -webkit-overflow-scrolling: touch; /* ให้เลื่อนในมือถือสมูทขึ้น */
}

#arrowLayer {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 10;
    filter: drop-shadow(0 0 3px var(--neon-purple)); 
}

.year-column {
    flex: 1 0 280px;
    min-width: 280px;
    background: var(--box-bg);
    border: 1px solid #333;
    border-radius: 10px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.8);
    padding: 10px;
    position: relative;
    z-index: 2;
}

.year-header {
    text-align: center;
    color: white;
    padding: 10px;
    border-radius: 5px;
    font-weight: bold;
    margin-bottom: 15px;
    background-color: #2d1b4e;
    border: 1px solid var(--neon-purple);
    box-shadow: 0 0 10px rgba(184, 41, 255, 0.5);
}

.terms-container {
    display: flex;
    gap: 20px;
}

.term-column {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.term-header {
    text-align: center;
    font-size: 0.9em;
    font-weight: bold;
    padding: 5px;
    border-bottom: 2px solid #333;
    color: #aaa;
    margin-bottom: 10px;
}

@keyframes pulse-glow {
    0% { box-shadow: 0 0 5px var(--neon-purple); }
    50% { box-shadow: var(--neon-purple-glow); }
    100% { box-shadow: 0 0 5px var(--neon-purple); }
}

.course {
    border: 2px solid #444;
    padding: 8px 10px;
    border-radius: 8px;
    font-size: 0.8em;
    text-align: center;
    background-color: #222230;
    color: #fff;
    cursor: pointer;
    transition: all 0.3s ease;
    position: relative;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 40px;
    z-index: 11;
}

.course:hover {
    transform: translateY(-3px) scale(1.02);
    background-color: #2a2a3d;
    border-color: var(--neon-purple) !important;
    animation: pulse-glow 1.5s infinite;
}

.border-yellow { border-color: var(--c-yellow); }
.border-blue { border-color: var(--c-blue); }
.border-orange { border-color: var(--c-orange); }
.border-gray { border-color: var(--c-gray); }

.plan-divider {
    margin-top: 20px;
    padding-top: 10px;
    border-top: 2px dashed var(--neon-purple);
    text-align: center;
    font-weight: bold;
    color: var(--neon-purple);
    font-size: 0.9em;
    text-shadow: 0 0 5px var(--neon-purple);
}

.legend-container, .info-box {
    background: var(--box-bg);
    border: 1px solid #333;
    color: var(--text-light);
    width: 100%; /* เพิ่มบรรทัดนี้ */
    max-width: 100%; /* เพิ่มบรรทัดนี้ */
}

.legend-container {
    display: flex;
    justify-content: flex-end;
    flex-wrap: wrap;
    gap: 15px;
    margin-top: 30px;
    padding: 15px 20px;
    border-radius: 8px;
    box-shadow: 0 2px 10px rgba(0, 0, 0, 0.5);
    max-width: 800px;
    margin-left: auto;
}

.legend-item { display: flex; align-items: center; font-size: 0.9em; }
.legend-box { width: 24px; height: 14px; border-radius: 4px; margin-right: 8px; }

.bg-yellow { background-color: var(--c-yellow); box-shadow: 0 0 5px var(--c-yellow); }
.bg-blue { background-color: var(--c-blue); box-shadow: 0 0 5px var(--c-blue); }
.bg-orange { background-color: var(--c-orange); box-shadow: 0 0 5px var(--c-orange); }
.bg-gray { background-color: var(--c-gray); box-shadow: 0 0 5px var(--c-gray); }

/* ตกแต่ง Scrollbar สำหรับกล่องตาราง */
.plan-container::-webkit-scrollbar {
    height: 10px;
}

.plan-container::-webkit-scrollbar-track {
    background: var(--bg-dark);
    border-radius: 10px;
}

.plan-container::-webkit-scrollbar-thumb {
    background: var(--neon-purple);
    border-radius: 10px;
}

.plan-container::-webkit-scrollbar-thumb:hover {
    background: #d066ff;
}

/* สำหรับหน้าจอมือถือ */
/* การแสดงผลบนจอมือถือ */
@media screen and (max-width: 768px) {
    h1 {
        font-size: 1.3rem; /* ย่อขนาดหัวข้อหลัก */
    }
    
    .info-box h2 {
        font-size: 1.1rem; /* ย่อขนาดชื่อหลักสูตรในกล่องด้านล่าง */
        line-height: 1.5;
        word-wrap: break-word;
        overflow-wrap: break-word;
    }

    .legend-container {
        flex-direction: column; /* ให้เรียงลงมาเป็นแนวตั้ง จะได้ไม่ล้นจอ */
        align-items: flex-start;
    }
}