/* EnginPath Study Reader — interface.
   Light by default, laid out the way people already expect a PDF reader to work:
   a thin toolbar with page controls on the left, zoom in the middle and tools on
   the right, a collapsible panel down the left, and the page on a grey canvas so
   the white sheet reads as paper. Night mode flips the whole thing dark. */

:root {
  --chrome:      #ffffff;   /* toolbars, panels */
  --chrome-2:    #f4f5f7;   /* hovers, inset areas */
  --chrome-3:    #eaebee;   /* pressed / selected */
  --canvas:      #e4e6e9;   /* the desk the page sits on */
  --border:      #d8dade;
  --border-soft: #e7e8eb;
  --text:        #23252a;
  --dim:         #6b6f76;
  --faint:       #8b9098;
  --accent:      #2f6fe0;
  --accent-soft: #e8f0fd;
  --accent-line: #b9d0f7;
  --green:       #17795a;
  --warn:        #c0761a;
  --danger:      #c43d3d;
  --hl:          rgba(255, 214, 0, 0.42);
  --shadow:      0 1px 3px rgba(16, 20, 28, 0.13), 0 6px 18px rgba(16, 20, 28, 0.09);
  --page-shadow: 0 1px 4px rgba(16, 20, 28, 0.18), 0 8px 26px rgba(16, 20, 28, 0.14);
}

body.night {
  --chrome:      #1b1e25;
  --chrome-2:    #23272f;
  --chrome-3:    #2c313a;
  --canvas:      #14161b;
  --border:      #343a44;
  --border-soft: #2a2f38;
  --text:        #e9ebee;
  --dim:         #a2a8b2;
  --faint:       #7d838d;
  --accent:      #6fa0ff;
  --accent-soft: rgba(111, 160, 255, 0.16);
  --accent-line: rgba(111, 160, 255, 0.4);
  --green:       #4ac79b;
  --warn:        #e0a23b;
  --danger:      #ef7676;
  --shadow:      0 1px 3px rgba(0, 0, 0, 0.5), 0 8px 24px rgba(0, 0, 0, 0.45);
  --page-shadow: 0 2px 10px rgba(0, 0, 0, 0.6);
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  display: flex;
  flex-direction: column;
  font-family: "Segoe UI", system-ui, -apple-system, sans-serif;
  font-size: 13.5px;
  background: var(--canvas);
  color: var(--text);
  overflow: hidden;
  user-select: none;
}
button, input, select, textarea { font-family: inherit; font-size: inherit; color: inherit; }

/* ── Tab strip ────────────────────────────────────────────────────────────── */
.tabs { display: flex; align-items: center; gap: 2px; height: 36px; flex: none;
  background: var(--chrome-2); border-bottom: 1px solid var(--border); padding: 0 6px; }
.tab-list { display: flex; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.tab-list::-webkit-scrollbar { display: none; }
.tab { display: flex; align-items: center; gap: 8px; max-width: 230px; height: 26px;
  padding: 0 9px; border-radius: 5px; background: transparent; border: 1px solid transparent;
  color: var(--dim); cursor: pointer; white-space: nowrap; font-size: 0.84rem; }
.tab:hover { background: var(--chrome-3); color: var(--text); }
.tab.on { background: var(--chrome); border-color: var(--border); color: var(--text);
  font-weight: 600; box-shadow: 0 1px 2px rgba(16,20,28,0.07); }
.tab span { overflow: hidden; text-overflow: ellipsis; }
.tab i { font-style: normal; opacity: 0.5; padding: 0 3px; border-radius: 3px; font-size: 0.8rem; }
.tab i:hover { opacity: 1; background: rgba(128,128,128,0.22); }
.tab-add { background: none; border: none; color: var(--dim); font-size: 1.05rem;
  cursor: pointer; padding: 1px 9px; border-radius: 5px; }
.tab-add:hover { background: var(--chrome-3); color: var(--text); }
.tab-spacer { flex: 1; }

/* ── Toolbar ──────────────────────────────────────────────────────────────── */
.toolbar { display: flex; align-items: center; gap: 2px; height: 42px; flex: none;
  background: var(--chrome); border-bottom: 1px solid var(--border); padding: 0 8px; }
.tb-btn { background: none; border: 1px solid transparent; color: var(--dim);
  border-radius: 5px; height: 30px; min-width: 30px; padding: 0 7px; cursor: pointer;
  font-size: 0.95rem; display: inline-flex; align-items: center; justify-content: center; }
.tb-btn:hover:not(:disabled) { background: var(--chrome-2); color: var(--text); }
.tb-btn:active:not(:disabled) { background: var(--chrome-3); }
.tb-btn.on { background: var(--accent-soft); color: var(--accent); border-color: var(--accent-line); }
.tb-btn:disabled { opacity: 0.32; cursor: default; }
.tb-sep { width: 1px; height: 20px; background: var(--border); margin: 0 6px; flex: none; }
.tb-spacer { flex: 1; }

.pagebox { display: flex; align-items: center; gap: 5px; font-size: 0.84rem; color: var(--dim); }
.pagebox input { width: 44px; text-align: center; background: var(--chrome); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px; padding: 4px 3px; user-select: text; }
.pagebox input:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft); }
.pagebox input:disabled { background: var(--chrome-2); color: var(--faint); }
#zoom-sel { background: var(--chrome); color: var(--text); border: 1px solid var(--border);
  border-radius: 4px; padding: 4px 5px; font-size: 0.8rem; cursor: pointer; min-width: 92px; }
