/* iEdit — dark, calm, refined. Reading pane is a quiet page; chrome is minimal. */

:root {
  --bg: #0e0f12;
  --bg-1: #14161a;
  --bg-2: #1b1e24;
  --bg-3: #232830;
  --line: #2a2f38;
  --line-2: #363d48;
  --text: #e6e8eb;
  --text-2: #a4acb8;
  --text-3: #6c7480;
  --accent: #6ea8fe;
  --accent-fg: #08131f;
  --shadow: 0 10px 30px rgba(0,0,0,.5);
  --radius: 14px;
  --tap: 48px;
  --safe-t: env(safe-area-inset-top);
  --safe-b: env(safe-area-inset-bottom);
  --safe-l: env(safe-area-inset-left);
  --safe-r: env(safe-area-inset-right);
  --ui: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", system-ui, sans-serif;
  --serif: "Iowan Old Style", "Charter", "Palatino", Georgia, "Times New Roman", serif;
}

/* ---- light theme (warm paper, low-glare — easy for long reading) ---- */
:root[data-theme="light"] {
  --bg: #f3f1ea;       /* warm off-white paper, NOT bright white */
  --bg-1: #f9f7f0;     /* cards, gently raised */
  --bg-2: #eae5da;     /* inputs */
  --bg-3: #e2dccc;     /* chips / pressed */
  --line: #e5e0d2;     /* soft borders */
  --line-2: #d7d0be;
  --text: #40454b;     /* soft graphite — deliberately not near-black */
  --text-2: #6e727a;
  --text-3: #9d9789;
  --accent: #3f6ccb;
  --accent-fg: #ffffff;
  --shadow: 0 8px 24px rgba(70,60,40,.10);
}
:root[data-theme="light"] { color-scheme: light; }
:root[data-theme="light"] .btn.danger { color: #b23c34; border-color: #e4cabf; background: #f2e5df; }
:root[data-theme="light"] .saved.on { color: #2c8f5c; }
:root[data-theme="light"] .toolbar,
:root[data-theme="light"] .sheet,
:root[data-theme="light"] .modal-wrap .modal,
:root[data-theme="light"] .toast,
:root[data-theme="light"] .resume,
:root[data-theme="light"] .gdot { box-shadow: 0 8px 24px rgba(70,60,40,.12); }
:root[data-theme="light"] .doc :not(pre) > code,
:root[data-theme="light"] .doc pre { background: #ede8dd; }

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%;
  background: var(--bg); color: var(--text);
  font-family: var(--ui);
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
  overscroll-behavior: none;
}
body { overflow: hidden; }
#app { height: 100%; }
button { font-family: inherit; color: inherit; cursor: pointer; -webkit-user-select: none; user-select: none; }
input, textarea { font-family: inherit; font-size: 16px; } /* 16px avoids iOS focus-zoom */

.hidden { display: none !important; }
[hidden] { display: none !important; }

/* ---------- generic buttons ---------- */
.btn {
  min-height: var(--tap); padding: 0 18px; border-radius: 12px;
  border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text);
  font-size: 15px; font-weight: 550; display: inline-flex; align-items: center; gap: 8px;
  transition: background .12s, border-color .12s, transform .05s;
}
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--accent); border-color: var(--accent); color: var(--accent-fg); font-weight: 650; }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { color: var(--text); }
.btn.danger { color: #ff8a8a; border-color: #4a2a2f; background: #24171b; }
.btn.sm { min-height: 38px; padding: 0 13px; font-size: 14px; border-radius: 10px; }
.icon-btn {
  width: var(--tap); height: var(--tap); border-radius: 12px; display: grid; place-items: center;
  border: 1px solid transparent; background: transparent; color: var(--text-2);
}
.icon-btn:hover { color: var(--text); background: var(--bg-2); }
.icon-btn svg { width: 22px; height: 22px; }

/* ---------- login ---------- */
.auth {
  height: 100%; display: grid; place-items: center;
  padding: calc(var(--safe-t) + 20px) 20px calc(var(--safe-b) + 20px);
}
.auth-card {
  width: min(400px, 100%); background: var(--bg-1); border: 1px solid var(--line);
  border-radius: 20px; padding: 34px 28px; text-align: center;
}
.brand { display: flex; align-items: center; justify-content: center; gap: 12px; margin-bottom: 6px; }
.brand img { width: 40px; height: 40px; }
.brand h1 { font-size: 26px; margin: 0; letter-spacing: -.02em; }
.auth p { color: var(--text-2); font-size: 14px; margin: 4px 0 22px; }
.field {
  width: 100%; height: 52px; padding: 0 16px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--line-2); color: var(--text); font-size: 16px;
}
.field:focus { outline: none; border-color: var(--accent); }
.auth .btn { width: 100%; justify-content: center; margin-top: 14px; }
.auth .err { color: #ff8a8a; font-size: 14px; min-height: 20px; margin-top: 10px; }

/* ---------- library ---------- */
.lib { height: 100%; display: flex; flex-direction: column; }
.lib-head {
  display: flex; align-items: center; gap: 12px;
  padding: calc(var(--safe-t) + 16px) calc(var(--safe-r) + 20px) 16px calc(var(--safe-l) + 20px);
  border-bottom: 1px solid var(--line);
}
.lib-head h1 { font-size: 20px; margin: 0; letter-spacing: -.01em; flex: 1; }
.lib-head .logo { width: 26px; height: 26px; }
.lib-body { flex: 1; overflow: auto; padding: 18px calc(var(--safe-r) + 20px) calc(var(--safe-b) + 40px) calc(var(--safe-l) + 20px); }
.doc-grid { display: grid; gap: 12px; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); max-width: 1100px; margin: 0 auto; }
.doc-card {
  text-align: left; background: var(--bg-1); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 18px; display: flex; flex-direction: column; gap: 14px;
  min-height: 132px; transition: border-color .12s, transform .05s;
}
.doc-card:active { transform: scale(.99); }
.doc-card:hover { border-color: var(--line-2); }
.doc-card .t { font-size: 16.5px; font-weight: 600; line-height: 1.35; letter-spacing: -.01em; }
.doc-card .meta { color: var(--text-3); font-size: 12.5px; margin-top: 2px; }
.doc-card .foot { margin-top: auto; display: flex; align-items: center; gap: 10px; }
.ring { --p: 0; width: 34px; height: 34px; flex: none; border-radius: 50%;
  background: conic-gradient(var(--accent) calc(var(--p) * 1%), var(--bg-3) 0);
  display: grid; place-items: center; }
