/* ==========================================================
   Mert Yeşil Eğitim Portalı — Akıllı Tahta v2.0
   ========================================================== */
:root {
  --primary: #2563eb;
  --primary-hover: #1d4ed8;
  --primary-light: #eff6ff;
  --primary-soft: rgba(37, 99, 235, 0.14);
  --accent: #0284c7;
  --success: #16a34a;
  --warn: #d97706;
  --danger: #ef4444;
  --bg-main: #f8fafc;
  --bg-dot: #e2e8f0;
  --surface: #ffffff;
  --surface-2: #f1f5f9;
  --text-main: #0f172a;
  --text-muted: #64748b;
  --border-color: #e2e8f0;
  --header-bg: rgba(255, 255, 255, 0.88);
  --shadow-sm: 0 2px 8px rgba(0, 0, 0, 0.04);
  --shadow-md: 0 10px 25px -5px rgba(0, 0, 0, 0.08), 0 8px 10px -6px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 20px 35px -10px rgba(0, 0, 0, 0.14);
  --shadow-book-3d: 25px 25px 45px rgba(0,0,0,0.35), -12px 12px 25px rgba(0,0,0,0.18);
  --font-body: 'Inter', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --font-heading: 'Outfit', system-ui, -apple-system, 'Segoe UI', sans-serif;
  --radius: 18px;
  --rd-bg: #0b1220;
  --rd-bar: rgba(17, 25, 40, 0.92);
  --rd-line: rgba(255, 255, 255, 0.12);
  --rd-text: rgba(255, 255, 255, 0.88);
  color-scheme: light;
}

html[data-theme="dark"] {
  --primary: #3b82f6;
  --primary-hover: #60a5fa;
  --primary-light: rgba(59, 130, 246, 0.14);
  --primary-soft: rgba(59, 130, 246, 0.22);
  --bg-main: #0b1220;
  --bg-dot: #1e293b;
  --surface: #111a2c;
  --surface-2: #17223a;
  --text-main: #e2e8f0;
  --text-muted: #94a3b8;
  --border-color: #1f2a40;
  --header-bg: rgba(11, 18, 32, 0.86);
  --shadow-md: 0 10px 25px -5px rgba(0, 0, 0, 0.45);
  --shadow-lg: 0 20px 35px -10px rgba(0, 0, 0, 0.6);
  color-scheme: dark;
}

* { margin: 0; padding: 0; box-sizing: border-box; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }
body.locked [data-upload], body:not(.locked) [data-locked-only] { display: none !important; }
img { -webkit-user-drag: none; }

body {
  font-family: var(--font-body);
  background-color: var(--bg-main);
  background-image: radial-gradient(var(--bg-dot) 1.2px, transparent 1.2px);
  background-size: 28px 28px;
  color: var(--text-main);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  overflow-x: hidden;
  -webkit-tap-highlight-color: transparent;
}
body.reader-open { overflow: hidden; }
.reader, .tool-palette, .thumbs, .timer-widget, .book-card { user-select: none; -webkit-user-select: none; }

.muted { color: var(--text-muted); }
.small { font-size: 0.85rem; }
kbd {
  font-family: ui-monospace, monospace; font-size: 0.78rem; font-weight: 700;
  background: var(--surface-2); border: 1px solid var(--border-color); border-bottom-width: 3px;
  border-radius: 6px; padding: 1px 7px; color: var(--text-main);
}
code { font-family: ui-monospace, monospace; background: var(--surface-2); padding: 1px 6px; border-radius: 6px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border: 1px solid transparent; border-radius: 12px; padding: 10px 18px;
  font-weight: 700; font-size: 0.95rem; transition: all .2s ease; white-space: nowrap;
}
.btn-primary { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28); }
.btn-primary:hover { background: var(--primary-hover); transform: translateY(-1px); }
.btn-ghost { background: var(--surface-2); color: var(--text-main); border-color: var(--border-color); }
.btn-ghost:hover { border-color: var(--primary); color: var(--primary); }
.btn.danger, .btn-ghost.danger { color: var(--danger); }
.btn:disabled { opacity: .5; pointer-events: none; }
.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }

.icon-btn {
  width: 44px; height: 44px; border-radius: 14px; border: 1px solid var(--border-color);
  background: var(--surface); color: var(--text-main); display: inline-flex; align-items: center; justify-content: center;
  font-size: 1.08rem; transition: all .2s ease; box-shadow: var(--shadow-sm); flex-shrink: 0;
}
.icon-btn:hover { color: var(--primary); border-color: var(--primary); transform: translateY(-1px); }
.icon-btn.spin i { animation: fa-spin 1s linear infinite; }

.select {
  border: 1px solid var(--border-color); background: var(--surface); color: var(--text-main);
  border-radius: 12px; padding: 10px 12px; font-weight: 600; font-size: 0.92rem;
}

