/*
 * topics.css, SPEC-171 + SPEC-179
 * Styles for the /topics concept constellation. SPEC-179 reshapes it map-first:
 * a full-bleed Canvas map with a right-side episode drawer and a floating filter
 * bar (search + compact Clusters popover with Select all / Deselect all + density).
 * Built on the SPEC-156 tokens in base.css (no new colors). The crawlable .pills
 * List view keeps its base.css styling and stays the no-JS / SEO fallback.
 */

/* ---- Header ---- */
.topics-head { margin: 4px 0 16px; }
.topics-head-row { display: flex; align-items: flex-end; justify-content: space-between; gap: 20px; flex-wrap: wrap; }
.topics-head .eyebrow {
    font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: .14em; color: var(--text-muted);
}
.topics-head h1 {
    font-family: var(--font-serif); font-size: clamp(32px, 4vw, 46px);
    font-weight: 500; margin: 10px 0 10px; color: var(--text-primary); line-height: 1.1;
}
.topics-head p { color: var(--text-secondary); font-size: 16px; max-width: 60ch; }
.topics-head .count-note { color: var(--text-muted); }

/* ---- Map | List toggle ---- */
.view-toggle {
    display: inline-flex; border: 1px solid var(--border-2);
    border-radius: var(--radius-pill); overflow: hidden; flex: none;
}
.view-toggle[hidden] { display: none; }
.view-toggle button {
    font-family: var(--font-mono); font-size: 11px; letter-spacing: .06em;
    text-transform: uppercase; color: var(--text-muted); background: transparent;
    border: 0; padding: 8px 16px; cursor: pointer; transition: color .15s var(--ease), background .15s var(--ease);
}
.view-toggle button:hover { color: var(--text-primary); }
.view-toggle button.on { background: var(--accent); color: var(--accent-ink); font-weight: 600; }
.view-toggle button:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

/* ---- Full-bleed map region (progressive enhancement; hidden until JS shows it) ---- */
.topic-map[hidden] { display: none; }
.topic-map {
    position: relative; left: 50%; width: 100vw; margin-left: -50vw; margin-bottom: 10px;
}

/* The bare [hidden] attribute cannot hide .pills on its own: base.css sets
   .pills { display: flex }, which beats the UA [hidden] rule. Force it so the
   Map/List toggle actually swaps the two views. */
#topics-list[hidden] { display: none; }

.tm-viz {
    position: relative; height: 84vh; min-height: 480px;
    border-top: 1px solid var(--border); border-bottom: 1px solid var(--border);
    background: radial-gradient(120% 120% at 50% 0%, var(--bg-2), var(--bg));
    overflow: hidden; cursor: grab; user-select: none;
}
.tm-viz.grabbing { cursor: grabbing; }
.tm-viz canvas { display: block; }
.tm-mode {
    position: absolute; top: 14px; left: 16px; font-family: var(--font-mono);
    font-size: 11px; color: var(--text-secondary); background: rgba(8, 9, 11, .62);
    border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; pointer-events: none;
}
.tm-mode b { color: var(--text-primary); }
.tm-hint {
    position: absolute; bottom: 14px; left: 16px; font-family: var(--font-mono);
    font-size: 11px; color: var(--text-muted); background: rgba(8, 9, 11, .62);
    border: 1px solid var(--border); border-radius: 8px; padding: 5px 10px; pointer-events: none;
}

/* ---- Episode drawer (slides in from the right, over the map) ---- */
.tm-drawer {
    position: absolute; top: 0; right: 0; height: 100%; width: min(440px, 94%);
    background: var(--surface); border-left: 1px solid var(--border-2);
    box-shadow: -24px 0 60px -24px rgba(0, 0, 0, .7);
    transform: translateX(105%); transition: transform .34s var(--ease);
    display: flex; flex-direction: column; padding: 18px; z-index: 6;
}
.tm-drawer.open { transform: translateX(0); }
.tm-drawer-close {
    position: absolute; top: 12px; right: 14px; width: 30px; height: 30px; border-radius: 50%;
    border: 1px solid var(--border-2); background: var(--surface-3); color: var(--text-secondary);
    font-size: 16px; line-height: 1; cursor: pointer; z-index: 7;
}
.tm-drawer-close:hover { color: var(--text-primary); }
.tm-drawer-close:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
#topic-map-panel { display: flex; flex-direction: column; flex: 1; min-height: 0; overflow: hidden; }

