/* 手写稿生成器：悬浮入口、生成面板、结果态
   与阅读页既有 .reader-actions / .reader-settings 不重叠，移动端抽屉 + 桌面侧栏 */

.hw-entry {
  border-color: #c9a45c !important;
  background: linear-gradient(180deg, #fffaf0, #f7edd6) !important;
  color: #7a5b22 !important;
  font-weight: 700 !important;
  display: inline-flex;
  align-items: center;
  gap: 6px;
}
.hw-entry:hover { border-color: #b08d47 !important; color: #6b4d1c !important; }
.hw-entry svg { width: 15px; height: 15px; }
body[data-reader-theme="dark"] .hw-entry {
  background: linear-gradient(180deg, #2a2b23, #23241d) !important;
  color: #e2c98a !important;
  border-color: #6b5a35 !important;
}

/* 移动端：抽成右下角圆形悬浮按钮，位于操作条上方 */
@media (max-width: 768px) {
  .hw-entry {
    position: fixed;
    right: 12px;
    bottom: 116px;
    z-index: 32;
    width: 56px !important;
    height: 56px !important;
    padding: 0 !important;
    border-radius: 50% !important;
    justify-content: center;
    box-shadow: 0 10px 24px rgba(122, 91, 34, .22);
    font-size: 11px;
    line-height: 1;
    flex-direction: column;
    gap: 2px;
  }
  .hw-entry svg { width: 20px; height: 20px; }
  body.script-reader .hw-entry { bottom: 96px; }
}

/* ---------- 遮罩与面板 ---------- */
.hw-overlay {
  position: fixed;
  inset: 0;
  background: rgba(24, 22, 18, .42);
  opacity: 0;
  pointer-events: none;
  transition: opacity .22s ease;
  z-index: 90;
}
.hw-overlay.show { opacity: 1; pointer-events: auto; }
/* 桌面：正文区仍要能读，遮罩只做极轻提示 */
@media (min-width: 769px) {
  .hw-overlay { background: rgba(24, 22, 18, .08); }
}

.hw-panel {
  position: fixed;
  z-index: 95;
  background: #fffdf9;
  color: #3a3733;
  display: flex;
  flex-direction: column;
  box-shadow: -8px 0 40px rgba(60, 50, 34, .18);
  transition: transform .26s cubic-bezier(.22, .61, .36, 1);
}
body[data-reader-theme="dark"] .hw-panel {
  background: #1d1f24;
  color: #d8dce6;
  box-shadow: -8px 0 40px rgba(0, 0, 0, .5);
}

/* 桌面：右侧 440px 侧栏 */
@media (min-width: 769px) {
  .hw-panel {
    top: 0;
    right: 0;
    width: 440px;
    height: 100%;
    transform: translateX(100%);
    border-left: 1px solid #eee2cc;
  }
  .hw-panel.show { transform: translateX(0); }
  body.hw-open .reader-shell { margin-right: 440px; transition: margin-right .26s ease; }
  body[data-reader-theme="dark"] .hw-panel { border-left-color: #2b2f38; }
}

/* 手机：底部抽屉 */
@media (max-width: 768px) {
  .hw-panel {
    left: 0;
    right: 0;
    bottom: 0;
    height: 88vh;
    border-radius: 20px 20px 0 0;
    transform: translateY(100%);
  }
  .hw-panel.show { transform: translateY(0); }
  .hw-grab { display: block; }
  .hw-preview { max-height: 30vh; }
  .hw-preview img { max-height: 30vh; }
}

.hw-grab {
  display: none;
  height: 22px;
  flex: 0 0 auto;
  position: relative;
}
.hw-grab::after {
  content: '';
  position: absolute;
  left: 50%;
  top: 8px;
  width: 40px;
  height: 4px;
  margin-left: -20px;
  border-radius: 2px;
  background: #ded3bd;
}

.hw-head {
  flex: 0 0 auto;
  padding: 14px 18px 10px;
  border-bottom: 1px solid #f0e7d6;
  display: flex;
  align-items: flex-start;
  gap: 10px;
}
.hw-head h3 { margin: 0; font-size: 16px; line-height: 1.2; }
.hw-head p { margin: 4px 0 0; font-size: 12px; color: #8a8272; }
.hw-close {
  margin-left: auto;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid #e6dcc8;
  background: #fff;
  color: #7a7264;
  font-size: 16px;
  line-height: 1;
  cursor: pointer;
}
.hw-close:hover { background: #f7f1e4; }

.hw-body {
  flex: 1 1 auto;
  overflow-y: auto;
  padding: 12px 18px 18px;
  -webkit-overflow-scrolling: touch;
}

.hw-sec { margin-bottom: 16px; }
.hw-label {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  color: #7a7264;
  margin-bottom: 8px;
  letter-spacing: .3px;
}
.hw-label .hw-val {
  margin-left: auto;
  font-weight: 600;
  color: #a58a4e;
  font-variant-numeric: tabular-nums;
}

/* 预览 */
.hw-preview {
  position: relative;
  border-radius: 12px;
  overflow: hidden;
  background: #f2ece0;
  border: 1px solid #eee3cf;
  display: flex;
  align-items: center;
  justify-content: center;
  min-height: 160px;
  max-height: 46vh;
}
.hw-preview img {
  display: block;
  max-width: 100%;
  max-height: 46vh;
  width: auto;
}
.hw-preview .hw-empty { font-size: 13px; color: #9a9184; padding: 24px; text-align: center; }
.hw-badge {
  position: absolute;
  left: 10px;
  bottom: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(28, 26, 22, .62);
  color: #fff;
  font-size: 11px;
}
.hw-meta {
  position: absolute;
  right: 10px;
  bottom: 10px;
  padding: 3px 9px;
  border-radius: 999px;
  background: rgba(255, 255, 255, .86);
  color: #6f6656;
  font-size: 11px;
}
.hw-spinner {
  width: 22px;
  height: 22px;
  border-radius: 50%;
  border: 2px solid #e2d6bd;
  border-top-color: #b08d47;
  animation: hw-spin .8s linear infinite;
}
@keyframes hw-spin { to { transform: rotate(360deg); } }

/* 模板卡片 */
.hw-row {
  display: flex;
  gap: 10px;
  overflow-x: auto;
  padding-bottom: 4px;
  scrollbar-width: none;
}
.hw-row::-webkit-scrollbar { display: none; }
.hw-tpl {
  flex: 0 0 auto;
  width: 96px;
  border: 2px solid transparent;
  border-radius: 10px;
  padding: 3px;
  background: none;
  cursor: pointer;
  position: relative;
}
.hw-tpl img {
  display: block;
  width: 100%;
  aspect-ratio: 9 / 16;
  object-fit: cover;
  border-radius: 7px;
  background: #f2ece0;
}
.hw-tpl span {
  display: block;
  font-size: 11px;
  color: #6f6656;
  margin-top: 4px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.hw-tpl.on { border-color: #c9a45c; background: #fdf7ea; }
.hw-tpl.on::after {
  content: '✓';
  position: absolute;
  top: 6px;
  right: 6px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #c9a45c;
  color: #fff;
  font-size: 11px;
  line-height: 18px;
  text-align: center;
}

/* 字体 */
.hw-font {
  flex: 0 0 auto;
  min-width: 72px;
  padding: 6px 10px;
  border-radius: 10px;
  border: 1px solid #ece1cc;
  background: #fff;
  cursor: pointer;
  text-align: center;
}
.hw-font b { display: block; font-size: 20px; font-weight: 400; line-height: 1.1; }
.hw-font span { display: block; font-size: 10.5px; color: #8a8272; margin-top: 2px; }
.hw-font.on { border-color: #c9a45c; background: #fdf7ea; }

/* 滑块 */
.hw-slider { display: flex; align-items: center; gap: 10px; margin: 8px 0; }
.hw-slider input[type="range"] {
  flex: 1;
  -webkit-appearance: none;
  appearance: none;
  height: 26px;
  background: none;
}
.hw-slider input[type="range"]::-webkit-slider-runnable-track {
  height: 4px;
  border-radius: 2px;
  background: #ece3d1;
}
.hw-slider input[type="range"]::-webkit-slider-thumb {
  -webkit-appearance: none;
  width: 20px;
  height: 20px;
  margin-top: -8px;
  border-radius: 50%;
  background: #c9a45c;
  border: 2px solid #fff;
  box-shadow: 0 1px 4px rgba(120, 96, 40, .3);
}
.hw-slider input[type="range"]::-moz-range-track { height: 4px; border-radius: 2px; background: #ece3d1; }
.hw-slider input[type="range"]::-moz-range-thumb {
  width: 18px; height: 18px; border-radius: 50%; background: #c9a45c; border: 2px solid #fff;
}

/* 墨色 */
.hw-inks { display: flex; gap: 10px; }
.hw-ink {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 2px solid #fff;
  box-shadow: 0 0 0 1px #e6dcc8;
  cursor: pointer;
}
.hw-ink.on { box-shadow: 0 0 0 2px #c9a45c; }

/* 尺寸与开关 */
.hw-chips { display: flex; flex-wrap: wrap; gap: 8px; }
.hw-chip {
  padding: 7px 12px;
  border-radius: 999px;
  border: 1px solid #e6dcc8;
  background: #fff;
  font-size: 12px;
  color: #6f6656;
  cursor: pointer;
}
.hw-chip.on { border-color: #c9a45c; background: #fdf7ea; color: #7a5b22; font-weight: 600; }

.hw-toggles { display: flex; flex-wrap: wrap; gap: 10px 18px; }
.hw-toggle { display: inline-flex; align-items: center; gap: 6px; font-size: 12.5px; color: #5f5749; }
.hw-toggle input { width: 16px; height: 16px; accent-color: #c9a45c; }

.hw-hint {
  font-size: 11.5px;
  line-height: 1.6;
  color: #8a8272;
  background: #fdf6e6;
  border: 1px solid #f0e4c8;
  border-radius: 8px;
  padding: 8px 10px;
  margin-top: 6px;
}
.hw-hint strong { color: #7a5b22; }

/* 底部操作栏 */
.hw-foot {
  flex: 0 0 auto;
  display: flex;
  gap: 10px;
  padding: 12px 18px calc(12px + env(safe-area-inset-bottom));
  border-top: 1px solid #f0e7d6;
  background: #fffdf9;
}
body[data-reader-theme="dark"] .hw-foot { background: #1d1f24; border-top-color: #2b2f38; }
.hw-btn {
  flex: 1;
  height: 44px;
  border-radius: 10px;
  border: 1px solid #e6dcc8;
  background: #fff;
  color: #5f5749;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.hw-btn.primary {
  flex: 1.6;
  background: linear-gradient(180deg, #d2ae66, #b08d47);
  border-color: #b08d47;
  color: #fff;
  box-shadow: 0 6px 16px rgba(176, 141, 71, .28);
}
.hw-btn.primary:disabled { opacity: .78; cursor: default; box-shadow: none; }
.hw-btn.ghost { flex: 0 0 96px; }

/* 结果态 */
.hw-results { display: none; }
.hw-results.show { display: block; }
.hw-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 768px) { .hw-grid { grid-template-columns: repeat(2, 1fr); } }
.hw-grid figure { margin: 0; position: relative; }
.hw-grid img {
  display: block;
  width: 100%;
  border-radius: 8px;
  border: 1px solid #ece1cc;
  background: #f2ece0;
  -webkit-touch-callout: default;
  -webkit-user-select: none;
  user-select: none;
}
.hw-grid figcaption {
  position: absolute;
  left: 0;
  bottom: 0;
  padding: 2px 8px;
  border-radius: 0 8px 0 8px;
  background: rgba(28, 26, 22, .6);
  color: #fff;
  font-size: 10.5px;
}

.hw-lightbox {
  position: fixed;
  inset: 0;
  z-index: 120;
  background: rgba(12, 11, 9, .92);
  display: none;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 10px;
}
.hw-lightbox.show { display: flex; }
.hw-lightbox img { max-width: 96vw; max-height: 82vh; border-radius: 8px; }
.hw-lightbox .hw-lb-bar { color: #e8e2d4; font-size: 12px; display: flex; gap: 16px; align-items: center; }
.hw-lightbox button {
  border: 1px solid rgba(255, 255, 255, .3);
  background: rgba(255, 255, 255, .12);
  color: #fff;
  border-radius: 999px;
  padding: 8px 16px;
  font-size: 12.5px;
  cursor: pointer;
}

.hw-toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  transform: translate(-50%, 10px);
  z-index: 130;
  max-width: 84vw;
  padding: 9px 16px;
  border-radius: 999px;
  background: rgba(28, 26, 22, .92);
  color: #fff;
  font-size: 12.5px;
  line-height: 1.5;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s ease, transform .2s ease;
}
.hw-toast.show { opacity: 1; transform: translate(-50%, 0); }

/* 手机端预览压到 30vh，给设置项留出空间（放在文件末尾确保覆盖通用规则） */
@media (max-width: 768px) {
  .hw-panel .hw-tpl { width: 82px; }
  .hw-panel .hw-tpl img { aspect-ratio: 3 / 4; object-fit: cover; object-position: top center; }
  .hw-panel .hw-preview { max-height: 30vh; }
  .hw-panel .hw-preview img { max-height: 30vh; }
}

/* 手机端 FAB 只显示图标，更干净；桌面保留文字 */
@media (max-width: 768px) {
  .hw-panel .hw-grid figure:only-child { grid-column: 1 / -1; max-width: 62%; margin: 0 auto; }
}
@media (max-width: 768px) {
  .reader-actions .hw-entry span { display: none; }
  .reader-actions .hw-entry svg { width: 24px; height: 24px; }
}
