/* 基础样式 */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --primary: #e74c3c;
    --primary-dark: #c0392b;
    --secondary: #3498db;
    --bg: #f8f9fa;
    --card-bg: #ffffff;
    --text: #2c3e50;
    --text-light: #7f8c8d;
    --border: #e0e0e0;
    --shadow: 0 2px 8px rgba(0,0,0,0.08);
    --radius: 12px;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* 头部 */
.site-header {
    background: linear-gradient(135deg, var(--primary) 0%, var(--primary-dark) 100%);
    color: white;
    padding: 24px;
    text-align: center;
    position: relative;
}

.site-header h1 {
    font-size: 2rem;
    margin-bottom: 4px;
}

.subtitle {
    opacity: 0.9;
    font-size: 0.95rem;
}

.back-link {
    position: absolute;
    left: 20px;
    top: 50%;
    transform: translateY(-50%);
    color: white;
    text-decoration: none;
    font-size: 0.95rem;
    padding: 6px 12px;
    border-radius: 6px;
    background: rgba(255,255,255,0.2);
    transition: background 0.2s;
}

.back-link:hover {
    background: rgba(255,255,255,0.3);
}

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

/* 年级导航 */
.grades-nav {
    margin-bottom: 24px;
}

.grades-nav h2 {
    font-size: 1.2rem;
    margin-bottom: 12px;
    color: var(--text);
}

.grade-buttons {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
}

.grade-btn {
    padding: 10px 18px;
    border: 2px solid var(--border);
    background: var(--card-bg);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s;
    color: var(--text);
}

.grade-btn:hover {
    border-color: var(--primary);
    color: var(--primary);
}

.grade-btn.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
}

/* 搜索 */
.search-section {
    margin-bottom: 20px;
}

#searchInput {
    width: 100%;
    max-width: 300px;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    outline: none;
    transition: border-color 0.2s;
}

#searchInput:focus {
    border-color: var(--primary);
}

/* 汉字区域 */
.chars-section {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--border);
}

.section-header h2 {
    font-size: 1.2rem;
}

.char-count {
    color: var(--text-light);
    font-size: 0.9rem;
}

.chars-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(72px, 1fr));
    gap: 12px;
}

.char-item {
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--bg);
    border-radius: var(--radius);
    font-size: 1.8rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
    text-decoration: none;
    color: var(--text);
}

.char-item:hover {
    border-color: var(--primary);
    background: #fff5f5;
    transform: translateY(-2px);
    box-shadow: var(--shadow);
}

/* 详情页 */
.detail-page {
    max-width: 900px;
}

.hero-char {
    padding: 32px;
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    margin-bottom: 24px;
}

.char-nav-wrapper {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 24px;
}

.char-main {
    text-align: center;
    flex: 1;
}

.nav-btn {
    padding: 10px 18px;
    border: 2px solid var(--border);
    background: var(--card-bg);
    border-radius: var(--radius);
    cursor: pointer;
    font-size: 0.95rem;
    transition: all 0.2s;
    color: var(--text);
    white-space: nowrap;
    min-width: 100px;
}

.nav-btn:hover:not(:disabled) {
    border-color: var(--primary);
    color: var(--primary);
    background: #fff5f5;
}

.nav-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

.char-display {
    font-size: 8rem;
    line-height: 1;
    margin-bottom: 8px;
    font-family: "KaiTi", "STKaiti", "楷体", serif;
}

.pinyin-display {
    font-size: 1.5rem;
    color: var(--text-light);
}

.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 20px;
}

.detail-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.detail-card h3 {
    font-size: 1.1rem;
    margin-bottom: 16px;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--primary);
    color: var(--primary);
}

.svg-card {
    grid-column: 1 / -1;
}

.svg-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
}

.svg-container svg {
    max-width: 100%;
    max-height: 300px;
    width: auto;
    height: auto;
}

.svg-container .stroke-gif {
    max-width: 100%;
    max-height: 300px;
    width: 240px;
    height: 240px;
    object-fit: contain;
    display: block;
}

/* 笔顺展示区域 */
.char-glyph {
    position: relative;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 0;
    width: 100%;
}

.svg-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 200px;
    width: 100%;
}

/* 笔顺动画：默认可见，播放时先隐藏再逐笔显示 */
.stroke-path {
    opacity: 1;
    transition: opacity 0.25s ease;
}

.stroke-path.anim-hidden {
    opacity: 0;
}

.stroke-path.anim-visible {
    opacity: 1;
}

.info-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.info-row {
    display: flex;
    justify-content: space-between;
    padding: 8px 0;
    border-bottom: 1px solid var(--border);
}

.info-row:last-child {
    border-bottom: none;
}

.info-label {
    color: var(--text-light);
    font-size: 0.9rem;
}

.info-value {
    font-weight: 500;
}

.semantic-card {
    grid-column: 1 / -1;
}

.semantic-content {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.semantic-item {
    padding: 12px;
    background: var(--bg);
    border-radius: 8px;
}

.semantic-pinyin {
    font-size: 1.1rem;
    color: var(--primary);
    font-weight: 600;
    margin-bottom: 8px;
}

.semantic-list {
    list-style: none;
}

.semantic-list li {
    padding: 6px 0;
    padding-left: 16px;
    position: relative;
    line-height: 1.7;
}

.semantic-list li::before {
    content: "•";
    position: absolute;
    left: 0;
    color: var(--primary);
}

.semantic-example {
    color: #5a8a5a;
}

.semantic-example-label {
    font-weight: 600;
}

.loading {
    color: var(--text-light);
    text-align: center;
    padding: 40px;
}

.not-found {
    text-align: center;
    padding: 60px 20px;
    color: var(--text-light);
}

.not-found .char-display {
    font-size: 4rem;
    margin-bottom: 16px;
    opacity: 0.5;
}

/* 页脚 */
.site-footer {
    text-align: center;
    padding: 20px;
    color: var(--text-light);
    font-size: 0.85rem;
    border-top: 1px solid var(--border);
}

/* 响应式 */
@media (max-width: 600px) {
    .site-header h1 {
        font-size: 1.5rem;
    }

    .back-link {
        position: static;
        display: inline-block;
        transform: none;
        margin-bottom: 8px;
    }

    .char-display {
        font-size: 5rem;
    }

    .chars-grid {
        grid-template-columns: repeat(auto-fill, minmax(56px, 1fr));
        gap: 8px;
    }

    .char-item {
        font-size: 1.4rem;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .svg-card,
    .semantic-card {
        grid-column: auto;
    }
}
