:root {
  color-scheme: light dark;
  --bg:       light-dark(#f6f6f7, #16171a);
  --panel:    light-dark(#ffffff, #1d1e22);
  --ink:      light-dark(#1a1a1c, #e8e8ea);
  --muted:    light-dark(#6a6a70, #93939b);
  --line:     light-dark(#e2e2e6, #2c2d33);
  --accent:   light-dark(#2f6fed, #6f9cff);
  --accent-soft: light-dark(#e8effd, #1e2a44);
  --mark:     light-dark(#ffe9a8, #6a5a1e);
  --mark-live: light-dark(#ffd24d, #b08c1a);
  --radius: 10px;
}

* { box-sizing: border-box; }
/* An author `display:` rule outranks the UA sheet's [hidden]{display:none},
   so elements styled as flex would stay visible when hidden. */
[hidden] { display: none !important; }
html, body { height: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--ink);
  font: 15px/1.55 -apple-system, system-ui, "Segoe UI", sans-serif;
}
button, input, textarea { font: inherit; color: inherit; }

/* ── buttons ─────────────────────────────────────────────── */
.btn {
  border: 1px solid var(--line); background: var(--panel); color: var(--ink);
  padding: .4rem .7rem; border-radius: var(--radius); cursor: pointer;
  white-space: nowrap; transition: background .12s, border-color .12s;
}
.btn:hover:not(:disabled) { border-color: var(--accent); }
.btn:disabled { opacity: .4; cursor: default; }
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.ghost { background: transparent; border-color: transparent; }
.btn.ghost:hover { background: var(--accent-soft); }
/* Header toggles dim when their panel is closed. */
.btn.off { opacity: .5; }
.muted { color: var(--muted); font-size: .85em; }
.spacer { flex: 1; }
.empty, .hint { color: var(--muted); padding: 1rem; }

/* ── library panel ──────────────────────────────────────── */
.library-panel {
  width: var(--lib-w, 300px); flex: 0 0 auto; min-width: 0; overflow: auto;
  display: flex; flex-direction: column; gap: .6rem; padding: .8rem;
  border-right: 1px solid var(--line); background: var(--panel);
}
body.lib-hidden .library-panel { display: none; }

.lib-toggle {
  position: absolute; left: var(--lib-w, 300px); top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 62px; padding: 0;
  border: 1px solid var(--line); border-left: none;
  border-radius: 0 var(--radius) var(--radius) 0;
  background: var(--panel); color: var(--muted);
  cursor: pointer; z-index: 20; font-size: .75rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: left .18s ease, color .12s, background .12s;
}
.lib-toggle:hover { color: var(--ink); background: var(--accent-soft); }
.lib-toggle::before { content: "\27E8"; }
body.lib-hidden .lib-toggle { left: 0; }
body.lib-hidden .lib-toggle::before { content: "\27E9"; }

.lib-head { display: flex; align-items: center; gap: .5rem; }
.lib-head h2 { font-size: 1rem; margin: 0; flex: 1; }
.btn.sm { padding: .25rem .55rem; font-size: .8rem; }
#lib-search {
  padding: .4rem .6rem; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--bg); width: 100%;
}
.book-list { display: flex; flex-direction: column; gap: .5rem; }
.card {
  background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .55rem .65rem; cursor: pointer;
  display: flex; flex-direction: column; gap: .2rem;
}
.card:hover { border-color: var(--accent); }
.card.current { border-color: var(--accent); background: var(--accent-soft); }
.card h3 { margin: 0; font-size: .88rem; line-height: 1.3; }
.card .meta { color: var(--muted); font-size: .75rem; }
.card .row { display: flex; gap: .5rem; align-items: center; }
.card .del {
  margin-left: auto; border: none; background: none; color: var(--muted);
  cursor: pointer; padding: .1rem .3rem; border-radius: 6px;
}
.card .del:hover { background: var(--accent-soft); color: var(--ink); }
.lib-results { display: flex; flex-direction: column; gap: .4rem; }

/* ── reader shell ────────────────────────────────────────── */
#reader { display: flex; flex-direction: column; height: 100vh; }
.bar {
  display: flex; align-items: center; gap: .5rem; padding: .5rem .75rem;
  border-bottom: 1px solid var(--line); background: var(--panel); flex-wrap: wrap;
}
.bar strong { max-width: 30ch; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.nav { display: flex; align-items: center; gap: .3rem; }
.center-tools { display: flex; align-items: center; gap: .5rem; }
#page-input {
  width: 4.2rem; text-align: center; padding: .3rem;
  border: 1px solid var(--line); border-radius: 8px; background: var(--bg);
}
.split { flex: 1; display: flex; min-height: 0; }

/* ── viewer ──────────────────────────────────────────────── */
.viewer:empty::after,
#pages:empty::after {
  content: "Soldan bir kitap seç ya da PDF ekle.";
  display: block; text-align: center; padding: 4rem 1rem;
  color: light-dark(#efefef, #6a6a72); font-size: .95rem;
}
.viewer { flex: 1; overflow: auto; background: light-dark(#8b8b90, #0e0f11); padding: 1rem; }
#pages {
  /* "safe" centring: once a zoomed page is wider than the viewport it aligns to
     the start instead of overflowing off the left edge, which is what made the
     anchored point drift sideways. */
  display: flex; flex-direction: column; align-items: safe center; gap: 1rem;
  /* No transition: the preview follows the wheel directly, and a tween here
     would lag behind and then snap when the crisp render swaps in. */
  will-change: transform;
}
.page-wrap { position: relative; box-shadow: 0 2px 12px rgba(0,0,0,.35); background: #fff; }
.page-wrap canvas { display: block; }
.page-num {
  position: absolute; top: 4px; right: 8px; font-size: .7rem;
  color: #666; background: rgba(255,255,255,.85); padding: 0 .35rem; border-radius: 4px;
}
.text-layer {
  position: absolute; inset: 0; overflow: hidden; opacity: .25; line-height: 1;
}
.text-layer span {
  position: absolute; white-space: pre; transform-origin: 0 0; color: transparent;
}
.text-layer ::selection { background: var(--accent); }
.mark {
  position: absolute; background: var(--mark); mix-blend-mode: multiply;
  border-radius: 2px; pointer-events: none;
}
.mark.live { background: var(--mark-live); animation: pulse 1.6s ease-out 2; }
@keyframes pulse { 0%,100% { opacity: .55 } 50% { opacity: 1 } }

/* ── sidebar ─────────────────────────────────────────────── */
.side {
  width: var(--side-w, 420px); flex: 0 0 auto; display: flex;
  flex-direction: column; border-left: 1px solid var(--line); background: var(--panel);
  min-width: 0; overflow: hidden;
}

/* Toggle tab living on the panel's left edge, sliding with it. */
.side-toggle {
  position: absolute; right: var(--side-w, 420px); top: 50%;
  transform: translateY(-50%);
  width: 18px; height: 62px; padding: 0;
  border: 1px solid var(--line); border-right: none;
  border-radius: var(--radius) 0 0 var(--radius);
  background: var(--panel); color: var(--muted);
  cursor: pointer; z-index: 20; font-size: .75rem; line-height: 1;
  display: flex; align-items: center; justify-content: center;
  transition: right .18s ease, color .12s, background .12s;
}
.side-toggle:hover { color: var(--ink); background: var(--accent-soft); }
.side-toggle::before { content: "⟩"; }
body.side-hidden .side-toggle { right: 0; }
body.side-hidden .side-toggle::before { content: "⟨"; }
.split { position: relative; }

/* Drag handle between the page and the panel. */
.grip {
  flex: 0 0 6px; cursor: col-resize; background: transparent;
  border-left: 1px solid var(--line);
}
.grip:hover, body.dragging .grip { background: var(--accent); }
body.dragging { cursor: col-resize; user-select: none; }

/* Collapsed states — the PDF takes the room back. */
body.side-hidden .side,
body.side-hidden .grip { display: none; }

.tabs { display: flex; border-bottom: 1px solid var(--line); }
.tab {
  flex: 1; padding: .6rem; background: none; border: none; cursor: pointer;
  color: var(--muted); border-bottom: 2px solid transparent;
}
.tab.active { color: var(--ink); border-bottom-color: var(--accent); }
.pane { display: none; flex: 1; min-height: 0; flex-direction: column; }
.pane.active { display: flex; }

.messages { flex: 1; overflow: auto; padding: .9rem; display: flex; flex-direction: column; gap: .8rem; }
.msg { max-width: 100%; }
.msg .who { font-size: .72rem; color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.msg .body { margin-top: .2rem; overflow-wrap: anywhere; }
/* The user's own text is literal — their line breaks should survive. The
   assistant's is rendered Markdown, so it lays itself out. */
.msg.user .body {
  white-space: pre-wrap;
  background: var(--accent-soft); padding: .5rem .7rem; border-radius: var(--radius);
}
.msg.assistant .body > :first-child { margin-top: 0; }
.msg.assistant .body > :last-child { margin-bottom: 0; }
.msg.assistant .body p { margin: .5rem 0; }
.msg.assistant .body h4 {
  margin: .8rem 0 .3rem; font-size: .95rem; font-weight: 650;
}
.msg.assistant .body ul,
.msg.assistant .body ol { margin: .4rem 0; padding-left: 1.3rem; }
.msg.assistant .body li { margin: .25rem 0; }
.msg.assistant .body code {
  background: light-dark(#eceef1, #24262c); padding: .05rem .3rem;
  border-radius: 4px; font-size: .9em;
}
.msg.assistant .body hr { border: none; border-top: 1px solid var(--line); margin: .7rem 0; }
.msg.assistant .body strong { font-weight: 650; }
.msg.assistant .body .math-block {
  margin: .6rem 0; overflow-x: auto; text-align: center;
}
.katex { font-size: 1.02em; }
.cite {
  display: inline-block; background: var(--accent-soft); color: var(--accent);
  border: 1px solid transparent; border-radius: 6px; padding: 0 .35rem;
  cursor: pointer; font-size: .85em; font-weight: 600;
}
.cite:hover { border-color: var(--accent); }
.thinking { color: var(--muted); font-style: italic; }

/* What the model went and did, before it answers. */
.tools { display: flex; flex-direction: column; gap: .25rem; margin-bottom: .5rem; }
.tool {
  border: 1px solid var(--line); border-radius: 8px;
  background: var(--bg); font-size: .8rem;
}
.tool > summary {
  display: flex; gap: .4rem; align-items: baseline; flex-wrap: wrap;
  padding: .3rem .5rem; cursor: pointer; list-style: none; color: var(--muted);
}
.tool > summary::-webkit-details-marker { display: none; }
.tool .ico { flex: 0 0 auto; }
/* Every flex child needs min-width:0 (or a fixed basis) or a long nowrap sibling
   squeezes the others to one character wide and the label renders vertically. */
.tool .lbl { flex: 0 0 auto; white-space: nowrap; color: var(--ink); }
.tool .arg {
  flex: 1 1 6rem; min-width: 0;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool .state {
  flex: 1 1 100%; min-width: 0; color: var(--muted); font-size: .75rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.tool.running { border-color: var(--accent); }
.tool.running .state::after { content: ''; animation: dots 1.2s steps(4) infinite; }
@keyframes dots { to { content: '...'; } }
.tool.with-image .ico::after { content: '🖼'; margin-left: .15rem; }
.tool .out {
  padding: .4rem .6rem; border-top: 1px solid var(--line);
  font-family: ui-monospace, monospace; font-size: .74rem;
  white-space: pre-wrap; color: var(--muted); max-height: 180px; overflow: auto;
}

.composer { display: flex; gap: .5rem; padding: .7rem; border-top: 1px solid var(--line); }
.composer.col { flex-direction: column; }
.composer-actions { display: flex; flex-direction: column; gap: .35rem; }
.web-toggle { font-size: .78rem; padding: .25rem .5rem; color: var(--muted); }
.web-toggle.on {
  background: var(--accent); border-color: var(--accent); color: #fff;
}
.web-card {
  position: fixed; z-index: 60; max-width: 340px;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .6rem .7rem;
  box-shadow: 0 6px 24px rgba(0,0,0,.3); font-size: .82rem;
}
.web-card b { display: block; margin-bottom: .2rem; }
.web-card .url {
  color: light-dark(#1a7f42, #6ee7a0); font-size: .75rem;
  overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.web-card .snip {
  margin-top: .35rem; color: var(--muted);
  display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical;
  overflow: hidden;
}
.web-card .hint { margin-top: .4rem; font-size: .72rem; color: var(--muted); }
.cite-card { max-width: 420px; }
.cite-card .crop:empty { display: none; }
.cite-card .crop img {
  display: block; max-width: 100%; max-height: 240px;
  border: 1px solid var(--line); border-radius: 6px; background: #fff;
}

a.webref { text-decoration: none; cursor: pointer; }
a.webref:hover { outline: 1px solid currentColor; }

.msg.assistant .body .webref {
  display: inline-block; background: light-dark(#e9f7ee, #14301f);
  color: light-dark(#1a7f42, #6ee7a0); border-radius: 6px; padding: 0 .35rem;
  font-size: .85em; font-weight: 600;
}

.composer textarea {
  flex: 1; resize: vertical; padding: .5rem .6rem; border: 1px solid var(--line);
  border-radius: var(--radius); background: var(--bg);
}

.list { flex: 1; overflow: auto; padding: .7rem; display: flex; flex-direction: column; gap: .6rem; }
.item {
  border: 1px solid var(--line); border-radius: var(--radius); padding: .6rem .7rem;
  background: var(--bg); cursor: pointer;
}
.item:hover { border-color: var(--accent); }
.item .top { display: flex; align-items: center; gap: .5rem; }
.item .quote { color: var(--muted); font-size: .85rem; border-left: 2px solid var(--line); padding-left: .5rem; margin-top: .3rem; }
.item .x { margin-left: auto; border: none; background: none; color: var(--muted); cursor: pointer; }

/* Region selection: drag a box over the page. */
body.region-mode .viewer { cursor: crosshair; }
body.region-mode .text-layer { pointer-events: none; }
#region-btn.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.region-box {
  position: absolute; border: 2px dashed var(--accent);
  background: rgba(47,111,237,.12); pointer-events: none; z-index: 6;
}
.pinned .pin-thumb {
  max-width: 84px; max-height: 60px; border-radius: 4px;
  border: 1px solid var(--line); flex: 0 0 auto;
}

/* Selection action bar, floating beside the highlighted text. */
.sel-menu {
  position: absolute; z-index: 45; display: flex; gap: .3rem;
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .3rem;
  box-shadow: 0 4px 16px rgba(0,0,0,.28);
}

/* One-tap questions about the page in front of you. */
/* Wrap rather than scroll: a suggestion you can only half-see is no suggestion. */
.quick {
  display: flex; flex-wrap: wrap; gap: .35rem; padding: .5rem .7rem 0;
}
.chip {
  border: 1px solid var(--line); background: var(--bg); color: var(--muted);
  border-radius: 999px; padding: .25rem .65rem; font-size: .8rem;
  cursor: pointer; text-align: left; line-height: 1.35;
  max-width: 100%; overflow-wrap: anywhere;
}
.chip:hover { border-color: var(--accent); color: var(--ink); }
.chip .katex { font-size: .95em; }
.chip strong, .chip em { font-weight: inherit; font-style: inherit; }

.queued {
  margin: 0 .7rem; padding: .3rem .5rem; font-size: .78rem;
  color: var(--muted); border: 1px dashed var(--line); border-radius: 8px;
}

/* The passage you pinned, sitting just above the composer. */
.pinned {
  display: flex; align-items: flex-start; gap: .5rem;
  margin: 0 .7rem; padding: .45rem .6rem;
  background: var(--accent-soft); border-left: 3px solid var(--accent);
  border-radius: 0 var(--radius) var(--radius) 0; font-size: .85rem;
}
.pinned .pin-page { color: var(--accent); font-weight: 650; white-space: nowrap; }
.pinned .pin-text {
  flex: 1; color: var(--ink); opacity: .85;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical;
  overflow: hidden;
}
.pinned .x { border: none; background: none; color: var(--muted); cursor: pointer; }
.pinned .x:hover { color: var(--ink); }

.msg.user .body .qref {
  display: block; border-left: 2px solid var(--accent);
  padding-left: .5rem; margin-bottom: .35rem; opacity: .75; font-size: .9em;
}

.toast {
  position: fixed; bottom: 1.2rem; left: 50%; transform: translateX(-50%);
  background: var(--ink); color: var(--bg); padding: .55rem 1rem;
  border-radius: 20px; font-size: .9rem; z-index: 50;
}

@media (max-width: 880px) {
  .split { flex-direction: column; }
  .side {
    width: auto; border-left: none; border-top: 1px solid var(--line); height: 45vh;
  }
  .grip { display: none; }
}

.who { display: inline-flex; align-items: center; gap: .5rem; font-size: .82rem; color: var(--muted); }
.who a { color: var(--muted); text-decoration: none; font-size: 1rem; }
.who a:hover { color: var(--accent); }

/* ── sign in / invite ────────────────────────────────────── */
.auth-page {
  display: grid; place-items: center; min-height: 100vh;
  background: var(--bg); padding: 1rem;
}
.auth-card {
  width: min(380px, 100%); background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px; padding: 1.8rem;
  box-shadow: 0 8px 40px rgba(0,0,0,.12);
}
.auth-card h1 { margin: 0; font-size: 1.5rem; }
.auth-card .sub { color: var(--muted); margin: .3rem 0 1.4rem; font-size: .9rem; }
.auth-card label { display: block; margin-bottom: .9rem; }
.auth-card label span {
  display: block; font-size: .8rem; color: var(--muted); margin-bottom: .3rem;
}
.auth-card input {
  width: 100%; padding: .55rem .7rem; background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius); outline: none;
}
.auth-card input:focus { border-color: var(--accent); }
.btn.wide { width: 100%; justify-content: center; padding: .55rem; }
.error {
  color: light-dark(#b3261e, #ff8a80); font-size: .85rem; margin: 0 0 .8rem;
}
.notice {
  color: var(--muted); font-size: .82rem; margin: 0 0 .8rem;
}
.alt { text-align: center; margin: 1rem 0 0; font-size: .85rem; }
.alt a { color: var(--accent); text-decoration: none; }
.alt a:hover { text-decoration: underline; }

/* ── admin ───────────────────────────────────────────────── */
.admin-page { background: var(--bg); }
.admin-bar {
  display: flex; align-items: center; gap: 1rem; padding: .7rem 1.2rem;
  border-bottom: 1px solid var(--line); background: var(--panel);
}
.admin-bar h1 { font-size: 1.1rem; margin: 0; }
.admin-main {
  max-width: 1000px; margin: 0 auto; padding: 1.5rem 1.2rem;
  display: flex; flex-direction: column; gap: 1.2rem;
}
.panel {
  background: var(--panel); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 1.1rem;
}
.panel h2 { margin: 0 0 .8rem; font-size: 1rem; }
.tiles { display: flex; flex-wrap: wrap; gap: .6rem; }
.tile {
  flex: 1 1 110px; background: var(--bg); border: 1px solid var(--line);
  border-radius: var(--radius); padding: .7rem; text-align: center;
}
.tile .v { font-size: 1.35rem; font-weight: 650; }
.tile .l { font-size: .74rem; color: var(--muted); text-transform: uppercase; letter-spacing: .03em; }
.tile.ok .v { color: #2ecc71; }
.tile.bad .v { color: #e74c3c; }

.table { width: 100%; border-collapse: collapse; font-size: .87rem; margin-top: .6rem; }
.table th, .table td {
  text-align: left; padding: .45rem .5rem; border-bottom: 1px solid var(--line);
}
.table th { font-size: .72rem; color: var(--muted); text-transform: uppercase; font-weight: 500; }
.table .actions { display: flex; gap: .35rem; justify-content: flex-end; }
.btn.sm { padding: .18rem .5rem; font-size: .78rem; }
.btn.danger { color: light-dark(#b3261e, #ff8a80); }
.btn.danger:hover { border-color: currentColor; }
.tag {
  font-size: .68rem; background: var(--accent-soft); color: var(--accent);
  padding: 0 .35rem; border-radius: 4px; margin-left: .35rem;
}
.tag.warn {
  background: light-dark(#fff3cd, #4a3a10); color: light-dark(#8a6d00, #ffd77a);
}
.table .email { font-size: .8rem; color: var(--muted); }
.status.open { color: light-dark(#1a7f42, #6ee7a0); }
.status.used { color: var(--muted); }

.row-form { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row-form input[type=text], .row-form input:not([type]), .row-form input[type=password] {
  flex: 1 1 12rem; padding: .45rem .6rem; background: var(--bg);
  border: 1px solid var(--line); border-radius: var(--radius);
}
.chk { display: inline-flex; align-items: center; gap: .3rem; font-size: .85rem; color: var(--muted); }
.invite-new { display: flex; gap: .5rem; margin-top: .7rem; }
.invite-new input {
  flex: 1; padding: .45rem .6rem; background: var(--accent-soft);
  border: 1px solid var(--accent); border-radius: var(--radius); font-size: .82rem;
}
.add-user { margin-top: .9rem; }
.add-user summary { cursor: pointer; color: var(--muted); font-size: .85rem; }
.add-user form { margin-top: .6rem; }

/* The honeypot must be reachable in the DOM but never perceivable: display:none
   is skipped by some form fillers, so it is moved off-screen instead. */
.hp {
  position: absolute; left: -9999px; top: auto;
  width: 1px; height: 1px; overflow: hidden;
}

/* ── onboarding / welcome cards ──────────────────────────── */
.onboard-overlay {
  position: fixed; inset: 0; z-index: 200;
  display: flex; align-items: center; justify-content: center;
  background: rgba(0,0,0,.45); padding: 1rem;
  backdrop-filter: blur(2px);
}
.onboard-card {
  width: min(440px, 100%); background: var(--panel);
  border: 1px solid var(--line); border-radius: 16px;
  box-shadow: 0 12px 48px rgba(0,0,0,.28);
  padding: 1.8rem 1.8rem 1.3rem; display: flex; flex-direction: column;
}
.onboard-body { text-align: center; min-height: 8.5rem; }
.onboard-emoji { font-size: 2.6rem; line-height: 1; margin-bottom: .7rem; }
.onboard-body h2 { margin: 0 0 .5rem; font-size: 1.25rem; }
.onboard-body p { margin: 0; color: var(--muted); line-height: 1.55; }
.onboard-dots { display: flex; gap: .4rem; justify-content: center; margin: 1.2rem 0; }
.onboard-dots span {
  width: 7px; height: 7px; border-radius: 999px;
  background: var(--line); transition: background .15s, width .15s;
}
.onboard-dots span.on { background: var(--accent); width: 18px; }
.onboard-actions { display: flex; flex-direction: column; gap: .9rem; }
.onboard-skipagain {
  display: flex; align-items: center; gap: .45rem;
  font-size: .82rem; color: var(--muted); cursor: pointer; user-select: none;
}
.onboard-skipagain input { cursor: pointer; }
.onboard-buttons { display: flex; justify-content: space-between; gap: .6rem; }
