/* =========================================================================
   NOTES LIBRARY

   The Home card and the two screens behind it (topics, then the chapters of
   one topic that have notes). notesLibrary.js paints both screens.

   Gold (--warning) is the card's accent and appears in two places only: the
   Home card and the topic icon tiles. Kind colours (PDF / Notes / Written /
   Formula) touch icons only, never a surface, so a long chapter list stays
   quiet. Tokens only — both themes come out of premium-ui.css.
   ========================================================================= */

/* ── Home card ───────────────────────────────────────────────────────────── */

.nlib-home-card {
    grid-column: 1 / -1 !important;
    position: relative;
    overflow: hidden;
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 18px;
    padding: 20px 22px;
    border-radius: var(--radius, 20px);
    border: 1px solid color-mix(in srgb, var(--warning) 38%, var(--line));
    background:
        radial-gradient(120% 140% at 100% 0%, color-mix(in srgb, var(--warning) 16%, transparent) 0%, transparent 55%),
        linear-gradient(135deg, color-mix(in srgb, var(--warning) 9%, var(--surface-solid)) 0%, var(--surface-solid) 70%);
    box-shadow: var(--shadow-sm);
    cursor: pointer;
    transition: transform .2s ease, box-shadow .2s ease, border-color .2s ease;
    -webkit-tap-highlight-color: transparent;
}

.nlib-home-card:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--warning) 60%, var(--line));
    box-shadow: var(--shadow-md);
}

.nlib-home-card:active { transform: scale(.985); }

.nlib-home-card:focus-visible {
    outline: 2px solid var(--warning);
    outline-offset: 3px;
}

.nlib-hc-icon {
    width: 56px;
    height: 56px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.45rem;
    color: #1d1503;
    background: linear-gradient(145deg, color-mix(in srgb, var(--warning) 80%, #fff) 0%, var(--warning) 100%);
    box-shadow: 0 6px 18px color-mix(in srgb, var(--warning) 35%, transparent);
}

.nlib-hc-text { min-width: 0; }

.nlib-home-card h3 {
    margin: 0 0 3px;
    font-size: 1.15rem;
    font-weight: 800;
    color: var(--text-main) !important;
}

.nlib-home-card p {
    margin: 0;
    font-size: .86rem;
    line-height: 1.4;
    color: var(--text-muted) !important;
}

.nlib-hc-stats {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-top: 10px;
}

.nlib-hc-stats:empty { display: none; }

.nlib-hc-go {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 9px 16px;
    border-radius: 999px;
    font-size: .85rem;
    font-weight: 700;
    white-space: nowrap;
    color: var(--text-main);
    border: 1px solid color-mix(in srgb, var(--warning) 45%, var(--line));
    background: color-mix(in srgb, var(--warning) 10%, transparent);
    transition: background .2s ease, color .2s ease;
}

.nlib-home-card:hover .nlib-hc-go {
    background: var(--warning);
    color: #1d1503;
}

.nlib-home-card.is-empty .nlib-hc-icon { filter: saturate(.4); }

/* ── Chips (card, topic tiles, rows) ─────────────────────────────────────── */

.nlib-chip {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 3px 9px;
    border-radius: 999px;
    font-size: .72rem;
    font-weight: 600;
    line-height: 1.5;
    color: var(--text-main);
    background: var(--surface-raised);
    border: 1px solid var(--line);
    white-space: nowrap;
}

.nlib-chip b { font-weight: 800; }
.nlib-chip-pdf i     { color: var(--danger); }
.nlib-chip-notes i   { color: var(--brand); }
.nlib-chip-written i { color: var(--success); }
.nlib-chip-formula i { color: var(--warning); }

/* ── Screens ─────────────────────────────────────────────────────────────── */

.nlib {
    max-width: 920px;
    margin: 0 auto;
    padding: 4px 0 40px;
}

.nlib-head {
    display: flex;
    align-items: center;
    gap: 12px;
    margin-bottom: 14px;
}

.nlib-back {
    flex: 0 0 auto;
    width: 40px;
    height: 40px;
    border-radius: 12px;
    border: 1px solid var(--line);
    background: var(--surface-raised);
    color: var(--text-main);
    cursor: pointer;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    transition: border-color .18s ease, background .18s ease;
}

.nlib-back:hover {
    border-color: var(--brand);
    background: var(--brand-soft);
}

.nlib-head-icon {
    flex: 0 0 auto;
    font-size: 1.6rem;
    line-height: 1;
}

.nlib-head-text { min-width: 0; }

.nlib-head-text h2 {
    margin: 0;
    font-size: 1.3rem;
    font-weight: 800;
    color: var(--text-main);
    overflow-wrap: anywhere;
}

.nlib-head-text p {
    margin: 2px 0 0;
    font-size: .85rem;
    color: var(--text-muted);
}

.nlib-search {
    display: flex;
    align-items: center;
    gap: 10px;
    height: 46px;
    padding: 0 14px;
    margin-bottom: 16px;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--surface-solid);
    color: var(--text-muted);
    transition: border-color .18s ease, box-shadow .18s ease;
}

.nlib-search:focus-within {
    border-color: var(--brand);
    box-shadow: 0 0 0 3px var(--brand-soft);
}

/* The light theme styles every input with a border and a white fill; this
   one is drawn by its label, so all of that is taken back off. That rule is
   `html.theme-light body:not(.test-taking-mode) input` with !important, so
   this selector has to out-rank it, not just come later. */
.nlib-search input,
html body .nlib-search input[type="search"][data-nlib] {
    flex: 1 1 auto;
    min-width: 0;
    height: 100%;
    padding: 0;
    border: 0 !important;
    border-radius: 0;
    outline: 0;
    box-shadow: none !important;
    background: transparent !important;
    color: var(--text-main);
    font: inherit;
    font-size: .95rem;
}

/* Topic grid */

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

.nlib-topic {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 6px;
    padding: 16px;
    text-align: left;
    font: inherit;
    border-radius: var(--radius-sm, 14px);
    border: 1px solid var(--line);
    background: var(--surface);
    box-shadow: var(--shadow-sm);
    color: var(--text-main);
    cursor: pointer;
    transition: transform .18s ease, border-color .18s ease;
    -webkit-tap-highlight-color: transparent;
}

.nlib-topic:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--warning) 55%, var(--line));
}

