/* === 墨笺 styles === */
:root {
  --ink: #1a1612;
  --ink-soft: #3a322b;
  --ink-mute: #6e6358;
  --ink-faint: #a89e90;
  --paper: #f5efe4;
  --paper-warm: #ebe2d2;
  --paper-cool: #f1ecdf;
  --rice: #ece2cf;
  --dan: #c4453a;
  --dan-deep: #9c2f25;
  --gold: #b08a3e;
  --gold-soft: #d4b56a;
  --celadon: #6f8a78;
  --jade: #4a6b5e;
  --line: rgba(26, 22, 18, 0.12);
  --line-soft: rgba(26, 22, 18, 0.06);

  --serif: "Noto Serif SC", "Songti SC", "STSong", "SimSun", serif;
  --sans: "Noto Sans SC", -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;

  --r-xs: 2px;
  --r-sm: 4px;
  --r-md: 8px;
  --r-lg: 14px;
}

* { box-sizing: border-box; }

html, body, #root {
  height: 100%;
  margin: 0;
}

body {
  font-family: var(--serif);
  font-weight: 400;
  color: var(--ink);
  background: var(--paper);
  -webkit-font-smoothing: antialiased;
  font-feature-settings: "palt";
}

button {
  font-family: inherit;
  color: inherit;
}

/* ============ App shell ============ */
.app {
  height: 100%;
  display: flex;
  flex-direction: column;
  background:
    radial-gradient(900px 600px at 8% -10%, rgba(196,69,58,0.04), transparent 60%),
    radial-gradient(800px 800px at 110% 110%, rgba(176,138,62,0.05), transparent 60%),
    var(--paper);
  overflow: hidden;
}

.topbar {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 14px 28px;
  border-bottom: 1px solid var(--line);
  background: rgba(245, 239, 228, 0.85);
  backdrop-filter: blur(8px);
  position: sticky;
  top: 0;
  z-index: 50;
}

.brand {
  display: flex;
  align-items: baseline;
  gap: 10px;
  font-family: var(--serif);
}
.brand .seal {
  width: 28px;
  height: 28px;
  border-radius: 3px;
  background: var(--dan);
  color: #f8e8c4;
  display: inline-grid;
  place-items: center;
  font-family: var(--serif);
  font-weight: 700;
  font-size: 16px;
  line-height: 1;
  align-self: center;
  box-shadow: 0 1px 0 rgba(0,0,0,0.1) inset, 0 0 0 1px rgba(0,0,0,0.05);
  position: relative;
  letter-spacing: -0.04em;
}
.brand .seal::after {
  content: "";
  position: absolute; inset: 2px;
  border: 1px solid rgba(248,232,196,0.5);
  border-radius: 2px;
  pointer-events: none;
}
.brand .name {
  font-size: 22px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--ink);
  white-space: nowrap;
}
.brand .tag {
  font-size: 11px;
  letter-spacing: 0.32em;
  color: var(--ink-faint);
  margin-left: 4px;
  white-space: nowrap;
}
@media (max-width: 1100px) {
  .brand .tag { display: none; }
}

.nav {
  display: flex;
  gap: 4px;
  margin-left: 8px;
}
.nav button {
  appearance: none;
  background: transparent;
  border: 0;
  padding: 8px 16px;
  font-size: 14px;
  letter-spacing: 0.22em;
  color: var(--ink-mute);
  cursor: pointer;
  border-radius: var(--r-sm);
  position: relative;
  font-family: var(--serif);
  white-space: nowrap;
}
.nav button:hover { color: var(--ink); background: rgba(26,22,18,0.04); }
.nav button.active {
  color: var(--ink);
}
.nav button.active::after {
  content: "";
  position: absolute;
  left: 50%; bottom: 2px;
  width: 16px; height: 2px;
  background: var(--dan);
  transform: translateX(-50%);
  border-radius: 1px;
}

.topbar .spacer { flex: 1; }

.topbar .iconbtn {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  padding: 7px 14px;
  border-radius: var(--r-sm);
  font-family: var(--serif);
  font-size: 13px;
  letter-spacing: 0.16em;
  color: var(--ink-soft);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  gap: 8px;
  white-space: nowrap;
}
.topbar .iconbtn:hover { background: rgba(26,22,18,0.04); border-color: var(--ink-mute); }
.topbar .iconbtn.primary {
  background: var(--ink);
  color: var(--paper);
  border-color: var(--ink);
}
.topbar .iconbtn.primary:hover { background: var(--ink-soft); }

