/* ===== 全局重置 ===== */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #FF6B35;
    --primary-dark: #E55A2B;
    --primary-light: #FF8A5C;
    --bg: #F5F5F5;
    --card-bg: #FFFFFF;
    --text: #333333;
    --text-light: #666666;
    --text-lighter: #999999;
    --shadow: 0 2px 12px rgba(0,0,0,0.06);
    --radius: 12px;
    --safe-bottom: env(safe-area-inset-bottom, 0px);
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background: var(--bg);
    color: var(--text);
    padding-bottom: calc(20px + var(--safe-bottom));
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

/* ===== 顶部导航 ===== */
.header {
    background: var(--primary);
    color: white;
    position: sticky;
    top: 0;
    z-index: 1000;
    padding: 12px 16px calc(12px + env(safe-area-inset-top, 0px));
    box-shadow: 0 2px 10px rgba(255, 107, 53, 0.3);
}

.header-content {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 500px;
    margin: 0 auto;
}

.logo {
    font-size: 20px;
    font-weight: 700;
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
}

.logo .emoji {
    font-size: 24px;
}

.header-actions {
    display: flex;
    gap: 12px;
    align-items: center;
}

.header-btn {
    background: rgba(255,255,255,0.15);
    border: none;
    color: white;
    padding: 6px 12px;
    border-radius: 20px;
    font-size: 14px;
    cursor: pointer;
    transition: all 0.3s;
    display: flex;
    align-items: center;
    gap: 4px;
}

.header-btn:active {
    transform: scale(0.95);
    background: rgba(255,255,255,0.25);
}

.header-btn .icon {
    font-size: 16px;
}

/* ===== 搜索框 ===== */
.search-box {
    max-width: 500px;
    margin: 0 auto;
    padding: 8px 0 0;
    display: none;
}

.search-box.show {
    display: block;
    animation: slideDown 0.3s ease;
}

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

.search-input-group {
    display: flex;
    align-items: center;
    background: rgba(255,255,255,0.2);
    border-radius: 24px;
    padding: 0 16px;
    transition: all 0.3s;
}

.search-input-group:focus-within {
    background: rgba(255,255,255,0.3);
    box-shadow: 0 0 0 2px rgba(255,255,255,0.2);
}

.search-input-group .icon {
    color: rgba(255,255,255,0.8);
    font-size: 16px;
}

.search-input-group input {
    flex: 1;
    background: transparent;
    border: none;
    padding: 10px 12px;
    color: white;
    font-size: 15px;
    outline: none;
    min-width: 0;
}

.search-input-group input::placeholder {
    color: rgba(255,255,255,0.7);
}

.clear-btn {
    background: none;
    border: none;
    color: rgba(255,255,255,0.7);
    padding: 4px 8px;
    cursor: pointer;
    display: none;
    font-size: 16px;
}

.clear-btn.show {
    display: block;
}

/* ===== 分类标签 ===== */
.category-tabs {
    background: white;
    border-bottom: 1px solid #eee;
    position: sticky;
    top: calc(60px + env(safe-area-inset-top, 0px));
    z-index: 999;
    padding: 8px 0;
}

.tabs-scroll {
    display: flex;
    overflow-x: auto;
    padding: 0 12px;
    gap: 8px;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
    max-width: 500px;
    margin: 0 auto;
}

.tabs-scroll::-webkit-scrollbar {
    display: none;
}

.tab-item {
    flex-shrink: 0;
    padding: 6px 16px;
    background: var(--bg);
    border: none;
    border-radius: 20px;
    font-size: 13px;
    color: var(--text-light);
    cursor: pointer;
    transition: all 0.3s;
    white-space: nowrap;
}

.tab-item:active {
    transform: scale(0.95);
}

.tab-item.active {
    background: var(--primary);
    color: white;
}

.tab-item .count {
    font-size: 11px;
    opacity: 0.7;
    margin-left: 4px;
}

/* ===== 加载状态 ===== */
.loading-container {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-lighter);
}

.spinner {
    display: inline-block;
    width: 40px;
    height: 40px;
    border: 3px solid #f3f3f3;
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

/* ===== 笑话列表 ===== */
.joke-list {
    max-width: 500px;
    margin: 0 auto;
    padding: 12px 16px;
}

.joke-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 12px;
    box-shadow: var(--shadow);
    transition: all 0.3s;
    cursor: pointer;
    animation: fadeUp 0.4s ease;
}

.joke-card:active {
    transform: scale(0.98);
}

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

