/* ===== RESET ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

/* ===== TOKENS ===== */
:root {
  --bg:       #F5F5F7;
  --surface:  #FFFFFF;
  --ink:      #1D1D1F;
  --secondary:#6E6E73;
  --tertiary: #AEAEB2;
  --border:   #D2D2D7;
  --r:        16px;
  --r-sm:     10px;
  --shadow:   0 2px 12px rgba(0,0,0,.07), 0 1px 3px rgba(0,0,0,.04);
  --shadow-lg:0 8px 32px rgba(0,0,0,.11), 0 2px 8px rgba(0,0,0,.06);
}

/* ===== BASE ===== */
body {
  background: var(--bg);
  color: var(--ink);
  font: 15px/1.6 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Apple SD Gothic Neo", sans-serif;
  -webkit-font-smoothing: antialiased;
}
a { color: inherit; text-decoration: none; }
h1 { font-size: 38px; font-weight: 700; letter-spacing: -1.5px; line-height: 1.15; }
h2 { font-size: 20px; font-weight: 700; letter-spacing: -0.4px; }
p  { color: var(--secondary); font-size: 15px; }

/* ===== HEADER ===== */
.site-header {
  position: sticky; top: 0; z-index: 100;
  height: 52px;
  display: flex; align-items: center; gap: 8px;
  padding: 0 28px;
  background: rgba(245,245,247,.85);
  backdrop-filter: saturate(180%) blur(20px);
  -webkit-backdrop-filter: saturate(180%) blur(20px);
  border-bottom: 1px solid rgba(210,210,215,.7);
}
.logo {
  font-size: 16px; font-weight: 700; letter-spacing: -0.5px;
  display: flex; align-items: center; gap: 8px;
}
.logo span {
  font-size: 9px; letter-spacing: 2.5px; font-weight: 500; color: var(--tertiary);
}
.header-nav { display: flex; align-items: center; gap: 4px; margin-left: auto; }

/* ===== BUTTONS ===== */
button, .button {
  display: inline-flex; align-items: center; justify-content: center;
  border: none; border-radius: 980px;
  background: var(--ink); color: #fff;
  padding: 7px 16px;
  font: inherit; font-size: 13px; font-weight: 500;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  white-space: nowrap;
}
button:hover, .button:hover  { opacity: .8; }
button:active, .button:active { transform: scale(.97); }
button:disabled               { opacity: .35; cursor: default; }

.subtle {
  background: rgba(0,0,0,.06);
  color: var(--ink);
}
.subtle:hover { background: rgba(0,0,0,.1); opacity: 1; }

/* ===== INPUTS ===== */
input, select, textarea {
  font: inherit; font-size: 15px;
  padding: 12px 16px;
  border: 1px solid var(--border);
  border-radius: var(--r-sm);
  background: var(--surface); color: var(--ink);
  width: 100%; min-width: 0;
  -webkit-appearance: none;
  transition: border-color .15s, box-shadow .15s;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(0,0,0,.08);
}
a:focus-visible, button:focus-visible {
  outline: 3px solid rgba(0,0,0,.2); outline-offset: 2px;
}

/* ===== LAYOUT ===== */
.library { max-width: 1120px; padding: 0 28px; margin: auto; }

/* ===== HERO ===== */
.intro { padding: 60px 0 28px; }
.eyebrow {
  font-size: 11px; letter-spacing: 2.5px; font-weight: 500;
  color: var(--tertiary); text-transform: uppercase; margin-bottom: 10px;
}

/* ===== SEARCH ===== */
.search { display: flex; gap: 8px; max-width: 520px; margin: 12px 0 52px; }
.search input { flex: 1; border-radius: 980px; padding: 10px 18px; }
.search button { border-radius: 980px; padding: 10px 20px; }

/* ===== SECTION HEADING ===== */
.section-heading {
  display: flex; align-items: center; justify-content: space-between;
  margin: 44px 0 18px;
}
.section-heading span { font-size: 12px; color: var(--tertiary); }

/* ===== GRID ===== */
.grid { display: grid; grid-template-columns: repeat(4, minmax(0,1fr)); gap: 20px; }

/* ===== BOOK CARD ===== */
.book-card-wrap { position: relative; }