.ring::after { content: ""; width: 26px; height: 26px; border-radius: 50%; background: var(--bg-1); }
.ring span { position: absolute; font-size: 10px; color: var(--text-2); font-variant-numeric: tabular-nums; }
.pill-row { display: flex; flex-wrap: wrap; gap: 6px; }
.cpill { display: inline-flex; align-items: center; gap: 5px; font-size: 12px; color: var(--text-2);
  background: var(--bg-2); border: 1px solid var(--line); border-radius: 20px; padding: 3px 9px 3px 7px; }
.cpill i { width: 9px; height: 9px; border-radius: 50%; display: inline-block; }
.empty { text-align: center; color: var(--text-3); padding: 80px 20px; max-width: 420px; margin: 0 auto; }
.empty h2 { color: var(--text-2); font-weight: 600; }

/* ---------- reader ---------- */
.reader { height: 100%; display: flex; flex-direction: column; }
.r-head {
  display: flex; align-items: center; gap: 6px;
  padding: calc(var(--safe-t) + 8px) calc(var(--safe-r) + 10px) 8px calc(var(--safe-l) + 6px);
  border-bottom: 1px solid var(--line); background: var(--bg); position: relative; z-index: 5;
}
.r-title { flex: 1; min-width: 0; }
.r-title .t { font-size: 15px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.r-title .s { font-size: 12px; color: var(--text-3); display: flex; align-items: center; gap: 8px; }
.saved { color: var(--text-3); font-size: 11.5px; transition: opacity .3s; }
.saved.on { color: #59c98a; }

/* filter chips */
.filters { display: flex; gap: 7px; padding: 9px calc(var(--safe-r) + 14px) 9px calc(var(--safe-l) + 14px);
  overflow-x: auto; border-bottom: 1px solid var(--line); background: var(--bg); scrollbar-width: none; }
.filters::-webkit-scrollbar { display: none; }
.chip {
  flex: none; height: 34px; padding: 0 12px 0 10px; border-radius: 18px; font-size: 13px; font-weight: 550;
  border: 1px solid var(--line-2); background: var(--bg-1); color: var(--text-2);
  display: inline-flex; align-items: center; gap: 7px;
}
.chip i { width: 11px; height: 11px; border-radius: 50%; display: inline-block; }
.chip .n { font-variant-numeric: tabular-nums; color: var(--text-3); }
.chip.on { color: var(--text); border-color: var(--line-2); background: var(--bg-3); }
.chip.on .n { color: var(--text); }

/* scroll + document */
.scroll { position: relative; flex: 1; overflow: auto; overscroll-behavior: contain; }
.doc {
  font-family: var(--serif); color: var(--text);
  font-size: 19px; line-height: 1.72;
  max-width: 720px; margin: 0 auto;
  padding: 34px calc(var(--safe-r) + 30px) 40vh calc(var(--safe-l) + 30px);
  -webkit-user-select: text; user-select: text;
  -webkit-touch-callout: default;
}
.doc h1, .doc h2, .doc h3, .doc h4 { font-family: var(--ui); line-height: 1.3; letter-spacing: -.015em; margin: 1.6em 0 .5em; }
.doc h1 { font-size: 26px; } .doc h2 { font-size: 22px; } .doc h3 { font-size: 19px; }
.doc p { margin: 0 0 1.05em; }
.doc blockquote { margin: 1em 0; padding: 4px 0 4px 18px; border-left: 3px solid var(--line-2); color: var(--text-2); }
.doc pre { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 14.5px; background: var(--bg-1);
  border: 1px solid var(--line); border-radius: 10px; padding: 14px; overflow-x: auto; }
.doc code { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: .88em; }
.doc :not(pre) > code { background: var(--bg-2); padding: 1px 5px; border-radius: 5px; }
.doc a { color: var(--accent); text-decoration: none; }
.doc img { max-width: 100%; border-radius: 8px; }
.doc hr { border: none; border-top: 1px solid var(--line); margin: 2em 0; }
.doc table { border-collapse: collapse; width: 100%; font-size: 16px; }
.doc th, .doc td { border: 1px solid var(--line); padding: 6px 10px; text-align: left; }

/* the marks (DOM-wrap spans). Colour + texture supplied inline via --c / data-deco */
.anno { border-radius: 3px; cursor: pointer; -webkit-user-select: text; }
.anno[data-deco="highlight"] { background: var(--cs); box-shadow: 0 0 0 1px color-mix(in srgb, var(--c) 30%, transparent); }
.anno[data-deco="strike"] { text-decoration: line-through; text-decoration-color: var(--c); text-decoration-thickness: 2px; color: color-mix(in srgb, var(--c) 60%, var(--text)); }
.anno[data-deco="underline"] { text-decoration: underline; text-decoration-color: var(--c); text-decoration-thickness: 2px; text-underline-offset: 3px; }
.anno[data-note]::after { content: ""; }
.anno.is-note-badge { }
.anno.is-done { opacity: .45; }
.anno.flash { animation: flash .9s ease; }
@keyframes flash { 0%,100% { background: var(--cs); } 40% { background: color-mix(in srgb, var(--c) 55%, transparent); } }

/* margin gutter */
.gutter { position: absolute; top: 0; width: 14px; pointer-events: none; z-index: 2; }
.gdot { position: absolute; right: 4px; width: 8px; height: 8px; border-radius: 50%;
  background: var(--c); pointer-events: auto; transform: translateY(-50%); opacity: .85; }
.gdot:active { transform: translateY(-50%) scale(1.4); }

/* resume pill */
.resume { position: absolute; left: 50%; bottom: calc(var(--safe-b) + 18px); transform: translateX(-50%);
  z-index: 6; background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text);
  border-radius: 22px; padding: 10px 18px; font-size: 13.5px; font-weight: 550; box-shadow: 0 8px 24px rgba(0,0,0,.4);
  display: inline-flex; gap: 8px; align-items: center; }

/* ---------- floating selection toolbar ---------- */
.toolbar {
  position: fixed; z-index: 50; display: flex; align-items: center; gap: 4px;
  background: var(--bg-3); border: 1px solid var(--line-2); border-radius: 14px;
  padding: 5px; box-shadow: 0 10px 30px rgba(0,0,0,.5);
}
.toolbar button { width: 44px; height: 44px; border-radius: 10px; border: none; background: transparent;
  display: grid; place-items: center; position: relative; }
.toolbar button:active { background: var(--bg-2); }
.toolbar .swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid var(--c); background: var(--cs); }
.toolbar .sep { width: 1px; height: 26px; background: var(--line-2); margin: 0 2px; }
.toolbar button .lbl { position: absolute; bottom: 2px; font-size: 8px; color: var(--text-3); }

