:root {
    /* Color Palette */
    --bg-page: #f8fafc;
    --bg-surface: #ffffff;
    --bg-glass: rgba(255, 255, 255, 0.85);
    
    --primary: #0f172a;
    --primary-light: #1e293b;
    --accent: #d97706;
    --accent-hover: #b45309;
    --secondary: #0d9488;
    
    --text-dark: #0f172a;
    --text-main: #334155;
    --text-muted: #64748b;
    
    --border: #e2e8f0;
    --border-focus: #94a3b8;
    
    /* Semantic Colors */
    --danger: #dc2626;
    --danger-bg: #fef2f2;
    --success: #16a34a;
    --warning: #f59e0b;
    
    /* Shadows */
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1), 0 4px 6px -2px rgba(0, 0, 0, 0.05);
    
    /* Typography */
    --font-sans: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", "Microsoft YaHei", Arial, sans-serif;
    --font-serif: "Songti SC", "SimSun", "Microsoft YaHei", serif;
    
    /* Borders & Spacing */
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-full: 9999px;
    
    --transition: all 0.2s cubic-bezier(0.4, 0, 0.2, 1);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    color: var(--text-main);
    background: var(--bg-page);
    font-family: var(--font-sans);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    overflow-x: hidden;
}

a {
    color: var(--accent);
    text-decoration: none;
    transition: var(--transition);
}
a:hover {
    color: var(--accent-hover);
}

/* Layout */
.wrap {
    width: min(1200px, calc(100% - 32px));
    margin: 0 auto;
}

.page {
    padding: 40px 0 60px;
    min-height: calc(100vh - 72px);
}

/* Typography elements */
h1, h2, h3, h4, h5, h6 {
    color: var(--text-dark);
    margin-top: 0;
    font-weight: 600;
}

h1 {
    font-size: 2rem;
    margin-bottom: 1.5rem;
    letter-spacing: -0.025em;
}

/* Header & Nav */
.site-header {
    background: var(--primary);
    color: #fff;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-md);
}

.site-header.admin {
    background: var(--primary-light);
}

.nav {
    display: flex;
    align-items: center;
    justify-content: space-between;
    height: 72px;
}

.brand {
    color: #fff;
    font-size: 22px;
    font-weight: 700;
    letter-spacing: 1px;
}
.brand:hover {
    color: var(--accent);
}

.nav nav {
    display: flex;
    gap: 16px;
    align-items: center;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none; /* Firefox */
}
.nav nav::-webkit-scrollbar {
    display: none; /* Chrome/Safari */
}

.nav nav a {
    color: #cbd5e1;
    font-weight: 500;
    font-size: 0.95rem;
    white-space: nowrap;
}
.nav nav a:hover {
    color: #fff;
}

/* Hero Section */
.hero {
    min-height: 360px;
    display: flex;
    align-items: center;
    padding: 64px 48px;
    color: #fff;
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-light) 100%);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    margin-bottom: 40px;
    position: relative;
    overflow: hidden;
}

.hero::after {
    content: '';
    position: absolute;
    top: 0; right: 0; bottom: 0; left: 0;
    background: radial-gradient(circle at top right, rgba(217, 119, 6, 0.15), transparent 50%);
    pointer-events: none;
}

.hero-content {
    position: relative;
    z-index: 1;
}

.hero h1 {
    color: #fff;
    margin: 0 0 16px;
    font-size: 48px;
    letter-spacing: -0.02em;
}

.hero p {
    max-width: 680px;
    margin: 0 0 32px;
    color: #94a3b8;
    font-size: 1.1rem;
}

/* Grid System */
.grid {
    display: grid;
    gap: 24px;
}
.grid > * {
    min-width: 0;
}
.grid.two { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.grid.three { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.grid.four { grid-template-columns: repeat(4, minmax(0, 1fr)); }

/* Card Component */
.card, .form-card, section:not(.hero) {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 24px;
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    min-width: 0;
    max-width: 100%;
}

.card:hover {
    box-shadow: var(--shadow-md);
    border-color: #cbd5e1;
}

/* Forms & Inputs */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 8px;
    font-weight: 500;
    color: var(--text-dark);
    font-size: 0.95rem;
}

input[type="text"],
input[type="password"],
input[type="email"],
input[type="number"],
input[type="datetime-local"],
input[type="date"],
textarea {
    width: 100%;
    padding: 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--bg-page);
    color: var(--text-dark);
    font: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
}