/* ---- Floating filter bar (search + compact Clusters popover + density) ---- */
.tm-filter {
    position: absolute; left: 50%; transform: translateX(-50%); bottom: 22px; z-index: 5;
    display: flex; align-items: center; justify-content: center; gap: 14px; flex-wrap: wrap;
    background: rgba(8, 9, 11, .74); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
    border: 1px solid var(--border-2); border-radius: var(--radius-pill); padding: 10px 16px;
    box-shadow: 0 22px 60px -22px rgba(0, 0, 0, .8); max-width: min(94vw, 880px);
}
.tm-filter input[type=search] {
    width: 240px; max-width: 50vw; background: var(--surface-3); border: 1px solid var(--border-2);
    border-radius: var(--radius-pill); color: var(--text-primary); font-family: var(--font-sans);
    font-size: 14px; padding: 9px 14px; outline: none;
}
.tm-filter input[type=search]:focus { border-color: var(--accent-line); }
.tm-density {
    font-family: var(--font-mono); font-size: 10px; text-transform: uppercase; letter-spacing: .1em;
    color: var(--text-muted); display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
}
.tm-density span { color: var(--text-secondary); }
.tm-filter input[type=range] { width: 120px; accent-color: var(--accent); }
.tm-count { display: none; }    /* the mode HUD already states the count */

.tm-btn {
    font-family: var(--font-sans); font-size: 13px; color: var(--text-secondary);
    background: var(--surface-3); border: 1px solid var(--border-2); border-radius: var(--radius-pill);
    padding: 9px 14px; cursor: pointer; white-space: nowrap;
}
.tm-btn:hover { color: var(--text-primary); border-color: var(--accent-line); }
.tm-btn:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }

/* ---- Compact Clusters popover (opens upward, above the floating bar) ---- */
.tm-clusters { position: relative; }
.tm-pop {
    position: absolute; bottom: calc(100% + 10px); left: 50%; transform: translateX(-50%);
    width: 300px; max-width: 86vw; background: var(--surface); border: 1px solid var(--border-2);
    border-radius: 14px; box-shadow: 0 24px 60px -20px rgba(0, 0, 0, .7); padding: 12px; z-index: 30; display: none;
}
.tm-pop.open { display: block; }
.tm-pop-actions { display: flex; gap: 8px; margin-bottom: 10px; }
.tm-pop-actions .tm-btn { flex: 1; text-align: center; padding: 7px 10px; font-size: 12px; }
.tm-pop-title {
    font-family: var(--font-mono); font-size: 9px; text-transform: uppercase;
    letter-spacing: .12em; color: var(--text-muted); margin: 2px 2px 8px;
}
#topic-map-legend { display: flex; flex-direction: column; gap: 3px; max-height: 46vh; overflow: auto; }
#topic-map-legend .cl {
    display: flex; align-items: center; gap: 9px; font-size: 13px; padding: 7px 9px;
    border-radius: 9px; border: 1px solid transparent; background: transparent;
    color: var(--text-secondary); cursor: pointer; text-align: left; width: 100%;
}
#topic-map-legend .cl:hover { background: var(--bg); }
#topic-map-legend .cl .dot { width: 10px; height: 10px; border-radius: 50%; flex: none; }
#topic-map-legend .cl .sz { margin-left: auto; font-family: var(--font-mono); font-size: 10px; color: var(--text-muted); }
#topic-map-legend .cl.off { opacity: .4; }
#topic-map-legend .cl:focus-visible { outline: 2px solid var(--accent); outline-offset: -2px; }

@media (max-width: 760px) {
    .tm-viz { height: 76vh; }
    .tm-filter { gap: 10px; padding: 9px 12px; }
    .tm-filter input[type=search] { width: 150px; }
}