/* ---------- bottom sheet ---------- */
.scrim { position: fixed; inset: 0; background: rgba(0,0,0,.4); z-index: 40; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 45;
  background: var(--bg-1); border-top: 1px solid var(--line-2);
  border-radius: 20px 20px 0 0; padding: 8px 20px calc(var(--safe-b) + 20px);
  max-height: 82vh; overflow: auto; box-shadow: 0 -10px 40px rgba(0,0,0,.5);
  animation: rise .18s ease;
}
@keyframes rise { from { transform: translateY(30px); opacity: .6; } to { transform: none; opacity: 1; } }
.sheet .grab { width: 40px; height: 4px; border-radius: 3px; background: var(--line-2); margin: 6px auto 14px; }
.sheet .quote { font-family: var(--serif); font-size: 17px; line-height: 1.6; color: var(--text);
  border-left: 3px solid var(--c); padding: 4px 0 4px 14px; margin-bottom: 16px; max-height: 30vh; overflow: auto; }
.sheet .loc { font-size: 12px; color: var(--text-3); margin-bottom: 16px; }
.sheet .lbl-row { font-size: 12px; color: var(--text-2); text-transform: uppercase; letter-spacing: .05em; margin: 4px 0 8px; }
.act-grid { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 18px; }
.act-opt { height: 40px; padding: 0 14px 0 12px; border-radius: 20px; font-size: 14px; font-weight: 550;
  border: 1px solid var(--line-2); background: var(--bg-2); color: var(--text-2);
  display: inline-flex; align-items: center; gap: 8px; }
