:root {
  --bg: #f4f1ff;
  --card: #ffffff;
  --ink: #2a2350;
  --muted: #6d6896;
  --brand: #6c4cf1;
  --brand-dark: #4f33c9;
  --accent: #ffc933;
  --danger: #e5484d;
  --line: #e3ddff;
  --radius: 18px;
  --shadow: 0 6px 20px rgba(76, 51, 201, 0.12);
  font-family: "Trebuchet MS", "Segoe UI", system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; background: var(--bg); color: var(--ink); font-size: 18px; line-height: 1.4; min-height: 100vh; }
h1, h2, h3 { margin: 0 0 0.4em; line-height: 1.15; }
h1 { font-size: 2rem; }
h2 { font-size: 1.5rem; }
p { margin: 0 0 1em; }
[hidden] { display: none !important; }

.noscript { padding: 2rem; text-align: center; }

/* ---------- layout ---------- */
.shell { max-width: 960px; margin: 0 auto; padding: 16px 16px 64px; }
.topbar { display: flex; align-items: center; gap: 12px; justify-content: space-between; padding: 8px 0 16px; flex-wrap: wrap; }
.brand { font-size: 1.7rem; font-weight: 800; color: var(--brand); letter-spacing: -0.02em; display: flex; align-items: center; gap: 8px; }
.brand img { width: 36px; height: 36px; }
.who { display: flex; align-items: center; gap: 10px; color: var(--muted); }
.who strong { color: var(--ink); }

.card { background: var(--card); border-radius: var(--radius); box-shadow: var(--shadow); padding: 24px; }
.center { max-width: 420px; margin: 8vh auto 0; }
.center .brand { justify-content: center; font-size: 2.4rem; margin-bottom: 4px; }
.tagline { text-align: center; color: var(--muted); margin-bottom: 20px; }

/* ---------- forms & buttons ---------- */
label { display: block; font-weight: 700; margin: 14px 0 6px; }
input[type="text"], input[type="password"] {
  width: 100%; font: inherit; padding: 12px 14px; border: 2px solid var(--line); border-radius: 12px; background: #fff; color: var(--ink);
}
input:focus-visible, button:focus-visible, a:focus-visible, .tile:focus-visible, .chip:has(input:focus-visible) {
  outline: 3px solid var(--accent); outline-offset: 2px;
}
.hint { color: var(--muted); font-size: 0.85rem; margin: 6px 0 0; }
.error { color: var(--danger); font-weight: 700; margin: 12px 0 0; min-height: 1.4em; }

.btn {
  font: inherit; font-weight: 800; cursor: pointer; border: 0; border-radius: 14px; padding: 12px 20px;
  background: var(--brand); color: #fff; box-shadow: 0 4px 0 var(--brand-dark); transition: transform 0.05s;
}
.btn:hover { background: #7a5cf5; }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 var(--brand-dark); }
.btn:disabled { opacity: 0.55; cursor: not-allowed; transform: none; box-shadow: 0 4px 0 var(--brand-dark); }
.btn.big { width: 100%; font-size: 1.15rem; margin-top: 18px; }
.btn.gold { background: var(--accent); color: #4a3500; box-shadow: 0 4px 0 #d9a50f; }
.btn.gold:hover { background: #ffd24f; }
.btn.ghost { background: transparent; color: var(--brand); box-shadow: none; border: 2px solid var(--line); }
.btn.ghost:hover { background: #f0ecff; }
.btn.danger { background: var(--danger); box-shadow: 0 4px 0 #b3363a; }
.btn.small { padding: 8px 14px; font-size: 0.9rem; box-shadow: none; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); font-weight: 700; cursor: pointer; text-decoration: underline; }

.switch { text-align: center; margin: 18px 0 0; color: var(--muted); }

/* ---------- library ---------- */
.library-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin: 8px 0 16px; flex-wrap: wrap; }
.library-head h2 { margin: 0; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 16px; }
.tile {
  background: var(--card); border: 0; border-radius: var(--radius); box-shadow: var(--shadow); padding: 10px 10px 14px; cursor: pointer;
  text-align: center; font: inherit; color: inherit; transition: transform 0.12s;
}
.tile:hover { transform: translateY(-4px) rotate(-1deg); }
.tile img { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: 12px; background: var(--bg); display: block; }
.tile .name { font-weight: 800; margin-top: 8px; overflow-wrap: anywhere; }
.badge { display: inline-block; margin-top: 4px; padding: 2px 10px; border-radius: 999px; font-size: 0.8rem; font-weight: 800; background: var(--bg); color: var(--brand-dark); }

.empty { text-align: center; padding: 48px 16px; }
.empty .big-emoji { font-size: 4rem; }

/* ---------- create ---------- */
.create-grid { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .create-grid { grid-template-columns: 1fr 1fr; } }
.preview {
  margin: 0; /* the drop zone is a <label>; don't inherit the form-label margin */
  aspect-ratio: 1; border-radius: var(--radius); background: var(--bg); border: 3px dashed var(--line);
  display: flex; align-items: center; justify-content: center; text-align: center; color: var(--muted); overflow: hidden; position: relative; padding: 12px;
}
.preview img { position: absolute; inset: 0; width: 100%; height: 100%; object-fit: cover; }
.preview.result { border-style: solid; border-color: var(--accent); }
.dropzone { cursor: pointer; }
.dropzone:hover { border-color: var(--brand); }
.file-input { position: absolute; width: 1px; height: 1px; opacity: 0; pointer-events: none; }
.dropzone:has(.file-input:focus-visible) { outline: 3px solid var(--accent); outline-offset: 2px; }
.steps { color: var(--muted); font-weight: 700; margin: 0 0 8px; }

.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { position: relative; margin: 0; }
.chip input { position: absolute; opacity: 0; inset: 0; cursor: pointer; }
.chip span { display: inline-block; padding: 8px 14px; border-radius: 999px; border: 2px solid var(--line); font-weight: 700; background: #fff; }
.chip input:checked + span { background: var(--brand); color: #fff; border-color: var(--brand); }
.chip { border-radius: 999px; }

.spinner { width: 54px; height: 54px; border: 6px solid var(--line); border-top-color: var(--brand); border-radius: 50%; animation: spin 0.9s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.magic-left { color: var(--muted); font-size: 0.9rem; }
.row { display: flex; gap: 10px; flex-wrap: wrap; margin-top: 14px; }

/* ---------- detail ---------- */
.detail { display: grid; gap: 20px; grid-template-columns: 1fr; }
@media (min-width: 720px) { .detail { grid-template-columns: 1fr 1fr; align-items: start; } }
.detail .art { width: 100%; aspect-ratio: 1; object-fit: cover; border-radius: var(--radius); background: var(--bg); }
.detail .original { width: 96px; height: 96px; object-fit: cover; border-radius: 12px; border: 3px solid var(--line); }
.back { margin-bottom: 12px; }
.original-row { display: flex; align-items: center; gap: 12px; margin: 12px 0; color: var(--muted); }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: var(--ink); color: #fff; padding: 12px 20px;
  border-radius: 999px; font-weight: 700; box-shadow: var(--shadow); max-width: 92vw; text-align: center; z-index: 10;
}
.toast.bad { background: var(--danger); }

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

/* checkbox rows */
label.check { display: flex; align-items: center; gap: 10px; font-weight: 700; margin: 16px 0 4px; cursor: pointer; }
label.check input { width: 22px; height: 22px; accent-color: var(--brand); }
