:root {
    --gap: 5px;
    --scroll-bar-width: 4px;
    --content-max-width: 900px;

    @media (max-width: 768px) {
        --scroll-bar-width: 2px;
    }
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* 深色/浅色基础 */
html.dark {
    background: #0f172a;
    color: #e2e8f0;
}

body {
    font-family: system-ui, -apple-system, 'Segoe UI', 'Roboto', 'Noto Sans', 'Helvetica Neue', sans-serif;
    height: 100vh;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

html.dark body {
    background: #0f172a;
}

#app {
    padding: var(--gap) 0 0;
    height: 100%;
    display: flex;
    gap: var(--gap);
    flex-direction: column;
}

/* ========= 顶部工具栏 (移动优先) ========= */
.toolbar {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    flex-shrink: 0;
    transition: all 0.2s;
    overflow-y: scroll;
    gap: var(--gap);
}

.search-box {
    display: flex;
    align-items: center;
    position: relative;
    width: 100%;
    margin: 0 auto;
    max-width: var(--content-max-width);
}

.search-box i {
    position: absolute;
    left: 14px;
    top: 50%;
    transform: translateY(-50%);
    color: #94a3b8;
    font-size: 0.9rem;
    pointer-events: none;
}

html.dark .search-box i {
    color: #64748b;
}

.search-box input {
    width: 100%;
    padding: 8px 40px;
    border: 1px solid #cbd5e1;
    color: #1e293b;
    transition: all 0.2s;
    -webkit-appearance: none;
}

html.dark .search-box input {
    background: #0f172a;
    border-color: #475569;
    color: #e2e8f0;
}

.search-box input:focus {
    outline: none;
    border-color: #667eea;
    box-shadow: 0 0 0 3px rgba(102, 126, 234, 0.15);
}

html.dark .search-box input:focus {
    border-color: #8b5cf6;
    box-shadow: 0 0 0 3px rgba(139, 92, 246, 0.2);
}

.clear-btn {
    position: absolute;
    right: 12px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: #94a3b8;
    font-size: 1.3rem;
    font-weight: 600;
    padding: 4px 8px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.clear-btn:hover {
    color: #e53e3e;
}

html.dark .clear-btn:hover {
    color: #f87171;
}

/* 复选框 */
.check-group {
    width: 100%;
    max-width: var(--content-max-width);
    display: flex;
    gap: var(--gap);
    border-radius: 12px;
}

.check-label {
    position: relative;
    cursor: pointer;
}

.check-label input {
    position: absolute;
    opacity: 0;
}

.check-label span,
.check-label {
    display: inline-block;
    padding: 4px 12px;
    font-size: 0.8rem;
    font-weight: 500;
    border-radius: 6px;
    background: #f8fafc;
    color: #475569;
    transition: all 0.15s;
    cursor: pointer;
    border: 1px solid #e2e8f0;
}

.check-label:hover span,
.check-label:hover {
    background: #f1f5f9;
    border-color: #cbd5e1;
}

.check-label input:checked + span,
.check-label:has(input:checked) {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

/* 深色模式 - 复选框组 */
html.dark .check-group .check-label span,
html.dark .check-group .check-label {
    background: #1e293b;
    border-color: #475569;
    color: #94a3b8;
}

html.dark .check-group .check-label:hover span,
html.dark .check-group .check-label:hover {
    background: #334155;
    border-color: #64748b;
    color: #cbd5e1;
}

html.dark .check-group .check-label input:checked + span,
html.dark .check-group .check-label:has(input:checked) {
    background: #3b82f6;
    color: white;
    border-color: #3b82f6;
}

/* ========= 卡片列表容器 ========= */
.card-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    overflow-y: scroll;
    overflow-x: hidden;
    transition: background 0.2s;
    -webkit-overflow-scrolling: touch;
}

html.dark .card-container {
    background: #0f172a;
}

/* 卡片设计 */
.grammar-card {
    width: 100%;
    display: flex;
    flex-direction: column;
    gap: var(--gap);
    padding: var(--gap);
    transition: all 0.2s;
    margin-left: auto;
    margin-right: auto;
    max-width: var(--content-max-width);
}

.grammar-card:last-child {
    margin-bottom: 150px;
}

html.dark .grammar-card {
    background: #1e293b;
}

.grammar-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 8px 20px rgba(0, 0, 0, 0.08);
}

html.dark .grammar-card:hover {
    background: #2d3a4e;
}

/* 卡片头部：序号 + 课程标签 */
.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.grammar-index {
    font-size: 0.7rem;
    color: #475569;
}

html.dark .grammar-index {
    color: #94a3b8;
}

.lesson-badge {
    display: inline-flex;
    padding: var(--gap);
    font-size: 0.7rem;
    align-items: center;
    gap: 6px;
}

html.dark .lesson-badge {
    color: #94a3b8;
}

.lesson-badge i {
    font-size: 0.7rem;
}

/* 语法点主体 */
.grammar-point {
    flex: 1 1 auto;
}

.grammar-title {
    font-size: 0.7rem;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #64748b;
    font-weight: 600;
}

html.dark .grammar-title {
    color: #94a3b8;
}

.grammar-value {
    width: 100%;
    padding: 6px;
    font-size: 1.1rem;
    font-weight: bolder;
    color: goldenrod;
    display: inline-block;
    word-break: break-word;
    white-space: normal;
}

/* 含义行 */
.meaning-text {
    font-size: 0.9rem;
    color: #334155;
    word-break: break-word;
    padding: 6px;
}

html.dark .meaning-text {
    color: #cbd5e1;
}

/* 例句区域 */
.example-block {
    border-left: 3px solid #cbd5e6;
    padding-left: 3px;
    background: #fefefe;
}

html.dark .example-block {
    border-left-color: #475569;
    background: transparent;
}

.example-text {
    font-size: 0.9rem;
    color: #475569;
    word-break: break-word;
    font-style: normal;
}

html.dark .example-text {
    color: #b9c3d4;
}

/* 高亮样式 */
mark {
    background: #fde047;
    color: #1e1b2c;
    padding: 0 3px;
    font-weight: 500;
}

html.dark mark {
    background: #facc15;
    color: #0f172a;
}

/* 空状态 & 加载状态 */
.state-message {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    padding: 60px 24px;
    color: #94a3b8;
}

.state-message i {
    font-size: 56px;
    margin-bottom: 16px;
    opacity: 0.6;
}

.loading-spinner {
    display: inline-block;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    border: 3px solid #e2e8f0;
    border-top-color: #667eea;
    animation: spin 0.8s linear infinite;
    margin-bottom: 12px;
}

@keyframes spin {
    to {
        transform: rotate(360deg);
    }
}

/* 表头总数显示区域 (统计条) */
.stats-header {
    background: white;
    border-bottom: 1px solid #e2e8f0;
    padding: 8px 20px;
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    flex-shrink: 0;
    font-size: 0.8rem;
    font-weight: 500;
    transition: all 0.2s;
}

html.dark .stats-header {
    background: #1e293b;
    border-bottom-color: #334155;
}

.stats-header span:first-child {
    color: #475569;
}

.stats-header span:last-child {
    background: #eef2ff;
    padding: 4px 12px;
    color: #4f46e5;
    font-weight: 600;
}

html.dark .stats-header span:last-child {
    background: #334155;
    color: #a78bfa;
}

::-webkit-scrollbar {
    width: var(--scroll-bar-width);
    height: 8px;
}

::-webkit-scrollbar-track {
    background: #f1f1f1;
}

html.dark ::-webkit-scrollbar-track {
    background: #1e293b;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
}

html.dark ::-webkit-scrollbar-thumb {
    background: #475569;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

html.dark ::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* 响应式微调 */
@media (max-width: 768px) {
    .toolbar, .card-container {
        padding: 0 var(--gap);
    }

    .grammar-card {
        padding: var(--gap);
    }

    .card-container::-webkit-scrollbar {
        width: var(--scroll-bar-width);
    }
}