/* ---------- CSS Variables ---------- */
:root {
    --bg-primary: #F8F9FA;
    --bg-surface: #FFFFFF;
    --text-primary: #1A1A1A;
    --text-secondary: #6B7280;
    --text-tertiary: #9CA3AF;
    --accent: #E11D48;
    --accent-hover: #C8192DBF;
    --accent-subtle: #FDF2F4;
    --border: #E5E7EB;
    --border-light: #F3F4F6;
    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.07), 0 2px 4px -1px rgba(0, 0, 0, 0.04);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.08), 0 4px 6px -2px rgba(0, 0, 0, 0.04);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --transition-fast: 150ms ease;
    --transition-normal: 250ms ease;
}

/* ---------- Font Import ---------- */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600&display=swap');

/* ---------- Reset & Base ---------- */
*, *::before, *::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
    -ms-text-size-adjust: 100%;
}

body {
    background-color: var(--bg-primary);
    padding-top: 64px;
    font-family: 'Inter', -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, "Noto Sans SC", sans-serif;
    font-size: 14px;
    color: var(--text-primary);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

a {
    text-decoration: none !important;
    color: inherit;
    transition: color var(--transition-fast);
}

ul {
    list-style: none;
}

img {
    border: 0;
    vertical-align: middle;
}

/* ---------- Container ---------- */
.container {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

.clearfix::after {
    content: "";
    display: table;
    clear: both;
}

/* ========================================
   Navigation Bar
   ======================================== */
.navbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 1000;
    height: 64px;
    background: rgba(255, 255, 255, 0.85);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.nav-container {
    display: flex;
    align-items: center;
    height: 64px;
    max-width: 1200px;
    padding: 0 24px;
    position: relative;
}

/* ---------- Brand / Logo ---------- */
.navbar-brand {
    font-family: Georgia, "Noto Serif SC", "Songti SC", serif;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-right: 24px;
    white-space: nowrap;
    flex-shrink: 0;
    user-select: none;
}

.brand-jav {
    color: var(--text-primary);
}

.brand-bus {
    color: var(--accent);
}

/* ---------- Hamburger Toggle (hidden on desktop) ---------- */
.nav-toggle {
    display: none;
}

.nav-toggle-label {
    display: none;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 40px;
    height: 40px;
    cursor: pointer;
    flex-shrink: 0;
    border-radius: var(--radius-sm);
    transition: background-color var(--transition-fast);
}

.nav-toggle-label:hover {
    background-color: var(--border-light);
}

.nav-toggle-label span {
    display: block;
    width: 20px;
    height: 2px;
    background: var(--text-primary);
    margin: 2px 0;
    border-radius: 1px;
    transition: all 0.3s;
}

/* Hamburger animation when checked */
.nav-toggle:checked + .nav-toggle-label span:nth-child(1) {
    transform: rotate(45deg) translate(5px, 0);
}

.nav-toggle:checked + .nav-toggle-label span:nth-child(2) {
    opacity: 0;
}

.nav-toggle:checked + .nav-toggle-label span:nth-child(3) {
    transform: rotate(-45deg) translate(5px, 0);
}

/* ---------- Nav Collapse ---------- */
.nav-collapse {
    display: flex;
    align-items: center;
    flex: 1;
    gap: 12px;
    min-width: 0;
}

/* ---------- Search Form ---------- */
.navbar-form {
    display: flex;
    align-items: center;
    flex: 1 1 auto;
    max-width: 420px;
    min-width: 0;
    margin-left: auto;
}

.navbar-form .form-group {
    display: flex;
    width: 100%;
    align-items: center;
    background: var(--bg-primary);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
    overflow: hidden;
    transition: border-color var(--transition-fast), box-shadow var(--transition-fast);
}

.navbar-form .form-group:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(225, 29, 72, 0.08);
}

.form-control {
    flex: 1;
    min-width: 0;
    height: 40px;
    padding: 0 16px;
    font-size: 14px;
    color: var(--text-primary);
    background: transparent;
    border: none;
    outline: none;
    font-family: inherit;
}

.form-control::placeholder {
    color: var(--text-tertiary);
}

.btn-search {
    height: 40px;
    padding: 0 20px;
    font-size: 14px;
    font-weight: 500;
    color: #FFF;
    background-color: var(--accent);
    border: none;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    flex-shrink: 0;
    transition: background-color var(--transition-fast);
}

.btn-search:hover {
    background-color: var(--accent-hover);
}

/* ---------- Nav Links ---------- */
.nav {
    display: flex;
    align-items: center;
    gap: 4px;
    flex-shrink: 0;
}

.navbar-nav {
    display: flex;
    align-items: center;
    gap: 4px;
}

/* Nav Buttons */
.btn-nav {
    display: block;
    padding: 8px 16px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    background: transparent;
    border: none;
    cursor: pointer;
    font-family: inherit;
    white-space: nowrap;
    border-radius: var(--radius-sm);
    transition: color var(--transition-fast), background-color var(--transition-fast);
}

.btn-nav:hover {
    color: var(--text-primary);
    background-color: var(--border-light);
}

/* ========================================
   Waterfall Grid - CSS Grid Layout
   ======================================== */
#wrapper {
    padding: 28px 0;
}

