/* ===== 全局变量 & 重置 ===== */
:root {
    --bg: #faf7f2;
    --sidebar-bg: #f3efe8;
    --card-bg: #ffffff;
    --text-primary: #3d3226;
    --text-secondary: #8c8075;
    --text-tertiary: #b0a599;
    --border: #e8e2d8;
    --border-light: #f0ebe1;
    --accent: #b8956a;
    --accent-hover: #a07848;
    --accent-light: #f5efe6;
    --accent-soft: #e8d9c4;
    --shadow-sm: 0 1px 2px rgba(61, 50, 38, 0.06);
    --shadow-md: 0 2px 8px rgba(61, 50, 38, 0.08);
    --shadow-lg: 0 4px 16px rgba(61, 50, 38, 0.1);
    --shadow-btn: 0 1px 3px rgba(61, 50, 38, 0.07);
    --shadow-btn-hover: 0 4px 14px rgba(61, 50, 38, 0.13);
    --radius-sm: 6px;
    --radius-md: 10px;
    --radius-lg: 14px;
    --transition-fast: 0.18s cubic-bezier(0.4, 0, 0.2, 1);
    --transition-smooth: 0.28s cubic-bezier(0.4, 0, 0.2, 1);
    --font-sans: 'Inter', 'PingFang SC', 'Hiragino Sans GB', 'Noto Sans SC',
        'Microsoft YaHei', system-ui, -apple-system, sans-serif;
    --font-mono: 'SF Mono', 'JetBrains Mono', 'Fira Code', 'Consolas',
        'Monaco', 'Courier New', monospace;
    --sidebar-width: 200px;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

html {
    font-size: 16px;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    font-family: var(--font-sans);
    background-color: #f5f1ea;
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 1px,
            rgba(180, 160, 140, 0.015) 1px,
            rgba(180, 160, 140, 0.015) 2px),
        repeating-linear-gradient(90deg,
            transparent,
            transparent 1px,
            rgba(170, 150, 130, 0.01) 1px,
            rgba(170, 150, 130, 0.01) 2px),
        repeating-linear-gradient(45deg,
            transparent,
            transparent 3px,
            rgba(160, 140, 120, 0.006) 3px,
            rgba(160, 140, 120, 0.006) 4px);
    background-color: #faf7f2;
    color: var(--text-primary);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: flex-start;
    padding: 20px;
    position: relative;
    overflow-x: hidden;
}

body::before {
    content: '';
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    background:
        radial-gradient(ellipse at 15% 20%, rgba(210, 180, 150, 0.04) 0%, transparent 55%),
        radial-gradient(ellipse at 85% 75%, rgba(190, 160, 130, 0.03) 0%, transparent 55%),
        radial-gradient(ellipse at 50% 50%, rgba(200, 175, 145, 0.025) 0%, transparent 70%);
    opacity: 0.7;
}

.app-container {
    position: relative;
    z-index: 1;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 1100px;
    min-height: 88vh;
    background: var(--bg);
    border-radius: var(--radius-lg);
    box-shadow:
        var(--shadow-lg),
        0 0 0 1px rgba(180, 160, 140, 0.12),
        0 20px 50px rgba(140, 120, 90, 0.08);
    overflow: hidden;
    background:
        linear-gradient(to bottom,
            #fdfbf7 0%,
            #faf7f2 3%,
            #faf7f2 97%,
            #f7f3ec 100%);
}

/* ===== Header ===== */
.header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 28px 16px 28px;
    border-bottom: 1px solid var(--border-light);
    position: relative;
    flex-shrink: 0;
    background: transparent;
    user-select: none;
}

.header::after {
    content: '';
    position: absolute;
    bottom: -1px;
    left: 28px;
    right: 28px;
    height: 1px;
    background: linear-gradient(to right,
            transparent,
            rgba(180, 155, 125, 0.25) 15%,
            rgba(180, 155, 125, 0.35) 50%,
            rgba(180, 155, 125, 0.25) 85%,
            transparent);
    opacity: 0.7;
}

.brand {
    display: flex;
    align-items: baseline;
    gap: 10px;
    cursor: default;
}

.brand-zh {
    font-size: 1.55rem;
    font-weight: 620;
    letter-spacing: 0.06em;
    color: #3d3226;
    line-height: 1;
    position: relative;
}

