/* ===========================================================
   base.css — tokens, reset, nav, buttons, footer
   ใช้ร่วมกันทุกหน้า (index / patch-notes / download / contact / 404)
   =========================================================== */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    /* สี */
    --bg-dark: #0a0d13;
    --bg-card: #111827;
    --bg-card-hover: #1a2332;
    --bg-section: #0f1520;
    --border-color: #1e2a3a;
    --border-accent: #2d4a6f;
    --gold: #f0b429;
    --gold-light: #ffd166;
    --gold-dark: #c4901c;
    --red: #ef4444;
    --red-light: #fca5a5;
    --green: #22c55e;
    --green-light: #86efac;
    --blue: #3b82f6;
    --blue-light: #93c5fd;
    --purple: #a855f7;
    --purple-light: #d8b4fe;
    --cyan: #06b6d4;
    --orange: #f97316;
    --discord: #5865f2;
    --line-green: #06c755;
    --text-primary: #e5e7eb;
    --text-secondary: #9ca3af;
    --text-muted: #6b7280;

    /* ตัวอักษร */
    /* Cinzel ไม่มีตัวอักษรไทย ต้องต่อด้วย Noto Sans Thai
       ไม่งั้นไทยจะตกไปใช้ serif ของระบบ ซึ่งทำวรรณยุกต์ซ้อนสระหาย เช่น อื่ */
    --font-display: 'Cinzel', 'Noto Sans Thai', serif;
    --font-body: 'Noto Sans Thai', system-ui, sans-serif;

    /* ระยะห่าง: ใช้เฉพาะค่าพวกนี้เท่านั้นทั้งเว็บ */
    --space-25: 2px;
    --space-50: 4px;
    --space-75: 8px;
    --space-100: 12px;
    --space-200: 16px;
    --space-300: 24px;
    --space-400: 32px;
    --space-500: 40px;
    --space-600: 48px;
    --space-700: 64px;
    --space-800: 80px;
    --space-900: 96px;

    /* มุมโค้ง */
    --radius-md: 6px;
    --radius-lg: 8px;
    --radius-xl: 12px;
    --radius-2xl: 16px;
    --radius-3xl: 24px;
    --radius-full: 9999px;

    /* ความสูงแถบเมนู ใช้อ้างอิงตอนเว้นที่ให้แถบแท็บและพื้นหลัง hero */
    --nav-h: 64px;

    /* กรอบนอกของเว็บ ใช้กับแถบเมนูและ footer กว้างเท่ากันทุกหน้า */
    --shell-max: 1320px;

    /* ความกว้างของเนื้อหา แถบแท็บ และ footer
       หน้าแรกกว้างกว่า ดูที่ .page-home ใน landing.css */
    --page-max: 1000px;

    /* จังหวะการเคลื่อนไหว */
    --ease-fluid: cubic-bezier(0.32, 0.72, 0, 1);
}

html {
    scroll-behavior: smooth;
    /* จองที่ให้แถบเลื่อนไว้เสมอ หน้าที่เนื้อหาสั้นจะได้ไม่กว้างกว่าหน้ายาว 8px
       ไม่งั้นพอสลับหน้า เมนูกับเนื้อหาจะขยับข้างละ 4px เห็นเป็นอาการหน้ากระตุก
       ใส่ both-edges เพื่อจองทางซ้ายด้วย ถ้าจองแค่ขวา เนื้อหาจะเยื้องซ้าย 4px */
    scrollbar-gutter: stable both-edges;
}

body {
    font-family: var(--font-body);
    background: var(--bg-dark);
    color: var(--text-primary);
    line-height: 1.7;
    overflow-x: hidden;
    text-wrap: pretty;
}

h1, h2, h3, h4 { text-wrap: balance; }

