@font-face {
  font-family: "CoverHand";
  src: url("../assets/hand.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "CoverSong";
  src: url("../assets/song.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "CoverKai";
  src: url("../assets/kai.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "CoverButter";
  src: url("../assets/butter.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "CoverXiaoWei";
  src: url("../assets/xiaowei.woff2") format("woff2");
  font-weight: 400 900;
  font-style: normal;
  font-display: swap;
}

:root {
  --ink: #14202b;
  --muted: #6f7c88;
  --line: #eef0f3;
  --pink: #ff2e4d;
  --safe-top: var(--safe-area-inset-top, env(safe-area-inset-top, 0px));
  --safe-bottom: var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px));
}

*,
*::before,
*::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  height: 100%;
  touch-action: manipulation;
}

body {
  height: 100%;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB",
    "Noto Sans CJK SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  -webkit-touch-callout: none;
  background: linear-gradient(165deg, #e8f7ee 0%, #edf4ff 52%, #f6efff 100%);
  background-attachment: fixed;
  overflow: hidden;
}

body,
.app {
  -webkit-user-select: none;
  user-select: none;
}

input,
textarea {
  -webkit-user-select: text;
  user-select: text;
}

.app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 560px;
  margin: 0 auto;
  position: relative;
  padding-top: var(--safe-top);
}

/* 只有屏幕极小时才允许整页滚动兜底 */
.wrap {
  flex: 1 1 auto;
  min-height: 0;
  overflow-y: auto;
  overflow-x: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 0 12px 10px;
}

/* ---------------- 预览 ---------------- */

.preview-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 4px 0 0;
}

.cover-stage {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: center;
  width: 100%;
  max-width: 100%;
  height: 268px;
  perspective: 1000px;
  perspective-origin: 50% 45%;
  touch-action: pan-y;
  -webkit-user-select: none;
  user-select: none;
}

.preview-frame {
  position: relative;
  z-index: 3;
  flex: 0 0 auto;
  width: 190px;
  height: 253px;
  padding: 0;
  border: 0;
  border-radius: 14px;
  background: #fff;
  box-shadow: 0 10px 24px rgba(52, 66, 120, 0.2);
  overflow: hidden;
  -webkit-appearance: none;
  appearance: none;
  transform: translateX(var(--dx, 0px)) rotateY(calc(var(--dx, 0px) * -0.055deg)) scale(calc(1 - var(--abs, 0) * 0.0002));
  transition: transform 0.34s cubic-bezier(0.22, 0.75, 0.3, 1);
  will-change: transform;
}

.cover-side {
  position: relative;
  z-index: 2;
  flex: 0 0 auto;
  width: 132px;
  height: 176px;
  margin: 0 -34px;
  box-shadow: 0 10px 22px rgba(20, 30, 50, 0.10);
  border-radius: 12px;
  overflow: hidden;
  background: #fff;
  box-shadow: 0 6px 16px rgba(52, 66, 120, 0.14);
  opacity: 0.94;
  transform: translateX(calc(var(--dx, 0px) * 0.55)) rotateY(34deg) scale(0.93) translateZ(-52px);
  transition: transform 0.34s cubic-bezier(0.22, 0.75, 0.3, 1), opacity 0.34s;
  will-change: transform;
  cursor: pointer;
}

.cover-side.side-next {
  transform: translateX(calc(var(--dx, 0px) * 0.55)) rotateY(-34deg) scale(0.93) translateZ(-52px);
}

.cover-side::after {
  content: "";
  position: absolute;
  inset: 0;
  border-radius: 12px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.5), inset 0 22px 40px -20px rgba(20, 26, 40, 0.5);
  pointer-events: none;
}

.cover-side canvas {
  width: 100%;
  height: 100%;
  display: block;
}

.preview-frame canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.preview-hint {
  margin-top: 6px;
  font-size: 10px;
  color: #98a4b0;
}

/* ---------------- 卡片 ---------------- */

.card {
  margin-top: 8px;
  padding: 10px 12px 12px;
  background: rgba(255, 255, 255, 0.9);
  border-radius: 16px;
  box-shadow: 0 5px 16px rgba(96, 118, 168, 0.08);
}

.card-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.card-title {
  font-size: 13px;
  font-weight: 700;
  letter-spacing: 0.2px;
}

.card-note {
  font-size: 11px;
  color: var(--muted);
}

.counter {
  font-size: 11px;
  color: #9aa2ab;
}

.tpl-name {
  margin-left: auto;
  margin-right: 10px;
  font-size: 11px;
  font-weight: 600;
  color: var(--pink);
}

