:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #e2e4e9;
  --text: #1b1d23;
  --muted: #6b7280;
  --accent: #7a1f2b;
  --accent-hover: #611723;
  --radius: 12px;
  --shadow: 0 1px 2px rgba(16,24,40,.04), 0 1px 3px rgba(16,24,40,.06);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14151a;
    --panel: #1c1e25;
    --border: #2b2e37;
    --text: #edeef0;
    --muted: #9599a3;
    --shadow: 0 1px 2px rgba(0,0,0,.3), 0 2px 6px rgba(0,0,0,.35);
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  display: flex;
  flex-direction: column;
}

.topbar {
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  background: var(--panel);
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 700;
  font-size: 1.05rem;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 32px;
  height: 32px;
  border-radius: 8px;
  background: var(--accent);
  color: #fff;
  font-size: 1rem;
}

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: minmax(320px, 420px) 1fr;
  gap: 20px;
  padding: 24px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
}

@media (max-width: 860px) {
  .layout { grid-template-columns: 1fr; }
}

.panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 20px;
}

.tabs {
  display: flex;
  gap: 4px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 4px;
  margin-bottom: 18px;
}

.tab {
  flex: 1;
  border: none;
  background: transparent;
  padding: 8px 12px;
  border-radius: 8px;
  cursor: pointer;
  font-weight: 600;
  color: var(--muted);
  font-size: .9rem;
}

.tab.active {
  background: var(--panel);
  color: var(--text);
  box-shadow: var(--shadow);
}

.tab-panel { display: none; flex-direction: column; gap: 14px; }
.tab-panel.active { display: flex; }

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  font-size: .85rem;
  color: var(--muted);
  flex: 1;
}

.field span { font-weight: 600; color: var(--text); }

.field input[type="text"],
.field input[type="number"],
.field textarea,
.field select {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 9px 10px;
  background: var(--bg);
  color: var(--text);
  font-size: .9rem;
  font-family: inherit;
  width: 100%;
}

.field input[type="color"] {
  width: 100%;
  height: 38px;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 3px;
  background: var(--bg);
  cursor: pointer;
}

.field input[type="range"] { width: 100%; }

.field.checkbox {
  flex-direction: row;
  align-items: center;
  gap: 8px;
}

.field.checkbox input { width: 16px; height: 16px; }

.field-row {
  display: flex;
  gap: 12px;
}

.field-group {
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.field-group legend {
  font-size: .8rem;
  font-weight: 700;
  color: var(--muted);
  padding: 0 4px;
}

.hint {
  min-height: 18px;
  font-size: .82rem;
  color: #c0392b;
  margin: 10px 0 0;
}

.btn {
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
  padding: 10px 16px;
  border-radius: 8px;
  font-weight: 600;
  font-size: .88rem;
  cursor: pointer;
}

.btn:hover { background: var(--bg); }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}

.btn-primary:hover { background: var(--accent-hover); }

.btn-ghost {
  background: transparent;
  border-color: transparent;
  color: var(--muted);
  text-decoration: underline;
}

.btn-sm { padding: 6px 10px; font-size: .8rem; align-self: flex-start; }

.preview {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
}

.preview-surface {
  width: 100%;
  flex: 1;
  min-height: 360px;
  display: flex;
  align-items: center;
  justify-content: center;
  background:
    linear-gradient(45deg, #00000008 25%, transparent 25%),
    linear-gradient(-45deg, #00000008 25%, transparent 25%),
    linear-gradient(45deg, transparent 75%, #00000008 75%),
    linear-gradient(-45deg, transparent 75%, #00000008 75%);
  background-size: 20px 20px;
  background-position: 0 0, 0 10px, 10px -10px, -10px 0px;
  border-radius: 10px;
  border: 1px dashed var(--border);
}

#preview-canvas {
  max-width: 100%;
  max-height: 480px;
}

.download-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

.save-meta {
  display: flex;
  gap: 12px;
  width: 100%;
}

@media (max-width: 560px) {
  .save-meta { flex-direction: column; }
}

.history {
  grid-column: 1 / -1;
}

.history-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  flex-wrap: wrap;
}

.history-head h2 {
  margin: 0;
  font-size: 1.05rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 24px;
  padding: 0 7px;
  border-radius: 999px;
  background: var(--accent);
  color: #fff;
  font-size: .78rem;
  font-weight: 700;
}

.history-actions { display: flex; gap: 8px; }

.history-hint {
  font-size: .82rem;
  color: var(--muted);
  margin: 8px 0 14px;
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.history-empty {
  font-size: .85rem;
  color: var(--muted);
  text-align: center;
  padding: 18px 0;
  margin: 0;
  border: 1px dashed var(--border);
  border-radius: 10px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 10px 12px;
  background: var(--bg);
}

.history-thumb {
  width: 56px;
  height: 56px;
  object-fit: contain;
  border-radius: 6px;
  background: #fff;
  border: 1px solid var(--border);
  flex-shrink: 0;
}

.history-main {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.history-main strong { font-size: .92rem; }

.history-meta {
  font-size: .82rem;
  color: var(--text);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.history-stats {
  font-size: .76rem;
  color: var(--muted);
}

.btn-danger {
  background: #c0392b;
  border-color: #c0392b;
  color: #fff;
  text-decoration: none;
}

.btn-danger:hover { background: #a93226; }

.lock-box {
  display: flex;
  flex-direction: column;
  gap: 10px;
  border: 1px dashed var(--border);
  border-radius: 10px;
  padding: 16px;
  align-items: flex-start;
}

.lock-box p {
  margin: 0;
  font-size: .88rem;
}

.lock-row {
  display: flex;
  gap: 8px;
  align-items: center;
  flex-wrap: wrap;
}

.lock-row input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  background: var(--bg);
  color: var(--text);
  font-size: .9rem;
  min-width: 220px;
}

.lock-err {
  font-size: .8rem;
  color: #c0392b;
}

.undo-bar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--accent);
  border-radius: 10px;
  padding: 8px 12px;
  font-size: .85rem;
}

.history-edit {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
}

.history-edit input {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  background: var(--panel);
  color: var(--text);
  font-size: .85rem;
  flex: 1;
  min-width: 140px;
}

.history-item-actions {
  display: flex;
  gap: 6px;
  flex-shrink: 0;
  flex-wrap: wrap;
  justify-content: flex-end;
}

@media (max-width: 560px) {
  .history-item { flex-wrap: wrap; }
  .history-item-actions { width: 100%; justify-content: flex-start; }
}

.foot {
  text-align: center;
  padding: 16px;
  font-size: .78rem;
  color: var(--muted);
}
