:root {
    --primary-color: #000000;
    --secondary-color: #ffffff;
    --accent-color: #3b82f6;
    --text-primary: #1f2937;
    --text-secondary: #6b7280;
    --border-color: #e5e7eb;
    --bg-light: #f9fafb;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.07);
    --shadow-lg: 0 10px 15px rgba(0, 0, 0, 0.1);
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

html,
body {
    overflow-x: hidden;
    width: 100%;
}

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    color: var(--text-primary);
    background-color: var(--secondary-color);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

/* =====================
   HEADER
   ===================== */
.header {
    background: rgba(255, 255, 255, 0.9);
    border-bottom: 1px solid var(--border-color);
    padding: 20px 0;
    position: sticky;
    top: 0;
    z-index: 201;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
}

.header .container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 16px;
}

.logo {
    font-size: 24px;
    font-weight: 700;
    color: var(--primary-color);
    letter-spacing: -0.5px;
    flex-shrink: 0;
    position: relative;
    z-index: 201;

}

nav {
    display: flex;
    gap: 32px;
}

.nav-link {
    color: var(--text-secondary);
    text-decoration: none;
    font-weight: 500;
    font-size: 14px;
    transition: var(--transition);
    position: relative;
}

.nav-link::after {
    content: '';
    position: absolute;
    bottom: -4px;
    left: 0;
    width: 0;
    height: 2px;
    background: var(--primary-color);
    transition: var(--transition);
}

.nav-link:hover {
    color: var(--primary-color);
}

.nav-link:hover::after {
    width: 100%;
}

/* =====================
   HERO SECTION
   ===================== */
.hero {
    padding: 80px 0 60px;
    text-align: center;
    background: linear-gradient(to bottom, var(--bg-light), var(--secondary-color));
}

.hero-title {
    font-size: clamp(28px, 5vw, 48px);
    font-weight: 700;
    margin-bottom: 16px;
    letter-spacing: -1px;
    line-height: 1.15;
}

.hero-subtitle {
    font-size: clamp(14px, 2vw, 18px);
    color: var(--text-secondary);
    font-weight: 400;
    max-width: 600px;
    margin: 0 auto;
    padding: 0 16px;
}

/* =====================
   PORTFOLIO SECTION
   ===================== */
.portfolio-section {
    padding: 60px 0 100px;
}

.portfolio-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 32px;
}

.portfolio-item {
    background: var(--secondary-color);
    border-radius: 12px;
    overflow: hidden;
    cursor: pointer;
    transition: var(--transition);
    border: 1px solid var(--border-color);
}

.portfolio-item:hover {
    transform: translateY(-4px);
    box-shadow: var(--shadow-lg);
}

.portfolio-image {
    position: relative;
    width: 100%;
    padding-top: 75%;
    overflow: hidden;
    background: var(--bg-light);
}

.portfolio-image img {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    object-fit: cover;
    transition: var(--transition);
}

.portfolio-item:hover .portfolio-image img {
    transform: scale(1.05);
}

.portfolio-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0;
    transition: var(--transition);
}

.portfolio-item:hover .portfolio-overlay {
    opacity: 1;
}

.view-details {
    color: var(--secondary-color);
    font-weight: 600;
    font-size: 14px;
    padding: 12px 24px;
    border: 2px solid var(--secondary-color);
    border-radius: 6px;
    transition: var(--transition);
}

.view-details:hover {
    background: var(--secondary-color);
    color: var(--primary-color);
}

.portfolio-info {
    padding: 20px;
}

.portfolio-title {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 8px;
    color: var(--text-primary);
}

.portfolio-category {
    display: inline-block;
    font-size: 12px;
    color: var(--text-secondary);
    background: var(--bg-light);
    padding: 4px 12px;
    border-radius: 12px;
    font-weight: 500;
}

/* =====================
   MODAL
   ===================== */
.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    inset: 0;
    background: rgba(0, 0, 0, 0.75);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
    padding: 48px 24px;
}

@keyframes fadeIn {
    from {
        opacity: 0;
    }

    to {
        opacity: 1;
    }
}