select {
    width: 100%;
    padding: 10px 36px 10px 14px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background-color: var(--bg-page);
    color: var(--text-dark);
    font: inherit;
    font-size: 0.95rem;
    transition: var(--transition);
    appearance: none;
    -webkit-appearance: none;
    -moz-appearance: none;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='currentColor' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 10px center;
    background-size: 16px;
}

input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
    background-color: var(--bg-surface);
    box-shadow: 0 0 0 3px rgba(217, 119, 6, 0.15);
}

/* Filter Panel */
.filter-panel {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 16px 24px;
    margin-bottom: 24px;
    box-shadow: var(--shadow-sm);
    display: flex;
    gap: 16px;
    align-items: flex-end;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 6px;
}
.filter-group label {
    margin: 0;
    font-size: 0.85rem;
    color: var(--text-muted);
}
.filter-group input, .filter-group select {
    padding: 8px 12px;
    height: 38px;
    min-width: 100px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 10px 20px;
    border: 1px solid transparent;
    border-radius: var(--radius-md);
    font-weight: 500;
    font-size: 0.95rem;
    cursor: pointer;
    transition: var(--transition);
    text-align: center;
}

.btn-primary {
    background: var(--primary);
    color: #fff !important;
    box-shadow: var(--shadow-sm);
}
.btn-primary:hover {
    background: var(--primary-light);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-accent {
    background: var(--accent);
    color: #fff !important;
}
.btn-accent:hover {
    background: var(--accent-hover);
    transform: translateY(-1px);
    box-shadow: var(--shadow-md);
}

.btn-outline {
    background: transparent;
    border-color: var(--border);
    color: var(--text-main) !important;
}
.btn-outline:hover {
    border-color: var(--border-focus);
    background: var(--bg-page);
}

.btn-sm {
    padding: 6px 12px;
    font-size: 0.85rem;
}

/* Lists & Tables */
.list-card {
    display: block;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 20px;
    margin-bottom: 16px;
    transition: var(--transition);
    color: inherit;
    text-decoration: none;
}
.list-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-md);
    border-color: #cbd5e1;
}

.list-card-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 12px;
}

.list-card-title {
    font-size: 1.15rem;
    font-weight: 600;
    color: var(--text-dark);
    margin: 0;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 2px 10px;
    border-radius: var(--radius-full);
    font-size: 0.75rem;
    font-weight: 500;
    background: var(--bg-page);
    color: var(--text-muted);
    border: 1px solid var(--border);
}
.badge.accent {
    background: rgba(217, 119, 6, 0.1);
    color: var(--accent-hover);
    border-color: rgba(217, 119, 6, 0.2);
}
.badge.primary {
    background: rgba(15, 23, 42, 0.05);
    color: var(--primary);
    border-color: rgba(15, 23, 42, 0.1);
}
.badge.danger {
    background: var(--danger-bg);
    color: var(--danger);
    border-color: rgba(220, 38, 38, 0.2);
}

.list-card-meta {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
    font-size: 0.85rem;
    color: var(--text-muted);
    margin-bottom: 12px;
}

.list-card-snippet {
    font-size: 0.95rem;
    color: var(--text-main);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    line-height: 1.5;
}

.table-wrap {
    overflow-x: auto;
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 14px 16px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    white-space: nowrap;
}

td.wrap-text {
    white-space: normal;
    min-width: 250px;
    max-width: 450px;
    line-height: 1.5;
}

th {
    background: var(--bg-page);
    font-weight: 600;
    color: var(--text-dark);
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 0.95rem;
}
.alert-error {
    color: var(--danger);
    background: var(--danger-bg);
    border: 1px solid rgba(220, 38, 38, 0.2);
}
.alert-success {
    color: var(--success);
    background: #f0fdf4;
    border: 1px solid rgba(22, 163, 74, 0.2);
}

/* Pagination */
.pagination {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 32px;
    flex-wrap: wrap;
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 36px;
    height: 36px;
    padding: 0 10px;
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    background: var(--bg-surface);
    color: var(--text-main);
    font-size: 0.9rem;
    font-weight: 500;
}
.page-link:hover {
    border-color: var(--border-focus);
    background: var(--bg-page);
}
.page-link.active {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}
.page-info {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-right: auto;
}

/* Da Liu Ren Classic Chart - Elegant Serif Design */
.liuren-classic {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 40px;
    background: var(--bg-surface);
    color: #1c1917; /* Very dark warm gray */
    font-family: var(--font-serif);
    font-weight: 700;
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    overflow-x: auto;
    border: 1px solid var(--border);
}

