/* Soft paper markers: color is always paired with a readable category name. */
.bookmark-sage{--marker:#dce5d4;--marker-ink:#526348}
.bookmark-peach{--marker:#f1ddd0;--marker-ink:#865c43}
.bookmark-lavender{--marker:#e4dfee;--marker-ink:#6c5c83}
.bookmark-blue{--marker:#dbe7ec;--marker-ink:#4c6878}
.bookmark-sand{--marker:#efe6c9;--marker-ink:#7b6d40}
.bookmark-title-row{display:flex;align-items:flex-start;gap:20px}
.bookmark-title-row h1{flex:1;min-width:0}
.bookmark-trigger{flex:none;display:flex;flex-direction:column;align-items:center;gap:6px;margin-top:12px;padding:10px;border:0;background:transparent;color:var(--muted,#85877e);border-radius:12px;cursor:pointer}
.bookmark-trigger:hover,.bookmark-trigger.is-marked{background:#eeeee7;color:#6b7357}
.bookmark-trigger.is-marked svg{fill:#dce5d4}
#bookmark-dots{display:flex;gap:3px;max-width:40px;flex-wrap:wrap;justify-content:center}
.bookmark-dot{display:inline-block;flex:none;width:10px;height:16px;background:var(--marker);border-radius:2px 2px 0 0;clip-path:polygon(0 0,100% 0,100% 100%,50% 77%,0 100%)}
#bookmark-dots .bookmark-dot{width:6px;height:9px}
.bookmark-filters{display:flex;gap:7px;flex-wrap:wrap;align-items:center;margin:12px 0 22px}
.bookmark-filter,.bookmark-settings{display:inline-flex;align-items:center;gap:7px;padding:7px 11px;border:1px solid transparent;border-radius:10px;background:transparent;color:#777b70;font:inherit;font-size:.82rem;cursor:pointer}
.bookmark-filter:hover{background:#efefe9}
.bookmark-filter[aria-pressed=true]{background:#eeeee6;border-color:#d8dccd;color:#444c3b}
.bookmark-settings{font-size:.75rem;text-decoration:underline;text-underline-offset:4px}
#bookmark-dialog{width:min(440px,calc(100vw - 32px));box-sizing:border-box}
.bookmark-hint{font-size:.86rem;color:#7b7f74;line-height:1.6}
.bookmark-options{display:grid;gap:9px;margin:22px 0}
.bookmark-option{display:flex;align-items:center;gap:12px;padding:13px 16px;text-align:left;background:color-mix(in srgb,var(--marker) 38%,#faf9f6);border:1px solid transparent;border-radius:12px;color:#41463c;font:inherit;cursor:pointer}
.bookmark-option[aria-pressed=true]{background:var(--marker);border-color:var(--marker-ink)}
.bookmark-option:disabled{opacity:.65;cursor:wait}
.bookmark-check{margin-left:auto;color:var(--marker-ink)}
.bookmark-manage{border-top:1px solid #e2e2d9;margin-top:24px;padding-top:16px}
.bookmark-manage summary{cursor:pointer;color:#767d68;font-size:.85rem}
.bookmark-label-row{display:flex;align-items:center;gap:12px;margin:14px 0}
.bookmark-label-row input{margin:0;min-width:0;width:100%}
#bookmark-feedback{font-size:.85rem;color:#727963;min-height:1.4em}
.bookmark-trigger:focus-visible,.bookmark-filter:focus-visible,.bookmark-option:focus-visible{outline:1px solid var(--accent);outline-offset:2px}
@media(max-width:520px){.bookmark-title-row{gap:8px}.bookmark-trigger{margin-top:2px}.bookmark-filter{padding:7px 8px}.bookmark-filters{gap:4px}}

/* Contents: separate view selection, markers and library actions. */
#contents .contents-heading{align-items:flex-start;gap:18px;margin-bottom:28px}
#contents .contents-heading h1{margin-bottom:0}
.contents-actions{display:flex;flex-direction:column;align-items:flex-end;gap:9px;flex-shrink:0;padding-top:7px}
.contents-actions #entry-count{font-size:11px;color:var(--muted);white-space:nowrap}
#contents .contents-actions .share-selection-tools{margin:0;justify-content:flex-end;gap:6px}
#contents .contents-actions .share-selection-tools button{font-size:11px;padding:6px 9px;border-radius:8px;background:#eeeee8;color:#72796a}
#contents .contents-actions .share-selection-tools button[aria-pressed=true]{background:#e3e7da;color:#4f5944}
#contents .search-line{margin-bottom:0}
#contents .bookmark-filters{display:grid;grid-template-columns:1fr auto;gap:12px 10px;margin:16px 0 0;padding-bottom:18px;border-bottom:1px solid var(--line)}
.bookmark-scope{grid-column:1;display:flex;gap:3px;align-items:center}
.bookmark-categories{grid-column:1 / -1;grid-row:2;display:flex;flex-wrap:wrap;gap:5px 10px;align-items:center}
#contents .bookmark-filter{font-size:12px;line-height:1.4;padding:7px 9px;gap:7px;border-radius:8px}
#contents .bookmark-scope .bookmark-filter{font-size:12px;padding:7px 12px}
#contents .bookmark-categories .bookmark-filter{border-color:transparent}
#contents .bookmark-categories .bookmark-filter[aria-pressed=true]{background:#eceee4;border-color:#d8ddce}
#contents .bookmark-dot{width:8px;height:13px}
#contents .bookmark-settings{grid-row:1;grid-column:2;justify-content:center;width:32px;height:32px;padding:0;font-size:12px;text-decoration:none;background:transparent;border-radius:8px}
#contents .bookmark-settings:hover{background:#eeeee8;color:#505a42}
#contents .bookmark-settings:focus-visible{outline:1px solid var(--accent);outline-offset:2px}
#contents .contents-context:empty{margin:12px 0 0}
#contents .chapter > summary{padding:18px 0;gap:12px}
#contents .chapter-name{font-size:17px;letter-spacing:-.25px;line-height:1.45}
#contents .chapter-chevron{font-size:19px}
#contents .chapter-entries > .chapter .chapter-name{font-size:15px}
#contents .chapter-entries > .chapter > summary{padding:13px 0}
@media(max-width:520px){
  #contents .contents-heading{flex-wrap:wrap;gap:12px;margin-bottom:22px}
  .contents-actions{width:100%;flex-direction:row;align-items:center;justify-content:space-between;padding-top:0}
  #contents .bookmark-categories{gap:4px 5px}
  #contents .bookmark-filter{font-size:11px;padding:7px}
  #contents .chapter-name{font-size:16px}
}

/* Management has no empty marker chooser or collapsible intermediate step. */
#bookmark-dialog.is-managing #bookmark-options,
#bookmark-dialog.is-managing .bookmark-hint,
#bookmark-dialog.is-managing .bookmark-manage > summary{display:none}
#bookmark-dialog.is-managing .bookmark-manage{margin-top:20px;padding-top:0;border:0}
#bookmark-dialog.is-managing h2{font-size:25px;line-height:1.2}
#bookmark-dialog.is-managing #bookmark-entry-name{font-size:13px;line-height:1.6;margin-bottom:0}
#bookmark-feedback:empty{display:none}
#bookmark-feedback{margin:14px 0 0;min-height:0}
.bookmark-form-actions{display:flex;justify-content:flex-end;margin-top:20px}
#bookmark-dialog .bookmark-save{border:0;border-radius:11px;padding:11px 16px;background:#686f52;color:#fff;font:inherit;font-size:13px;cursor:pointer}
#bookmark-dialog .bookmark-save:hover{background:#596145}
#bookmark-dialog .bookmark-save:disabled{opacity:.55;cursor:wait}
#bookmark-dialog .bookmark-save:focus-visible{outline:1px solid var(--accent);outline-offset:2px}

#contents .contents-heading{display:grid;grid-template-columns:minmax(0,1fr) auto;align-items:center;gap:8px 18px}
#contents .contents-actions{grid-column:2;grid-row:1;padding:0;width:auto;align-self:center}
#contents .contents-heading #entry-count{grid-column:1 / -1;grid-row:2;margin:0;font-size:11px;color:var(--muted);white-space:nowrap}
#contents .contents-actions .share-selection-tools{max-width:220px}
@media(max-width:520px){#contents .contents-heading{gap:8px 10px}#contents .contents-heading h1{font-size:25px}#contents .contents-actions .share-selection-tools{max-width:110px}}

/* Index controls form three distinct groups: heading, search, marker filters. */
#contents { padding-top:22px; padding-bottom:48px; }
#contents .contents-heading { margin-bottom:20px; }
#contents .contents-heading h1 { margin:0; }
#contents .search-line { border:1px solid var(--line); border-radius:12px; padding:9px 13px; background:#ffffff40; }
#contents .search-line:focus-within { border-color:var(--accent); }
#contents .bookmark-filters { margin-top:16px; row-gap:14px; padding-bottom:20px; }
#contents .bookmark-scope { width:fit-content; padding:3px; background:#686f520a; border-radius:11px; gap:2px; }
#contents .bookmark-scope .bookmark-filter { min-height:36px; padding:7px 12px; border:0; background:transparent; }
#contents .bookmark-scope .bookmark-filter[aria-pressed=true] { background:var(--paper); box-shadow:0 1px 3px #30332f12; }
#contents .bookmark-settings { align-self:center; width:38px; height:38px; border:1px solid var(--line); border-radius:11px; }
#contents .bookmark-categories { gap:6px 10px; }
#contents .bookmark-categories .bookmark-filter { min-height:36px; }
.book-nav[hidden] { display:none; }
.book { padding-bottom:32px; }
@media(max-width:600px) {
  .book-nav { margin-top:14px; }
  #contents { padding-top:14px; }
  #contents .contents-heading { margin-bottom:16px; }
  #contents .contents-heading h1 { font-size:clamp(22px,6vw,28px); letter-spacing:-.7px; }
  #contents .bookmark-filters { margin-top:12px; row-gap:12px; }
  #contents .bookmark-categories { gap:4px 8px; }
  #contents .bookmark-categories .bookmark-filter { padding:8px 6px; }
  #contents .search-line input { font-size:16px; }
}

#contents { padding-top:28px; }
#contents .contents-actions { display:flex; flex-direction:row; align-items:center; gap:8px; }
#contents .index-random { display:grid; place-items:center; width:40px; height:40px; flex-shrink:0; color:var(--muted); border:1px solid var(--line); border-radius:11px; }
#contents .index-random:hover { background:#686f5210; color:var(--ink); }
#contents .index-random svg { width:20px; height:20px; }
#contents .bookmark-categories .bookmark-filter { border:1px solid var(--line); border-radius:20px; padding:8px 12px; background:transparent; }
#contents .bookmark-categories .bookmark-filter[aria-pressed=true] { border-color:var(--marker-ink,var(--accent)); background:var(--marker,#eceee4); color:var(--ink); }
@media(max-width:600px) {
  #contents { padding-top:24px; }
  #contents .contents-heading { grid-template-columns:1fr auto; }
  #contents .contents-heading h1 { grid-column:1 / -1; font-size:26px; }
  #contents .contents-heading #entry-count { grid-column:1; grid-row:2; }
  #contents .contents-actions { grid-column:2; grid-row:2; }
  #contents .bookmark-categories { gap:8px; }
  #contents .bookmark-categories .bookmark-filter { font-size:12px; padding:8px 10px; }
}

#contents .index-random,
#contents .contents-actions .share-selection-tools button { min-height:28px; height:28px; border:0; border-radius:8px; background:#eeeee8; color:#72796a; }
#contents .index-random { width:28px; }
#contents .index-random svg { width:16px; height:16px; stroke-width:1.4; }
#contents .contents-actions .share-selection-tools button { padding:4px 9px; }

/* Category names and colors are independent; the list can grow or be empty. */
#bookmark-dialog { max-height:calc(100dvh - 32px); overflow-y:auto; }
.bookmark-label-row { display:grid; grid-template-columns:minmax(0,1fr) 36px; gap:10px; margin:12px 0; }
.bookmark-label-row label { display:flex; align-items:center; gap:12px; margin:0; min-width:0; }
.bookmark-label-row input { margin:0; }
.bookmark-delete { display:grid; place-items:center; width:36px; height:36px; padding:0; color:var(--muted); border-radius:9px; }
.bookmark-delete:hover { color:var(--ink); background:#686f5210; }
.bookmark-delete-confirm { grid-column:1 / -1; padding:12px; border:1px solid var(--line); border-radius:12px; font-size:12px; }
.bookmark-delete-confirm p { margin:0 0 8px; line-height:1.5; }
.bookmark-delete-confirm button { padding:8px 12px; border-radius:8px; margin-right:8px; background:#686f5210; }
.bookmark-delete-confirm button:last-child { color:#855d4b; }
.bookmark-create { margin-top:24px; padding-top:20px; border-top:1px solid var(--line); }
.bookmark-create h3 { margin:0 0 14px; font-size:14px; font-weight:500; }
.bookmark-create > label { margin:0 0 8px; }
.bookmark-create > input { margin:0 0 16px; }
.bookmark-palette { display:flex; gap:10px; border:0; margin:0; padding:0; }
.bookmark-palette legend { font-size:12px; margin-bottom:8px; color:var(--muted); }
.bookmark-palette .bookmark-swatch { position:relative; display:grid; place-items:center; width:36px; height:36px; margin:0; cursor:pointer; }
.bookmark-swatch input { position:absolute; opacity:0; width:100%; height:100%; margin:0; }
.bookmark-swatch > span:first-of-type { display:block; width:28px; height:28px; border:3px solid var(--paper); outline:1px solid transparent; border-radius:50%; background:var(--marker); }
.bookmark-swatch input:checked + span { outline-color:var(--marker-ink); }
.bookmark-swatch input:focus-visible + span { outline:2px solid var(--accent); outline-offset:2px; }
#contents .bookmark-categories[hidden], .bookmark-delete-confirm[hidden], .bookmark-form-actions[hidden] { display:none; }
@media(max-width:600px) { #bookmark-dialog input:not([type=radio]) { font-size:16px; } }

/* Reading order stays separate from bookmark filters. */
.contents-views { display:flex; gap:22px; align-items:center; margin:8px 0 0; border-bottom:1px solid var(--line); }
.contents-views button { min-height:44px; padding:10px 0; border-bottom:2px solid transparent; font-size:13px; color:var(--muted); }
.contents-views button[aria-pressed=true] { border-bottom-color:var(--accent); color:var(--ink); }
.contents-views button:hover { color:var(--ink); }
#contents .contents-views[hidden] { display:none; }
#contents .contents-context:empty { margin:0; }
#contents .bookmark-filters { border-bottom:0; padding-bottom:4px; }

/* The list follows the search directly; secondary controls open on demand. */
#contents .contents-heading { margin-bottom:16px; }
#contents .contents-toolbar { display:flex; align-items:center; justify-content:space-between; gap:12px; margin:10px 0 0; border-bottom:1px solid var(--line); }
#contents .contents-views { border:0; margin:0; gap:20px; }
.contents-menu { position:relative; flex:none; }
.contents-menu > summary { display:flex; align-items:center; justify-content:center; gap:7px; min-height:44px; list-style:none; cursor:pointer; color:var(--muted); font-size:12px; border-radius:8px; }
.contents-menu > summary::-webkit-details-marker { display:none; }
.contents-menu > summary:hover,.contents-menu[open] > summary { color:var(--ink); }
#contents-menu > summary { width:36px; min-height:36px; }
.contents-menu-panel { position:absolute; right:0; top:calc(100% + 6px); z-index:20; border:1px solid var(--line); background:var(--paper); border-radius:13px; box-shadow:0 8px 30px #30332f14; padding:8px; }
.contents-menu:not([open]) > .contents-menu-panel { display:none !important; }
#contents-menu .contents-menu-panel { min-width:210px; }
#contents-menu .contents-menu-panel button { display:flex; align-items:center; gap:10px; width:100%; height:auto; min-height:44px; padding:10px 12px; background:transparent; border:0; border-radius:8px; color:var(--ink); font-size:13px; text-align:left; }
#contents-menu .contents-menu-panel button:hover { background:#686f520c; }
#contents-menu #random svg { flex:none; }
#contents-menu #share-select-toggle { padding-left:38px; }
#bookmark-filter-menu { margin-left:auto; }
#bookmark-filter-toggle { max-width:180px; padding:0 4px; }
#bookmark-filter-toggle svg { flex:none; }
#bookmark-filter-label { overflow:hidden; text-overflow:ellipsis; white-space:nowrap; }
#bookmark-filter-toggle.is-filtered { color:var(--accent); }
#bookmark-filter-toggle.is-filtered svg { fill:#dce5d4; }
#contents #bookmark-filters { width:min(310px,calc(100vw - 48px)); margin:0; padding:12px; border:1px solid var(--line); gap:12px; box-sizing:border-box; }
#contents #bookmark-filters .bookmark-scope { padding:0; background:transparent; }
#contents #bookmark-filters .bookmark-scope button { padding:7px 9px; }
#contents #bookmark-filters .bookmark-settings { width:34px; height:34px; border:0; }
#contents #bookmark-filters .bookmark-categories { gap:7px; }
#contents #bookmark-filters .bookmark-categories button { min-height:36px; padding:8px 10px; }
.share-selection-bar { display:flex; align-items:center; justify-content:space-between; gap:12px; padding:12px 0; border-bottom:1px solid var(--line); }
.share-selection-bar button { min-height:36px; font-size:12px; color:var(--muted); }
#share-selection-send { padding:8px 12px; border-radius:9px; background:#686f5210; color:var(--ink); }
.share-selection-bar[hidden] { display:none; }
@media(max-width:600px) {
  #contents .contents-heading { grid-template-columns:minmax(0,1fr) auto; gap:6px 12px; }
  #contents .contents-heading h1 { grid-column:1; grid-row:1; font-size:clamp(22px,6.6vw,26px); }
  #contents .contents-actions { grid-column:2; grid-row:1 / 3; }
  #contents .contents-heading #entry-count { grid-column:1; grid-row:2; }
  #bookmark-filter-toggle { max-width:150px; }
}