.brand-zh::after {
    content: '';
    position: absolute;
    bottom: -2px;
    left: 0;
    width: 100%;
    height: 1.5px;
    background: var(--accent-soft);
    border-radius: 1px;
    opacity: 0.5;
    transform: scaleX(0.7);
    transform-origin: left center;
}

.brand-en {
    font-size: 0.8rem;
    font-weight: 400;
    letter-spacing: 0.1em;
    color: var(--text-tertiary);
    text-transform: uppercase;
    font-style: italic;
    line-height: 1;
}

.header-subtitle {
    font-size: 0.75rem;
    color: var(--text-tertiary);
    letter-spacing: 0.04em;
    font-weight: 400;
}

/* ===== Header 右侧操作区 ===== */
.header-actions {
    display: flex;
    align-items: center;
    gap: 12px;
}

/* ===== NSFW 切换按钮 ===== */
.nsfw-toggle {
    display: flex;
    align-items: center;
    gap: 8px;
    cursor: pointer;
    user-select: none;
    padding: 6px 14px 6px 12px;
    border-radius: 20px;
    border: 1px solid var(--border);
    background: var(--card-bg);
    transition: all var(--transition-fast);
    font-size: 0.78rem;
    font-weight: 450;
    color: var(--text-secondary);
    box-shadow: var(--shadow-sm);
    white-space: nowrap;
}

.nsfw-toggle:hover {
    border-color: #d5ccc0;
    box-shadow: var(--shadow-btn-hover);
    background: #fefdfb;
}

.nsfw-toggle:active {
    transform: scale(0.97);
}

.nsfw-toggle .toggle-track {
    position: relative;
    width: 34px;
    height: 20px;
    border-radius: 10px;
    background: #d5ccc0;
    transition: background var(--transition-fast);
    flex-shrink: 0;
}

.nsfw-toggle .toggle-track::after {
    content: '';
    position: absolute;
    top: 3px;
    left: 3px;
    width: 14px;
    height: 14px;
    border-radius: 50%;
    background: #fff;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
    transition: transform var(--transition-fast);
}

.nsfw-toggle.active .toggle-track {
    background: #d32f2f;
}

.nsfw-toggle.active .toggle-track::after {
    transform: translateX(14px);
}

.nsfw-toggle .toggle-label {
    display: flex;
    align-items: center;
    gap: 4px;
}

.nsfw-toggle .toggle-label-icon {
    font-size: 0.85rem;
}

/* ===== 主体布局 ===== */
.main-content {
    display: flex;
    flex: 1;
    min-height: 0;
    position: relative;
}

/* ===== Sidebar ===== */
.sidebar {
    width: var(--sidebar-width);
    flex-shrink: 0;
    background: var(--sidebar-bg);
    padding: 20px 0;
    display: flex;
    flex-direction: column;
    gap: 2px;
    border-right: 1px solid var(--border-light);
    position: relative;
    user-select: none;
    background-image:
        repeating-linear-gradient(0deg,
            transparent,
            transparent 3px,
            rgba(0, 0, 0, 0.006) 3px,
            rgba(0, 0, 0, 0.006) 4px);
    background-color: #f3efe8;
}

.sidebar-label {
    font-size: 0.68rem;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: var(--text-tertiary);
    padding: 6px 22px 14px 22px;
    font-weight: 500;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 1px;
    padding: 0 10px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 11px 14px;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all var(--transition-fast);
    color: var(--text-secondary);
    font-size: 0.9rem;
    font-weight: 450;
    letter-spacing: 0.03em;
    position: relative;
    text-decoration: none;
    outline: none;
    -webkit-tap-highlight-color: transparent;
    white-space: nowrap;
}

.sidebar-item:hover {
    background: rgba(180, 150, 120, 0.08);
    color: var(--text-primary);
}

.sidebar-item:active {
    background: rgba(180, 150, 120, 0.14);
    transform: scale(0.97);
}

.sidebar-item.active {
    background: rgba(180, 150, 120, 0.12);
    color: #3d3226;
    font-weight: 550;
    box-shadow: inset 3px 0 0 var(--accent);
    border-radius: var(--radius-sm);
    padding-left: 11px;
}

.sidebar-item .dot {
    width: 5px;
    height: 5px;
    border-radius: 50%;
    background: transparent;
    transition: all var(--transition-fast);
    flex-shrink: 0;
}

.sidebar-item.active .dot {
    background: var(--accent);
    box-shadow: 0 0 6px rgba(184, 149, 106, 0.5);
}