#waterfall {
    margin: 0 auto;
    display: grid;
    grid-template-columns: repeat(6, 1fr);
    gap: 20px;
    justify-content: center;
}

/* ---------- Movie Card ---------- */
.movie-box {
    display: block;
    background-color: var(--bg-surface);
    overflow: hidden;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-light);
    transition: box-shadow var(--transition-normal), transform var(--transition-normal), border-color var(--transition-normal);
}

.movie-box:hover {
    box-shadow: var(--shadow-lg);
    transform: translateY(-4px);
    border-color: transparent;
}

.item-link {
    display: block;
    color: var(--text-primary);
}

/* Photo Frame */
.photo-frame {
    overflow: hidden;
    width: calc(100% - 16px);
    margin: 8px 8px 0 8px;
    border-radius: var(--radius-md);
    aspect-ratio: 3 / 4;
    background: var(--border-light);
}

.photo-frame img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    display: block;
    transition: transform 0.4s ease;
}

.movie-box:hover .photo-frame img {
    transform: scale(1.06);
}

/* Card Content */
.item-content {
    padding: 12px 12px 14px 12px;
}

.item-title {
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    text-overflow: ellipsis;
    word-wrap: break-word;
    font-size: 13px;
    font-weight: 500;
    color: var(--text-primary);
    line-height: 1.5;
    min-height: 40px;
}

/* Meta (Code + Date) */
.item-meta {
    display: flex;
    align-items: center;
    gap: 8px;
    margin-top: 8px;
    font-size: 12px;
}

.item-code {
    display: inline-block;
    padding: 2px 8px;
    font-size: 11px;
    font-weight: 600;
    color: var(--accent);
    background-color: var(--accent-subtle);
    border-radius: 20px;
    letter-spacing: 0.02em;
}

.item-date {
    color: var(--text-secondary);
    font-size: 12px;
}

/* Visited links */
.item a:visited .item-title {
    color: var(--text-tertiary);
}

/* ========================================
   Pagination
   ======================================== */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
    padding: 32px 0;
    flex-wrap: wrap;
}

.pagination li {
    display: inline-block;
}

.pagination li a {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 40px;
    height: 40px;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-secondary);
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    transition: all var(--transition-fast);
}

.pagination li a:hover {
    color: var(--accent);
    border-color: var(--accent);
    background-color: var(--accent-subtle);
}

.pagination li.active a {
    color: #FFF;
    background-color: var(--accent);
    border-color: var(--accent);
    cursor: default;
}

/* ========================================
   Footer
   ======================================== */
.footer {
    padding: 32px 0;
    color: var(--text-secondary);
    background: #111827;
    text-align: center;
    margin-top: auto;
}

.footer a {
    color: #9CA3AF;
    margin: 0 12px;
    font-size: 13px;
    transition: color var(--transition-fast);
}

.footer a:hover {
    color: #FFF;
}

.footer-links {
    margin-bottom: 16px;
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 8px;
}

.footer-copy {
    font-size: 12px;
    color: #4B5563;
}

/* ========================================
   Responsive — Tablet (≤ 991px)
   ======================================== */
@media screen and (max-width: 991px) {
    .navbar-form {
        max-width: 280px;
    }

    .btn-nav {
        padding: 8px 12px;
        font-size: 13px;
    }

    /* Grid: smaller minmax for tablet */
    #waterfall {
        grid-template-columns: repeat(auto-fill, minmax(155px, 1fr));
        gap: 16px;
    }
}

/* ========================================
   Responsive — Small Tablet / Mobile (≤ 767px)
   ======================================== */
