/* ==========================================================================
   SETTINGS & CATEGORY DRAWER SHEETS
   ========================================================================== */

/* Theme Circle Button (Tomato / Hongguo Style) */
.theme-circle-btn {
  position: relative;
  height: 48px;
  border-radius: 12px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, border-color 0.15s ease;
  user-select: none;
}
.theme-circle-btn:hover {
  transform: translateY(-1px);
}
.theme-circle-btn.selected {
  box-shadow: 0 0 0 2px var(--accent-gold), 0 4px 12px rgba(0,0,0,0.25);
  border-color: var(--accent-gold) !important;
}
.theme-circle-btn .circle-label {
  font-size: 11px;
  font-weight: 700;
  line-height: 1;
}
.theme-circle-btn .check-icon {
  position: absolute;
  top: -5px;
  right: -5px;
  width: 15px;
  height: 15px;
  border-radius: 9999px;
  display: none;
  align-items: center;
  justify-content: center;
  background-color: var(--accent-gold);
  color: #ffffff;
  box-shadow: 0 2px 5px rgba(0, 0, 0, 0.35);
}
.theme-circle-btn.selected .check-icon {
  display: flex;
}

/* Legacy Theme Options for desktop if needed */
.theme-option {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 11px 10px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  border: 1px solid rgba(128, 128, 128, 0.35);
  transition: all 0.15s ease;
}
.theme-option:hover {
  transform: translateY(-1px);
}
.theme-option.selected {
  border-color: var(--accent-gold);
  box-shadow: 0 0 0 3px var(--accent-gold-subtle);
}
.theme-option .swatch {
  width: 14px;
  height: 14px;
  border-radius: 9999px;
  border: 1px solid rgba(128, 128, 128, 0.5);
  flex-shrink: 0;
}
.theme-option .check-icon {
  position: absolute;
  top: -7px;
  right: -7px;
  width: 18px;
  height: 18px;
  border-radius: 9999px;
  display: none;
  align-items: center;
  justify-content: center;
  background-color: var(--accent-gold);
  color: #ffffff;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
.theme-option.selected .check-icon {
  display: flex;
}

/* Font Options */
.font-option {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 8px;
  border-radius: 12px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  background-color: var(--bg-surface-elevated);
  color: var(--text-primary);
  border: 1px solid var(--border-subtle);
  transition: all 0.15s ease;
}
.font-option:hover {
  border-color: var(--border-medium);
}
.font-option.selected {
  border-color: var(--accent-gold);
  color: var(--accent-gold);
  background-color: var(--accent-gold-subtle);
}
.font-option .sample-glyph {
  font-size: 17px;
  line-height: 1.2;
  color: inherit;
}

/* Setting Value Chips */
.setting-value-chip {
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  font-weight: 700;
  font-size: 12px;
  color: var(--accent-gold);
  background-color: var(--accent-gold-subtle);
  border: 1px solid var(--accent-gold-border);
  padding: 1px 8px;
  border-radius: 6px;
}

/* Settings Sheet（桌面：居中浮动卡片；移动：底部圆角面板） */
.settings-sheet {
  width: 100%;
  max-width: 380px;
  max-height: min(86vh, 780px);
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border-radius: 22px;
  border: 1px solid var(--border-subtle);
  padding: 14px 20px 10px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  box-shadow: 0 24px 60px -12px rgba(0, 0, 0, 0.45);
  cursor: default;
  overflow-y: auto;
  transition: background-color 0.25s ease;
  animation: modalPopIn 0.24s cubic-bezier(0.16, 1, 0.3, 1);
}

.sheet-handle {
  width: 38px;
  height: 5px;
  border-radius: 999px;
  background-color: var(--border-medium);
  margin: 2px auto 8px;
  flex-shrink: 0;
}

/* Row structures */
.setting-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 12px 0;
}
.setting-row + .setting-row { border-top: 1px solid var(--border-subtle); }
.setting-col { padding: 4px 0; }
.setting-row-label {
  width: 40px;
  flex-shrink: 0;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--text-primary);
}
.desktop-only-row { display: flex; }
@media (max-width: 640px) {
  .desktop-only-row { display: none !important; }
}

/* Sliders */
.setting-slider {
  -webkit-appearance: none;
  appearance: none;
  flex: 1;
  min-width: 0;
  height: 22px;
  background: transparent;
  cursor: pointer;
}
.setting-slider::-webkit-slider-runnable-track {
  height: 5px;
  border-radius: 999px;
  background: var(--bg-surface-hover);
}
.setting-slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #f2f2f4;
  border: none;
  margin-top: -8px;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}
.setting-slider::-moz-range-track {
  height: 5px;
  border-radius: 999px;
  background: var(--bg-surface-hover);
}
.setting-slider::-moz-range-thumb {
  width: 21px;
  height: 21px;
  border-radius: 50%;
  background: #f2f2f4;
  border: none;
  box-shadow: 0 1px 6px rgba(0, 0, 0, 0.35);
}

/* Eye Comfort Button */
.eye-comfort-btn {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  padding: 7px 11px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  color: var(--text-secondary);
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all 0.15s ease;
}
.eye-comfort-btn.active {
  color: var(--accent-gold);
  border-color: var(--accent-gold-border);
  background-color: var(--accent-gold-subtle);
}

/* Step Pills */
.step-pill {
  min-width: 62px;
  padding: 10px 14px;
  border-radius: 12px;
  font-size: 15px;
  font-weight: 700;
  color: var(--text-primary);
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all 0.15s ease;
}
.step-pill:active { transform: scale(0.95); }
.step-value {
  min-width: 30px;
  text-align: center;
  font-size: 15px;
  font-weight: 700;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
  color: var(--text-primary);
}