/* ============ Main layout ============ */
.workspace {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr 280px;
  min-height: 0;
  overflow: hidden;
}

@media (max-width: 1080px) {
  .workspace { grid-template-columns: 280px 1fr; }
  .right-rail { display: none; }
}
@media (max-width: 760px) {
  .workspace { grid-template-columns: 1fr; grid-template-rows: 1fr auto; }
  .left-rail { display: none; }
  .mobile-sheet { display: block !important; }
}

.left-rail {
  border-right: 1px solid var(--line);
  background: rgba(255,255,255,0.35);
  overflow-y: auto;
  padding: 18px 18px 80px;
}
.right-rail {
  border-left: 1px solid var(--line);
  background: rgba(255,255,255,0.35);
  overflow-y: auto;
  padding: 18px 18px 80px;
}

.stage-wrap {
  position: relative;
  overflow: hidden;
  background:
    radial-gradient(1200px 800px at 50% 30%, rgba(255,255,255,0.5), transparent 70%),
    linear-gradient(180deg, var(--paper-cool), var(--paper));
}

/* ============ Panels ============ */
.panel {
  margin-bottom: 18px;
}
.panel-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 10px;
  padding-bottom: 6px;
  border-bottom: 1px solid var(--line-soft);
}
.panel-head .ord {
  font-family: var(--serif);
  color: var(--dan);
  font-weight: 500;
  font-size: 13px;
  letter-spacing: 0.08em;
}
.panel-head .title {
  font-size: 13px;
  letter-spacing: 0.32em;
  color: var(--ink);
  font-weight: 500;
}
.panel-head .en {
  margin-left: auto;
  font-family: var(--sans);
  font-size: 9px;
  letter-spacing: 0.24em;
  color: var(--ink-faint);
  text-transform: uppercase;
}

.field {
  margin-bottom: 12px;
}
.field-label {
  font-size: 11px;
  letter-spacing: 0.24em;
  color: var(--ink-mute);
  margin-bottom: 6px;
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.field-label .val {
  font-family: var(--sans);
  color: var(--ink-faint);
  letter-spacing: 0.06em;
}

/* swatch grid */
.swatch-grid {
  display: grid;
  grid-template-columns: repeat(6, 1fr);
  gap: 6px;
}
.swatch {
  aspect-ratio: 1;
  border-radius: var(--r-xs);
  cursor: pointer;
  position: relative;
  border: 1px solid var(--line);
  overflow: hidden;
  transition: transform .12s ease;
}
.swatch:hover { transform: translateY(-1px); }
.swatch.active {
  border-color: var(--ink);
  box-shadow: 0 0 0 1px var(--ink);
}
.swatch.active::after {
  content: "";
  position: absolute;
  inset: 3px;
  border: 1px solid var(--paper);
  border-radius: 1px;
  pointer-events: none;
}

/* option grid (text labels) */
.opt-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
}
.opt-grid.cols-2 { grid-template-columns: repeat(2, 1fr); }
.opt-grid.cols-4 { grid-template-columns: repeat(4, 1fr); }
.opt {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  padding: 8px 4px;
  font-size: 12px;
  border-radius: var(--r-xs);
  cursor: pointer;
  color: var(--ink-soft);
  font-family: var(--serif);
  letter-spacing: 0.08em;
  position: relative;
  text-align: center;
  line-height: 1.4;
}
.opt:hover { border-color: var(--ink-mute); color: var(--ink); }
.opt.active {
  border-color: var(--ink);
  background: var(--ink);
  color: var(--paper);
}
.opt .sub {
  display: block;
  font-size: 9px;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  margin-top: 2px;
  font-family: var(--sans);
}
.opt.active .sub { color: rgba(245,239,228,0.6); }

/* shape preview grid (icon-like) */
.shape-grid {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 6px;
}
.shape-cell {
  aspect-ratio: 1;
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  cursor: pointer;
  display: grid;
  place-items: center;
  background: rgba(255,255,255,0.4);
  transition: all .12s ease;
}
.shape-cell:hover { border-color: var(--ink-mute); }
.shape-cell.active { border-color: var(--ink); background: rgba(26,22,18,0.04); }
.shape-cell svg { width: 60%; height: 60%; }