::selection { background: var(--gold); color: #0a0d13; }

:focus-visible {
    outline: 2px solid var(--gold);
    outline-offset: 3px;
    border-radius: var(--radius-md);
}

/* --- Scrollbar --- */
::-webkit-scrollbar { width: 8px; }
::-webkit-scrollbar-track { background: var(--bg-dark); }
::-webkit-scrollbar-thumb { background: var(--border-accent); border-radius: var(--radius-md); }
::-webkit-scrollbar-thumb:hover { background: var(--gold-dark); }

/* --- Skip link สำหรับคีย์บอร์ด --- */
.skip-link {
    position: absolute;
    left: var(--space-200);
    top: -80px;
    z-index: 200;
    background: var(--gold);
    color: #0a0d13;
    font-size: 0.875rem;
    line-height: 20px;
    font-weight: 600;
    padding: var(--space-75) var(--space-100);
    border-radius: var(--radius-lg);
    text-decoration: none;
    transition: top 400ms var(--ease-fluid);
}
.skip-link:focus { top: var(--space-200); }

/* ===== Nav เต็มความกว้าง ยึดติดด้านบน ===== */
.site-nav {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    background: rgba(10, 13, 19, 0.78);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    transition: background 700ms var(--ease-fluid), border-color 700ms var(--ease-fluid);
}
.site-nav.scrolled {
    background: rgba(10, 13, 19, 0.94);
    border-bottom-color: var(--border-accent);
}

.site-nav-inner {
    width: 100%;
    max-width: var(--shell-max);
    margin: 0 auto;
    height: var(--nav-h);
    /* สามช่อง: แบรนด์ชิดซ้าย เมนูอยู่กึ่งกลางจอ ปุ่มอยู่ขวา */
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: center;
    gap: var(--space-300);
    padding: 0 var(--space-300);
}
.site-nav-inner > .nav-brand { grid-column: 1; justify-self: start; }
.site-nav-inner > .nav-links { grid-column: 2; justify-self: center; }
.site-nav-inner > .nav-actions { grid-column: 3; justify-self: end; }

.nav-actions {
    display: flex;
    align-items: center;
    gap: var(--space-100);
}

.nav-cta {
    font-family: var(--font-display);
    letter-spacing: 0.08em;
}
.nav-cta i { font-size: 14px; }

.nav-brand {
    display: flex;
    align-items: center;
    gap: var(--space-75);
    font-family: var(--font-display);
    font-size: 1rem;
    line-height: 24px;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--gold);
    text-decoration: none;
    white-space: nowrap;
}
.nav-brand-mark {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
    border-radius: var(--radius-lg);
    background: rgba(240, 180, 41, 0.14);
    border: 1px solid rgba(240, 180, 41, 0.35);
    font-size: 0.75rem;
    line-height: 16px;
}

.nav-links {
    display: flex;
    align-items: center;
    gap: var(--space-75);
    list-style: none;

}

.nav-link {
    display: block;
    font-size: 0.875rem;
    line-height: 20px;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    padding: var(--space-75) var(--space-100);
    border-radius: var(--radius-full);
    white-space: nowrap;
    transition: color 700ms var(--ease-fluid), background 700ms var(--ease-fluid), transform 300ms var(--ease-fluid);
}
.nav-link:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.05); }
.nav-link:active { transform: translateY(1px); }
.nav-link[aria-current="page"] { color: var(--gold); background: rgba(240, 180, 41, 0.1); }

/* ปุ่มแฮมเบอร์เกอร์ที่หมุนเป็นกากบาท */
.nav-toggle {
    display: none;
    position: relative;
    width: 36px;
    height: 36px;
    border: 1px solid var(--border-color);
    border-radius: var(--radius-full);
    background: transparent;
    cursor: pointer;
    transition: border-color 700ms var(--ease-fluid), background 700ms var(--ease-fluid);
}
.nav-toggle:hover { background: rgba(255, 255, 255, 0.05); border-color: var(--border-accent); }
.nav-toggle-bar {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 16px;
    height: 1.5px;
    margin-left: -8px;
    border-radius: var(--radius-full);
    background: var(--text-primary);
    transition: transform 700ms var(--ease-fluid);
}
.nav-toggle-bar:nth-of-type(1) { transform: translateY(-4px); }
.nav-toggle-bar:nth-of-type(2) { transform: translateY(4px); }
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-of-type(1) { transform: rotate(45deg); }
.nav-toggle[aria-expanded="true"] .nav-toggle-bar:nth-of-type(2) { transform: rotate(-45deg); }

