:root {
  --ink: #1b1210;
  --ink-soft: #3a2a26;
  --paper: #efe6d8;
  --paper-deep: #e4d7c5;
  --sheet: #fffdf8;
  --red: #c43b32;
  --red-deep: #9d2a24;
  --line: rgba(255, 244, 230, 0.12);
  --text: #f7efe6;
  --muted: #cbb8ab;
  --shadow: 0 18px 40px rgba(40, 18, 12, 0.18);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  font-family: "Microsoft YaHei", "PingFang SC", "Noto Sans SC", sans-serif;
  color: var(--ink);
  background: var(--paper);
}

body {
  display: grid;
  grid-template-columns: 300px 1fr;
  min-height: 100%;
}

.sidebar {
  background:
    radial-gradient(circle at 20% -10%, rgba(196, 59, 50, 0.28), transparent 42%),
    linear-gradient(180deg, #2a1a16 0%, #17100e 100%);
  color: var(--text);
  padding: 28px 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid #000;
}

.brand {
  display: flex;
  gap: 12px;
  align-items: center;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border: 2px solid var(--red);
  border-radius: 50%;
  position: relative;
  flex: 0 0 auto;
}

.brand-mark::after {
  content: "";
  position: absolute;
  inset: 8px;
  background: var(--red);
  clip-path: polygon(50% 8%, 61% 38%, 94% 38%, 67% 58%, 78% 90%, 50% 70%, 22% 90%, 33% 58%, 6% 38%, 39% 38%);
}

.brand h1 {
  margin: 0;
  font-size: 20px;
  letter-spacing: 0.08em;
}

.brand p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 12px;
}

.upload {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 16px;
  border: 1px dashed rgba(247, 239, 230, 0.35);
  border-radius: 12px;
  cursor: pointer;
  background: rgba(255, 255, 255, 0.03);
  transition: border-color 0.15s, background 0.15s;
}

.upload:hover, .upload.dragover {
  border-color: var(--red);
  background: rgba(196, 59, 50, 0.12);
}

.upload input { display: none; }
.upload strong { font-size: 14px; }
.upload span { font-size: 12px; color: var(--muted); }

.file-chip {
  font-size: 12px;
  color: var(--muted);
  padding: 8px 10px;
  background: rgba(255, 255, 255, 0.05);
  border-radius: 8px;
  word-break: break-all;
}

.stamp-panel {
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 14px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  font-size: 13px;
  margin-bottom: 10px;
}

.panel-head .size {
  color: var(--red);
  font-variant-numeric: tabular-nums;
}

