/* Theme variables (light by default, overridden in dark mode) */
:root {
  --bg: #f8fafc;
  --text: #0f172a;
  --muted: #666666;
  --author: #4b5563; /* tailwind gray-600 */
  --summary: #374151; /* maps to tailwind gray-700 */
  --border: #e5e7eb;
  --row-border: #eeeeee;
  --row-hover: #f0f4f8;
  --focus: #2563eb;
  --card-bg: #ffffff;
  --card-shadow: rgba(0,0,0,0.1);
  --cover-bg: #f3f4f6;
  --modal-overlay: rgba(0,0,0,0.6);
  --modal-bg: #ffffff;
  --modal-shadow: 0 10px 30px rgba(2,6,23,0.3);
  --format-bg: #e8f1ff;
  --format-color: #2563eb;
  --placeholder: #999999;
}

/* Hint to user agents that both schemes are supported */
html { color-scheme: light dark; }

/* Topbar (app header) */
.topbar { background: #1f2937; color: #fff; box-shadow: 0 4px 12px rgba(2,6,23,0.4); }
.topbar-inner { max-width: 1024px; margin: 0 auto; padding: 0.5rem 1rem; display: flex; align-items: center; gap: 0.75rem; }
.topbar .top-logo { flex: 0 0 48px; width: 48px; height: 48px; border-radius: 8px; object-fit: contain; }
.topbar .top-search { flex: 1 1 0; max-width: none; background: rgba(255,255,255,0.06); border: 1px solid rgba(255,255,255,0.06); color: #fff; padding: 0.6rem 0.75rem; border-radius: 8px; }
.topbar .top-search::placeholder { color: rgba(255,255,255,0.7); }
.topbar .reset-btn { flex: 0 0 auto; background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.06); padding: 0.35rem 0.6rem; border-radius: 6px; cursor: pointer; }
.topbar .reset-btn:hover { background: rgba(255,255,255,0.04); }

/* Dark-mode logo tweak: make logo readable on dark background if needed */
@media (prefers-color-scheme: dark) {
  .topbar .top-logo { filter: invert(1) brightness(1.15); }
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #071022;
    --text: #e6eef8;
    --muted: #9aa6b2;
    --summary: #cbd5e1; /* lighter summary text for dark mode */
    --author: #cbd5e1;
    --border: #1f2937;
    --row-border: #15202a;
    --row-hover: rgba(255,255,255,0.02);
    --focus: #60a5fa;
    --card-bg: #071026;
    --card-shadow: rgba(0,0,0,0.6);
    --cover-bg: #0f1724;
    --modal-overlay: rgba(0,0,0,0.7);
    --modal-bg: #071026;
    --modal-shadow: 0 10px 30px rgba(0,0,0,0.6);
    --format-bg: rgba(96,165,250,0.12);
    --format-color: #60a5fa;
    --placeholder: #9aa6b2;
  }
}

/* prefers-color-scheme handles theme; no JS overrides */

/* Minimal fallback styles; Tailwind CDN still used for utility classes */
body {
  background: var(--bg);
  color: var(--text);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial;
}

.hidden { display: none !important; }