/* เมนูเต็มจอบนมือถือ */
.nav-overlay {
    position: fixed;
    inset: 0;
    z-index: 99;
    display: grid;
    place-items: center;
    background: rgba(10, 13, 19, 0.82);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 700ms var(--ease-fluid), visibility 700ms var(--ease-fluid);
}
.nav-overlay.open { opacity: 1; visibility: visible; }

.nav-overlay-list {
    list-style: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: var(--space-300);
}
.nav-overlay-list a {
    display: block;
    font-family: var(--font-display);
    font-size: 1.875rem;
    line-height: 36px;
    font-weight: 600;
    color: var(--text-primary);
    text-decoration: none;
    opacity: 0;
    transform: translateY(48px);
    transition: opacity 800ms var(--ease-fluid), transform 800ms var(--ease-fluid), color 400ms var(--ease-fluid);
}
.nav-overlay-list a:hover { color: var(--gold); }
.nav-overlay.open .nav-overlay-list a { opacity: 1; transform: translateY(0); }
.nav-overlay.open .nav-overlay-list li:nth-child(1) a { transition-delay: 100ms; }
.nav-overlay.open .nav-overlay-list li:nth-child(2) a { transition-delay: 150ms; }
.nav-overlay.open .nav-overlay-list li:nth-child(3) a { transition-delay: 200ms; }
.nav-overlay.open .nav-overlay-list li:nth-child(4) a { transition-delay: 250ms; }
.nav-overlay.open .nav-overlay-list li:nth-child(5) a { transition-delay: 300ms; }

/* ===== ปุ่ม ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: var(--space-75);
    font-family: var(--font-body);
    font-size: 1rem;
    line-height: 24px;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    border: 1px solid transparent;
    border-radius: var(--radius-full);
    padding: var(--space-100) var(--space-300);
    transition: transform 700ms var(--ease-fluid), background 700ms var(--ease-fluid), border-color 700ms var(--ease-fluid), color 700ms var(--ease-fluid);
}
.btn:active { transform: scale(0.98); }
.btn svg { width: 18px; height: 18px; flex-shrink: 0; }

.btn-primary { background: var(--gold); color: #0a0d13; }
.btn-primary:hover { background: var(--gold-light); transform: translateY(-2px); }

.btn-ghost {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--border-color);
    color: var(--text-primary);
}
.btn-ghost:hover { background: rgba(255, 255, 255, 0.08); border-color: var(--border-accent); transform: translateY(-2px); }

.btn-discord { background: var(--discord); color: #ffffff; }
.btn-discord:hover { background: #4752d4; transform: translateY(-2px); }

.btn-line { background: var(--line-green); color: #05270f; }
.btn-line:hover { background: #05b04c; transform: translateY(-2px); }

.btn-sm { font-size: 0.875rem; line-height: 20px; padding: var(--space-75) var(--space-100); }

.btn[aria-disabled="true"],
.btn:disabled { opacity: 0.4; pointer-events: none; cursor: not-allowed; }

/* ===== เอฟเฟกต์ตอนเลื่อนเข้ามาในจอ ===== */
.reveal {
    opacity: 0;
    transform: translateY(64px);
    filter: blur(6px);
    transition: opacity 800ms var(--ease-fluid), transform 800ms var(--ease-fluid), filter 800ms var(--ease-fluid);
}
.reveal.visible { opacity: 1; transform: translateY(0); filter: blur(0); }

