/* ============================================================
   base.css —— 重置、全屏容器、安全区、通用控件
   ============================================================ */

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  height: 100%;
  overflow: hidden;
  background: var(--read-bg);
  color: var(--read-text);
  font-size: 16px;
  font-family: var(--read-font, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  -webkit-text-size-adjust: 100%;
  -webkit-font-smoothing: antialiased;
}

body {
  /* 固定定位 + 不可滚动，是隐藏浏览器地址栏、避免页面回弹的前提 */
  position: fixed;
  inset: 0;
  touch-action: manipulation;
}

button,
input {
  font-family: inherit;
  color: inherit;
}

button {
  border: 0;
  background: none;
  padding: 0;
  cursor: pointer;
}

img {
  display: block;
}

::-webkit-scrollbar {
  width: 0;
  height: 0;
}

/* ---------- 应用容器与安全区 ---------- */

.app {
  position: absolute;
  inset: 0;
  /* 优先 dvh：iOS 地址栏收起/展开时高度变化更准确 */
  height: 100vh;
  height: 100dvh;
  overflow: hidden;
  background: var(--read-bg);
  color: var(--read-text);
}

.app.is-hidden {
  visibility: hidden;
}

/* ---------- 通用遮罩层（亮度 / 护眼） ---------- */

.overlay {
  position: absolute;
  inset: 0;
  pointer-events: none;
  z-index: 90;
}

.overlay-dim {
  background: #000;
  opacity: 0;
  transition: opacity 0.15s linear;
}

.overlay-eyecare {
  background: var(--eyecare-color, #E8A33D);
  opacity: 0;
  transition: opacity 0.2s linear;
}

/* ---------- 通用面板 / 行 / 分隔线 ---------- */

.panel {
  position: absolute;
  left: 0;
  right: 0;
  z-index: 60;
  background: var(--ui-bg);
  color: var(--ui-text);
  backdrop-filter: blur(12px);
  -webkit-backdrop-filter: blur(12px);
}

.panel-section {
  padding: 14px 16px;
}

.row {
  display: flex;
  align-items: center;
  gap: 10px;
  min-height: 44px;
}

.row-label {
  flex: none;
  width: 3.5em;
  font-size: 15px;
  color: var(--ui-sub);
}

.divider {
  height: 1px;
  background: var(--ui-line);
  margin: 0 16px;
}

.divider-v {
  width: 1px;
  align-self: stretch;
  background: var(--ui-line);
  margin: 6px 0;
}

/* ---------- 圆形图标按钮 ---------- */

.icon-btn {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  flex: 1;
  padding: 4px 0;
  color: var(--ui-text);
  font-size: 13px;
  line-height: 1;
}

.icon-btn svg {
  width: 26px;
  height: 26px;
  stroke: currentColor;
  stroke-width: 1.7;
  fill: none;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-btn.is-active {
  color: var(--ui-accent);
}

/* ---------- 滑块 ---------- */

.range {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  margin: 0;
  padding: 0;
  background: transparent;
  /* 高度跟着滑块走，否则大滑块会被输入框的默认高度挤扁 */
  height: calc(var(--range-thumb) + 8px);
  --range-track-h: 6px;
  --range-thumb: 22px;
}

.range::-webkit-slider-runnable-track {
  height: var(--range-track-h);
  border-radius: calc(var(--range-track-h) / 2);
  /* 半透明中性灰在浅色与深色主题下都能成立，避免为每个主题单独配色 */
  background: rgba(128, 128, 128, 0.22);
}

.range::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: var(--range-thumb);
  height: var(--range-thumb);
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
  margin-top: calc((var(--range-track-h) - var(--range-thumb)) / 2);
}

.range::-moz-range-track {
  height: var(--range-track-h);
  border-radius: calc(var(--range-track-h) / 2);
  background: rgba(128, 128, 128, 0.22);
}

.range::-moz-range-thumb {
  width: var(--range-thumb);
  height: var(--range-thumb);
  border: 0;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.22);
}

.range-lg {
  --range-track-h: 40px;
  --range-thumb: 52px;
}

.range-md {
  --range-track-h: 6px;
  --range-thumb: 22px;
}

/* ---------- 开关 ---------- */

.switch {
  position: relative;
  flex: none;
  width: 46px;
  height: 28px;
  border-radius: 14px;
  background: var(--ui-switch-off);
  transition: background 0.2s ease;
}