@keyframes slideUp {
    from {
        transform: translateY(50px);
        opacity: 0;
    }

    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-content {
    position: relative;
    background: var(--secondary-color);
    margin: 0 auto;
    width: 100%;
    max-width: 780px;
    border-radius: 16px;
    animation: slideUp 0.3s ease;
    /* สูงตามเนื้อหา ไม่ยืดเต็มจอ */
    align-self: flex-start;
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 20px;
    font-size: 32px;
    font-weight: 300;
    color: var(--text-secondary);
    cursor: pointer;
    z-index: 1001;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    transition: var(--transition);
    line-height: 1;
}

.modal-close:hover {
    background: var(--bg-light);
    color: var(--primary-color);
}

.modal-body {
    padding: 0;
    display: flex;
    flex-direction: column;
    height: auto;
}

.modal-carousel {
    position: relative;
    width: 100%;
    background: #000;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 400px;
    border-radius: 16px 16px 0 0;
    overflow: hidden;
}

.carousel-container {
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
}

.modal-image {
    max-width: 100%;
    max-height: 70vh;
    object-fit: contain;
    transition: var(--transition);
}

.carousel-btn {
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    background: rgba(255, 255, 255, 0.2);
    color: white;
    border: none;
    width: 50px;
    height: 50px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: var(--transition);
    z-index: 10;
    backdrop-filter: blur(4px);
}

.carousel-btn:hover {
    background: rgba(255, 255, 255, 0.4);
}

.carousel-btn.prev {
    left: 20px;
}

.carousel-btn.next {
    right: 20px;
}

.carousel-dots {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    gap: 8px;
    z-index: 10;
}

.dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.3);
    cursor: pointer;
    transition: var(--transition);
}

.dot.active {
    background: white;
    transform: scale(1.2);
}

.modal-info-content {
    padding: 40px;
}

.modal-description {
    white-space: pre-wrap;
    word-break: break-word;
    margin-bottom: 24px;
    color: var(--text-primary);
    line-height: 1.7;
    font-size: 15px;
}

.modal-header-flex {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    gap: 20px;
    margin-bottom: 20px;
}

.modal-meta {
    margin-bottom: 20px;
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
}

.tech-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 16px;
}

.tech-tag {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 12px;
    background: var(--bg-light);
    color: var(--text-secondary);
    border-radius: 4px;
    border: 1px solid var(--border-color);
}

.project-date {
    font-size: 14px;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 6px;
}

.external-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 12px 24px;
    background: var(--primary-color);
    color: white;
    text-decoration: none;
    border-radius: 8px;
    font-weight: 600;
    transition: var(--transition);
    white-space: nowrap;
}

.external-btn:hover {
    background: var(--accent-color);
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
}

.no-items {
    grid-column: 1 / -1;
    text-align: center;
    padding: 60px 20px;
    color: var(--text-secondary);
}

/* =====================
   HAMBURGER MENU
   ===================== */
.menu-toggle {
    display: none;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
    width: 44px;
    height: 44px;
    background: none;
    border: none;
    cursor: pointer;
    padding: 8px;
    z-index: 201;
    /* ป้องกัน tap highlight บน iOS */
    -webkit-tap-highlight-color: transparent;
}

.menu-toggle span {
    display: block;
    width: 100%;
    height: 2px;
    background: var(--primary-color);
    border-radius: 2px;
    transition: var(--transition);
    transform-origin: center;
}

.menu-toggle.active span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 5px);
}

.menu-toggle.active span:nth-child(2) {
    opacity: 0;
    transform: scaleX(0);
}

.menu-toggle.active span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, -5px);
}

/* =====================
   NAV OVERLAY
   ===================== */
.nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    z-index: 150;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s ease, visibility 0.3s ease;
    pointer-events: none;
}

.nav-overlay.active {
    opacity: 1;
    visibility: visible;
    /* คง pointer-events: auto ไว้เพื่อให้คลิกที่พื้นที่ว่างแล้วปิดเมนูได้ 
       แต่ต้องให้ nav มี z-index สูงกว่า */
    pointer-events: auto; 
}

/* =====================
   RESPONSIVE — Tablet Landscape (≤ 1024px)
   ===================== */
@media (max-width: 1024px) {
    .container {
        padding: 0 20px;
    }

    .hero {
        padding: 60px 0 40px;
    }

    .portfolio-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 24px;
    }

    .portfolio-section {
        padding: 40px 0 80px;
    }

    .modal-content {
        max-width: 720px;
    }

    .modal-info-content {
        padding: 28px 32px;
    }
}

/* =====================
   RESPONSIVE — Tablet Portrait (≤ 768px)
   ===================== */
