:root {
  --bg: #f2f7fb;
  --surface: #fbfdff;
  --surface-soft: #edf5fa;
  --ink: #183047;
  --muted: #657889;
  --line: #d5e2ec;
  --brand: #4b8db9;
  --brand-dark: #255b7c;
  --accent: #d99a35;
  --danger: #bd2f24;
  --shadow: 0 18px 46px rgba(42, 85, 112, 0.1);
  --radius-sm: 8px;
  --radius-md: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 4px 12px rgba(42, 85, 112, 0.06);
  --shadow-md: 0 8px 24px rgba(42, 85, 112, 0.08);
  --shadow-lg: 0 16px 40px rgba(42, 85, 112, 0.12);
  --transition-fast: 0.15s ease;
  --transition-normal: 0.25s ease;
  /* 现代化设计令牌：更柔和的阴影分层、品牌渐变、焦点环 */
  --shadow-card: 0 1px 2px rgba(24, 48, 71, 0.04), 0 8px 24px rgba(42, 85, 112, 0.07);
  --shadow-hover: 0 2px 4px rgba(24, 48, 71, 0.05), 0 14px 32px rgba(42, 85, 112, 0.11);
  --brand-gradient: linear-gradient(135deg, #5a9bc7 0%, #3d7da8 100%);
  --brand-gradient-hover: linear-gradient(135deg, #66a8d2 0%, #4689b4 100%);
  --focus-ring: 0 0 0 3px rgba(75, 141, 185, 0.28);
  --radius-xl: 20px;
  font-family: "PingFang SC", "Microsoft YaHei", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  /* 文字渲染优化：中文更清晰、抗锯齿 */
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  text-rendering: optimizeLegibility;
  letter-spacing: 0.01em;
}

/* 尊重用户的减少动画偏好 */
@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}

* {
  box-sizing: border-box;
}

.file-drop-zone {
  transition: border-color var(--transition-fast), box-shadow var(--transition-fast), background-color var(--transition-fast), outline-color var(--transition-fast);
}

.file-drop-zone.is-file-dragover {
  outline: 2px dashed var(--brand);
  outline-offset: 3px;
  border-color: var(--brand) !important;
  background-color: rgba(52, 116, 95, 0.1) !important;
  box-shadow: 0 0 0 5px rgba(52, 116, 95, 0.12) !important;
}

body {
  margin: 0;
  min-height: 100vh;
  background:
    linear-gradient(90deg, rgba(75, 141, 185, 0.035) 1px, transparent 1px) 0 0 / 38px 38px,
    linear-gradient(0deg, rgba(75, 141, 185, 0.028) 1px, transparent 1px) 0 0 / 38px 38px,
    linear-gradient(135deg, #f8fbfd 0%, #eef6fb 52%, #f5f9fc 100%);
  color: var(--ink);
}

body.popout-page {
  min-width: 360px;
  overflow-x: hidden;
}

body.popout-page .site-header,
body.popout-page .toolbox-section,
body.popout-page .community-section {
  display: none;
}

body.reader-popout-page {
  min-width: 0;
  overflow: hidden;
  background: #f6f1e8;
}

body.page-hidden {
  background: #f7f7f4 !important;
}

body.page-hidden > * {
  visibility: hidden !important;
}

body.reader-popout-page.page-hidden {
  background: #f7f7f4 !important;
}

body.reader-popout-page .site-header,
body.reader-popout-page .game-section,
body.reader-popout-page .community-section,
body.reader-popout-page .toolbox-head,
body.reader-popout-page .tool-status,
body.reader-popout-page .tool-card:not(.novel-tool) {
  display: none !important;
}

body.reader-popout-page .toolbox-section {
  display: block;
  width: min(100vw - 8px, 560px);
  padding: 4px 0;
}

body.reader-popout-page .tool-grid {
  display: block;
}

body.reader-popout-page .novel-tool {
  min-height: calc(100svh - 8px);
  padding: 10px;
  border-radius: 10px;
  box-shadow: none;
}

body.reader-popout-page .novel-layout {
  grid-template-columns: 1fr;
}

body.reader-popout-page .novel-shelf-panel {
  margin-bottom: 8px;
}

body.reader-popout-page .novel-search-panel {
  display: none;
}

body.reader-popout-page .novel-input {
  display: none;
}

body.reader-popout-page .novel-current-head {
  grid-template-columns: 1fr;
}

body.reader-popout-page .novel-controls {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

body.reader-popout-page .novel-controls select,
body.reader-popout-page .novel-controls button {
  grid-column: span 1;
}

body.reader-popout-page .novel-reader {
  height: calc(100svh - 288px);
}

body.reader-popout-page.novel-minimal .novel-tool {
  padding: 0;
  border: 0;
  background: transparent;
}

body.reader-popout-page.novel-minimal .tool-title,
body.reader-popout-page.novel-minimal .novel-shelf-panel,
body.reader-popout-page.novel-minimal .novel-current-head,
body.reader-popout-page.novel-minimal .novel-controls,
body.reader-popout-page.novel-minimal .novel-meta {
  display: none;
}

body.reader-popout-page.novel-minimal .novel-reader {
  height: 100svh;
  border: 0;
  border-radius: 0;
}

.confirm-modal {
  position: fixed;
  inset: 0;
  z-index: 2000;
  display: grid;
  place-items: center;
  padding: 24px;
  background: rgba(15, 30, 45, 0.45);
  backdrop-filter: blur(4px);
  pointer-events: auto;
  opacity: 0;
  transition: opacity 0.18s ease;
}

.confirm-modal:not(.hidden) {
  opacity: 1;
}

.confirm-box {
  width: min(400px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  background: var(--surface);
  box-shadow: var(--shadow-lg);
  pointer-events: auto;
}

.confirm-box h3 {
  margin: 0 0 8px;
  font-size: 16px;
  color: var(--ink);
}

.confirm-box p {
  margin: 0 0 16px;
  color: var(--muted);
  font-size: 14px;
  line-height: 1.5;
}

.confirm-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

.confirm-actions button {
  min-width: 72px;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  border: 1px solid var(--line);
  background: #fff;
  color: var(--brand-dark);
  font-weight: 800;
  font-size: 14px;
  cursor: pointer;
  transition: background var(--transition-fast), transform var(--transition-fast);
}

.confirm-actions button:hover {
  transform: translateY(-1px);
}

.confirm-actions button:first-child {
  background: #f5f5f5;
}

.confirm-actions button:last-child {
  background: linear-gradient(180deg, #6aa7cd, #4b8db9);
  color: #fff;
  border-color: var(--brand-dark);
  box-shadow: 0 4px 0 rgba(37, 91, 124, 0.5);
}

.confirm-actions button:last-child:hover {
  box-shadow: 0 6px 0 rgba(37, 91, 124, 0.5);
  transform: translateY(-2px);
}

.toast-container {
  position: fixed;
  top: 72px;
  right: 16px;
  z-index: 5000;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  pointer-events: auto;
  padding: 10px 16px;
  border-radius: var(--radius-md);
  background: var(--surface);
  border: 1px solid var(--line);
  box-shadow: var(--shadow-md);
  font-size: 13px;
  font-weight: 800;
  color: var(--ink);
  animation: toast-in var(--transition-normal) ease-out both;
  max-width: 320px;
}

.toast.toast-success {
  border-color: rgba(17, 133, 108, 0.35);
  background: linear-gradient(135deg, #e8f5f1, #d1ede6);
  color: #0a4b40;
}

.toast.toast-error {
  border-color: rgba(189, 47, 36, 0.3);
  background: linear-gradient(135deg, #fde8e6, #f5d1cd);
  color: #742520;
}

.toast.toast-warning {
  border-color: rgba(217, 154, 53, 0.35);
  background: linear-gradient(135deg, #fff6e5, #ffe9c2);
  color: #6a3e04;
}

/* ── 全局可访问性与交互细节 ── */
/* 键盘焦点可见：用 :focus-visible 区分鼠标/键盘，避免鼠标点击也出现焦点环 */
button:focus-visible,
a:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible,
[tabindex]:focus-visible {
  outline: none;
  box-shadow: var(--focus-ring);
  border-radius: var(--radius-sm);
}

/* 选中文本配色，呼应品牌色 */
::selection {
  background: rgba(75, 141, 185, 0.22);
  color: var(--brand-dark);
}

/* 滚动条美化（WebKit），呼应浅蓝白主题 */
::-webkit-scrollbar {
  width: 10px;
  height: 10px;
}
::-webkit-scrollbar-track {
  background: transparent;
}
::-webkit-scrollbar-thumb {
  background: rgba(75, 141, 185, 0.28);
  border-radius: 8px;
  border: 2px solid transparent;
  background-clip: padding-box;
}
::-webkit-scrollbar-thumb:hover {
  background: rgba(75, 141, 185, 0.45);
  background-clip: padding-box;
}