.classic-inner {
    min-width: 840px; /* Ensure chart does not wrap on small screens, triggers horizontal scroll instead */
    margin: 0 auto;
}

.classic-meta {
    font-size: 32px;
    line-height: 1.5;
    text-align: center;
    margin-bottom: 40px;
    border-bottom: 2px solid var(--border);
    padding-bottom: 20px;
}

.classic-meta span {
    margin: 0 12px;
}

/* Colors for specific branches */
.orange { color: #d97706; }
.red, .is-day { color: #dc2626; }
.is-hour { color: #7e22ce; }
.is-sky { color: #0284c7; }

/* Grid layout for the chart elements */
.classic-main {
    display: flex;
    justify-content: space-between;
    gap: 40px;
}

/* Left side: Three transmissions (San Chuan) */
.classic-transmission {
    display: grid;
    gap: 12px;
    width: 260px;
    font-size: 32px;
    line-height: 1.4;
}

.transmission-line {
    display: grid;
    grid-template-columns: 100px 80px 60px;
    align-items: baseline;
    padding: 8px 12px;
    background: var(--bg-page);
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

.transmission-line em {
    color: #444;
    font-style: normal;
}

/* Middle: Four Lessons (Si Ke) */
.classic-lessons {
    display: grid;
    grid-template-columns: repeat(4, 70px);
    width: 280px;
    text-align: center;
    font-size: 32px;
    line-height: 1.4;
    margin-top: 20px;
}

.lesson-line {
    display: grid;
    grid-template-rows: repeat(3, 44px);
    padding: 0 4px;
}

.lesson-line:nth-child(even) {
    background: var(--bg-page);
    border-radius: var(--radius-md);
}

.lesson-line b {
    color: #444;
}

/* Right side: Heaven/Earth Board (Tian Di Pan) */
.classic-board {
    width: 360px;
    font-size: 32px;
    line-height: 1.2;
    padding: 20px;
    border: 2px solid var(--border);
    border-radius: var(--radius-md);
    position: relative;
    background: var(--bg-surface);
}

.board-top-name,
.board-top-sky,
.board-bottom-sky,
.board-bottom-name {
    display: grid;
    grid-template-columns: repeat(4, 72px);
    width: 288px;
    margin: 0 auto;
    text-align: center;
}

.board-top-sky { margin-top: 4px; }
.board-bottom-sky { margin-top: 40px; }
.board-bottom-name { margin-top: 4px; }

.board-side-line {
    display: flex;
    justify-content: space-between;
    width: 340px;
    margin: 36px auto 0;
}
.board-side-line.second { margin-top: 28px; }

.side-pair {
    display: inline-flex;
    flex-direction: column;
    align-items: center;
    line-height: 1.1;
}

.side-pair em {
    color: #444;
    font-style: normal;
    font-size: 28px;
}

/* Split Detail Layout */
.detail-layout {
    display: grid;
    grid-template-columns: 1fr;
    gap: 32px;
}
@media (min-width: 1024px) {
    .detail-layout {
        grid-template-columns: minmax(0, 1.2fr) minmax(0, 0.8fr);
        align-items: start;
    }
}

.detail-content-card {
    background: var(--bg-surface);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-sm);
}

.detail-content-card h2 {
    font-size: 1.5rem;
    margin-bottom: 24px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.article-body {
    font-size: 1.05rem;
    line-height: 1.8;
    color: var(--text-dark);
}

.article-body p {
    margin-bottom: 1.2em;
}

.mobile-menu-toggle {
    display: none;
    background: transparent;
    border: none;
    color: #fff;
    cursor: pointer;
    padding: 8px;
    margin-left: auto;
}

/* Mobile Adjustments */
@media (max-width: 768px) {
    .mobile-menu-toggle {
        display: block;
    }

    .nav {
        height: auto;
        padding: 16px 0;
        flex-wrap: wrap;
    }
    
    .nav nav {
        display: none;
        width: 100%;
        flex-direction: column;
        align-items: center;
        gap: 16px;
        padding-top: 16px;
    }
    
    .nav nav.active {
        display: flex;
    }

    .hero {
        padding: 40px 24px;
    }
    .hero h1 { font-size: 32px; }

    .grid.two, .grid.three, .grid.four {
        grid-template-columns: 1fr;
    }
    
    .filter-panel {
        flex-direction: column;
        align-items: stretch;
    }
    
    .filter-group input, .filter-group select {
        width: 100%;
    }
    
    .btn {
        width: 100%;
    }
    
    .liuren-classic {
        padding: 20px;
    }
}
