/* ─── Reset & Base ──────────────────────────────────────────────────────────── */

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

:root {
  --bg:           #0d0d0d;
  --bg-card:      #161616;
  --bg-hover:     #22242c;
  --border:       #2a2a2a;
  --accent:       #FF6B35;
  --accent-hover: #c94e1f;
  --accent-dim:   rgba(255, 107, 53, 0.15);
  --btn-text:     #0d0d0d;
  --accent-text:  #FF6B35;
  --text:         #f0f0f0;
  --text-muted:   #8a8a8a;
  --text-dim:     #4a4a4a;
  --success:      #34d399;
  --error:        #f87171;
  --warning:      #fbbf24;
  --radius:       12px;
  --radius-sm:    8px;
  --shadow:       0 4px 24px rgba(0, 0, 0, 0.4);
}

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: 'Inter', system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  font-size: 15px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

/* ─── Layout ────────────────────────────────────────────────────────────────── */

.screen {
  display: none;
  min-height: 100vh;
  padding: 40px 20px;
}

.screen.active {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.card {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 40px;
  width: 100%;
  max-width: 480px;
  box-shadow: var(--shadow);
}

.card-wide {
  max-width: 640px;
}

/* ─── Wordmark / Logo ────────────────────────────────────────────────────────── */

.wordmark {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 32px;
}

.wordmark-icon {
  flex-shrink: 0;
}

.wordmark h1 {
  font-size: 18px;
  font-weight: 700;
  color: var(--text);
  letter-spacing: -0.3px;
}

.wordmark-sub {
  font-size: 9px;
  font-weight: 400;
  letter-spacing: 2.5px;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ─── Typography ────────────────────────────────────────────────────────────── */

h2 {
  font-size: 22px;
  font-weight: 700;
  letter-spacing: -0.4px;
  margin-bottom: 8px;
}

h3 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 12px;
  color: var(--text);
}

p.subtitle {
  color: var(--text-muted);
  font-size: 14px;
  margin-bottom: 28px;
}

/* ─── Buttons ────────────────────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 20px;
  border-radius: var(--radius-sm);
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  border: none;
  transition: background 0.15s, opacity 0.15s, transform 0.1s;
  text-decoration: none;
  white-space: nowrap;
  user-select: none;
}

.btn:active {
  transform: scale(0.98);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: var(--btn-text);
  width: 100%;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-primary:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-google {
  background: #fff;
  color: #222;
  width: 100%;
  border: 1px solid #ddd;
}

.btn-google:hover {
  background: #f5f5f5;
}

.btn-ghost {
  background: transparent;
  color: var(--text-muted);
  font-size: 13px;
  padding: 8px 12px;
}

.btn-ghost:hover {
  color: var(--text);
  background: var(--bg-hover);
}

.btn-outline {
  background: transparent;
  color: var(--accent-text);
  border: 1px solid var(--accent);
  width: 100%;
}

.btn-outline:hover {
  background: var(--accent-dim);
}

/* ─── ToS consent checkbox ───────────────────────────────────────────────────── */

.tos-consent {
  display: flex;
  align-items: flex-start;
  gap: 8px;
  margin-bottom: 16px;
  font-size: 12.5px;
  font-weight: 400;
  line-height: 1.4;
  color: var(--text-muted);
  cursor: pointer;
}

.tos-consent input[type="checkbox"] {
  flex-shrink: 0;
  margin-top: 2px;
  width: 15px;
  height: 15px;
  accent-color: var(--accent);
  cursor: pointer;
}

.tos-consent a {
  color: var(--text);
  text-decoration: underline;
}

.tos-consent a:hover {
  color: var(--accent-text);
}

/* ─── Divider ────────────────────────────────────────────────────────────────── */

.divider {
  display: flex;
  align-items: center;
  gap: 12px;
  color: var(--text-dim);
  font-size: 12px;
  margin: 20px 0;
}

.divider::before,
.divider::after {
  content: '';
  flex: 1;
  height: 1px;
  background: var(--border);
}

/* ─── Forms ─────────────────────────────────────────────────────────────────── */

.form-group {
  margin-bottom: 16px;
}

label {
  display: block;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="email"],
input[type="text"],
select {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text);
  font-size: 14px;
  padding: 10px 14px;
  outline: none;
  transition: border-color 0.15s;
  appearance: none;
}

