:root {
  --surface-0: #f4f3ee;
  --surface-1: #ffffff;
  --surface-2: #eeece4;
  --text-primary: #232320;
  --text-secondary: #6b6a63;
  --text-muted: #9a9890;
  --border: #ddd9cd;
  --accent: #185fa5;
  --accent-bg: #e6f1fb;
  --accent-text: #0c447c;
  --danger: #e24b4a;
  --danger-bg: #fcebeb;
  --danger-text: #a32d2d;
  --success: #639922;
  --success-bg: #eaf3de;
  --success-text: #27500a;
  --radius: 10px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --surface-0: #201f1c;
    --surface-1: #2a2925;
    --surface-2: #35342f;
    --text-primary: #f0efe9;
    --text-secondary: #b8b6ad;
    --text-muted: #85837b;
    --border: #46443d;
    --accent-bg: #0c2438;
    --accent-text: #85b7eb;
    --danger-bg: #3a1414;
    --danger-text: #f09595;
    --success-bg: #1c2a0f;
    --success-text: #97c459;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic", sans-serif;
  background: var(--surface-0);
  color: var(--text-primary);
  -webkit-tap-highlight-color: transparent;
}

#app {
  max-width: 1300px;
  margin: 0 auto;
  min-height: 100vh;
  background: var(--surface-1);
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 5;
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 16px;
  background: var(--surface-1);
  border-bottom: 0.5px solid var(--border);
}

.topbar h1 {
  font-size: 16px;
  font-weight: 500;
  margin: 0;
  flex: 1;
}

.topbar .sub {
  font-size: 12px;
  color: var(--text-secondary);
  margin: 2px 0 0;
}

.iconbtn {
  border: none;
  background: none;
  font-size: 20px;
  color: var(--text-primary);
  padding: 6px;
  cursor: pointer;
  line-height: 1;
}

