:root {
  --bg: #fafafa;
  --surface: #ffffff;
  --surface-2: #f4f4f6;
  --border: #e5e7eb;
  --text: #111827;
  --text-muted: #6b7280;
  --accent: #6366f1;
  --accent-hover: #4f46e5;
  --accent-soft: #eef2ff;
  --danger: #dc2626;
  --radius: 12px;
  --radius-lg: 16px;
  --shadow-sm: 0 1px 2px rgba(0,0,0,.04), 0 1px 3px rgba(0,0,0,.06);
  --shadow-md: 0 4px 12px rgba(0,0,0,.06), 0 2px 6px rgba(0,0,0,.04);
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b0d12;
    --surface: #14171f;
    --surface-2: #1c2029;
    --border: #2a2f3a;
    --text: #f3f4f6;
    --text-muted: #9ca3af;
    --accent: #818cf8;
    --accent-hover: #a5b4fc;
    --accent-soft: #1e1b4b;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Yu Gothic UI",
    "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

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

.container {
  max-width: 1080px;
  margin: 0 auto;
  padding: 0 20px;
}

.site-header {
  padding: 28px 0 12px;
}
.logo {
  display: flex;
  align-items: center;
  gap: 12px;
  margin: 0;
  font-size: 26px;
  letter-spacing: -0.01em;
}
.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #818cf8 0%, #6366f1 50%, #4f46e5 100%);
  box-shadow: 0 4px 14px rgba(99, 102, 241, .4);
  position: relative;
}
.logo-mark::after {
  content: "";
  position: absolute;
  inset: 8px;
  border-radius: 5px;
  background: rgba(255,255,255,.85);
}
.tagline {
  margin: 6px 0 0;
  color: var(--text-muted);
  font-size: 14px;
}

.generator {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin: 20px 0;
  box-shadow: var(--shadow-sm);
}

.form .field { margin-bottom: 16px; }
.form label {
  display: block;
  font-weight: 600;
  font-size: 14px;
  margin-bottom: 6px;
}
.form .hint {
  font-size: 12px;
  color: var(--text-muted);
  margin-top: 4px;
}

.form textarea,
.form select,
.form input[type="text"] {
  width: 100%;
  padding: 11px 12px;
  font-size: 15px;
  font-family: inherit;
  color: var(--text);
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  outline: none;
  transition: border-color .15s, box-shadow .15s;
}

.form textarea:focus,
.form select:focus,
.form input[type="text"]:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-soft);
}

.form textarea { resize: vertical; min-height: 80px; }

.row {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 12px;
}
@media (max-width: 640px) {
  .row { grid-template-columns: 1fr; }
}

.color-row {
  display: flex;
  gap: 8px;
  align-items: center;
}
.color-row input[type="color"] {
  width: 44px;
  height: 44px;
  padding: 2px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  cursor: pointer;
}
.color-row input[type="text"] {
  width: 120px;
  font-family: ui-monospace, SFMono-Regular, Menlo, monospace;
}

.actions {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  margin-top: 20px;
}

.btn-primary, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 12px 20px;
  font-size: 15px;
  font-weight: 600;
  font-family: inherit;
  border-radius: var(--radius);
  cursor: pointer;
  transition: background .15s, transform .05s, box-shadow .15s;
  border: 1px solid transparent;
}
.btn-primary {
  background: var(--accent);
  color: white;
  box-shadow: 0 1px 2px rgba(99,102,241,.3), 0 4px 12px rgba(99,102,241,.15);
}
.btn-primary:hover { background: var(--accent-hover); }
.btn-primary:active { transform: translateY(1px); }
.btn-primary:disabled { opacity: .6; cursor: not-allowed; }

.btn-ghost {
  background: transparent;
  color: var(--text);
  border-color: var(--border);
}
.btn-ghost:hover { background: var(--surface-2); }

.spinner {
  display: none;
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255,255,255,.4);
  border-top-color: white;
  border-radius: 50%;
  animation: spin .7s linear infinite;
}
.btn-primary.loading .spinner { display: inline-block; }
.btn-primary.loading .btn-label { opacity: .7; }

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

.error {
  margin-top: 14px;
  padding: 10px 14px;
  background: #fef2f2;
  color: var(--danger);
  border: 1px solid #fecaca;
  border-radius: var(--radius);
  font-size: 14px;
}
@media (prefers-color-scheme: dark) {
  .error { background: #2a0f12; border-color: #5a1a1f; color: #fca5a5; }
}

.result {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin: 20px 0;
  box-shadow: var(--shadow-sm);
}
.result h2 { margin: 0 0 16px; font-size: 18px; }

.result-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 24px;
}
@media (max-width: 720px) {
  .result-grid { grid-template-columns: 1fr; }
}

.preview-card { }
.preview {
  background:
    linear-gradient(45deg, var(--surface-2) 25%, transparent 25%) 0 0/16px 16px,
    linear-gradient(-45deg, var(--surface-2) 25%, transparent 25%) 0 8px/16px 16px,
    linear-gradient(45deg, transparent 75%, var(--surface-2) 75%) 8px -8px/16px 16px,
    linear-gradient(-45deg, transparent 75%, var(--surface-2) 75%) -8px 0/16px 16px;
  background-color: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  aspect-ratio: 1 / 1;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  padding: 12px;
}
.preview img {
  max-width: 100%;
  max-height: 100%;
  display: block;
  border-radius: 6px;
}
.preview-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 14px;
}

.preview-meta h3 {
  margin: 0 0 12px;
  font-size: 14px;
  color: var(--text-muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
}
.preview-meta dl {
  display: grid;
  grid-template-columns: 80px 1fr;
  gap: 8px 14px;
  margin: 0;
  font-size: 14px;
}
.preview-meta dt { color: var(--text-muted); }
.preview-meta dd { margin: 0; word-break: break-word; }

.history {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 24px;
  margin: 20px 0;
  box-shadow: var(--shadow-sm);
}
.history-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.history-head h2 { margin: 0; font-size: 18px; }

.history-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(110px, 1fr));
  gap: 12px;
}

.history-item {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 8px;
  cursor: pointer;
  transition: transform .1s, box-shadow .15s;
}
.history-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }
.history-item img {
  display: block;
  width: 100%;
  aspect-ratio: 1;
  object-fit: cover;
  border-radius: 6px;
  background: white;
}
.history-item .h-label {
  font-size: 11px;
  color: var(--text-muted);
  margin-top: 6px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.site-footer {
  border-top: 1px solid var(--border);
  margin-top: 40px;
  padding: 24px 0 40px;
  color: var(--text-muted);
  font-size: 13px;
  text-align: center;
}
.site-footer .note { font-size: 12px; opacity: .8; margin-top: 4px; }
