*,
html,
body {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
  -webkit-tap-highlight-color: transparent;
}

/* 所有超链接继承父级文字颜色，不使用蓝色 */
a {
  color: inherit;
  text-decoration: none;
}

a:focus-visible {
  outline: 2px solid var(--primary);
  outline-offset: 2px;
  border-radius: 4px;
}

body {
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  /* 极浅蓝紫渐变底色 */
  background: #EEF2FF;
  background: linear-gradient(180deg, #EEF2FF 0%, #F4F6FF 40%, #FAFBFF 70%, #FFFFFF 100%);
  background-attachment: fixed;
  color: var(--ink);
  -webkit-font-smoothing: antialiased;
  min-height: 100vh;
  position: relative;
}

/* 弥散光晕装饰层 */
body::before {
  content: '';
  position: fixed;
  top: -10%;
  right: -15%;
  width: 400px;
  height: 400px;
  background: radial-gradient(circle, rgba(108,99,255,.06) 0%, transparent 65%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

body::after {
  content: '';
  position: fixed;
  bottom: 5%;
  left: -10%;
  width: 350px;
  height: 350px;
  background: radial-gradient(circle, rgba(16,185,129,.05) 0%, transparent 65%);
  border-radius: 50%;
  pointer-events: none;
  z-index: 0;
}

/* 手机端 / 平板端：铺满全屏，充当 App */
.app-shell {
  width: 100%;
  max-width: 100%;
  margin: 0;
  min-height: 100vh;
  position: relative;
  overflow: hidden;
  border-radius: 0;
  background: transparent;
}

/* 电脑端：居中显示为"手机壳"样式，模拟真机运行 */
@media (min-width: 1024px) {
  body {
    background: #0F1115;
    background: linear-gradient(135deg, #1A1D2E 0%, #2D1B3D 50%, #1E2A3A 100%);
    background-attachment: fixed;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px 0;
  }

  .app-shell {
    width: 390px;
    max-width: 390px;
    min-height: 844px;
    border-radius: 44px;
    overflow: hidden;
    background: #EEF2FF;
    background: linear-gradient(180deg, #EEF2FF 0%, #F4F6FF 40%, #FAFBFF 70%, #FFFFFF 100%);
    border: 8px solid #0A0A0A;
    box-shadow:
      0 0 0 2px #2A2A2A,
      0 30px 80px rgba(0,0,0,.6),
      0 10px 30px rgba(0,0,0,.4);
    position: relative;
  }

  /* 手机壳顶部刘海 */
  .app-shell::before {
    content: '';
    position: absolute;
    top: 8px;
    left: 50%;
    transform: translateX(-50%);
    width: 120px;
    height: 28px;
    background: #0A0A0A;
    border-radius: 0 0 18px 18px;
    z-index: 100;
    pointer-events: none;
  }
}

.app-header {
  height: 56px;
  padding-top: env(safe-area-inset-top);
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding-left: 16px;
  padding-right: 16px;
  background: rgba(255,255,255,.55);
  backdrop-filter: blur(24px) saturate(200%);
  -webkit-backdrop-filter: blur(24px) saturate(200%);
  border-bottom: 1px solid rgba(255,255,255,.5);
  z-index: 30;
  position: sticky;
  top: 0;
}

.app-main {
  position: relative;
  z-index: 5;
  padding: 16px 16px calc(100px + env(safe-area-inset-bottom)) 16px;
  overflow-y: auto;
  min-height: calc(100vh - 56px);
  scrollbar-width: none;
}

.app-main::-webkit-scrollbar {
  display: none;
}

.glass-card {
  background: rgba(255,255,255,.55);
  backdrop-filter: blur(20px) saturate(180%);
  -webkit-backdrop-filter: blur(20px) saturate(180%);
  border: 1px solid rgba(255,255,255,.6);
  border-radius: var(--r-lg);
  box-shadow: var(--shadow-glass);
}

.section {
  margin-bottom: 20px;
}

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin: 0 0 12px;
  padding: 0 4px;
}

.section-title {
  font-size: 16px;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
}

.section-link {
  display: inline-flex;
  align-items: center;
  gap: 2px;
  font-size: 13px;
  font-weight: 400;
  color: var(--ink-3);
}

.section-link svg {
  width: 16px;
  height: 16px;
}

.btn {
  padding: 10px 20px;
  border-radius: var(--r-pill);
  font-weight: 600;
  background: linear-gradient(135deg, var(--primary), var(--primary-light));
  color: #fff;
  border: none;
  box-shadow: var(--shadow-primary);
  cursor: pointer;
  font-size: 14px;
  transition: transform .18s var(--ease), box-shadow .25s var(--ease);
}

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

.btn-ghost {
  background: var(--glass);
  color: var(--ink);
  border: 1px solid var(--glass-border);
  box-shadow: none;
}

.page-push {
  animation: pushIn .35s var(--ease) both;
}

@keyframes pushIn {
  from {
    opacity: 0;
    transform: translateX(18px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.toast {
  position: fixed;
  top: 24px;
  left: 50%;
  transform: translate(-50%, -10px);
  padding: 10px 20px;
  background: #FFFFFF;
  border: 1px solid rgba(0,0,0,0.06);
  border-radius: var(--r-pill);
  box-shadow: 0 4px 16px rgba(0,0,0,.1);
  z-index: 200;
  opacity: 0;
  transition: .25s;
  font-size: 14px;
  color: var(--ink);
  pointer-events: none;
}

.toast.show {
  opacity: 1;
  transform: translate(-50%, 0);
}

.toast.success {
  border-color: rgba(94, 231, 223, 0.4);
  color: #0e8a80;
}

.toast.error {
  border-color: rgba(245, 87, 108, 0.4);
  color: #c03650;
}

/* ===== 设置弹层 ===== */
.settings-modal {
  position: fixed;
  inset: 0;
  z-index: 200;
  background: rgba(0,0,0,.35);
  display: none;
  align-items: flex-end;
  justify-content: center;
}

.settings-modal.show {
  display: flex;
}

/* ===== icon-btn 精致毛玻璃风格 ===== */
.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  border: none;
  background: rgba(255,255,255,.6);
  backdrop-filter: blur(12px) saturate(180%);
  -webkit-backdrop-filter: blur(12px) saturate(180%);
  color: var(--primary);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform .16s, box-shadow .2s, background .18s, color .18s;
  flex-shrink: 0;
  box-shadow: var(--shadow-float);
  border: 1px solid rgba(255,255,255,.6);
}

.header-left .icon-btn {
  background: rgba(108,99,255,.08);
  color: var(--primary);
  border: 1px solid rgba(108,99,255,.12);
}

.header-right .icon-btn:first-child {
  background: rgba(16,185,129,.08);
  color: var(--success);
  border: 1px solid rgba(16,185,129,.12);
}

.header-right .icon-btn:last-child {
  background: rgba(255,138,101,.08);
  color: var(--warm);
  border: 1px solid rgba(255,138,101,.12);
}

/* 关闭按钮 */
.icon-btn[aria-label="关闭"] {
  background: rgba(239,68,68,.08);
  color: var(--red);
  border: 1px solid rgba(239,68,68,.12);
}

.icon-btn:hover {
  transform: translateY(-1px);
}

.icon-btn:active {
  transform: scale(.92);
}

.icon-btn svg {
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.settings-sheet {
  width: 100%;
  max-width: 430px;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(24px) saturate(200%);
  -webkit-backdrop-filter: blur(24px) saturate(200%);
  border: 1px solid rgba(255,255,255,.6);
  border-radius: var(--r-xl) var(--r-xl) 0 0;
  padding: 16px 16px calc(24px + env(safe-area-inset-bottom)) 16px;
  max-height: 80vh;
  overflow-y: auto;
  animation: settingsSlideUp .3s var(--ease);
  box-shadow: 0 -8px 32px rgba(110,140,255,.08);
}

@keyframes settingsSlideUp {
  from { transform: translateY(100%); }
  to { transform: none; }
}

.settings-sheet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  padding-bottom: 12px;
  border-bottom: 1px solid rgba(0,0,0,.06);
}

.settings-sheet-title {
  font-size: 17px;
  font-weight: 600;
  color: var(--ink);
}

.settings-group {
  margin-bottom: 20px;
}

.settings-group-title {
  font-size: 13px;
  color: var(--ink-3);
  margin-bottom: 10px;
  font-weight: 500;
}

.settings-theme-options {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.settings-theme-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding: 10px 6px;
  border: 2px solid rgba(255,255,255,.6);
  border-radius: var(--r);
  background: rgba(255,255,255,.5);
  cursor: pointer;
  font-size: 12px;
  color: var(--ink-2);
  transition: .2s;
}

.settings-theme-option.active {
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 600;
  background: var(--primary-soft);
}

.theme-preview {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  border: 1px solid rgba(0,0,0,.06);
}

.theme-preview-light {
  background: linear-gradient(135deg, #F0F4FF, #FFF5F0);
}

.theme-preview-warm {
  background: linear-gradient(135deg, #FFECD2, #FCB69F);
}

.theme-preview-cool {
  background: linear-gradient(135deg, #E0F7FA, #84FAB0);
}

.settings-toggle-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 12px 14px;
  background: rgba(255,255,255,.4);
  border: 1px solid rgba(255,255,255,.5);
  border-radius: var(--r);
}

.settings-toggle-label {
  font-size: 15px;
  color: var(--ink);
}

/* 设置弹层开关组件 */
.setting-switch {
  position: relative;
  display: inline-block;
  width: 44px;
  height: 26px;
  flex-shrink: 0;
}

.setting-switch input {
  opacity: 0;
  width: 0;
  height: 0;
}

.setting-switch .slider {
  position: absolute;
  cursor: pointer;
  inset: 0;
  background: rgba(0,0,0,.15);
  border-radius: 999px;
  transition: .3s;
}

.setting-switch .slider::before {
  content: '';
  position: absolute;
  height: 20px;
  width: 20px;
  left: 3px;
  bottom: 3px;
  background: white;
  border-radius: 50%;
  transition: .3s;
  box-shadow: 0 2px 4px rgba(0,0,0,.15);
}

.setting-switch input:checked + .slider {
  background: linear-gradient(135deg, var(--primary), var(--warm));
}

.setting-switch input:checked + .slider::before {
  transform: translateX(18px);
}

.settings-font-size {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 14px;
  background: rgba(255,255,255,.4);
  border: 1px solid rgba(255,255,255,.5);
  border-radius: var(--r);
}

.font-size-label {
  font-size: 13px;
  color: var(--ink-3);
}

.font-size-slider {
  flex: 1;
  accent-color: var(--primary);
}

.font-size-value {
  text-align: center;
  font-size: 14px;
  font-weight: 600;
  color: var(--primary);
  margin-top: 8px;
}

.settings-action-btn {
  width: 100%;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px;
  border: 1px solid rgba(255,255,255,.6);
  border-radius: var(--r);
  background: rgba(255,255,255,.5);
  font-size: 15px;
  color: var(--ink);
  cursor: pointer;
  transition: .18s;
}

.settings-action-btn:active {
  background: var(--primary-soft);
}

.settings-action-btn svg {
  width: 20px;
  height: 20px;
  stroke: currentColor;
  fill: none;
  stroke-width: 2;
  stroke-linecap: round;
  stroke-linejoin: round;
}

/* ===== 夜间模式 ===== */
body.night-mode {
  background: #14161C;
  background: linear-gradient(180deg, #14161C 0%, #1A1D26 50%, #1E1620 100%);
  background-attachment: fixed;
  color: #e8e6e3;
}

body.night-mode .app-shell {
  background: transparent;
}

@media (min-width: 1024px) {
  body.night-mode .app-shell {
    background: #14161C;
    background: linear-gradient(180deg, #14161C 0%, #1A1D26 50%, #1E1620 100%);
  }
}

body.night-mode .app-header,
body.night-mode .bottom-tabbar {
  background: rgba(30,33,40,.85);
  backdrop-filter: blur(16px) saturate(180%);
  -webkit-backdrop-filter: blur(16px) saturate(180%);
  border-color: rgba(255,255,255,.06);
}

body.night-mode .glass-card,
body.night-mode .role-card,
body.night-mode .chapter-card,
body.night-mode .community-entry,
body.night-mode .post-card,
body.night-mode .search-item-card,
body.night-mode .search-role-card,
body.night-mode .search-input-bar {
  background: rgba(37,40,48,.72);
  backdrop-filter: blur(20px) saturate(160%);
  -webkit-backdrop-filter: blur(20px) saturate(160%);
  border-color: rgba(255,255,255,.08);
  box-shadow: 0 8px 24px rgba(0,0,0,.2);
  color: #e8e6e3;
}

body.night-mode .role-name,
body.night-mode .chapter-title,
body.night-mode .post-card-title,
body.night-mode .section-title,
body.night-mode .search-item-title,
body.night-mode .header-title-text {
  color: #e8e6e3;
}

body.night-mode .role-tag,
body.night-mode .chapter-summary,
body.night-mode .post-card-excerpt,
body.night-mode .post-card-footer,
body.night-mode .search-item-desc,
body.night-mode .entry-desc {
  color: #9a9a9a;
}

body.night-mode .tab-item svg.tab-icon,
body.night-mode .tab-item span.tab-label,
body.night-mode .tab-item .tab-icon-ri {
  color: #6a6a6a;
}

body.night-mode .tab-item.active svg.tab-icon,
body.night-mode .tab-item.active span.tab-label,
body.night-mode .tab-item.active .tab-icon-ri {
  color: var(--primary);
}

body.night-mode .settings-sheet {
  background: rgba(37,40,48,.85);
  backdrop-filter: blur(24px) saturate(160%);
  -webkit-backdrop-filter: blur(24px) saturate(160%);
  border-color: rgba(255,255,255,.08);
  color: #e8e6e3;
}

body.night-mode .settings-toggle-row,
body.night-mode .settings-font-size,
body.night-mode .settings-action-btn {
  background: rgba(255,255,255,.04);
  border-color: rgba(255,255,255,.06);
  color: #e8e6e3;
}

body.night-mode .settings-theme-option {
  background: rgba(255,255,255,.04);
  border-color: rgba(255,255,255,.08);
}

/* ===== 暖色/冷色主题 ===== */
body.theme-warm {
  background: #FFF5F0;
  background: linear-gradient(180deg, #FFF5F0 0%, #FFE8D6 50%, #FFE0CC 100%);
  background-attachment: fixed;
}

body.theme-cool {
  background: #E8F7FA;
  background: linear-gradient(180deg, #E8F7FA 0%, #E0F2F8 50%, #E8EEF6 100%);
  background-attachment: fixed;
}

/* ===== 设置弹窗响应式适配 ===== */
@media (max-width: 360px) {
  .settings-sheet {
    padding: 14px 12px calc(20px + env(safe-area-inset-bottom)) 12px;
  }
  .settings-sheet-title { font-size: 16px; }
  .settings-group { margin-bottom: 16px; }
  .settings-group-title { font-size: 12px; }
  .settings-theme-option { padding: 8px 4px; }
  .theme-preview { width: 34px; height: 34px; }
  .settings-toggle-label { font-size: 14px; }
  .settings-action-btn { padding: 12px; font-size: 14px; }
  .icon-btn { width: 34px; height: 34px; }
}

@media (min-width: 561px) {
  .settings-modal {
    align-items: center;
    padding: 24px;
  }
  .settings-sheet {
    max-width: 420px;
    border-radius: var(--r-xl);
    max-height: 85vh;
    box-shadow: 0 20px 60px rgba(0,0,0,.15);
  }
  @keyframes settingsSlideUp {
    from { transform: translateY(40px); opacity: 0; }
    to { transform: none; opacity: 1; }
  }
}