.list {
  padding: 10px 12px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.card {
  background: var(--surface-1);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
  cursor: pointer;
  display: block;
  text-align: left;
  width: 100%;
  color: inherit;
  font: inherit;
}

.card-title { font-size: 14px; font-weight: 500; margin: 0; }
.card-sub { font-size: 12px; color: var(--text-secondary); margin: 3px 0 0; }
.card-row { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px; }
.card-meta { font-size: 12px; color: var(--text-muted); margin-top: 8px; }

.badge {
  font-size: 11px;
  padding: 3px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge-danger { background: var(--danger-bg); color: var(--danger-text); }
.badge-success { background: var(--success-bg); color: var(--success-text); }
.badge-accent { background: var(--accent-bg); color: var(--accent-text); }

.card-delete, .card-edit {
  border: none;
  background: none;
  font-size: 15px;
  padding: 4px;
  line-height: 1;
  cursor: pointer;
  color: var(--text-muted);
}

.fab-row {
  display: flex;
  justify-content: center;
  padding: 14px;
}

.btn {
  border: 0.5px solid var(--border);
  background: var(--surface-1);
  color: var(--text-primary);
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13px;
  display: inline-flex;
  align-items: center;
  gap: 6px;
  cursor: pointer;
}
.btn:active { transform: scale(0.98); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-block { width: 100%; justify-content: center; }

.form {
  padding: 14px 16px;
  display: flex;
  flex-direction: column;
  gap: 12px;
}

.sticky-actions {
  position: sticky;
  bottom: 0;
  background: var(--surface-1);
  padding: 10px 0 4px;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.field label {
  display: block;
  font-size: 12px;
  color: var(--text-secondary);
  margin-bottom: 5px;
}
.field input, .field select, .field textarea {
  width: 100%;
  border: 0.5px solid var(--border);
  background: var(--surface-1);
  border-radius: var(--radius);
  padding: 9px 10px;
  font-size: 14px;
  color: var(--text-primary);
  font-family: inherit;
}

.status-toggle {
  display: flex;
  gap: 8px;
}
.status-toggle button {
  flex: 1;
  border: 0.5px solid var(--border);
  background: var(--surface-1);
  border-radius: var(--radius);
  padding: 9px;
  font-size: 13px;
  color: var(--text-secondary);
  cursor: pointer;
}
.status-toggle button.active-danger { background: var(--danger-bg); color: var(--danger-text); border-color: var(--danger-bg); }
.status-toggle button.active-success { background: var(--success-bg); color: var(--success-text); border-color: var(--success-bg); }

.panels {
  display: flex;
  gap: 1px;
  background: var(--border);
}
.panel {
  flex: 1;
  min-width: 0;
  position: relative;
  aspect-ratio: 1/1;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}
.zoom-wrap {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  transform-origin: 0 0;
}
.panel img {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  object-fit: contain;
}
.panel canvas {
  position: absolute;
  inset: 0;
  width: 100%;
  height: 100%;
  touch-action: none;
}
.replace-btn, .expand-btn, .delete-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  z-index: 3;
  width: 28px;
  height: 28px;
  border-radius: 50%;
  border: 0.5px solid var(--border);
  background: var(--surface-1);
  font-size: 14px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  padding: 0;
}
.expand-btn {
  top: auto;
  right: auto;
  bottom: 6px;
  left: 6px;
}
.delete-btn {
  right: 40px;
}
.zoom-reset-btn {
  position: absolute;
  bottom: 6px;
  right: 6px;
  z-index: 3;
  height: 26px;
  padding: 0 10px;
  border-radius: 13px;
  border: 0.5px solid var(--border);
  background: var(--surface-1);
  font-size: 11px;
  color: var(--text-secondary);
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
}
.fs-overlay {
  display: none;
  position: fixed;
  inset: 0;
  z-index: 50;
  background: var(--surface-1);
  flex-direction: column;
  overflow-y: auto;
}
.fs-overlay.show { display: flex; }
.fs-close {
  position: fixed;
  top: 10px;
  right: 10px;
  z-index: 51;
  background: var(--surface-2);
  border-radius: var(--radius);
  padding: 6px 12px;
  font-size: 13px;
}
.fs-canvas-area {
  flex: 1;
  min-height: 260px;
  aspect-ratio: auto;
  width: 100%;
  flex-shrink: 0;
}
.panel-label {
  position: absolute;
  top: 6px;
  left: 6px;
  font-size: 10px;
  color: var(--text-muted);
  background: var(--surface-1);
  padding: 2px 7px;
  border-radius: 4px;
  z-index: 2;
}
.panel-empty {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 8px;
  color: var(--text-muted);
  font-size: 12px;
  cursor: pointer;
}
.panel-empty span { font-size: 26px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  background: var(--surface-2);
  border-bottom: 0.5px solid var(--border);
}
.tool-btn {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1.5px solid var(--border);
  background: var(--surface-1);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 15px;
  cursor: pointer;
  color: var(--text-secondary);
  padding: 0;
}
.tool-btn.active { border-color: var(--text-primary); color: var(--text-primary); }
.swatch {
  width: 18px;
  height: 18px;
  border-radius: 50%;
  border: 2px solid transparent;
  cursor: pointer;
  padding: 0;
}
.swatch.active { border-color: var(--text-primary); }
.toolbar .spacer { flex: 1; }

.tags-row { display: flex; gap: 6px; flex-wrap: wrap; padding: 12px 16px 0; }
.tag-chip { font-size: 11px; background: var(--accent-bg); color: var(--accent-text); padding: 3px 10px; border-radius: 20px; }

.empty-state {
  padding: 60px 24px;
  text-align: center;
  color: var(--text-secondary);
}
.empty-state .big { font-size: 28px; margin-bottom: 10px; }

.file-input { display: none; }

.share-toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text-primary);
  color: var(--surface-1);
  padding: 10px 18px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 20;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  max-width: 90%;
  text-align: center;
}
.share-toast.show { opacity: 1; }
