:root {
    --lib-primary: #2d6b4f;
    --lib-secondary: #1f4d38;
    --lib-accent: #4f8c70;
    --lib-light: #f1f5f2;
    --lib-light-border: #d6dfd9;
    --lib-hover-bg: #eaefec;
    --lib-update-bg: #fff8e6;
    --lib-update-border: #d4a017;
    --lib-update-text: #5b4200;
    --lib-imported-bg: #eef5f0;
    --lib-imported-border: #4f8c70;
    --lib-imported-text: #1f4d38;
    --lib-danger: #b3261e;
    --lib-chip-bg: #f5f7f5;
    --lib-chip-border: #cfd6d1;
    --lib-chip-text: #3a4a42;
}

[data-theme='dark'] {
    --lib-primary: #6fa88e;
    --lib-secondary: #4f8c70;
    --lib-accent: #8ec4ad;
    --lib-light: #1c2a23;
    --lib-light-border: #2c3e35;
    --lib-hover-bg: #213029;
    --lib-update-bg: #3a2f15;
    --lib-update-border: #d4a017;
    --lib-update-text: #f0d27a;
    --lib-imported-bg: #1c2a23;
    --lib-imported-border: #4f8c70;
    --lib-imported-text: #a5cdb8;
    --lib-chip-bg: #232c27;
    --lib-chip-border: #38463d;
    --lib-chip-text: #c5d2cb;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    line-height: 1.5;
    color: var(--text-color, #2a2f2c);
    background-color: var(--surface-secondary, #fafbfa);
    margin: 0;
    padding: 0;
    min-height: 100vh;
}

.container {
    width: 90%;
    max-width: 960px;
    margin: 1rem auto;
}

.library-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem 1rem;
    background-color: var(--surface-color, #fff);
    border-radius: 6px;
    box-shadow: 0 1px 3px var(--shadow-color, rgba(0, 0, 0, 0.08));
    margin-bottom: 1rem;
    border-left: 3px solid var(--lib-primary);
}

.back-link {
    color: var(--lib-primary);
    text-decoration: none;
    font-size: 1.5rem;
    font-weight: 500;
    line-height: 1;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    transition: background-color 0.2s;
}

.back-link:hover {
    background-color: var(--lib-light);
}

.header-content {
    flex: 1;
    text-align: center;
}

.library-header h1 {
    color: var(--lib-primary);
    margin: 0;
    font-size: 1.3rem;
    font-weight: 600;
    letter-spacing: 0.01em;
}

.library-header p {
    margin: 0.2rem 0 0 0;
    font-size: 0.9rem;
    color: var(--text-muted, #6c7570);
}

.state-message {
    padding: 1.5rem;
    text-align: center;
    color: var(--text-muted, #6c7570);
    background-color: var(--surface-color, #fff);
    border-radius: 6px;
    box-shadow: 0 1px 3px var(--shadow-color, rgba(0, 0, 0, 0.08));
}

.search-row {
    margin-bottom: 1rem;
}

.library-search-input {
    width: 100%;
    box-sizing: border-box;
    padding: 0.6rem 0.9rem;
    font-size: 1rem;
    border: 1px solid var(--input-border, #ced4da);
    border-radius: 5px;
    background-color: var(--input-bg, #fff);
    color: var(--text-color, #2a2f2c);
}

.library-search-input:focus {
    outline: none;
    border-color: var(--lib-primary);
    box-shadow: 0 0 0 2px var(--lib-light);
}

.deck-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(290px, 1fr));
    gap: 1rem;
}

.deck-card {
    background-color: var(--surface-color, #fff);
    border-radius: 6px;
    padding: 1rem 1.1rem;
    box-shadow: 0 1px 3px var(--shadow-color, rgba(0, 0, 0, 0.08));
    border-top: 3px solid var(--lib-primary);
    cursor: pointer;
    transition:
        box-shadow 0.15s ease,
        transform 0.15s ease;
    display: flex;
    flex-direction: column;
    gap: 0.55rem;
    text-decoration: none;
    color: inherit;
}

.deck-card:hover {
    transform: translateY(-1px);
    box-shadow: 0 3px 8px var(--shadow-color, rgba(0, 0, 0, 0.12));
    background-color: var(--lib-hover-bg);
}

/* Small monospace-ish chips for subject/grade/learningUnit codes */
.meta-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 0.3rem;
}

.meta-chip {
    font-size: 0.72rem;
    padding: 0.1rem 0.45rem;
    background-color: var(--lib-chip-bg);
    color: var(--lib-chip-text);
    border: 1px solid var(--lib-chip-border);
    border-radius: 3px;
    font-family: 'SFMono-Regular', Consolas, monospace;
    letter-spacing: 0.02em;
    line-height: 1.4;
}

.deck-card-title {
    font-size: 1.05rem;
    font-weight: 600;
    color: var(--lib-secondary);
    margin: 0;
    word-break: break-word;
    line-height: 1.3;
}

.deck-card-description {
    font-size: 0.88rem;
    color: var(--text-muted, #6c7570);
    margin: 0;
    line-height: 1.4;
}

.deck-card-stats {
    font-size: 0.85rem;
    color: var(--text-muted, #6c7570);
}

.stats-line {
    margin: 0;
}

.stats-breakdown {
    color: var(--text-muted, #888);
    font-size: 0.82rem;
}

/* Bullet list of categories — "table of contents" feel */
.category-list {
    list-style: none;
    margin: 0.25rem 0 0 0;
    padding: 0;
    font-size: 0.88rem;
    color: var(--text-color, #2a2f2c);
}

.category-list li {
    padding: 0.1rem 0;
    padding-left: 0.85rem;
    position: relative;
    line-height: 1.4;
}

.category-list li::before {
    content: '•';
    position: absolute;
    left: 0;
    color: var(--lib-accent);
    font-weight: bold;
}

.category-list .cat-count {
    color: var(--text-muted, #888);
    font-size: 0.82rem;
    margin-left: 0.25rem;
}

.category-list .cat-more {
    color: var(--text-muted, #888);
    font-style: italic;
    list-style: none;
    padding-left: 0.85rem;
}

.category-list .cat-more::before {
    content: '…';
    position: absolute;
    left: 0;
    color: var(--text-muted, #888);
}

.deck-card-status {
    margin-top: auto;
    padding-top: 0.4rem;
    font-size: 0.82rem;
}

.status-pill {
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.1rem 0.55rem;
    border-radius: 3px;
    font-weight: 500;
    border: 1px solid;
}

.status-pill.imported {
    background-color: var(--lib-imported-bg);
    color: var(--lib-imported-text);
    border-color: var(--lib-imported-border);
}

.status-pill.update {
    background-color: var(--lib-update-bg);
    color: var(--lib-update-text);
    border-color: var(--lib-update-border);
}

/* Detail view */
.back-to-grid {
    margin-bottom: 1rem;
}

.detail-card {
    background-color: var(--surface-color, #fff);
    border-radius: 6px;
    padding: 1.5rem;
    box-shadow: 0 1px 3px var(--shadow-color, rgba(0, 0, 0, 0.08));
    border-top: 3px solid var(--lib-primary);
}

.detail-title {
    font-size: 1.5rem;
    color: var(--lib-secondary);
    margin: 0 0 0.4rem 0;
    word-break: break-word;
    font-weight: 600;
}

.detail-description {
    font-size: 0.95rem;
    color: var(--text-color, #2a2f2c);
    margin: 0.5rem 0 1rem 0;
    line-height: 1.5;
}

.detail-meta {
    margin: 0.75rem 0 1.25rem 0;
    padding: 0.75rem 0.9rem;
    background-color: var(--surface-secondary, #fafbfa);
    border: 1px solid var(--border-color, #e4e7e5);
    border-radius: 5px;
    display: grid;
    grid-template-columns: max-content 1fr;
    column-gap: 1rem;
    row-gap: 0.3rem;
    font-size: 0.9rem;
}

.detail-meta-row {
    display: contents;
}

.detail-meta dt {
    color: var(--text-muted, #6c7570);
    font-weight: 500;
}

.detail-meta dd {
    margin: 0;
    color: var(--text-color, #2a2f2c);
    word-break: break-word;
}

.detail-meta-row:nth-last-child(-n + 3) dd {
    font-family: 'SFMono-Regular', Consolas, monospace;
    font-size: 0.85rem;
    color: var(--text-muted, #6c7570);
}

.detail-meta dd a {
    color: var(--lib-primary);
    text-decoration: underline;
}

.update-banner,
.imported-banner {
    padding: 0.75rem 0.9rem;
    border-radius: 4px;
    margin-bottom: 1rem;
    border-left: 3px solid;
    font-size: 0.92rem;
}

.update-banner {
    background-color: var(--lib-update-bg);
    border-left-color: var(--lib-update-border);
    color: var(--lib-update-text);
}

.imported-banner {
    background-color: var(--lib-imported-bg);
    border-left-color: var(--lib-imported-border);
    color: var(--lib-imported-text);
}

.banner-title {
    font-weight: 600;
    margin-bottom: 0.2rem;
}

.banner-detail {
    font-size: 0.88rem;
    line-height: 1.4;
}

/* Detail stats: one prominent count, breakdown line below */
.detail-summary {
    background-color: var(--surface-secondary, #fafbfa);
    border: 1px solid var(--border-color, #e4e7e5);
    border-radius: 5px;
    padding: 0.9rem 1rem;
    margin: 1rem 0 1.25rem 0;
}

.detail-summary-count {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--lib-secondary);
    margin: 0;
}

.detail-summary-breakdown {
    font-size: 0.88rem;
    color: var(--text-muted, #6c7570);
    margin: 0.2rem 0 0 0;
}

.detail-section-title {
    font-size: 0.95rem;
    margin: 1rem 0 0.4rem 0;
    color: var(--text-color, #2a2f2c);
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.detail-author {
    font-size: 0.85rem;
    color: var(--text-muted, #6c7570);
    margin-top: 1rem;
    padding-top: 0.75rem;
    border-top: 1px solid var(--border-color, #e4e7e5);
}

.detail-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.55rem;
    margin-top: 1.5rem;
}

.btn {
    padding: 0.55rem 1.05rem;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 0.95rem;
    font-weight: 500;
    transition:
        background-color 0.15s,
        transform 0.1s;
    font-family: inherit;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
}

.btn:active {
    transform: translateY(1px);
}

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

.btn-primary {
    background-color: var(--lib-primary);
    color: white;
}

.btn-primary:hover {
    background-color: var(--lib-secondary);
}

.btn-secondary {
    background-color: var(--surface-secondary, #fafbfa);
    color: var(--text-color, #2a2f2c);
    border: 1px solid var(--border-color, #ced4d0);
}

.btn-secondary:hover {
    background-color: var(--lib-hover-bg);
}

.btn-update {
    background-color: var(--lib-update-border);
    color: #2a2200;
}

.btn-update:hover {
    background-color: #b88912;
}

.message-banner {
    position: fixed;
    bottom: 1rem;
    left: 50%;
    transform: translateX(-50%);
    background-color: var(--lib-secondary);
    color: white;
    padding: 0.7rem 1.2rem;
    border-radius: 5px;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.15);
    z-index: 1000;
    max-width: 90%;
    text-align: center;
    font-size: 0.92rem;
}

.message-banner.error {
    background-color: var(--lib-danger);
}

.hidden {
    display: none !important;
}

@media (max-width: 600px) {
    .container {
        width: 95%;
    }
    .deck-grid {
        grid-template-columns: 1fr;
    }
    .detail-card {
        padding: 1.1rem;
    }
    .detail-title {
        font-size: 1.25rem;
    }
}
