/* ======================================================
 *         ไฟล์ lesson-style.css (สำหรับหน้าบทเรียนทั้งหมด)
 * ====================================================== */

/* --- 1. โครงสร้างพื้นฐาน, ตัวแปรสี และ Font --- */
@import url('https://fonts.googleapis.com/css2?family=Kanit:wght@300;400;500;600;700&display=swap');
@import url('https://fonts.googleapis.com/css2?family=Sarabun:wght@400;500;700&display=swap');

:root {
    --primary-pink: #FADADD;
    --primary-blue: #D6EAF8;
    --accent-pink: #FF8FAB;
    --accent-blue: #74B9FF;
    --text-color: #4A4A4A;
    --bg-color-lesson: #f8f9fa;
    --correct-color: #28a745;
    --incorrect-color: #dc3545;
    --button-primary-blue: #007bff;
    --button-primary-blue-hover: #0056b3;
    --code-bg: #2d2d2d;
    --code-text: #f8f8f2;
}

body {
    font-family: 'Kanit', 'Sarabun', sans-serif;
    background-color: var(--bg-color-lesson);
    color: var(--text-color);
    line-height: 1.7;
    margin: 0;
}

.container {
    max-width: 900px;
    margin: 20px auto;
    padding: 0 20px;
}

/* --- 9. Component: Styled Table (สำหรับตารางเนื้อหา) --- */
/* เราเพิ่ม main เข้าไปข้างหน้าเพื่อเพิ่มความเฉพาะเจาะจง (Specificity) และป้องกันการทับซ้อนของสไตล์ */

.styled-table {
    border-collapse: collapse;
    margin: 25px 0;
    font-size: 0.9em;
    color: #0056b3; /* น้ำเงินเข้ม เห็นชัด */
    width: 100%;
    border-radius: 12px; /* ทำให้มุมมนสวยงาม */
    overflow: hidden; /* สำคัญมากสำหรับ border-radius */
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
    border: 1px solid #e0e0e0; /* เพิ่มเส้นขอบรอบตาราง */
    display: table;
    table-layout: auto;
}

.styled-table thead tr {
    /* ใช้สีจากตัวแปรในไฟล์ของคุณเพื่อให้เข้ากับธีม */
    background-color: var(--accent-blue); 
    color: #ffffff;
    text-align: left;
    font-weight: 600; 
    font-size: 1rem;
}

.styled-table th,
.styled-table td {
    padding: 14px 18px;

}

.styled-table tbody tr {
    border-bottom: 1px solid #e9ecef; /* เส้นคั่นแนวนอนระหว่างแถว */
}

/* สลับสีแถวเพื่อให้ดูง่ายขึ้น */
.styled-table tbody tr:nth-of-type(even) {
    background-color: #f8f9fa; 
}

/* ทำให้เส้นขอบล่างสุดของตารางหนาและเป็นสีเดียวกับหัวข้อ */
.styled-table tbody tr:last-of-type {
    border-bottom: 3px solid var(--accent-blue);
}

/* เอฟเฟกต์เมื่อเมาส์ชี้ */
.styled-table tbody tr:hover {
    background-color: #e7f3fe; 
    cursor: default;
}

/* สไตล์สำหรับแท็ก code ในตาราง */
.styled-table code {
    background-color: #e9ecef; 
    color: #0056b3; /* น้ำเงินเข้ม เห็นชัด */
    padding: 3px 6px;
    border-radius: 4px;
    font-family: 'Courier New', Courier, monospace;
    font-size: 0.95em;
}

/* --- 2. Layout: Header, Navigation, Footer --- */
header {
    background: linear-gradient(135deg, var(--primary-pink), var(--primary-blue));
    padding: 2rem 1rem;
    text-align: center;
    border-radius: 0 0 20px 20px;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.05);
}
header h1 {
    margin: 0;
    font-size: 2.8rem;
    font-weight: 700;
    background: linear-gradient(45deg, #3498db, #9b59b6);
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    text-shadow: 2px 2px 8px rgba(0, 0, 0, 0.1);
}
nav.main-nav {
    text-align: center;
    margin: 25px 0;
    padding: 10px;
    background-color: white;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.08);
}
nav.main-nav a {
    color: var(--accent-pink);
    text-decoration: none;
    font-weight: 500;
    margin: 0 15px;
    padding: 8px 12px;
    border-radius: 8px;
    transition: background-color 0.3s, color 0.3s;
}
nav.main-nav a.active, nav.main-nav a:hover {
    background-color: var(--primary-pink);
    color: var(--text-color);
}
nav.main-nav a.active {
    font-weight: 700;
}
footer {
    text-align: center;
    padding: 2rem;
    color: #4a5568;
    background-color: transparent;
    font-size: 0.9rem;
}