input[type="email"]:focus,
input[type="text"]:focus,
select:focus {
  border-color: var(--accent);
}

input::placeholder {
  color: var(--text-dim);
}

select {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%237a7f9a' d='M0 0l6 8 6-8z'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 14px center;
  padding-right: 36px;
  cursor: pointer;
}

select option {
  background: var(--bg-card);
}

/* ─── Magic-link form ───────────────────────────────────────────────────────── */

#magic-link-section {
  display: none;
}

#magic-link-section.visible {
  display: block;
  margin-top: 16px;
  animation: fadeIn 0.2s ease;
}

.success-notice {
  background: rgba(52, 211, 153, 0.1);
  border: 1px solid rgba(52, 211, 153, 0.3);
  border-radius: var(--radius-sm);
  color: var(--success);
  font-size: 13px;
  padding: 12px 14px;
  text-align: center;
}

/* ─── Drop zone ─────────────────────────────────────────────────────────────── */

#drop-zone {
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  padding: 36px 24px;
  text-align: center;
  cursor: pointer;
  transition: border-color 0.15s, background 0.15s;
  position: relative;
}

#drop-zone:hover,
#drop-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-dim);
}

#drop-zone p {
  color: var(--text-muted);
  font-size: 14px;
  margin: 8px 0 0;
}

#drop-zone .drop-icon {
  font-size: 32px;
  display: block;
  margin-bottom: 8px;
}

#file-input {
  position: absolute;
  inset: 0;
  opacity: 0;
  cursor: pointer;
}

.file-chosen {
  margin-top: 12px;
  font-size: 13px;
  color: var(--accent-text);
  font-weight: 500;
  word-break: break-all;
}

/* ─── Upload progress bar ────────────────────────────────────────────────────── */

.upload-progress {
  display: none;
  margin-top: 12px;
}

.upload-progress.visible {
  display: block;
}

.progress-bar-wrap {
  background: var(--border);
  border-radius: 100px;
  height: 6px;
  overflow: hidden;
}

.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 100px;
  transition: width 0.2s ease;
  width: 0%;
}

.progress-label {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 6px;
  text-align: right;
}

/* ─── Analysis results ───────────────────────────────────────────────────────── */

#analysis-results {
  display: none;
  margin-top: 20px;
  animation: fadeIn 0.25s ease;
}

#analysis-results.visible {
  display: block;
}

.stats-row {
  display: flex;
  gap: 12px;
  margin-bottom: 16px;
}

.stat-box {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  text-align: center;
}

.stat-box .stat-value {
  font-size: 20px;
  font-weight: 700;
  color: var(--accent-text);
}

.stat-box .stat-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 2px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.characters-list {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  margin-bottom: 16px;
  font-size: 13px;
}

.characters-list strong {
  display: block;
  color: var(--text-muted);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  margin-bottom: 8px;
}

.characters-list .char-tags {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}

.char-tag {
  background: var(--accent-dim);
  color: var(--accent-text);
  border-radius: 4px;
  padding: 2px 8px;
  font-size: 12px;
}

/* ─── Processing screen ───────────────────────────────────────────────────────── */

.processing-icon {
  font-size: 48px;
  margin-bottom: 20px;
  display: block;
  text-align: center;
}

.big-progress-wrap {
  background: var(--border);
  border-radius: 100px;
  height: 10px;
  overflow: hidden;
  margin: 20px 0 8px;
}

.big-progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), #ffb347);
  border-radius: 100px;
  transition: width 0.4s ease;
  width: 0%;
}

#processing-percent {
  font-size: 13px;
  color: var(--text-muted);
  text-align: right;
  margin-bottom: 16px;
}

#processing-status-text {
  font-size: 14px;
  color: var(--text-muted);
  text-align: center;
  min-height: 22px;
}

