/* eReader shared styles. Designed for e-ink first: no animations, high contrast, big targets. */
:root {
  --bg: #ffffff;
  --fg: #111111;
  --muted: #555555;
  --line: #cfcfcf;
  --panel: #f4f4f4;
  --accent: #1a1a1a;
  --accent-fg: #ffffff;
  --danger: #a11;
  --radius: 6px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-left: env(safe-area-inset-left, 0px);
  --safe-right: env(safe-area-inset-right, 0px);
  --ui-font: system-ui, -apple-system, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #121212;
  --fg: #e6e6e6;
  --muted: #a5a5a5;
  --line: #3a3a3a;
  --panel: #1e1e1e;
  --accent: #e6e6e6;
  --accent-fg: #121212;
  --danger: #ff7b7b;
  color-scheme: dark;
}
:root[data-theme="sepia"] {
  --bg: #f6ecd9;
  --fg: #4a3b2a;
  --muted: #7a6a55;
  --line: #d9c9ad;
  --panel: #efe2c8;
  --accent: #4a3b2a;
  --accent-fg: #f6ecd9;
}
:root[data-eink="1"] {
  --bg: #ffffff;
  --fg: #000000;
  --muted: #000000;
  --line: #000000;
  --panel: #ffffff;
  --accent: #000000;
  --accent-fg: #ffffff;
}
:root[data-eink="1"][data-theme="dark"] {
  --bg: #000000;
  --fg: #ffffff;
  --muted: #ffffff;
  --line: #ffffff;
  --panel: #000000;
  --accent: #ffffff;
  --accent-fg: #000000;
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--fg); }
body { font-family: var(--ui-font); font-size: 16px; line-height: 1.4; -webkit-text-size-adjust: 100%; -webkit-tap-highlight-color: transparent; }
a { color: inherit; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
img { max-width: 100%; }
.hidden { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); }

/* Buttons and forms */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: .4em;
  min-height: 44px; padding: 0 16px; border: 2px solid var(--fg); border-radius: var(--radius);
  background: var(--bg); color: var(--fg); text-decoration: none; font-weight: 600; white-space: nowrap;
}
.btn.primary { background: var(--accent); color: var(--accent-fg); border-color: var(--accent); }
.btn.danger { border-color: var(--danger); color: var(--danger); }
.btn.small { min-height: 36px; padding: 0 12px; font-size: 14px; }
.btn.icon { min-width: 44px; padding: 0 10px; }
.btn:disabled { opacity: .5; cursor: default; }
.btn:focus-visible, input:focus-visible, select:focus-visible { outline: 3px solid var(--fg); outline-offset: 2px; }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field label { font-weight: 600; font-size: 14px; }
.field input, .field select, .field textarea {
  min-height: 44px; padding: 8px 12px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--bg); color: var(--fg); width: 100%;
}
.field input:focus, .field select:focus { border-color: var(--fg); outline: none; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.row.between { justify-content: space-between; }
.muted { color: var(--muted); }
.error { color: var(--danger); font-weight: 600; }
.notice { padding: 10px 14px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--panel); margin: 10px 0; }

/* App header */
.app-header {
  display: flex; align-items: center; gap: 12px; padding: calc(10px + var(--safe-top)) calc(16px + var(--safe-right)) 10px calc(16px + var(--safe-left));
  border-bottom: 2px solid var(--line); position: sticky; top: 0; background: var(--bg); z-index: 5;
}
.app-header .brand { font-weight: 800; font-size: 20px; text-decoration: none; letter-spacing: .5px; }
.app-header .spacer { flex: 1; }
.app-header nav { display: flex; gap: 8px; flex-wrap: wrap; }
main.page { padding: 16px calc(16px + var(--safe-right)) calc(24px + var(--safe-bottom)) calc(16px + var(--safe-left)); max-width: 1200px; margin: 0 auto; }
main.narrow { max-width: 480px; }
h1, h2, h3 { line-height: 1.2; }
h1 { font-size: 24px; margin: 8px 0 16px; }
h2 { font-size: 20px; margin: 20px 0 10px; }

