@import url("https://fonts.googleapis.com/css2?family=Long+Cang&family=Ma+Shan+Zheng&family=Noto+Serif+SC:wght@400;600;700&family=ZCOOL+XiaoWei&display=swap");

:root {
  --paper: #f3eee5;
  --paper-deep: #e9e1d4;
  --ink: #181512;
  --muted: #766f66;
  --line: rgba(34, 28, 22, 0.14);
  --red: #a72f2b;
  --white: #fffdf8;
}

* { box-sizing: border-box; }
html { scroll-behavior: smooth; }
body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    radial-gradient(circle at 15% 4%, rgba(167,47,43,.055), transparent 28%),
    linear-gradient(rgba(61,49,36,.025) 1px, transparent 1px),
    var(--paper);
  background-size: auto, 100% 28px, auto;
  font-family: "Noto Serif SC", "Songti SC", serif;
}
button, input { font: inherit; }
button { color: inherit; }
button:focus-visible, input:focus-visible { outline: 2px solid var(--red); outline-offset: 2px; }

header {
  width: min(100% - 32px, 720px);
  height: 74px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--ink); text-decoration: none; font-weight: 700; }
.brand > span:last-child { display: flex; flex-direction: column; gap: 1px; }
.brand small { color: #8c857b; font: 7px ui-monospace, monospace; letter-spacing: .14em; }
.brand-seal {
  display: grid;
  width: 35px; height: 35px;
  place-items: center;
  color: #fff7eb;
  background: var(--red);
  font-family: "Ma Shan Zheng", cursive;
  font-size: 20px;
  transform: rotate(-4deg);
  box-shadow: inset 0 0 0 2px rgba(255,255,255,.2);
}
.history-button {
  padding: 8px 10px;
  border: 0;
  cursor: pointer;
  background: transparent;
  font-size: 11px;
}
.history-button b {
  display: inline-grid;
  min-width: 20px; height: 20px;
  margin-left: 4px;
  place-items: center;
  border-radius: 50%;
  color: #fff;
  background: var(--ink);
  font: 9px ui-monospace, monospace;
}
main { width: min(100% - 28px, 720px); margin: 0 auto; }
.intro { padding: 52px 2px 34px; }
.eyebrow { margin: 0 0 12px; color: var(--red); font: 9px ui-monospace, monospace; letter-spacing: .16em; }
h1 { margin: 0; font-size: clamp(42px, 13vw, 70px); line-height: 1.08; letter-spacing: -.07em; }
h1 em { color: var(--red); font-style: normal; font-weight: 400; }
.intro > p:last-child { max-width: 440px; margin: 18px 0 0; color: var(--muted); font-size: 13px; line-height: 1.8; }

.studio { padding: 22px 0 58px; }
.name-field > label, .choice-row label { display: block; margin-bottom: 9px; color: #5d574f; font-size: 11px; font-weight: 600; }
.input-row {
  height: 62px;
  display: flex;
  align-items: center;
  border-bottom: 2px solid var(--ink);
}
.input-row input {
  min-width: 0;
  flex: 1;
  border: 0;
  outline: 0;
  background: transparent;
  font-size: 23px;
  font-weight: 600;
}
.input-row input::placeholder { color: #aaa297; }
.input-row button {
  width: 38px; height: 38px;
  border: 0;
  cursor: pointer;
  color: #8e877d;
  background: transparent;
  font-size: 23px;
}
.input-meta { display: flex; justify-content: space-between; margin-top: 8px; color: #9a9287; font-size: 9px; }

.preview-card {
  margin-top: 30px;
  padding: 13px;
  border: 1px solid var(--line);
  background: rgba(255,253,248,.7);
  box-shadow: 0 24px 70px rgba(61,47,34,.09);
}
.preview-head, .preview-foot {
  display: flex;
  align-items: center;
  justify-content: space-between;
  font: 9px ui-monospace, monospace;
  letter-spacing: .08em;
}
.preview-head { height: 36px; color: #696158; }
.preview-head button { border: 0; cursor: pointer; color: var(--red); background: transparent; font-size: 10px; }
.canvas-wrap {
  position: relative;
  overflow: hidden;
  aspect-ratio: 1.58;
  border: 1px solid rgba(34,28,22,.1);
  background: #ede6d9;
}
#signatureCanvas { display: block; width: 100%; height: 100%; }
.empty-tip {
  position: absolute; inset: 0;
  display: grid;
  place-items: center;
  margin: 0;
  color: #999186;
  font-size: 12px;
}
.preview-foot { height: 34px; color: #928a80; font-size: 8px; }

.control-section { padding-top: 38px; }
.section-title { display: flex; align-items: flex-end; justify-content: space-between; margin-bottom: 16px; }
.section-title > div { display: flex; align-items: center; gap: 9px; }
.section-title span { color: var(--red); font: 9px ui-monospace, monospace; }
.section-title h2 { margin: 0; font-size: 17px; }
.section-title small { color: #999187; font-size: 8px; }
.style-list {
  display: grid;
  grid-auto-flow: column;
  grid-auto-columns: 142px;
  gap: 9px;
  overflow-x: auto;
  padding: 1px 1px 10px;
  scrollbar-width: none;
  scroll-snap-type: x mandatory;
}
.style-list::-webkit-scrollbar { display: none; }
.style-option {
  min-height: 132px;
  padding: 14px 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  text-align: left;
  background: rgba(255,253,248,.58);
  scroll-snap-align: start;
}
.style-option.active { border-color: var(--red); box-shadow: inset 0 -3px 0 var(--red); }
.style-sample {
  height: 56px;
  display: flex;
  align-items: center;
  color: #29241f;
  font-size: 27px;
  white-space: nowrap;
}
.style-flow { font-family: "Ma Shan Zheng", cursive; transform: skewX(-8deg); }
.style-ink { font-family: "Long Cang", cursive; font-size: 34px; font-weight: 700; }
.style-minimal { font-family: "Noto Serif SC", serif; font-size: 19px; letter-spacing: .14em; }
.style-orbit { font-family: "ZCOOL XiaoWei", serif; font-style: italic; }
.style-seal { font-family: "ZCOOL XiaoWei", serif; letter-spacing: .05em; }
.style-dragon { font-family: "Long Cang", cursive; font-size: 37px; transform: skewX(-10deg) rotate(-3deg); }
.style-ribbon { font-family: "Ma Shan Zheng", cursive; font-size: 29px; font-style: italic; border-bottom: 1px solid currentColor; }
.style-business { font-family: "Noto Serif SC", serif; font-size: 21px; font-weight: 600; transform: skewX(-8deg); }
.style-monogram { font-family: Georgia, serif; font-size: 24px; letter-spacing: -.08em; font-style: italic; }
.style-geometry { font-family: "ZCOOL XiaoWei", serif; font-size: 21px; letter-spacing: .12em; text-decoration: underline; }
.style-vertical { width: 30px; height: 62px; line-height: 1.05; white-space: normal; font-family: "ZCOOL XiaoWei", serif; font-size: 17px; text-align: center; }
.style-flourish { font-family: "Ma Shan Zheng", cursive; font-size: 28px; text-decoration: underline double; transform: skewX(-12deg); }
.style-wang { font-family: "Ma Shan Zheng", cursive; font-size: 30px; transform: skewX(-7deg); }
.style-su { font-family: "ZCOOL XiaoWei", serif; font-size: 26px; font-weight: 700; transform: rotate(2deg); }
.style-libai { font-family: "Long Cang", cursive; font-size: 38px; transform: skewX(-13deg) rotate(-4deg); }
.style-yan { font-family: "Noto Serif SC", serif; font-size: 22px; font-weight: 700; letter-spacing: .06em; }
.style-huaisu { font-family: "Long Cang", cursive; font-size: 37px; transform: skewX(-16deg); }
.style-mifu { font-family: "Ma Shan Zheng", cursive; font-size: 31px; transform: skewX(-9deg) rotate(-2deg); }
.style-zhao { font-family: "ZCOOL XiaoWei", serif; font-size: 25px; letter-spacing: .04em; }
.master-option { position: relative; background: rgba(167,47,43,.035); }
.master-tag {
  position: absolute;
  top: 8px; right: 8px;
  padding: 2px 4px;
  color: var(--red);
  background: rgba(167,47,43,.08);
  font: 7px ui-monospace, monospace;
}
.style-option b, .style-option small { display: block; }
.style-option b { font-size: 12px; }
.style-option small { margin-top: 3px; color: #9a9287; font-size: 8px; }

.choice-row { display: grid; gap: 25px; }
.swatches, .backgrounds { display: flex; gap: 9px; }
.swatch {
  width: 42px; height: 42px;
  display: grid;
  place-items: center;
  border: 1px solid var(--line);
  border-radius: 50%;
  cursor: pointer;
  background: transparent;
}
.swatch i { width: 26px; height: 26px; border-radius: 50%; }
.swatch.active { border: 2px solid var(--ink); }
.backgrounds { overflow-x: auto; }
.backgrounds button {
  min-width: 58px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  cursor: pointer;
  background: rgba(255,253,248,.5);
  font-size: 10px;
}
.backgrounds button.active { border-color: var(--ink); color: #fff; background: var(--ink); }

.action-bar {
  position: sticky;
  bottom: 0;
  z-index: 8;
  margin: 38px -14px 0;
  padding: 11px 14px calc(11px + env(safe-area-inset-bottom));
  display: grid;
  grid-template-columns: .72fr 1.28fr;
  gap: 8px;
  background: rgba(243,238,229,.91);
  backdrop-filter: blur(15px);
}
.action-bar button { min-height: 52px; border: 1px solid var(--ink); cursor: pointer; font-size: 12px; font-weight: 700; }
.action-bar .secondary { background: transparent; }
.action-bar .primary { color: #fffaf0; background: var(--ink); }
.action-bar .primary:active { background: var(--red); }
.privacy-note { margin: 17px 5px 0; color: #9a9287; font-size: 9px; line-height: 1.7; text-align: center; }
.master-note { margin: 9px 5px 0; color: #a29a90; font-size: 8px; line-height: 1.65; text-align: center; }

.tips { padding: 42px 0 64px; border-top: 1px solid var(--line); }
.tips > span { color: var(--red); font: 9px ui-monospace, monospace; letter-spacing: .15em; }
.tips > div { display: grid; gap: 9px; margin-top: 16px; }
.tips article { padding: 18px; border: 1px solid var(--line); background: rgba(255,253,248,.45); }
.tips article b { color: var(--red); font: 9px ui-monospace, monospace; }
.tips h3 { margin: 8px 0 5px; font-size: 13px; }
.tips p { margin: 0; color: var(--muted); font-size: 10px; line-height: 1.7; }

.history-drawer {
  position: fixed;
  top: 0; right: 0; z-index: 30;
  width: min(390px, 92vw);
  height: 100dvh;
  padding: 24px;
  display: flex;
  flex-direction: column;
  background: var(--paper);
  transform: translateX(102%);
  transition: transform .3s ease;
}
.history-drawer.open { transform: translateX(0); }
.drawer-head { display: flex; justify-content: space-between; padding-bottom: 18px; border-bottom: 1px solid var(--line); }
.drawer-head small { color: var(--red); font: 8px ui-monospace, monospace; letter-spacing: .14em; }
.drawer-head h2 { margin: 6px 0 0; font-size: 24px; }
.drawer-head button { border: 0; cursor: pointer; background: transparent; font-size: 28px; }
.history-list { overflow-y: auto; flex: 1; padding: 16px 0; }
.history-empty { padding: 70px 16px; color: #948d83; font-size: 11px; line-height: 1.7; text-align: center; }
.history-item { margin-bottom: 10px; padding: 9px; border: 1px solid var(--line); background: #fffaf1; }
.history-item img { display: block; width: 100%; aspect-ratio: 1.58; object-fit: cover; background: #eee6d9; }
.history-meta { display: flex; justify-content: space-between; padding: 9px 3px 2px; font-size: 10px; }
.history-meta span:last-child { color: #928a80; }
.clear-history { padding: 12px; border: 1px solid var(--line); cursor: pointer; color: #81796f; background: transparent; font-size: 10px; }
.backdrop { position: fixed; inset: 0; z-index: 25; background: rgba(20,16,12,.45); backdrop-filter: blur(3px); }
.toast {
  position: fixed;
  left: 50%; bottom: calc(82px + env(safe-area-inset-bottom));
  z-index: 50;
  padding: 11px 16px;
  color: #fff;
  background: var(--ink);
  font-size: 11px;
  opacity: 0;
  pointer-events: none;
  transform: translate(-50%, 15px);
  transition: .2s;
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
[hidden] { display: none !important; }
footer {
  width: min(100% - 32px, 720px);
  margin: 0 auto;
  padding: 30px 0 46px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  border-top: 1px solid var(--line);
}
footer p { margin: 0; color: #8f877d; font-size: 9px; }

@media (min-width: 620px) {
  .choice-row { grid-template-columns: 1fr 1.35fr; }
  .tips > div { grid-template-columns: repeat(3, 1fr); }
  .action-bar { position: static; margin: 38px 0 0; padding: 0; background: transparent; }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { scroll-behavior: auto !important; transition-duration: .01ms !important; }
}
