:root {
  --ink: #161310;
  --ink-2: #2a241e;
  --paper: #f4efe6;
  --paper-2: #ebe4d8;
  --surface: #fffdf8;
  --line: #d5cbb8;
  --line-strong: #b7aa94;
  --muted: #6f6558;
  --accent: #c45b2c;
  --accent-ink: #8a3514;
  --accent-soft: rgba(196, 91, 44, 0.12);
  --ok: #2f7d4a;
  --warn: #9a6b12;
  --bad: #b42318;
  --cloud: #2b5ea8;
  --radius: 8px;
  --radius-lg: 14px;
  --font: "Noto Sans SC", "PingFang SC", "Microsoft YaHei", system-ui, sans-serif;
  --space-1: 4px;
  --space-2: 8px;
  --space-3: 12px;
  --space-4: 16px;
  --space-5: 24px;
  --btn-h: 42px;
  --console-w: 380px;
  --shell-max: 1360px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  min-height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
}

button, input, textarea { font: inherit; color: inherit; }

a { color: var(--accent-ink); }
a:hover { color: var(--accent); }

/* ---------- App shell ---------- */
.app-frame {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: var(--space-4);
  padding: 10px 20px;
  background: var(--ink);
  color: #f6f1e8;
  border-bottom: 1px solid #000;
}

.brand-lockup {
  display: flex;
  align-items: baseline;
  gap: 10px;
  min-width: 0;
}
.brand-lockup h1 {
  margin: 0;
  font-size: 16px;
  font-weight: 700;
  letter-spacing: 0.02em;
}
.brand-lockup .tag {
  margin: 0;
  font-size: 12px;
  color: rgba(246, 241, 232, 0.62);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-shrink: 0;
}

