/* 1. CSS Variables - หัวใจของการทำ Theme */


/* 2. Reset & Base */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
  font-family: var(--font-main);
  background-color: var(--z-bg-main);
  color: var(--z-text-main);
  display: grid;
  grid-template-columns: var(--nav-width) 1fr;
  min-height: 100vh;
  transition: background-color var(--transition-speed);
  position: relative;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  font-size: 16px;
  line-height: 1.6;
}

/* 2. Paper Texture Overlay */
body::before {
    content: "";
    position: fixed;
    top: 0; left: 0; width: 100%; height: 100%;
    background-image: var(--paper-noise);
    opacity: var(--z-noise-opacity);
    pointer-events: none;
    z-index: 99;
}

h1, h2, h3 {
  /* หัวข้ออาจจะใช้ฟอนต์ตัวหนาเป็นพิเศษ */
  font-weight: 700;
  line-height: 1.2;
}

/* 3. Navigation (Sticky Sidebar) */
.side-nav {
    background-color: var(--z-bg-soft);
    border-right: 1px solid var(--z-border);
    height: 100vh;
    position: sticky;
    top: 0;
    padding: 2rem;
    overflow-y: auto;
    backdrop-filter: blur(5px);
}

.nav-content h2 {
  margin-bottom: 1.5rem;
  font-size: 1.2rem;
  text-transform: uppercase;
  letter-spacing: 1px;
}

.side-nav ul {
  list-style: none;
  display: flex;
  flex-direction: column; /* วางแนวตั้งใน Desktop */
  gap: 0.8rem;
}
.side-nav li { margin-bottom: 0.8rem; }
.side-nav a {
    text-decoration: none;
    color: var(--z-text-soft);
    transition: all var(--transition-speed);
}

.side-nav a.active, .side-nav a:hover {
    color: var(--z-accent);
    font-weight: 600;
}

.theme-switcher {
    margin-top: auto;
    display: flex;
    gap: 4px;
    padding: 2px;
    background: var(--z-bg-main);
    border: 1px solid var(--z-border);
    border-radius: 6px;
}

.btn-theme {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--z-text-soft);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    transition: all var(--transition-speed);
}

/* เมื่อปุ่มถูกเลือก (เราจะใช้ JS ช่วยคุมสถานะ หรือจะเช็คจาก Attribute ก็ได้) */
[data-theme="light"] .btn-theme:first-child,
[data-theme="dark"] .btn-theme:last-child {
    background: var(--z-accent);
    color: var(--z-bg-main);
    box-shadow: 0 2px 4px var(--z-shadow);
}

[data-theme="dark"] .btn-theme:hover {
    color: var(--z-text-soft);
    background-color: rgba(255, 255, 255, 0.05);
}

.btn-theme:hover {
    color: var(--z-text-main);
    background-color: rgba(0, 0, 0, 0.03);
}

.about{
  margin-top: 40px;
}

/* 4. Main Content */
.welcome {
  background-image: url('/assets/images/cover_002.png');
  background-repeat: no-repeat;
  background-position: center; /* ยุบรวมแกน X และ Y ไว้ด้วยกันได้ค่ะ */
  background-size: 100%;        /* เปลี่ยนเป็นตัวนี้ รูปจะย่อมาพอดีกล่อง */
  display: block;                  /* แก้จาก content เป็น block เพื่อให้ยอมรับค่า width/height */
  width: 100%;
  height: 300px;
}
.main-content {
  display: flex;
  flex-direction: column;
  align-items: center;
  width: 100%;
}

.section-card {
    width: 100%;
    max-width: 1000px;
    margin-bottom: 4rem;
    animation: fadeIn 0.8s ease-out;
}

.intro{
  margin-top: 20px;
}

/* 5. Layout Helpers (Flex & Grid) */
.content-full {
  width: 100%;
  background: var(--z-bg-card);
  border: 1px solid var(--z-border);
  padding: 20px;
  border-radius: var(--z-radius);
  box-shadow: 2px 2px 12px var(--z-shadow);
  gap: 20px;
  transition: transform 0.2s;
}