/* Error UI */
.error-toast { position: fixed; top: 1rem; right: 1rem; background: #fee; border: 1px solid #f99; border-radius: 8px; padding: 1rem; box-shadow: 0 4px 12px rgba(255,100,100,0.2); z-index: 999; max-width: 500px; animation: slideIn 0.3s ease; }
.error-toast.error-success { background: #efe; border-color: #9f9; }
.error-toast.error-warn { background: #fef0e0; border-color: #ffc; }
.error-toast-content { display: flex; justify-content: space-between; align-items: center; gap: 1rem; }
.error-toast-message { color: var(--text); font-size: 0.95rem; }
.error-toast-close { background: transparent; border: none; cursor: pointer; font-size: 1.2rem; color: var(--muted); padding: 0; }
.error-toast-close:hover { color: var(--text); }
@keyframes slideIn { from { transform: translateX(400px); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* File browser row */
.file-row { padding: 0.85rem 1rem; border-bottom: 1px solid var(--row-border); display: flex; align-items: center; gap: 0.75rem; cursor: pointer; transition: background 0.15s ease; }
.file-row:hover { background: var(--row-hover); }
.file-row[role="button"]:focus { outline: 2px solid var(--focus); outline-offset: -2px; background: rgba(37,99,235,0.06); }
.file-icon { font-size: 1.2rem; min-width: 1.2rem; }
.file-name { flex: 1; font-size: 0.95rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.load-more-btn { padding: 0.75rem 1rem; text-align: center; background: var(--card-bg); border-top: 1px solid var(--row-border); cursor: pointer; color: var(--focus); font-weight: 500; transition: background 0.15s ease; }
.load-more-btn:hover { background: rgba(37,99,235,0.06); }

/* Book grid & cards */
.book-card { background: var(--card-bg); border: 1px solid var(--border); border-radius: 12px; padding: 0.75rem; display: flex; flex-direction: column; cursor: pointer; transition: all 0.2s ease; }
.book-card:hover { box-shadow: 0 8px 20px var(--card-shadow); transform: translateY(-2px); }
.book-card:focus { outline: 2px solid var(--focus); outline-offset: 2px; }
.book-cover { aspect-ratio: 2/3; background: var(--cover-bg); border-radius: 8px; margin-bottom: 0.75rem; display: flex; align-items: center; justify-content: center; font-size: 0.8rem; color: var(--placeholder); overflow: hidden; }
.book-cover-img { width: 100%; height: 100%; object-fit: cover; border-radius: 8px; }
.book-title { font-size: 0.85rem; font-weight: 700; margin: 0 0 0.5rem 0; line-height: 1.2; overflow: hidden; text-overflow: ellipsis; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.book-author { font-size: 0.75rem; color: var(--author); margin: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Modal styles */
.modal-overlay { position: fixed; inset: 0; background: var(--modal-overlay); display: flex; align-items: center; justify-content: center; z-index: 60; padding: 1rem; }
.modal-content { position: relative; background: var(--modal-bg); border-radius: 10px; width: 92%; max-width: 720px; max-height: 80vh; overflow-y: auto; padding: 1.5rem; display: flex; gap: 1.5rem; align-items: flex-start; box-shadow: var(--modal-shadow); }
.modal-cover { width: 36%; min-width: 140px; aspect-ratio: 2/3; background: #f3f4f6; border-radius: 8px; overflow: hidden; display:flex; align-items:center; justify-content:center; }
.modal-cover { width: 36%; min-width: 140px; aspect-ratio: 2/3; background: var(--cover-bg); border-radius: 8px; overflow: hidden; display:flex; align-items:center; justify-content:center; }
.modal-cover img{ width:100%; height:100%; object-fit:cover; display:block; }
.modal-info { flex: 1; }
#modal-summary { color: var(--summary); }
.modal-info #modal-author { color: var(--author); }
.modal-close { position: absolute; top: 8px; right: 8px; background: transparent; border: none; font-size: 18px; cursor: pointer; padding: 0.5rem; transition: transform 0.15s ease; }
.modal-close:hover { transform: scale(1.2); }
.modal-close:focus { outline: 2px solid var(--focus); }

/* Format link */
.format-link { display: inline-block; margin-right: 0.75rem; margin-bottom: 0.5rem; padding: 0.35rem 0.6rem; background: var(--format-bg); color: var(--format-color); text-decoration: none; border-radius: 4px; font-size: 0.8rem; font-weight: 600; transition: all 0.15s ease; }
.format-link:hover { background: var(--format-color); color: #fff; }
.format-link:focus { outline: 2px solid var(--format-color); outline-offset: 2px; }

/* Utility classes for text content */
.text-base { font-size: 1rem; }
.font-bold { font-weight: 700; }
.mb-2 { margin-bottom: 0.5rem; }
.mb-3 { margin-bottom: 0.75rem; }
.mb-4 { margin-bottom: 1rem; }
.mt-4 { margin-top: 1rem; }
.text-xs { font-size: 0.75rem; }
.text-sm { font-size: 0.875rem; }
.break-all { word-break: break-all; }

/* Search input */
.search-input { width: 100%; padding: 0.75rem 1rem; border: 1px solid var(--border); border-radius: 8px; font-size: 1rem; transition: all 0.2s ease; background: transparent; color: var(--text); }
.search-input:focus { outline: none; border-color: var(--focus); box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.08); }
.search-input::placeholder { color: var(--placeholder); }

/* Panel (folder view) styling to override Tailwind utility classes in a theme-aware way */
.panel { background: var(--card-bg); border-radius: 16px; box-shadow: 0 6px 18px var(--card-shadow); border: 1px solid var(--border); overflow: hidden; }
.panel-header { padding: 1rem; border-bottom: 1px solid var(--row-border); display: flex; justify-content: space-between; align-items: center; background: transparent; }
.panel .file-list { border-top: none; }
.up-btn { font-size: 0.7rem; font-weight: 700; color: var(--focus); text-transform: uppercase; letter-spacing: 0.08em; background: transparent; border: none; cursor: pointer; }
.muted { color: var(--muted); }