.joke-card .category-tag {
    display: inline-block;
    padding: 2px 12px;
    background: var(--primary-light);
    color: white;
    border-radius: 12px;
    font-size: 11px;
    margin-bottom: 8px;
}

.joke-card .title {
    font-size: 16px;
    font-weight: 600;
    margin-bottom: 8px;
    line-height: 1.4;
}

.joke-card .content-preview {
    color: var(--text-light);
    font-size: 14px;
    line-height: 1.6;
    display: -webkit-box;
    -webkit-line-clamp: 3;
    -webkit-box-orient: vertical;
    overflow: hidden;
}

.joke-card .meta {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 10px;
    padding-top: 10px;
    border-top: 1px solid #f0f0f0;
    font-size: 12px;
    color: var(--text-lighter);
}

.joke-card .meta .time {
    display: flex;
    align-items: center;
    gap: 4px;
}

.joke-card .meta .view-more {
    color: var(--primary);
}

/* ===== 加载更多 ===== */
.load-more {
    text-align: center;
    padding: 20px;
    max-width: 500px;
    margin: 0 auto;
}

.load-more button {
    background: white;
    border: 2px solid var(--primary);
    color: var(--primary);
    padding: 10px 30px;
    border-radius: 24px;
    font-size: 14px;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s;
    width: 100%;
    max-width: 300px;
}

.load-more button:active {
    transform: scale(0.95);
}

.load-more button:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.load-more .loading-text {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.load-more .small-spinner {
    display: inline-block;
    width: 16px;
    height: 16px;
    border: 2px solid #f3f3f3;
    border-top: 2px solid var(--primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

.no-more {
    text-align: center;
    padding: 30px 0;
    color: var(--text-lighter);
    font-size: 13px;
}

/* ===== 弹窗 ===== */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 2000;
    padding: 20px;
    animation: fadeIn 0.3s ease;
}

.modal-overlay.show {
    display: flex;
    align-items: center;
    justify-content: center;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background: white;
    border-radius: var(--radius);
    max-width: 500px;
    width: 100%;
    max-height: 80vh;
    overflow-y: auto;
    position: relative;
    animation: slideUp 0.3s ease;
}

.modal-close {
    position: sticky;
    top: 0;
    float: right;
    background: none;
    border: none;
    font-size: 24px;
    padding: 12px 16px;
    cursor: pointer;
    color: var(--text-light);
    z-index: 1;
}

.modal-close:active {
    transform: scale(0.9);
}

.modal-body {
    padding: 0 20px 20px;
}

.modal-body .joke-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 12px;
    padding-right: 40px;
}

.modal-body .joke-category {
    display: inline-block;
    padding: 4px 14px;
    background: var(--primary-light);
    color: white;
    border-radius: 16px;
    font-size: 13px;
    margin-bottom: 12px;
}

.modal-body .joke-content {
    font-size: 16px;
    line-height: 1.8;
    color: var(--text);
    white-space: pre-wrap;
    word-wrap: break-word;
}

.modal-body .joke-time {
    margin-top: 16px;
    padding-top: 12px;
    border-top: 1px solid #f0f0f0;
    font-size: 13px;
    color: var(--text-lighter);
    display: flex;
    align-items: center;
    gap: 6px;
}

/* ===== 暗色模式 ===== */
@media (prefers-color-scheme: dark) {
    :root {
        --bg: #1a1a1a;
        --card-bg: #2d2d2d;
        --text: #e0e0e0;
        --text-light: #b0b0b0;
        --text-lighter: #808080;
        --shadow: 0 2px 12px rgba(0,0,0,0.3);
    }
    
    .category-tabs {
        background: var(--card-bg);
        border-bottom-color: #3d3d3d;
    }
    
    .tab-item {
        background: var(--bg);
        color: var(--text-light);
    }
    
    .tab-item.active {
        background: var(--primary);
        color: white;
    }
    
    .modal-content {
        background: var(--card-bg);
    }
    
    .joke-card .meta {
        border-top-color: #3d3d3d;
    }
    
    .load-more button {
        background: var(--card-bg);
    }
}

@media (max-width: 400px) {
    .joke-card .title {
        font-size: 15px;
    }
    .joke-card .content-preview {
        font-size: 13px;
    }
    .modal-body .joke-title {
        font-size: 18px;
    }
    .modal-body .joke-content {
        font-size: 15px;
    }
    .header-btn span {
        display: none;
    }
}