.status-labels {
  display: flex;
  justify-content: space-between;
  font-size: 11px;
  color: var(--text-dim);
  margin-top: 16px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}

.status-labels span.active-step {
  color: var(--accent-text);
}

#processing-error {
  display: none;
  background: rgba(248, 113, 113, 0.1);
  border: 1px solid rgba(248, 113, 113, 0.3);
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 13px;
  padding: 14px 16px;
  margin-top: 20px;
  text-align: center;
}

#processing-error.visible {
  display: block;
}

/* ─── Done screen ────────────────────────────────────────────────────────────── */

.done-icon {
  font-size: 56px;
  display: block;
  text-align: center;
  margin-bottom: 16px;
}

.done-title {
  text-align: center;
  margin-bottom: 6px;
}

.done-subtitle {
  text-align: center;
  margin-bottom: 28px;
}

.btn-download {
  background: var(--success);
  color: #0a2e1f;
  font-weight: 700;
  width: 100%;
  font-size: 15px;
  padding: 14px 20px;
}

.btn-download:hover {
  background: #2ec488;
}

/* ─── User badge ─────────────────────────────────────────────────────────────── */

.user-badge {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 20px;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
}

.user-badge .user-info {
  display: flex;
  flex-direction: column;
  gap: 2px;
  overflow: hidden;
}

.user-badge .user-email {
  font-size: 13px;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 260px;
}

.user-badge .balance-text {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.user-badge .balance-actions {
  display: flex;
  align-items: center;
  gap: 16px;
  margin-left: 12px;
  white-space: nowrap;
}

.btn-text {
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  padding: 0;
}

.btn-text:hover {
  color: var(--text);
}

.btn-cta {
  background: var(--accent);
  color: var(--btn-text);
  border: none;
  border-radius: var(--radius-sm);
  padding: 7px 14px;
  font-size: 13px;
  font-weight: 700;
  cursor: pointer;
}

.btn-cta:hover {
  background: var(--accent-hover);
}

/* ─── Pricing modal ──────────────────────────────────────────────────────────── */

#pricing-modal {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.7);
  backdrop-filter: blur(4px);
  z-index: 7500;
  align-items: center;
  justify-content: center;
  padding: 16px;
}

#pricing-modal.visible {
  display: flex;
}

#pricing-modal .card {
  position: relative;
  max-height: 90vh;
  overflow-y: auto;
}

.modal-close {
  position: absolute;
  top: 14px;
  right: 14px;
  background: transparent;
  border: none;
  color: var(--text-muted);
  font-size: 22px;
  line-height: 1;
  cursor: pointer;
  padding: 4px;
}

.modal-close:hover {
  color: var(--text);
}

.pricing-packages {
  margin-top: 16px;
}

.pkg-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
  margin-bottom: 10px;
}

.pkg-card.featured {
  border-color: var(--accent);
}

.pkg-info .pkg-name {
  font-weight: 600;
  font-size: 14px;
}

.pkg-info .pkg-name .pkg-badge {
  display: inline-block;
  margin-left: 6px;
  font-size: 10px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  color: var(--accent-text);
  background: var(--accent-dim);
  border-radius: 100px;
  padding: 2px 8px;
  vertical-align: middle;
}

.pkg-info .pkg-chars {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 2px;
}

.pkg-buy {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 6px;
  flex-shrink: 0;
}

.pkg-buy .pkg-price {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.btn-sm {
  width: auto;
  padding: 7px 16px;
  font-size: 13px;
}

/* ─── Spinner ────────────────────────────────────────────────────────────────── */

.spinner {
  display: inline-block;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.25);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
  flex-shrink: 0;
}

.spinner-lg {
  width: 28px;
  height: 28px;
  border-width: 3px;
  border-color: var(--accent-dim);
  border-top-color: var(--accent);
  margin: 0 auto 20px;
}

/* ─── Global error banner ────────────────────────────────────────────────────── */

#error-banner {
  display: none;
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--error);
  color: #fff;
  font-size: 13px;
  font-weight: 500;
  padding: 10px 20px;
  border-radius: var(--radius-sm);
  z-index: 9999;
  max-width: calc(100vw - 32px);
  text-align: center;
  box-shadow: 0 4px 16px rgba(248, 113, 113, 0.4);
  animation: fadeIn 0.2s ease;
}