#zoom-sel:focus { outline: none; border-color: var(--accent); }

.progress { display: flex; align-items: center; gap: 8px; margin-right: 2px; }
.progress-bar { width: 80px; height: 6px; background: var(--chrome-3); border-radius: 999px;
  overflow: hidden; }
.progress-bar i { display: block; height: 100%; width: 0; border-radius: 999px;
  background: linear-gradient(90deg, var(--accent), var(--green)); transition: width 0.25s ease; }
#progress-txt { font-size: 0.74rem; color: var(--dim); min-width: 28px; font-weight: 600; }

/* ── Find bar ─────────────────────────────────────────────────────────────── */
.findbar { display: flex; align-items: center; gap: 6px; flex: none; height: 40px;
  background: var(--chrome-2); border-bottom: 1px solid var(--border); padding: 0 10px; }
.findbar input[type=text] { flex: 0 1 300px; background: var(--chrome); color: var(--text);
  border: 1px solid var(--border); border-radius: 5px; padding: 6px 10px; user-select: text; }
.findbar input[type=text]:focus { outline: none; border-color: var(--accent);
  box-shadow: 0 0 0 2px var(--accent-soft); }
#find-count { font-size: 0.79rem; color: var(--dim); min-width: 78px; }

/* ── Layout ───────────────────────────────────────────────────────────────── */
.main { flex: 1; display: flex; min-height: 0; }

.sidebar { width: 250px; flex: none; background: var(--chrome); border-right: 1px solid var(--border);
  display: flex; flex-direction: column; min-height: 0; }
.sidebar.hidden { display: none; }
/* Seven tabs no longer fit on one row at this width, and a clipped label is
   worse than a second row, so they wrap four-up. */
.side-tabs { display: flex; flex-wrap: wrap; flex: none; border-bottom: 1px solid var(--border);
  background: var(--chrome-2); }
