/* ==========================================================================
   小说速读 — Apple-inspired Design System
   tokens / primitives shared by index.html / book.html / reader.html
   ========================================================================== */

:root {
  /* Typography */
  --font-sans: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
               "PingFang SC", "Microsoft YaHei UI", "Segoe UI", system-ui, sans-serif;
  --font-display: -apple-system, BlinkMacSystemFont, "SF Pro Display",
                  "PingFang SC", system-ui, sans-serif;
  --font-serif: "PingFang SC", "Songti SC", "Source Han Serif SC",
                "Noto Serif CJK SC", "Times New Roman", serif;
  --font-mono: ui-monospace, SFMono-Regular, "SF Mono", Menlo, monospace;

  /* Apple-style palette — light */
  --bg: #fbfbfd;
  --surface: #ffffff;
  --surface-2: #f5f5f7;
  --surface-3: #ececee;
  --border: rgba(0, 0, 0, 0.08);
  --border-strong: rgba(0, 0, 0, 0.14);
  --text: #1d1d1f;
  --text-2: #6e6e73;
  --text-3: #86868b;
  --accent: #0071e3;
  --accent-hover: #0077ed;
  --accent-pressed: #006edb;
  --accent-soft: rgba(0, 113, 227, 0.08);
  --success: #30a14e;
  --warning: #b25e09;
  --warning-bg: #fff4e0;
  --warning-border: #f4cd87;
  --danger: #d70015;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.04), 0 1px 1px rgba(0, 0, 0, 0.03);
  --shadow: 0 4px 16px rgba(0, 0, 0, 0.06), 0 1px 2px rgba(0, 0, 0, 0.04);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.14), 0 4px 12px rgba(0, 0, 0, 0.06);

  --radius-sm: 8px;
  --radius: 14px;
  --radius-lg: 22px;

  --nav-h: 52px;
  --nav-blur: saturate(180%) blur(20px);

  --ease-apple: cubic-bezier(0.32, 0.72, 0, 1);
}

.dark {
  --bg: #000000;
  --surface: #1c1c1e;
  --surface-2: #2c2c2e;
  --surface-3: #3a3a3c;
  --border: rgba(255, 255, 255, 0.08);
  --border-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f5f7;
  --text-2: #a1a1a6;
  --text-3: #6e6e73;
  --accent: #2997ff;
  --accent-hover: #5cb1ff;
  --accent-pressed: #0a84ff;
  --accent-soft: rgba(41, 151, 255, 0.14);
  --success: #30d158;
  --warning: #ffb340;
  --warning-bg: rgba(180, 110, 20, 0.18);
  --warning-border: rgba(255, 159, 10, 0.4);
  --danger: #ff453a;
  --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
  --shadow: 0 4px 24px rgba(0, 0, 0, 0.6);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.7);
}

/* ── Base ───────────────────────────────────────────────── */
* { box-sizing: border-box; }
html, body {
  margin: 0;
  font-family: var(--font-sans);
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: var(--text);
  background: var(--bg);
  letter-spacing: -0.003em;
  font-size: 14px;
  line-height: 1.5;
  text-rendering: optimizeLegibility;
}
body { min-height: 100vh; }

a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

h1, h2, h3, h4 {
  font-family: var(--font-display);
  letter-spacing: -0.02em;
  color: var(--text);
  margin: 0;
}

/* ── Glass nav bar (Apple-style) ────────────────────────── */
.nav-glass {
  position: sticky;
  top: 0;
  z-index: 50;
  height: var(--nav-h);
  background: rgba(251, 251, 253, 0.72);
  backdrop-filter: var(--nav-blur);
  -webkit-backdrop-filter: var(--nav-blur);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 22px;
  gap: 12px;
}
.dark .nav-glass { background: rgba(22, 22, 23, 0.72); }

.nav-title {
  font-size: 15px;
  font-weight: 600;
  letter-spacing: -0.012em;
}

.nav-back {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 13px; color: var(--text-2);
  padding: 6px 10px 6px 6px;
  margin-left: -6px;
  border-radius: 8px;
  transition: all 0.15s var(--ease-apple);
}
.nav-back:hover { color: var(--accent); background: var(--accent-soft); }