.font-more-btn {
  display: inline-flex;
  align-items: center;
  gap: 3px;
  margin-left: auto;
  padding: 8px 10px;
  border-radius: 10px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
  white-space: nowrap;
  flex-shrink: 0;
}

.font-chips-row {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
  padding: 4px 0 10px 52px;
}

/* Color Dots */
.color-dots-row {
  display: flex;
  align-items: center;
  gap: 14px;
  flex-wrap: wrap;
}
.color-dot {
  width: 37px;
  height: 37px;
  min-height: unset;
  padding: 0;
  border-radius: 50% !important;
  border: 1.5px solid rgba(128,128,128,0.35) !important;
  box-shadow: inset 0 1px 3px rgba(0,0,0,0.08);
}
.color-dot.selected {
  box-shadow: 0 0 0 2.5px var(--text-primary), inset 0 1px 3px rgba(0,0,0,0.08) !important;
  border-color: transparent !important;
}
.color-dot .check-icon {
  top: -4px;
  right: -4px;
  width: 16px;
  height: 16px;
}

.sheet-chip-btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  border-radius: 999px;
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-secondary);
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
}

.auto-read-row {
  display: none;
  justify-content: center;
  padding: 10px 0 14px;
}
body.is-reading .auto-read-row { display: flex; }
.autoread-btn {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  padding: 9px 20px;
  border-radius: 999px;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-secondary);
  background: transparent;
  border: none;
  cursor: pointer;
}
.autoread-btn.active { color: var(--accent-gold); }

.sheet-icon-bar {
  position: sticky;
  bottom: 0;
  display: flex;
  align-items: stretch;
  margin: auto -20px -10px;
  background-color: var(--bg-surface);
  border-top: 1px solid var(--border-subtle);
}
.sheet-icon-item {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 4px;
  padding: 11px 0 12px;
  background: transparent;
  border: none;
  color: var(--text-secondary);
  font-size: 11.5px;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s ease, transform 0.15s ease;
}
/* 显式像素尺寸：PWA 独立窗口下不依赖 Tailwind JIT 也保持稳定大小 */
.sheet-icon-item svg {
  width: 22px;
  height: 22px;
}
.eye-comfort-btn svg,
.font-more-btn svg { width: 14px; height: 14px; }
.sheet-chip-btn svg { width: 14px; height: 14px; }
.autoread-btn svg { width: 15px; height: 15px; }
.color-dot svg { width: 12px; height: 12px; }
.toc-pop-btn svg { width: 14px; height: 14px; }
.toc-pop-close svg { width: 16px; height: 16px; }
.sheet-icon-item:active { transform: scale(0.93); color: var(--accent-gold); }

/* Category Bottom Sheet */
.category-backdrop {
  align-items: flex-end;
  justify-content: center;
}
.category-sheet {
  width: 100%;
  max-width: 520px;
  max-height: 72vh;
  background-color: var(--bg-surface);
  color: var(--text-primary);
  border-radius: 20px 20px 0 0;
  border: 1px solid var(--border-subtle);
  padding: 10px 20px calc(20px + env(safe-area-inset-bottom, 0px));
  box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
  cursor: default;
  overflow-y: auto;
  animation: slideInUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
}
@media (min-width: 641px) {
  .category-backdrop { align-items: center; }
  .category-sheet {
    border-radius: 20px;
    padding-bottom: 20px;
    animation: modalPopIn 0.24s cubic-bezier(0.16, 1, 0.3, 1);
  }
}
.cat-header {
  display: flex;
  align-items: baseline;
  gap: 10px;
  padding: 6px 0 14px;
}
.cat-header span {
  font-size: 16px;
  font-weight: 800;
  font-family: "Songti SC", "SimSun", "Noto Serif SC", serif;
}
.cat-header em {
  font-style: normal;
  font-size: 11.5px;
  color: var(--text-muted);
}
.cat-grid {
  display: flex;
  flex-wrap: wrap;
  gap: 9px;
}
.cat-chip {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 8px 14px;
  border-radius: 10px;
  font-size: 13px;
  font-weight: 500;
  color: var(--text-primary);
  background-color: var(--bg-surface-elevated);
  border: 1px solid var(--border-subtle);
  cursor: pointer;
  transition: all 0.15s ease;
}
.cat-chip em {
  font-style: normal;
  font-size: 10.5px;
  color: var(--text-muted);
}
.cat-chip.active {
  color: var(--accent-gold);
  border-color: var(--accent-gold-border);
  background-color: var(--accent-gold-subtle);
}

@keyframes slideInUp {
  from { transform: translateY(100%); }
  to { transform: translateY(0); }
}

@media (max-width: 640px) {
  #settingsDrawer.drawer-backdrop {
    align-items: flex-end;
    justify-content: center;
  }
  #settingsDrawer .settings-sheet {
    max-width: 100%;
    height: auto;
    max-height: 80vh;
    border-radius: 20px 20px 0 0;
    border-left: none;
    border-top: 1px solid var(--border-subtle);
    padding: 10px 18px calc(10px + env(safe-area-inset-bottom, 0px));
    box-shadow: 0 -10px 40px rgba(0, 0, 0, 0.4);
    animation: slideInUp 0.28s cubic-bezier(0.16, 1, 0.3, 1);
  }
  /* 图标栏贴住圆角底边：负边距对齐移动端内边距，安全区只算一次 */
  #settingsDrawer .sheet-icon-bar {
    margin: 8px -18px calc(-10px - env(safe-area-inset-bottom, 0px));
    padding-bottom: env(safe-area-inset-bottom, 0px);
    border-radius: 0 0 0 0;
  }
  .sheet-icon-item { font-size: 12px; }
}