/* --- 3. Main Content (General) --- */
main {
    background-color: #FFFFFF;
    padding: 2rem;
    border-radius: 15px;
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.08);
}
main h2 {
    color: var(--accent-pink);
    font-size: 2rem;
    border-bottom: 3px solid var(--primary-blue);
    padding-bottom: 10px;
    margin-top: 0;
}
main h3 {
    color: var(--accent-blue);
    font-size: 1.6rem;
    margin-top: 1.5em;
}
.component-card, .feature-card {
    background-color: #fcfaff;
    padding: 20px;
    border-radius: 12px;
    border-left: 5px solid var(--accent-blue);
    margin-bottom: 1rem;
}

/* --- 4. Components --- */
/* User Display */
.user-display {
    text-align: center; padding: 10px 0; color: var(--text-color);
    font-size: 0.95rem; display: none;
}
.user-display strong#user-name-display {
    color: #333; font-weight: 500;
}
.user-display button#logout-btn-header {
    background-color: var(--accent-pink); color: white; border: none; padding: 6px 14px;
    border-radius: 20px; cursor: pointer; font-family: 'Kanit', sans-serif;
    font-size: 0.9rem; margin-left: 15px; transition: background-color 0.3s;
}
.user-display button#logout-btn-header:hover {
    background-color: #e57395;
}

/* Scroll-to-Top Button */
#scrollToTopBtn {
    display: none; position: fixed; bottom: 30px; right: 30px;
    z-index: 100; border: none; outline: none; background-color: var(--accent-pink); color: white;
    cursor: pointer; padding: 10px; border-radius: 50%; width: 50px; height: 50px;
    font-size: 20px; box-shadow: 0 4px 8px rgba(0, 0, 0, 0.2);
    transition: background-color 0.3s, transform 0.2s;
}
#scrollToTopBtn:hover {
    background-color: #e57395; transform: scale(1.1);
}

