.upload-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem 3rem;
}

.upload-card {
  width: min(1080px, 96vw);
  padding: 1.4rem;
  display: grid;
  gap: 1rem;
}

.hero {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
}

.logo-title {
  font-size: clamp(1.6rem, 2.8vw, 2.6rem);
  font-weight: 700;
  letter-spacing: -0.02em;
}

.hero p {
  color: var(--text-dim);
}

/* ── Tab Navigation ─────────────────────────────── */

.tab-nav {
  display: flex;
  gap: 0.4rem;
  padding: 0.35rem;
  border-radius: 16px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.tab-btn {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.5rem;
  padding: 0.7rem 1rem;
  border: 1px solid transparent;
  border-radius: 12px;
  background: transparent;
  color: var(--text-dim);
  font-size: 0.92rem;
  font-weight: 500;
  cursor: pointer;
  transition: all 0.25s ease;
}

.tab-btn:hover {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.06);
}

.tab-btn.active {
  color: var(--text-primary);
  background: rgba(255, 255, 255, 0.1);
  border-color: rgba(255, 255, 255, 0.15);
  box-shadow: 0 2px 12px rgba(0, 0, 0, 0.2);
}

.tab-icon {
  font-size: 1.1rem;
}

/* ── Tab Panels ─────────────────────────────────── */

.tab-panel {
  display: none;
}

.tab-panel.active {
  display: block;
}

/* ── Upload Grid ────────────────────────────────── */

.upload-grid {
  display: grid;
  gap: 1rem;
  grid-template-columns: 1.2fr 1fr;
}

.upload-grid > * {
  min-width: 0;
}

.upload-zone {
  border: 1px dashed rgba(255, 255, 255, 0.3);
  border-radius: 20px;
  min-height: 180px;
  display: grid;
  place-items: center;
  text-align: center;
  padding: 1.5rem;
  background: rgba(255, 255, 255, 0.03);
  cursor: pointer;
  transition: border-color 0.2s ease, background 0.2s ease;
}

.upload-zone.dragging {
  border-color: var(--accent);
  background: rgba(255, 94, 91, 0.1);
}

.upload-zone strong {
  display: block;
  font-size: 1.1rem;
  margin-bottom: 0.3rem;
}

.config-panel {
  display: grid;
  gap: 0.95rem;
  align-content: start;
}

.config-row {
  display: grid;
  gap: 0.35rem;
}

.config-row label {
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.config-row input[type="number"] {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.04);
  padding: 0.5rem 0.65rem;
}

.pages-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.8rem;
}

.meta-line {
  font-size: 0.88rem;
  color: var(--text-dim);
}

/* ── Reader Mode Toggle ─────────────────────────── */

.reader-mode-select {
  display: flex;
  gap: 0.35rem;
  padding: 0.25rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid rgba(255, 255, 255, 0.08);
}

.mode-btn {
  padding: 0.5rem 1rem !important;
  font-size: 0.85rem !important;
  border-radius: 10px !important;
  min-width: 90px;
  transition: all 0.2s ease;
}

.mode-btn.active {
  background: rgba(255, 94, 91, 0.18) !important;
  border-color: var(--accent) !important;
  box-shadow: 0 0 14px var(--accent-glow) !important;
  color: var(--text-primary) !important;
}

/* ── Preview Shell ──────────────────────────────── */

.preview-shell {
  display: grid;
  gap: 0.75rem;
  grid-template-columns: 1fr 280px;
  margin-top: 0.5rem;
}

.preview-shell > * {
  min-width: 0;
}

.page-strip {
  display: flex;
  width: 100%;
  max-width: 100%;
  overflow-x: auto;
  overflow-y: hidden;
  gap: 0.7rem;
  padding-bottom: 0.55rem;
  scroll-behavior: smooth;
  overscroll-behavior-x: contain;
  scrollbar-gutter: stable;
}

.thumb {
  flex: 0 0 100px;
  max-width: 100px;
  display: grid;
  gap: 0.35rem;
}

.page-strip::-webkit-scrollbar {
  height: 10px;
}

.page-strip::-webkit-scrollbar-track {
  background: rgba(255, 255, 255, 0.06);
  border-radius: 999px;
}

.page-strip::-webkit-scrollbar-thumb {
  background: rgba(255, 255, 255, 0.24);
  border-radius: 999px;
}

.page-strip::-webkit-scrollbar-thumb:hover {
  background: rgba(255, 255, 255, 0.36);
}

.thumb canvas {
  width: 100%;
  border-radius: 10px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  background: rgba(255, 255, 255, 0.05);
}