@keyframes float {
    0%, 100% { transform: translateY(0); }
    50% { transform: translateY(-10px); }
}
@keyframes particle-rise {
    /* เริ่มที่ขอบล่างพอดีและสว่างเต็มใน 4% ของรอบ จะได้เห็นว่าโผล่จากล่างสุดจริง
       เดิมเริ่มที่ scale(0) และค่อยสว่างถึง 10% จุดแสงจึงเหมือนโผล่กลางจอ */
    0% { transform: translateY(0) scale(0.7); opacity: 0; }
    4% { opacity: 1; }
    88% { opacity: 1; }
    100% { transform: translateY(-100vh) scale(1); opacity: 0; }
}


/* ===== Footer แบ่งเป็นคอลัมน์ ===== */
.footer {
    border-top: 1px solid var(--border-color);
    background: var(--bg-section);
    color: var(--text-secondary);
    font-size: 0.875rem;
    line-height: 20px;
}

.footer-inner {
    width: 100%;
    max-width: var(--shell-max);
    margin: 0 auto;
    padding: var(--space-700) var(--space-300) var(--space-600);
    /* คอลัมน์แบรนด์กว้างกว่า เพราะมีคำบรรยายด้วย */
    display: grid;
    grid-template-columns: 1.6fr 1fr 1fr;
    gap: var(--space-600) var(--space-400);
}

.footer-logo {
    font-family: var(--font-display);
    font-size: 1.25rem;
    line-height: 28px;
    font-weight: 700;
    color: var(--gold);
    letter-spacing: 0.08em;
    margin-bottom: var(--space-100);
}

.footer-tagline {
    color: var(--text-secondary);
    max-width: 320px;
}

.footer-heading {
    font-size: 0.75rem;
    line-height: 16px;
    font-weight: 600;
    color: var(--text-primary);
    text-transform: uppercase;
    letter-spacing: 0.14em;
    margin-bottom: var(--space-200);
}

.footer-col ul {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: var(--space-100);
}

.footer-col a {
    display: inline-flex;
    align-items: center;
    gap: var(--space-75);
    width: max-content;
    color: var(--text-secondary);
    text-decoration: none;
    transition: color 400ms var(--ease-fluid), transform 400ms var(--ease-fluid);
}
.footer-col a:hover { color: var(--gold); transform: translateX(2px); }
.footer-col a i { font-size: 14px; line-height: 1; }

.footer-bottom {
    border-top: 1px solid var(--border-color);
}

.footer-bottom-inner {
    width: 100%;
    max-width: var(--shell-max);
    margin: 0 auto;
    padding: var(--space-300);
    display: flex;
    flex-wrap: wrap;
    justify-content: space-between;
    gap: var(--space-100) var(--space-300);
    color: var(--text-muted);
    font-size: 0.75rem;
    line-height: 16px;
}

@media (max-width: 860px) {
    .footer-inner {
        grid-template-columns: 1fr 1fr;
        padding: var(--space-600) var(--space-200) var(--space-500);
        gap: var(--space-500) var(--space-300);
    }
    /* คอลัมน์แบรนด์กินเต็มแถวบนจอแคบ */
    .footer-brand { grid-column: 1 / -1; }
    .footer-bottom-inner { padding: var(--space-300) var(--space-200); }
}

/* ===== ไอคอนสำรองเมื่อโหลดรูปไม่สำเร็จ ===== */
.img-fallback {
    width: 100%;
    height: 100%;
    display: grid;
    place-items: center;
    font-size: 1.25rem;
    line-height: 28px;
    background: var(--bg-card-hover);
    border-radius: var(--radius-lg);
}

@media (max-width: 860px) {
    .nav-links { display: none; }
    .nav-toggle { display: block; }
    .site-nav-inner { grid-template-columns: auto 1fr; gap: var(--space-200); }
    .site-nav-inner > .nav-actions { grid-column: 2; }
}