.switch::after {
  content: "";
  position: absolute;
  top: 3px;
  left: 3px;
  width: 22px;
  height: 22px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.25);
  transition: transform 0.2s ease;
}

.switch.is-on {
  background: var(--ui-accent);
}

.switch.is-on::after {
  transform: translateX(18px);
}

.switch[aria-disabled="true"] {
  opacity: 0.45;
  pointer-events: none;
}

/* ---------- 胶囊选项 ---------- */

.chip {
  flex: 1;
  min-width: 0;
  padding: 10px 4px;
  border-radius: 999px;
  background: var(--ui-chip);
  color: var(--ui-chip-text);
  font-size: 15px;
  text-align: center;
  transition: background 0.15s ease, color 0.15s ease;
}

.chip.is-active {
  background: var(--ui-accent-soft);
  color: var(--ui-accent);
  box-shadow: inset 0 0 0 1.5px var(--ui-accent);
}

.chip-group {
  display: flex;
  gap: 8px;
  flex: 1;
  min-width: 0;
}

/* ---------- 书架 ---------- */

/* 必须是不透明整屏浮层：阅读层仍在它下面，透明的话会透出正文 */
.shelf {
  position: absolute;
  inset: 0;
  z-index: 80;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  background: var(--read-bg);
  padding:
    calc(env(safe-area-inset-top) + 22px)
    calc(env(safe-area-inset-right) + 18px)
    calc(env(safe-area-inset-bottom) + 24px)
    calc(env(safe-area-inset-left) + 18px);
}

.shelf-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto 14px;
}

.shelf-heading {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
}

/* 次要按钮：把本页固定到手机桌面（桌面快捷方式 / PWA） */
.shelf-pin {
  padding: 9px 16px;
  border: 1px solid var(--ui-line);
  border-radius: 999px;
  background: var(--ui-chip);
  color: var(--ui-chip-text);
  font-size: 13px;
}

.shelf-list {
  display: flex;
  flex-direction: column;
  gap: 12px;
  max-width: 720px;
  margin: 0 auto;
}

.shelf-card {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  width: 100%;
  padding: 12px;
  border-radius: 12px;
  background: var(--ui-chip);
  color: var(--ui-chip-text);
  text-align: left;
}

/* 无封面时只输出空元素占位，所以尺寸与底色都写在这一条上 */
.shelf-cover {
  display: block;
  flex: 0 0 auto;
  width: 76px;
  aspect-ratio: 3 / 4;
  border-radius: 8px;
  object-fit: cover;
  background: var(--ui-line);
}

.shelf-info {
  display: flex;
  flex-direction: column;
  gap: 4px;
  min-width: 0;
}

.shelf-title {
  font-size: 16px;
  font-weight: 600;
}

.shelf-meta {
  font-size: 12px;
  color: var(--ui-sub);
}

.shelf-intro {
  font-size: 13px;
  line-height: 1.6;
  color: var(--ui-sub);
  display: -webkit-box;
  -webkit-box-orient: vertical;
  -webkit-line-clamp: 2;
  overflow: hidden;
}

.shelf-action {
  font-size: 12px;
  color: var(--ui-accent);
}

/* ---------- 开场粒子层 ---------- */

.splash {
  position: absolute;
  inset: 0;
  z-index: 95;
  pointer-events: none;
  opacity: 1;
  transition: opacity 0.5s ease;
}

.splash.is-out {
  opacity: 0;
}

/* ---------- 启动失败提示 ---------- */

.fatal {
  position: absolute;
  inset: 0;
  z-index: 99;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  padding: 32px 24px;
  text-align: center;
  background: var(--read-bg);
  color: var(--read-text);
}

.fatal-title {
  margin: 0;
  font-size: 17px;
  font-weight: 600;
}

.fatal-msg {
  margin: 0;
  max-width: 32em;
  font-size: 14px;
  line-height: 1.8;
  color: var(--ui-sub);
  word-break: break-word;
}

/* ---------- 轻提示 ---------- */

.toast {
  position: absolute;
  left: 50%;
  top: 22%;
  transform: translateX(-50%);
  z-index: 97;
  max-width: 70vw;
  padding: 8px 14px;
  border-radius: 999px;
  background: rgba(0, 0, 0, 0.7);
  color: #fff;
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.2s ease;
  pointer-events: none;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.toast.is-show {
  opacity: 1;
}