@media screen and (max-width: 767px) {
    body {
        padding-top: 56px;
    }

    .navbar {
        height: 56px;
        background: rgba(255, 255, 255, 0.95);
    }

    .nav-container {
        flex-wrap: nowrap;
        height: 56px;
        padding: 0 16px;
    }

    /* Show hamburger */
    .nav-toggle-label {
        display: flex;
        order: 3;
        margin-left: auto;
    }

    .navbar-brand {
        font-size: 22px;
        margin-right: 0;
        order: 1;
    }

    /* Collapse nav into dropdown panel */
    .nav-collapse {
        position: absolute;
        top: 56px;
        left: 0;
        right: 0;
        flex-direction: column;
        align-items: stretch;
        background: var(--bg-surface);
        border-top: 2px solid var(--border);
        box-shadow: 0 8px 24px rgba(0, 0, 0, 0.12);
        padding: 0;
        gap: 0;
        max-height: 0;
        overflow: hidden;
        transition: max-height 0.3s ease;
        z-index: 999;
    }

    .nav-toggle:checked ~ .nav-collapse {
        max-height: 500px;
        overflow-y: auto;
    }

    /* Search section */
    .navbar-form {
        max-width: none;
        padding: 16px;
        margin-left: 0;
        border-bottom: 8px solid var(--bg-primary);
    }

    .navbar-form .form-group {
        background: var(--bg-primary);
        border: none;
    }

    .form-control {
        height: 44px;
        font-size: 16px;
        padding: 0 16px;
    }

    .btn-search {
        height: 44px;
        padding: 0 24px;
        font-size: 16px;
    }

    /* Nav links section */
    .nav {
        padding: 8px 0;
        background: var(--bg-surface);
    }

    .navbar-nav {
        display: flex;
        flex-direction: column;
        gap: 0;
    }

    .navbar-nav > li {
        border-bottom: 1px solid var(--border-light);
    }

    .navbar-nav > li:last-child {
        border-bottom: none;
    }

    .btn-nav {
        display: block;
        width: 100%;
        padding: 16px;
        font-size: 16px;
        font-weight: 500;
        color: var(--text-primary);
        text-align: left;
        border-radius: 0;
        border: none;
        background: transparent;
        transition: background-color var(--transition-fast), color var(--transition-fast);
    }

    .btn-nav:hover,
    .btn-nav:active {
        background-color: var(--bg-primary);
        color: var(--accent);
    }

    /* Icons for nav buttons */
    .navbar-nav > li:nth-child(1) .btn-nav::before {
        content: "⊞";
        margin-right: 10px;
        font-size: 18px;
    }

    .navbar-nav > li:nth-child(2) .btn-nav::before {
        content: "👤";
        margin-right: 10px;
        font-size: 18px;
    }

    /* Grid: 2 columns on mobile */
    #waterfall {
        grid-template-columns: repeat(2, 1fr);
        gap: 12px;
        margin: 0 auto;
        padding: 0 12px;
    }

    .photo-frame {
        width: calc(100% - 12px);
        margin: 6px 6px 0 6px;
        border-radius: var(--radius-sm);
    }

    .item-content {
        padding: 10px 8px 12px 8px;
    }

    .item-title {
        font-size: 12px;
        min-height: 36px;
        line-height: 1.4;
    }

    .item-meta {
        margin-top: 6px;
    }

    .item-code {
        padding: 1px 6px;
        font-size: 10px;
    }

    .item-date {
        font-size: 11px;
    }

    /* Pagination */
    .pagination {
        gap: 4px;
        padding: 24px 0;
    }

    .pagination li a {
        min-width: 36px;
        height: 36px;
        padding: 6px 10px;
        font-size: 13px;
    }

    /* Footer */
    .footer-links {
        flex-direction: column;
        gap: 10px;
    }

    .footer a {
        margin: 0;
    }
}

/* ========================================
   Responsive — Phone (≤ 480px)
   ======================================== */
@media screen and (max-width: 480px) {
    body {
        padding-top: 52px;
    }

    .navbar {
        height: 52px;
    }

    .nav-container {
        height: 52px;
        padding: 0 12px;
    }

    .nav-toggle-label {
        width: 36px;
        height: 36px;
    }

    .nav-toggle-label span {
        width: 18px;
    }

    .navbar-brand {
        font-size: 20px;
    }

    .nav-collapse {
        top: 52px;
    }

    .navbar-form {
        padding: 10px 12px;
    }

    .form-control {
        height: 38px;
        font-size: 14px;
    }

    .btn-search {
        height: 38px;
        padding: 0 18px;
        font-size: 14px;
    }

    /* Grid: 2 columns, tighter gap */
    #waterfall {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
        padding: 0 10px;
    }

    .photo-frame {
        width: calc(100% - 8px);
        margin: 4px 4px 0 4px;
    }

    .item-content {
        padding: 8px 6px 10px 6px;
    }

    .item-title {
        font-size: 11px;
        min-height: 30px;
    }

    .item-meta {
        margin-top: 4px;
    }

    .item-code {
        font-size: 10px;
        padding: 1px 5px;
    }

    .item-date {
        font-size: 10px;
    }

    /* Pagination: compact */
    .pagination {
        gap: 3px;
        padding: 20px 0;
    }

    .pagination li a {
        min-width: 32px;
        height: 32px;
        padding: 4px 8px;
        font-size: 12px;
        border-radius: 4px;
    }

    /* Footer */
    .footer {
        padding: 24px 0;
    }

    .footer a {
        font-size: 12px;
    }

    .footer-copy {
        font-size: 11px;
    }
}

/* ========================================
   Responsive — Large Desktop (≥ 1400px)
   ======================================== */
@media screen and (min-width: 1400px) {
    .container {
        max-width: 1200px;
    }

    #waterfall {
        grid-template-columns: repeat(6, 1fr);
        gap: 20px;
    }
}

/* ========================================
   Accessibility — Touch Targets
   ======================================== */
@media (pointer: coarse) {
    .btn-search,
    .btn-nav,
    .pagination li a {
        min-height: 44px;
    }
}

/* ========================================
   Accessibility — Reduced Motion
   ======================================== */
@media (prefers-reduced-motion: reduce) {
    .movie-box,
    .photo-frame img,
    a {
        transition: none;
    }
}

/* ========================================
   Print Styles
   ======================================== */
@media print {
    .navbar,
    .footer,
    .pagination {
        display: none;
    }

    body {
        padding-top: 0;
        background: #FFF;
    }

    .movie-box {
        box-shadow: none;
        border: 1px solid #DDD;
        break-inside: avoid;
    }
}