/* ---------------- 文字 ---------------- */

.text-area {
  display: block;
  width: 100%;
  min-height: 62px;
  max-height: 62px;
  padding: 9px 11px;
  border: 0;
  border-radius: 12px;
  background: #f5f6f8;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  line-height: 1.5;
  resize: none;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.text-area::placeholder {
  color: #b3bac2;
}

.inline-row {
  display: flex;
  align-items: center;
  margin-top: 7px;
  padding: 0 11px;
  height: 34px;
  border-radius: 12px;
  background: #f5f6f8;
}

.inline-label {
  flex: 0 0 auto;
  margin-right: 8px;
  font-size: 12px;
  color: var(--muted);
}

.inline-input {
  flex: 1 1 auto;
  min-width: 0;
  border: 0;
  background: none;
  color: var(--ink);
  font-family: inherit;
  font-size: 13px;
  outline: none;
}

.inline-input::placeholder {
  color: #b3bac2;
}

.credit-input {
  flex: 0 1 auto;
  width: 76px;
  margin-left: 8px;
  padding: 0 8px;
  height: 26px;
  border-radius: 8px;
  background: #f5f6f8;
  font-size: 12px;
  text-align: center;
}

/* ---------------- 版式 ---------------- */

.chips {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 4px;
  margin-bottom: 2px;
}

.chips::-webkit-scrollbar,
.thumbs::-webkit-scrollbar,
.swatches::-webkit-scrollbar,
.favs::-webkit-scrollbar {
  display: none;
}

.chip {
  flex: 0 0 auto;
  margin-right: 6px;
  padding: 0 12px;
  height: 26px;
  line-height: 26px;
  border: 0;
  border-radius: 13px;
  background: #f5f6f8;
  color: #55606c;
  font-family: inherit;
  font-size: 12px;
  -webkit-appearance: none;
  appearance: none;
}

.chip.is-active {
  background: #17191d;
  color: #fff;
  font-weight: 600;
}

.thumbs {
  display: flex;
  overflow-x: auto;
  overflow-y: hidden;
  -webkit-overflow-scrolling: touch;
  padding: 2px 0 2px;
}

.thumb {
  flex: 0 0 auto;
  width: 58px;
  margin-right: 7px;
  padding: 0;
  border: 0;
  background: none;
  font-family: inherit;
  color: inherit;
  text-align: center;
  -webkit-appearance: none;
  appearance: none;
}

.thumb-box {
  position: relative;
  width: 100%;
  padding-top: 133.3333%;
  border-radius: 9px;
  overflow: hidden;
  background: #f2f3f5;
  box-shadow: 0 2px 8px rgba(52, 66, 120, 0.1);
}

.thumb.is-active .thumb-box {
  box-shadow: 0 0 0 2px var(--pink), 0 4px 12px rgba(255, 46, 77, 0.22);
}

.thumb canvas {
  position: absolute;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  display: block;
}

.thumb-name {
  display: block;
  margin-top: 4px;
  font-size: 10px;
  line-height: 1.2;
  color: var(--muted);
}

.thumb.is-active .thumb-name {
  color: var(--pink);
  font-weight: 600;
}

.fav-add {
  flex: 0 0 auto;
  margin-left: 8px;
  padding: 0 10px;
  height: 25px;
  line-height: 25px;
  border: 1px dashed #d8b7bf;
  border-radius: 13px;
  background: #fff;
  color: #b06070;
  font-family: inherit;
  font-size: 11px;
  -webkit-appearance: none;
  appearance: none;
}

/* ---------------- 微调 ---------------- */

.tune-row {
  display: flex;
  align-items: center;
  margin-top: 5px;
}

.tune-label {
  flex: 0 0 auto;
  width: 32px;
  font-size: 11px;
  color: var(--muted);
}

.tune-label-tight {
  width: auto;
  margin-left: 12px;
  margin-right: 4px;
}

.seg {
  display: flex;
  flex: 0 0 auto;
  height: 28px;
  padding: 2px;
  border-radius: 14px;
  background: #f2f3f5;
}

.seg-item {
  border: 0;
  border-radius: 12px;
  background: none;
  color: #4b5560;
  font-family: inherit;
  font-size: 12px;
  -webkit-appearance: none;
  appearance: none;
}

.seg-item.is-active {
  background: #fff;
  color: var(--pink);
  font-weight: 700;
  box-shadow: 0 1px 4px rgba(24, 28, 40, 0.12);
}

.seg-font .seg-item {
  padding: 0 7px;
  font-size: 12px;
}

.seg-font {
  overflow-x: auto;
  max-width: 100%;
}

.seg-font::-webkit-scrollbar {
  display: none;
}

.seg-size {
  margin-left: 8px;
}

.seg-size .seg-item {
  padding: 0 7px;
}

.swatches {
  display: flex;
  flex: 1 1 auto;
  align-items: center;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
}

.swatch {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  margin-right: 7px;
  border: 2px solid #fff;
  border-radius: 50%;
  box-shadow: 0 0 0 1px #e3e6ea;
  font-family: inherit;
  font-size: 10px;
  color: #6b7580;
  background: #f0f1f3;
  -webkit-appearance: none;
  appearance: none;
}

.swatch.is-active {
  box-shadow: 0 0 0 2px var(--pink);
}

.switch {
  position: relative;
  flex: 0 0 auto;
  width: 42px;
  height: 24px;
  border: 0;
  border-radius: 12px;
  background: #e2e5ea;
  -webkit-appearance: none;
  appearance: none;
}

.switch .knob {
  position: absolute;
  top: 3px;
  left: 3px;
  width: 18px;
  height: 18px;
  border-radius: 50%;
  background: #fff;
  box-shadow: 0 1px 3px rgba(24, 28, 40, 0.2);
}

.switch.is-on {
  background: var(--pink);
}

.switch.is-on .knob {
  left: 21px;
}

/* ---------------- 收藏 ---------------- */

.favs {
  display: flex;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  padding-bottom: 2px;
}

.fav-chip {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  margin-right: 8px;
  padding: 0 10px;
  height: 28px;
  border: 0;
  border-radius: 14px;
  background: #f5f6f8;
  color: #3d4854;
  font-family: inherit;
  font-size: 12px;
  -webkit-appearance: none;
  appearance: none;
}

.fav-chip-del {
  margin-left: 6px;
  color: #a9b0b9;
  font-size: 13px;
}

.foot-note {
  margin: 8px 0 4px;
  text-align: center;
  font-size: 10px;
  color: #98a4b0;
}

/* ---------------- 底部栏 ---------------- */

.bar {
  flex: 0 0 auto;
  display: flex;
  padding: 8px 12px calc(8px + var(--safe-bottom));
  background: rgba(255, 255, 255, 0.92);
  box-shadow: 0 -4px 16px rgba(24, 28, 40, 0.08);
}

.btn {
  height: 46px;
  border: 0;
  border-radius: 23px;
  font-family: inherit;
  font-size: 15px;
  font-weight: 600;
  -webkit-appearance: none;
  appearance: none;
}

.btn.ghost {
  flex: 0 0 108px;
  margin-right: 10px;
  background: #f2f3f5;
  color: #38414b;
}

.btn.primary {
  flex: 1 1 auto;
  background: var(--pink);
  color: #fff;
  box-shadow: 0 6px 16px rgba(255, 46, 77, 0.28);
}

.btn[disabled] {
  opacity: 0.65;
}

/* ---------------- 收藏命名弹层 ---------------- */

.sheet {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 20;
}

.sheet[hidden] {
  display: none;
}

.sheet-mask {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(16, 17, 20, 0.42);
}

.sheet-card {
  position: absolute;
  right: 0;
  bottom: 0;
  left: 0;
  padding: 18px 16px calc(18px + var(--safe-bottom));
  border-radius: 22px 22px 0 0;
  background: #fff;
}

.sheet-card h3 {
  font-size: 16px;
  font-weight: 700;
}

.sheet-sub {
  margin-top: 4px;
  font-size: 12px;
  color: var(--muted);
}

.sheet-card .text-input {
  display: block;
  width: 100%;
  height: 44px;
  margin-top: 12px;
  padding: 0 12px;
  border: 0;
  border-radius: 12px;
  background: #f5f6f8;
  color: var(--ink);
  font-family: inherit;
  font-size: 14px;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}

.sheet-actions {
  display: flex;
  margin-top: 14px;
}

.sheet-actions .btn {
  flex: 1 1 auto;
  height: 44px;
}

.sheet-actions .btn:first-child {
  margin-right: 10px;
}

/* ---------------- 大图查看 ---------------- */

.viewer {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  z-index: 30;
  background: rgba(16, 17, 20, 0.92);
}

.viewer[hidden] {
  display: none;
}

.viewer-body {
  position: absolute;
  top: 0;
  right: 16px;
  bottom: 0;
  left: 16px;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
}

.viewer-body img {
  max-width: 100%;
  max-height: 78%;
  border-radius: 10px;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.4);
}