.thumb span {
  text-align: center;
  font-size: 0.75rem;
  color: var(--text-dim);
}

.sentences-preview {
  padding: 0.85rem;
  border-radius: 14px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
}

.sentences-preview h3 {
  font-size: 0.84rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
  margin-bottom: 0.65rem;
}

.sentences-preview ol {
  margin: 0;
  padding-left: 1rem;
  display: grid;
  gap: 0.45rem;
  font-size: 0.86rem;
  color: rgba(255, 255, 255, 0.8);
}

/* ── Actions ────────────────────────────────────── */

.actions {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  flex-wrap: wrap;
  margin-top: 0.5rem;
}

.actions .left {
  display: flex;
  gap: 0.75rem;
  align-items: center;
  color: var(--text-dim);
}

.start-btn {
  min-width: 190px;
}

/* ── Library Grid ───────────────────────────────── */

.library-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 0.75rem;
}

.library-title {
  font-size: 1.1rem;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.library-meta {
  font-size: 0.85rem;
  color: var(--text-dim);
}

.library-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 0.85rem;
}

.library-card {
  padding: 1.1rem;
  display: grid;
  gap: 0.8rem;
  transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
  cursor: default;
}

.library-card:hover {
  transform: translateY(-2px);
  box-shadow: 0 14px 48px rgba(0, 0, 0, 0.5), inset 0 1px 0 rgba(255, 255, 255, 0.09);
  border-color: rgba(255, 255, 255, 0.2);
}

.library-card.loading {
  opacity: 0.5;
  pointer-events: none;
}

.library-card-body {
  display: grid;
  gap: 0.35rem;
}

.library-card-icon {
  font-size: 1.6rem;
  line-height: 1;
}

.library-card-title {
  font-size: 1rem;
  font-weight: 600;
  line-height: 1.3;
  margin: 0;
}

.library-card-meta {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.library-card-actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 0.4rem;
}

.library-action-btn {
  font-size: 0.82rem !important;
  padding: 0.5rem 0.6rem !important;
  text-align: center;
}

.library-wpm-row {
  display: flex;
  align-items: center;
  gap: 0.8rem;
  margin-top: 0.75rem;
  padding: 0.7rem 0.9rem;
  border-radius: 14px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}

.library-wpm-row label {
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--text-dim);
  white-space: nowrap;
}

.library-wpm-row input[type="range"] {
  flex: 1;
  accent-color: var(--accent);
}

.library-wpm-row strong {
  font-size: 0.88rem;
  white-space: nowrap;
  min-width: 70px;
  text-align: right;
}

.library-loading {
  grid-column: 1 / -1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.65rem;
  padding: 2rem;
  color: var(--text-dim);
}

.library-empty {
  grid-column: 1 / -1;
  text-align: center;
  padding: 2rem;
  color: var(--text-dim);
}

.spinner {
  width: 20px;
  height: 20px;
  border: 2px solid rgba(255, 255, 255, 0.15);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

/* ── Saved Books ────────────────────────────────── */

.saved-books {
  padding: 0.9rem;
  display: grid;
  gap: 0.7rem;
}

.saved-books-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 0.75rem;
}

.saved-books-head h3 {
  font-size: 0.9rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-dim);
}

.saved-books-list {
  display: grid;
  gap: 0.55rem;
}

.saved-empty {
  color: var(--text-dim);
  font-size: 0.9rem;
}

.saved-book-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 0.65rem;
  align-items: center;
  padding: 0.65rem 0.75rem;
  border-radius: 12px;
  border: 1px solid rgba(255, 255, 255, 0.1);
  background: rgba(255, 255, 255, 0.03);
}

.saved-book-info {
  min-width: 0;
}

.saved-book-title {
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.saved-book-meta {
  font-size: 0.8rem;
  color: var(--text-dim);
}

.saved-book-actions {
  display: flex;
  gap: 0.35rem;
}

.saved-action-btn {
  min-width: 72px;
  padding: 0.42rem 0.5rem !important;
  font-size: 0.8rem !important;
}

/* ── Responsive ─────────────────────────────────── */

@media (max-width: 980px) {
  .upload-grid,
  .preview-shell {
    grid-template-columns: 1fr;
  }

  .upload-card {
    padding: 1rem;
  }

  .hero {
    align-items: start;
    flex-direction: column;
  }

  .saved-book-row {
    grid-template-columns: 1fr;
  }

  .saved-book-actions {
    width: 100%;
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
  }

  .library-grid {
    grid-template-columns: 1fr;
  }

  .actions {
    flex-direction: column;
    align-items: stretch;
  }

  .reader-mode-select {
    justify-content: center;
  }
}