/* ── Buttons ────────────────────────────────────────────── */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px;
  height: 34px; padding: 0 18px;
  border-radius: 980px;
  font: inherit;
  font-size: 13px; font-weight: 500;
  letter-spacing: -0.005em;
  border: 1px solid transparent;
  cursor: pointer;
  user-select: none;
  transition: background 0.16s var(--ease-apple),
              color 0.16s var(--ease-apple),
              transform 0.12s var(--ease-apple),
              box-shadow 0.16s var(--ease-apple);
  white-space: nowrap;
}
.btn:disabled { opacity: 0.36; cursor: not-allowed; }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--accent-soft); }

.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover:not(:disabled) { background: var(--accent-hover); }
.btn-primary:active:not(:disabled) { background: var(--accent-pressed); transform: scale(0.97); }

.btn-secondary {
  background: var(--surface); color: var(--text);
  border-color: var(--border-strong);
}
.btn-secondary:hover:not(:disabled) { background: var(--surface-2); border-color: var(--text-3); }

.btn-ghost { background: transparent; color: var(--text-2); }
.btn-ghost:hover:not(:disabled) { background: var(--surface-2); color: var(--text); }

.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled) { filter: brightness(1.06); }

.btn-sm { height: 28px; padding: 0 12px; font-size: 12px; }
.btn-lg { height: 44px; padding: 0 24px; font-size: 14px; font-weight: 500; }

/* Square icon button */
.icon-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 32px; height: 32px;
  border-radius: 8px;
  background: transparent;
  color: var(--text-2);
  border: none; cursor: pointer;
  transition: all 0.15s var(--ease-apple);
}
.icon-btn:hover { background: var(--surface-2); color: var(--text); }
.icon-btn svg { width: 16px; height: 16px; }

/* ── Cards ──────────────────────────────────────────────── */
.card {
  background: var(--surface);
  border-radius: var(--radius);
  border: 1px solid var(--border);
}
.card-elev {
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
  border: 1px solid transparent;
  transition: box-shadow 0.25s var(--ease-apple), transform 0.25s var(--ease-apple);
}
.card-elev:hover { box-shadow: var(--shadow); transform: translateY(-2px); }

/* ── Inputs ─────────────────────────────────────────────── */
.input, .select, .textarea {
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border-strong);
  border-radius: 10px;
  padding: 9px 12px;
  font-family: inherit;
  font-size: 13.5px;
  color: var(--text);
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.textarea { line-height: 1.55; resize: vertical; }
.input::placeholder, .textarea::placeholder { color: var(--text-3); }
.input:focus, .select:focus, .textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}
.label {
  display: block;
  font-size: 12px; font-weight: 500;
  color: var(--text-2);
  margin-bottom: 6px;
  letter-spacing: -0.005em;
}
.help {
  font-size: 11.5px; color: var(--text-3); margin-top: 6px; line-height: 1.5;
}

/* ── Modal ──────────────────────────────────────────────── */
.modal-backdrop {
  position: fixed; inset: 0; z-index: 70;
  background: rgba(0, 0, 0, 0.32);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
  display: flex; align-items: center; justify-content: center;
  padding: 24px;
  animation: bd-in 0.18s ease;
}
@keyframes bd-in { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  width: 100%; max-width: 560px;
  max-height: 88vh; overflow-y: auto;
  animation: modal-in 0.28s var(--ease-apple);
}
.modal-lg { max-width: 680px; }
.modal-sm { max-width: 400px; }
.modal-header {
  padding: 22px 26px 6px;
}
.modal-title {
  font-size: 18px; font-weight: 600; letter-spacing: -0.015em;
}
.modal-body { padding: 18px 26px; }
.modal-footer {
  padding: 14px 22px 18px;
  display: flex; justify-content: flex-end; gap: 10px;
  border-top: 1px solid var(--border);
  margin-top: 8px;
}
@keyframes modal-in {
  from { opacity: 0; transform: scale(0.94) translateY(10px); }
  to { opacity: 1; transform: none; }
}

/* ── Segmented control (Apple) ──────────────────────────── */
.segmented {
  display: inline-flex;
  background: var(--surface-2);
  border-radius: 9px;
  padding: 2px;
  gap: 2px;
  width: 100%;
}
.segmented button {
  flex: 1;
  padding: 6px 14px;
  font: inherit; font-size: 13px; font-weight: 500;
  color: var(--text-2);
  background: transparent;
  border: none; border-radius: 7px;
  cursor: pointer;
  transition: all 0.18s var(--ease-apple);
}
.segmented button:hover { color: var(--text); }
.segmented button.active {
  background: var(--surface);
  color: var(--text);
  box-shadow: 0 1px 2px rgba(0, 0, 0, 0.06), 0 0 0 0.5px var(--border-strong);
}
.dark .segmented button.active {
  background: var(--surface-3);
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.6);
}