#error-banner.visible {
  display: block;
}

#error-banner.success {
  background: var(--success);
  box-shadow: 0 4px 16px rgba(52, 211, 153, 0.4);
}

#error-banner.info {
  background: var(--bg-card);
  border: 1px solid var(--border);
  color: var(--text);
  box-shadow: var(--shadow);
}

/* ─── Loading overlay ────────────────────────────────────────────────────────── */

#loading-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(15, 17, 23, 0.7);
  backdrop-filter: blur(4px);
  z-index: 8000;
  align-items: center;
  justify-content: center;
}

#loading-overlay.visible {
  display: flex;
}

/* ─── Utilities ─────────────────────────────────────────────────────────────── */

.mt-8  { margin-top: 8px; }
.mt-12 { margin-top: 12px; }
.mt-16 { margin-top: 16px; }
.mt-20 { margin-top: 20px; }

.text-center { text-align: center; }
.text-muted  { color: var(--text-muted); font-size: 13px; }

.hidden { display: none !important; }

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

@keyframes fadeIn {
  from { opacity: 0; transform: translateY(-6px); }
  to   { opacity: 1; transform: translateY(0); }
}

/* ─── Voice preview ──────────────────────────────────────────────────────────── */

.voice-select-row {
  display: flex;
  gap: 8px;
}

.voice-select-row select {
  flex: 1;
}

.voice-select-row .btn {
  width: auto;
  flex-shrink: 0;
}

/* ─── My Books ───────────────────────────────────────────────────────────────── */

.books-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.book-card {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 16px;
}

.book-card-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
}

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

.book-status {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.4px;
  padding: 2px 8px;
  border-radius: 100px;
  background: var(--accent-dim);
  color: var(--accent-text);
  white-space: nowrap;
  flex-shrink: 0;
}

.book-status-done {
  background: rgba(52, 211, 153, 0.15);
  color: var(--success);
}

.book-status-failed {
  background: rgba(248, 113, 113, 0.15);
  color: var(--error);
}

.book-meta {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.book-actions {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.book-actions .btn {
  width: auto;
}

.book-expiry {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
}

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

@media (max-width: 520px) {
  .card {
    padding: 28px 20px;
  }

  .stats-row {
    flex-direction: column;
  }
}


/* ─── Day / night themes (orange accent both modes) ────────────────────────── */
@media (prefers-color-scheme: light) {
  :root:not([data-theme="dark"]) {
    --bg:           #FBF8F2;
    --bg-card:      #FFFFFF;
    --bg-hover:     #F0EAE0;
    --border:       #E7E0D3;
    --accent-hover: #E0551F;
    --accent-dim:   rgba(255, 107, 53, 0.12);
    --btn-text:     #2a1305;
    --accent-text:  #C2410C;
    --text:         #20242C;
    --text-muted:   #6B6256;
    --text-dim:     #A99F8E;
    --shadow:       0 4px 24px rgba(0, 0, 0, 0.08);
  }
}
:root[data-theme="light"] {
  --bg:           #FBF8F2;
  --bg-card:      #FFFFFF;
  --bg-hover:     #F0EAE0;
  --border:       #E7E0D3;
  --accent-hover: #E0551F;
  --accent-dim:   rgba(255, 107, 53, 0.12);
  --btn-text:     #2a1305;
  --accent-text:  #C2410C;
  --text:         #20242C;
  --text-muted:   #6B6256;
  --text-dim:     #A99F8E;
  --shadow:       0 4px 24px rgba(0, 0, 0, 0.08);
}

/* Floating theme toggle — works across all SPA screens */
.app-theme-toggle {
  position: fixed;
  bottom: 18px;
  right: 18px;
  z-index: 9000;
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: var(--bg-card);
  color: var(--text-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  box-shadow: var(--shadow);
  transition: color .15s, border-color .15s;
}
.app-theme-toggle:hover { color: var(--text); border-color: var(--accent); }
.app-theme-toggle:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