.side-tab { flex: 1 0 25%; background: none; border: none; border-bottom: 2px solid transparent;
  color: var(--dim); padding: 8px 2px; font-size: 0.72rem; font-weight: 600; cursor: pointer;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-tab:hover { color: var(--text); background: var(--chrome-3); }
.side-tab.on { color: var(--accent); border-bottom-color: var(--accent); background: var(--chrome); }
.side-body { flex: 1; overflow-y: auto; min-height: 0; }
.panel { display: none; padding: 10px; }
.panel.on { display: block; }

.thumb { margin-bottom: 10px; cursor: pointer; border: 2px solid transparent; border-radius: 4px;
  overflow: hidden; background: #fff; position: relative; box-shadow: 0 1px 3px rgba(16,20,28,0.16); }
.thumb.on { border-color: var(--accent); }
.thumb canvas { display: block; width: 100%; height: auto; }
.thumb b { position: absolute; right: 4px; bottom: 4px; background: rgba(0,0,0,0.62);
  color: #fff; font-size: 0.67rem; border-radius: 3px; padding: 1px 6px; font-weight: 600; }
.thumb.done::after { content: "✓"; position: absolute; left: 4px; top: 4px; background: var(--green);
  color: #fff; font-size: 0.68rem; font-weight: 800; border-radius: 50%; width: 17px; height: 17px;
  display: flex; align-items: center; justify-content: center; }

.ol-item { display: block; width: 100%; text-align: left; background: none; border: none;
  color: var(--dim); font-size: 0.82rem; padding: 6px 8px; border-radius: 4px; cursor: pointer;
  line-height: 1.45; }
.ol-item:hover { background: var(--chrome-2); color: var(--text); }

.note-card { background: var(--chrome); border: 1px solid var(--border);
  border-left: 3px solid var(--warn); border-radius: 6px; padding: 10px 12px; margin-bottom: 9px;
  cursor: pointer; box-shadow: 0 1px 2px rgba(16,20,28,0.05); }
.note-card:hover { border-color: var(--accent); border-left-color: var(--warn); }
.note-card .nc-p { font-size: 0.69rem; color: var(--accent); font-weight: 700; margin-bottom: 4px; }
.note-card .nc-q { font-size: 0.8rem; color: var(--text); line-height: 1.5; margin: 0 0 5px;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.note-card .nc-n { font-size: 0.77rem; color: var(--dim); line-height: 1.5; margin: 0; font-style: italic; }
.note-card img { width: 100%; border-radius: 4px; margin-top: 6px; background: #fff;
  border: 1px solid var(--border-soft); }
.note-card .nc-x { float: right; background: none; border: none; color: var(--faint);
  cursor: pointer; font-size: 0.78rem; }
.note-card .nc-x:hover { color: var(--danger); }

.panel .empty { color: var(--dim); font-size: 0.82rem; line-height: 1.7; padding: 14px 6px; }
.panel .side-act { width: 100%; background: var(--chrome-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 5px; padding: 8px; font-size: 0.79rem; font-weight: 600;
  cursor: pointer; margin-bottom: 10px; }
.panel .side-act:hover:not(:disabled) { border-color: var(--accent); color: var(--accent);
  background: var(--accent-soft); }
.panel .side-act:disabled { opacity: 0.5; cursor: default; }

.lib-item { display: flex; align-items: center; gap: 9px; background: var(--chrome);
  border: 1px solid var(--border); border-radius: 6px; padding: 9px 11px; margin-bottom: 8px;
  cursor: pointer; }
.lib-item:hover { border-color: var(--accent); background: var(--accent-soft); }
.lib-item .li-b { flex: 1; min-width: 0; }
.lib-item b { display: block; font-size: 0.79rem; font-weight: 600; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.lib-item span { font-size: 0.71rem; color: var(--dim); }

/* ── Viewer ───────────────────────────────────────────────────────────────── */
.viewer-wrap { flex: 1; position: relative; min-width: 0; display: flex; flex-direction: column; }
/* An explicit display beats the hidden attribute, which left the split pane
   open on every launch and squeezed the document into half the window. */
.viewer-wrap[hidden] { display: none; }
.viewer { flex: 1; overflow: auto; padding: 20px 0 48px; background: var(--canvas); outline: none; }
.viewer.spread .page-holder { display: inline-block; vertical-align: top; }

.page-holder { position: relative; margin: 0 auto 18px; background: #fff;
  box-shadow: var(--page-shadow); }
.page-holder canvas { display: block; }
.page-holder.studied { outline: 2px solid var(--green); outline-offset: 2px; }

/* Night mode inverts the page itself, never the chrome around it. */
body.night .page-holder canvas { filter: invert(1) hue-rotate(180deg); }
body.night .thumb canvas { filter: invert(1) hue-rotate(180deg); }

.text-layer { position: absolute; inset: 0; overflow: hidden; opacity: 0.25;
  line-height: 1; user-select: text; }
.text-layer span { position: absolute; white-space: pre; transform-origin: 0 0;
  color: transparent; cursor: text; }
.text-layer ::selection { background: rgba(47,111,224,0.45); }
.text-layer .find-hit { background: rgba(255,190,40,0.6); border-radius: 2px; }
.text-layer .find-hit.current { background: rgba(47,111,224,0.55); }

.anno-layer { position: absolute; inset: 0; pointer-events: none; }
.anno { position: absolute; border-radius: 2px; pointer-events: auto; cursor: pointer; }
.anno.hl { background: var(--hl); mix-blend-mode: multiply; }
.anno.note { background: rgba(224,162,59,0.3); border-bottom: 2px solid var(--warn);
  mix-blend-mode: multiply; }
.anno.note::after { content: "🗒"; position: absolute; right: -16px; top: -6px; font-size: 0.7rem; }

.sel-box { position: absolute; border: 1.5px dashed var(--accent);
  background: rgba(47,111,224,0.13); pointer-events: none; }

.viewer.tool-snip { cursor: crosshair; }
.viewer.tool-highlight .text-layer, .viewer.tool-note .text-layer { cursor: text; }

/* Split view */
.viewer-wrap.split { border-left: 1px solid var(--border); max-width: 50%; }
.split-head { display: flex; align-items: center; gap: 8px; height: 33px; flex: none;
  background: var(--chrome); border-bottom: 1px solid var(--border); padding: 0 8px;
  font-size: 0.79rem; }
#split-name { flex: 1; color: var(--dim); overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }

/* ── Welcome ──────────────────────────────────────────────────────────────── */
.welcome { position: absolute; inset: 0; display: flex; align-items: center;
  justify-content: center; background: var(--canvas); padding: 24px; overflow-y: auto; }
.welcome[hidden] { display: none; }
.wel-box { max-width: 460px; text-align: center; }
.wel-logo { font-size: 2.7rem; margin-bottom: 10px; }
.wel-box h1 { margin: 0 0 10px; font-size: 1.55rem; font-weight: 700; letter-spacing: -0.02em; }
.wel-box h1 span { color: var(--accent); }
.wel-box p { color: var(--dim); line-height: 1.7; margin: 0 0 20px; font-size: 0.9rem; }
.wel-btn { background: var(--accent); color: #fff; border: none; border-radius: 6px;
  padding: 11px 26px; font-size: 0.93rem; font-weight: 600; cursor: pointer;
  box-shadow: 0 1px 3px rgba(47,111,224,0.4); }
.wel-btn:hover { background: #2660c9; }
.wel-drop { margin-top: 14px !important; font-size: 0.79rem !important; color: var(--faint) !important; }
.wel-recent { margin-top: 22px; text-align: left; }

/* ── Floating panels ──────────────────────────────────────────────────────── */
.pop { position: fixed; right: 18px; bottom: 18px; width: 288px; z-index: 40;
  background: var(--chrome); border: 1px solid var(--border); border-radius: 9px;
  padding: 14px; box-shadow: var(--shadow); }
.pop[hidden] { display: none; }
.pop-wide { width: 460px; }
.pop-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 11px; }
.pop-head b { font-size: 0.89rem; }
.pop-x { background: none; border: none; color: var(--faint); cursor: pointer; font-size: 0.85rem; }
.pop-x:hover { color: var(--text); }
.pop-note { font-size: 0.76rem; color: var(--dim); line-height: 1.6; margin: 10px 0 0; }
.pop-row { display: flex; gap: 8px; margin-top: 11px; flex-wrap: wrap; }
.pop-btn { flex: 1; background: var(--accent); color: #fff; border: none; border-radius: 5px;
  padding: 8px 12px; font-size: 0.81rem; font-weight: 600; cursor: pointer; white-space: nowrap; }
.pop-btn:hover { background: #2660c9; }
.pop-btn.ghost { background: var(--chrome-2); border: 1px solid var(--border); color: var(--text); }
.pop-btn.ghost:hover { background: var(--chrome-3); }
.pop textarea, .pop input[type=text], .pop select {
  width: 100%; background: var(--chrome); color: var(--text); border: 1px solid var(--border);
  border-radius: 5px; padding: 8px 10px; user-select: text; }
.pop textarea:focus, .pop input:focus, .pop select:focus { outline: none;
  border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }
#snip-img { width: 100%; border-radius: 5px; background: #fff; display: block;
  border: 1px solid var(--border); }

/* ── Scientific calculator ────────────────────────────────────────────────── */
.pop-calc { width: 340px; }
.calc-screen { background: #dfe4dc; border: 1px solid #b6bdb2; border-radius: 5px;
  padding: 7px 11px 9px; margin-bottom: 10px; }
body.night .calc-screen { background: #23291f; border-color: #39412f; }
.calc-flags { display: flex; align-items: center; gap: 8px; font-size: 0.62rem;
  font-weight: 800; letter-spacing: 0.08em; color: #5c6356; height: 12px; }
body.night .calc-flags { color: #8d9682; }
.calc-flags .calc-spacer { flex: 1; }
.calc-flags span[hidden] { display: none; }
#calc-shift { color: var(--accent); }
.calc-hist { text-align: right; font-size: 0.74rem; color: #5c6356; min-height: 14px;
  font-family: ui-monospace, Consolas, monospace; overflow: hidden; text-overflow: ellipsis;
  white-space: nowrap; }
body.night .calc-hist { color: #8d9682; }
.calc-out { text-align: right; font-size: 1.5rem; font-weight: 700; color: #1d2418;
  font-family: ui-monospace, Consolas, monospace; line-height: 1.35; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
body.night .calc-out { color: #d7e2cb; }

.calc-keys { display: grid; grid-template-columns: repeat(6, 1fr); gap: 4px; }
.calc-keys button { position: relative; background: var(--chrome-2); border: 1px solid var(--border);
  color: var(--text); border-radius: 4px; padding: 13px 0 5px; font-size: 0.78rem;
  cursor: pointer; line-height: 1.1; }
.calc-keys button:hover { background: var(--chrome-3); border-color: var(--accent); }
.calc-keys button:active { transform: translateY(1px); }
.calc-keys .k-sh { position: absolute; top: 2px; left: 0; right: 0; font-size: 0.55rem;
  font-style: normal; color: var(--faint); letter-spacing: -0.01em; }
.calc-keys .k-fn { color: var(--accent); }
.calc-keys .k-op { color: var(--accent); font-weight: 700; }
.calc-keys .k-shift { background: var(--accent-soft); border-color: var(--accent-line);
  color: var(--accent); font-weight: 700; }
.calc-keys .k-mode { font-weight: 700; font-size: 0.7rem; }
.calc-keys .k-mem { font-size: 0.72rem; color: var(--dim); }
.calc-keys .k-del { color: var(--warn); font-weight: 600; }
.calc-keys .k-ac { color: var(--danger); font-weight: 700; }
.calc-keys .k-eq { background: var(--accent); color: #fff; border-color: var(--accent);
  font-weight: 700; font-size: 0.95rem; }
.calc-keys .k-eq:hover { background: #2660c9; }

.u-row { display: flex; gap: 7px; }
.u-row input, .u-row select { flex: 1; }
.u-eq { text-align: center; color: var(--faint); margin: 7px 0; font-weight: 700; }
#u-cat { margin-bottom: 10px; }

/* ── Toast + drop hint ────────────────────────────────────────────────────── */
.toast { position: fixed; left: 50%; bottom: 26px; transform: translateX(-50%); z-index: 60;
  background: #23252a; border: 1px solid #3a3d44; color: #fff; border-radius: 6px;
  padding: 10px 18px; font-size: 0.84rem; font-weight: 500; box-shadow: var(--shadow); }
.toast[hidden] { display: none; }
.drop-hint { position: fixed; inset: 0; z-index: 70; background: rgba(228,230,233,0.9); }
body.night .drop-hint { background: rgba(20,22,27,0.9); }
.drop-hint { display: flex; align-items: center; justify-content: center; }
.drop-hint[hidden] { display: none; }
.drop-hint div { border: 2px dashed var(--accent); border-radius: 12px; padding: 40px 56px;
  font-size: 1.05rem; font-weight: 600; color: var(--accent); background: var(--chrome); }

::-webkit-scrollbar { width: 13px; height: 13px; }
::-webkit-scrollbar-track { background: var(--chrome-2); }
::-webkit-scrollbar-thumb { background: #c2c6cc; border-radius: 8px;
  border: 3px solid var(--chrome-2); }
::-webkit-scrollbar-thumb:hover { background: #a8adb5; }
body.night ::-webkit-scrollbar-thumb { background: #414751; border-color: var(--chrome-2); }
body.night ::-webkit-scrollbar-thumb:hover { background: #525966; }

@media print {
  .tabs, .toolbar, .findbar, .sidebar, .pop, .toast, .split-head, .welcome { display: none !important; }
  .viewer { overflow: visible; background: #fff; padding: 0; }
  .page-holder { box-shadow: none; margin: 0; page-break-after: always; }
  .text-layer, .anno-layer { display: none; }
}

/* ── Brand ───────────────────────────────────────────────────────────────── */
.brand { display: flex; align-items: center; gap: 7px; padding: 0 12px 0 4px; flex: none;
  margin-right: 4px; border-right: 1px solid var(--border); height: 22px; }
.brand img { display: block; flex: none; }
.brand span { font-size: 0.83rem; font-weight: 700; letter-spacing: -0.01em; color: var(--text);
  white-space: nowrap; }
.brand span b { color: #c0522a; font-weight: 700; }
body.night .brand span b { color: #ff8a4c; }

img.wel-logo { display: block; margin: 0 auto 14px; }
.about-brand { display: flex; align-items: center; gap: 11px; margin-bottom: 10px; }
.about-brand b { font-size: 0.9rem; }
.about-brand span { font-size: 0.76rem; color: var(--dim); }
/* Without a label this reads as a zoom slider, which is the one thing it isn't. */
.progress-lbl { font-size: 0.72rem; color: var(--faint); font-weight: 600;
  text-transform: uppercase; letter-spacing: 0.04em; white-space: nowrap; }

/* ── Notepad ─────────────────────────────────────────────────────────────────
   Sits to the right of the page so you can read and write at the same time,
   which is the whole point: the output is a new document, not an annotation. */
.notepad { width: 400px; flex: none; display: flex; flex-direction: column; min-height: 0;
  background: var(--chrome); border-left: 1px solid var(--border); }
.notepad[hidden] { display: none; }

.np-head { display: flex; align-items: center; gap: 3px; height: 38px; flex: none;
  padding: 0 8px 0 14px; border-bottom: 1px solid var(--border); background: var(--chrome-2); }
.np-head b { font-size: 0.86rem; }
.np-spacer { flex: 1; }

.np-pick { display: flex; align-items: center; gap: 9px; padding: 9px 12px 0; }
.np-pick select { flex: 1; min-width: 0; background: var(--chrome); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px; padding: 5px 7px; font-size: 0.8rem; }
.np-pick select:focus { outline: none; border-color: var(--accent); }
.np-meta { font-size: 0.72rem; color: var(--faint); white-space: nowrap; }
.np-saved { color: var(--green); }

.np-title { margin: 9px 12px 0; padding: 7px 10px; background: var(--chrome);
  border: 1px solid var(--border); border-radius: 4px; font-size: 0.92rem; font-weight: 600;
  color: var(--text); user-select: text; }
.np-title:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 2px var(--accent-soft); }

.np-tools { display: flex; align-items: center; gap: 2px; flex-wrap: wrap;
  padding: 9px 12px; border-bottom: 1px solid var(--border-soft); }
.np-t { background: none; border: 1px solid transparent; color: var(--dim); border-radius: 4px;
  min-width: 27px; height: 26px; padding: 0 6px; cursor: pointer; font-size: 0.82rem; }
.np-t:hover { background: var(--chrome-2); color: var(--text); border-color: var(--border); }
.np-tsep { width: 1px; height: 16px; background: var(--border); margin: 0 4px; }

.np-editor { flex: 1; overflow-y: auto; min-height: 0; padding: 14px 16px;
  font-size: 0.92rem; line-height: 1.75; color: var(--text); user-select: text; outline: none; }
.np-editor:empty::before { content: attr(data-placeholder); color: var(--faint);
  white-space: pre-wrap; font-size: 0.86rem; line-height: 1.8; }
.np-editor h2 { font-size: 1.05rem; margin: 16px 0 7px; }
.np-editor p { margin: 0 0 9px; }
.np-editor ul, .np-editor ol { margin: 0 0 10px; padding-left: 22px; }
.np-editor li { margin-bottom: 5px; }
.np-editor blockquote { margin: 10px 0; padding: 9px 13px; border-left: 3px solid var(--accent-line);
  background: var(--chrome-2); border-radius: 0 5px 5px 0; font-size: 0.88rem; color: var(--dim); }
.np-editor figure { margin: 12px 0; }
.np-editor img { max-width: 100%; border: 1px solid var(--border); border-radius: 4px;
  background: #fff; display: block; }
.np-editor .np-src, .np-editor figcaption { display: block; margin-top: 5px; font-size: 0.74rem;
  color: var(--faint); font-style: normal; }

.np-foot { display: flex; align-items: center; gap: 8px; flex: none; padding: 9px 12px;
  border-top: 1px solid var(--border); background: var(--chrome-2); }
.np-btn { background: var(--chrome); border: 1px solid var(--border); color: var(--text);
  border-radius: 4px; padding: 6px 12px; font-size: 0.79rem; font-weight: 600; cursor: pointer; }
.np-btn:hover { background: var(--chrome-3); }
.np-btn.np-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.np-btn.np-primary:hover { background: #2660c9; }

@media (max-width: 1100px) { .notepad { width: 330px; } }

/* Format picker for saving a note */
.np-menu { position: absolute; right: 12px; bottom: 50px; z-index: 30; width: 232px;
  background: var(--chrome); border: 1px solid var(--border); border-radius: 8px;
  box-shadow: var(--shadow); overflow: hidden; }
.np-menu button { display: block; width: 100%; text-align: left; background: none;
  border: none; border-bottom: 1px solid var(--border-soft); padding: 9px 13px; cursor: pointer; }
.np-menu button:last-child { border-bottom: none; }
.np-menu button:hover { background: var(--accent-soft); }
.np-menu b { display: block; font-size: 0.83rem; color: var(--text); font-weight: 600; }
.np-menu span { display: block; font-size: 0.72rem; color: var(--faint); margin-top: 1px; }
.notepad { position: relative; }

/* ── Movable, resizable panels ───────────────────────────────────────────── */
.pop-head { cursor: grab; user-select: none; }
.pop-dragging { cursor: grabbing; user-select: none; }
.pop-dragging .pop-head { cursor: grabbing; }
/* A sized panel scrolls its body rather than spilling out of its own frame. */
/* This sits after .pop[hidden] and has the same specificity, so without the
   guard below it wins and a resized panel can never be closed again — and the
   size is remembered, so the close button stays dead across restarts. */
.pop.pop-sized { display: flex; flex-direction: column; padding-bottom: 16px; }
.pop[hidden] { display: none !important; }
.pop.pop-sized { overflow: hidden; }
/* .calc-keys is excluded because this selector out-specifies the rule below and
   would otherwise pin the keypad to its full height, overflowing a small panel. */
.pop.pop-sized > *:not(.pop-head):not(.pop-grip):not(.calc-keys) { flex: 0 0 auto; min-height: 0; }
/* Shrunk to the minimum, the keypad is taller than the panel. Letting it scroll
   keeps every key reachable; clipping alone would hide the "=" key. */
.pop.pop-sized .calc-keys { flex: 1 1 auto; min-height: 0; overflow-y: auto; }
.pop.pop-sized .pop-note { display: none; }
.pop.pop-sized .calc-keys button { font-size: clamp(0.78rem, 1.4vh, 1.05rem); }
.pop-grip { position: absolute; right: 2px; bottom: 2px; width: 16px; height: 16px;
  cursor: nwse-resize; opacity: 0.5; }
.pop-grip::after { content: ""; position: absolute; right: 3px; bottom: 3px;
  width: 8px; height: 8px;
  border-right: 2px solid var(--faint); border-bottom: 2px solid var(--faint); }
.pop-grip:hover { opacity: 1; }

/* ── Clearer toolbar icons ───────────────────────────────────────────────── */
/* The icons were small and grey against white, which made the tools easy to
   miss entirely. Bigger, darker, and with a visible resting shape. */
.toolbar .tb-btn { font-size: 1.12rem; color: var(--text); height: 32px; min-width: 34px; }
.toolbar .tb-btn:hover:not(:disabled) { background: var(--accent-soft); color: var(--accent);
  border-color: var(--accent-line); }
.toolbar .tb-btn.tool { color: var(--accent); }
.toolbar .tb-btn.on { background: var(--accent); color: #fff; border-color: var(--accent); }
.tabs .tb-btn { font-size: 1.05rem; color: var(--text); }
.toolbar .tb-btn:disabled { color: var(--faint); opacity: 0.45; }

/* ── Library: backup and restore ─────────────────────────────────────────── */
.lib-backup { padding: 2px 0 10px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.lib-backup .side-act { margin-bottom: 6px; }
.lib-note { font-size: 0.72rem; color: var(--dim); line-height: 1.45; margin: 6px 2px 0; }

/* ── Flashcard revision session ──────────────────────────────────────────── */
.rev { padding: 2px; }
.rev-top { display: flex; align-items: center; justify-content: space-between;
  font-size: 0.72rem; color: var(--dim); margin-bottom: 8px; }
.rev-x { background: none; border: 0; color: var(--dim); font-size: 0.72rem; cursor: pointer; padding: 2px 4px; }
.rev-x:hover { color: var(--text); text-decoration: underline; }
.rev-q { background: var(--chrome-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 12px 11px; font-size: 0.88rem; font-weight: 600; color: var(--text); line-height: 1.45; }
.rev-a { background: var(--chrome-2); border: 1px solid var(--border); border-left: 3px solid var(--accent);
  border-radius: 6px; padding: 11px; margin-top: 7px; font-size: 0.82rem; color: var(--text); line-height: 1.5; }
.rev-btns { display: flex; gap: 6px; margin-top: 10px; }
.rev-b { flex: 1; display: flex; flex-direction: column; align-items: center; gap: 1px;
  border: 1px solid var(--border); background: var(--chrome-2); color: var(--text);
  border-radius: 6px; padding: 8px 4px; font-size: 0.78rem; font-weight: 600; cursor: pointer; }
.rev-b span { font-size: 0.64rem; font-weight: 500; color: var(--dim); }
.rev-b:hover { border-color: var(--accent); }
.rev-show { flex: 1; }
.rev-again:hover { border-color: #c0392b; }
.rev-easy:hover { border-color: #1e8e4e; }
.rev-src { font-size: 0.68rem; color: var(--dim); margin: 8px 2px 0; }
.rev-done { text-align: center; padding: 18px 8px; }
.rev-done b { display: block; font-size: 0.92rem; color: var(--text); margin-bottom: 4px; }
.rev-done p { font-size: 0.78rem; color: var(--dim); margin: 0 0 12px; }
.side-act-due { border-color: var(--accent); color: var(--accent); font-weight: 600; }

/* ── Formula sheet ───────────────────────────────────────────────────────── */
.fx-top { padding-bottom: 9px; border-bottom: 1px solid var(--border); margin-bottom: 10px; }
.fx-hint { font-size: 0.71rem; color: var(--dim); line-height: 1.45; margin: 7px 2px 0; }
.fx-subj { display: block; font-size: 0.7rem; color: var(--dim); margin: 9px 2px 0; }
.fx-subj input { display: block; width: 100%; margin-top: 3px; box-sizing: border-box;
  background: var(--chrome-2); border: 1px solid var(--border); border-radius: 5px;
  padding: 5px 7px; font: inherit; font-size: 0.78rem; color: var(--text); }
.fx-group { margin-bottom: 14px; }
.fx-ghead { display: flex; align-items: center; gap: 7px; margin-bottom: 7px; }
.fx-ghead b { font-size: 0.8rem; color: var(--text); flex: 1; overflow: hidden;
  text-overflow: ellipsis; white-space: nowrap; }
.fx-ghead span { font-size: 0.68rem; color: var(--dim); flex: none; }
.fx-print { flex: none; border: 1px solid var(--border); background: var(--chrome-2);
  color: var(--text); border-radius: 5px; padding: 3px 7px; font-size: 0.7rem; cursor: pointer; }
.fx-print:hover { border-color: var(--accent); color: var(--accent); }
.fx-item { background: var(--chrome-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px; margin-bottom: 7px; }
.fx-img { display: block; max-width: 100%; background: #fff; border-radius: 4px; }
.fx-text { font-size: 0.8rem; color: var(--text); line-height: 1.45; word-break: break-word; }
.fx-label { width: 100%; box-sizing: border-box; margin-top: 6px; background: var(--chrome);
  border: 1px solid var(--border); border-radius: 4px; padding: 4px 6px;
  font: inherit; font-size: 0.73rem; color: var(--text); }
.fx-meta { display: flex; align-items: center; gap: 6px; margin-top: 5px; font-size: 0.67rem; color: var(--dim); }
.fx-meta span { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.fx-go { flex: none; background: none; border: 0; color: var(--accent); font-size: 0.67rem;
  font-weight: 600; cursor: pointer; padding: 0; }
.fx-del { flex: none; background: none; border: 0; color: var(--dim); cursor: pointer; padding: 0 2px; }
.fx-del:hover { color: #c0392b; }

/* ── Study progress ──────────────────────────────────────────────────────── */
.pg-sum { padding-bottom: 11px; border-bottom: 1px solid var(--border); margin-bottom: 11px; }
.pg-bar { height: 7px; background: var(--chrome-2); border: 1px solid var(--border);
  border-radius: 4px; overflow: hidden; }
.pg-bar span { display: block; height: 100%; background: var(--accent); transition: width 0.3s; }
.pg-bar.small { height: 5px; margin-top: 6px; }
.pg-pct { font-size: 1.22rem; font-weight: 700; color: var(--text); margin-top: 7px; }
.pg-pct small { font-size: 0.7rem; font-weight: 500; color: var(--dim); display: block; margin-top: 1px; }
.pg-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 7px; margin-top: 10px; }
.pg-stats div { background: var(--chrome-2); border: 1px solid var(--border);
  border-radius: 6px; padding: 7px 8px; }
.pg-stats b { display: block; font-size: 0.92rem; color: var(--text); }
.pg-stats span { font-size: 0.66rem; color: var(--dim); }
.pg-eta { font-size: 0.73rem; color: var(--dim); line-height: 1.5; margin: 10px 2px 0; }
.pg-uhead { display: flex; align-items: center; gap: 6px; margin-bottom: 8px; }
.pg-uhead b { flex: 1; font-size: 0.8rem; color: var(--text); }
.pg-mini { flex: none; border: 1px solid var(--border); background: var(--chrome-2); color: var(--text);
  border-radius: 5px; padding: 3px 8px; font-size: 0.7rem; cursor: pointer; }
.pg-mini:hover { border-color: var(--accent); color: var(--accent); }
.pg-unit { background: var(--chrome-2); border: 1px solid var(--border); border-radius: 6px;
  padding: 8px; margin-bottom: 7px; }
.pg-unit.done { border-color: var(--accent); }
.pg-urow { display: flex; flex-wrap: wrap; align-items: center; gap: 4px; }
/* Auto-detected names run long ("3. Bending of beams · 4. Worked example"), so
   the name gets the full width and the page range sits under it. */
.pg-uname { flex: 1 0 100%; min-width: 0; margin-bottom: 2px; background: var(--chrome); border: 1px solid var(--border);
  border-radius: 4px; padding: 4px 6px; font: inherit; font-size: 0.76rem; color: var(--text); }
.pg-upage { flex: none; width: 46px; background: var(--chrome); border: 1px solid var(--border);
  border-radius: 4px; padding: 4px 3px; font: inherit; font-size: 0.73rem; color: var(--text);
  text-align: center; }
.pg-dash { flex: none; color: var(--dim); font-size: 0.72rem; }
.pg-udel { flex: none; background: none; border: 0; color: var(--dim); cursor: pointer; padding: 0 2px; }
.pg-udel:hover { color: #c0392b; }
.pg-umeta { display: flex; align-items: center; gap: 7px; margin-top: 5px; font-size: 0.67rem; color: var(--dim); }
.pg-umeta span { flex: 1; text-align: right; }
.pg-ugo { background: none; border: 0; color: var(--accent); font-size: 0.67rem;
  font-weight: 600; cursor: pointer; padding: 0; }

/* ── Recent files: removable ─────────────────────────────────────────────── */
.li-x { flex: none; background: none; border: 0; color: var(--faint); cursor: pointer;
  font-size: 0.8rem; line-height: 1; padding: 4px 5px; border-radius: 4px; opacity: 0; }
.lib-item:hover .li-x, .li-x:focus-visible { opacity: 1; }
.li-x:hover { color: #c0392b; background: rgba(192,57,43,0.1); }
.lib-clear { display: block; width: 100%; background: none; border: 1px solid var(--border);
  border-radius: 5px; color: var(--dim); font: inherit; font-size: 0.72rem; padding: 5px;
  margin-bottom: 9px; cursor: pointer; }
.lib-clear:hover { color: #c0392b; border-color: #c0392b; }

/* ── Welcome screen: where the app comes from ────────────────────────────── */
.wel-promo { margin-top: 26px; padding: 15px 17px; text-align: left;
  background: var(--chrome-2); border: 1px solid var(--border); border-radius: 10px; }
.wp-head { display: flex; align-items: center; gap: 8px; margin-bottom: 7px; }
.wp-head b { font-size: 0.83rem; color: var(--text); }
.wel-promo p { margin: 0; font-size: 0.79rem; color: var(--dim); line-height: 1.65; }
.wel-promo p b { color: var(--text); font-weight: 600; }
.wp-links { display: flex; flex-wrap: wrap; gap: 14px; margin-top: 10px; }
.wp-links a { font-size: 0.78rem; font-weight: 600; color: var(--accent);
  text-decoration: none; cursor: pointer; }
.wp-links a:hover { text-decoration: underline; }