.sidebar-item .count {
    margin-left: auto;
    font-size: 0.7rem;
    color: var(--text-tertiary);
    font-weight: 400;
    letter-spacing: 0;
    background: rgba(0, 0, 0, 0.03);
    padding: 2px 7px;
    border-radius: 10px;
    transition: all var(--transition-fast);
}

.sidebar-item.active .count {
    background: rgba(184, 149, 106, 0.15);
    color: var(--accent-hover);
    font-weight: 500;
}

/* ===== 内容区 ===== */
.content-area {
    flex: 1;
    padding: 24px 28px 32px 28px;
    overflow-y: auto;
    position: relative;
    background: transparent;
    min-height: 400px;
}

.content-area::-webkit-scrollbar {
    width: 5px;
}
.content-area::-webkit-scrollbar-track {
    background: transparent;
}
.content-area::-webkit-scrollbar-thumb {
    background: rgba(180, 160, 140, 0.25);
    border-radius: 10px;
}
.content-area::-webkit-scrollbar-thumb:hover {
    background: rgba(180, 160, 140, 0.4);
}

.category-title {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    color: var(--text-tertiary);
    margin-bottom: 18px;
    font-weight: 500;
    padding-left: 2px;
    transition: all var(--transition-smooth);
}

.category-title .highlight {
    color: var(--accent);
    font-weight: 600;
}

/* ===== TAG 网格 ===== */
.tag-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(170px, 1fr));
    gap: 12px;
    transition: opacity var(--transition-smooth);
}

.tag-grid.fade-out {
    opacity: 0;
    transform: translateY(6px);
    transition: opacity 0.15s ease, transform 0.15s ease;
}

.tag-grid.fade-in {
    opacity: 1;
    transform: translateY(0);
    transition: opacity 0.25s ease, transform 0.25s ease;
}

/* ===== 单个 TAG 按钮 ===== */
.tag-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 18px 14px 16px 14px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-md);
    cursor: pointer;
    transition: all var(--transition-fast);
    box-shadow: var(--shadow-btn);
    position: relative;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
    outline: none;
    text-align: center;
    min-height: 80px;
    background-image:
        linear-gradient(to bottom,
            #ffffff 0%,
            #fefdfb 100%);
}

.tag-btn::before {
    content: '';
    position: absolute;
    inset: 0;
    border-radius: var(--radius-md);
    opacity: 0;
    background: radial-gradient(circle at center, rgba(184, 149, 106, 0.06) 0%, transparent 70%);
    transition: opacity var(--transition-fast);
    pointer-events: none;
}

.tag-btn:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-btn-hover);
    border-color: #d5ccc0;
    background: #fefdfb;
}

.tag-btn:hover::before {
    opacity: 1;
}

.tag-btn:active {
    transform: translateY(0) scale(0.97);
    box-shadow: var(--shadow-sm);
    transition: all 0.08s ease;
    background: #faf7f3;
    border-color: #d0c8bb;
}

.tag-btn.copied-flash {
    border-color: var(--accent-soft) !important;
    background: #fdf9f4 !important;
    box-shadow: 0 0 0 3px rgba(184, 149, 106, 0.12) !important;
    transition: all 0.12s ease !important;
}

/* ----- NSFW 角标 ----- */
.tag-btn .nsfw-badge {
    position: absolute;
    top: -1px;
    left: -1px;
    background: #d32f2f;
    color: #fff;
    font-size: 0.6rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 2px 7px 2px 6px;
    border-radius: var(--radius-md) 0 var(--radius-md) 0;
    line-height: 1.3;
    pointer-events: none;
    user-select: none;
    z-index: 2;
    box-shadow: 0 1px 3px rgba(0,0,0,0.15);
}

/* ----- NSFW 隐藏态 ----- */
.tag-btn.nsfw-hidden {
    display: none !important;
}

/* ----- 中文标签 ----- */
.tag-btn .tag-zh {
    font-size: 0.95rem;
    font-weight: 520;
    color: var(--text-primary);
    letter-spacing: 0.03em;
    line-height: 1.3;
    transition: color var(--transition-fast);
    pointer-events: none;
}

/* ----- 英文部分：多个可点击词汇 ----- */
.tag-btn .tag-en-wrapper {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: center;
    gap: 2px 4px;
    font-size: 0.72rem;
    font-family: var(--font-mono);
    color: var(--text-tertiary);
    letter-spacing: 0.02em;
    line-height: 1.4;
    max-width: 100%;
    pointer-events: none;
}