/* slider */
.slider {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  height: 2px;
  background: var(--line);
  outline: none;
  border-radius: 1px;
}
.slider::-webkit-slider-thumb {
  -webkit-appearance: none;
  appearance: none;
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--ink);
  cursor: pointer;
  border: 2px solid var(--paper);
  box-shadow: 0 0 0 1px var(--ink);
}
.slider::-moz-range-thumb {
  width: 14px; height: 14px;
  border-radius: 50%;
  background: var(--ink);
  cursor: pointer;
  border: 2px solid var(--paper);
}

/* text input */
.input, .textarea {
  width: 100%;
  background: rgba(255,255,255,0.6);
  border: 1px solid var(--line);
  border-radius: var(--r-xs);
  padding: 10px 12px;
  font-family: var(--serif);
  font-size: 14px;
  color: var(--ink);
  outline: none;
}
.input:focus, .textarea:focus { border-color: var(--ink); }
.textarea { resize: vertical; min-height: 60px; }

/* toggle */
.toggle {
  display: flex;
  align-items: center;
  gap: 8px;
  cursor: pointer;
  font-size: 12px;
  color: var(--ink-soft);
  letter-spacing: 0.16em;
}
.toggle .dot {
  width: 28px; height: 16px;
  background: var(--line);
  border-radius: 8px;
  position: relative;
  transition: background .15s ease;
}
.toggle .dot::before {
  content: "";
  position: absolute;
  width: 12px; height: 12px;
  border-radius: 50%;
  background: var(--paper);
  top: 2px; left: 2px;
  transition: transform .15s ease;
}
.toggle.on .dot { background: var(--ink); }
.toggle.on .dot::before { transform: translateX(12px); }

/* ============ Stage / Preview ============ */
.stage {
  position: relative;
  height: 100%;
  display: grid;
  grid-template-rows: auto 1fr auto;
  min-height: 0;
  overflow: hidden;
}
.stage-head {
  padding: 14px 24px;
  display: flex;
  align-items: center;
  gap: 16px;
  border-bottom: 1px solid var(--line-soft);
  background: rgba(255,255,255,0.4);
}
.stage-head .title {
  font-size: 13px;
  letter-spacing: 0.32em;
  color: var(--ink-soft);
  white-space: nowrap;
}
.stage-head .meta {
  margin-left: auto;
  font-size: 11px;
  letter-spacing: 0.18em;
  color: var(--ink-faint);
  font-family: var(--sans);
}
.stage-head .chip {
  font-size: 11px;
  letter-spacing: 0.16em;
  padding: 4px 10px;
  border: 1px solid var(--line);
  border-radius: 100px;
  color: var(--ink-mute);
  background: rgba(255,255,255,0.5);
  white-space: nowrap;
}

.stage-body {
  position: relative;
  overflow: hidden;
  display: grid;
  place-items: center;
  min-height: 0;
}

.stage-foot {
  padding: 12px 24px;
  border-top: 1px solid var(--line-soft);
  display: flex;
  align-items: center;
  gap: 12px;
  background: rgba(255,255,255,0.4);
  font-size: 12px;
  color: var(--ink-mute);
  letter-spacing: 0.16em;
}
.stage-foot .right { margin-left: auto; display: flex; gap: 8px; }

/* Mount canvas (the background scene) */
.mount-canvas {
  position: relative;
  width: min(90%, 720px);
  aspect-ratio: 4 / 3;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,0.25), 0 8px 24px -8px rgba(0,0,0,0.15);
  transition: aspect-ratio .3s ease;
}
.mount-canvas.tall { aspect-ratio: 3 / 4; width: min(70%, 520px); }
.mount-canvas.wide { aspect-ratio: 16 / 9; }
.mount-canvas.square { aspect-ratio: 1; width: min(70%, 600px); }

