:root {
  --bg: #0b0c10;
  --bg2: #111319;
  --card: #15171f;
  --card2: #1b1e28;
  --line: #262a36;
  --text: #eceef4;
  --muted: #9aa1b2;
  --dim: #6b7183;
  --accent: #7c5cff;
  --accent2: #22d3ee;
  --ok: #34d399;
  --warn: #fbbf24;
  --err: #f87171;
  --radius: 18px;
  --shadow: 0 20px 50px -20px rgba(0, 0, 0, .6);
  font-family: ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, "Noto Sans", "Helvetica Neue", Arial, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html { scroll-behavior: smooth; scroll-padding-top: 80px; }
body {
  margin: 0; background: var(--bg); color: var(--text); line-height: 1.55;
  background-image:
    radial-gradient(900px 500px at 85% -10%, rgba(124, 92, 255, .18), transparent 60%),
    radial-gradient(700px 400px at -10% 10%, rgba(34, 211, 238, .10), transparent 60%);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
}
a { color: #b9a8ff; text-decoration: none; }
a:hover { text-decoration: underline; }
.wrap { width: min(1200px, 100% - 32px); margin-inline: auto; }
.skip { position: absolute; left: -999px; }
.skip:focus { left: 16px; top: 16px; z-index: 99; background: var(--accent); color: #fff; padding: 8px 12px; border-radius: 8px; }

/* Header */
.topbar { position: sticky; top: 0; z-index: 20; backdrop-filter: blur(14px); background: rgba(11, 12, 16, .72); border-bottom: 1px solid var(--line); }
.topbar-inner { display: flex; align-items: center; gap: 24px; height: 64px; }
.brand { display: flex; align-items: center; gap: 10px; white-space: nowrap; color: var(--text); font-size: 17px; letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand b { font-weight: 700; background: linear-gradient(90deg, #a594ff, var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.logo { display: grid; }
.nav { display: flex; gap: 4px; margin-left: auto; }
.nav a { color: var(--muted); padding: 8px 12px; border-radius: 10px; font-size: 14px; }
.nav a:hover, .nav a.active { color: var(--text); background: var(--card2); text-decoration: none; }
.status-pill { display: inline-flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); border: 1px solid var(--line); padding: 5px 10px; border-radius: 999px; white-space: nowrap; }
.status-pill i { width: 8px; height: 8px; border-radius: 50%; background: var(--warn); box-shadow: 0 0 0 3px rgba(251, 191, 36, .15); }
.status-pill.ok i { background: var(--ok); box-shadow: 0 0 0 3px rgba(52, 211, 153, .15); }
.status-pill.err i { background: var(--err); box-shadow: 0 0 0 3px rgba(248, 113, 113, .15); }

/* Hero */
.hero { text-align: center; padding: 56px 0 28px; }
.hero h1 { font-size: clamp(30px, 5vw, 54px); line-height: 1.08; letter-spacing: -.03em; margin: 0 0 14px; }
.grad { background: linear-gradient(90deg, var(--accent), var(--accent2)); -webkit-background-clip: text; background-clip: text; color: transparent; }
.hero p { color: var(--muted); max-width: 620px; margin: 0 auto; font-size: clamp(15px, 2vw, 18px); }

/* Layout */
.studio { display: grid; grid-template-columns: minmax(320px, 420px) 1fr; gap: 20px; align-items: start; }
.card { background: linear-gradient(180deg, var(--card), var(--bg2)); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
.panel { padding: 22px; display: flex; flex-direction: column; gap: 20px; }
.field { display: flex; flex-direction: column; gap: 10px; }
.label, label[for] { font-weight: 600; font-size: 14px; }
.label-row { display: flex; justify-content: space-between; align-items: center; }
.counter { font-size: 12px; color: var(--dim); font-variant-numeric: tabular-nums; }
.counter.near { color: var(--warn); }
textarea, input[type="number"] {
  width: 100%; background: #0e1016; color: var(--text); border: 1px solid var(--line);
  border-radius: 12px; padding: 12px 14px; font: inherit; font-size: 15px; transition: border-color .15s, box-shadow .15s;
}
textarea { resize: vertical; min-height: 130px; }
textarea:focus, input:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px rgba(124, 92, 255, .18); }
input:disabled { opacity: .5; }
.hint { margin: 0; font-size: 12.5px; color: var(--dim); }
.hint.subtle { margin-top: -8px; }

.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chips button { background: var(--card2); color: var(--muted); border: 1px solid var(--line); border-radius: 999px; padding: 5px 11px; font-size: 12px; cursor: pointer; transition: .15s; }
.chips button:hover { color: var(--text); border-color: #3a3f50; }

.seg { display: grid; grid-template-columns: repeat(auto-fit, minmax(96px, 1fr)); gap: 6px; background: #0e1016; border: 1px solid var(--line); padding: 5px; border-radius: 14px; }
.seg label { cursor: pointer; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg span { display: flex; flex-direction: column; align-items: center; padding: 9px 4px; border-radius: 10px; font-weight: 600; font-size: 15px; color: var(--muted); transition: .15s; }
.seg small { font-weight: 500; font-size: 11px; color: var(--dim); }
.seg input:checked + span { background: linear-gradient(180deg, #2a2350, #221d3f); color: #fff; box-shadow: inset 0 0 0 1px rgba(124, 92, 255, .55); }
.seg input:focus-visible + span { outline: 2px solid var(--accent); }

.seed-row { display: flex; gap: 8px; }
.toggle { display: inline-flex; align-items: center; gap: 8px; font-size: 13px; color: var(--muted); cursor: pointer; }
.toggle input { position: absolute; opacity: 0; }
.toggle span { width: 34px; height: 20px; border-radius: 999px; background: #2a2e3b; position: relative; transition: .2s; }
.toggle span::after { content: ""; position: absolute; top: 3px; left: 3px; width: 14px; height: 14px; border-radius: 50%; background: #fff; transition: .2s; }
.toggle input:checked + span { background: var(--accent); }
.toggle input:checked + span::after { transform: translateX(14px); }
.toggle input:focus-visible + span { outline: 2px solid var(--accent); outline-offset: 2px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 10px; border: 1px solid transparent; border-radius: 12px; padding: 12px 18px; font: inherit; font-weight: 600; font-size: 15px; cursor: pointer; color: var(--text); transition: transform .1s, filter .15s, background .15s, opacity .15s; text-decoration: none !important; user-select: none; }
.btn:active { transform: translateY(1px) scale(.99); }
.btn.primary { background: linear-gradient(135deg, var(--accent), #5b3df5 60%, #3b82f6); box-shadow: 0 10px 30px -10px rgba(124, 92, 255, .7); color: #fff; }
.btn.primary:hover { filter: brightness(1.1); }
.btn.ghost { background: var(--card2); border-color: var(--line); }
.btn.ghost:hover { border-color: #3a3f50; }
.btn.small { padding: 7px 12px; font-size: 13px; border-radius: 10px; }
.btn.icon { padding: 0 14px; font-size: 18px; }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .45; pointer-events: none; }
.btn kbd { font: 11px ui-monospace, monospace; opacity: .7; border: 1px solid rgba(255, 255, 255, .3); border-radius: 5px; padding: 1px 5px; }
.actions { display: grid; grid-template-columns: 1fr auto; gap: 10px; }
.actions .btn.primary { padding: 15px; font-size: 16px; }
.btn.busy .btn-label::before { content: ""; display: inline-block; width: 14px; height: 14px; margin-right: 8px; vertical-align: -2px; border: 2px solid rgba(255, 255, 255, .35); border-top-color: #fff; border-radius: 50%; animation: spin .8s linear infinite; }

.status { min-height: 1.4em; margin: -6px 0 0; font-size: 13.5px; color: var(--muted); }
.status.err { color: var(--err); }
.status.ok { color: var(--ok); }
#hfFallback { align-self: flex-start; margin-top: -10px; }
[hidden] { display: none !important; }

/* Result */
.result { padding: 16px; display: flex; flex-direction: column; gap: 14px; position: sticky; top: 80px; }
.stage { position: relative; aspect-ratio: 1; width: 100%; border-radius: 14px; overflow: hidden; background: repeating-conic-gradient(#12141b 0 25%, #0f1117 0 50%) 0 0 / 28px 28px; border: 1px solid var(--line); display: grid; place-items: center; }
.stage > * { grid-area: 1 / 1; }
.stage img { width: 100%; height: 100%; object-fit: contain; opacity: 0; transition: opacity .4s; cursor: zoom-in; }
.stage[data-state="done"] img { opacity: 1; }
.empty, .loading { display: none; flex-direction: column; align-items: center; gap: 12px; color: var(--dim); text-align: center; padding: 20px; }
.stage[data-state="empty"] .empty, .stage[data-state="error"] .empty { display: flex; }
.stage[data-state="loading"] .loading { display: flex; }
.stage[data-state="loading"] img { opacity: .15; filter: blur(8px); }
.empty-art { width: 88px; height: 88px; border-radius: 22px; background: linear-gradient(135deg, rgba(124, 92, 255, .25), rgba(34, 211, 238, .2)); border: 1px dashed #3a3f50; position: relative; }
.empty-art::after { content: ""; position: absolute; inset: 26px 22px; background: #fff3; clip-path: polygon(0 100%, 35% 30%, 60% 70%, 75% 50%, 100% 100%); }
.orb { width: 84px; height: 84px; border-radius: 50%; background: conic-gradient(from 0deg, var(--accent), var(--accent2), #f472b6, var(--accent)); animation: spin 1.6s linear infinite; filter: blur(.5px); position: relative; }
.orb::after { content: ""; position: absolute; inset: 6px; border-radius: 50%; background: #0f1117; }
.loading p { margin: 0; color: var(--muted); }
.timer { font: 600 22px ui-monospace, SFMono-Regular, Menlo, monospace; color: var(--text) !important; }
.stage[data-state="loading"]::before { content: ""; position: absolute; inset: 0; background: linear-gradient(100deg, transparent 30%, rgba(255, 255, 255, .05) 50%, transparent 70%); background-size: 200% 100%; animation: shimmer 1.6s infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -50% 0; } }

.meta { display: flex; flex-wrap: wrap; gap: 8px; }
.meta span { font-size: 12.5px; color: var(--muted); background: var(--card2); border: 1px solid var(--line); padding: 4px 10px; border-radius: 999px; font-variant-numeric: tabular-nums; }
.result-actions { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 8px; }

/* History */
.history-wrap { margin-top: 40px; }
.section-head { display: flex; align-items: center; justify-content: space-between; }
.section-head h2 { font-size: 20px; margin: 0 0 10px; }
.history { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; margin-top: 10px; }
.thumb { position: relative; border-radius: 14px; overflow: hidden; border: 1px solid var(--line); background: var(--card); aspect-ratio: 1; animation: pop .35s ease; }
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; cursor: zoom-in; transition: transform .3s; }
.thumb:hover img { transform: scale(1.04); }
.thumb .bar { position: absolute; inset: auto 0 0 0; display: flex; justify-content: space-between; align-items: center; gap: 6px; padding: 8px; background: linear-gradient(transparent, rgba(0, 0, 0, .85)); font-size: 11px; color: #ddd; }
.thumb .bar a { color: #fff; background: rgba(255, 255, 255, .14); padding: 4px 8px; border-radius: 8px; font-weight: 600; }
@keyframes pop { from { transform: scale(.95); opacity: 0; } }

/* Info */
.info-grid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 20px; margin-top: 56px; }
.info { padding: 22px; }
.info h2 { margin: 0 0 10px; font-size: 18px; }
.info p, .info li { color: var(--muted); font-size: 14.5px; }
.info ul { padding-left: 18px; }
.info dl { display: grid; grid-template-columns: auto 1fr; gap: 8px 16px; margin: 0; font-size: 14.5px; }
.info dt { color: var(--dim); }
.info dd { margin: 0; }

.footer { display: flex; justify-content: space-between; flex-wrap: wrap; gap: 10px; padding: 40px 0; margin-top: 40px; border-top: 1px solid var(--line); color: var(--dim); font-size: 13px; }

/* Viewer */
dialog { border: 1px solid var(--line); background: var(--card); color: var(--text); border-radius: 18px; padding: 12px; max-width: min(92vw, 1100px); max-height: 94vh; }
dialog::backdrop { background: rgba(0, 0, 0, .78); backdrop-filter: blur(4px); }
dialog img { display: block; max-width: 100%; max-height: calc(94vh - 90px); margin: auto; border-radius: 10px; }
.viewer-bar { display: flex; align-items: center; gap: 8px; padding-top: 10px; }
.viewer-bar span { margin-right: auto; font-size: 13px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* Responsive */
@media (max-width: 920px) {
  .studio { grid-template-columns: 1fr; }
  .result { position: static; }
  .info-grid { grid-template-columns: 1fr; }
}
@media (max-width: 560px) {
  .topbar-inner { gap: 8px; }
  .wrap { width: calc(100% - 24px); }
  .nav { gap: 0; }
  .brand > span:last-child { font-size: 15px; }
  .nav a { padding: 6px 7px; font-size: 13px; }
  .brand svg { width: 24px; height: 24px; }
  .status-pill { padding: 5px; }
  .status-pill span { display: none; }
  .hero { padding: 32px 0 18px; }
  .panel, .result { padding: 14px; }
  .btn kbd { display: none; }
  .result-actions { grid-template-columns: 1fr 1fr; }
  .result-actions .btn.primary { grid-column: 1 / -1; }
  .history { grid-template-columns: repeat(2, 1fr); }
}
@media (prefers-reduced-motion: reduce) { *, *::before, *::after { animation: none !important; transition: none !important; } }