.viewer-tip {
  margin-top: 14px;
  font-size: 12px;
  color: #d5d8dd;
  text-align: center;
}

/* ---------------- toast ---------------- */

.toast {
  position: fixed;
  left: 50%;
  bottom: 96px;
  z-index: 40;
  max-width: 78%;
  padding: 9px 16px;
  border-radius: 18px;
  background: rgba(20, 22, 26, 0.9);
  color: #fff;
  font-size: 13px;
  line-height: 1.4;
  text-align: center;
  transform: translateX(-50%);
}

.toast[hidden] {
  display: none;
}

/* ---------------- 兜底：窄屏微调 ---------------- */

@media (max-width: 384px) {
  .seg-font .seg-item {
    padding: 0 6px;
  }

  .seg-size .seg-item {
    padding: 0 6px;
  }

  .seg-size {
    margin-left: 6px;
  }
}

@media (min-width: 420px) {
  .cover-stage { height: 296px; }
  .preview-frame { width: 208px; height: 277px; }
  .cover-side { width: 146px; height: 195px; margin: 0 -38px; }
}

@media (max-height: 860px) {
  .card { margin-top: 6px; padding: 9px 11px 10px; }
  .text-area { min-height: 58px; max-height: 58px; font-size: 13px; }
  .inline-row { height: 32px; margin-top: 6px; }
  .chip { height: 26px; line-height: 26px; }
  .thumb { width: 54px; margin-right: 6px; }
  .thumb-name { margin-top: 3px; font-size: 9px; }
  .tune-row { margin-top: 5px; }
  .seg { height: 27px; }
  .swatch { width: 23px; height: 23px; margin-right: 6px; }
  .foot-note { display: none; }
}