/* ---------- Splash ---------- */
#splash-screen {
  position: fixed; inset: 0; z-index: 10000;
  background: linear-gradient(135deg, #ffffff 0%, #eef2ff 50%, #e2e8f0 100%);
  display: flex; justify-content: center; align-items: center; text-align: center;
  transition: opacity .7s cubic-bezier(0.16, 1, 0.3, 1), visibility .7s;
}
html[data-theme="dark"] #splash-screen { background: linear-gradient(135deg, #0b1220, #111a2c 60%, #172554); }
#splash-screen.hidden { opacity: 0; visibility: hidden; pointer-events: none; }
.splash-card {
  background: var(--surface); padding: 46px 64px; border-radius: 36px;
  box-shadow: 0 30px 70px -15px rgba(37, 99, 235, 0.2); border: 1px solid var(--border-color);
  display: flex; flex-direction: column; align-items: center; gap: 18px; max-width: 680px; width: 92%;
  animation: splashFloat 3.5s ease-in-out infinite alternate;
}
@keyframes splashFloat { to { transform: translateY(-10px); } }
.splash-logo-badge {
  background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff; width: 88px; height: 88px; border-radius: 26px;
  display: flex; align-items: center; justify-content: center; font-size: 2.6rem; box-shadow: 0 15px 30px rgba(37, 99, 235, 0.35);
}
.splash-title { font-family: var(--font-heading); font-size: 2.3rem; font-weight: 800; letter-spacing: -0.5px; line-height: 1.2; }
.splash-subtitle {
  margin: 12px auto 0; font-size: 1.15rem; color: var(--primary); font-weight: 700; background: var(--primary-light);
  padding: 8px 22px; border-radius: 50px; border: 1px solid var(--primary-soft); display: inline-block;
}
.splash-version-tag { margin: 12px auto 0; font-size: .9rem; font-weight: 800; letter-spacing: 1px; color: var(--text-muted); background: var(--surface-2); padding: 6px 18px; border-radius: 12px; display: table; }
.splash-loader-bar { width: 220px; height: 6px; background: var(--surface-2); border-radius: 10px; overflow: hidden; }
.splash-loader-progress { height: 100%; background: linear-gradient(90deg, #2563eb, #38bdf8, #a78bfa); border-radius: 10px; animation: loadProgress 1.1s ease-in-out forwards; }
@keyframes loadProgress { from { width: 0; } to { width: 100%; } }

/* ---------- Header ---------- */
.app-header {
  width: 100%; padding: 14px 32px; background: var(--header-bg); backdrop-filter: blur(20px);
  display: flex; align-items: center; gap: 22px; border-bottom: 1px solid var(--border-color);
  position: sticky; top: 0; z-index: 100; box-shadow: var(--shadow-sm);
}
.brand-container { display: flex; align-items: center; gap: 14px; min-width: 0; }
.brand-icon {
  background: linear-gradient(135deg, #2563eb, #7c3aed); color: #fff; width: 48px; height: 48px; border-radius: 16px;
  display: flex; align-items: center; justify-content: center; font-size: 1.45rem; box-shadow: 0 6px 16px rgba(37, 99, 235, 0.28); flex-shrink: 0;
}
.brand-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.brand-title { font-family: var(--font-heading); font-size: 1.35rem; font-weight: 800; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.brand-badge {
  align-self: flex-start; background: var(--primary-light); color: var(--primary); font-size: .7rem; font-weight: 800;
  padding: 3px 10px; border-radius: 20px; letter-spacing: .8px; border: 1px solid var(--primary-soft);
}
.header-search {
  flex: 1; max-width: 520px; margin: 0 auto; display: flex; align-items: center; gap: 10px;
  background: var(--surface); border: 1px solid var(--border-color); border-radius: 16px; padding: 0 14px; height: 48px;
  box-shadow: var(--shadow-sm); transition: border-color .2s, box-shadow .2s;
}
.header-search:focus-within { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.header-search i { color: var(--text-muted); }
.header-search input { flex: 1; border: none; background: transparent; outline: none; font-size: 1rem; min-width: 0; }
.header-actions { display: flex; align-items: center; gap: 10px; }
.live-clock-card {
  display: flex; align-items: center; gap: 10px; background: var(--surface); padding: 0 16px; height: 44px; border-radius: 14px;
  border: 1px solid var(--border-color); box-shadow: var(--shadow-sm); font-family: ui-monospace, monospace; font-size: 1.2rem; font-weight: 700;
}
.live-clock-card i { color: var(--primary); }

/* ---------- Main / Library ---------- */
.container { max-width: 1280px; width: 100%; margin: 32px auto; padding: 0 28px; flex: 1; }
.section-title { font-family: var(--font-heading); font-size: 1.35rem; font-weight: 800; display: flex; align-items: center; gap: 10px; margin-bottom: 14px; }
.section-title i { color: var(--primary); }

.continue-section { margin-bottom: 34px; }
.continue-row { display: flex; gap: 16px; overflow-x: auto; padding: 4px 4px 12px; scroll-snap-type: x mandatory; }
.continue-card {
  scroll-snap-align: start; flex: 0 0 300px; display: flex; gap: 14px; align-items: center; background: var(--surface);
  border: 1px solid var(--border-color); border-radius: var(--radius); padding: 12px; box-shadow: var(--shadow-sm); cursor: pointer; text-align: left;
  transition: transform .25s ease, border-color .25s ease;
}
.continue-card:hover { transform: translateY(-3px); border-color: var(--primary); }
.continue-card .mini-cover { width: 62px; height: 84px; border-radius: 10px; overflow: hidden; flex-shrink: 0; background: var(--surface-2); }
.continue-card .mini-cover img { width: 100%; height: 100%; object-fit: cover; }
.continue-card b { display: block; font-size: .98rem; line-height: 1.3; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.continue-card small { color: var(--text-muted); font-weight: 600; }

.shelf-header { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; margin-bottom: 16px; flex-wrap: wrap; }
.shelf-title { font-family: var(--font-heading); font-size: 2rem; font-weight: 800; display: flex; align-items: center; gap: 12px; }
.shelf-title i { color: var(--primary); }
.shelf-subtitle { color: var(--text-muted); font-size: 1rem; margin-top: 6px; }
.shelf-tools { display: flex; gap: 10px; align-items: center; }

.tabs { display: flex; gap: 8px; overflow-x: auto; padding-bottom: 4px; }
.tab {
  border: 1px solid var(--border-color); background: var(--surface); color: var(--text-muted); border-radius: 14px;
  padding: 10px 16px; font-weight: 700; font-size: .93rem; display: inline-flex; align-items: center; gap: 8px; white-space: nowrap; transition: all .2s;
}
.tab:hover { color: var(--primary); border-color: var(--primary-soft); }
.tab.active { background: var(--primary); border-color: var(--primary); color: #fff; box-shadow: 0 6px 14px rgba(37, 99, 235, .25); }
.tab .count { font-size: .75rem; background: rgba(127, 127, 127, .18); padding: 1px 8px; border-radius: 10px; }
.tab .count:empty { display: none; }
.tabs.small .tab { padding: 8px 12px; font-size: .88rem; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; margin: 14px 0 22px; }
.chip {
  border: 1px dashed var(--border-color); background: transparent; color: var(--text-muted); border-radius: 30px;
  padding: 6px 14px; font-weight: 600; font-size: .86rem; transition: all .2s;
}
.chip:hover { color: var(--primary); border-color: var(--primary); }
.chip.active { background: var(--primary-light); border-style: solid; border-color: var(--primary); color: var(--primary); }

.book-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 26px; padding-bottom: 40px; }
.book-card {
  background: var(--surface); border-radius: 22px; padding: 14px; border: 1px solid var(--border-color); box-shadow: var(--shadow-md);
  transition: transform .35s cubic-bezier(0.16, 1, 0.3, 1), box-shadow .35s, border-color .35s;
  cursor: pointer; display: flex; flex-direction: column; position: relative; overflow: hidden; outline: none;
  animation: cardIn .45s cubic-bezier(0.16, 1, 0.3, 1) both;
}
@keyframes cardIn { from { opacity: 0; transform: translateY(14px) scale(.98); } }
.book-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 5px; z-index: 2;
  background: linear-gradient(90deg, var(--primary), #a855f7); opacity: 0; transition: opacity .3s ease;
}
.book-card:hover, .book-card:focus-visible { transform: translateY(-8px); box-shadow: var(--shadow-lg), 0 0 25px rgba(37, 99, 235, 0.15); border-color: var(--primary-soft); }
.book-card:hover::before, .book-card:focus-visible::before { opacity: 1; }
.book-cover-wrapper {
  position: relative; width: 100%; aspect-ratio: 3 / 4; border-radius: 14px; overflow: hidden; margin-bottom: 12px;
  box-shadow: 0 10px 22px rgba(0, 0, 0, 0.12); background: var(--surface-2);
}
.book-cover-img { width: 100%; height: 100%; object-fit: cover; transition: transform .5s ease; display: block; }
.book-card:hover .book-cover-img { transform: scale(1.05); }
.cover-fallback {
  position: absolute; inset: 0; display: flex; flex-direction: column; justify-content: space-between; padding: 58px 18px 20px; color: #fff;
  background: linear-gradient(150deg, hsl(var(--h, 220) 75% 52%), hsl(calc(var(--h, 220) + 40) 70% 38%));
}
.cover-fallback i { font-size: 2.3rem; opacity: .9; }
.cover-fallback b { font-family: var(--font-heading); font-size: 1.25rem; line-height: 1.25; text-shadow: 0 2px 8px rgba(0,0,0,.25); }
.cover-fallback::after { content: ''; position: absolute; left: 10px; top: 0; bottom: 0; width: 3px; background: rgba(255,255,255,.25); }

.book-badges { position: absolute; top: 10px; left: 10px; right: 10px; display: flex; justify-content: space-between; align-items: flex-start; gap: 6px; z-index: 1; }
.book-badge {
  background: rgba(15, 23, 42, 0.82); backdrop-filter: blur(8px); color: #fff; font-size: .72rem; font-weight: 700;
  padding: 5px 10px; border-radius: 10px; letter-spacing: .3px; display: inline-flex; align-items: center; gap: 6px;
}
.book-badge.drive { background: rgba(22, 163, 74, .9); }
.book-badge.local { background: rgba(124, 58, 237, .9); }
.fav-btn {
  width: 36px; height: 36px; border-radius: 12px; border: none; background: rgba(15, 23, 42, .6); color: #fff; backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center; transition: transform .2s; font-size: 1rem;
}
.fav-btn:hover { transform: scale(1.12); }
.card-tools { display: flex; flex-direction: column; gap: 6px; }
.fav-btn.extra { opacity: 0; transform: translateX(6px); transition: opacity .2s, transform .2s; }
.book-card:hover .fav-btn.extra, .book-card:focus-within .fav-btn.extra { opacity: 1; transform: none; }
.fav-btn.danger:hover { background: rgba(239, 68, 68, .9); }
@media (hover: none) { .fav-btn.extra { opacity: 1; transform: none; } }
.fav-btn.on { color: #facc15; }
.book-progress { position: absolute; left: 0; right: 0; bottom: 0; height: 6px; background: rgba(0,0,0,.25); }
.book-progress > div { height: 100%; background: linear-gradient(90deg, #22c55e, #84cc16); }
.book-info { display: flex; flex-direction: column; gap: 6px; flex: 1; }
.book-title { font-family: var(--font-heading); font-size: 1.12rem; font-weight: 800; line-height: 1.3; }
.book-meta { font-size: .82rem; color: var(--text-muted); display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.book-meta span { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.book-actions { display: flex; gap: 8px; margin-top: auto; padding-top: 10px; }
.btn-open-book {
  flex: 1; padding: 11px; border-radius: 12px; border: none; background: var(--primary-light); color: var(--primary);
  font-weight: 700; font-size: .95rem; display: flex; align-items: center; justify-content: center; gap: 8px; transition: all .25s ease; white-space: nowrap;
}
.book-card:hover .btn-open-book { background: var(--primary); color: #fff; box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35); }
.card-icon-btn {
  width: 42px; border-radius: 12px; border: 1px solid var(--border-color); background: var(--surface); color: var(--text-muted);
  display: flex; align-items: center; justify-content: center; transition: all .2s;
}
.card-icon-btn:hover { color: var(--primary); border-color: var(--primary); }
.card-icon-btn.danger:hover { color: var(--danger); border-color: var(--danger); }

.empty-state { text-align: center; padding: 60px 20px; color: var(--text-muted); display: flex; flex-direction: column; align-items: center; gap: 12px; }
.empty-state > i { font-size: 3rem; color: var(--primary); opacity: .7; }
.empty-state h3 { color: var(--text-main); font-family: var(--font-heading); font-size: 1.4rem; }

.app-footer {
  color: var(--text-muted); font-size: .9rem; border-top: 1px solid var(--border-color); background: var(--header-bg); backdrop-filter: blur(12px);
  display: flex; justify-content: space-between; align-items: center; gap: 16px; padding: 16px 32px; flex-wrap: wrap;
}
.footer-hint i { color: var(--primary); margin-left: 6px; }
.footer-version { font-weight: 800; color: var(--primary); background: var(--primary-light); padding: 4px 14px; border-radius: 12px; border: 1px solid var(--primary-soft); }

/* ==========================================================
   READER
   ========================================================== */
.reader {
  position: fixed; inset: 0; z-index: 1000; display: flex; flex-direction: column; color: var(--rd-text);
  background: radial-gradient(ellipse at center, #1a2540 0%, var(--rd-bg) 75%);
  opacity: 0; visibility: hidden; transition: opacity .3s ease, visibility .3s;
}
.reader.active { opacity: 1; visibility: visible; }
.reader.board-mode { background: #2a3142; }

.reader-top {
  min-height: 64px; background: var(--rd-bar); border-bottom: 1px solid var(--rd-line); padding: 8px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px; z-index: 20; flex-wrap: wrap;
  transition: transform .35s ease, opacity .35s ease;
}
.reader-title { font-family: var(--font-heading); font-size: 1.15rem; font-weight: 700; display: flex; align-items: center; gap: 10px; min-width: 0; flex: 1 1 180px; }
.reader-title span:last-child { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.src-badge { width: 34px; height: 34px; border-radius: 10px; background: rgba(56, 189, 248, .15); color: #38bdf8; display: inline-flex; align-items: center; justify-content: center; flex-shrink: 0; }
.src-badge.drive { background: rgba(34, 197, 94, .15); color: #4ade80; }
.src-badge.local { background: rgba(167, 139, 250, .15); color: #c4b5fd; }

.reader-nav, .zoom-box, .segmented {
  display: flex; align-items: center; gap: 4px; background: rgba(2, 6, 23, 0.55); padding: 4px 8px; border-radius: 16px; border: 1px solid var(--rd-line);
}
.reader-actions { display: flex; align-items: center; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }
.btn-ctrl {
  background: transparent; border: none; color: var(--rd-text); width: 42px; height: 42px; border-radius: 12px;
  display: inline-flex; align-items: center; justify-content: center; font-size: 1.08rem; transition: all .2s ease; flex-shrink: 0;
}
.btn-ctrl:hover { background: rgba(255, 255, 255, 0.14); color: #fff; }
.btn-ctrl.active { background: var(--primary); color: #fff; }
.btn-ctrl:disabled { opacity: .35; pointer-events: none; }
.segmented button {
  border: none; background: transparent; color: var(--rd-text); padding: 8px 12px; border-radius: 11px; font-weight: 700; font-size: .88rem;
  display: inline-flex; align-items: center; gap: 7px;
}
.segmented button:hover { background: rgba(255,255,255,.1); }
.segmented button.active { background: var(--primary); color: #fff; }
.segmented button:disabled { opacity: .35; pointer-events: none; }
.zoom-label { min-width: 62px; background: transparent; border: none; color: #fff; font-weight: 800; font-size: .9rem; border-radius: 10px; padding: 8px 4px; }
.zoom-label:hover { background: rgba(255,255,255,.1); }
.page-jump-box { display: flex; align-items: center; gap: 6px; font-size: .95rem; font-weight: 700; padding: 0 6px; }
.page-jump-input {
  width: 62px; background: rgba(255, 255, 255, 0.12); border: 1px solid rgba(255, 255, 255, 0.22); border-radius: 9px; color: #fff;
  text-align: center; font-weight: 800; padding: 6px 0; -moz-appearance: textfield;
}
.page-jump-input::-webkit-inner-spin-button { display: none; }
.page-jump-input:focus { outline: none; border-color: var(--primary); }
.btn-close-reader {
  background: var(--danger); color: #fff; border: none; padding: 10px 16px; border-radius: 12px; font-weight: 700;
  display: inline-flex; align-items: center; gap: 8px; box-shadow: 0 4px 14px rgba(239, 68, 68, 0.35); transition: all .2s;
}
.btn-close-reader:hover { background: #dc2626; transform: scale(1.03); }

.reader-body { flex: 1; display: flex; min-height: 0; position: relative; }

/* Tool palette */
.tool-palette {
  width: 70px; background: var(--rd-bar); border-right: 1px solid var(--rd-line); padding: 10px 8px; display: flex; flex-direction: column;
  gap: 10px; overflow-y: auto; z-index: 15; scrollbar-width: none; transition: transform .35s ease, opacity .35s ease;
}
.tool-palette::-webkit-scrollbar { display: none; }
.tool-group { display: flex; flex-direction: column; gap: 4px; padding-bottom: 10px; border-bottom: 1px solid var(--rd-line); align-items: center; }
.tool-group:last-child { border-bottom: none; }
.tool {
  width: 52px; height: 48px; border-radius: 14px; border: none; background: transparent; color: var(--rd-text);
  font-size: 1.15rem; display: flex; align-items: center; justify-content: center; transition: all .18s ease; position: relative;
}
.tool:hover { background: rgba(255,255,255,.12); color: #fff; }
.tool.active { background: var(--primary); color: #fff; box-shadow: 0 6px 16px rgba(37, 99, 235, .45); }
.tool.danger:hover { background: rgba(239,68,68,.2); color: #fca5a5; }
.tool.on { color: #facc15; }
.tool:disabled { opacity: .3; pointer-events: none; }
.colors { display: grid; grid-template-columns: repeat(2, 24px); gap: 7px; justify-content: center; }
.swatch {
  width: 24px; height: 24px; border-radius: 50%; border: 2px solid rgba(255,255,255,.35); transition: transform .15s; padding: 0;
}
.swatch:hover { transform: scale(1.15); }
.swatch.active { border-color: #fff; box-shadow: 0 0 0 3px var(--primary); transform: scale(1.1); }
.swatch.custom { position: relative; overflow: hidden; background: conic-gradient(red, yellow, lime, cyan, blue, magenta, red); }
.swatch.custom input { position: absolute; inset: -6px; opacity: 0; cursor: pointer; }
.size-dot { width: 52px; height: 34px; border: none; background: transparent; border-radius: 12px; display: flex; align-items: center; justify-content: center; }
.size-dot span { background: var(--rd-text); border-radius: 50%; display: block; }
.size-dot:hover { background: rgba(255,255,255,.1); }
.size-dot.active { background: rgba(37, 99, 235, .35); }
.board-only { display: none !important; }
.reader.board-mode .board-only { display: flex !important; }

/* Stage */
.reader-stage { flex: 1; position: relative; overflow: hidden; touch-action: none; min-width: 0; }
.reader-stage.tool-hand, .reader-stage.panning { cursor: grab; }
.reader-stage.panning:active { cursor: grabbing; }
.reader-viewport {
  position: absolute; inset: 0; display: flex; justify-content: center; align-items: center; transform-origin: center center;
  will-change: transform;
}
.reader-viewport.animate { transition: transform .28s cubic-bezier(0.16, 1, 0.3, 1); }

.flip-box { position: relative; flex-shrink: 0; }
.flip-container .stf__block, .flip-container { border-radius: 4px; }
.flip-box.landscape::before {
  content: ''; position: absolute; inset: 0; box-shadow: var(--shadow-book-3d); pointer-events: none; border-radius: 4px;
}
.page-wrapper { background: #fff; overflow: hidden; }
.page-content { width: 100%; height: 100%; background: #fff; position: relative; display: flex; align-items: center; justify-content: center; }
.page-content canvas { width: 100%; height: 100%; display: block; object-fit: contain; }
.page-ph {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center; color: #94a3b8; font-weight: 800; font-size: 2rem;
  background: linear-gradient(110deg, #f8fafc 30%, #eef2f7 50%, #f8fafc 70%); background-size: 200% 100%; animation: shimmer 1.4s linear infinite;
}
@keyframes shimmer { to { background-position: -200% 0; } }
.page-wrapper.--left .page-content::after, .page-wrapper.--right .page-content::after {
  content: ''; position: absolute; top: 0; bottom: 0; width: 40px; pointer-events: none;
}
.page-wrapper.--left .page-content::after { right: 0; background: linear-gradient(to left, rgba(0,0,0,0.22), rgba(0,0,0,0.04) 70%, transparent); }
.page-wrapper.--right .page-content::after { left: 0; background: linear-gradient(to right, rgba(0,0,0,0.22), rgba(0,0,0,0.04) 70%, transparent); }

.single-sheet { position: relative; background: #fff; box-shadow: var(--shadow-book-3d); flex-shrink: 0; border-radius: 3px; overflow: hidden; }
.single-sheet canvas.page-canvas { width: 100%; height: 100%; display: block; }
.single-sheet.flash-next { animation: slideNext .32s ease; }
.single-sheet.flash-prev { animation: slidePrev .32s ease; }
@keyframes slideNext { from { opacity: .3; transform: translateX(40px); } }
@keyframes slidePrev { from { opacity: .3; transform: translateX(-40px); } }

.embed-wrap { position: absolute; inset: 12px; border-radius: 12px; overflow: hidden; background: #1f2937; box-shadow: var(--shadow-book-3d); }
.embed-wrap iframe { width: 100%; height: 100%; border: 0; display: block; background: #fff; }

/* Ink */
.ink-layer { position: absolute; inset: 0; z-index: 5; pointer-events: none; touch-action: none; }
.ink-layer canvas { position: absolute; inset: 0; width: 100%; height: 100%; }
.ink-layer.active { pointer-events: auto; cursor: crosshair; }
.ink-layer.eraser { cursor: cell; }
.ink-layer.laser { cursor: none; }
.ink-layer.text { cursor: text; }
.ink-layer.hidden-ink canvas.base { opacity: 0; }
.ink-layer.flipping { opacity: 0; transition: opacity .1s; }
.ink-text-editor { position: fixed; z-index: 1300; }
.ink-text-editor textarea {
  min-width: 220px; background: rgba(255,255,255,.96); color: #0f172a; border: 2px dashed var(--primary); border-radius: 8px;
  padding: 6px 8px; outline: none; resize: both; font-family: var(--font-body); font-weight: 600; line-height: 1.25;
}

.reader-loading {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%); display: flex; flex-direction: column; align-items: center; gap: 14px;
  color: #fff; font-size: 1.05rem; font-weight: 600; background: rgba(15, 23, 42, 0.9); padding: 26px 40px; border-radius: 22px;
  border: 1px solid var(--rd-line); backdrop-filter: blur(12px); z-index: 30; text-align: center; max-width: 90%;
}
.reader-loading > i { font-size: 2.4rem; color: var(--primary); }
.reader-loading.error > i { color: var(--danger); }
.reader-loading .btn { margin-top: 4px; }
.mini-progress { width: 220px; height: 5px; border-radius: 6px; background: rgba(255,255,255,.12); overflow: hidden; }
.mini-progress div { height: 100%; width: 0; background: linear-gradient(90deg, #2563eb, #38bdf8); transition: width .2s; }
.reader-loading.error .mini-progress { display: none; }

.reader-notice {
  position: absolute; left: 50%; top: 16px; transform: translateX(-50%); z-index: 25; max-width: min(720px, 92%);
  background: rgba(120, 53, 15, .92); border: 1px solid rgba(251, 191, 36, .4); color: #fef3c7; padding: 10px 14px 10px 16px; border-radius: 14px;
  display: flex; align-items: center; gap: 12px; font-size: .9rem; font-weight: 600; box-shadow: var(--shadow-lg);
}
.reader-notice button { background: rgba(255,255,255,.15); border: none; color: #fff; padding: 6px 12px; border-radius: 9px; font-weight: 700; white-space: nowrap; }
.reader-notice button:hover { background: rgba(255,255,255,.28); }

.stage-arrow {
  position: absolute; top: 50%; transform: translateY(-50%); z-index: 12; width: 56px; height: 96px; border: none; border-radius: 18px;
  background: rgba(15, 23, 42, .45); color: #fff; font-size: 1.5rem; opacity: .35; transition: opacity .2s, background .2s;
}
.stage-arrow:hover { opacity: 1; background: rgba(37, 99, 235, .8); }
.stage-arrow.left { left: 10px; }
.stage-arrow.right { right: 10px; }
.stage-arrow:disabled { display: none; }

.spotlight { position: absolute; inset: 0; z-index: 18; pointer-events: none; transition: background .05s linear; }
.curtain {
  position: absolute; left: 0; right: 0; top: 0; z-index: 19; pointer-events: none; height: 55%;
  background: repeating-linear-gradient(90deg, #1e1b4b 0 26px, #272463 26px 52px); box-shadow: 0 12px 30px rgba(0,0,0,.5);
}
.curtain-handle {
  position: absolute; left: 50%; bottom: -22px; transform: translateX(-50%); pointer-events: auto; cursor: ns-resize; touch-action: none;
  background: #facc15; color: #1e1b4b; font-weight: 800; padding: 10px 22px; border-radius: 14px; box-shadow: 0 8px 20px rgba(0,0,0,.4); white-space: nowrap;
}

/* Side panel */
.side-panel {
  width: 330px; background: var(--rd-bar); border-left: 1px solid var(--rd-line); display: none; flex-direction: column; z-index: 15;
}
.reader.panel-open .side-panel { display: flex; }
.side-tabs { display: flex; padding: 8px; gap: 4px; border-bottom: 1px solid var(--rd-line); }
.side-tabs button { flex: 1; border: none; background: transparent; color: var(--rd-text); padding: 9px 4px; border-radius: 10px; font-weight: 700; font-size: .82rem; }
.side-tabs button.active { background: rgba(37, 99, 235, .3); color: #fff; }
.side-content { flex: 1; overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 6px; }
.side-content .muted { color: rgba(255,255,255,.55); }
.outline-list, .outline-list ul { list-style: none; }
.outline-list ul { padding-left: 14px; border-left: 1px solid var(--rd-line); margin-left: 8px; }
.outline-list button, .result-item, .note-item {
  width: 100%; text-align: left; border: none; background: transparent; color: var(--rd-text); padding: 8px 10px; border-radius: 10px; font-size: .9rem; line-height: 1.35;
  display: flex; justify-content: space-between; gap: 10px;
}
.outline-list button:hover, .result-item:hover, .note-item:hover { background: rgba(255,255,255,.1); color: #fff; }
.outline-list .pg, .result-item .pg, .note-item .pg { color: #93c5fd; font-weight: 800; font-size: .8rem; flex-shrink: 0; }
.result-item { flex-direction: column; gap: 4px; }
.result-item mark { background: #facc15; color: #111; border-radius: 3px; padding: 0 2px; }
.search-form { display: flex; gap: 6px; }
.search-form input { flex: 1; background: rgba(255,255,255,.08); border: 1px solid var(--rd-line); color: #fff; border-radius: 10px; padding: 9px 12px; outline: none; min-width: 0; }
.search-form input:focus { border-color: var(--primary); }
.side-content .btn-ghost { background: rgba(255,255,255,.06); border-color: var(--rd-line); margin-top: 10px; }

/* Thumbnails */
.thumbs {
  height: 118px; background: var(--rd-bar); border-top: 1px solid var(--rd-line); display: flex; align-items: center; gap: 12px;
  padding: 10px 18px; overflow-x: auto; scroll-behavior: smooth; z-index: 15; transition: transform .35s ease, opacity .35s ease;
}
.reader.thumbs-hidden .thumbs { display: none; }
.thumbs::-webkit-scrollbar { height: 6px; }
.thumbs::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.25); border-radius: 10px; }
.thumb-item {
  height: 92px; min-width: 66px; border-radius: 8px; overflow: hidden; border: 2px solid rgba(255, 255, 255, 0.18); position: relative; flex-shrink: 0;
  transition: all .2s ease; opacity: .62; background: #cbd5e1; padding: 0;
}
.thumb-item:hover { opacity: .95; transform: translateY(-3px); }
.thumb-item.active { opacity: 1; border-color: var(--primary); box-shadow: 0 0 14px var(--primary); transform: translateY(-4px); }
.thumb-item.has-ink::before { content: '\f303'; font-family: 'Font Awesome 6 Free'; font-weight: 900; position: absolute; top: 3px; left: 3px; font-size: .6rem; background: #e11d48; color: #fff; padding: 2px 4px; border-radius: 4px; z-index: 1; }
.thumb-item canvas { width: 100%; height: 100%; display: block; }
.thumb-page-num { position: absolute; bottom: 2px; right: 2px; background: rgba(0, 0, 0, 0.75); color: #fff; font-size: .66rem; padding: 1px 5px; border-radius: 4px; font-weight: 700; }

/* Auto-hide chrome */
.reader.idle .reader-top { transform: translateY(-100%); opacity: 0; pointer-events: none; }
.reader.idle .tool-palette { transform: translateX(-100%); opacity: 0; pointer-events: none; }
.reader.idle .thumbs { transform: translateY(100%); opacity: 0; pointer-events: none; }
.reader.idle .stage-arrow { opacity: 0; }

/* ---------- Timer ---------- */
.timer-widget {
  position: fixed; right: 24px; bottom: 140px; z-index: 1400; width: 300px; background: rgba(15, 23, 42, .95); color: #fff;
  border: 1px solid rgba(255,255,255,.14); border-radius: 22px; padding: 14px; box-shadow: 0 25px 50px rgba(0,0,0,.45); backdrop-filter: blur(12px);
}
.timer-widget.ringing { animation: ring .5s ease-in-out infinite alternate; border-color: #ef4444; }
@keyframes ring { to { box-shadow: 0 0 0 10px rgba(239,68,68,.35), 0 25px 50px rgba(0,0,0,.45); } }
.timer-head { display: flex; justify-content: space-between; align-items: center; cursor: move; font-weight: 700; font-size: .9rem; touch-action: none; }
.timer-head > div { display: flex; gap: 6px; }
.timer-display { font-family: ui-monospace, monospace; font-size: 3.6rem; font-weight: 800; text-align: center; letter-spacing: 2px; margin: 6px 0; }
.timer-display.low { color: #f87171; }
.timer-presets { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.timer-presets button, .mini {
  border: 1px solid rgba(255,255,255,.16); background: rgba(255,255,255,.07); color: #fff; padding: 7px 10px; border-radius: 10px; font-weight: 700; font-size: .85rem;
}
.timer-presets button:hover, .mini:hover { background: rgba(255,255,255,.18); }
.timer-controls { display: flex; gap: 6px; margin-top: 10px; }
.timer-controls .btn { flex: 1; }

/* ---------- Dialogs ---------- */
.dialog { border: none; background: transparent; padding: 16px; max-width: 100vw; max-height: 100vh; margin: auto; color: var(--text-main); }
.dialog::backdrop { background: rgba(2, 6, 23, .55); backdrop-filter: blur(4px); }
.dialog[open] .dialog-card { animation: dialogIn .3s cubic-bezier(0.16, 1, 0.3, 1); }
@keyframes dialogIn { from { opacity: 0; transform: translateY(16px) scale(.97); } }
.dialog-card {
  width: min(640px, 94vw); max-height: calc(100vh - 40px); background: var(--surface); border: 1px solid var(--border-color);
  border-radius: 24px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; overflow: hidden;
}
.dialog-card.narrow { width: min(420px, 94vw); }
.dialog-head { display: flex; justify-content: space-between; align-items: center; padding: 18px 22px; border-bottom: 1px solid var(--border-color); }
.dialog-head h3 { font-family: var(--font-heading); font-size: 1.3rem; display: flex; align-items: center; gap: 10px; }
.dialog-head h3 i { color: var(--primary); }
.dialog-card > .tabs { padding: 14px 22px 0; }
.dialog-body { padding: 18px 22px; overflow-y: auto; display: flex; flex-direction: column; gap: 14px; }
.dialog-body.center { align-items: center; text-align: center; }
.dialog-body h4 { font-family: var(--font-heading); font-size: 1.05rem; margin-top: 6px; display: flex; align-items: center; gap: 8px; }
.dialog-body h4 i { color: var(--primary); }
.dialog-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 22px; border-top: 1px solid var(--border-color); background: var(--surface-2); }
.field { display: flex; flex-direction: column; gap: 6px; font-weight: 600; font-size: .9rem; }
.field small { color: var(--text-muted); font-weight: 500; }
.field input, .field select, .input-row input {
  border: 1px solid var(--border-color); background: var(--surface-2); color: var(--text-main); border-radius: 12px; padding: 11px 13px; font-size: .95rem; outline: none; width: 100%;
}
.field input:focus, .input-row input:focus { border-color: var(--primary); box-shadow: 0 0 0 4px var(--primary-soft); }
.input-row { display: flex; gap: 8px; align-items: center; width: 100%; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.check { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: .92rem; cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--primary); }
.hint { font-size: .84rem; color: var(--text-muted); line-height: 1.45; }
.hint.ok { color: var(--success); font-weight: 700; }
.hint.bad { color: var(--danger); font-weight: 700; }
.info-box { display: flex; gap: 10px; background: var(--primary-light); border: 1px solid var(--primary-soft); padding: 12px 14px; border-radius: 14px; font-size: .86rem; line-height: 1.5; }
.info-box > i { color: var(--primary); margin-top: 3px; }
.drop-zone {
  border: 2px dashed var(--border-color); border-radius: 18px; padding: 28px; display: flex; flex-direction: column; align-items: center; gap: 8px;
  text-align: center; cursor: pointer; transition: all .2s; position: relative;
}
.drop-zone > i { font-size: 2.2rem; color: var(--primary); }
.drop-zone.over, .drop-zone:hover { border-color: var(--primary); background: var(--primary-light); }
.drop-zone input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.drop-zone small { color: var(--text-muted); }
.folder-list { display: flex; flex-direction: column; gap: 8px; }
.folder-row { display: flex; align-items: center; gap: 10px; background: var(--surface-2); border: 1px solid var(--border-color); border-radius: 12px; padding: 8px 10px; font-size: .88rem; }
.folder-row > i { color: var(--success); }
.folder-row div { flex: 1; min-width: 0; }
.folder-row b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.folder-row small { color: var(--text-muted); }
.folder-row .icon-btn { width: 36px; height: 36px; border-radius: 10px; font-size: .9rem; }
.qr-box { background: #fff; padding: 14px; border-radius: 16px; min-width: 220px; min-height: 220px; display: flex; align-items: center; justify-content: center; }
.qr-box img, .qr-box svg { width: 240px; height: 240px; image-rendering: pixelated; }
.shortcut-grid { display: grid; grid-template-columns: auto 1fr; gap: 10px 18px; align-items: center; font-size: .9rem; }
.help-list { padding-left: 20px; display: flex; flex-direction: column; gap: 6px; font-size: .92rem; line-height: 1.5; }

/* ---------- Toasts ---------- */
.toast-stack { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 2000; display: flex; flex-direction: column; gap: 10px; align-items: center; pointer-events: none; }
.toast {
  pointer-events: auto; background: #0f172a; color: #fff; padding: 12px 18px; border-radius: 14px; box-shadow: 0 15px 35px rgba(0,0,0,.35);
  font-weight: 600; font-size: .93rem; display: flex; align-items: center; gap: 10px; max-width: min(560px, 92vw); animation: toastIn .3s ease;
  border-left: 4px solid var(--primary);
}
.toast.ok { border-left-color: var(--success); }
.toast.warn { border-left-color: #f59e0b; }
.toast.err { border-left-color: var(--danger); }
.toast.out { opacity: 0; transform: translateY(10px); transition: all .3s ease; }
@keyframes toastIn { from { opacity: 0; transform: translateY(14px); } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .header-actions .btn span, .segmented button span, .btn-close-reader span { display: none; }
  .live-clock-card { display: none; }
}
@media (max-width: 820px) {
  .app-header { flex-wrap: wrap; padding: 12px 16px; gap: 12px; }
  .header-search { order: 3; max-width: none; flex-basis: 100%; }
  .header-actions { margin-left: auto; gap: 6px; }
  .brand-badge { display: none; }
  .container { padding: 0 16px; margin-top: 22px; }
  .book-grid { grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
  .footer-hint { display: none; }
  .zoom-box .btn-ctrl[data-cmd="fit-width"] { display: none; }
  .reader-body { flex-direction: column-reverse; }
  .tool-palette { width: 100%; flex-direction: row; overflow-x: auto; overflow-y: hidden; border-right: none; border-top: 1px solid var(--rd-line); padding: 6px; }
  .tool-group { flex-direction: row; border-bottom: none; border-right: 1px solid var(--rd-line); padding: 0 6px 0 0; }
  .colors { grid-template-columns: repeat(4, 24px); align-content: center; }
  .tool { width: 44px; height: 44px; }
  .side-panel { position: absolute; right: 0; top: 0; bottom: 0; width: min(330px, 90vw); }
  .thumbs { height: 96px; }
  .thumb-item { height: 72px; min-width: 52px; }
  .grid-2 { grid-template-columns: 1fr; }
  .stage-arrow { width: 40px; height: 70px; }
}
@media (max-width: 520px) {
  .icon-btn { width: 40px; height: 40px; }
  .brand-title { font-size: 1.1rem; }
  .shelf-title { font-size: 1.5rem; }
  .reader-title { display: none; }
  .btn-ctrl { width: 38px; height: 38px; }
}
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; transition-duration: .01ms !important; }
}
