/* os.oscuuro Research extras: attachments, media viewer, YouTube-style player,
   rich-text notes and the full-screen writer. Builds on dashboard.css variables. */

.grow { flex: 1; }
.ico-s { width: 18px; height: 18px; fill: currentColor; flex: none; }
.section-head { display: flex; align-items: center; gap: 10px; min-height: 34px; }
.section-head > h3 { color: var(--muted); font-size: .74rem; letter-spacing: .12em; text-transform: uppercase; font-weight: 600; }
.section-head .btn .ico-s { width: 16px; height: 16px; }
html.viewer-open, html.writer-open { overflow: hidden; }
/* The item pane sizes its content to itself, never the other way round: a wide
   toolbar or long file name must not push it past its column. */
.detail-pane { position: relative; gap: 22px; grid-template-columns: minmax(0, 1fr); min-width: 0; container: pane / inline-size; }
.detail-pane > * { min-width: 0; }
.section-head { flex-wrap: wrap; row-gap: 8px; }
.research-head .head-row .actions { flex-wrap: wrap; }

@container pane (max-width: 620px) {
  .composer-hint, .usage { display: none; }
  .composer-tools { overflow-x: auto; scrollbar-width: none; }
  .composer-tools::-webkit-scrollbar { display: none; }
  .composer-tools .tb { min-width: 30px; padding: 0 5px; }
  .detail-grid { grid-template-columns: minmax(0, 1fr); }
  .att-grid { grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 10px; }
  .article-cover { width: 92px; }
}
@container pane (max-width: 420px) {
  .section-head .btn { padding: .45rem .65rem; }
  .section-head .btn .ico-s { display: none; }
  .composer-tools .btn { padding: .45rem .7rem; }
}
.detail-pane > .section + .section { border-top: 1px solid var(--stroke); padding-top: 20px; }

/* ================================================================ attachments */
.att-empty {
  display: grid; justify-items: center; gap: 6px; padding: 26px 18px; width: 100%;
  border: 1px dashed var(--stroke-2); border-radius: var(--r-md); background: transparent;
  color: var(--text); font: inherit; cursor: pointer; text-align: center;
  transition: border-color .2s ease, background .2s ease, color .2s ease;
}
.att-empty:hover { border-color: rgba(var(--accent-rgb), .5); background: var(--accent-soft); }
.att-empty strong { font-size: .92rem; font-weight: 600; }
.att-empty-ico { width: 30px; height: 30px; fill: var(--accent); opacity: .9; }
.usage { white-space: nowrap; }
.section-head > .dim.small { white-space: nowrap; }
.section-head .btn, .composer-tools .btn { white-space: nowrap; }
@media (max-width: 600px) {
  .usage { display: none; }
  .composer-tools { flex-wrap: nowrap; overflow-x: auto; scrollbar-width: none; }
  .composer-tools .tb { min-width: 30px; padding: 0 5px; }
}