@media (max-width: 768px) {

    /* Header */
    .header {
        padding: 14px 0;
    }

    .logo {
        font-size: 20px;
    }

    .menu-toggle {
        display: flex;
    }

    /* Mobile nav — dropdown จากข้างบน */
    nav {
        position: fixed;
        top: 0;
        left: 0;
        width: 100%;
        height: auto;
        background: var(--secondary-color);
        flex-direction: column;
        /* padding-top = ความสูง header โดยประมาณ */
        padding: 68px 24px 16px;
        gap: 0;
        z-index: 200;
        /* ต่ำกว่า header (100) เพื่อให้ header ทับ nav */
        /* ซ่อนขึ้นบนโดย translate + clip กัน shadow รั่ว */
        transform: translateY(-100%);
        transition: transform 0.35s cubic-bezier(0.4, 0, 0.2, 1);
        visibility: hidden;
        /* shadow โผล่เฉพาะข้างล่าง */
        box-shadow: 0 8px 20px rgba(0, 0, 0, 0.12);
    }

    nav.active {
        transform: translateY(0);
        visibility: visible;
    }

    .nav-link {
        font-size: 16px;
        padding: 16px 0;
        border-bottom: 1px solid var(--border-color);
        display: block;
        width: 100%;
        color: var(--text-primary);
    }

    .nav-link:last-child {
        border-bottom: none;
    }

    .nav-link::after {
        bottom: 0;
    }

    /* Hero */
    .hero {
        padding: 48px 0 32px;
    }

    /* Portfolio */
    .portfolio-section {
        padding: 32px 0 60px;
    }

    .portfolio-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 16px;
    }

    .portfolio-info {
        padding: 14px 16px;
    }

    .portfolio-title {
        font-size: 15px;
    }

    /* Modal — เว้นขอบรอบด้านให้พอดี */
    .modal {
        /* เปลี่ยนจาก center เป็น flex-start เพื่อให้ modal เริ่มวางจากด้านบน */
        align-items: flex-start;
        /* เพิ่ม padding-top เพื่อเว้นระยะจากขอบบนจอ */
        padding: 60px 16px 24px;
        overflow-y: auto;
    }

    .modal-content {
        /* ลบ margin-bottom ออกเล็กน้อยถ้าจำเป็น */
        margin-bottom: 20px;
    }

    .modal-carousel {
        min-height: 260px;
        border-radius: 12px 12px 0 0;
    }

    .modal-image {
        max-height: 45vh;
    }

    .carousel-btn {
        width: 40px;
        height: 40px;
        font-size: 18px;
    }

    .carousel-btn.prev {
        left: 10px;
    }

    .carousel-btn.next {
        right: 10px;
    }

    .modal-info-content {
        padding: 24px 20px;
    }

    .modal-header-flex {
        flex-direction: column;
        gap: 12px;
        align-items: stretch;
    }

    .modal-title {
        font-size: 22px;
    }

    .modal-close {
        top: 10px;
        right: 12px;
        font-size: 28px;
        width: 34px;
        height: 34px;
    }

    .external-btn {
        width: 100%;
        justify-content: center;
        padding: 12px 20px;
        font-size: 14px;
    }

    .view-details {
        font-size: 13px;
        padding: 10px 20px;
    }
}

/* =====================
   RESPONSIVE — Small Mobile (≤ 480px)
   ===================== */
@media (max-width: 480px) {
    .container {
        padding: 0 14px;
    }

    /* Header */
    .header {
        padding: 12px 0;
    }

    .logo {
        font-size: 18px;
    }

    /* Hero */
    .hero {
        padding: 36px 0 24px;
    }

    /* Portfolio — single column */
    .portfolio-grid {
        grid-template-columns: 1fr;
        gap: 14px;
    }

    .portfolio-item:hover {
        transform: none;
        /* ปิด hover lift บน touch */
    }

    .portfolio-image {
        padding-top: 60%;
    }

    .portfolio-info {
        padding: 12px 14px;
    }

    .portfolio-title {
        font-size: 15px;
        margin-bottom: 5px;
    }

    .portfolio-category {
        font-size: 11px;
        padding: 3px 10px;
    }

    /* Modal — เว้นขอบรอบด้าน ไม่เต็มจอ */
    .modal {
        /* เว้นระยะด้านบนให้มากขึ้นสำหรับมือถือเล็ก */
        padding: 100px 12px 20px;
        align-items: flex-start;
    }

    .modal-content {
        min-height: unset;
        border-radius: 12px;
    }

    .modal-carousel {
        min-height: 220px;
        border-radius: 12px 12px 0 0;
    }

    .modal-image {
        max-height: 38vh;
    }

    .carousel-dots {
        bottom: 10px;
    }

    .dot {
        width: 7px;
        height: 7px;
    }

    .carousel-btn {
        width: 36px;
        height: 36px;
        font-size: 16px;
    }

    .modal-info-content {
        padding: 18px 14px 32px;
    }

    .modal-title {
        font-size: 19px;
        line-height: 1.3;
    }

    .modal-description {
        font-size: 14px;
        line-height: 1.75;
    }

    .tech-tag {
        font-size: 11px;
        padding: 3px 10px;
    }

    /* close button ลอยบน dark bg */
    .modal-close {
        top: 10px;
        right: 10px;
        background: rgba(255, 255, 255, 0.9); /* ให้เด่นตัดกับรูปภาพ */
        color: var(--primary-color);
        box-shadow: var(--shadow-md);
    }

    .modal-close:hover {
        background: rgba(0, 0, 0, 0.75);
        color: white;
    }

    .project-date {
        font-size: 13px;
    }

    .modal-meta {
        gap: 8px;
    }

    .tech-tags {
        gap: 6px;
    }
}