:root {
    /* Educational & Clean Theme */
    --bg-body: #f1f3f5;
    --bg-surface: #ffffff;
    --bg-header: #3b5bdb;
    /* Classic educational blue */
    --text-primary: #343a40;
    --text-secondary: #495057;
    --text-muted: #868e96;
    --text-inverse: #ffffff;

    --border-color: #dee2e6;
    --border-color-hover: #adb5bd;

    --accent-color: #3b5bdb;
    --accent-hover: #4c6ef5;

    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px rgba(0, 0, 0, 0.08);

    /* Category Tag Colors (Muted for readability) */
    --tag-joy: #ffe3e3;
    --tag-joy-text: #c92a2a;
    --tag-sad: #e7f5ff;
    --tag-sad-text: #1864ab;
    --tag-anger: #fff0f6;
    --tag-anger-text: #a61e4d;
    --tag-surprise: #fff9db;
    --tag-surprise-text: #e67700;
    --tag-fear: #f3f0ff;
    --tag-fear-text: #5f3dc4;
    --tag-awe: #e6fcf5;
    --tag-awe-text: #0ca678;
    /* Teal/Green for Awe/Emotion */
}

/* Accessibility: SR Only class */
.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Noto Sans JP', sans-serif;
    background-color: var(--bg-body);
    color: var(--text-primary);
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
}

/* Typography styles for dictionary terms */
h1,
h2,
h3,
.word-term,
.detail-term {
    font-family: 'Noto Serif JP', serif;
}

/* Header */
.app-header {
    background-color: var(--bg-header);
    color: var(--text-inverse);
    padding: 1rem 0;
    box-shadow: var(--shadow-sm);
}

.header-content {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 1.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 1rem;
}

.site-branding {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.app-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin: 0;
    letter-spacing: 1px;
}

.subtitle {
    font-size: 0.9rem;
    opacity: 0.9;
    font-family: 'Noto Sans JP', sans-serif;
}

/* Layout */
.app-container {
    max-width: 1200px;
    margin: 2rem auto;
    padding: 0 1.5rem;
    display: grid;
    grid-template-columns: 280px 1fr;
    gap: 2rem;
    align-items: start;
}

/* Views */
.view {
    display: none;
}

.view.active {
    display: block;
    animation: fadeIn 0.3s ease;
}

.template-hidden {
    display: none !important;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(5px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* Sidebar */
.sidebar {
    background: var(--bg-surface);
    border-radius: 8px;
    box-shadow: var(--shadow-sm);
    border: 1px solid var(--border-color);
    padding: 1.5rem;
    position: sticky;
    top: 2rem;
}

/* Search Box */
.search-container {
    margin-bottom: 2rem;
}

.search-box {
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 10px;
    color: var(--text-muted);
}

#search-input {
    width: 100%;
    padding: 0.75rem 1rem 0.75rem 2.5rem;
    border: 2px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    transition: border-color 0.2s;
}

#search-input:focus {
    outline: none;
    border-color: var(--accent-color);
}

/* Category Nav */
.category-nav h2 {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}

#category-list {
    list-style: none;
}

/* Using a custom list design for categories */
.category-item {
    margin-bottom: 0.5rem;
}

.category-btn {
    width: 100%;
    text-align: left;
    background: transparent;
    border: none;
    padding: 0.75rem 1rem;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    color: var(--text-primary);
    transition: background-color 0.2s;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.category-btn:hover {
    background-color: var(--bg-body);
}

.category-btn.active {
    background-color: var(--accent-color);
    color: white;
    font-weight: 500;
}

/* Main Content Area */
.main-content {
    min-height: 500px;
}

/* List Header */
.list-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1.5rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}

.list-header h2 {
    font-size: 1.5rem;
    color: var(--text-primary);
}

.word-count {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

/* Word List Grid (More dense for studying) */
.word-list {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 1rem;
}

.word-item {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 1.25rem;
    cursor: pointer;
    transition: box-shadow 0.2s, border-color 0.2s;
    display: flex;
    flex-direction: column;
}

.word-item:hover {
    box-shadow: var(--shadow-md);
    border-color: var(--accent-color);
}

.word-item-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 0.5rem;
}