.stamp-source {
  height: 168px;
  border-radius: 12px;
  display: grid;
  place-items: center;
  cursor: grab;
  touch-action: none;
  background-color: #d8d2c6;
  background-image:
    linear-gradient(45deg, #cfc8ba 25%, transparent 25%),
    linear-gradient(-45deg, #cfc8ba 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #cfc8ba 75%),
    linear-gradient(-45deg, transparent 75%, #cfc8ba 75%);
  background-size: 16px 16px;
  background-position: 0 0, 0 8px, 8px -8px, -8px 0;
}

.stamp-source:active { cursor: grabbing; }

.stamp-source img {
  width: 138px;
  height: 138px;
  user-select: none;
  pointer-events: none;
  filter: drop-shadow(0 6px 10px rgba(120, 20, 16, 0.18));
}

.hint {
  margin: 10px 0 0;
  font-size: 12px;
  line-height: 1.55;
  color: var(--muted);
}

.seam-btn {
  margin-top: 12px;
  width: 100%;
  appearance: none;
  border: 1px solid rgba(247, 239, 230, 0.28);
  background: rgba(196, 59, 50, 0.16);
  color: var(--text);
  font-size: 13px;
  padding: 10px 12px;
  border-radius: 10px;
  cursor: pointer;
}

.seam-btn:hover { background: rgba(196, 59, 50, 0.28); }

.rotate-bar {
  margin-top: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--muted);
}

.rotate-bar button {
  appearance: none;
  border: 1px solid rgba(247, 239, 230, 0.28);
  background: rgba(255, 255, 255, 0.06);
  color: var(--text);
  border-radius: 8px;
  padding: 6px 8px;
  cursor: pointer;
  font-size: 12px;
}

.rotate-bar button:hover { background: rgba(196, 59, 50, 0.28); }

.rotate-bar strong {
  min-width: 42px;
  text-align: center;
  color: var(--red);
  font-variant-numeric: tabular-nums;
}

.status {
  font-size: 12px;
  color: var(--muted);
  min-height: 18px;
}

.export {
  margin-top: auto;
  appearance: none;
  border: 0;
  background: var(--red);
  color: white;
  font-size: 15px;
  font-weight: 700;
  letter-spacing: 0.12em;
  padding: 14px 16px;
  border-radius: 12px;
  cursor: pointer;
}

.export:hover:not(:disabled) { background: var(--red-deep); }
.export:disabled { opacity: 0.4; cursor: not-allowed; }

.workspace {
  overflow: auto;
  padding: 36px 28px 80px;
  background:
    linear-gradient(180deg, rgba(255,255,255,0.28), transparent 120px),
    var(--paper);
}

.empty {
  min-height: calc(100vh - 72px);
  display: grid;
  place-items: center;
}

.empty-card {
  width: min(520px, 100%);
  background: rgba(255, 253, 248, 0.72);
  border: 1px dashed #c8b49a;
  border-radius: 18px;
  padding: 36px 32px;
  text-align: center;
}

.empty-card h2 { margin: 0 0 8px; font-size: 22px; }
.empty-card p { margin: 0; color: #6b5b50; line-height: 1.7; }

.pages {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 28px;
}

.page-wrap {
  width: min(860px, 100%);
}

.page-label {
  font-size: 12px;
  color: #7a685c;
  margin: 0 0 8px 4px;
}

.page {
  position: relative;
  background: var(--sheet);
  box-shadow: var(--shadow);
  border-radius: 2px;
  overflow: visible;
}

.page img.sheet {
  display: block;
  width: 100%;
  height: auto;
  user-select: none;
  pointer-events: none;
}

.placed-stamp {
  position: absolute;
  cursor: grab;
  touch-action: none;
}

.placed-stamp.selected {
  outline: 2px solid rgba(196, 59, 50, 0.85);
  outline-offset: 2px;
}

.placed-stamp img {
  width: 100%;
  height: 100%;
  pointer-events: none;
  user-select: none;
  transform-origin: center center;
}

.placed-stamp .remove {
  position: absolute;
  top: -10px;
  right: -10px;
  width: 22px;
  height: 22px;
  border: 0;
  border-radius: 50%;
  background: var(--ink);
  color: white;
  cursor: pointer;
  display: none;
  line-height: 22px;
  font-size: 14px;
}

.placed-stamp.selected .remove,
.placed-stamp:hover .remove { display: block; }

.placed-stamp.seam {
  left: auto;
  right: 0;
  overflow: hidden;
  cursor: move;
}

.placed-stamp.seam img {
  position: absolute;
  top: 0;
  height: 100%;
  width: auto;
  max-width: none;
}

.stamp-tools {
  position: absolute;
  left: 50%;
  bottom: -38px;
  transform: translateX(-50%);
  display: none;
  align-items: center;
  gap: 4px;
  background: #1b1210;
  color: #fff;
  border-radius: 999px;
  padding: 4px;
  z-index: 6;
  white-space: nowrap;
  box-shadow: 0 8px 18px rgba(0, 0, 0, 0.28);
}

.placed-stamp.selected .stamp-tools { display: flex; }

.stamp-tools button {
  appearance: none;
  border: 0;
  background: rgba(255, 255, 255, 0.1);
  color: #fff;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  cursor: pointer;
  font-size: 14px;
  line-height: 28px;
}

.stamp-tools button:hover { background: var(--red); }

.stamp-tools .angle {
  width: auto;
  min-width: 40px;
  border-radius: 999px;
  padding: 0 8px;
  font-size: 12px;
  font-variant-numeric: tabular-nums;
}

.placed-stamp.seam .stamp-tools {
  left: auto;
  right: calc(100% + 8px);
  bottom: 50%;
  transform: translateY(50%);
}

.ghost {
  position: fixed;
  z-index: 50;
  pointer-events: none;
  filter: drop-shadow(0 10px 16px rgba(80, 16, 12, 0.28));
  opacity: 0.92;
}

.ghost img { width: 100%; height: 100%; display: block; }

.loading {
  position: fixed;
  inset: 0;
  background: rgba(23, 16, 14, 0.42);
  display: grid;
  place-items: center;
  color: white;
  z-index: 80;
}

.loading p { margin: 14px 0 0; letter-spacing: 0.08em; }

.spinner {
  width: 36px;
  height: 36px;
  border: 3px solid rgba(255,255,255,0.25);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
  margin: 0 auto;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 28px;
  transform: translateX(-50%);
  background: var(--ink);
  color: white;
  padding: 10px 16px;
  border-radius: 999px;
  font-size: 13px;
  z-index: 90;
}

.hidden { display: none !important; }
.dragging { user-select: none; cursor: grabbing; }

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 860px) {
  body { grid-template-columns: 1fr; }
  .sidebar { min-height: auto; }
}

body.login-page {
  display: grid;
  place-items: center;
  grid-template-columns: 1fr;
  background:
    radial-gradient(circle at 20% -10%, rgba(196, 59, 50, 0.28), transparent 42%),
    linear-gradient(180deg, #2a1a16 0%, #17100e 100%);
}

.login-card {
  width: min(380px, calc(100% - 32px));
  background: rgba(255, 255, 255, 0.04);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 28px 24px 22px;
  color: var(--text);
  display: flex;
  flex-direction: column;
  gap: 16px;
}

.login-card .brand h1,
.login-card .brand p { color: inherit; }

.login-field {
  display: flex;
  flex-direction: column;
  gap: 8px;
  font-size: 13px;
  color: var(--muted);
}

.login-field input {
  appearance: none;
  border: 1px solid rgba(247, 239, 230, 0.22);
  background: rgba(0, 0, 0, 0.28);
  color: var(--text);
  border-radius: 10px;
  padding: 12px 14px;
  font-size: 16px;
}

.login-field input:focus {
  outline: 2px solid rgba(196, 59, 50, 0.7);
  border-color: var(--red);
}

.login-error {
  margin: 0;
  color: #f3b4ae;
  font-size: 13px;
}

.login-card .export { margin-top: 4px; }
.login-card .hint { margin: 0; }
