:root {
  --bg: #0f1115;
  --panel: #1a1d24;
  --panel-2: #232732;
  --text: #e9ecf1;
  --muted: #8a93a6;
  --accent: #6aa7ff;
  --accent-2: #4d8cff;
  --danger: #ff6b6b;
  --ok: #2bbd7e;
  --radius: 12px;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.4);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { height: 100%; margin: 0; background: var(--bg); color: var(--text); }

/* --- Login --- */
body.login {
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.card {
  background: var(--panel);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 28px;
  width: 100%;
  max-width: 380px;
}

.card h1 {
  margin: 0 0 4px;
  font-size: 22px;
  font-weight: 600;
}

.card .hint {
  margin: 0 0 20px;
  color: var(--muted);
  font-size: 14px;
}

.card label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  margin: 12px 0 6px;
}

.card input {
  width: 100%;
  padding: 12px 14px;
  background: var(--panel-2);
  border: 1px solid #2c3140;
  color: var(--text);
  border-radius: 8px;
  font-size: 16px;
  outline: none;
  transition: border-color 0.15s;
}

.card input:focus { border-color: var(--accent); }

.card #code {
  letter-spacing: 8px;
  font-size: 20px;
  text-align: center;
  font-variant-numeric: tabular-nums;
}

.card button {
  margin-top: 16px;
  width: 100%;
  padding: 12px 14px;
  background: var(--accent-2);
  border: 0;
  color: white;
  font-weight: 600;
  border-radius: 8px;
  font-size: 15px;
  cursor: pointer;
  transition: background 0.15s, opacity 0.15s;
}

.card button:hover:not(:disabled) { background: var(--accent); }
.card button:disabled { opacity: 0.5; cursor: not-allowed; }

.card .row {
  display: flex;
  gap: 8px;
}

.card .row button { margin-top: 16px; }
.card .row .link { width: auto; flex: 0 0 auto; }

.card button.link {
  background: transparent;
  color: var(--muted);
  font-weight: 500;
  padding: 8px 10px;
  margin-top: 8px;
}

.card button.link:hover:not(:disabled) { color: var(--accent); background: transparent; }

.msg {
  margin-top: 14px;
  font-size: 13px;
  min-height: 18px;
}

.msg.error { color: var(--danger); }
.msg.ok { color: var(--ok); }

/* --- Viewer --- */
body.viewer {
  overflow: hidden;
}

.loading {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 14px;
  color: var(--muted);
}

.spinner {
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: 3px solid #2c3140;
  border-top-color: var(--accent);
  animation: spin 0.8s linear infinite;
}

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

#loading progress {
  width: 240px;
  height: 6px;
  -webkit-appearance: none;
  appearance: none;
  border: none;
  background: var(--panel-2);
  border-radius: 999px;
  overflow: hidden;
}

#loading progress::-webkit-progress-bar { background: var(--panel-2); }
#loading progress::-webkit-progress-value { background: var(--accent); transition: width 0.2s; }
#loading progress::-moz-progress-bar { background: var(--accent); }

#book-wrap {
  position: fixed;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at center, #1a1f2a 0%, #0a0d12 100%);
  padding: 32px 16px 80px;
}

#book {
  max-width: 100%;
  max-height: 100%;
}

.toolbar {
  position: fixed;
  bottom: 16px;
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  align-items: center;
  gap: 8px;
  background: rgba(20, 23, 30, 0.85);
  backdrop-filter: blur(10px);
  padding: 8px 12px;
  border-radius: 999px;
  box-shadow: var(--shadow);
  z-index: 10;
}

.toolbar button {
  background: transparent;
  border: 0;
  color: var(--text);
  width: 36px;
  height: 36px;
  font-size: 20px;
  border-radius: 50%;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background 0.15s;
}

.toolbar button:hover { background: rgba(255, 255, 255, 0.08); }
.toolbar button.link {
  width: auto;
  padding: 0 12px;
  font-size: 13px;
  color: var(--muted);
  border-radius: 18px;
}

#page-indicator {
  font-size: 13px;
  color: var(--muted);
  font-variant-numeric: tabular-nums;
  min-width: 60px;
  text-align: center;
}

@media (max-width: 640px) {
  #book-wrap { padding: 12px 0 80px; }
}
