:root {
  color-scheme: light;
  --paper: #faf9f5;
  --panel: #fcfbf7;
  --ink: #101820;
  --muted: #736f66;
  --line: #ded7ca;
  --accent: #0f5c66;
  --accent-strong: #0a4249;
  --gold: #c08b3e;
  --danger: #a63a2b;
  --shadow: 0 22px 80px rgba(37, 31, 21, 0.16);
  --radius: 8px;
}

* {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  width: 100%;
  height: 100%;
  overflow: hidden;
}

body {
  height: 100vh;
  background: var(--paper);
  color: var(--ink);
  font-family: "Avenir Next", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

button,
input,
.import-btn {
  font: inherit;
}

button,
.import-btn {
  cursor: pointer;
}

.app-shell {
  display: grid;
  grid-template-columns: minmax(280px, 360px) minmax(0, 1fr);
  gap: 24px;
  height: 100vh;
  padding: 22px;
  overflow: hidden;
}

.panel,
.workspace {
  border: 1px solid var(--line);
  background: rgba(252, 251, 247, 0.93);
  box-shadow: var(--shadow);
}

.panel {
  display: flex;
  flex-direction: column;
  gap: 18px;
  min-height: 0;
  padding: 22px;
  border-radius: var(--radius);
  overflow: hidden;
}

.brand {
  display: flex;
  align-items: center;
  padding-bottom: 8px;
}

.eyebrow,
.topbar p {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0;
  text-transform: uppercase;
}

h1 {
  margin: 2px 0 0;
  font-family: Georgia, "Songti SC", serif;
  font-size: clamp(26px, 4vw, 38px);
  font-weight: 700;
  line-height: 1.05;
}

.control-block {
  display: grid;
  gap: 12px;
  padding: 16px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fffdf8;
}

.block-title {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  font-weight: 700;
}

.block-title small,
.file-drop small,
.hint {
  color: var(--muted);
  font-size: 12px;
}

.file-drop {
  display: grid;
  grid-template-columns: 42px 1fr;
  gap: 12px;
  align-items: center;
  min-height: 74px;
  padding: 14px;
  border: 1px dashed #b9ad9a;
  border-radius: var(--radius);
  background: #faf6ec;
  cursor: pointer;
}

.file-drop input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.file-icon {
  display: grid;
  place-items: center;
  width: 42px;
  height: 42px;
  border-radius: 50%;
  background: var(--ink);
  color: #fff;
  font-size: 24px;
}

.file-drop strong,
.file-drop small {
  display: block;
}

.field-grid {
  display: grid;
  grid-template-columns: 86px 1fr;
  gap: 14px;
  align-items: end;
}

.field-grid label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 12px;
}

input[type="color"] {
  width: 100%;
  height: 40px;
  padding: 3px;
  border: 1px solid var(--line);
  background: #fff;
}

input[type="range"] {
  width: 100%;
  accent-color: var(--accent);
}

.swatches {
  display: flex;
  gap: 10px;
}

.swatch {
  width: 34px;
  height: 34px;
  border: 2px solid transparent;
  border-radius: 50%;
  background: var(--swatch);
}

.swatch[data-color="#f8f6ef"]:not(.active) {
  border-color: #d8cebd;
}

.swatch.active {
  border-color: var(--gold);
  box-shadow: 0 0 0 2px #fff, 0 0 0 3px var(--gold);
}

.actions {
  grid-template-columns: repeat(2, minmax(0, 1fr));
}

.actions .block-title {
  grid-column: 1 / -1;
}

.export-actions {
  display: grid;
  margin-top: auto;
}

.icon-btn,
.text-btn,
.import-btn,
.primary-btn,
.quiet-btn {
  min-height: 42px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  transition: transform 160ms ease, border-color 160ms ease, background 160ms ease;
}

.icon-btn {
  font-size: 24px;
}

.text-btn {
  font-weight: 700;
}