.att-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(132px, 1fr)); gap: 12px; }
.att-grid:empty { display: none; }
.att-tile { position: relative; display: grid; gap: 6px; min-width: 0; animation: fade .3s ease; }
.att-open {
  position: relative; display: block; width: 100%; aspect-ratio: 4 / 3; padding: 0; overflow: hidden;
  border: 1px solid var(--stroke); border-radius: 14px; background: var(--glass-sunk); cursor: pointer; color: inherit;
  transition: border-color .2s ease, transform .2s ease;
}
.att-open:hover { border-color: rgba(var(--accent-rgb), .45); }
.att-open:hover .att-media > img, .att-open:hover .att-media > video { transform: scale(1.04); }
.att-media { position: absolute; inset: 0; display: grid; place-items: center; }
.att-media > img, .att-media > video { width: 100%; height: 100%; object-fit: cover; transition: transform .35s ease; pointer-events: none; }
.att-media.kind-pdf > img { object-fit: cover; object-position: top; background: #fff; }
.att-media.no-thumb { gap: 4px; align-content: center; }
.att-glyph { width: 34px; height: 34px; fill: var(--muted); opacity: .8; }
.att-media.kind-pdf .att-glyph { fill: #ef8a8a; }
.att-media.kind-video .att-glyph { fill: var(--link); }
.att-media.kind-audio .att-glyph { fill: var(--warn); }
.att-ext { font: 700 .68rem var(--mono); letter-spacing: .08em; color: var(--dim); }
.att-play {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: 42px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: rgba(0, 0, 0, .62); color: #fff; backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
}
.att-open:hover .att-play { background: #ff0033; }
.att-badge {
  position: absolute; right: 6px; bottom: 6px; padding: 2px 6px; border-radius: 6px;
  background: rgba(0, 0, 0, .72); color: #fff; font: 600 .7rem var(--font); letter-spacing: .02em;
}
.att-foot { display: grid; padding: 0 2px; min-width: 0; }
.att-name { font-size: .8rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.att-meta { font-size: .72rem; color: var(--dim); }
.att-del {
  position: absolute; top: 6px; right: 6px; width: 26px; height: 26px; padding: 0; display: grid; place-items: center;
  border: 0; border-radius: 50%; background: rgba(0, 0, 0, .65); color: #fff; cursor: pointer;
  opacity: 0; transition: opacity .15s ease, background .15s ease;
}
.att-del .ico-s { width: 15px; height: 15px; }
.att-tile:hover .att-del, .att-del:focus-visible, .att-del.armed, .att-tile.pending .att-del { opacity: 1; }
.att-del.armed { background: var(--bad); color: #1a0808; }
@media (hover: none) { .att-del { opacity: 1; } }
.att-tile.pending .att-open { cursor: default; }
.att-tile.pending .att-media > img { opacity: .45; filter: blur(1px); }
.att-uploading { position: absolute; left: 10px; right: 10px; bottom: 10px; display: grid; gap: 6px; }
.att-pct { font: 600 .74rem var(--font); color: var(--text); text-shadow: 0 1px 4px #000; }
.att-progress { height: 4px; border-radius: 4px; background: rgba(255, 255, 255, .14); overflow: hidden; }
.att-progress > span { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .2s ease; }

.drop-overlay {
  position: absolute; inset: 8px; z-index: 5; display: none; place-content: center; justify-items: center; gap: 10px;
  border: 2px dashed rgba(var(--accent-rgb), .7); border-radius: var(--r-lg);
  background: rgba(0, 0, 0, .72); backdrop-filter: blur(6px); -webkit-backdrop-filter: blur(6px);
  color: var(--accent); pointer-events: none;
}
.drop-region.dragging > .drop-overlay { display: grid; }

/* ================================================================ YouTube dialog + downloads */
.dialog-backdrop { position: fixed; inset: 0; z-index: 85; display: grid; place-items: center; padding: 16px; background: rgba(0, 0, 0, .6); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); animation: vIn .15s ease; }
.mini-dialog { width: min(480px, 100%); padding: 22px; display: grid; gap: 12px; }
.mini-dialog h2 { font-size: 1.1rem; }
.mini-dialog input.inset { width: 100%; padding: .8rem 1rem; color: var(--text); font: .95rem var(--font); outline: 0; }
.mini-dialog .actions { margin-top: 2px; }
.dialog-error { color: var(--bad); }
.dl-tray { position: fixed; left: 18px; bottom: 18px; z-index: 60; width: min(340px, calc(100vw - 36px)); display: grid; gap: 8px; }
.dl-row {
  display: flex; gap: 12px; align-items: center; padding: 12px 12px 12px 14px; border-radius: var(--r-md);
  background: rgba(18, 18, 22, .94); border: 1px solid var(--stroke-2); box-shadow: var(--drop);
  backdrop-filter: var(--blur); -webkit-backdrop-filter: var(--blur); animation: fade .25s ease;
}
.dl-ico { flex: none; width: 34px; height: 24px; border-radius: 7px; display: grid; place-items: center; background: #ff0033; color: #fff; }
.dl-ico .ico-s { width: 14px; height: 14px; }
.dl-text { display: grid; gap: 4px; min-width: 0; flex: 1; }
.dl-name { font-size: .85rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dl-state { font-size: .76rem; color: var(--muted); }
.dl-bar { height: 3px; border-radius: 3px; background: rgba(255, 255, 255, .12); overflow: hidden; }
.dl-bar > span { display: block; height: 100%; width: 0; background: #ff0033; transition: width .4s ease; }
.dl-row.ok .dl-state { color: var(--found); }
.dl-row.ok .dl-bar > span { background: var(--found); width: 100%; }
.dl-row.bad .dl-state { color: var(--bad); }
.dl-row.bad .dl-bar { display: none; }
.dl-x { flex: none; width: 28px; height: 28px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%; background: transparent; color: var(--muted); cursor: pointer; }
.dl-x:hover { background: rgba(255, 255, 255, .08); color: var(--text); }
@media (max-width: 960px) { .dl-tray { left: 12px; bottom: 76px; } }

/* ================================================================ viewer */
.viewer {
  position: fixed; inset: 0; z-index: 80; display: grid; grid-template-rows: auto minmax(0, 1fr) auto;
  background: rgba(3, 3, 5, .94); backdrop-filter: blur(18px); -webkit-backdrop-filter: blur(18px);
  animation: vIn .18s ease;
}
.viewer.closing { animation: vOut .16s ease forwards; }
@keyframes vIn { from { opacity: 0; } to { opacity: 1; } }
@keyframes vOut { to { opacity: 0; } }
.viewer-bar { display: flex; align-items: center; gap: 16px; padding: 12px 16px 12px 22px; min-width: 0; }
.viewer-title { display: grid; min-width: 0; flex: 1; }
.viewer-name { font-size: .95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.viewer-sub { display: flex; flex-wrap: wrap; gap: 2px 10px; font-size: .78rem; color: var(--muted); }
.viewer-count { white-space: nowrap; }
.viewer-count { color: var(--accent); }
.viewer-count:empty { display: none; }
.viewer-tools, .viewer-context { display: flex; align-items: center; gap: 4px; }
.viewer-context:not(:empty) { margin-right: 10px; padding-right: 10px; border-right: 1px solid var(--stroke); }
.vbtn {
  width: 38px; height: 38px; padding: 0; display: grid; place-items: center; border: 0; border-radius: 50%;
  background: transparent; color: var(--text); cursor: pointer; text-decoration: none !important;
  transition: background .15s ease;
}
.vbtn:hover { background: rgba(255, 255, 255, .1); }
.vbtn .ico-s { width: 20px; height: 20px; }
.vbtn.armed { background: var(--bad); color: #1a0808; }
.zoom-pct { min-width: 46px; text-align: center; font: 500 .78rem var(--mono); color: var(--muted); }
.viewer-stage { position: relative; min-height: 0; display: grid; place-items: center; overflow: hidden; padding: 0 72px; }
.viewer-nav {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 3; width: 48px; height: 48px;
  background: rgba(255, 255, 255, .06); border: 1px solid var(--stroke);
}
.viewer-nav.prev { left: 14px; }
.viewer-nav.next { right: 14px; }
.viewer-strip { display: flex; gap: 8px; padding: 12px 16px 16px; overflow-x: auto; justify-content: safe center; scrollbar-width: thin; }
.strip-item { position: relative; flex: none; width: 64px; height: 48px; padding: 0; border: 2px solid transparent; border-radius: 10px; overflow: hidden; background: var(--glass); cursor: pointer; opacity: .55; transition: opacity .15s ease, border-color .15s ease; }
.strip-item:hover { opacity: .9; }
.strip-item[aria-selected="true"] { opacity: 1; border-color: var(--accent); }
.strip-item .att-glyph { width: 22px; height: 22px; }
.strip-item .att-ext { display: none; }

.zoom-wrap { position: absolute; inset: 0 72px 8px; display: grid; place-items: center; overflow: hidden; touch-action: none; cursor: zoom-in; }
.zoom-wrap.zoomed { cursor: grab; }
.zoom-wrap.zoomed:active { cursor: grabbing; }
.viewer-img { max-width: 100%; max-height: 100%; object-fit: contain; user-select: none; transform-origin: center; transition: transform .12s ease-out; border-radius: 4px; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }

.viewer-player { width: min(100%, calc((100vh - 190px) * 16 / 9)); }
.viewer-stage.kind-audio .viewer-player { width: min(100%, 620px); }

.viewer-stage.kind-pdf, .viewer-stage.kind-text { padding: 0; place-items: stretch; }
.pdf-scroll { overflow: auto; height: 100%; padding: 8px 24px 40px; outline: 0; }
.pdf-pages { display: grid; justify-content: center; gap: 18px; }
.pdf-page { position: relative; background: #fff; box-shadow: 0 10px 40px rgba(0, 0, 0, .55); border-radius: 3px; overflow: hidden; --scale-round-x: 1px; --scale-round-y: 1px; }
.pdf-page canvas { display: block; }
.pdf-status { text-align: center; padding: 60px 0; }
.pdf-pager { display: inline-flex; align-items: center; gap: 6px; font-size: .82rem; margin-right: 6px; }
.viewer .pdf-page-input { width: 44px; padding: .3rem .4rem; text-align: center; border-radius: 8px; border: 1px solid var(--stroke); background: var(--glass-sunk); color: var(--text); font: .82rem var(--mono); }
/* PDF.js text layer (selectable, invisible text over the canvas) */
.textLayer { position: absolute; text-align: initial; inset: 0; overflow: clip; opacity: 1; line-height: 1; text-size-adjust: none; -webkit-text-size-adjust: none; forced-color-adjust: none; transform-origin: 0 0; z-index: 0; --min-font-size: 1; --text-scale-factor: calc(var(--total-scale-factor) * var(--min-font-size)); --min-font-size-inv: calc(1 / var(--min-font-size)); }
.textLayer :is(span, br) { color: transparent; position: absolute; white-space: pre; cursor: text; transform-origin: 0% 0%; }
.textLayer > :not(.markedContent), .textLayer .markedContent span:not(.markedContent) { z-index: 1; --font-height: 0; font-size: calc(var(--text-scale-factor) * var(--font-height)); --scale-x: 1; --rotate: 0deg; transform: rotate(var(--rotate)) scaleX(var(--scale-x)) scale(var(--min-font-size-inv)); }
.textLayer .markedContent { display: contents; }
.textLayer ::selection { background: rgba(0, 90, 255, .3); }
.textLayer br::selection { background: transparent; }
.textLayer .endOfContent { display: block; position: absolute; inset: 100% 0 0; z-index: 0; cursor: default; user-select: none; }

.text-view { overflow: auto; height: 100%; padding: 8px 24px 40px; display: grid; gap: 12px; align-content: start; justify-items: center; }
.text-pre { display: flex; margin: 0; width: min(100%, 980px); padding: 18px 0; border-radius: var(--r-md); border: 1px solid var(--stroke); background: var(--glass-sunk); font: .82rem/1.6 var(--mono); color: #cfd2da; overflow: auto; }
.text-gutter { flex: none; padding: 0 14px 0 16px; text-align: right; color: var(--dim); user-select: none; border-right: 1px solid var(--stroke); white-space: pre; }
.text-pre code { padding: 0 18px; white-space: pre; font: inherit; }
.csv-wrap { width: min(100%, 1200px); border: 1px solid var(--stroke); border-radius: var(--r-md); background: var(--glass-sunk); }
.table.csv th { position: sticky; top: 0; background: #121216; padding-top: 10px; }
.viewer-file { display: grid; justify-items: center; gap: 10px; text-align: center; padding: 40px; }
.viewer-file-ico { display: grid; justify-items: center; gap: 4px; padding: 22px 26px; border-radius: 20px; border: 1px solid var(--stroke); background: var(--glass); margin-bottom: 6px; }
.viewer-file .btn { margin-top: 10px; }
.viewer-file .btn .ico-s { width: 18px; height: 18px; }

/* ================================================================ YouTube-style player */
.ytp {
  --red: #ff0033;
  position: relative; width: 100%; aspect-ratio: 16 / 9; background: #000; overflow: hidden;
  border-radius: 12px; outline: none; user-select: none; -webkit-user-select: none; color: #fff;
  font: 400 13px/1 "YouTube Sans", Roboto, var(--font);
  isolation: isolate;
}
.ytp:focus-visible { box-shadow: 0 0 0 2px var(--accent); }
.ytp.ytp-full { border-radius: 0; }
.ytp-video { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: contain; background: #000; }
.ytp-shade { position: absolute; inset: 0; z-index: 1; }
.ytp-shade::after { content: ""; position: absolute; left: 0; right: 0; bottom: 0; height: 140px; background: linear-gradient(transparent, rgba(0, 0, 0, .25) 40%, rgba(0, 0, 0, .78)); pointer-events: none; transition: opacity .25s ease; }
.ytp-top { position: absolute; z-index: 2; left: 0; right: 0; top: 0; padding: 14px 18px 40px; background: linear-gradient(rgba(0, 0, 0, .6), transparent); pointer-events: none; transition: opacity .25s ease; }
.ytp-title { font-size: 15px; font-weight: 500; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; text-shadow: 0 0 2px rgba(0, 0, 0, .5); }
.ytp-fresh .ytp-top { opacity: 1; }
.ytp:not(.ytp-fresh):not(.ytp-full) .ytp-top { opacity: 0; }
.ytp.ytp-full:not(.ytp-idle) .ytp-top { opacity: 1; }

.ytp-chrome { position: absolute; z-index: 3; left: 12px; right: 12px; bottom: 0; transition: opacity .25s ease; }
.ytp-idle { cursor: none; }
.ytp-idle .ytp-chrome, .ytp-idle .ytp-shade::after, .ytp-idle .ytp-top { opacity: 0; pointer-events: none; }
.ytp-fresh:not(.ytp-audio) .ytp-chrome, .ytp-fresh:not(.ytp-audio) .ytp-shade::after { opacity: 0; pointer-events: none; }

/* progress bar */
.ytp-progress { position: relative; height: 16px; display: flex; align-items: center; cursor: pointer; touch-action: none; }
.ytp-rail { position: relative; width: 100%; height: 3px; background: rgba(255, 255, 255, .2); transition: height .1s ease; }
.ytp-progress:hover .ytp-rail, .ytp-dragging .ytp-rail { height: 5px; }
.ytp-buffered, .ytp-hoverbar, .ytp-played { position: absolute; left: 0; top: 0; bottom: 0; width: 0; }
.ytp-buffered { background: rgba(255, 255, 255, .4); }
.ytp-hoverbar { background: rgba(255, 255, 255, .5); }
.ytp-played { background: var(--red); }
.ytp-scrubber {
  position: absolute; top: 50%; left: 0; width: 13px; height: 13px; margin: -6.5px 0 0 -6.5px; border-radius: 50%;
  background: var(--red); transform: scale(0); transition: transform .1s ease;
}
.ytp-progress:hover .ytp-scrubber, .ytp-dragging .ytp-scrubber { transform: scale(1); }
.ytp-preview {
  position: absolute; bottom: 26px; left: 0; transform: translateX(-50%); display: none; justify-items: center; gap: 6px;
  pointer-events: none;
}
.ytp-hovering .ytp-preview { display: grid; }
.ytp-preview-frame { display: none; width: 160px; border-radius: 8px; border: 2px solid #fff; background: #000; }
.ytp-preview.has-frame .ytp-preview-frame { display: block; }
.ytp-preview-time { padding: 3px 7px; border-radius: 4px; background: rgba(0, 0, 0, .7); font-weight: 500; font-size: 12.5px; font-variant-numeric: tabular-nums; }

/* control row */
.ytp-controls { display: flex; align-items: center; justify-content: space-between; height: 48px; }
.ytp-left, .ytp-right { display: flex; align-items: center; height: 100%; }
.ytp-btn {
  width: 44px; height: 44px; padding: 0; display: grid; place-items: center; border: 0; background: transparent;
  color: #fff; cursor: pointer; opacity: .92; border-radius: 50%;
}
.ytp-btn:hover { opacity: 1; }
.ytp-btn:focus-visible { outline: 2px solid #fff; outline-offset: -4px; }
.ytp-svg { width: 26px; height: 26px; fill: currentColor; filter: drop-shadow(0 0 2px rgba(0, 0, 0, .35)); }
.ytp-svg.small { width: 20px; height: 20px; }
.ytp-play .ytp-svg { width: 30px; height: 30px; }
.ytp-gear .ytp-svg { transition: transform .25s ease; }
.ytp-gear.on .ytp-svg { transform: rotate(30deg); }
.ytp-volume-wrap { display: flex; align-items: center; height: 100%; }
.ytp-volume {
  --v: 100%;
  width: 0; height: 100%; margin: 0; opacity: 0; appearance: none; -webkit-appearance: none; background: transparent; cursor: pointer;
  transition: width .2s ease, opacity .2s ease, margin .2s ease;
}
.ytp-volume-wrap:hover .ytp-volume, .ytp-volume:focus-visible { width: 64px; opacity: 1; margin-right: 10px; }
.ytp-volume::-webkit-slider-runnable-track { height: 3px; background: linear-gradient(90deg, #fff var(--v), rgba(255, 255, 255, .25) var(--v)); border-radius: 2px; }
.ytp-volume::-webkit-slider-thumb { -webkit-appearance: none; width: 12px; height: 12px; margin-top: -4.5px; border-radius: 50%; background: #fff; }
.ytp-volume::-moz-range-track { height: 3px; background: rgba(255, 255, 255, .25); border-radius: 2px; }
.ytp-volume::-moz-range-progress { height: 3px; background: #fff; border-radius: 2px; }
.ytp-volume::-moz-range-thumb { width: 12px; height: 12px; border: 0; border-radius: 50%; background: #fff; }
.ytp-time { padding: 0 8px; font-size: 13px; font-variant-numeric: tabular-nums; white-space: nowrap; color: #eee; text-shadow: 0 0 2px rgba(0, 0, 0, .5); }
.ytp-speed-badge { padding: 2px 6px; margin-right: 4px; border-radius: 4px; background: rgba(255, 255, 255, .16); font-size: 11.5px; font-weight: 600; }

/* overlays */
.ytp-big-play {
  position: absolute; z-index: 4; left: 50%; top: 50%; width: 68px; height: 48px; margin: -24px 0 0 -34px; padding: 0;
  display: none; place-items: center; border: 0; border-radius: 14px; cursor: pointer;
  background: rgba(33, 33, 33, .8); color: #fff; transition: background .15s ease;
}
.ytp-big-play .ytp-svg { width: 30px; height: 30px; filter: none; }
.ytp-fresh:not(.ytp-audio) .ytp-big-play, .ytp-ended .ytp-big-play { display: grid; }
.ytp:hover .ytp-big-play, .ytp-big-play:focus-visible { background: var(--red); }
.ytp-bezel {
  position: absolute; z-index: 4; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  display: grid; place-items: center; background: rgba(0, 0, 0, .5); opacity: 0; pointer-events: none;
}
.ytp-bezel .ytp-svg { width: 30px; height: 30px; }
.ytp-bezel.show { animation: bezel .5s linear; }
@keyframes bezel { 0% { opacity: 1; transform: scale(1); } 100% { opacity: 0; transform: scale(2); } }
.ytp-seek-hint {
  position: absolute; z-index: 2; top: 0; bottom: 0; width: 38%; display: grid; place-content: center; justify-items: center; gap: 4px;
  opacity: 0; pointer-events: none; font-size: 12px; font-weight: 500;
}
.ytp-seek-hint.left { left: 0; border-radius: 0 50% 50% 0 / 0 50% 50% 0; background: rgba(255, 255, 255, .08); }
.ytp-seek-hint.right { right: 0; border-radius: 50% 0 0 50% / 50% 0 0 50%; background: rgba(255, 255, 255, .08); }
.ytp-seek-hint.show { animation: hint .7s ease; }
@keyframes hint { 0%, 60% { opacity: 1; } 100% { opacity: 0; } }
.ytp-spinner {
  position: absolute; z-index: 4; left: 50%; top: 50%; width: 52px; height: 52px; margin: -26px 0 0 -26px; border-radius: 50%;
  border: 4px solid rgba(255, 255, 255, .2); border-top-color: #fff; display: none; animation: spin .9s linear infinite;
  pointer-events: none;
}
.ytp-loading:not(.ytp-paused) .ytp-spinner { display: block; }
.ytp-error { position: absolute; z-index: 5; inset: 0; display: grid; place-content: center; justify-items: center; gap: 8px; padding: 20px; text-align: center; background: rgba(0, 0, 0, .86); }
.ytp-error-sub { color: #aaa; font-size: 12.5px; }
.ytp-error-link { margin-top: 8px; padding: 8px 16px; border-radius: 18px; background: #fff; color: #0f0f0f; font-weight: 600; text-decoration: none !important; }
.ytp-has-error .ytp-chrome, .ytp-has-error .ytp-big-play { display: none; }

/* settings menu */
.ytp-menu {
  position: absolute; z-index: 6; right: 12px; bottom: 62px; min-width: 250px; max-height: calc(100% - 80px); overflow-y: auto;
  padding: 8px 0; border-radius: 12px; background: rgba(28, 28, 28, .92); backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  text-shadow: none; animation: fade .15s ease;
}
.ytp-menu-row, .ytp-menu-head {
  display: flex; align-items: center; gap: 12px; width: 100%; height: 40px; padding: 0 16px; border: 0; background: transparent;
  color: #eee; font: 500 13.5px var(--font); text-align: left; cursor: pointer;
}
.ytp-menu-row:hover, .ytp-menu-head:hover { background: rgba(255, 255, 255, .1); }
.ytp-menu-label { flex: 1; }
.ytp-menu-value { display: inline-flex; align-items: center; gap: 4px; color: #ccc; font-weight: 400; }
.ytp-menu-head { border-bottom: 1px solid rgba(255, 255, 255, .15); margin-bottom: 6px; padding-bottom: 2px; height: 44px; }
.ytp-menu-option { padding-left: 48px; position: relative; }
.ytp-menu-option .ytp-check { position: absolute; left: 16px; }
.ytp-switch { position: relative; width: 36px; height: 14px; border-radius: 7px; background: rgba(255, 255, 255, .3); }
.ytp-switch::after { content: ""; position: absolute; top: -3px; left: -2px; width: 20px; height: 20px; border-radius: 50%; background: #bdbdbd; box-shadow: 0 1px 4px rgba(0, 0, 0, .5); transition: transform .15s ease, background .15s ease; }
.ytp-switch.on { background: rgba(255, 0, 51, .55); }
.ytp-switch.on::after { transform: translateX(20px); background: #fff; }

/* audio mode */
.ytp-audio { aspect-ratio: auto; height: 190px; background: radial-gradient(120% 140% at 20% 0%, rgba(var(--accent-rgb), .22), #08080b 60%); }
.ytp-audio .ytp-video { opacity: 0; }
.ytp-audio-cover { position: absolute; inset: 0 0 56px; z-index: 1; display: none; align-items: center; gap: 16px; padding: 0 22px; cursor: pointer; }
.ytp-audio .ytp-audio-cover { display: flex; }
.ytp-audio-disc { flex: none; width: 76px; height: 76px; border-radius: 16px; display: grid; place-items: center; background: rgba(255, 255, 255, .08); border: 1px solid rgba(255, 255, 255, .12); }
.ytp-audio-disc .ytp-svg { width: 36px; height: 36px; fill: var(--accent); filter: none; }
.ytp-audio-name { font-size: 15px; font-weight: 500; line-height: 1.35; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.ytp-audio:not(.ytp-paused) .ytp-audio-disc { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.05); } }
.ytp-audio .ytp-top, .ytp-audio .ytp-shade::after { display: none; }
.ytp-audio.ytp-idle .ytp-chrome { opacity: 1; pointer-events: auto; }
.ytp-audio.ytp-idle { cursor: auto; }

@media (max-width: 600px) {
  .ytp-btn { width: 38px; height: 38px; }
  .ytp-svg { width: 22px; height: 22px; }
  .ytp-volume-wrap .ytp-volume { display: none; }
  .ytp-pipbtn { display: none; }
  .ytp-chrome { left: 6px; right: 6px; }
  .viewer-stage { padding: 0 8px; }
  .zoom-wrap { inset: 0 0 8px; }
  .viewer-nav { display: none; }
  .viewer-bar { padding: 10px 10px 10px 16px; gap: 8px; }
  .viewer-context .zoom-pct, .viewer-context .vbtn:not(:first-child):not(:last-child) { display: none; }
  .viewer-player { width: 100%; }
}

/* ================================================================ rich text */
.ProseMirror { position: relative; word-wrap: break-word; white-space: pre-wrap; white-space: break-spaces; font-variant-ligatures: none; outline: none; }
.ProseMirror pre { white-space: pre-wrap; }
.ProseMirror li { position: relative; }
.ProseMirror-hideselection *::selection { background: transparent; }
.ProseMirror-hideselection { caret-color: transparent; }
.ProseMirror [draggable][contenteditable="false"] { user-select: text; }
img.ProseMirror-separator { display: inline !important; border: none !important; margin: 0 !important; }
.ProseMirror-gapcursor { display: none; pointer-events: none; position: absolute; }
.ProseMirror-gapcursor::after { content: ""; display: block; position: absolute; top: -2px; width: 20px; border-top: 1px solid var(--text); animation: pmBlink 1.1s steps(2, start) infinite; }
.ProseMirror-focused .ProseMirror-gapcursor { display: block; }
@keyframes pmBlink { to { visibility: hidden; } }
.ProseMirror-selectednode.os-media { outline: 2px solid var(--accent); outline-offset: 3px; border-radius: 12px; }

.rt { color: var(--text); font-size: .95rem; line-height: 1.65; caret-color: var(--accent); }
.rt > * + * { margin-top: .7em; }
.rt p { margin: 0; }
.rt h1, .rt h2, .rt h3 { line-height: 1.25; margin-top: 1.2em; }
.rt > :first-child { margin-top: 0; }
.rt h1 { font-size: 1.6em; }
.rt h2 { font-size: 1.3em; }
.rt h3 { font-size: 1.08em; }
.rt a { color: var(--accent); text-decoration: underline; text-decoration-color: rgba(var(--accent-rgb), .4); text-underline-offset: 3px; cursor: pointer; }
.rt strong { font-weight: 650; }
.rt mark { background: rgba(240, 198, 116, .32); color: inherit; padding: 0 .12em; border-radius: 3px; }
.rt code { font: .86em var(--mono); padding: .12em .38em; border-radius: 6px; background: rgba(255, 255, 255, .08); border: 1px solid var(--stroke); }
.rt pre { margin: 0; padding: 14px 16px; border-radius: var(--r-sm); background: rgba(0, 0, 0, .4); border: 1px solid var(--stroke); font: .84rem/1.6 var(--mono); overflow-x: auto; }
.rt pre code { padding: 0; border: 0; background: none; font-size: inherit; }
.rt blockquote { margin: 0; padding: .1em 0 .1em 1.1em; border-left: 3px solid rgba(var(--accent-rgb), .55); color: var(--muted); }
.rt hr { border: 0; height: 1px; background: var(--stroke-2); margin: 1.6em 0; }
.rt hr.ProseMirror-selectednode { background: var(--accent); }
.rt ul, .rt ol { padding-left: 1.4em; }
.rt ul { list-style: disc; }
.rt ol { list-style: decimal; }
.rt li > p { margin: 0; }
.rt li + li { margin-top: .25em; }
.rt li::marker { color: var(--muted); }
.rt ul[data-type="taskList"] { list-style: none; padding-left: .1em; }
.rt ul[data-type="taskList"] li { display: flex; gap: .6em; align-items: flex-start; }
.rt ul[data-type="taskList"] li > label { flex: none; margin-top: .22em; user-select: none; }
.rt ul[data-type="taskList"] li > div { flex: 1; min-width: 0; }
.rt ul[data-type="taskList"] li[data-checked="true"] > div { color: var(--dim); text-decoration: line-through; }
.rt input[type="checkbox"] { appearance: none; -webkit-appearance: none; width: 17px; height: 17px; margin: 0; border-radius: 5px; border: 1.5px solid var(--stroke-2); background: var(--glass-sunk); display: grid; place-items: center; cursor: pointer; }
.rt input[type="checkbox"]:checked { background: var(--accent); border-color: var(--accent); }
.rt input[type="checkbox"]:checked::after { content: ""; width: 9px; height: 5px; border: 2px solid var(--accent-ink); border-top: 0; border-right: 0; transform: rotate(-45deg) translate(1px, -1px); }
.rt input[type="checkbox"]:disabled { cursor: default; }
.rt p.is-editor-empty:first-child::before, .rt .is-empty.is-editor-empty::before { content: attr(data-placeholder); float: left; height: 0; color: var(--dim); pointer-events: none; }

/* media inside notes */
.os-media { position: relative; margin: 1.1em 0; }
.os-media > img { display: block; max-width: 100%; max-height: 560px; height: auto; border-radius: 12px; border: 1px solid var(--stroke); }
.os-media > img.zoomable { cursor: zoom-in; }
.os-media-grip { position: absolute; top: 8px; left: 8px; z-index: 5; width: 22px; height: 22px; border-radius: 6px; cursor: grab; opacity: 0; background: rgba(0, 0, 0, .6) radial-gradient(circle, #fff 1.2px, transparent 1.6px) 0 0 / 6px 6px; transition: opacity .15s ease; }
.ProseMirror .os-media:hover .os-media-grip { opacity: .9; }
.embed-file {
  display: flex; align-items: center; gap: 14px; width: 100%; padding: 10px 14px 10px 10px; text-align: left; font: inherit; color: var(--text);
  border: 1px solid var(--stroke); border-radius: 14px; background: var(--glass); cursor: pointer; transition: border-color .2s ease, background .2s ease;
}
.embed-file:hover { border-color: rgba(var(--accent-rgb), .45); background: var(--glass-2); }
.embed-file-thumb { position: relative; flex: none; width: 64px; height: 64px; border-radius: 10px; overflow: hidden; background: var(--glass-sunk); border: 1px solid var(--stroke); }
.embed-file-thumb .att-glyph { width: 26px; height: 26px; }
.embed-file-thumb .att-ext { display: none; }
.embed-file-text { display: grid; gap: 2px; min-width: 0; flex: 1; }
.embed-file-text strong { font-size: .9rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.embed-missing { padding: 14px; border: 1px dashed var(--stroke-2); border-radius: 12px; color: var(--dim); font-size: .85rem; }

/* toolbar buttons (shared) */
.tb {
  height: 32px; min-width: 32px; padding: 0 7px; display: inline-grid; place-items: center; flex: none;
  border: 0; border-radius: 8px; background: transparent; color: var(--muted); cursor: pointer; font: 600 .82rem var(--font);
  transition: background .15s ease, color .15s ease;
}
.tb:hover { background: rgba(255, 255, 255, .08); color: var(--text); }
.tb.on { background: var(--accent-soft); color: var(--accent); }
.tb.danger { color: var(--bad); }
.tb-text { padding: 0 10px; }
.tb-sep { width: 1px; height: 20px; background: var(--stroke-2); margin: 0 4px; flex: none; }
.tb-select { width: auto !important; height: 32px; padding: 0 2rem 0 .7rem !important; font-size: .84rem !important; border-radius: 8px; border: 1px solid var(--stroke); background-color: transparent; }

/* selection toolbar, link box, "/" menu */
.rt-bubble, .rt-link, .rt-slash {
  position: fixed; z-index: 95; background: rgba(20, 20, 24, .96); border: 1px solid var(--stroke-2); border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0, 0, 0, .55); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
}
.rt-bubble { display: flex; align-items: center; gap: 2px; padding: 4px; animation: fade .12s ease; }
.rt-link { display: flex; align-items: center; gap: 4px; padding: 6px; width: 330px; }
.rt-link-input { flex: 1; min-width: 0; padding: .45rem .6rem; border: 1px solid var(--stroke); border-radius: 8px; background: var(--glass-sunk); color: var(--text); font: .86rem var(--font); outline: 0; }
.rt-link-input:focus { border-color: rgba(var(--accent-rgb), .5); }
.rt-slash { width: 280px; max-height: 340px; overflow-y: auto; padding: 6px; display: grid; gap: 1px; }
.rt-slash-row { display: flex; align-items: center; gap: 12px; padding: 7px 8px; border: 0; border-radius: 8px; background: transparent; color: var(--text); text-align: left; cursor: pointer; font: inherit; }
.rt-slash-row.on, .rt-slash-row:hover { background: rgba(255, 255, 255, .08); }
.rt-slash-ico { width: 34px; height: 34px; flex: none; display: grid; place-items: center; border-radius: 8px; border: 1px solid var(--stroke); background: var(--glass); color: var(--muted); }
.rt-slash-row.on .rt-slash-ico { color: var(--accent); border-color: rgba(var(--accent-rgb), .4); }
.rt-slash-text { display: grid; }
.rt-slash-text strong { font-size: .86rem; font-weight: 600; }
.rt-slash-text span { font-size: .74rem; color: var(--dim); }
.rt-slash-empty { padding: 10px; color: var(--dim); font-size: .85rem; }

/* ================================================================ composer + timeline */
.composer { display: grid; padding: 0; border-radius: var(--r-md); transition: border-color .2s ease, box-shadow .2s ease; }
.composer:focus-within { border-color: rgba(var(--accent-rgb), .45); }
.composer-editor { padding: 14px 16px 6px; min-height: 88px; max-height: 420px; overflow-y: auto; cursor: text; }
.composer-editor .rt { min-height: 66px; }
.composer-tools { display: flex; align-items: center; gap: 2px; padding: 6px 8px 8px; border-top: 1px solid var(--stroke); }
.composer-tools .btn { margin-left: 6px; }
.composer-hint { margin-right: 6px; white-space: nowrap; }
.tb-expand { color: var(--text); }

.timeline { gap: 12px; }
.timeline li.note { padding: 14px 16px; gap: 8px; }
.timeline .rt-read { font-size: .93rem; }
.timeline .rt-read .ytp { border-radius: 10px; }
.timeline-empty { padding: 6px 2px; border: 0 !important; background: none !important; }
.note-tools { display: inline-flex; gap: 2px; opacity: .65; transition: opacity .15s ease; }
.note:hover .note-tools, .note:focus-within .note-tools { opacity: 1; }
.timeline li.note.is-article { padding: 12px; }
.article-card {
  display: flex; gap: 16px; width: 100%; padding: 6px; text-align: left; color: var(--text); font: inherit; cursor: pointer;
  border: 0; border-radius: 12px; background: transparent; transition: background .2s ease;
}
.article-card:hover { background: rgba(255, 255, 255, .04); }
.article-cover { flex: none; width: 128px; aspect-ratio: 4 / 3; border-radius: 10px; overflow: hidden; border: 1px solid var(--stroke); }
.article-cover img { width: 100%; height: 100%; object-fit: cover; }
.article-text { display: grid; gap: 5px; align-content: start; min-width: 0; }
.article-text .eyebrow { color: var(--accent); font-size: .64rem; }
.article-title { font-size: 1.08rem; font-weight: 650; letter-spacing: -.01em; line-height: 1.3; }
.article-excerpt { color: var(--muted); font-size: .87rem; line-height: 1.5; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
@media (max-width: 600px) {
  .article-cover { width: 84px; }
  .composer-hint { display: none; }
}

/* ================================================================ full-screen writer */
.writer {
  position: fixed; inset: 0; z-index: 70; display: grid; grid-template-rows: auto auto minmax(0, 1fr);
  background: var(--bg); animation: wIn .22s cubic-bezier(.2, .8, .2, 1);
}
.writer::before { content: ""; position: absolute; inset: 0; z-index: -1; background: radial-gradient(900px 600px at 50% -10%, rgba(var(--accent-rgb), .07), transparent 70%); pointer-events: none; }
.writer.closing { animation: wOut .16s ease forwards; }
@keyframes wIn { from { opacity: 0; transform: translateY(14px) scale(.995); } to { opacity: 1; transform: none; } }
@keyframes wOut { to { opacity: 0; transform: translateY(10px); } }
.writer-bar { display: flex; align-items: center; gap: 10px; padding: 12px 18px; border-bottom: 1px solid var(--hair); min-width: 0; }
.writer-back { width: 38px; padding: 0; }
.writer-crumb { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.writer-status:empty, .writer-count:empty { display: none; }
.writer-status, .writer-count { white-space: nowrap; }
.writer-bar .btn .ico-s { width: 17px; height: 17px; }
.writer-export { position: relative; }
.writer-menu { position: absolute; right: 0; top: calc(100% + 8px); z-index: 5; width: 270px; padding: 6px; display: grid; gap: 2px; border-radius: var(--r-md); background: rgba(18, 18, 22, .96); }
.writer-menu-row { display: grid; gap: 1px; padding: 9px 12px; border: 0; border-radius: 10px; background: transparent; color: var(--text); text-align: left; cursor: pointer; font: inherit; }
.writer-menu-row:hover { background: rgba(255, 255, 255, .07); }
.writer-menu-row strong { font-size: .88rem; font-weight: 600; }
.writer-menu-sep { height: 1px; margin: 4px 6px; background: var(--stroke); }
.writer-menu-row:last-child strong { color: var(--bad); }

.writer-toolbar {
  display: flex; align-items: center; gap: 2px; padding: 8px 18px; overflow-x: auto; scrollbar-width: none;
  justify-content: safe center; border-bottom: 1px solid var(--hair); background: rgba(255, 255, 255, .015);
}
.writer-toolbar::-webkit-scrollbar { display: none; }
.writer-scroll { overflow-y: auto; scroll-padding: 120px; }
.writer-page { max-width: 740px; margin: 0 auto; padding: 64px 28px 40vh; }
.writer-title {
  display: block; width: 100%; padding: 0; margin: 0; resize: none; overflow: hidden; border: 0; outline: 0; background: transparent;
  color: var(--text); font: 700 2.5rem/1.15 var(--font); letter-spacing: -.03em;
}
.writer-title::placeholder { color: rgba(255, 255, 255, .18); }
.writer-byline { margin: 14px 0 34px; padding-bottom: 22px; border-bottom: 1px solid var(--hair); }
.writer-body .rt {
  min-height: 50vh; font: 400 1.16rem/1.78 Charter, "Bitstream Charter", "Sitka Text", Cambria, Georgia, serif;
  color: #dcdde2; letter-spacing: .003em;
}
.writer-body .rt h1, .writer-body .rt h2, .writer-body .rt h3 { font-family: var(--font); color: var(--text); letter-spacing: -.02em; margin-top: 1.6em; }
.writer-body .rt h1 { font-size: 1.75em; }
.writer-body .rt h2 { font-size: 1.38em; }
.writer-body .rt h3 { font-size: 1.12em; }
.writer-body .rt > * + * { margin-top: .95em; }
.writer-body .rt blockquote { font-style: italic; font-size: 1.06em; }
.writer-body .rt code, .writer-body .rt pre { font-size: .8em; }
.writer-body .rt ul[data-type="taskList"] li > label { margin-top: .4em; }
.writer-body .os-media { margin: 2em 0; }
.writer-body .os-media > img { margin: 0 auto; max-height: 72vh; }
.writer.reading .writer-title { cursor: default; }
.writer.reading .writer-title:placeholder-shown { display: none; }
@media (max-width: 700px) {
  .writer-bar { padding: 10px 12px; gap: 6px; }
  .writer-crumb, .writer-count, .hide-sm { display: none; }
  .writer-toolbar { justify-content: flex-start; padding: 6px 10px; }
  .writer-page { padding: 30px 18px 40vh; }
  .writer-title { font-size: 1.85rem; }
  .writer-body .rt { font-size: 1.06rem; }
}

/* Print / Save as PDF from the writer: only the article. */
@media print {
  html.print-writer body > *:not(.writer) { display: none !important; }
  html.print-writer body { background: #fff !important; }
  html.print-writer body::before { display: none; }
  html.print-writer .writer { position: static; display: block; background: #fff; animation: none; }
  html.print-writer .writer::before, html.print-writer .writer-bar, html.print-writer .writer-toolbar { display: none !important; }
  html.print-writer .writer-scroll { overflow: visible; }
  html.print-writer .writer-page { max-width: none; padding: 0; }
  html.print-writer .writer-title { color: #111; font-size: 26pt; height: auto !important; }
  html.print-writer .writer-byline { color: #666; border-color: #ddd; }
  html.print-writer .rt { color: #1a1a1a !important; font-size: 11.5pt !important; min-height: 0; }
  html.print-writer .rt h1, html.print-writer .rt h2, html.print-writer .rt h3 { color: #000 !important; break-after: avoid; }
  html.print-writer .rt a { color: #0b57d0; }
  html.print-writer .rt pre, html.print-writer .rt code { background: #f3f3f3; border-color: #ddd; color: #111; }
  html.print-writer .rt blockquote { color: #444; border-color: #bbb; }
  html.print-writer .os-media { break-inside: avoid; }
  html.print-writer .os-media .ytp-chrome, html.print-writer .os-media .ytp-big-play, html.print-writer .os-media-grip { display: none !important; }
  html.print-writer .embed-file { border-color: #ccc; background: #fafafa; color: #111; }
}