.act-opt i { width: 12px; height: 12px; border-radius: 50%; background: var(--c); }
.act-opt.on { color: var(--text); background: var(--bg-3); border-color: var(--c); }
.note-area { width: 100%; min-height: 96px; resize: vertical; padding: 12px 14px; border-radius: 12px;
  background: var(--bg-2); border: 1px solid var(--line-2); color: var(--text); font-size: 16px; line-height: 1.5; }
.note-area:focus { outline: none; border-color: var(--accent); }
.chips-canned { display: flex; flex-wrap: wrap; gap: 7px; margin: 10px 0 18px; }
.canned { height: 34px; padding: 0 12px; border-radius: 17px; font-size: 13px; color: var(--text-2);
  background: var(--bg-2); border: 1px solid var(--line); }
.sheet-foot { display: flex; align-items: center; gap: 10px; margin-top: 6px; }
.sheet-foot .spacer { flex: 1; }
.done-toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 14px; color: var(--text-2); }
.done-toggle input { width: 20px; height: 20px; accent-color: var(--accent); }

/* ---------- modal (upload / report / settings) ---------- */
.modal-wrap { position: fixed; inset: 0; z-index: 60; display: grid; place-items: center; padding: 20px; }
.modal-wrap .scrim2 { position: absolute; inset: 0; background: rgba(0,0,0,.55); }
.modal { position: relative; width: min(760px, 100%); max-height: 88vh; overflow: auto;
  background: var(--bg-1); border: 1px solid var(--line-2); border-radius: 18px;
  padding: 22px calc(var(--safe-r) + 22px) calc(var(--safe-b) + 22px) calc(var(--safe-l) + 22px); }