/* ── Pills ──────────────────────────────────────────────── */
.pill {
  display: inline-flex; align-items: center;
  height: 20px; padding: 0 9px;
  font-size: 11px; font-weight: 500;
  border-radius: 980px;
  letter-spacing: 0.01em;
  line-height: 1;
}
.pill-success { background: rgba(48, 161, 78, 0.12); color: var(--success); }
.pill-warn    { background: var(--warning-bg); color: var(--warning); }
.pill-danger  { background: rgba(215, 0, 21, 0.1); color: var(--danger); }
.pill-info    { background: var(--accent-soft); color: var(--accent); }

/* ── Progress bar ───────────────────────────────────────── */
.progress {
  height: 4px;
  background: var(--surface-2);
  border-radius: 980px;
  overflow: hidden;
}
.progress > div {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-hover));
  border-radius: inherit;
  transition: width 0.6s var(--ease-apple);
}
.progress.thin { height: 2px; }

/* ── Scrollbar (Apple overlay style) ────────────────────── */
::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb {
  background: transparent; border-radius: 4px;
  transition: background 0.25s;
}
*:hover::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.18); }
.dark *:hover::-webkit-scrollbar-thumb { background: rgba(255, 255, 255, 0.2); }
::-webkit-scrollbar-thumb:hover { background: rgba(0, 0, 0, 0.3) !important; }
.dark ::-webkit-scrollbar-thumb:hover { background: rgba(255, 255, 255, 0.32) !important; }

/* ── Indeterminate checkbox ─────────────────────────────── */
input[type="checkbox"] {
  appearance: none; -webkit-appearance: none;
  width: 15px; height: 15px;
  border: 1.5px solid var(--border-strong);
  border-radius: 4px;
  background: var(--surface);
  cursor: pointer;
  display: inline-grid; place-content: center;
  transition: all 0.15s var(--ease-apple);
  flex-shrink: 0;
}
input[type="checkbox"]:checked {
  background: var(--accent); border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round' d='M3.5 8.3 6.8 11.5 12.5 4.8'/%3e%3c/svg%3e");
  background-size: 100%; background-repeat: no-repeat;
}
input[type="checkbox"]:indeterminate {
  background: var(--accent); border-color: var(--accent);
  background-image: url("data:image/svg+xml,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 16 16'%3e%3cpath fill='none' stroke='white' stroke-width='2.2' stroke-linecap='round' d='M4 8h8'/%3e%3c/svg%3e");
  background-size: 100%; background-repeat: no-repeat;
}

/* ── Utility ────────────────────────────────────────────── */
[x-cloak] { display: none !important; }

.no-scrollbar::-webkit-scrollbar { display: none; }
.no-scrollbar { scrollbar-width: none; }

.fade-in { animation: fade-in 0.4s var(--ease-apple) both; }
@keyframes fade-in {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}
.stagger > * { animation: fade-in 0.4s var(--ease-apple) both; }
.stagger > *:nth-child(1) { animation-delay: 0.02s; }
.stagger > *:nth-child(2) { animation-delay: 0.06s; }
.stagger > *:nth-child(3) { animation-delay: 0.10s; }
.stagger > *:nth-child(4) { animation-delay: 0.14s; }
.stagger > *:nth-child(5) { animation-delay: 0.18s; }
.stagger > *:nth-child(6) { animation-delay: 0.22s; }
.stagger > *:nth-child(7) { animation-delay: 0.26s; }
.stagger > *:nth-child(8) { animation-delay: 0.30s; }

.muted { color: var(--text-2); }
.muted-2 { color: var(--text-3); }
.text-tiny { font-size: 11.5px; }

/* ── Toast (top-center, Apple HUD style) ────────────────── */
.toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
  z-index: 90;
  background: rgba(28, 28, 30, 0.92);
  backdrop-filter: blur(20px); -webkit-backdrop-filter: blur(20px);
  color: #fff;
  padding: 10px 18px;
  border-radius: 980px;
  font-size: 13px; font-weight: 500;
  box-shadow: var(--shadow-lg);
  animation: toast-in 0.3s var(--ease-apple);
}
@keyframes toast-in {
  from { opacity: 0; transform: translateX(-50%) translateY(-12px); }
  to { opacity: 1; transform: translateX(-50%); }
}