.tag-btn .tag-en-sep {
    color: var(--text-tertiary);
    opacity: 0.4;
    font-size: 0.6rem;
    pointer-events: none;
    user-select: none;
}

.tag-btn .tag-en-part {
    display: inline-block;
    padding: 1px 4px;
    border-radius: 3px;
    font-size: 0.72rem;
    font-family: var(--font-mono);
    color: var(--text-secondary);
    background: transparent;
    cursor: pointer;
    pointer-events: auto;
    transition: all var(--transition-fast);
    border-bottom: 1.5px solid transparent;
    line-height: 1.4;
    position: relative;
}

.tag-btn .tag-en-part:hover {
    color: var(--accent-hover);
    background: rgba(184, 149, 106, 0.07);
    border-bottom-color: var(--accent-soft);
    transform: translateY(-0.5px);
}

.tag-btn .tag-en-part:active {
    transform: scale(0.94);
    background: rgba(184, 149, 106, 0.15);
    transition: all 0.06s ease;
}

.tag-btn .tag-en-part.copied-part {
    background: rgba(184, 149, 106, 0.18);
    border-bottom-color: var(--accent);
    color: var(--accent-hover);
    transition: all 0.12s ease;
}

/* 在英文部分整体 hover 时提示可点击 */
.tag-btn:hover .tag-en-wrapper .tag-en-part {
    color: #8c7d6e;
}

.tag-btn:hover .tag-en-wrapper .tag-en-part:hover {
    color: var(--accent-hover);
}

/* ----- 复制提示（右上角） ----- */
.tag-btn .copy-hint {
    position: absolute;
    top: 8px;
    right: 10px;
    font-size: 0.6rem;
    color: transparent;
    transition: color var(--transition-fast);
    letter-spacing: 0.05em;
    pointer-events: none;
    font-weight: 400;
}

.tag-btn:hover .copy-hint {
    color: #c4b49e;
}

/* ===== Toast ===== */
.toast-container {
    position: fixed;
    top: 28px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9999;
    pointer-events: none;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 8px;
}

.toast {
    padding: 10px 20px;
    background: #3d3226;
    color: #f5efe6;
    border-radius: 20px;
    font-size: 0.82rem;
    letter-spacing: 0.03em;
    font-weight: 450;
    box-shadow: 0 8px 24px rgba(61, 50, 38, 0.3);
    animation: toastIn 0.35s cubic-bezier(0.22, 0.61, 0.36, 1) forwards,
        toastOut 0.3s cubic-bezier(0.55, 0.06, 0.68, 0.19) 1.6s forwards;
    white-space: nowrap;
    pointer-events: auto;
    cursor: default;
    display: flex;
    align-items: center;
    gap: 8px;
}

.toast .toast-icon {
    font-size: 0.9rem;
}
.toast .toast-tag {
    font-family: var(--font-mono);
    font-size: 0.7rem;
    opacity: 0.85;
    letter-spacing: 0.04em;
}

