/* Library (notes list + preview pane), the map, topics and settings. */

/* --- Library ----------------------------------------------------------------- */
.filters { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-bottom: 1rem; }
.filters input[type=search] { flex: 1 1 18rem; min-width: 0; }

.library-layout { display: grid; grid-template-columns: minmax(0, 1fr) minmax(20rem, 30rem); gap: 1.25rem; align-items: start; }
.preview-pane { position: sticky; top: 1rem; max-height: calc(100vh - 2rem); overflow: auto; padding: 1.25rem 1.4rem;
  border-radius: var(--r-xl); background: var(--card); border: 1px solid var(--line); box-shadow: var(--shadow-1); }
.pane-empty { display: grid; justify-items: center; gap: 0.4rem; padding: 3rem 1rem; color: var(--faint); text-align: center; }
.pane-empty .icon { width: 2rem; height: 2rem; stroke-width: 1.4; }
.pane-body { font-size: 1.12rem; }
.pane-head { display: flex; align-items: center; justify-content: space-between; gap: 0.5rem; margin-bottom: 1rem;
  font-family: var(--font-ui); font-size: var(--text-sm); }
@media (max-width: 1100px) { .library-layout { grid-template-columns: minmax(0, 1fr); } .preview-pane { display: none; } }

.note-rows { container-type: inline-size; min-width: 0; }
.note-list { border-radius: var(--r-lg); background: var(--card); border: 1px solid var(--line); overflow: visible; }
.note-head, .note-row { display: grid; align-items: center; gap: 0.75rem;
  grid-template-columns: 1.5rem 1.4rem minmax(0, 1fr) 9.5rem 8.5rem 7.5rem; padding: 0.55rem 0.9rem; }
.note-head { padding-block: 0.6rem; border-bottom: 1px solid var(--line); color: var(--faint);
  font: 600 0.68rem/1.2 var(--font-ui); letter-spacing: 0.06em; text-transform: uppercase; }