/* ---- Episode drill-down panel (rendered into the drawer by topic-map.js) ---- */
.ep-panel { display: flex; flex-direction: column; height: 100%; min-height: 0; }
.ep-head { padding: 0 2px 14px; border-bottom: 1px solid var(--border); flex: none; }
.ep-kicker {
    font-family: var(--font-mono); font-size: 10px; text-transform: uppercase;
    letter-spacing: .12em; margin-bottom: 6px;
}
.ep-head h3 {
    font-family: var(--font-serif); font-size: 25px; font-weight: 500;
    line-height: 1.1; margin-bottom: 5px; color: var(--text-primary); padding-right: 32px;
}
.ep-sub { font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.ep-sub a { color: var(--c, var(--accent)); }
.ep-rel { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 11px; }
.ep-rel .lbl {
    font-family: var(--font-mono); font-size: 9px; text-transform: uppercase;
    letter-spacing: .1em; color: var(--text-muted); width: 100%; margin-bottom: 1px;
}
.ep-relchip {
    font-size: 12px; padding: 4px 9px; border-radius: var(--radius-pill);
    border: 1px solid var(--border-2); color: var(--text-secondary); cursor: pointer; background: transparent;
}
.ep-relchip:hover { border-color: var(--c, var(--accent)); color: var(--text-primary); }
.ep-tools { display: flex; gap: 10px; align-items: center; padding: 13px 0 10px; flex: none; }
.ep-tools input {
    flex: 1; min-width: 0; background: var(--surface-3); border: 1px solid var(--border-2);
    border-radius: 10px; color: var(--text-primary); font-family: var(--font-sans);
    font-size: 14px; padding: 10px 14px; outline: none;
}
.ep-tools input:focus { border-color: var(--accent-line); }
.ep-sort { display: flex; border: 1px solid var(--border-2); border-radius: 9px; overflow: hidden; flex: none; }
.ep-sort button {
    font-family: var(--font-mono); font-size: 10px; letter-spacing: .04em; text-transform: uppercase;
    color: var(--text-muted); background: transparent; border: 0; padding: 8px 9px; cursor: pointer;
}
.ep-sort button.on { background: var(--surface-3); color: var(--text-primary); }
.ep-list { display: flex; flex-direction: column; gap: 2px; overflow: auto; min-height: 0; flex: 1; }
.ep-row {
    display: flex; gap: 11px; align-items: flex-start; padding: 10px; border-radius: 10px;
    border: 1px solid transparent; transition: background .12s, border-color .12s; color: inherit;
}
.ep-row:hover { background: var(--bg); border-color: var(--border); }
.ep-thumb {
    position: relative; width: 96px; flex: none; aspect-ratio: 16/9; border-radius: 7px;
    overflow: hidden; border: 1px solid var(--border-2); background: var(--bg-2);
}
.ep-thumb-fallback {
    position: absolute; inset: 0; display: flex; align-items: flex-end; padding: 5px 7px;
    font-family: var(--font-serif); font-weight: 600; font-size: 14px; color: #fff;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .65);
    background: radial-gradient(130% 130% at 22% 18%, var(--c, var(--accent)), transparent 60%), var(--bg-2);
}
.ep-thumb-img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.ep-rbody { min-width: 0; flex: 1; }
.ep-rtitle { font-size: 14px; color: var(--text-primary); line-height: 1.32; margin-bottom: 5px; }
.ep-rmeta { display: flex; flex-wrap: wrap; gap: 9px; font-family: var(--font-mono); font-size: 11px; color: var(--text-muted); }
.ep-rmeta .g { color: var(--text-secondary); }
.ep-rmeta .nov { color: var(--c, var(--accent)); }
.ep-empty, .ep-loading, .ep-error {
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    height: 100%; color: var(--text-muted); font-family: var(--font-mono); font-size: 13px;
    text-align: center; padding: 30px; gap: 10px;
}
.ep-empty .big, .ep-error .big { font-family: var(--font-serif); font-size: 20px; color: var(--text-secondary); }
.ep-error a { color: var(--accent); }

@media (prefers-reduced-motion: reduce) {
    .tm-drawer { transition: none; }
    .ep-row { transition: none; }
    .view-toggle button { transition: none; }
}
