:root {
  --bg: #f5f1ea;
  --surface: #fffdf9;
  --surface-2: #ece6db;
  --text: #1f1b16;
  --muted: #7a7065;
  --line: #e3dbcd;
  --brand: #1f4d3f;
  --brand-ink: #ffffff;
  --brand-soft: #dde9e3;
  --accent: #c8623d;
  --danger: #b42318;
  --shadow: 0 1px 2px rgba(40, 30, 20, .06), 0 6px 20px rgba(40, 30, 20, .08);
  --radius: 16px;
  --safe-t: env(safe-area-inset-top, 0px);
  --safe-b: env(safe-area-inset-bottom, 0px);
  --serif: "Iowan Old Style", "Palatino Linotype", Palatino, Georgia, "Times New Roman", serif;
  --sans: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14120f;
    --surface: #1f1c18;
    --surface-2: #2a2621;
    --text: #efe8dd;
    --muted: #a39887;
    --line: #36302a;
    --brand: #7fc4a8;
    --brand-ink: #0d1f19;
    --brand-soft: #1d3129;
    --accent: #e48a66;
    --danger: #f97066;
    --shadow: 0 1px 2px rgba(0, 0, 0, .3), 0 6px 20px rgba(0, 0, 0, .3);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.45 var(--sans);
  -webkit-font-smoothing: antialiased;
}
button, input, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
svg { display: block; }

#app { max-width: 480px; margin: 0 auto; min-height: 100%; }

/* ---------- Ortak ---------- */
.icon-btn {
  width: 44px; height: 44px; border: 0; border-radius: 12px; background: transparent;
  display: grid; place-items: center; color: inherit; flex: none;
}
.icon-btn:active { background: var(--surface-2); }
.icon-btn svg { width: 22px; height: 22px; }

.btn {
  height: 48px; padding: 0 20px; border: 0; border-radius: 12px; font-weight: 600;
  background: var(--brand); color: var(--brand-ink); display: inline-flex; align-items: center;
  justify-content: center; gap: 8px;
}
.btn:active { opacity: .85; }
.btn:disabled { opacity: .5; }
.btn.block { width: 100%; }
.btn svg { width: 18px; height: 18px; flex: none; }
.btn.ghost { background: var(--surface-2); color: var(--text); }
.btn.danger { background: transparent; color: var(--danger); border: 1px solid currentColor; }

.field { display: block; margin-bottom: 14px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; height: 48px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--surface); outline: none; font-size: 16px;
}
.input:focus { border-color: var(--brand); }

/* ---------- Giriş ---------- */
.login { min-height: 100vh; min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px; }
.login-card { width: 100%; max-width: 360px; text-align: center; }
.login-card img { width: 72px; height: 72px; border-radius: 18px; margin: 0 auto 16px; display: block; }
.login-card h1 { font: 600 30px/1.2 var(--serif); margin: 0 0 6px; }
.login-card p { color: var(--muted); margin: 0 0 24px; }
.login-card .err { color: var(--danger); font-size: 14px; min-height: 20px; margin: 8px 0 0; }

/* ---------- Kütüphane ---------- */
.topbar {
  position: sticky; top: 0; z-index: 5; background: var(--bg);
  padding: calc(var(--safe-t) + 8px) 8px 8px 16px; display: flex; align-items: center; gap: 4px;
}
.topbar h1 { font: 600 28px/1.1 var(--serif); margin: 0; flex: 1; }

.search { display: block; margin: 0 16px 16px; position: relative; }
.search svg { position: absolute; left: 14px; top: 50%; width: 18px; height: 18px; transform: translateY(-50%); color: var(--muted); }
.search .input { padding-left: 42px; background: var(--surface-2); border-color: transparent; }

.section-title { font-size: 13px; font-weight: 600; letter-spacing: .04em; text-transform: uppercase; color: var(--muted); margin: 8px 16px 10px; }