.note-row { position: relative; cursor: pointer; border-top: 1px solid var(--line); transition: background var(--dur-1); }
.note-head + .note-row { border-top: 0; }
.note-row:hover, .note-row:focus-within { background: var(--hover); }
.note-row:has(input[name=ids]:checked) { background: var(--accent-soft); }
.note-row:last-child { border-radius: 0 0 var(--r-lg) var(--r-lg); }
.pick { display: grid; place-items: center; cursor: default; }
.type-ic { display: grid; place-items: center; color: var(--faint); }
.type-ic .icon { width: 1rem; height: 1rem; }
.note-cell { min-width: 0; }
.note-title { display: block; color: var(--fg); text-decoration: none; font-size: 1.02rem; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.note-title:hover { color: var(--accent-text); }
.note-title p { display: inline; margin: 0; text-wrap: nowrap; }
.note-title img { max-height: 1.6rem; vertical-align: middle; }
.note-title .katex-display { display: inline; margin: 0; }
.col-topic { min-width: 0; }
.col-mem { display: flex; align-items: center; gap: 0.45rem; font-size: var(--text-xs); color: var(--muted); white-space: nowrap; }
.col-due { font-size: var(--text-xs); color: var(--muted); white-space: nowrap; font-variant-numeric: tabular-nums; }

@container (max-width: 760px) {
  .note-head, .note-row { grid-template-columns: 1.5rem 1.4rem minmax(0, 1fr) auto 6.5rem; }
  .note-head .col-topic, .note-row .col-topic { display: none; }
  .mem-word { display: none; }
}
@container (max-width: 480px) {
  .note-head { display: none; }
  .note-head, .note-row { grid-template-columns: 1.5rem minmax(0, 1fr) auto; gap: 0.55rem; padding-inline: 0.65rem; }
  .note-row .type-ic, .note-row .col-due { display: none; }
  .note-row { border-top: 1px solid var(--line); }
  .note-row:first-of-type { border-top: 0; }
}

/* Hover preview: a popover on narrower screens, unfolding in place in the
   narrow list on the Add page; the Library on wide screens uses the pane. */
.preview { display: none; position: absolute; left: 3.4rem; top: calc(100% - 0.3rem); z-index: 10; width: min(40rem, 80vw);
  max-height: 60vh; overflow: auto; padding: 1rem 1.2rem; cursor: default; border-radius: var(--r-lg);
  background: var(--raised); border: 1px solid var(--line-strong); box-shadow: var(--shadow-3); font-size: 1.05rem; }
.note-row:hover .preview:not(:empty), .note-row:focus-within .preview:not(:empty) { display: block; animation: pop-in var(--dur-2) var(--ease-out); }
@media (min-width: 1101px) { .library .note-row .preview { display: none !important; } }
.note-rows.compact .preview { position: static; width: auto; max-height: none; margin-top: 0.5rem; padding: 0.7rem 0.85rem;
  box-shadow: none; background: var(--sunken); font-size: 0.95rem; }
.pv p { margin: 0 0 0.5em; }
.pv .pv-split { border: 0; border-top: 1px dashed var(--line-strong); margin: 0.8rem 0; }

/* Ticked rows: the bar floats at the bottom, so ticking never shifts the list. */
.bulk { counter-reset: ticked; }
.bulk input[name=ids]:checked { counter-increment: ticked; }
.bulk-bar { display: none; position: fixed; bottom: 1.25rem; left: 50%; z-index: 30; translate: -50% 0;
  flex-wrap: wrap; align-items: center; gap: 0.5rem 0.9rem; max-width: calc(100vw - 2rem); padding: 0.5rem 0.6rem 0.5rem 1rem;
  border-radius: var(--r-pill); background: var(--glass); backdrop-filter: blur(16px) saturate(1.4);
  -webkit-backdrop-filter: blur(16px) saturate(1.4); border: 1px solid var(--line-strong); box-shadow: var(--shadow-3);
  font-size: var(--text-sm);
  transition: opacity var(--dur-2) var(--ease-out), transform var(--dur-3) var(--spring-bouncy), display var(--dur-3) allow-discrete; }
.bulk:has(input[name=ids]:checked) .bulk-bar { display: flex; }
@starting-style { .bulk:has(input[name=ids]:checked) .bulk-bar { opacity: 0; transform: translateY(24px) scale(0.95); } }
.bulk-count::before { content: counter(ticked) " " attr(data-ticked); font-weight: 600; }
.bulk-action { display: inline-flex; gap: 0.3rem; align-items: center; }
.bulk-bar select { min-height: 1.85rem; font-size: var(--text-xs); padding-block: 0.15rem; border-radius: var(--r-sm); }
.bulk-message { margin-bottom: 0.75rem; }

/* --- Map --------------------------------------------------------------------- */
.map-page { position: relative; height: 100vh; overflow: hidden;
  background: radial-gradient(ellipse at 50% 45%, color-mix(in oklch, var(--accent) 5%, var(--bg)), var(--bg) 70%); }
.map-canvas { position: absolute; inset: 0; }
.map-canvas .empty { position: absolute; inset: 0; align-content: center; }
.glass { background: var(--glass); backdrop-filter: blur(16px) saturate(1.4); -webkit-backdrop-filter: blur(16px) saturate(1.4);
  border: 1px solid var(--line-strong); border-radius: var(--r-lg); box-shadow: var(--shadow-2); }
.map-top { position: absolute; top: 1rem; left: 1rem; max-width: 22rem; padding: 0.8rem 1rem; animation: rise-in var(--dur-3) var(--ease-out); }
.map-top h1 { font-size: var(--text-lg); }
.map-top p { margin: 0.3rem 0 0; font-size: var(--text-xs); color: var(--muted); }
.map-review { position: absolute; top: 1rem; left: 50%; translate: -50% 0; z-index: 3; box-shadow: var(--shadow-3);
  animation: pop-in var(--dur-3) var(--spring-bouncy); }
.map-review .icon { fill: currentColor; stroke-width: 0; }
.map-panel { position: absolute; top: 1rem; right: 1rem; bottom: 1rem; width: min(24rem, calc(100vw - 2rem)); height: fit-content;
  max-height: calc(100% - 2rem); overflow: auto; padding: 1.1rem 1.2rem; font-size: var(--text-sm);
  animation: slide-in var(--dur-3) var(--spring); }
@keyframes slide-in { from { opacity: 0; transform: translateX(16px); } }
.panel-head { display: flex; align-items: center; gap: 0.6rem; margin-bottom: 0.7rem; }
.panel-head .topic-dot { width: 0.75rem; height: 0.75rem; }
.panel-stats { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin-bottom: 1rem; color: var(--muted); }
.panel-stats b { color: var(--fg); font-variant-numeric: tabular-nums; }
.panel-actions { display: flex; flex-wrap: wrap; gap: 0.45rem; }
.pick-topic.on { border-color: var(--accent); color: var(--accent-text); background: var(--accent-soft); }
.panel-hint { margin: 0.9rem 0 0; font-size: var(--text-xs); }
.panel-mem { display: flex; align-items: center; gap: 0.45rem; color: var(--muted); font-size: var(--text-xs); }
.panel-preview { font-size: 1.02rem; }
.map-legend { position: absolute; left: 1rem; bottom: 1rem; width: 15rem; padding: 0.55rem 0.8rem 0.7rem; font-size: var(--text-xs); color: var(--muted); }
.legend-toggle { display: flex; align-items: center; justify-content: space-between; width: 100%; padding: 0.15rem 0; border: 0;
  background: none; color: var(--fg-soft); font-weight: 600; font-size: var(--text-xs); cursor: pointer; }
.legend-toggle .icon { width: 0.9rem; height: 0.9rem; transition: transform var(--dur-2) var(--ease-out); }
.map-legend.folded .legend-toggle .icon { transform: rotate(180deg); }
.map-legend.folded .legend-body { display: none; }
.legend-ramp { margin: 0.5rem 0; }
.legend-ramp .ramp { display: block; height: 7px; border-radius: var(--r-pill); }
.legend-ramp .ends { display: flex; justify-content: space-between; margin-top: 0.25rem; color: var(--faint); font-size: 0.66rem; }
.map-legend ul { list-style: none; margin: 0; padding: 0; display: grid; gap: 0.3rem; }
.map-legend li { display: flex; align-items: center; gap: 0.5rem; }
.ring { display: inline-block; width: 0.7rem; height: 0.7rem; border-radius: 50%; }
.ring.due { box-shadow: inset 0 0 0 1.5px var(--accent); }
.ring.picked { box-shadow: inset 0 0 0 2.5px var(--accent); background: var(--faint); }
.map-controls { position: absolute; right: 1rem; bottom: 1rem; display: flex; flex-direction: column; padding: 3px; }
.map-controls button { display: grid; place-items: center; width: 2.1rem; height: 2.1rem; border: 0; border-radius: var(--r-sm);
  background: none; color: var(--fg-soft); cursor: pointer; }
.map-controls button:hover { background: var(--hover); color: var(--fg); }
@media (max-width: 760px) {
  .map-top { top: 3.6rem; }
  .map-panel { top: auto; bottom: 4.5rem; max-height: 50%; }
  .map-review { top: auto; bottom: 1rem; }
  .map-legend { display: none; }
}

/* --- Topics ------------------------------------------------------------------ */
.new-topic { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; margin-bottom: 1.25rem; padding: 0.7rem 0.8rem; }
.new-topic input[name=name] { flex: 1 1 12rem; }
.new-icon { display: grid; place-items: center; width: 2.1rem; height: 2.1rem; border-radius: var(--r); background: var(--accent-soft);
  color: var(--accent-text); }
.inline-label { display: flex; gap: 0.45rem; align-items: center; color: var(--muted); font-size: var(--text-sm); }
.topic-list { border-radius: var(--r-lg); background: var(--card); border: 1px solid var(--line); }
.topic-head, .topic-row { display: grid; grid-template-columns: minmax(0, 1fr) 5rem 6rem 5rem 12rem; align-items: center;
  gap: 0.5rem; padding: 0.45rem 0.9rem; }
.topic-head { color: var(--faint); font: 600 0.68rem/1.2 var(--font-ui); letter-spacing: 0.06em; text-transform: uppercase;
  border-bottom: 1px solid var(--line); padding-block: 0.65rem; }
.topic-row { border-top: 1px solid var(--line); transition: background var(--dur-1); }
.topic-head + .topic-row { border-top: 0; }
.topic-row:hover, .topic-row:focus-within { background: var(--hover); }
.topic-row .num, .topic-head .num { text-align: right; font-variant-numeric: tabular-nums; color: var(--muted); font-size: var(--text-sm); }
.topic-row .num.due { color: var(--accent-text); font-weight: 600; }
.topic-edit { padding-left: calc(var(--depth, 0) * 1.4rem); min-width: 0; }
.topic-edit summary { display: flex; align-items: center; gap: 0.55rem; cursor: pointer; list-style: none; min-height: 1.9rem; }
.topic-edit summary::-webkit-details-marker { display: none; }
.topic-name { font-weight: 550; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.edit-hint { display: inline-flex; align-items: center; gap: 0.25rem; font-size: var(--text-xs); color: var(--faint); opacity: 0;
  transition: opacity var(--dur-2); }
.edit-hint .icon { width: 0.8rem; height: 0.8rem; }
.topic-edit summary:hover .edit-hint, .topic-edit[open] .edit-hint { opacity: 1; }
.topic-edit form { display: flex; flex-wrap: wrap; gap: 0.5rem; align-items: center; margin: 0.4rem 0 0.6rem;
  animation: rise-in var(--dur-2) var(--ease-out); }
.topic-edit label { display: flex; gap: 0.4rem; align-items: center; color: var(--muted); font-size: var(--text-sm); }
.topic-actions { display: flex; justify-content: flex-end; gap: 1px; opacity: 0.35; transition: opacity var(--dur-2); }
.topic-row:hover .topic-actions, .topic-row:focus-within .topic-actions { opacity: 1; }
.topic-actions .icon { width: 0.95rem; height: 0.95rem; }
@media (max-width: 700px) {
  .topic-head, .topic-row { grid-template-columns: minmax(0, 1fr) 3.5rem 3.5rem; }
  .topic-head span:nth-child(4), .topic-head span:nth-child(5), .topic-row > .num:nth-of-type(3) { display: none; }
  .topic-actions { grid-column: 1 / -1; justify-content: flex-start; opacity: 1; }
}

/* --- Settings ------------------------------------------------------------------ */
.settings { display: grid; gap: 0.9rem; }
.setting { display: grid; gap: 0.45rem; justify-items: start; }
.setting > label, .setting-label { font: 560 var(--text-md)/1.3 var(--font-read); }
.setting .muted, .choice .muted { margin: 0; font-size: var(--text-sm); }
.setting input[type=number] { width: 7rem; }
.range-row { display: flex; align-items: center; gap: 0.8rem; width: 100%; max-width: 30rem; }
.range-row input[type=range] { flex: 1; }
.range-row input[type=number] { width: 5.5rem; }
.readout { margin: 0; color: var(--fg-soft); }
.readout b { color: var(--accent-text); font-variant-numeric: tabular-nums; }
.choice { display: grid; gap: 0.5rem; margin: 0; border: 1px solid var(--line); }
.choice legend { float: left; width: 100%; margin-bottom: 0.4rem; padding: 0; font: 560 var(--text-md)/1.3 var(--font-read); }
.option { display: flex; flex-wrap: wrap; align-items: center; gap: 0.5rem; padding: 0.45rem 0.6rem; border-radius: var(--r);
  transition: background var(--dur-1); }
.option:hover { background: var(--hover); }
.option:has(input[type=radio]:checked) { background: var(--accent-soft); }
.option input[type=number] { width: 6rem; min-height: 2rem; }
.own-block { margin-top: 2rem; }
.own-block h2 { margin-bottom: 0.6rem; }
.own-settings { margin: 0; padding-left: 1.2rem; color: var(--fg-soft); }
.own-settings li { margin-bottom: 0.3rem; }