/* Library toolbar */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; margin-bottom: 16px; }
.toolbar input[type="search"] { flex: 1 1 200px; min-height: 44px; padding: 8px 12px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--bg); color: var(--fg); }
.toolbar select { min-height: 44px; padding: 6px 10px; border: 2px solid var(--line); border-radius: var(--radius); background: var(--bg); color: var(--fg); }
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 14px; text-align: center; margin-bottom: 16px; color: var(--muted); }
.dropzone.active { border-color: var(--fg); color: var(--fg); background: var(--panel); }
.uploads { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.uploads .item { display: flex; justify-content: space-between; gap: 10px; padding: 8px 12px; border: 2px solid var(--line); border-radius: var(--radius); font-size: 14px; }

/* Book grid */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)); gap: 16px; }
@media (min-width: 600px) { .grid { grid-template-columns: repeat(auto-fill, minmax(170px, 1fr)); } }
.card { position: relative; display: flex; flex-direction: column; border: 2px solid var(--line); border-radius: var(--radius); overflow: hidden; background: var(--bg); text-decoration: none; }
.card:focus-within, .card:hover { border-color: var(--fg); }
.card .cover { display: block; aspect-ratio: 2 / 3; width: 100%; object-fit: cover; background: var(--panel); border-bottom: 2px solid var(--line); }
.card .cover.placeholder { display: flex; flex-direction: column; justify-content: center; align-items: center; text-align: center; padding: 12px; gap: 6px; font-weight: 700; }
.card .cover.placeholder .t { font-size: 16px; line-height: 1.2; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 5; -webkit-box-orient: vertical; }
.card .cover.placeholder .a { font-size: 12px; font-weight: 500; color: var(--muted); }
.card .info { padding: 10px 10px 8px; display: flex; flex-direction: column; gap: 4px; flex: 1; }
.card .title { font-weight: 700; font-size: 14px; line-height: 1.25; overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; }
.card .author { font-size: 13px; color: var(--muted); overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }
.card .meta { display: flex; justify-content: space-between; align-items: center; font-size: 12px; color: var(--muted); margin-top: auto; }
.badge { display: inline-block; padding: 1px 6px; border: 1px solid var(--line); border-radius: 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; }
.progress { height: 8px; border: 1px solid var(--fg); border-radius: 4px; overflow: hidden; background: var(--bg); }
.progress > div { height: 100%; background: var(--fg); }
.card .menu-btn { position: absolute; top: 6px; right: 6px; width: 40px; height: 40px; border-radius: 50%; border: 2px solid var(--fg); background: var(--bg); color: var(--fg); font-weight: 800; font-size: 18px; line-height: 1; }
.card .status { position: absolute; left: 0; right: 0; top: 40%; text-align: center; font-weight: 700; background: var(--bg); padding: 8px; border-top: 2px solid var(--fg); border-bottom: 2px solid var(--fg); }
.card .status.err { color: var(--danger); }
.card .link { position: absolute; top: 0; right: 0; bottom: 0; left: 0; }
.empty { text-align: center; padding: 40px 20px; color: var(--muted); }
.section-title { display: flex; align-items: baseline; gap: 10px; margin: 20px 0 10px; }

/* Dialog / sheet */
.sheet-backdrop { position: fixed; top: 0; right: 0; bottom: 0; left: 0; background: rgba(0,0,0,.35); z-index: 20; }
.sheet { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(92vw, 420px); max-height: 90vh; overflow: auto; background: var(--bg); color: var(--fg); border: 2px solid var(--fg); border-radius: var(--radius); padding: 18px; z-index: 21; }
.sheet h2 { margin-top: 0; }
.menu { display: flex; flex-direction: column; gap: 8px; }
.menu .btn { justify-content: flex-start; }

/* Tables */
table.list { width: 100%; border-collapse: collapse; }
table.list th, table.list td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
table.list th { font-size: 13px; text-transform: uppercase; letter-spacing: .5px; color: var(--muted); }

.toast { position: fixed; left: 50%; bottom: calc(24px + var(--safe-bottom)); transform: translateX(-50%); background: var(--fg); color: var(--bg); padding: 10px 16px; border-radius: var(--radius); z-index: 50; max-width: 90vw; text-align: center; font-weight: 600; }