.book-card {
  display: block;
  background: var(--surface);
  border-radius: var(--r);
  overflow: hidden;
  box-shadow: var(--shadow);
  transition: box-shadow .25s, transform .25s;
}
.book-card:hover { box-shadow: var(--shadow-lg); transform: translateY(-4px); }

.cover-img {
  width: 100%; aspect-ratio: 2/3; object-fit: cover; display: block;
}

.cover {
  aspect-ratio: 2/3;
  display: flex; flex-direction: column; justify-content: flex-end;
  padding: 20px; gap: 4px;
}
.book-card-wrap:nth-child(4n+1) .cover { background: linear-gradient(150deg,#E3EAE5,#C5D8CC); }
.book-card-wrap:nth-child(4n+2) .cover { background: linear-gradient(150deg,#EDE8DF,#D8CABB); }
.book-card-wrap:nth-child(4n+3) .cover { background: linear-gradient(150deg,#DEE7ED,#C0D2DC); }
.book-card-wrap:nth-child(4n+4) .cover { background: linear-gradient(150deg,#EDE0DE,#D8B8B5); }

.cover span  { font-size: 9px; letter-spacing: 2px; color: rgba(0,0,0,.4); font-weight: 600; }
.cover strong{ font-size: 17px; font-weight: 700; line-height: 1.3; color: #1D1D1F; overflow-wrap: anywhere; }
.cover small  { font-size: 11px; color: rgba(0,0,0,.45); }

.book-card h3 {
  font-size: 13px; font-weight: 600; color: var(--ink);
  padding: 12px 14px 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.book-card p {
  font-size: 12px; color: var(--secondary);
  padding: 0 14px 14px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.progress-text { font-size: 11px; color: var(--tertiary) !important; padding-bottom: 12px !important; }

/* admin hover btns */
.edit-btn, .delete-btn {
  position: absolute; top: 10px;
  width: 30px; height: 30px; border-radius: 50%; padding: 0;
  display: flex; align-items: center; justify-content: center;
  font-size: 13px;
  background: rgba(255,255,255,.92); color: var(--ink);
  backdrop-filter: blur(4px);
  opacity: 0; transition: opacity .15s;
  box-shadow: 0 1px 4px rgba(0,0,0,.15);
}
.edit-btn   { right: 46px; }
.delete-btn { right: 10px; }
.book-card-wrap:hover .edit-btn,
.book-card-wrap:hover .delete-btn { opacity: 1; }

.empty {
  grid-column: 1 / -1;
  padding: 48px;
  border: 1.5px dashed var(--border);
  border-radius: var(--r);
  text-align: center;
  font-size: 14px;
  color: var(--secondary);
}

/* ===== FOOTER ===== */
footer {
  padding: 64px 0 28px;
  font-size: 12px; color: var(--tertiary);
  text-align: center; letter-spacing: .5px;
}

/* ===== AUTH / FORM PAGES ===== */
.upload-page { max-width: 420px; padding: 72px 24px; margin: auto; }
.upload-page h1 { font-size: 30px; margin: 8px 0 4px; }

.upload-page form {
  display: flex; flex-direction: column; gap: 10px;
  margin-top: 28px;
}
.upload-page form > label:not(.drop-zone) {
  font-size: 13px; font-weight: 600; color: var(--secondary);
  margin-top: 6px;
}
.upload-page form button[type="submit"] {
  width: 100%; border-radius: var(--r-sm);
  padding: 14px; font-size: 15px; margin-top: 6px;
}

.auth-divider {
  display: flex; align-items: center; gap: 12px;
  margin: 20px 0; color: var(--tertiary); font-size: 12px;
}
.auth-divider::before, .auth-divider::after {
  content: ''; flex: 1; height: 1px; background: var(--border);
}

.google-btn {
  display: flex; align-items: center; justify-content: center; gap: 10px;
  width: 100%; border-radius: var(--r-sm);
  padding: 13px; font-size: 15px; font-weight: 500;
  background: var(--surface); color: var(--ink);
  border: 1.5px solid var(--border);
}
.google-btn:hover { background: var(--bg); opacity: 1; }
.google-btn svg { flex-shrink: 0; }

/* ===== DROPZONE ===== */
.drop-zone {
  padding: 32px 20px; margin: 8px 0;
  border: 1.5px dashed var(--border); border-radius: var(--r-sm);
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  text-align: center; cursor: pointer;
  transition: border-color .15s, background .15s;
}
.drop-zone:hover, .dragging { border-color: var(--ink); background: rgba(0,0,0,.02); }
.drop-zone span { font-size: 13px; color: var(--secondary); }
.drop-zone input { max-width: 100%; font-size: 13px; }

/* ===== PROFILE ===== */
.stat-row { display: flex; gap: 16px; flex-wrap: wrap; margin-bottom: 44px; }
.stat-card {
  background: var(--surface); border-radius: var(--r);
  padding: 24px 36px; text-align: center; min-width: 130px;
  box-shadow: var(--shadow);
}
.stat-num { font-size: 36px; font-weight: 700; letter-spacing: -1px; color: var(--ink); }
.stat-label { font-size: 13px; color: var(--secondary); margin-top: 4px; }

/* progress bar */
.progress-bar-track {
  height: 4px; background: var(--bg); border-radius: 2px; overflow: hidden; margin: 6px 0 3px;
}
.progress-bar-fill { height: 100%; background: var(--ink); border-radius: 2px; }

/* ===== READER ===== */
.reader { height: 100dvh; display: flex; flex-direction: column; background: #fff; }

.reader-header {
  display: flex; align-items: center; gap: 16px;
  padding: 12px 24px;
  border-bottom: 1px solid var(--border);
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(12px);
}
.reader-header h1 {
  flex: 1; text-align: center;
  font-size: 15px; font-weight: 600; letter-spacing: -0.3px;
  white-space: nowrap; text-overflow: ellipsis; overflow: hidden;
}
.reader-header a, .reader-header span { font-size: 13px; color: var(--secondary); }
.reader-header button { color: #333; }

.progress-track { height: 2px; background: var(--border); flex-shrink: 0; }
#progress-bar   { height: 100%; background: var(--ink); width: 0; transition: width .3s; }
#viewer         { flex: 1; min-height: 0; overflow: hidden; }

.reader-controls {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 24px;
  border-top: 1px solid var(--border);
  background: rgba(255,255,255,.9);
  backdrop-filter: blur(12px);
}
.reader-controls span { text-align: center; font-size: 12px; color: var(--secondary); }
.reader-controls button { border-radius: 980px; padding: 8px 16px; font-size: 13px; }

.speech-controls {
  display: flex; align-items: center; gap: 8px; flex-wrap: wrap;
  padding: 8px 24px;
  background: var(--bg); border-bottom: 1px solid var(--border);
  font-size: 13px;
}
.speech-controls button { border-radius: 980px; padding: 6px 14px; font-size: 13px; }
.speech-controls select {
  padding: 5px 10px; width: auto;
  border: 1px solid var(--border); border-radius: 8px;
  background: var(--surface); font-size: 13px;
}
.speech-controls span { color: var(--secondary); font-size: 12px; }
.star-btn { background: none; color: var(--ink); border-radius: 0; padding: 0; min-width: 0; }
.star-btn:hover { background: none; opacity: 1; }

#viewer.pdf-viewer { overflow: auto; background: #E5E5EA; text-align: center; padding: 16px; }
.pdf-viewer canvas  { display: block; margin: 0 auto; box-shadow: 0 2px 16px rgba(0,0,0,.12); max-width: 100%; height: auto !important; }

/* ===== UTILITY ===== */
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0,0,0,0); }
[hidden]  { display: none !important; }

/* ===== BOOK LIST PAGE ===== */
.filter-row { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 12px; }
.filter-row .button.active, .filter-row .subtle.active {
  background: var(--ink); color: #fff;
}

/* ===== RESPONSIVE ===== */
@media (max-width: 768px) {
  .site-header { padding: 0 16px; }
  h1 { font-size: 26px; }
  .library { padding: 0 16px; }
  .intro { padding: 36px 0 20px; }
  .grid { grid-template-columns: repeat(2, minmax(0,1fr)); gap: 14px; }
  .search { margin-bottom: 32px; }
  .reader-header { padding: 10px 14px; }
  .reader-controls { padding: 10px 12px; }
  .reader-controls button { padding: 8px 12px; font-size: 12px; }
  .speech-controls { padding: 8px 12px; }
  .upload-page { padding: 48px 20px; }
}