.content-card {
    background: var(--z-bg-card);
    border: 1px solid var(--z-border);
    padding: 20px;
    border-radius: var(--z-radius);
    box-shadow: 2px 2px 12px var(--z-shadow);
    display: flex;
    flex: 1;             /* เพิ่มตรงนี้: เพื่อให้ขยายเต็มพื้นที่ที่เหลือ */
    min-width: 350px;
    gap: 20px;
    transition: transform 0.2s;
}

.content-row {
  display: flex;
  flex-wrap: wrap; /* สำคัญ: เพื่อให้ของที่ล้น เด้งลงมาแถวใหม่ */
  gap: 20px;       /* ระยะห่างระหว่างก้อนเนื้อหา */
}

.column-text, .column-visual {
  flex: 1;
}

.col-text {
    direction: rtl;
    unicode-bidi: bidi-override;
    display: inline-block;
}

.zen-ui input, .zen-ui select {
    background: var(--z-bg-soft);
    border: 1px solid var(--z-border);
    color: var(--z-text-main);
    padding: 6px 12px;
    border-radius: 4px;
}

.zen-ui .btn-primary.active {
    background: var(--z-accent);
    color: var(--z-bg-main);
    border: none;
}

.responsive-img {
  width: 100%;
  height: auto;
  border-radius: 8px;
  box-shadow: var(--card-shadow);
}

/* 6. Read More System (แบบเนียนตา) */
.readmore-text {
  max-height: 4.8em; /* โชว์ประมาณ 3 บรรทัด */
  overflow: hidden;
  transition: max-height 0.5s ease; /* ยืดแบบ Animation */
}

.readmore-text.expanded {
  max-height: 1000px; /* ค่ามากพอที่จะครอบคลุมเนื้อหา */
}

.more-content {
  display: none;
}

.readmore-text.expanded .more-content {
  display: inline;
}

.btn-toggle {
  margin-top: 1rem;
  background: var(--primary-color);
  color: white;
  border: none;
  padding: 0.5rem 1rem;
  border-radius: 4px;
  cursor: pointer;
  font-size: 0.9rem;
}

.btn-toggle:hover { background: var(--primary-hover); }

/* 7. Responsive */
@media (max-width: 768px) {
  body {
    grid-template-columns: 1fr; /* ยุบ Grid เหลือแถวเดียว */
  }

  .side-nav {
    position: fixed; /* ล็อคเมนูไว้ด้านบน */
    top: 0;
    left: 0;
    width: 100%;
    height: auto; /* ให้สูงเท่ากับเนื้อหาเมนู */
    padding: 1rem;
    border-right: none;
    border-bottom: 1px solid var(--z-border);
    z-index: 1000; /* ให้อยู่เหนือเนื้อหาอื่น */
  }

  .nav-content h2 {
    display: none; /* ซ่อนหัวข้อ "เมนู" ในมือถือเพื่อประหยัดพื้นที่ */
  }

  .side-nav ul {
    flex-direction: row; /* เปลี่ยนเมนูเป็นแนวนอน */
    justify-content: space-around; /* กระจายเมนูให้เต็มความกว้าง */
    gap: 10px;
  }

  .side-nav li {
    margin-bottom: 0; /* ลบ margin ล่างที่เคยใช้ในแนวตั้ง */
  }

  .side-nav a {
    font-size: 0.9rem; /* ปรับขนาดตัวอักษรให้พอดีกับหน้าจอมือถือ */
    padding: 5px 10px;
    display: block;
  }

  .theme-switcher {
        margin-top: 0;
        padding-top: 0;
        border-top: none;
        margin-left: auto; /* ผลักไปไว้ขวาสุดของจอ แอบไว้เงียบๆ */
    }

  /* ปรับ Main Content ให้ไม่โดนเมนูทับ */
  .main-content {
    padding: 120px 1.5rem 2rem; /* padding-top ต้องมากกว่าความสูงของเมนู */
  }
  .content-card { flex-direction: column; }

  .btn-theme span {
        display: none; /* ซ่อนตัวหนังสือ เหลือแค่ Emoji */
    }

    .btn-theme {
        padding: 6px;
        font-size: 16px; /* ขยาย Emoji นิดเดียวเพื่อให้กดง่ายแต่ไม่เตะตา */
    }
}

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(10px); }
  to { opacity: 1; transform: translateY(0); }
}