:root {
  --ink: #36291f;
  --paper: #f8f1e4;
  --soft: #c7b89e;
  --accent: #805044;
  --line: rgba(64, 48, 32, 0.18);
}

@font-face {
  font-family: "CollageMing";
  src: url("./fonts/huiwen-ming.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "CollageQiji";
  src: url("./fonts/qiji-combo.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "CollageBitmap";
  src: url("./fonts/wenquanyi-bitmap.woff2") format("woff2");
  font-display: swap;
}

@font-face {
  font-family: "CollagePapyrus";
  src: url("./fonts/papyrus.woff2") format("woff2");
  font-display: swap;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html,
body {
  width: 100%;
  height: 100%;
  margin: 0;
  overflow: hidden;
  background: #e3d6bf;
  color: var(--ink);
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

body {
  position: fixed;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  overscroll-behavior: none;
}

button,
textarea {
  font: inherit;
}

button {
  border: 0;
  cursor: pointer;
}

.app-shell {
  position: fixed;
  top: 0;
  right: auto;
  bottom: 0;
  left: 50%;
  display: flex;
  flex-direction: column;
  width: 100%;
  max-width: 520px;
  height: 100vh;
  height: 100dvh;
  margin: 0 auto;
  padding: 8px 12px 0;
  /* Reserve the native mini-tool navigation row above our own controls. */
  padding-top: 66px;
  padding-top: calc(12px + var(--safe-area-inset-top, env(safe-area-inset-top, 0px)));
  transform: translateX(-50%);
  background-color: #e3d6bf;
  background-image: repeating-linear-gradient(0deg, rgba(81, 63, 39, 0.025) 0, rgba(81, 63, 39, 0.025) 1px, transparent 1px, transparent 4px);
}

.topbar {
  flex: 0 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 44px;
  margin-bottom: 6px;
}

.editor {
  display: grid;
  flex: 1 1 auto;
  grid-template-rows: minmax(0, 1fr) 46px auto;
  min-height: 0;
}

.top-actions {
  display: flex;
  align-items: center;
}

.top-actions > * + * { margin-left: 8px; }

.layout-rotate-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  border: 1px solid var(--line);
  border-radius: 50%;
  background: rgba(255, 250, 239, 0.36);
  color: var(--ink);
}

.layout-rotate-button svg {
  width: 22px;
  height: 22px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.brand {
  display: flex;
  align-items: center;
  min-width: 0;
  font-family: "CollageMing", "Songti SC", "SimSun", serif;
  font-size: 17px;
  font-weight: 400;
  letter-spacing: 0.08em;
}

.save-button {
  min-height: 42px;
  padding: 0 17px;
  border-radius: 22px;
  background: var(--ink);
  color: var(--paper);
  font-size: 14px;
  font-weight: 700;
}

.save-button:active {
  transform: scale(0.98);
}

.canvas-wrap {
  overflow: hidden;
  width: 100%;
  height: auto;
  max-width: 100%;
  justify-self: center;
  align-self: center;
  background: #b9ab92;
  box-shadow: 0 12px 30px rgba(72, 48, 30, 0.16);
}

.app-shell.is-previewing {
  padding-right: 0;
  padding-left: 0;
}

.app-shell.is-previewing .topbar,
.app-shell.is-previewing .under-canvas {
  margin-right: 12px;
  margin-left: 12px;
}

#artboard {
  display: block;
  width: 100%;
  height: 100%;
  touch-action: none;
}

.under-canvas {
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 46px;
}

.under-canvas > * + * { margin-left: 4px; }

.canvas-status {
  display: flex;
  min-width: 0;
  align-items: center;
}

.canvas-status > * + * { margin-left: 8px; }

.source-switch-button {
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 30px;
  padding: 0 9px;
  border: 1px solid var(--line);
  border-radius: 16px;
  background: rgba(255, 250, 239, 0.45);
  color: var(--ink);
  font-size: 11px;
}

.source-switch-button strong {
  margin-left: 7px;
  color: var(--accent);
  font-weight: 650;
}

.canvas-status p {
  overflow: hidden;
  min-width: 0;
  margin: 0;
  color: rgba(54, 41, 31, 0.55);
  font-size: 11px;
  line-height: 1.4;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-actions {
  display: flex;
  flex: 0 0 auto;
  align-items: center;
}

.icon-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 42px;
  height: 42px;
  margin-left: 2px;
  border-radius: 50%;
  background: transparent;
  color: var(--ink);
}

.icon-button svg {
  width: 23px;
  height: 23px;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.icon-button:disabled {
  color: rgba(54, 41, 31, 0.22);
}

.bottom-tools {
  position: relative;
  z-index: 8;
  align-self: end;
  width: 100%;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 18px 18px 0 0;
  background: rgba(247, 238, 220, 0.97);
  box-shadow: 0 -8px 28px rgba(72, 48, 30, 0.08);
  backdrop-filter: blur(18px);
}

.tool-content {
  height: 190px;
  min-height: 190px;
  padding: 8px 10px 6px;
}

.tool-content[hidden],
.range-controls[hidden],
.text-disabled-note[hidden] {
  display: none !important;
}

.bottom-tools.is-collapsed .tool-content {
  display: none !important;
}

.tool-section-label {
  margin: 0 0 5px 3px;
  color: rgba(54, 41, 31, 0.6);
  font-size: 12px;
  letter-spacing: 0.1em;
}

.tool-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  grid-gap: 6px;
  padding: 6px 8px;
  padding-right: calc(8px + var(--safe-area-inset-right, env(safe-area-inset-right, 0px)));
  padding-bottom: calc(6px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  padding-left: calc(8px + var(--safe-area-inset-left, env(safe-area-inset-left, 0px)));
  border-top: 1px solid var(--line);
}

.tool-tab {
  min-height: 42px;
  border-radius: 13px;
  background: transparent;
  color: rgba(54, 41, 31, 0.7);
  font-size: 15px;
  font-weight: 650;
}

.tool-tab.is-active {
  background: #7b5142;
  color: #fff8eb;
}

.tool-tab.is-disabled {
  color: rgba(54, 41, 31, 0.28);
  cursor: default;
}

.option-panel {
  display: flex;
  overflow-x: auto;
  padding: 3px 2px 9px;
  scrollbar-width: none;
}

.option-panel::-webkit-scrollbar {
  display: none;
}

.pattern-chip {
  position: relative;
  display: flex;
  flex: 0 0 auto;
  align-items: center;
  min-height: 42px;
  margin-right: 8px;
  padding: 5px 12px 5px 7px;
  border: 1px solid transparent;
  border-radius: 22px;
  background: rgba(83, 63, 41, 0.065);
  color: rgba(54, 41, 31, 0.78);
  font-size: 13px;
}

.pattern-chip.is-selected {
  border-color: var(--accent);
  color: var(--ink);
}

.pattern-sample {
  width: 31px;
  height: 31px;
  margin-right: 8px;
  border-radius: 50%;
  border: 1px solid #b6aa97;
  background-color: #fffdf7;
  background-position: center;
  background-size: cover;
}

.sample-none {
  background-image: linear-gradient(135deg, transparent 47%, rgba(73, 63, 51, 0.42) 48%, rgba(73, 63, 51, 0.42) 52%, transparent 53%);
}

.upload-sample {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  background-color: #fffdf7;
  background-position: center;
  background-size: cover;
  color: var(--accent);
  font-size: 21px;
  font-weight: 400;
}

.upload-chip.is-selected {
  border-color: var(--accent);
  color: var(--ink);
}

.color-panel {
  align-items: center;
  min-height: 47px;
}

.color-swatch {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 38px;
  height: 38px;
  margin-right: 9px;
  border: 2px solid rgba(54, 41, 31, 0.14);
  border-radius: 50%;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, 0.08);
}

.color-swatch.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: 3px;
}

.original-color-swatch {
  background: #fffaf0;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
}

.custom-color-swatch {
  overflow: hidden;
  background: #fffdf7;
  color: var(--accent);
  font-size: 25px;
  font-weight: 300;
  cursor: pointer;
}

.custom-color-swatch input {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.text-controls {
  display: flex;
  align-items: center;
  justify-content: center;
  height: 205px;
  min-height: 205px;
}

.text-disabled-note {
  margin: 0;
  color: rgba(54, 41, 31, 0.4);
  font-size: 14px;
}

.range-controls {
  display: grid;
  width: 100%;
  grid-gap: 1px;
}

.typed-font-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  min-height: 35px;
  color: rgba(54, 41, 31, 0.75);
  font-size: 12px;
}

.font-options {
  display: flex;
  overflow-x: auto;
  padding: 3px 4px 5px;
  scrollbar-width: none;
}

.font-options > * + * { margin-left: 6px; }

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

.font-option {
  flex: 0 0 auto;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid rgba(54, 41, 31, 0.17);
  border-radius: 16px;
  background: #fffaf0;
  color: var(--ink);
  font-size: 12px;
}

.font-option.is-selected {
  border-color: var(--accent);
  background: #805044;
  color: #fff8eb;
}

.range-controls > label {
  display: grid;
  grid-template-columns: 70px 1fr 44px;
  align-items: center;
  min-height: 23px;
  grid-gap: 6px;
  color: rgba(54, 41, 31, 0.8);
  font-size: 13px;
}

.range-controls > label output {
  grid-column: 3;
  grid-row: 1;
  color: rgba(54, 41, 31, 0.56);
  text-align: right;
}

.range-controls > label input[type="range"] {
  grid-column: 2;
  grid-row: 1;
  width: 100%;
  accent-color: var(--accent);
}

.typed-color-controls {
  display: grid;
  grid-gap: 3px;
  margin-bottom: 2px;
  padding-bottom: 5px;
  border-bottom: 1px solid var(--line);
}

.typed-color-row {
  display: grid;
  grid-template-columns: 42px minmax(0, 1fr);
  align-items: center;
  min-height: 27px;
  color: rgba(54, 41, 31, 0.75);
  font-size: 12px;
}

.mini-swatches {
  display: flex;
  align-items: center;
  overflow-x: auto;
  padding: 2px 4px;
  scrollbar-width: none;
}

.mini-swatches::-webkit-scrollbar {
  display: none;
}

.mini-swatch {
  position: relative;
  display: inline-flex;
  flex: 0 0 auto;
  align-items: center;
  justify-content: center;
  width: 22px;
  height: 22px;
  margin-right: 10px;
  padding: 0;
  border: 1px solid rgba(54, 41, 31, 0.3);
  border-radius: 50%;
  color: var(--ink);
  font-size: 15px;
}

.mini-swatch.is-selected {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

.custom-swatch {
  overflow: hidden;
  background: #fffdf7;
}

.custom-swatch input {
  position: absolute;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  opacity: 0;
  cursor: pointer;
}

.reset-text-button {
  justify-self: end;
  min-height: 27px;
  padding: 0 12px;
  border-radius: 16px;
  background: rgba(83, 63, 41, 0.09);
  color: rgba(54, 41, 31, 0.72);
  font-size: 12px;
}

.sheet-backdrop {
  position: fixed;
  z-index: 20;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  background: rgba(0, 0, 0, 0.62);
  backdrop-filter: blur(5px);
}

.bottom-sheet {
  position: fixed;
  z-index: 21;
  right: 0;
  bottom: 0;
  left: 0;
  max-width: 520px;
  margin: 0 auto;
  padding: 10px 18px 18px;
  padding-bottom: calc(18px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  border-radius: 22px 22px 0 0;
  background: #f6eddd;
  color: var(--ink);
  transform: translateY(110%);
  transition: transform 220ms ease;
}

.bottom-sheet.is-open {
  transform: translateY(0);
}

.sheet-handle {
  width: 38px;
  height: 4px;
  margin: 1px auto 18px;
  border-radius: 2px;
  background: rgba(17, 16, 15, 0.18);
}

.bottom-sheet h2,
.dialog-card h2 {
  margin: 0 0 6px;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 23px;
  font-weight: 600;
}

.bottom-sheet p {
  margin: 0 0 18px;
  color: rgba(54, 41, 31, 0.58);
  font-size: 14px;
}

.source-actions {
  display: flex;
}

.source-actions button,
.source-actions label {
  position: relative;
  display: flex;
  flex: 1 1 0;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 96px;
  margin-right: 8px;
  border-radius: 15px;
  background: #e7dac5;
  color: var(--ink);
  font-size: 13px;
  font-weight: 650;
  text-align: center;
}

.source-actions > :last-child {
  margin-right: 0;
}

.source-actions > * > span {
  display: block;
  margin-bottom: 8px;
  font-family: "Songti SC", "SimSun", serif;
  font-size: 24px;
}

.native-file-input {
  position: absolute;
  z-index: 2;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  width: 100%;
  height: 100%;
  margin: 0;
  opacity: 0;
  cursor: pointer;
}

.sheet-cancel {
  width: 100%;
  min-height: 48px;
  margin-top: 10px;
  border-radius: 13px;
  background: var(--ink);
  color: var(--paper);
}

.text-dialog,
.replace-dialog {
  display: none;
  position: fixed;
  z-index: 30;
  top: 0;
  right: 0;
  bottom: 0;
  left: 0;
  align-items: center;
  justify-content: center;
  padding: 18px;
  background: rgba(0, 0, 0, 0.68);
}

.text-dialog.is-open,
.replace-dialog.is-open {
  display: flex;
}

.dialog-card {
  width: 100%;
  max-width: 460px;
  padding: 22px;
  border-radius: 20px;
  background: #f6eddd;
  color: var(--ink);
}

.dialog-card textarea {
  width: 100%;
  margin-top: 12px;
  padding: 15px;
  resize: none;
  border: 1px solid rgba(17, 16, 15, 0.14);
  border-radius: 13px;
  outline: none;
  background: #fffaf0;
  color: var(--ink);
  font-family: "Songti SC", "SimSun", serif;
  font-size: 16px;
  line-height: 1.75;
}

.text-entry-tools {
  display: flex;
  align-items: center;
  margin-top: 10px;
}

.text-entry-tools > * + * { margin-left: 10px; }

.text-entry-tools button {
  flex: 0 0 auto;
  min-height: 34px;
  padding: 0 12px;
  border: 1px solid rgba(54, 41, 31, 0.24);
  border-radius: 18px;
  background: #fffaf0;
  color: var(--ink);
  font-size: 13px;
}

.text-entry-tools span {
  color: rgba(54, 41, 31, 0.58);
  font-size: 12px;
  line-height: 1.4;
}

.dialog-card > p {
  margin: 10px 0 0;
  color: rgba(17, 16, 15, 0.58);
  font-size: 14px;
  line-height: 1.65;
}

.dialog-actions {
  display: flex;
  justify-content: flex-end;
  margin-top: 14px;
}

.dialog-actions button {
  min-height: 44px;
  margin-left: 9px;
  padding: 0 18px;
  border-radius: 12px;
  background: #dfd0b8;
  color: var(--ink);
}

.dialog-actions .primary {
  background: var(--ink);
  color: var(--paper);
}

.toast {
  position: fixed;
  z-index: 40;
  right: 18px;
  bottom: 24px;
  bottom: calc(24px + var(--safe-area-inset-bottom, env(safe-area-inset-bottom, 0px)));
  left: 18px;
  max-width: 420px;
  margin: 0 auto;
  padding: 12px 16px;
  border-radius: 12px;
  background: rgba(54, 41, 31, 0.95);
  color: var(--paper);
  font-size: 14px;
  text-align: center;
  opacity: 0;
  pointer-events: none;
  transform: translateY(12px);
  transition: opacity 180ms ease, transform 180ms ease;
}

.toast.is-showing {
  opacity: 1;
  transform: translateY(0);
}

@media (min-width: 720px) {
  .app-shell {
    padding-top: 16px;
  }

  .canvas-wrap {
    border: 1px solid rgba(54, 41, 31, 0.16);
  }
}

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