/* Library: quiet surfaces, clear titles and consistent action states. */
.xp-root {
    --xp-panel: var(--wq-surface, #1a1d24);
    --xp-panel-2: var(--wq-surface-2, #23262f);
    --xp-border: var(--wq-border, #2b2f3a);
    --xp-text: var(--wq-text, #e8eaf0);
    --xp-muted: var(--wq-text-muted, #9aa0ad);
    --xp-accent: var(--wq-accent-2, #a0d3e1);
    max-width: var(--wq-page-max, 1080px);
    margin: 0 auto;
    padding: 8px 0 56px;
    color: var(--xp-text);
    min-width: 0;
}
.xp-root, .xp-root * { box-sizing: border-box; }
.xp-root :is(a, button, select):focus-visible {
    outline: 2px solid var(--xp-accent);
    outline-offset: 4px;
}
.xp-heading {
    display: flex;
    align-items: flex-end;
    justify-content: space-between;
    gap: 20px;
    margin-bottom: 18px;
}
.xp-heading h1 {
    margin: 0;
    font-size: clamp(1.5rem, 3vw, 1.9rem);
    font-weight: 750;
    letter-spacing: -.045em;
    line-height: 1.3;
}
.xp-section { min-width: 0; }

/* Search and filters form one compact toolbar. */
.xp-search-row { margin-bottom: 12px; }
.xp-search {
    display: flex;
    align-items: center;
    gap: 10px;
    min-height: 52px;
    padding: 5px 6px 5px 16px;
    border: 1px solid var(--xp-border);
    border-radius: 13px;
    background: var(--xp-panel);
    transition: border-color .16s, box-shadow .16s;
}
.xp-search:focus-within { border-color: var(--xp-accent); box-shadow: 0 0 0 3px var(--wq-accent-soft); }
.xp-search-ico { display: inline-flex; flex-shrink: 0; color: var(--xp-muted); }
.xp-root input.xp-search-input,
html.dark .xp-root input.xp-search-input {
    flex: 1;
    min-width: 0;
    height: 38px !important;
    min-height: 0 !important;
    padding: 0 !important;
    margin: 0 !important;
    border: 0 !important;
    background: transparent !important;
    box-shadow: none !important;
    outline: none;
    color: var(--xp-text) !important;
    font: inherit;
    font-size: .9rem !important;
}
.xp-search-input::placeholder { color: var(--xp-muted); }
.xp-search-clear { display: inline-flex; align-items: center; justify-content: center; width: 36px; height: 36px; color: var(--xp-muted); border-radius: 8px; }
.xp-search-clear:hover { color: var(--xp-text); }
.xp-search-submit {
    min-height: 40px;
    padding: 0 18px;
    border: 0;
    border-left: 1px solid var(--xp-border);
    border-radius: 0;
    background: transparent;
    color: var(--xp-text);
    font: inherit;
    font-size: .8rem;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
}
.xp-search-submit:hover { color: var(--xp-accent); }
.xp-filter-row { display: flex; align-items: center; gap: 16px; margin-bottom: 24px; min-width: 0; }
.xp-topic-bar { display: flex; flex: 1; min-width: 0; gap: 4px; overflow-x: auto; scrollbar-width: none; padding: 4px 0; }
.xp-topic-bar::-webkit-scrollbar { display: none; }
.xp-root a.xp-topic {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-height: 38px;
    padding: 0 13px;
    border-radius: 9px;
    border: 1px solid transparent;
    color: var(--xp-muted);
    text-decoration: none;
    white-space: nowrap;
    font-size: .8rem;
    font-weight: 500;
    flex-shrink: 0;
}
.xp-root a.xp-topic:hover { background: var(--xp-panel); color: var(--xp-text); }
.xp-root a.xp-topic.is-active { background: var(--wq-accent-soft); color: var(--xp-accent); border-color: rgba(160, 211, 225, .18); font-weight: 650; }
.xp-toolbar, .xp-topic-mobile { margin: 0; flex-shrink: 0; }
.xp-topic-mobile { display: none; }
.xp-sort-wrap { display: flex; align-items: center; min-height: 40px; gap: 8px; padding: 0 11px; border: 1px solid var(--xp-border); border-radius: 9px; background: var(--xp-panel); }
.xp-sort-ico { display: inline-flex; color: var(--xp-muted); flex-shrink: 0; }
.xp-root .xp-sort-select,
html.dark .xp-root .xp-sort-select {
    appearance: none;
    border: 0;
    padding: 0 20px 0 0;
    min-width: 72px;
    min-height: 0;
    height: 36px;
    margin: 0;
    color: var(--xp-text);
    font: inherit;
    font-size: .78rem;
    background: transparent url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa0ad' stroke-width='2'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") right center / 12px no-repeat !important;
    cursor: pointer;
}
.xp-sort-select option { background: var(--xp-panel); color: var(--xp-text); }
.xp-active-filters { display: flex; align-items: center; flex-wrap: wrap; gap: 8px; margin: -8px 0 20px; font-size: .73rem; }
.xp-af-label, .xp-af-k { color: var(--xp-muted); }
.xp-af-label { margin-right: 2px; }
.xp-af-chip { display: inline-flex; align-items: center; gap: 6px; padding: 5px 9px; border-radius: 6px; background: var(--xp-panel-2); }
.xp-root a.xp-af-clear { padding: 8px 0 8px 6px; color: var(--xp-muted); text-decoration: none; }
.xp-root a.xp-af-clear:hover { color: var(--xp-text); }

/* Consistent card hierarchy: metadata, title, creator, action. */
.xp-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 16px; }
.xp-card {
    min-width: 0;
    position: relative;
    display: flex;
    flex-direction: column;
    padding: 20px;
    border: 1px solid var(--xp-border);
    border-radius: 16px;
    background: var(--xp-panel);
    transition: border-color .18s, box-shadow .18s;
}
.xp-card:hover { border-color: var(--wq-border-strong); box-shadow: 0 8px 24px rgba(0, 0, 0, .10); }
.xp-card:focus-within { border-color: var(--xp-accent); }
.xp-card-top { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 16px; }
.xp-card-chips { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; min-width: 0; }
.xp-chip-topic { padding: 4px 8px; border-radius: 6px; color: var(--xp-accent); background: var(--wq-accent-soft); font-size: .68rem; font-weight: 600; line-height: 1.4; }
.xp-chip-count { color: var(--xp-muted); font-size: .71rem; white-space: nowrap; }
.xp-card-badges { flex-shrink: 0; }
.xp-badge { font-size: .66rem; font-weight: 500; color: var(--xp-muted); white-space: nowrap; }
.xp-card-main { flex: 1; min-width: 0; }
.xp-card-title { margin: 0; font-size: 1.02rem; font-weight: 650; line-height: 1.55; letter-spacing: -.025em; overflow-wrap: anywhere; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.xp-root .xp-card-title a { color: var(--xp-text); text-decoration: none; }
.xp-stretched::after { content: ""; position: absolute; inset: 0; border-radius: 16px; z-index: 1; }
.xp-card-desc { margin: 8px 0 0; color: var(--xp-muted); font-size: .78rem; line-height: 1.65; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; overflow-wrap: anywhere; }
.xp-card-bottom { display: flex; flex-direction: column; gap: 12px; margin-top: 20px; }
.xp-card-author { display: flex; align-items: center; gap: 6px; color: var(--xp-muted); font-size: .7rem; min-width: 0; }
.xp-card-author svg { flex-shrink: 0; }
.xp-card-author span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.xp-card-tags { display: flex; flex-wrap: wrap; gap: 8px; }
.xp-root a.xp-tag { color: var(--xp-muted); text-decoration: none; font-size: .69rem; position: relative; z-index: 2; }
.xp-root a.xp-tag:hover { color: var(--xp-accent); }
.xp-card-empty-space { display: none; }
.xp-progress-mini { display: flex; align-items: center; gap: 8px; }
.xp-progress-bar { flex: 1; height: 3px; border-radius: 4px; background: var(--xp-border); overflow: hidden; }
.xp-progress-bar span { display: block; height: 100%; border-radius: inherit; background: var(--xp-accent); }
.xp-progress-val { color: var(--xp-muted); font-size: .68rem; font-variant-numeric: tabular-nums; }
.xp-card-action { display: flex; gap: 8px; border-top: 1px solid var(--xp-border); padding-top: 14px; }
.xp-root .xp-study-btn {
    position: relative;
    z-index: 2;
    flex: 1;
    min-width: 0;
    min-height: 44px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 10px 12px;
    margin: 0;
    border: 1px solid rgba(160, 211, 225, .22);
    border-radius: 9px;
    background: var(--wq-accent-soft);
    color: var(--xp-accent);
    font: inherit;
    font-size: .78rem;
    font-weight: 600;
    line-height: 1.4;
    text-decoration: none;
    cursor: pointer;
    transition: background-color .16s, border-color .16s;
}
.xp-study-btn svg { flex-shrink: 0; }
.xp-root .xp-play-btn { flex: .8; }
.xp-study-btn span { white-space: nowrap; }
.xp-root .xp-study-btn:hover:not(:disabled) { background: rgba(120, 189, 210, .22); border-color: var(--xp-accent); }
.xp-root .xp-study-btn:disabled { cursor: wait; }
.xp-root .xp-study-btn.is-added,
.xp-root .xp-study-btn.is-added:hover {
    color: var(--xp-muted);
    background: var(--xp-panel-2);
    border-color: var(--xp-border);
    opacity: 1;
    cursor: default;
}
.xp-root .xp-study-btn.disabled { color: var(--xp-muted); background: transparent; border-color: var(--xp-border); cursor: default; }

.xp-empty { grid-column: 1 / -1; padding: 56px 20px; text-align: center; background: var(--xp-panel); border: 1px solid var(--xp-border); border-radius: 16px; }
.xp-empty-ico { color: var(--xp-muted); margin-bottom: 16px; }
.xp-empty h3 { margin: 0 0 8px; font-size: 1rem; }
.xp-empty p { margin: 0 0 20px; color: var(--xp-muted); font-size: .84rem; line-height: 1.6; }
.xp-root a.xp-btn { display: inline-flex; align-items: center; min-height: 44px; padding: 0 16px; border: 1px solid var(--xp-border); border-radius: 9px; color: var(--xp-text); text-decoration: none; background: var(--xp-panel-2); font-size: .8rem; }
.xp-pagination { display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 28px; }
.xp-pg-nums { display: flex; gap: 4px; }
.xp-root :is(.xp-pg-link, .xp-pg-num) { display: inline-flex; align-items: center; justify-content: center; min-width: 38px; min-height: 44px; padding: 0 8px; border-radius: 9px; gap: 4px; color: var(--xp-muted); text-decoration: none; font-size: .78rem; }
.xp-root :is(a.xp-pg-link, a.xp-pg-num):hover { color: var(--xp-text); background: var(--xp-panel-2); }
.xp-root .xp-pg-num.is-active { color: var(--xp-accent); background: var(--wq-accent-soft); font-weight: 650; }
.xp-root .xp-pg-link.disabled { opacity: .35; }

@media (max-width: 960px) {
    .xp-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 640px) {
    .xp-root { padding: 4px 0 32px; }
    .xp-heading { margin-bottom: 12px; }
    .xp-heading h1 { font-size: 1.25rem; }
    .xp-search-row { margin-bottom: 8px; }
    .xp-search { min-height: 46px; padding: 0 4px 0 12px; gap: 7px; }
    .xp-root input.xp-search-input,
    html.dark .xp-root input.xp-search-input { font-size: 16px !important; }
    .xp-search-submit { padding: 0 13px; }
    .xp-filter-row { gap: 8px; margin-bottom: 12px; }
    .xp-topic-bar { display: none; }
    .xp-topic-mobile { display: block; flex: 1; min-width: 0; }
    .xp-toolbar { flex: 1; min-width: 0; }
    .xp-sort-wrap { min-height: 44px; }
    .xp-root .xp-sort-select { flex: 1; min-width: 0; width: 100%; }
    .xp-grid { grid-template-columns: 1fr; gap: 8px; }
    .xp-card { padding: 12px 14px; border-radius: 12px; }
    .xp-card-top { margin-bottom: 7px; }
    .xp-chip-topic { padding: 2px 6px; }
    .xp-card-title { font-size: .94rem; line-height: 1.45; }
    .xp-card-desc { margin-top: 4px; -webkit-line-clamp: 1; line-height: 1.45; font-size: .74rem; }
    .xp-card-bottom { display: grid; grid-template-columns: minmax(0, 1fr) auto; column-gap: 10px; row-gap: 8px; align-items: center; margin-top: 9px; }
    .xp-card-author { grid-column: 1; grid-row: 1; font-size: .67rem; }
    .xp-card-tags, .xp-progress-mini { grid-column: 2; grid-row: 1; }
    .xp-card-tags { flex-wrap: nowrap; overflow: hidden; }
    .xp-root a.xp-tag { white-space: nowrap; text-overflow: ellipsis; overflow: hidden; }
    .xp-card-action { grid-column: 1 / -1; grid-row: 2; padding: 0; border: 0; }
    .xp-root .xp-study-btn { width: auto; padding: 8px 10px; gap: 5px; font-size: .71rem; border-radius: 8px; }
    .xp-active-filters { gap: 6px; margin: 0 0 12px; }
    .xp-af-label { display: none; }
    .xp-pagination { gap: 2px; }
    .xp-root .xp-pg-num { min-width: 30px; padding: 0 6px; }
    .xp-pg-link span { display: none; }
}
@media (prefers-reduced-motion: reduce) {
    .xp-root * { transition: none !important; }
}
