/* CSS Reset and Base Styles */
* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

/* Ensure ruby elements are not affected by reset */
ruby, rt {
    margin: unset;
    padding: unset;
    box-sizing: unset;
}

body {
    font-family: 'Hiragino Sans', 'Hiragino Kaku Gothic ProN', 'Noto Sans CJK JP', sans-serif;
    line-height: 1.7;
    color: #333;
    background-color: #f8f9fa;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
}

/* Header */
.site-header {
    background: #4a5568;
    color: white;
    padding: 1rem 0;
    margin-bottom: 2rem;
}

.header-container {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 2rem;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 1rem;
}

.site-header h1 {
    font-size: 1.5rem;
    margin: 0;
    font-weight: 600;
}

.site-description {
    font-size: 0.9rem;
    opacity: 0.85;
    font-weight: 300;
}

.breadcrumb {
    font-size: 0.95rem;
}

.breadcrumb a {
    color: white;
    text-decoration: none;
}

.breadcrumb a:hover {
    text-decoration: underline;
}

/* Controls */
.controls {
    display: flex;
    align-items: center;
    gap: 1.5rem;
}

.level-control {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.level-label {
    font-size: 0.9rem;
    font-weight: 400;
    display: flex;
    align-items: center;
    gap: 0.3rem;
    white-space: nowrap;
}

.level-value {
    font-weight: 600;
    font-size: 1rem;
    min-width: 1.5rem;
    text-align: center;
}

.level-slider {
    width: 200px;
    height: 6px;
    border-radius: 3px;
    background: rgba(255,255,255,0.3);
    outline: none;
    -webkit-appearance: none;
}

.level-slider::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.level-slider::-moz-range-thumb {
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: white;
    cursor: pointer;
    border: none;
    box-shadow: 0 1px 3px rgba(0,0,0,0.3);
}

.toggle-label {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    cursor: pointer;
    user-select: none;
}

.toggle-label input[type="checkbox"] {
    display: none;
}

.slider {
    width: 40px;
    height: 20px;
    background: rgba(255,255,255,0.3);
    border-radius: 20px;
    position: relative;
    transition: background 0.3s;
}

.slider:before {
    content: '';
    position: absolute;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: white;
    top: 2px;
    left: 2px;
    transition: transform 0.3s;
}

.toggle-label input:checked + .slider {
    background: rgba(255,255,255,0.6);
}

.toggle-label input:checked + .slider:before {
    transform: translateX(20px);
}

.label-text {
    font-size: 0.85rem;
    font-weight: 300;
}

/* Articles Grid */
.articles-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(min(400px, 100%), 1fr));
    gap: 2rem;
    margin-top: 2rem;
}

.article-card {
    background: white;
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    transition: transform 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
}

.article-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 4px 20px rgba(0,0,0,0.15);
}

.card-link {
    text-decoration: none;
    color: inherit;
    display: block;
    flex: 1;
}

.card-link:hover {
    text-decoration: none;
}

.article-title {
    font-size: 1.3rem;
    margin-bottom: 0.5rem;
    color: #333;
}

.card-link:hover .article-title {
    color: #667eea;
}

.article-date {
    color: #666;
    font-size: 0.9rem;
    margin-bottom: 1rem;
    display: block;
}

/* Article Stats */
.article-stats {
    display: flex;
    gap: 1rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.stat {
    background: #e9ecef;
    padding: 0.25rem 0.75rem;
    border-radius: 20px;
    font-size: 0.85rem;
    font-weight: 500;
}

.stat.unknown {
    background: #fff3cd;
    color: #856404;
}

.stat.known {
    background: #d1ecf1;
    color: #0c5460;
}

/* Article Images */
.article-image {
    margin: 1rem 0;
    border-radius: 8px;
    overflow: hidden;
}

.article-image img {
    width: 100%;
    height: 200px;
    object-fit: cover;
    border-radius: 8px;
    transition: transform 0.2s;
}

.article-image img:hover {
    transform: scale(1.02);
}

.article-image-full {
    margin: 2rem 0;
    text-align: center;
}

.article-image-full img {
    max-width: 100%;
    height: auto;
    border-radius: 12px;
    box-shadow: 0 4px 20px rgba(0,0,0,0.1);
}

/* Article Content */
.article-preview {
    color: #666;
    margin-bottom: 1rem;
    line-height: 1.6;
}

.article-content {
    font-size: 1.1rem;
    line-height: 1.8;
    margin: 2rem 0;
}

.article-content p {
    margin-bottom: 1.5rem;
}

.article-content p:last-child {
    margin-bottom: 0;
}

.article-footer {
    display: flex;
    justify-content: flex-end;
    align-items: center;
    padding-top: 1rem;
    border-top: 1px solid #e9ecef;
    margin-top: auto;
}

.original-link, .back-link {
    color: #667eea;
    text-decoration: none;
    font-weight: 500;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    transition: background 0.2s;
}

.original-link:hover, .back-link:hover {
    background: #f8f9ff;
}

/* Furigana Styles */
ruby {
    ruby-position: over;
    display: ruby;
    ruby-align: center;
}

rt {
    display: ruby-text;
    font-size: 0.6em;
    color: #666;
    font-weight: normal;
    line-height: 1;
    text-align: center;
}

/* Level-based furigana control */
ruby.hide-furigana rt {
    display: none;
}

ruby.show-furigana rt {
    display: ruby-text;
}

/* Kanji By Level List */
.kanji-by-level-list {
    margin: 1rem 0;
}

.kanji-by-level-list summary {
    cursor: pointer;
    font-weight: 500;
    color: #667eea;
    margin-bottom: 0.5rem;
}

.unknown-kanji-list {
    margin: 1rem 0;
}

.unknown-kanji-list summary {
    cursor: pointer;
    font-weight: 500;
    color: #667eea;
    margin-bottom: 0.5rem;
}

.kanji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 0.5rem;
    margin-top: 0.5rem;
}

.kanji-item {
    background: #fff3cd;
    color: #856404;
    padding: 0.5rem;
    text-align: center;
    border-radius: 6px;
    font-weight: 500;
    font-size: 1.2rem;
}

/* Full Article */
.article-full {
    background: white;
    border-radius: 12px;
    padding: 2rem;
    box-shadow: 0 2px 10px rgba(0,0,0,0.1);
    margin-bottom: 2rem;
}

.article-full .article-title {
    font-size: 2rem;
    margin-bottom: 1rem;
    color: #333;
}

/* Footer */
.site-footer {
    background: #343a40;
    color: white;
    text-align: center;
    padding: 2rem 0;
    margin-top: 3rem;
}

.site-footer a {
    color: #adb5bd;
}

.no-articles {
    text-align: center;
    color: #666;
    font-size: 1.1rem;
    padding: 3rem;
}

/* Responsive Design */
@media (max-width: 768px) {
    .container {
        padding: 0 15px;
    }

    .header-container {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .header-left {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.25rem;
    }

    .controls {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.75rem;
        width: 100%;
    }

    .level-slider {
        width: 100%;
        max-width: 300px;
    }

    .site-header h1 {
        font-size: 1.3rem;
    }

    .site-description {
        font-size: 0.8rem;
    }

    .articles-grid {
        grid-template-columns: 1fr;
        gap: 1rem;
    }

    .article-card {
        padding: 1rem;
    }

    .article-footer {
        flex-direction: column;
        gap: 1rem;
        align-items: stretch;
    }

    .article-full {
        padding: 1rem;
    }

    .article-full .article-title {
        font-size: 1.5rem;
    }

    .article-image img {
        height: 150px;
    }

    .article-image-full img {
        border-radius: 8px;
    }
}