/* จอแคบมาก เหลือแค่แบรนด์กับปุ่มเมนู ส่วน WC3TH ไปอยู่ในเมนูเต็มจอแทน */
@media (max-width: 560px) {
    .nav-cta { display: none; }
}

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
        scroll-behavior: auto !important;
    }
    .reveal { opacity: 1; transform: none; filter: none; }
}

/* --- ไอคอน Phosphor ในเมนู (ใช้เป็นฟอนต์) --- */
.nav-brand-mark i { font-size: 14px; line-height: 1; }
.btn i { font-size: 18px; line-height: 1; }

.nav-overlay-list a[aria-current="page"] { color: var(--gold); }

/* ทุกหน้าสูงอย่างน้อยเต็มจอ เพื่อไม่ให้ขอบ footer โผล่มาตั้งแต่ยังไม่เลื่อน */
main {
    min-height: 100vh;
    min-height: 100svh;
}

/* ซ่อนจากสายตาแต่ยังอ่านได้ด้วยโปรแกรมอ่านหน้าจอและเครื่องมือค้นหา */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* ===== แถบแท็บใต้เมนู ใช้ทั้งหน้า patch และหน้า unit ===== */
.toc-nav {
    position: sticky;
    /* เริ่มต้นอยู่ใต้แถบเมนูพอดี แล้วค่อยหนึบไว้ที่เดิมตอนเลื่อน */
    margin-top: 64px;
    top: 64px;
    z-index: 90;
    background: rgba(10, 13, 19, 0.92);
    backdrop-filter: blur(20px);
    border-bottom: 1px solid var(--border-color);
    padding: 0;
}

.toc-nav-inner {
    /* กว้างและมีขอบในเท่าแถบเมนูด้านบน เพื่อให้ขอบซ้ายตรงกัน
       สามช่องเหมือนแถบเมนู ปุ่มกลับชิดซ้าย แท็บอยู่กลางจอ */
    width: 100%;
    max-width: var(--page-max);
    margin: 0 auto;
    padding: 0 var(--space-300);
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    align-items: stretch;
    gap: var(--space-300);
}
/* ระบุช่องไว้ชัดเจน หน้าที่ไม่มีปุ่มกลับ แท็บก็ยังอยู่กลางจอ */
.toc-nav-inner > .toc-back { grid-column: 1; justify-self: start; }
.toc-nav-inner > .toc-links { grid-column: 2; justify-self: center; min-width: 0; max-width: 100%; }

.toc-back {
    display: flex;
    align-items: center;
    gap: var(--space-75);
    flex-shrink: 0;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
    text-decoration: none;
    white-space: nowrap;
    border-bottom: 2px solid transparent;
    transition: color 400ms var(--ease-fluid);
}
.toc-back:hover { color: var(--gold); }
.toc-back i { font-size: 15px; line-height: 1; }

.toc-links {
    display: flex;
    align-items: stretch;
    gap: var(--space-300);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.toc-links::-webkit-scrollbar { display: none; }

.toc-link {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    padding: var(--space-200) 0;
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
    text-decoration: none;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    border-bottom: 2px solid transparent;
    transition: color 400ms var(--ease-fluid), border-color 400ms var(--ease-fluid);
    white-space: nowrap;
}

.toc-link:hover, .toc-link.active {
    color: var(--gold);
    border-bottom-color: var(--gold);
}

/* หัวข้อที่แถบแท็บเลื่อนไปหา ต้องเว้นที่ให้เมนูกับแถบแท็บที่ลอยอยู่ */
.section { scroll-margin-top: 140px; }

@media (max-width: 768px) {
    .toc-nav-inner { padding: 0 var(--space-200); gap: var(--space-200); }
    .toc-links { gap: var(--space-200); }
    .toc-link { padding: var(--space-100) 0; font-size: 0.72rem; }
    .toc-back span { display: none; }
}