.nlib-topic:active { transform: scale(.98); }

.nlib-topic-icon {
    width: 44px;
    height: 44px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    background: color-mix(in srgb, var(--warning) 14%, var(--surface-raised));
    margin-bottom: 4px;
}

.nlib-topic-name {
    font-size: 1rem;
    font-weight: 700;
    line-height: 1.3;
}

.nlib-topic-count {
    font-size: .82rem;
    color: var(--text-muted);
}

.nlib-topic-chips {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    margin-top: 4px;
}

/* "PDF Notes" — the shortcut to every booklet, first and full width so it
   reads as the place to start, in the same red the PDF chips use. */
.nlib-topic-pdf {
    grid-column: 1 / -1;
    flex-direction: row;
    align-items: center;
    gap: 14px;
    border-color: color-mix(in srgb, var(--danger) 40%, var(--line));
    background: linear-gradient(135deg, color-mix(in srgb, var(--danger) 9%, var(--surface)), var(--surface) 70%);
}

.nlib-topic-pdf:hover { border-color: color-mix(in srgb, var(--danger) 70%, var(--line)); }

.nlib-topic-pdf .nlib-topic-icon {
    flex: 0 0 auto;
    margin-bottom: 0;
    color: var(--danger);
    background: color-mix(in srgb, var(--danger) 14%, var(--surface-raised));
}

.nlib-topic-text {
    display: flex;
    flex-direction: column;
    gap: 3px;
    flex: 1;
    min-width: 0;
}

.nlib-head-icon-pdf {
    color: var(--danger);
    font-size: 1.4rem;
}

/* Chapter list */

.nlib-group + .nlib-group { margin-top: 22px; }

.nlib-group-title {
    margin: 0 0 8px 2px;
    font-size: .74rem;
    font-weight: 800;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--text-muted);
}

.nlib-list {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.nlib-row {
    display: grid;
    grid-template-columns: auto minmax(0, 1fr) auto;
    align-items: center;
    gap: 12px;
    width: 100%;
    padding: 12px 14px;
    text-align: left;
    font: inherit;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--surface);
    color: var(--text-main);
    cursor: pointer;
    transition: border-color .18s ease, background .18s ease;
    -webkit-tap-highlight-color: transparent;
}

.nlib-row:hover {
    border-color: var(--brand);
    background: color-mix(in srgb, var(--brand) 5%, var(--surface));
}

.nlib-row:active { transform: scale(.99); }

.nlib-row-icon {
    width: 38px;
    height: 38px;
    border-radius: 11px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    background: var(--surface-raised);
}

.nlib-row-pdf     { color: var(--danger);  background: color-mix(in srgb, var(--danger) 12%, var(--surface-raised)); }
.nlib-row-notes   { color: var(--brand);   background: color-mix(in srgb, var(--brand) 12%, var(--surface-raised)); }
.nlib-row-written { color: var(--success); background: color-mix(in srgb, var(--success) 12%, var(--surface-raised)); }
.nlib-row-formula { color: var(--warning); background: color-mix(in srgb, var(--warning) 12%, var(--surface-raised)); }

.nlib-row-text {
    display: flex;
    flex-direction: column;
    gap: 5px;
    min-width: 0;
}

.nlib-row-title {
    font-size: .95rem;
    font-weight: 650;
    line-height: 1.35;
    overflow-wrap: anywhere;
}

.nlib-row-sub {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 6px;
}

.nlib-row-meta {
    font-size: .78rem;
    color: var(--text-muted);
}

.nlib-row-go {
    color: var(--text-muted);
    font-size: .85rem;
}

/* Empty */

.nlib-empty {
    text-align: center;
    padding: 48px 20px;
    border-radius: var(--radius, 20px);
    border: 1px dashed var(--line);
    background: var(--surface);
}

.nlib-empty-icon {
    width: 56px;
    height: 56px;
    margin: 0 auto 12px;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4rem;
    color: var(--warning);
    background: color-mix(in srgb, var(--warning) 12%, var(--surface-raised));
}

.nlib-empty h3 {
    margin: 0 0 6px;
    font-size: 1.05rem;
    color: var(--text-main);
}

.nlib-empty p {
    margin: 0 auto;
    max-width: 420px;
    font-size: .88rem;
    color: var(--text-muted);
}

/* ── Phone ───────────────────────────────────────────────────────────────── */

@media (max-width: 560px) {
    .nlib-home-card {
        grid-template-columns: auto minmax(0, 1fr);
        gap: 14px;
        padding: 16px;
    }

    .nlib-hc-icon {
        width: 48px;
        height: 48px;
        border-radius: 14px;
        font-size: 1.25rem;
        align-self: start;
    }

    .nlib-hc-go { display: none; }

    .nlib-topics {
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .nlib-topic { padding: 13px; }
    .nlib-topic-name { font-size: .92rem; }
    .nlib-row { padding: 11px 12px; gap: 10px; }
}

@media (prefers-reduced-motion: reduce) {
    .nlib-home-card,
    .nlib-topic,
    .nlib-row { transition: none; }
    .nlib-home-card:hover,
    .nlib-topic:hover { transform: none; }
}
