*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: #f5f5f5;
  color: #1a1a1a;
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}

.container {
  width: 100%;
  max-width: 540px;
  padding: 1.5rem;
}

/* Tighter padding on small screens */
@media (max-width: 480px) {
  .container { padding: 0.75rem; }
  .card { padding: 1.75rem 1.25rem; }
}

.card {
  background: #fff;
  border-radius: 12px;
  padding: 2.5rem 2rem;
  box-shadow: 0 2px 16px rgba(0,0,0,0.08);
  display: flex;
  flex-direction: column;
  gap: 1.25rem;
}

h1 {
  font-size: 1.75rem;
  font-weight: 700;
  letter-spacing: -0.02em;
}

h2 {
  font-size: 1.25rem;
  font-weight: 600;
}

.subtitle {
  color: #555;
  font-size: 0.95rem;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 2px solid #e8e8e8;
  margin-bottom: -0.25rem;
}

.tab {
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  margin-bottom: -2px;
  padding: 0.4rem 1rem;
  font-size: 0.95rem;
  font-weight: 500;
  color: #888;
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.tab.active {
  color: #4a6cf7;
  border-bottom-color: #4a6cf7;
}

.tab-panel.hidden { display: none; }

.optional {
  font-size: 0.75rem;
  font-weight: 400;
  color: #aaa;
}

select {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1.5px solid #d0d0d0;
  border-radius: 8px;
  font-size: 1rem;
  background: #fff;
  outline: none;
  transition: border-color 0.15s;
}

select:focus { border-color: #4a6cf7; }

/* Forms */
form {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;
}

label {
  font-size: 0.875rem;
  font-weight: 500;
  color: #333;
}

input[type="text"],
input[type="password"] {
  width: 100%;
  padding: 0.65rem 0.85rem;
  border: 1.5px solid #d0d0d0;
  border-radius: 8px;
  font-size: 1rem;
  transition: border-color 0.15s;
  outline: none;
}

input:focus {
  border-color: #4a6cf7;
}

button[type="submit"],
a.button {
  display: block;
  width: 100%;
  padding: 0.7rem;
  background: #4a6cf7;
  color: #fff;
  border: none;
  border-radius: 8px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  text-align: center;
  text-decoration: none;
  transition: background 0.15s;
  margin-top: 0.25rem;
}

button[type="submit"]:hover,
a.button:hover {
  background: #3a5ce6;
}

/* Alert */
.alert {
  background: #fff0f0;
  color: #c0392b;
  border: 1px solid #f5c6c6;
  border-radius: 8px;
  padding: 0.65rem 0.85rem;
  font-size: 0.9rem;
}

/* Book identification */
.book-id {
  text-align: center;
  line-height: 1.4;
}

.book-title {
  font-size: 1.2rem;
  font-weight: 700;
}

.book-by {
  color: #888;
  font-size: 1rem;
}

.book-author {
  font-size: 1rem;
  font-weight: 500;
  color: #444;
}

/* Original IRC filename with highlights */
.source-file {
  background: #f7f7f7;
  border-radius: 8px;
  padding: 0.6rem 0.85rem;
}

.source-label {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: #999;
  margin-bottom: 0.25rem;
}

.source-filename {
  font-size: 0.8rem;
  color: #555;
  word-break: break-all;
  line-height: 1.5;
}

mark {
  background: #fef3c7;
  color: inherit;
  border-radius: 2px;
  padding: 0 1px;
}

/* Status page */
.status-icon {
  font-size: 2.5rem;
  text-align: center;
  color: #27ae60;
}

.status-icon.error {
  color: #c0392b;
}

.filename {
  font-size: 0.875rem;
  color: #444;
  word-break: break-all;
  background: #f7f7f7;
  padding: 0.5rem 0.75rem;
  border-radius: 6px;
}

.error-msg {
  font-size: 0.9rem;
  color: #c0392b;
}

.hint {
  font-size: 0.85rem;
  color: #888;
  text-align: center;
}

.rate-limit-msg {
  font-size: 0.85rem;
  color: #b8860b;
  text-align: center;
  margin-top: 0.25rem;
}

a.link {
  color: #4a6cf7;
  text-align: center;
  font-size: 0.9rem;
  text-decoration: none;
}

a.link:hover { text-decoration: underline; }

/* Sign-out button looks like a plain link */
.logout-form {
  margin-top: -0.5rem;
}

.link-button {
  background: none;
  border: none;
  color: #888;
  font-size: 0.85rem;
  cursor: pointer;
  padding: 0;
  text-align: center;
  width: 100%;
}

.link-button:hover { color: #555; }

/* Spinner */
.spinner {
  width: 40px;
  height: 40px;
  border: 3px solid #e0e0e0;
  border-top-color: #4a6cf7;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

@keyframes spin { to { transform: rotate(360deg); } }

/* Series book list */
.book-list {
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.book-row {
  display: grid;
  grid-template-columns: 1fr auto;
  grid-template-rows: auto auto;
  align-items: baseline;
  gap: 0.1rem 0.75rem;
  padding: 0.6rem 0.75rem;
  background: #f7f7f7;
  border-radius: 8px;
  font-size: 0.875rem;
}

.book-row-title {
  font-weight: 500;
  grid-column: 1;
  grid-row: 1;
  min-width: 0;
  word-break: break-word;
}

.book-row-meta {
  font-size: 0.75rem;
  color: #999;
  grid-column: 1;
  grid-row: 2;
}

.book-row-status {
  grid-column: 2;
  grid-row: 1;
  font-weight: 600;
  text-align: right;
}

.book-done .book-row-status { color: #27ae60; }
.book-failed .book-row-status { color: #c0392b; }
.book-downloading .book-row-status { color: #4a6cf7; }
.book-pending .book-row-status { color: #bbb; }

.book-download-form {
  grid-column: 1 / -1;
  display: flex;
  gap: 0.5rem;
  align-items: center;
}

@media (max-width: 480px) {
  .book-download-form { flex-direction: column; align-items: stretch; }
  .save-as-input { font-size: 1rem; } /* prevent iOS auto-zoom */
  .small-button { text-align: center; }
}

.save-as-input {
  flex: 1;
  padding: 0.35rem 0.6rem;
  border: 1.5px solid #d0d0d0;
  border-radius: 6px;
  font-size: 0.8rem;
  outline: none;
}

.save-as-input:focus { border-color: #4a6cf7; }

.small-button {
  padding: 0.35rem 0.75rem;
  background: #4a6cf7;
  color: #fff;
  border: none;
  border-radius: 6px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}

.small-button:hover { background: #3a5ce6; }

.book-error {
  grid-column: 1 / -1;
  font-size: 0.8rem;
  color: #c0392b;
}