.word-term {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: 0.25rem;
    line-height: 1.2;
}

.word-reading {
    font-size: 0.85rem;
    color: var(--text-secondary);
    font-family: 'Noto Sans JP', sans-serif;
}

.list-word-meaning {
    font-size: 0.95rem;
    color: var(--text-primary);
    display: -webkit-box;
    -webkit-line-clamp: 2;
    -webkit-box-orient: vertical;
    overflow: hidden;
    margin-top: 0.5rem;
    flex-grow: 1;
}

/* Tags */
.tag {
    display: inline-block;
    padding: 0.25rem 0.6rem;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 700;
}

.tag-喜び {
    background: var(--tag-joy);
    color: var(--tag-joy-text);
}

.tag-悲しみ {
    background: var(--tag-sad);
    color: var(--tag-sad-text);
}

.tag-怒り {
    background: var(--tag-anger);
    color: var(--tag-anger-text);
}

.tag-驚き {
    background: var(--tag-surprise);
    color: var(--tag-surprise-text);
}

.tag-感動 {
    background: var(--tag-awe);
    color: var(--tag-awe-text);
}

.tag-恐れ {
    background: var(--tag-fear);
    color: var(--tag-fear-text);
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    border-radius: 6px;
    font-size: 1rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    border: none;
    font-family: inherit;
}

.btn-secondary {
    background-color: var(--bg-surface);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background-color: var(--bg-body);
    border-color: var(--border-color-hover);
}

.detail-actions {
    margin-bottom: 1.5rem;
}

/* Dictionary Entry (Detail View) */
.dictionary-entry {
    background: var(--bg-surface);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 3rem;
    box-shadow: var(--shadow-sm);
}

.entry-header {
    margin-bottom: 2.5rem;
    padding-bottom: 2rem;
    border-bottom: 3px double var(--border-color);
    /* Dictionary feel */
}

.detail-reading {
    font-size: 1.4rem;
    color: var(--text-secondary);
    margin-bottom: 0.5rem;
    letter-spacing: 1px;
}

.entry-title-row {
    display: flex;
    align-items: baseline;
    gap: 1.5rem;
    flex-wrap: wrap;
}

.detail-term {
    font-size: 3.5rem;
    font-weight: 700;
    margin: 0;
    line-height: 1.2;
}

.entry-section {
    margin-bottom: 2.5rem;
}

.entry-section h3 {
    font-family: 'Noto Sans JP', sans-serif;
    font-size: 1.4rem;
    color: var(--accent-color);
    margin-bottom: 1rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.entry-section h3::before {
    content: "■";
    font-size: 1rem;
}

.detail-meaning {
    font-size: 1.5rem;
    font-weight: 500;
    line-height: 1.8;
    margin-bottom: 1rem;
    color: var(--text-primary);
}

.detail-nuance {
    background-color: var(--bg-body);
    padding: 1.5rem;
    border-radius: 6px;
    border-left: 6px solid var(--border-color-hover);
    font-size: 1.25rem;
    line-height: 1.8;
}

/* Example Sentences List */
.example-list {
    list-style: none;
}

.example-item {
    margin-bottom: 1.5rem;
    padding-left: 2rem;
    position: relative;
}

.example-item::before {
    content: "・";
    position: absolute;
    left: 0;
    top: 2px;
    font-size: 1.5rem;
    color: var(--text-secondary);
}

.example-ja {
    font-size: 1.35rem;
    line-height: 1.7;
    margin-bottom: 0.5rem;
}

/* Responsive */
@media (max-width: 768px) {
    .app-container {
        grid-template-columns: 1fr;
    }

    .sidebar {
        position: static;
        margin-bottom: 1rem;
    }

    .dictionary-entry {
        padding: 1.5rem;
    }

    .detail-term {
        font-size: 2.5rem;
    }

    .detail-reading {
        font-size: 1.2rem;
    }

    .detail-meaning {
        font-size: 1.25rem;
    }

    .example-ja {
        font-size: 1.2rem;
    }

    .word-list {
        grid-template-columns: 1fr;
    }
}