/* ============ Paper strip ============ */
.strip {
  position: relative;
  color: var(--ink);
  display: grid;
  place-items: center;
  user-select: none;
  /* a soft drop shadow + slight rotation set via inline style */
}
.strip-inner {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: hidden;
  isolation: isolate;
  container-type: size;
  container-name: strip;
}
.strip-paper {
  position: absolute;
  inset: 0;
  z-index: 1;
}
.strip-pattern {
  position: absolute;
  inset: 0;
  z-index: 2;
  mix-blend-mode: multiply;
  opacity: 0.7;
}
.strip-content {
  position: relative;
  z-index: 4;
  width: 100%;
  height: 100%;
  display: flex;
  align-items: stretch;
  justify-content: stretch;
  padding: 6%;
  gap: 4%;
  box-sizing: border-box;
}
.strip-content.col { flex-direction: column; }
.strip-content.row { flex-direction: row; }
.strip-content.rev { flex-direction: column-reverse; }
.strip-content.rev-row { flex-direction: row-reverse; }
.strip-text {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  text-align: center;
  min-height: 0;
  min-width: 0;
  container-type: size;
  container-name: striptext;
}
.strip-text .glyphs {
  display: flex;
  align-items: center;
  justify-content: center;
  flex-direction: row;
  gap: 0.05em;
}
.strip-text.vertical .glyphs {
  flex-direction: column;
  gap: 0.04em;
}
.strip-text .ch {
  display: inline-block;
  line-height: 1.05;
}

/* seal — inline (stacked) and corner (absolute) modes */
.seal-row {
  display: flex;
  align-items: center;
  justify-content: center;
  flex: 0 0 auto;
}
.seal-row.vertical { width: 100%; height: 16%; }
.seal-row.horizontal { width: 18%; height: 100%; }

/* seal */
.seal-mark {
  z-index: 5;
  aspect-ratio: 1;
  display: grid;
  place-items: center;
  color: #f6e9ce;
  font-family: var(--serif);
  font-weight: 600;
  letter-spacing: -0.04em;
  border-radius: 2px;
  text-shadow: 0 0 0 currentColor;
  background: var(--dan);
  opacity: 0.94;
  box-shadow: 0 1px 0 rgba(0,0,0,0.06) inset;
  container-type: size;
  container-name: seal;
}
.seal-mark.corner {
  position: absolute;
  width: 14%;
}
.seal-mark.inline-v {
  height: 100%;
}
.seal-mark.inline-h {
  width: 100%;
}
.seal-mark > * {
  font-size: 60cqmin;
  line-height: 1;
}
.seal-mark.round { border-radius: 50%; }
.seal-mark::after {
  content: "";
  position: absolute;
  inset: 8%;
  border: 1px solid rgba(246,233,206,0.45);
  border-radius: inherit;
  pointer-events: none;
}
.seal-mark.weather {
  filter: url(#sealNoise);
}

/* border decoration */
.strip-border {
  position: absolute;
  inset: 4%;
  border: 1px solid currentColor;
  opacity: 0.18;
  z-index: 3;
  pointer-events: none;
  border-radius: inherit;
}
.strip-border.double {
  box-shadow: inset 0 0 0 1px currentColor, inset 0 0 0 3px transparent, inset 0 0 0 4px currentColor;
  opacity: 0.14;
}

/* gold fleck overlay */
.gold-fleck {
  position: absolute;
  inset: 0;
  z-index: 3;
  pointer-events: none;
  mix-blend-mode: screen;
  opacity: 0.6;
}

/* ============ Right rail / actions ============ */
.action-list { display: flex; flex-direction: column; gap: 10px; }
.action {
  width: 100%;
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--line);
  border-radius: var(--r-sm);
  padding: 14px 14px;
  cursor: pointer;
  text-align: left;
  font-family: var(--serif);
  display: flex;
  align-items: center;
  gap: 10px;
  color: var(--ink-soft);
  transition: all .15s ease;
}
.action:hover { border-color: var(--ink-mute); background: rgba(255,255,255,0.8); color: var(--ink); }
.action .icon {
  width: 28px; height: 28px;
  display: grid; place-items: center;
  border-radius: 3px;
  background: rgba(26,22,18,0.06);
  color: var(--ink-soft);
  flex-shrink: 0;
}
.action .label { font-size: 13px; letter-spacing: 0.18em; font-weight: 500; color: var(--ink); }
.action .desc { font-size: 11px; letter-spacing: 0.08em; color: var(--ink-faint); margin-top: 2px; font-family: var(--sans); }
.action .body { flex: 1; min-width: 0; }