.continue {
  margin: 0 16px 24px; padding: 14px; border-radius: var(--radius); background: var(--surface);
  box-shadow: var(--shadow); display: flex; gap: 14px; align-items: center; border: 0; width: calc(100% - 32px); text-align: left;
}
.continue .cover { width: 64px; flex: none; }
.continue .info { flex: 1; min-width: 0; }
.continue .t { font: 600 18px/1.25 var(--serif); display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.continue .a { color: var(--muted); font-size: 14px; margin: 2px 0 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.continue .row { display: flex; align-items: center; gap: 10px; font-size: 13px; color: var(--muted); }
.continue .bar { flex: 1; }

.bar { height: 4px; border-radius: 4px; background: var(--surface-2); overflow: hidden; }
.bar i { display: block; height: 100%; background: var(--brand); border-radius: 4px; }

.grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px 14px; padding: 0 16px 120px; }
@media (max-width: 340px) { .grid { grid-template-columns: repeat(2, 1fr); } }

.book { position: relative; min-width: 0; }
.book > button.open { border: 0; padding: 0; background: none; width: 100%; text-align: left; }
.book .t { font-size: 14px; font-weight: 600; line-height: 1.25; margin-top: 8px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.book .a { font-size: 12px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.book .bar { margin-top: 6px; height: 3px; }
.book .more {
  position: absolute; top: 4px; right: 4px; width: 32px; height: 32px; border-radius: 10px; border: 0;
  background: rgba(0, 0, 0, .45); color: #fff; display: grid; place-items: center; backdrop-filter: blur(4px);
}
.book .more svg { width: 18px; height: 18px; }
.book .done { position: absolute; left: 6px; top: 6px; background: var(--brand); color: var(--brand-ink); font-size: 11px; font-weight: 700; padding: 2px 7px; border-radius: 8px; }

.cover {
  aspect-ratio: 2 / 3; border-radius: 6px; overflow: hidden; background: var(--surface-2);
  box-shadow: 0 1px 2px rgba(0,0,0,.12), 0 4px 12px rgba(0,0,0,.12); position: relative;
}
.cover img { width: 100%; height: 100%; object-fit: cover; display: block; }
.cover.placeholder {
  display: flex; flex-direction: column; justify-content: space-between; padding: 10px 8px;
  color: #fff; font: 600 13px/1.2 var(--serif); word-break: break-word;
}
.cover.placeholder small { font: 500 9px/1.2 var(--sans); opacity: .8; text-transform: uppercase; letter-spacing: .06em; }
.continue .cover.placeholder { font-size: 9px; padding: 6px; }

.empty { text-align: center; padding: 64px 32px; color: var(--muted); }
.empty svg { width: 56px; height: 56px; margin: 0 auto 16px; color: var(--brand); }
.empty h2 { font: 600 22px/1.2 var(--serif); color: var(--text); margin: 0 0 8px; }

.fab {
  position: fixed; right: max(16px, calc(50% - 240px + 16px)); bottom: calc(var(--safe-b) + 20px); z-index: 6;
  height: 56px; padding: 0 20px 0 16px; border-radius: 18px; border: 0; box-shadow: var(--shadow);
  background: var(--brand); color: var(--brand-ink); font-weight: 600; display: flex; align-items: center; gap: 8px;
}
.fab svg { width: 22px; height: 22px; }

/* ---------- Alt sayfa (sheet) ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, .4); z-index: 40; animation: fade .15s; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 41; max-width: 480px; margin: 0 auto;
  background: var(--surface); color: var(--text); border-radius: 22px 22px 0 0;
  padding: 8px 16px calc(var(--safe-b) + 20px); max-height: 85vh; max-height: 85dvh; overflow-y: auto;
  animation: up .2s ease-out;
}
.sheet .grip { width: 40px; height: 5px; border-radius: 3px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { font: 600 20px/1.2 var(--serif); margin: 0 0 16px; }
.sheet .actions { display: flex; gap: 10px; margin-top: 8px; }
.sheet .actions .btn { flex: 1; }
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
@keyframes fade { from { opacity: 0; } }

.list { list-style: none; margin: 0; padding: 0; }
.list li { border-bottom: 1px solid var(--line); display: flex; align-items: center; }
.list li:last-child { border-bottom: 0; }
.list button.go { flex: 1; min-height: 50px; border: 0; background: none; text-align: left; padding: 10px 4px; display: flex; gap: 10px; align-items: baseline; }
.list button.go span:first-child { flex: 1; }
.list .meta { color: var(--muted); font-size: 13px; flex: none; }
.list .current { color: var(--brand); font-weight: 600; }
.list .muted { color: var(--muted); padding: 20px 4px; text-align: center; }

.tabs { display: flex; background: var(--surface-2); border-radius: 12px; padding: 4px; margin-bottom: 12px; }
.tabs button { flex: 1; height: 38px; border: 0; border-radius: 9px; background: none; font-weight: 600; color: var(--muted); }
.tabs button[aria-selected="true"] { background: var(--surface); color: var(--text); box-shadow: 0 1px 3px rgba(0,0,0,.1); }

.setting { margin-bottom: 20px; }
.setting > span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.stepper { display: flex; align-items: center; background: var(--surface-2); border-radius: 12px; }
.stepper button { width: 64px; height: 48px; border: 0; background: none; font-weight: 600; }
.stepper button.small { font-size: 15px; }
.stepper button.big { font-size: 22px; }
.stepper output { flex: 1; text-align: center; font-weight: 600; }
.swatches { display: flex; gap: 10px; }
.swatches button {
  flex: 1; height: 56px; border-radius: 12px; border: 2px solid var(--line); font-weight: 600;
}
.swatches button[aria-pressed="true"] { border-color: var(--brand); box-shadow: 0 0 0 2px var(--brand); }

/* ---------- Okuyucu ---------- */
.reader {
  --r-bg: #ffffff; --r-fg: #1c1c1c; --r-bar: rgba(255, 255, 255, .96); --r-muted: #777; --r-line: #e5e5e5;
  position: fixed; inset: 0; background: var(--r-bg); color: var(--r-fg); z-index: 10; overflow: hidden;
}
.reader.sepia { --r-bg: #f4ecd8; --r-fg: #5b4636; --r-bar: rgba(244, 236, 216, .97); --r-muted: #8f7b66; --r-line: #e0d4b8; }
.reader.gray { --r-bg: #3a3a3c; --r-fg: #e3e3e3; --r-bar: rgba(50, 50, 52, .97); --r-muted: #a5a5a8; --r-line: #4a4a4d; }
.reader.dark { --r-bg: #141414; --r-fg: #d4d4d4; --r-bar: rgba(28, 28, 28, .97); --r-muted: #8a8a8a; --r-line: #2e2e2e; }

.stage {
  position: absolute; left: 0; right: 0; top: calc(var(--safe-t) + 36px); bottom: calc(var(--safe-b) + 32px);
  max-width: 720px; margin: 0 auto;
}
.stage.epub { left: var(--m, 22px); right: var(--m, 22px); }
.stage.pdf { overflow: auto; touch-action: pan-x pan-y; -webkit-overflow-scrolling: touch; display: flex; }
.stage.pdf canvas { margin: auto; display: block; box-shadow: 0 1px 6px rgba(0,0,0,.15); }
.reader.dark .stage.pdf canvas { filter: invert(.9) hue-rotate(180deg); }
.reader.gray .stage.pdf canvas { filter: invert(.82) hue-rotate(180deg) brightness(1.1); }
.stage.pdf.scroll { flex-direction: column; align-items: safe center; gap: 10px; padding: 4px 0 40px; touch-action: pan-x pan-y pinch-zoom; }
.stage.pdf.scroll canvas { margin: 0; }
.stage .pg { flex: none; background: #fff; box-shadow: 0 1px 6px rgba(0,0,0,.15); }
.reader.dark .stage .pg, .reader.gray .stage .pg { background: #222; }
.reader.sepia .stage.pdf canvas { filter: sepia(.35) brightness(.97); }

.r-title, .r-foot {
  position: absolute; left: 0; right: 0; text-align: center; font-size: 12px; color: var(--r-muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 56px; pointer-events: none;
}
.r-foot { display: flex; justify-content: space-between; padding: 0 22px; gap: 12px; }
.r-foot span { overflow: hidden; text-overflow: ellipsis; }
.r-title { top: calc(var(--safe-t) + 10px); }
.r-foot { bottom: calc(var(--safe-b) + 8px); }

.r-bar {
  position: absolute; left: 0; right: 0; z-index: 5; background: var(--r-bar); color: var(--r-fg);
  backdrop-filter: blur(8px); transition: transform .2s ease, opacity .2s ease;
}
.r-top { top: 0; padding: calc(var(--safe-t) + 4px) 4px 4px; display: flex; align-items: center; border-bottom: 1px solid var(--r-line); }
.r-top .name { flex: 1; min-width: 0; font-weight: 600; font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; padding: 0 4px; }
.r-top .icon-btn:active, .r-bottom .icon-btn:active { background: var(--r-line); }
.r-bottom { bottom: 0; padding: 12px 16px calc(var(--safe-b) + 12px); border-top: 1px solid var(--r-line); }
.r-bottom .meta { display: flex; justify-content: space-between; font-size: 13px; color: var(--r-muted); margin-top: 6px; gap: 12px; }
.r-bottom .meta span:first-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.reader:not(.ui) .r-top { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.reader:not(.ui) .r-bottom { transform: translateY(100%); opacity: 0; pointer-events: none; }
.icon-btn.on svg { fill: currentColor; color: var(--accent); }

.slider { width: 100%; accent-color: var(--brand); height: 28px; margin: 0; }

.loading { position: absolute; inset: 0; display: grid; place-items: center; color: var(--r-muted); z-index: 3; pointer-events: none; }
.spinner { width: 32px; height: 32px; border: 3px solid var(--r-line); border-top-color: var(--brand); border-radius: 50%; animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Bildirim ---------- */
#toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-b) + 92px); transform: translate(-50%, 20px);
  background: #1f1b16; color: #fff; padding: 12px 18px; border-radius: 12px; font-size: 14px; z-index: 60;
  opacity: 0; pointer-events: none; transition: .2s; max-width: calc(100% - 32px); text-align: center;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }

/* ---------- Kütüphane: filtre ve sıralama ---------- */
.shelf-head { display: flex; align-items: center; gap: 8px; margin: 4px 16px 14px; }
.chips { display: flex; gap: 6px; overflow-x: auto; flex: 1; scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none; height: 34px; padding: 0 12px; border-radius: 17px; border: 1px solid var(--line);
  background: transparent; font-size: 14px; color: var(--muted);
}
.chips button[aria-pressed="true"] { background: var(--brand); border-color: var(--brand); color: var(--brand-ink); font-weight: 600; }
.sort { flex: none; height: 34px; border: 0; background: none; color: var(--muted); font-size: 13px; display: flex; align-items: center; gap: 4px; padding: 0 2px; }
.sort svg { width: 16px; height: 16px; }
.sheet-note { color: var(--muted); margin: -8px 0 16px; font-size: 14px; }

/* ---------- Okuyucu: ek katmanlar ---------- */
.dim { position: absolute; inset: 0; background: #000; opacity: 0; pointer-events: none; z-index: 4; }

.back-chip {
  position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(var(--safe-b) + 34px); z-index: 6;
  height: 36px; padding: 0 14px 0 10px; border-radius: 18px; border: 1px solid var(--r-line);
  background: var(--r-bar); color: var(--r-fg); font-size: 14px; font-weight: 600;
  display: flex; align-items: center; gap: 6px; box-shadow: 0 2px 10px rgba(0,0,0,.15);
}
.back-chip[hidden] { display: none; }
.back-chip svg { width: 18px; height: 18px; }
.reader.ui .back-chip { bottom: calc(var(--safe-b) + 100px); }

.selbar {
  position: absolute; left: 12px; right: 12px; bottom: calc(var(--safe-b) + 12px); z-index: 7;
  max-width: 456px; margin: 0 auto; background: #1f1b16; color: #fff; border-radius: 16px;
  padding: 8px 10px; display: flex; align-items: center; gap: 8px; box-shadow: 0 6px 24px rgba(0,0,0,.3);
}
.selbar[hidden] { display: none; }
.selbar button:not(.dot) { border: 0; background: none; color: #fff; font-size: 14px; font-weight: 600; height: 40px; padding: 0 6px; }
.selbar .sep { flex: 1; }
.dot { width: 30px; height: 30px; border-radius: 50%; border: 2px solid rgba(255,255,255,.7); flex: none; padding: 0; }
.colors { display: flex; gap: 12px; margin: 0 0 14px; }
.colors .dot { width: 36px; height: 36px; border-color: transparent; }
.colors .dot[aria-pressed="true"] { box-shadow: 0 0 0 3px var(--surface), 0 0 0 5px var(--text); }
.quote {
  margin: 0 0 14px; padding: 10px 12px; border-left: 4px solid; background: var(--surface-2); border-radius: 0 10px 10px 0;
  font: 15px/1.5 var(--serif); max-height: 30vh; overflow-y: auto;
}
.textarea { height: 110px; padding: 12px 14px; resize: vertical; line-height: 1.45; margin-bottom: 4px; }

/* ---------- Sheet içerikleri ---------- */
.sheet.tall { height: 85vh; height: 85dvh; }
.list .go.note { flex-direction: column; align-items: stretch; gap: 4px; border-left: 4px solid; padding-left: 12px; margin: 8px 0; }
.list .excerpt { font-family: var(--serif); display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden; }
.list .note-text { color: var(--muted); font-style: italic; font-size: 14px; }
.list .go.result { flex-direction: column; align-items: stretch; gap: 2px; }
.list .go.result .meta { font-size: 12px; }
mark { background: rgba(245, 217, 10, .55); color: inherit; border-radius: 3px; padding: 0 1px; }
.search-form { display: flex; gap: 8px; margin-bottom: 8px; }
.search-form .btn { flex: none; }
.search-status { color: var(--muted); font-size: 13px; margin: 0 0 4px; min-height: 18px; }

.settings-sheet .setting { margin-bottom: 16px; }
.settings-sheet .setting[hidden] { display: none; }
.settings-sheet .tabs { margin-bottom: 0; }
.settings-sheet .tabs button { font-size: 14px; }
.settings-sheet .swatches button { height: 48px; font-size: 14px; }
.bright { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.bright svg { width: 20px; height: 20px; flex: none; }
.fonts { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px; }
.fonts::-webkit-scrollbar { display: none; }
.fonts button {
  flex: none; min-width: 84px; height: 64px; border-radius: 12px; border: 2px solid var(--line); background: var(--surface);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; font-size: 12px;
}
.fonts button b { font-size: 20px; }
.fonts button[aria-pressed="true"] { border-color: var(--brand); box-shadow: 0 0 0 1px var(--brand); }
.toggle { display: flex; align-items: center; justify-content: space-between; min-height: 48px; font-weight: 500; cursor: pointer; }
.toggle input { position: absolute; opacity: 0; pointer-events: none; }
.toggle i { width: 50px; height: 30px; border-radius: 15px; background: var(--surface-2); border: 1px solid var(--line); position: relative; transition: .2s; flex: none; }
.toggle i::after { content: ""; position: absolute; top: 2px; left: 2px; width: 24px; height: 24px; border-radius: 50%; background: #fff; box-shadow: 0 1px 3px rgba(0,0,0,.25); transition: .2s; }
.toggle input:checked + i { background: var(--brand); border-color: var(--brand); }
.toggle input:checked + i::after { transform: translateX(20px); }