/* Code Blocks */
.code-container {
    position: relative; margin: 20px 0;
}
pre {
    background-color: var(--code-bg); color: var(--code-text);
    padding: 20px; padding-top: 50px; border-radius: 10px;
    font-family: 'Courier New', Courier, monospace; white-space: pre-wrap;
    word-wrap: break-word; font-size: 1rem; overflow-x: auto;
}
.code-container .copy-btn {
    position: absolute; top: 10px; right: 10px; background-color: var(--accent-blue);
    color: white; border: none; padding: 6px 12px; border-radius: 6px;
    cursor: pointer; font-family: 'Kanit', sans-serif; font-size: 0.9rem;
    transition: background-color 0.3s ease; z-index: 2;
}
.code-container .copy-btn:hover { background-color: #55a2e8; }
.code-container .copy-btn.copied { background-color: var(--correct-color); }
pre .comment { color: #8f8f8f; font-style: italic; }


/* --- 5. Quiz System (Universal) --- */
#quiz {
  background-color: #ffffff; padding: 2rem 2.5rem; margin-top: 2rem;
  border-radius: 10px; box-shadow: 0 4px 15px rgba(0, 0, 0, 0.05);
}
#quiz h2, #quiz h3 {
  text-align: center; color: var(--accent-pink); font-size: 2.2rem;
  font-weight: bold; margin-bottom: 15px; padding-bottom: 15px;
  border-bottom: 3px solid var(--primary-blue);
}
.question-block {
  background-color: #fff; border: 1px solid #f0f0f0; border-radius: 12px;
  padding: 1.5rem 2rem; margin-top: 2rem; box-shadow: 0 2px 8px rgba(0, 0, 0, 0.05);
  transition: border-color 0.3s, background-color 0.3s;
}
.question-block p {
  font-size: 1.1rem; font-weight: 600; margin-top: 0; margin-bottom: 1.5rem;
}
.question-block div { margin-bottom: 1rem; display: flex; align-items: center; }
.question-block label { margin-left: 10px; font-size: 1rem; color: #333; }
.submit-btn {
  display: block; width: 200px; margin: 2.5rem auto 1rem auto; padding: 12px 20px;
  font-size: 1.1rem; background-color: var(--button-primary-blue); color: white;
  border: none; border-radius: 8px; cursor: pointer; transition: background-color 0.3s;
}
.submit-btn:hover { background-color: var(--button-primary-blue-hover); }
.question-block.correct-answer { border-color: var(--correct-color); background-color: #f0fff4; }
.question-block.incorrect-answer { border-color: var(--incorrect-color); background-color: #fff5f5; }
.feedback { margin-top: 1rem; font-weight: bold; }
.feedback.correct { color: var(--correct-color); }
.feedback.incorrect { color: var(--incorrect-color); }


/* --- 6. Success Modal & Next Lesson Buttons --- */
#quiz-navigation { text-align: center; margin: 2rem 0; }
.next-lesson-btn {
    display: inline-block; padding: 12px 25px; background-color: var(--correct-color);
    color: white; font-size: 1.1rem; font-weight: bold; text-decoration: none;
    border-radius: 8px; transition: all 0.3s; box-shadow: 0 4px 10px rgba(40, 167, 69, 0.3);
}
.next-lesson-btn:hover { background-color: #218838; transform: translateY(-2px); }
.modal-action-btn {
    display: inline-block; background-color: var(--button-primary-blue); color: white !important;
    border: none; padding: 12px 30px; border-radius: 8px; font-size: 1rem; font-weight: bold;
    cursor: pointer; text-decoration: none; transition: all 0.2s;
}
.modal-action-btn:hover { background-color: var(--button-primary-blue-hover); transform: scale(1.05); }

#success-modal-overlay {
  position: fixed; top: 0; left: 0; width: 100%; height: 100%;
  background-color: rgba(0, 0, 0, 0.6); display: none; justify-content: center;
  align-items: center; z-index: 1000; backdrop-filter: blur(5px);
}
.modal-content {
  background-color: white; padding: 30px 40px; border-radius: 15px; text-align: center;
  box-shadow: 0 5px 25px rgba(0, 0, 0, 0.2); width: 90%; max-width: 400px;
  transform: translateY(-20px); opacity: 0; animation: modal-appear 0.4s forwards ease-out;
}
@keyframes modal-appear { to { transform: translateY(0); opacity: 1; } }
.modal-icon {
  width: 80px; height: 80px; border-radius: 50%; background-color: var(--correct-color);
  color: white; font-size: 50px; line-height: 80px; margin: 0 auto 20px auto;
}


/* --- 7. Page-Specific Styles --- */

/* 7.1 For Pages with Tabbed Navigation (Turtle & Basics) */
.sub-nav, .tab-nav { text-align: center; margin-bottom: 30px; }
/* Turtle Tabs */
.sub-nav { display: flex; flex-wrap: wrap; border-bottom: 2px solid #eee; }
.sub-nav a {
    padding: 10px 20px; cursor: pointer; border-bottom: 3px solid transparent;
    margin-bottom: -2px; font-weight: 500; color: #888; text-decoration: none;
    transition: all 0.2s;
}
.sub-nav a.active, .sub-nav a:hover { color: var(--accent-pink); }
.sub-nav a.active { border-bottom-color: var(--accent-pink); }
/* Basics Tabs */
.tab-nav { padding: 15px 10px; background-color: #f8f9fa; border-bottom: 2px solid #e0e0e0; }
.tab-row { display: flex; justify-content: center; flex-wrap: wrap; gap: 10px; }
.tab-row:first-child { margin-bottom: 10px; }
.tab-nav a {
    display: inline-block; padding: 10px 18px; border: 1px solid #ced4da;
    border-radius: 8px; background-color: #ffffff; color: #495057; font-size: 1em;
    font-weight: 500; text-decoration: none; transition: all 0.3s ease;
    cursor: pointer; box-shadow: 0 2px 4px rgba(0,0,0,0.05);
}
.tab-nav a:hover {
    background-color: #e7f3fe; color: var(--button-primary-blue-hover);
    border-color: #b3d7ff; transform: translateY(-2px); box-shadow: 0 4px 8px rgba(0,0,0,0.1);
}
.tab-nav a.active {
    background-color: var(--button-primary-blue); color: #ffffff;
    border-color: var(--button-primary-blue-hover); font-weight: bold; transform: translateY(0);
}
/* Universal Tab Content */
.content-section, .tab-section { display: none; }
.content-section.active, .tab-section.active { display: block; animation: fadeIn 0.5s; }
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }

/* 7.2 For Python Turtle Page */
.table-of-contents {
    background-color: #fdfcff; border: 1px solid var(--primary-pink);
    border-radius: 8px; padding: 15px 25px; margin-bottom: 30px;
}
.table-of-contents h4 {
    margin-top: 0; margin-bottom: 15px; border-left: none;
    padding-left: 0; color: var(--accent-pink); font-size: 1.2em;
}
.table-of-contents ul {
    list-style-type: none; padding-left: 0; margin: 0; display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr)); gap: 10px;
}
.table-of-contents li a {
    text-decoration: none; color: var(--text-color); transition: color 0.2s, background-color 0.2s;
    display: block; padding: 5px 8px; border-radius: 4px;
}
.table-of-contents li a:hover { color: var(--accent-blue); background-color: #e9ecef; }
.challenge-box {
    background-color: #fffbe6; border: 2px dashed #ffc107;
    padding: 20px; margin-top: 30px; border-radius: 10px;
}
.challenge-box h3 { margin-top: 0; color: #d35400; }
.command-list { list-style-type: none; padding-left: 0; }
.command-list li {
    background-color: #f8f9fa; margin-bottom: 10px; padding: 10px 15px;
    border-radius: 5px; border-left: 4px solid var(--accent-blue);
}
.command-list code {
    color: #e83e8c; font-weight: bold; background-color: #fdf2f7;
    padding: 2px 5px; border-radius: 3px;
}

/* 7.3 For Python Basics Page */
.exercise-box {
    background-color: #f9f9f9; border: 1px solid #ddd; border-radius: 8px;
    padding: 20px; margin-bottom: 25px;
}
.exercise-box h4 { margin-top: 0; color: var(--accent-blue); }
.exercise-box .code-output {
    background-color: #1e1e1e; color: #d4d4d4; padding: 15px; border-radius: 4px;
    font-family: 'Courier New', Courier, monospace; white-space: pre-wrap; margin-top: 10px;
}
.exercise-box .code-output strong { color: #9cdcfe; }

/* 7.4 For Editor Containers (Turtle & Basics) */
.editor-container {
    position: relative; border: 1px solid #ccc; border-radius: 10px;
    overflow: hidden; background-color: #f8f9fa; margin: 20px 0;
}
.editor-container .fullscreen-toggle-btn {
    position: absolute; top: 10px; right: 10px; z-index: 10; padding: 8px 16px;
    background-color: var(--accent-blue); color: white; border: none;
    border-radius: 5px; cursor: pointer; font-family: 'Kanit', sans-serif; font-size: 0.9em;
}
.editor-container .return-btn {
    display: none; position: fixed; top: 15px; left: 15px; z-index: 9999; padding: 10px 20px;
    background-color: var(--accent-pink); color: white; border: none; border-radius: 8px;
    cursor: pointer; font-family: 'Kanit', sans-serif; font-size: 1em;
    box-shadow: 0 4px 8px rgba(0,0,0,0.2);
}
.editor-container.fullscreen-active iframe {
    position: fixed; top: 0; left: 0; width: 100vw; height: 100vh;
    z-index: 9998; border: none; background: #fff;
}
.editor-container.fullscreen-active .fullscreen-toggle-btn {
    opacity: 0; pointer-events: none;
}
.editor-container.fullscreen-active .return-btn {
    display: block;
}

/* lesson-style.css (ส่วนที่ต้องเพิ่ม) */

/* --- 8. Component: Tab Pagination (ปุ่มนำทางท้ายแท็บ) --- */
.tab-pagination {
    display: flex;
    justify-content: space-between;
    align-items: stretch; /* ทำให้ปุ่มสูงเท่ากัน */
    margin-top: 40px;
    padding-top: 20px;
    border-top: 2px solid #f0f0f0;
    gap: 15px; /* ระยะห่างระหว่างปุ่ม */
}

.tab-pagination a {
    flex: 1; /* ทำให้ปุ่มขยายเต็มพื้นที่ที่มี */
    display: flex;
    align-items: center;
    padding: 15px 20px;
    border: 1px solid #ddd;
    border-radius: 12px;
    text-decoration: none;
    color: var(--text-color);
    background-color: #f8f9fa;
    transition: all 0.3s ease;
    box-shadow: 0 2px 5px rgba(0,0,0,0.05);
}

.tab-pagination a:hover {
    transform: translateY(-3px);
    box-shadow: 0 4px 10px rgba(0,0,0,0.1);
    border-color: var(--accent-blue);
}

.tab-pagination .nav-arrow {
    font-size: 2em;
    font-weight: bold;
    color: var(--accent-blue);
}

.tab-pagination .prev-btn .nav-arrow {
    margin-right: 15px;
}

.tab-pagination .next-btn {
    flex-direction: row-reverse; /* สลับตำแหน่งลูกศรกับข้อความ */
    text-align: right;
}

.tab-pagination .next-btn .nav-arrow {
    margin-left: 15px;
}

.tab-pagination .nav-text {
    display: flex;
    flex-direction: column;
}

.tab-pagination .nav-label {
    font-size: 0.9em;
    color: #888;
}

.tab-pagination .nav-title {
    font-weight: 500;
    font-size: 1.05em;
    color: #333;
}

/* lesson-style.css (ส่วนที่ต้องเพิ่มสำหรับบทที่ 6) */

/* --- 8. Page-Specific: Tkinter Page --- */
.info-box {
    background-color: #e7f3fe;
    border-left: 6px solid #2196F3;
    padding: 15px 20px;
    margin: 20px 0;
    border-radius: 5px;
}
.run-on-pc-guide {
    margin-top: 40px;
    padding: 25px;
    background-color: #f8f9fa;
    border-top: 5px solid var(--accent-blue);
    border-radius: 0 0 10px 10px;
}
.run-on-pc-guide h3 {
    color: var(--accent-blue);
    margin-top: 0;
    font-size: 1.8rem;
}
.run-on-pc-guide ol {
    padding-left: 25px;
    font-size: 1.1rem;
}
.run-on-pc-guide li {
    margin-bottom: 15px;
}
.run-on-pc-guide a.button {
    display: inline-block;
    background-color: #28a745;
    color: white;
    padding: 10px 20px;
    text-decoration: none;
    font-weight: bold;
    border-radius: 8px;
    transition: background-color 0.2s;
}
.run-on-pc-guide a.button:hover {
    background-color: #218838;
}
.run-on-pc-guide strong.key-point {
    color: #d35400;
    font-weight: bold;
}
.run-on-pc-guide .editor-logos {
    display: flex;
    gap: 20px;
    align-items: center;
    margin-top: 10px;
}
.run-on-pc-guide .editor-logos img {
    height: 40px;
}

/* เพิ่มสีพื้นสำหรับแต่ละหมวด */
.example-card.bg-life {
  background-color: #fff8f0;
  border-left: 6px solid #ffa94d;
}
.example-card.bg-code {
  background-color: #f0faff;
  border-left: 6px solid #4dabf7;
}
.example-card ul {
  padding-left: 1.2em;
  margin: 10px 0 0 0;
}
.example-card ul li {
  margin-bottom: 10px;
  line-height: 1.6;
}
.example-card h4 {
  margin-bottom: 10px;
}

/* --- 10. Syntax Highlighting for Code --- */
/* ปรับปรุงสไตล์ของ pre ให้เหมือน Editor สมัยใหม่ */
pre {
    background-color: #1E1E1E; /* พื้นหลังสีเทาเข้ม */
    color: #D4D4D4; /* สีตัวอักษรปกติ (สีเทาอ่อน) */
    padding: 25px;
    padding-top: 50px; /* เพิ่ม padding ด้านบนสำหรับปุ่ม */
    border-radius: 10px;
    font-family: 'Consolas', 'Courier New', Courier, monospace; /* ใช้ฟอนต์สำหรับโค้ดดิ้ง */
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 1rem;
    overflow-x: auto;
    border: 1px solid #333;
}

/* คลาสสำหรับเน้นสีแต่ละส่วนของโค้ด */
pre .py-comment { color: #6A9955; font-style: italic; } /* สีเขียวสำหรับคอมเมนต์ */
pre .py-keyword { color: #C586C0; font-weight: bold; } /* สีชมพูม่วงสำหรับ def, if, import, try... */
pre .py-string { color: #CE9178; } /* สีส้มสำหรับข้อความใน " " */
pre .py-function { color: #DCDCAA; } /* สีเหลืองสำหรับชื่อฟังก์ชัน */
pre .py-builtin { color: #4FC1FF; } /* สีฟ้าสำหรับฟังก์ชันในตัว เช่น float */
pre .py-number { color: #B5CEA8; } /* สีเขียวอ่อนสำหรับตัวเลข */
pre .py-class { color: #4EC9B0; } /* สีเขียวอมฟ้าสำหรับชื่อคลาส เช่น Tk, Label */