.action.primary { background: var(--ink); color: var(--paper); border-color: var(--ink); }
.action.primary .label { color: var(--paper); }
.action.primary .desc { color: rgba(245,239,228,0.6); }
.action.primary .icon { background: rgba(245,239,228,0.12); color: var(--paper); }
.action.primary:hover { background: var(--ink-soft); }

/* ============ AI panel ============ */
.ai-panel {
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.ai-head {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  letter-spacing: 0.24em;
  color: var(--ink);
  font-weight: 500;
}
.ai-head .badge {
  font-family: var(--sans);
  font-size: 9px;
  padding: 2px 6px;
  background: var(--ink);
  color: var(--paper);
  border-radius: 3px;
  letter-spacing: 0.18em;
}
.preset-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.preset-row .pill {
  appearance: none;
  background: transparent;
  border: 1px solid var(--line);
  padding: 5px 10px;
  font-size: 11px;
  letter-spacing: 0.16em;
  border-radius: 100px;
  cursor: pointer;
  color: var(--ink-mute);
  font-family: var(--serif);
  white-space: nowrap;
}
.preset-row .pill:hover { border-color: var(--ink); color: var(--ink); }

/* ============ Canvas (collage) ============ */
.collage-stage {
  position: relative;
  width: 100%;
  height: 100%;
  overflow: auto;
  display: grid;
  place-items: center;
  padding: 40px;
}
.collage-board {
  position: relative;
  width: min(95%, 760px);
  aspect-ratio: 4 / 3;
  border-radius: 4px;
  overflow: hidden;
  box-shadow: 0 30px 60px -20px rgba(0,0,0,0.3);
}
.collage-strip {
  position: absolute;
  cursor: grab;
  transition: filter .15s ease, outline .15s ease;
}
.collage-strip:hover { filter: brightness(1.04); }
.collage-strip.selected { outline: 2px dashed var(--dan); outline-offset: 4px; }
.collage-strip:active { cursor: grabbing; }

/* ============ Templates ============ */
.templates-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
  gap: 18px;
  padding: 28px;
  overflow-y: auto;
  height: 100%;
  width: 100%;
  box-sizing: border-box;
}
.tpl-card {
  background: rgba(255,255,255,0.5);
  border: 1px solid var(--line);
  border-radius: var(--r-md);
  padding: 14px;
  cursor: pointer;
  transition: all .15s ease;
  display: flex;
  flex-direction: column;
  align-items: center;
}
.tpl-card:hover { border-color: var(--ink-mute); transform: translateY(-2px); box-shadow: 0 6px 20px -6px rgba(0,0,0,0.15); }
.tpl-card .preview {
  width: 100%;
  aspect-ratio: 3 / 4;
  display: grid;
  place-items: center;
  margin-bottom: 10px;
  background:
    repeating-linear-gradient(45deg, rgba(0,0,0,0.02) 0 1px, transparent 1px 8px),
    var(--paper-cool);
  border-radius: 3px;
  overflow: hidden;
}
.tpl-card .name {
  font-size: 13px;
  letter-spacing: 0.18em;
  color: var(--ink);
}
.tpl-card .meta {
  font-size: 10px;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
  font-family: var(--sans);
  margin-top: 2px;
}

/* ============ Modal / dialog ============ */
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(26,22,18,0.5);
  z-index: 100;
  display: grid; place-items: center;
}
.modal {
  background: var(--paper);
  border-radius: var(--r-md);
  padding: 24px;
  width: min(420px, 90vw);
  box-shadow: 0 30px 60px -10px rgba(0,0,0,0.4);
}
.modal h3 { margin: 0 0 4px; font-weight: 500; letter-spacing: 0.24em; font-size: 16px; }
.modal .sub { font-size: 12px; color: var(--ink-mute); letter-spacing: 0.16em; margin-bottom: 16px; }

/* hide on mobile sheet default */
.mobile-sheet { display: none; }

/* hairline divider */
.hr {
  height: 1px;
  background: var(--line-soft);
  margin: 14px 0;
}

/* small text */
.muted {
  font-size: 11px;
  letter-spacing: 0.16em;
  color: var(--ink-faint);
}

/* fancy lines */
.deco-line {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 10px;
  letter-spacing: 0.4em;
  color: var(--ink-faint);
  margin: 12px 0;
  text-transform: uppercase;
}
.deco-line::before, .deco-line::after {
  content: "";
  flex: 1;
  height: 1px;
  background: var(--line-soft);
}