@media (max-height: 800px) {
  .cover-stage { height: 212px; }
  .preview-frame { width: 158px; height: 211px; border-radius: 11px; }
  .cover-side { width: 110px; height: 147px; margin: 0 -26px; border-radius: 9px; }
  .preview-hint { margin-top: 4px; font-size: 9px; }
  .tune-row { margin-top: 4px; }
  .inline-row { height: 30px; margin-top: 5px; }
  .btn { height: 42px; }
}

@media (max-height: 700px) {
  .cover-stage { height: 162px; }
  .preview-frame { width: 120px; height: 160px; }
  .cover-side { width: 84px; height: 112px; margin: 0 -18px; }
  .text-area { min-height: 46px; max-height: 46px; }
  .text-card .meta-row { height: 28px; }
  .thumb { width: 48px; }
  .chip { height: 22px; line-height: 22px; }
  .style-card .card-head { margin-bottom: 4px; }
}

@media (max-height: 660px) {
  .cover-stage { height: 140px; }
  .preview-frame { width: 104px; height: 139px; }
  .cover-side { width: 74px; height: 98px; margin: 0 -14px; }
  .text-area { min-height: 44px; max-height: 44px; }
  .text-card .meta-row { height: 26px; margin-top: 4px; }
  .thumb { width: 44px; }
  .card { margin-top: 5px; padding: 7px 9px 8px; }
  .tune-row { margin-top: 3px; }
}

/* ---------------- 横版画布适配 ---------------- */
.orient-card {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.orient-switch {
  display: flex;
  gap: 8px;
}

.orient-btn {
  flex: 1;
  height: 44px;
  border: 0;
  border-radius: 14px;
  background: #f2f3f5;
  color: #4b5560;
  font-family: inherit;
  font-size: 14px;
  font-weight: 600;
  -webkit-appearance: none;
  appearance: none;
}

.orient-btn.is-active {
  background: #fff;
  color: var(--pink);
  box-shadow: 0 1px 6px rgba(24, 28, 40, 0.14);
}

.seg-ratio {
  align-self: center;
}

.seg-ratio .seg-item {
  padding: 0 10px;
  font-size: 12px;
}

.app[data-orient="landscape"] .cover-stage {
  height: auto;
  padding: 8px 0;
}

.app[data-orient="landscape"] .preview-frame {
  width: 300px;
  height: auto;
  aspect-ratio: 4 / 3;
  border-radius: 12px;
}

.app[data-orient="landscape"] .cover-side {
  width: 132px;
  height: auto;
  aspect-ratio: 4 / 3;
  margin: 0 -22px;
  border-radius: 10px;
}

.app[data-orient="landscape"] .thumb {
  width: 86px;
}

.app[data-orient="landscape"] .thumb-box {
  padding-top: 75%;
}

@media (max-width: 420px) {
  .app[data-orient="landscape"] .preview-frame { width: 236px; }
  .app[data-orient="landscape"] .cover-side { width: 104px; margin: 0 -16px; }
}
