/* =====================================================================
   viewer.css  —  document viewer (reference 3): dark glass shell,
   context panel on the left, white "paper" on the right.
   Used for every PDF, image/diagram and study note. Always dark, in both themes.
   ===================================================================== */
#viewer { position: fixed; inset: 0; z-index: 80; }
.vw { --vf: #e9ebf3; --vm: #a3a9bd; --vl: rgba(255, 255, 255, .14); position: absolute; inset: 0; display: flex; padding: 14px; color: var(--vf); background: #0a0c12; animation: vwIn .35s var(--ease) both; }
@keyframes vwIn { from { opacity: 0; transform: scale(.985); } }
.vw-bg { position: absolute; inset: 0; overflow: hidden; }
.vw-bg::before, .vw-bg::after { content: ""; position: absolute; border-radius: 50%; filter: blur(70px); opacity: .55; }
.vw-bg::before { width: 60vmax; height: 60vmax; left: -15vmax; top: -20vmax; background: color-mix(in srgb, var(--ac) 55%, #0a0c12); }
.vw-bg::after { width: 55vmax; height: 55vmax; right: -20vmax; bottom: -25vmax; background: #26395f; }
.vw-glass {
  position: relative; flex: 1; min-width: 0; min-height: 0; display: grid; grid-template-columns: 330px minmax(0, 1fr);
  border: 1px solid var(--vl); border-radius: 22px; overflow: hidden;
  background: rgba(16, 18, 26, .66); -webkit-backdrop-filter: blur(28px) saturate(1.3); backdrop-filter: blur(28px) saturate(1.3);
  transition: grid-template-columns .4s var(--ease);
}
.vw[data-panel=closed] .vw-glass { grid-template-columns: 0 minmax(0, 1fr); }

/* panel */
.vw-panel { display: flex; flex-direction: column; min-width: 0; min-height: 0; border-right: 1px solid var(--vl); overflow: hidden; }
.vw[data-panel=closed] .vw-panel { visibility: hidden; border-right-color: transparent; transition: visibility 0s .4s; }
.vw-ph { display: flex; flex-direction: column; gap: 2px; padding: 18px 18px 12px; min-width: 300px; }
.vw-ph small { color: var(--vm); font-size: 12px; text-transform: lowercase; }
.vw-ph h2 { color: var(--vf); font-size: 19px; line-height: 1.22; font-family: var(--serif); font-weight: 600; letter-spacing: -.01em; overflow-wrap: anywhere; }
.vw-pb { flex: 1; min-height: 0; overflow: auto; padding: 0 18px 18px; min-width: 300px; display: grid; gap: 18px; align-content: start; }
.vw-pb p { color: #c9cddc; font-size: 14px; }
.vw-ctxrow { display: flex; flex-wrap: wrap; gap: 6px; }
.vw .chip { color: var(--vm); border-color: var(--vl); }
.vw-sec h3 { font-size: 12px; font-weight: 600; text-transform: lowercase; color: var(--vm); letter-spacing: 0; margin-bottom: 8px; }
.vw-list { list-style: none; padding: 0; display: grid; gap: 2px; }
.vw-list a { display: grid; grid-template-columns: 22px minmax(0, 1fr); align-items: center; gap: 8px; min-height: 42px; padding: 6px 10px; border-radius: 10px; font-size: 14px; color: #d3d7e4; transition: background .18s; }
.vw-list a:hover { background: rgba(255, 255, 255, .07); }
.vw-list a[aria-current=page] { background: rgba(255, 255, 255, .12); color: #fff; font-weight: 600; }
.vw-list .sg circle { stroke: var(--vm); }
.vw-list .sg[data-s=done] circle { fill: #d3d7e4; stroke: #d3d7e4; }
.vw-list .sg path { stroke: #14161e; }
.vw-list .sg[data-s=current] circle { stroke: var(--ac); }
.vw-list .tx { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.vw-acts { display: grid; gap: 8px; }
.vw .btn { border-color: var(--vl); color: var(--vf); justify-content: flex-start; }
.vw .btn:hover { background: rgba(255, 255, 255, .08); }
.vw .btn-ac { background: var(--ac); border-color: var(--ac); color: var(--on-ac); }
.vw-pn { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.vw-pn .btn { justify-content: center; }

/* document side */
.vw-doc { display: flex; flex-direction: column; min-width: 0; min-height: 0; position: relative; }
.vw-bar { display: flex; align-items: center; flex-wrap: wrap; gap: 6px 4px; padding: 8px 10px; padding-top: calc(8px + env(safe-area-inset-top)); border-bottom: 1px solid var(--vl); background: rgba(255, 255, 255, .04); }
.vw-bar .grp { display: flex; align-items: center; gap: 2px; }
.vw-bar .sep { width: 1px; align-self: stretch; margin: 6px 6px; background: var(--vl); }
.vw-bar .sp { flex: 1; }
.vw-ttl { display: none; flex: 1; min-width: 0; font-weight: 600; font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 6px; }
.vb { display: inline-grid; place-items: center; min-width: 38px; height: 38px; padding: 0 8px; border: 0; border-radius: 10px; background: transparent; color: var(--vf); font-weight: 600; font-size: 13px; transition: background .18s, transform .18s; }
.vb svg { width: 20px; height: 20px; fill: none; stroke: currentColor; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.vb:hover { background: rgba(255, 255, 255, .1); }
.vb:active { transform: scale(.92); }
.vb:disabled { opacity: .35; pointer-events: none; }
.vb[aria-pressed=true] { background: rgba(255, 255, 255, .14); }
.vb.zl { min-width: 54px; font-variant-numeric: tabular-nums; }
.vw-pgin { display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--vm); font-variant-numeric: tabular-nums; }
.vw-pgin input { width: 46px; height: 32px; border: 1px solid var(--vl); border-radius: 8px; background: rgba(255, 255, 255, .06); color: var(--vf); text-align: center; font-size: 14px; -moz-appearance: textfield; }
.vw-pgin input::-webkit-outer-spin-button, .vw-pgin input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.vw[data-panel=closed] .vw-ttl { display: block; }
@media (pointer: coarse) { .vb { min-width: 44px; height: 44px; } .vw-pgin input { height: 40px; } }

.vw-scroll { position: relative; flex: 1; min-height: 0; overflow: auto; overscroll-behavior: contain; touch-action: pan-x pan-y; background: rgba(0, 0, 0, .22); -webkit-overflow-scrolling: touch; }
.vw-pages { position: relative; display: flex; flex-direction: column; align-items: center; gap: 14px; padding: 18px 16px calc(24px + env(safe-area-inset-bottom)); width: max-content; min-width: 100%; transform-origin: 0 0; }
.pg { position: relative; background: #fff; box-shadow: 0 6px 26px rgba(0, 0, 0, .4); flex: none; overflow: hidden; }
.pg canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.pg::after { content: attr(data-n); position: absolute; right: 8px; bottom: 6px; font: 11px var(--mono); color: #9a9fb1; }
.pg[data-ok=true]::after { display: none; }

.vw-stage { position: absolute; inset: 0; overflow: hidden; cursor: grab; touch-action: none; user-select: none; -webkit-user-select: none; }
.vw-stage:active { cursor: grabbing; }
.vw-stage img { position: absolute; left: 0; top: 0; max-width: none; transform-origin: 0 0; background: #fff; box-shadow: 0 6px 26px rgba(0, 0, 0, .4); -webkit-user-drag: none; user-select: none; will-change: transform; }

.paper { width: min(calc(100% - 32px), 840px); margin: 18px auto calc(28px + env(safe-area-inset-bottom)); padding: clamp(22px, 5.5vw, 60px); background: #fff; color: #1b1c22; border-radius: 4px; box-shadow: 0 6px 26px rgba(0, 0, 0, .4); font: 400 clamp(16px, 2.4vw, 18px)/1.7 var(--serif); overflow-wrap: anywhere; }
.paper h1, .paper h2, .paper h3, .paper h4 { font-family: var(--serif); color: #111; letter-spacing: -.01em; line-height: 1.2; margin: 1.4em 0 .5em; }
.paper > :first-child { margin-top: 0; }
.paper h1 { font-size: 1.9em; } .paper h2 { font-size: 1.45em; border-bottom: 1px solid #d8dae3; padding-bottom: .25em; } .paper h3 { font-size: 1.2em; } .paper h4 { font-size: 1.05em; }
.paper p { margin: .8em 0; }
.paper ul, .paper ol { margin: .8em 0; padding-left: 1.5em; }
.paper li { margin: .25em 0; }
.paper a { color: #2447c9; text-decoration: underline; }
.paper code { font: .86em var(--mono); background: #eef0f6; padding: .1em .35em; border-radius: 4px; }
.paper pre { font: 13.5px/1.55 var(--mono); background: #12141c; color: #e8ebf5; padding: 14px 16px; border-radius: 8px; overflow: auto; margin: 1em 0; }
.paper pre code { background: none; padding: 0; color: inherit; }
.paper blockquote, .paper .callout { margin: 1em 0; padding: .6em 1em; border-left: 4px solid var(--ac); background: #f3f4f9; border-radius: 0 8px 8px 0; }
.paper table { border-collapse: collapse; display: block; overflow-x: auto; max-width: 100%; margin: 1em 0; font-size: .92em; }
.paper th, .paper td { border: 1px solid #cfd2de; padding: 7px 11px; text-align: left; }
.paper th { background: #eef0f6; font-family: var(--font); font-size: .86em; }
.paper img, .paper svg { max-width: 100%; height: auto; display: block; margin: 1em auto; }
.paper hr { border: 0; border-top: 1px solid #d8dae3; margin: 1.6em 0; }

.vw-load { position: absolute; inset: 0; display: grid; place-content: center; justify-items: center; gap: 14px; text-align: center; padding: 24px; color: var(--vm); font-size: 14px; background: rgba(10, 12, 18, .35); z-index: 3; }
.vw-load[hidden] { display: none; }
.vw-load b { color: var(--vf); font-size: 16px; }
.spin { width: 30px; height: 30px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .18); border-top-color: var(--ac); animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.vw-dim { display: none; }

/* ---------- mobile / small tablets ---------- */
@media (max-width: 859px) {
  .vw { padding: 0; }
  .vw-glass { grid-template-columns: minmax(0, 1fr); border: 0; border-radius: 0; }
  .vw[data-panel=closed] .vw-glass { grid-template-columns: minmax(0, 1fr); }
  .vw-ttl { display: block; }
  .vw-bar .sep.hide-s { display: none; }
  .vw-bar .row-break { flex-basis: 100%; height: 0; }
  .vw-bar .tools { flex: 1 1 100%; display: flex; align-items: center; justify-content: center; gap: 2px; flex-wrap: wrap; }
  .vw-panel {
    position: absolute; z-index: 6; left: 0; right: 0; bottom: 0; max-height: min(82%, 640px); border: 1px solid var(--vl); border-bottom: 0; border-radius: 20px 20px 0 0;
    background: rgba(18, 20, 29, .97); box-shadow: 0 -20px 50px rgba(0, 0, 0, .5);
    transform: translateY(105%); visibility: hidden; transition: transform .38s var(--ease), visibility 0s .38s;
    padding-bottom: env(safe-area-inset-bottom);
  }
  .vw[data-panel=open] .vw-panel { transform: none; visibility: visible; transition: transform .38s var(--ease), visibility 0s; }
  .vw[data-panel=closed] .vw-panel { visibility: hidden; }
  .vw-ph, .vw-pb { min-width: 0; }
  .vw-dim { display: block; position: absolute; inset: 0; z-index: 5; background: rgba(0, 0, 0, .5); opacity: 0; pointer-events: none; transition: opacity .3s; }
  .vw[data-panel=open] .vw-dim { opacity: 1; pointer-events: auto; }
  .vw-pages { padding: 12px 10px calc(24px + env(safe-area-inset-bottom)); }
  .paper { width: calc(100% - 20px); margin-top: 12px; }
}
@media (min-width: 860px) { .vw-bar .tools { display: contents; } .vw-bar .row-break { display: none; } }

/* toolbar order on small screens: [close] [title ........] [details] / tools on their own row */
@media (max-width: 859px) {
  #vwClose { order: 1; }
  .vw-ttl { order: 2; }
  .vw-bar .sp { display: none; }
  #vwPanelBtn { order: 3; }
  .vw-bar .tools { order: 4; }
  .vw-bar .grp { flex-wrap: nowrap; }
}
@media (max-width: 520px) { .vw-bar .sep { display: none; } .vw-bar .vb { min-width: 40px; } .vb.zl { min-width: 48px; } .vw-bar .tools { gap: 6px; } }
.paper th, .paper td { overflow-wrap: normal; }

/* ---- new design language overrides: square, flat, ink-on-paper ---- */
.vw { padding: 0; }
.vw-bg { display: none; }
.vw-glass { border-radius: 0 !important; border: 0 !important; background: #0e0e0d !important; -webkit-backdrop-filter: none !important; backdrop-filter: none !important; }
.vb, .vw-pgin input, .vw .btn { border-radius: 0 !important; }
.vw-panel { border-radius: 0 !important; }
.paper { border-radius: 0 !important; font-family: var(--font); font-size: clamp(16px, 2.4vw, 18px); line-height: 1.7; }
.paper h1, .paper h2, .paper h3, .paper h4 { font-family: var(--font); font-weight: 600; letter-spacing: -.03em; }
.paper h2 { border-bottom: 1px solid #111; }
.paper code { border-radius: 0; background: #ece9df; }
.paper pre { border-radius: 0; background: #111; }
.paper blockquote, .paper .callout { border-radius: 0; border: 1px solid #111; border-left: 6px solid var(--ac); background: #f6f5ef; }
.paper th, .paper td { border-color: #111; }
.paper th { background: #ece9df; }
.paper svg { display: block; max-width: 100%; height: auto; margin: 1.2em auto; border: 1px solid #111; background: #fbfaf6; padding: 8px; }
.paper table { display: block; max-width: 100%; overflow-x: auto; }