.user-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  height: 34px;
  padding: 0 10px 0 4px;
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  border: 1px solid rgba(255, 255, 255, 0.14);
  color: #f6f1e8;
  font-size: 12px;
  max-width: 200px;
}
.user-avatar {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  font-size: 12px;
  font-weight: 700;
  flex-shrink: 0;
}
.user-name {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.credits-pill {
  display: inline-flex;
  align-items: center;
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  background: rgba(196, 91, 44, 0.22);
  border: 1px solid rgba(196, 91, 44, 0.45);
  color: #ffd2b8;
  font-size: 12px;
  font-weight: 700;
  white-space: nowrap;
}

.pill {
  display: inline-flex;
  align-items: center;
  height: 28px;
  padding: 0 10px;
  border-radius: 999px;
  font-size: 11px;
  font-weight: 600;
  border: 1px solid transparent;
}
.pill.ok { background: rgba(47, 125, 74, 0.2); color: #9fddb3; border-color: rgba(47, 125, 74, 0.35); }
.pill.warn { background: rgba(154, 107, 18, 0.22); color: #f0d08a; border-color: rgba(154, 107, 18, 0.4); }
.pill.bad { background: rgba(180, 35, 24, 0.22); color: #f0a39c; border-color: rgba(180, 35, 24, 0.4); }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: var(--btn-h);
  padding: 0 14px;
  border-radius: var(--radius);
  border: 1px solid var(--line-strong);
  background: var(--surface);
  cursor: pointer;
  font-weight: 600;
  text-decoration: none;
  color: var(--ink);
}
.btn:hover { border-color: var(--ink); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn.primary {
  background: var(--accent);
  border-color: var(--accent-ink);
  color: #fff;
}
.btn.primary:hover { filter: brightness(1.05); }
.btn.secondary { background: var(--paper-2); }
.btn.ghost {
  background: transparent;
  border-color: rgba(255,255,255,0.22);
  color: #f6f1e8;
  min-height: 34px;
  padding: 0 12px;
  font-size: 12px;
}
.btn.ghost:hover { background: rgba(255,255,255,0.08); border-color: rgba(255,255,255,0.4); }
.btn.block { width: 100%; }

.app-body {
  flex: 1;
  width: min(100% - 32px, var(--shell-max));
  margin: 0 auto;
  padding: 16px 0 28px;
}

.page-tabs {
  display: inline-flex;
  gap: 4px;
  padding: 4px;
  margin-bottom: 14px;
  background: var(--paper-2);
  border: 1px solid var(--line);
  border-radius: 999px;
}
.page-tab {
  border: 0;
  background: transparent;
  min-height: 34px;
  padding: 0 14px;
  border-radius: 999px;
  font-weight: 600;
  font-size: 13px;
  color: var(--muted);
  cursor: pointer;
}
.page-tab.active {
  background: var(--ink);
  color: #f6f1e8;
}

.layout {
  display: grid;
  grid-template-columns: var(--console-w) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
  min-height: calc(100vh - 140px);
}

.console, .proof {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  min-width: 0;
}
.console {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.proof {
  padding: 14px;
  min-height: 520px;
}

.block { display: flex; flex-direction: column; gap: 8px; }
.section-title {
  margin: 0;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.04em;
  text-transform: uppercase;
  color: var(--muted);
}
.hint {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
  line-height: 1.4;
}
.hint.tight { margin: 0; }
.hint strong { color: var(--ink); font-weight: 600; }

.drop {
  display: grid;
  place-items: center;
  gap: 4px;
  min-height: 120px;
  padding: 16px;
  border: 1.5px dashed var(--line-strong);
  border-radius: var(--radius);
  background:
    linear-gradient(180deg, rgba(196,91,44,0.05), transparent 48%),
    var(--paper);
  cursor: pointer;
  text-align: center;
}
.drop:hover, .drop.drag {
  border-color: var(--accent);
  background: var(--accent-soft);
}
.drop-title { font-weight: 700; color: var(--ink); font-size: 14px; }
.drop-sub { font-size: 12px; color: var(--muted); }

.prompt-box {
  width: 100%;
  resize: vertical;
  min-height: 88px;
  padding: 10px 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
}
.prompt-box:focus, input.field:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
input.field {
  width: 100%;
  min-height: var(--btn-h);
  padding: 0 12px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
}

.seg {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.seg-btn {
  min-height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--muted);
  font-weight: 600;
  font-size: 12px;
  cursor: pointer;
}
.seg-btn.active {
  background: var(--ink);
  border-color: var(--ink);
  color: #fff;
}

.actions { margin-top: 4px; }
.run-meta { min-height: 1.2em; }

.ref-preview {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  max-height: 160px;
  background: var(--paper-2);
}
.ref-preview img {
  display: block;
  width: 100%;
  max-height: 160px;
  object-fit: contain;
}

.proof-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.proof-idle {
  margin: 48px 16px;
  text-align: center;
  color: var(--muted);
  font-size: 13px;
}
.ecom-result {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--paper);
}
.ecom-result img {
  display: block;
  width: 100%;
  max-height: min(72vh, 780px);
  object-fit: contain;
  background:
    linear-gradient(45deg, #e8e0d2 25%, transparent 25%) 0 0 / 16px 16px,
    linear-gradient(-45deg, #e8e0d2 25%, transparent 25%) 0 8px / 16px 16px,
    #f7f2e9;
}
.ecom-result-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  padding: 10px 12px;
  border-top: 1px solid var(--line);
  background: var(--surface);
}
.ecom-result .hint { padding: 0 12px 12px; }

.advanced {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 8px 10px;
  background: var(--paper);
}
.advanced summary {
  cursor: pointer;
  font-size: 12px;
  font-weight: 600;
  color: var(--muted);
}
.advanced-body { margin-top: 8px; display: grid; gap: 8px; }
.ack { display: flex; gap: 8px; align-items: center; font-size: 12px; color: var(--ink); }

.example-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.example-chip {
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink-2);
  border-radius: 999px;
  min-height: 30px;
  padding: 0 11px;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  max-width: 100%;
}
.example-chip:hover {
  border-color: var(--accent);
  background: var(--accent-soft);
  color: var(--accent-ink);
}

.print-crop-frame {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  overflow: hidden;
  background: #0a0908;
}
.print-crop-frame canvas {
  display: block;
  width: 100%;
  height: auto;
  touch-action: none;
  cursor: crosshair;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: 24px;
  transform: translateX(-50%);
  z-index: 50;
  max-width: min(92vw, 420px);
  padding: 10px 14px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #f6f1e8;
  font-size: 13px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}

.tool-panel[hidden],
#viewLogin[hidden],
#viewApp[hidden],
#panelHistory[hidden],
#printResultCard[hidden],
#ecomResultCard[hidden],
#ecomUploadBlock[hidden],
#printOptionsBlock[hidden],
#printAdvanced[hidden],
#printCropBlock[hidden],
#printSourcePreviewWrap[hidden] {
  display: none !important;
}

.history-list {
  display: grid;
  gap: 10px;
}
.history-card {
  display: grid;
  grid-template-columns: 96px 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 10px;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: var(--paper);
}
.history-card img {
  width: 96px;
  height: 96px;
  object-fit: cover;
  border-radius: 6px;
  background: var(--paper-2);
}
.history-card h3 {
  margin: 0 0 4px;
  font-size: 14px;
}
.history-card p {
  margin: 0;
  font-size: 12px;
  color: var(--muted);
}
@media (max-width: 640px) {
  .history-card {
    grid-template-columns: 72px 1fr;
  }
  .history-card .btn { grid-column: 1 / -1; }
}

/* ---------- Login split ---------- */
.login-frame {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 1.05fr 0.95fr;
}

.login-visual {
  position: relative;
  color: #f6f1e8;
  overflow: hidden;
  min-height: 100%;
}
.login-visual__bg {
  position: absolute;
  inset: 0;
  background:
    url("/assets/login-cover.jpg") center right / cover no-repeat,
    linear-gradient(160deg, #1c1712 0%, #0f0d0b 55%, #241910 100%);
  transform: scale(1.02);
}
.login-visual__shade {
  position: absolute;
  inset: 0;
  background:
    linear-gradient(90deg, rgba(12,10,8,0.88) 0%, rgba(12,10,8,0.62) 42%, rgba(12,10,8,0.28) 70%, rgba(12,10,8,0.12) 100%),
    linear-gradient(180deg, rgba(12,10,8,0.25) 0%, transparent 30%, rgba(12,10,8,0.45) 100%);
  pointer-events: none;
}
.login-visual__content {
  position: relative;
  z-index: 1;
  min-height: 100%;
  padding: 40px 44px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.login-kicker {
  font-size: 12px;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  color: rgba(246,241,232,0.7);
  margin: 0 0 12px;
}
.login-visual h1 {
  margin: 0;
  font-size: clamp(28px, 4vw, 42px);
  line-height: 1.15;
  font-weight: 700;
  max-width: 10em;
  text-shadow: 0 8px 28px rgba(0,0,0,0.45);
}
.login-visual p.lead {
  margin: 16px 0 0;
  max-width: 28em;
  color: rgba(246,241,232,0.82);
  font-size: 14px;
  text-shadow: 0 4px 16px rgba(0,0,0,0.35);
}
.login-meta {
  font-size: 12px;
  color: rgba(246,241,232,0.55);
}

.login-panel {
  display: grid;
  place-items: center;
  padding: 32px 24px;
  background: var(--paper);
}
.login-card {
  width: min(100%, 380px);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius-lg);
  padding: 24px;
  box-shadow: 0 12px 40px rgba(22, 19, 16, 0.06);
}
.login-card h2 {
  margin: 0 0 4px;
  font-size: 22px;
}
.login-card .sub {
  margin: 0 0 18px;
  color: var(--muted);
  font-size: 13px;
}
.field-label {
  display: block;
  margin: 0 0 6px;
  font-size: 12px;
  font-weight: 600;
  color: var(--ink-2);
}
.field-group { margin-bottom: 14px; }
.login-error {
  margin: 0 0 12px;
  padding: 8px 10px;
  border-radius: var(--radius);
  background: rgba(180, 35, 24, 0.08);
  color: var(--bad);
  font-size: 12px;
}

@media (max-width: 960px) {
  .layout { grid-template-columns: 1fr; }
  .proof { min-height: 360px; }
  .brand-lockup .tag { display: none; }
  .app-body { width: min(100% - 24px, var(--shell-max)); }
}

@media (max-width: 820px) {
  .login-frame { grid-template-columns: 1fr; }
  .login-visual { min-height: 220px; padding: 28px 24px; }
  .login-visual h1 { font-size: 28px; }
}

@media (max-width: 640px) {
  .topbar { padding: 10px 12px; gap: 8px; }
  .user-pill { max-width: 120px; }
  .pill { display: none; }
  .page-tabs { width: 100%; }
  .page-tab { flex: 1; text-align: center; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