@keyframes toastIn {
    0% {
        opacity: 0;
        transform: translateY(-18px) scale(0.92);
    }
    100% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

@keyframes toastOut {
    0% {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
    100% {
        opacity: 0;
        transform: translateY(-10px) scale(0.94);
    }
}

/* ===== Footer ===== */
.footer {
    text-align: center;
    padding: 12px 28px 16px 28px;
    font-size: 0.68rem;
    color: var(--text-tertiary);
    letter-spacing: 0.05em;
    border-top: 1px solid var(--border-light);
    flex-shrink: 0;
    user-select: none;
    opacity: 0.7;
}

/* ===== 响应式 ===== */
@media (max-width: 768px) {
    body {
        padding: 8px;
    }

    .app-container {
        border-radius: var(--radius-md);
        max-width: 100%;
    }

    .header {
        padding: 14px 16px 12px 16px;
        flex-wrap: wrap;
        gap: 6px;
    }
    .header::after {
        left: 16px;
        right: 16px;
    }

    .brand-zh {
        font-size: 1.3rem;
    }
    .brand-en {
        font-size: 0.7rem;
    }
    .header-subtitle {
        display: none;
    }

    .header-actions {
        margin-left: auto;
    }

    .nsfw-toggle {
        padding: 4px 10px 4px 8px;
        font-size: 0.7rem;
    }
    .nsfw-toggle .toggle-track {
        width: 28px;
        height: 16px;
    }
    .nsfw-toggle .toggle-track::after {
        width: 10px;
        height: 10px;
        top: 3px;
        left: 3px;
    }
    .nsfw-toggle.active .toggle-track::after {
        transform: translateX(12px);
    }

    .main-content {
        flex-direction: column;
    }

    .sidebar {
        width: 100%;
        flex-direction: row;
        overflow-x: auto;
        padding: 10px 12px;
        gap: 6px;
        border-right: none;
        border-bottom: 1px solid var(--border-light);
        flex-shrink: 0;
        -webkit-overflow-scrolling: touch;
        scrollbar-width: none;
        background: #f3efe8;
    }

    .sidebar::-webkit-scrollbar {
        display: none;
    }

    .sidebar-label {
        display: none;
    }

    .sidebar-nav {
        flex-direction: row;
        gap: 4px;
        padding: 0;
        flex-wrap: nowrap;
    }

    .sidebar-item {
        padding: 9px 14px;
        font-size: 0.8rem;
        white-space: nowrap;
        flex-shrink: 0;
        gap: 5px;
        border-radius: 20px;
        box-shadow: none;
    }

    .sidebar-item.active {
        box-shadow: none;
        border-radius: 20px;
        padding-left: 14px;
        background: rgba(180, 150, 120, 0.16);
    }

    .sidebar-item .dot {
        display: none;
    }
    .sidebar-item .count {
        font-size: 0.65rem;
        padding: 1px 6px;
    }

    .content-area {
        padding: 16px 14px 20px 14px;
    }

    .tag-grid {
        grid-template-columns: repeat(auto-fill, minmax(130px, 1fr));
        gap: 8px;
    }

    .tag-btn {
        padding: 13px 10px 11px 10px;
        min-height: 64px;
        gap: 4px;
        border-radius: var(--radius-sm);
    }
    .tag-btn .tag-zh {
        font-size: 0.82rem;
    }
    .tag-btn .tag-en-wrapper {
        font-size: 0.65rem;
    }
    .tag-btn .tag-en-part {
        font-size: 0.65rem;
        padding: 0 3px;
    }
    .tag-btn .tag-en-sep {
        font-size: 0.55rem;
    }
    .tag-btn .copy-hint {
        display: none;
    }
    .tag-btn .nsfw-badge {
        font-size: 0.5rem;
        padding: 1px 5px 1px 4px;
    }

    .category-title {
        font-size: 0.7rem;
        margin-bottom: 12px;
    }

    .toast-container {
        top: 16px;
    }
    .toast {
        padding: 8px 16px;
        font-size: 0.75rem;
        border-radius: 16px;
    }
}

@media (max-width: 420px) {
    .tag-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 7px;
    }
    .tag-btn {
        padding: 11px 8px 10px 8px;
        min-height: 56px;
        gap: 3px;
    }
    .tag-btn .tag-zh {
        font-size: 0.76rem;
    }
    .tag-btn .tag-en-wrapper {
        font-size: 0.6rem;
    }
    .tag-btn .tag-en-part {
        font-size: 0.6rem;
        padding: 0 2px;
    }
    .tag-btn .tag-en-sep {
        font-size: 0.5rem;
    }
    .tag-btn .nsfw-badge {
        font-size: 0.45rem;
        padding: 1px 4px 1px 3px;
        border-radius: var(--radius-sm) 0 var(--radius-sm) 0;
    }
    .sidebar-item {
        padding: 7px 11px;
        font-size: 0.73rem;
    }
    .content-area {
        padding: 12px 8px 16px 8px;
    }
    .header {
        padding: 10px 12px 10px 12px;
    }
    .brand-zh {
        font-size: 1.15rem;
    }
    .brand-en {
        font-size: 0.65rem;
    }
    .nsfw-toggle {
        padding: 3px 8px 3px 6px;
        font-size: 0.65rem;
    }
    .nsfw-toggle .toggle-track {
        width: 24px;
        height: 14px;
    }
    .nsfw-toggle .toggle-track::after {
        width: 8px;
        height: 8px;
        top: 3px;
        left: 3px;
    }
    .nsfw-toggle.active .toggle-track::after {
        transform: translateX(10px);
    }
}