.import-btn {
  display: grid;
  place-items: center;
  font-weight: 700;
}

.hidden-input {
  position: absolute;
  width: 1px;
  height: 1px;
  opacity: 0;
  pointer-events: none;
}

.primary-btn {
  grid-column: 1 / -1;
  border-color: var(--accent-strong);
  background: var(--accent);
  color: #fff;
  font-weight: 800;
}

.quiet-btn {
  min-height: 36px;
  padding: 0 14px;
  background: transparent;
  font-weight: 700;
}

button:hover,
.import-btn:hover {
  transform: translateY(-1px);
}

button:active,
.import-btn:active {
  transform: translateY(0);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.45;
  transform: none;
}

.workspace {
  display: grid;
  grid-template-rows: auto minmax(0, 1fr) auto;
  min-width: 0;
  min-height: 0;
  padding: 18px;
  border-radius: var(--radius);
  overflow: hidden;
}

.topbar,
.workspace-footer {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: center;
}

.topbar-tools,
.page-controls {
  display: flex;
  align-items: center;
  gap: 10px;
}

.page-controls {
  min-height: 38px;
  padding: 4px;
  border: 1px solid #c7bca9;
  border-radius: 999px;
  background: #fffaf0;
}

.page-controls.hidden {
  display: none;
}

.mini-btn {
  display: grid;
  place-items: center;
  width: 30px;
  height: 30px;
  border: 1px solid transparent;
  border-radius: 50%;
  background: #fff;
  color: var(--ink);
  font-size: 20px;
  line-height: 1;
}

#pageIndicator {
  min-width: 54px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 800;
  text-align: center;
}

.topbar strong {
  display: block;
  max-width: min(62vw, 760px);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  font-size: 18px;
}

.status-pill {
  min-width: 84px;
  padding: 7px 12px;
  border: 1px solid #c7bca9;
  border-radius: 999px;
  background: #fffaf0;
  color: var(--muted);
  text-align: center;
  font-size: 13px;
  font-weight: 700;
}

.status-pill.signed {
  border-color: rgba(15, 92, 102, 0.35);
  background: rgba(15, 92, 102, 0.1);
  color: var(--accent-strong);
}

.document-stage {
  position: relative;
  align-self: stretch;
  justify-self: center;
  width: min(100%, 940px);
  max-height: calc(100vh - 150px);
  aspect-ratio: var(--stage-aspect, 1 / 1.36);
  margin: 18px 0;
  background: transparent;
  overflow: hidden;
  touch-action: none;
}

.document-canvas,
.signature-canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
}

.document-canvas {
  background: transparent;
}

.signature-canvas {
  cursor: crosshair;
}

.signature-move {
  position: absolute;
  z-index: 3;
  min-height: 28px;
  padding: 0 9px;
  border: 1px solid rgba(15, 92, 102, 0.34);
  border-radius: 999px;
  background: rgba(255, 253, 248, 0.94);
  color: var(--accent-strong);
  font-size: 12px;
  font-weight: 800;
  touch-action: none;
  cursor: grab;
  transform: translate(-50%, -50%);
}

.signature-move:hover,
.signature-move:active {
  transform: translate(-50%, -50%);
}

.signature-move:active {
  cursor: grabbing;
}

.signature-move.hidden {
  display: none;
}

.workspace-footer {
  color: var(--muted);
}

@media (max-width: 920px) {
  body {
    overflow: auto;
  }

  .app-shell {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    overflow: visible;
    padding: 14px;
  }

  .panel {
    order: 2;
  }

  .workspace {
    min-height: 70vh;
  }
}

@media (max-width: 560px) {
  .panel,
  .workspace {
    padding: 14px;
  }

  .actions,
  .field-grid {
    grid-template-columns: 1fr;
  }

  .topbar,
  .topbar-tools,
  .workspace-footer {
    align-items: flex-start;
    flex-direction: column;
  }

  .document-stage {
    max-height: 64vh;
  }
}