.modal h2 { margin: 0 0 4px; font-size: 20px; letter-spacing: -.01em; }
.modal .sub { color: var(--text-3); font-size: 13px; margin-bottom: 18px; }
.modal .row { display: flex; gap: 10px; align-items: center; margin-bottom: 12px; flex-wrap: wrap; }
.modal label.lab { font-size: 13px; color: var(--text-2); display: block; margin: 12px 0 6px; }
.textarea-lg { width: 100%; min-height: 220px; padding: 14px; border-radius: 12px; background: var(--bg-2);
  border: 1px solid var(--line-2); color: var(--text); font-size: 15px; line-height: 1.55;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace; resize: vertical; }
.textarea-lg:focus, .field:focus { outline: none; border-color: var(--accent); }
.seg { display: inline-flex; background: var(--bg-2); border: 1px solid var(--line-2); border-radius: 10px; padding: 3px; }
.seg button { min-height: 36px; padding: 0 14px; border-radius: 8px; border: none; background: transparent; color: var(--text-2); font-size: 14px; }
.seg button.on { background: var(--bg-3); color: var(--text); }
.modal-foot { display: flex; gap: 10px; justify-content: flex-end; margin-top: 20px; }
.report-pre { white-space: pre-wrap; font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-size: 13px; line-height: 1.55; background: var(--bg); border: 1px solid var(--line); border-radius: 12px;
  padding: 16px; max-height: 46vh; overflow: auto; color: var(--text-2); }

/* palette editor */
.pal-row { display: flex; align-items: center; gap: 10px; margin-bottom: 10px; }
.pal-row input[type=color] { width: 42px; height: 42px; border: none; background: none; padding: 0; border-radius: 10px; }
.pal-row input[type=text] { flex: 1; height: 42px; padding: 0 12px; border-radius: 10px; background: var(--bg-2); border: 1px solid var(--line-2); color: var(--text); }
.pal-row select { height: 42px; border-radius: 10px; background: var(--bg-2); color: var(--text); border: 1px solid var(--line-2); padding: 0 8px; }

/* toast */
.toast { position: fixed; left: 50%; bottom: calc(var(--safe-b) + 24px); transform: translateX(-50%) translateY(20px);
  background: var(--bg-3); border: 1px solid var(--line-2); color: var(--text); border-radius: 12px;
  padding: 11px 16px; font-size: 14px; z-index: 80; opacity: 0; transition: opacity .2s, transform .2s;
  display: flex; align-items: center; gap: 12px; box-shadow: 0 10px 30px rgba(0,0,0,.5); }
.toast.on { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast button { color: var(--accent); background: none; border: none; font-weight: 650; font-size: 14px; }

.spinner { width: 20px; height: 20px; border: 2px solid var(--line-2); border-top-color: var(--accent); border-radius: 50%; animation: spin 0.7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.center-load { height: 100%; display: grid; place-items: center; }
