:root {
  --bg: #f5f6f8;
  --card: #fff;
  --text: #17202a;
  --muted: #667085;
  --line: #e4e7ec;
  --brand: #1d5bd8;
  --brand-dark: #1747a8;
  --ok: #067647;
  --ok-bg: #ecfdf3;
  --err: #b42318;
  --err-bg: #fef3f2;
  --warn-bg: #fffaeb;
  --radius: 14px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color: var(--text);
  background: var(--bg);
}
* { box-sizing: border-box; }
body { margin: 0; min-height: 100vh; line-height: 1.5; }
h1 { font-size: 1.45rem; margin: 0 0 .35rem; }
h2 { font-size: 1.1rem; margin: 0 0 .75rem; }
h3 { font-size: 1rem; margin: 0; }
a { color: var(--brand); }
code { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .92em; }

.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap;
  padding: .8rem 1rem; background: var(--card); border-bottom: 1px solid var(--line); }
.brand { display: flex; align-items: center; gap: .5rem; font-weight: 700; color: var(--text); text-decoration: none; }
.logo { display: grid; place-items: center; width: 30px; height: 30px; border-radius: 8px; background: var(--brand); color: #fff; }
.badge { font-size: .7rem; font-weight: 600; padding: .1rem .45rem; border-radius: 99px; background: #fff4e5; color: #b54708; border: 1px solid #fedf89; }
.nav { display: flex; align-items: center; gap: 1rem; }
.nav a { text-decoration: none; color: var(--muted); font-weight: 500; }
.nav a:hover { color: var(--text); }
.nav form { margin: 0; }

.wrap { max-width: 560px; margin: 0 auto; padding: 1.25rem 1rem 3rem; }
.wrap.wide { max-width: 1040px; }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 1.25rem; box-shadow: 0 1px 2px rgba(16,24,40,.04); }
.card + .card, .card + .tabs, .stats + .search, .search + .sub-list { margin-top: 1rem; }
.narrow { max-width: 420px; margin: 1.5rem auto 0; }
.center { text-align: center; }
.muted { color: var(--muted); margin-top: 0; }
.hint { color: var(--muted); font-size: .85rem; margin: .5rem 0 0; }
.row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.row form { margin: 0; }

.stack { display: grid; gap: .9rem; }
label, .field { display: grid; gap: .35rem; font-weight: 500; font-size: .95rem; }
.label small, label small { color: var(--muted); font-weight: 400; }
input, textarea { width: 100%; font: inherit; padding: .7rem .8rem; border: 1px solid #d0d5dd; border-radius: 10px; background: #fff; }
input:focus, textarea:focus { outline: 3px solid rgba(29,91,216,.18); border-color: var(--brand); }

.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; font: inherit; font-weight: 600;
  padding: .6rem 1rem; border-radius: 10px; border: 1px solid #d0d5dd; background: #fff; color: var(--text);
  text-decoration: none; cursor: pointer; transition: background .15s, transform .05s; }
.btn:hover { background: #f9fafb; }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ghost { background: transparent; }
.btn.big { padding: .85rem 1rem; font-size: 1.05rem; }
.btn[disabled] { opacity: .6; cursor: progress; }
.link { background: none; border: 0; padding: 0; font: inherit; color: var(--brand); cursor: pointer; }
.link.danger { color: var(--err); }

.alert { padding: .7rem .9rem; border-radius: 10px; margin: .75rem 0; font-size: .93rem; }
.alert.error { background: var(--err-bg); color: var(--err); }
.alert.ok { background: var(--ok-bg); color: var(--ok); }
.alert.warn { background: var(--warn-bg); color: #93370d; }
.demo-box { margin-top: 1.25rem; padding: .9rem; border: 1px dashed #fedf89; background: #fffcf5; border-radius: 10px; font-size: .92rem; }
.demo-box p { margin: 0 0 .6rem; }
.demo-box p:last-child { margin: 0; }

.form-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; }
.chip { display: inline-block; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: .78rem; padding: .1rem .5rem; border-radius: 6px; background: #eef4ff; color: var(--brand-dark); }
.drop { position: relative; display: grid; place-items: center; min-height: 110px; padding: 1rem; border: 2px dashed #c8d0dc;
  border-radius: 12px; background: #fafbfc; color: var(--muted); font-weight: 400; text-align: center; cursor: pointer; }
.drop:hover, .drop.over { border-color: var(--brand); background: #f5f8ff; }
.drop input { position: absolute; inset: 0; opacity: 0; cursor: pointer; }
.previews { display: grid; grid-template-columns: repeat(3, 1fr); gap: .5rem; }
.previews:empty { display: none; }
.prev { position: relative; aspect-ratio: 1; border-radius: 10px; overflow: hidden; background: #eee; }
.prev img { width: 100%; height: 100%; object-fit: cover; }
.prev button { position: absolute; top: 4px; right: 4px; width: 26px; height: 26px; border-radius: 50%; border: 0; background: rgba(0,0,0,.6); color: #fff; cursor: pointer; }
.prev small { position: absolute; left: 4px; bottom: 4px; font-size: .7rem; background: rgba(0,0,0,.55); color: #fff; padding: 0 .3rem; border-radius: 4px; }

.done-icon { width: 64px; height: 64px; margin: 0 auto .75rem; display: grid; place-items: center; border-radius: 50%; background: var(--ok-bg); color: var(--ok); font-size: 2rem; }

.page-head { display: flex; justify-content: space-between; align-items: center; gap: .75rem; flex-wrap: wrap; margin-bottom: 1rem; }
.stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: .75rem; }
.stat { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: .8rem 1rem; color: var(--muted); font-size: .85rem; }
.stat span { display: block; font-size: 1.5rem; font-weight: 700; color: var(--text); }
.search { display: flex; gap: .5rem; }
.search input { flex: 1; }
.sub-list { display: grid; gap: .75rem; }
.sub { display: flex; gap: 1rem; align-items: flex-start; padding: 1rem; }
.thumbs { display: flex; gap: .4rem; flex-shrink: 0; }
.thumbs img { width: 72px; height: 72px; object-fit: cover; border-radius: 8px; display: block; background: #eee; transition: transform .15s; }
.thumbs a:hover img { transform: scale(1.04); }
.sub-body { min-width: 0; }
.meta { margin: .2rem 0 0; color: var(--muted); font-size: .88rem; }
.ket { margin: .4rem 0 0; font-size: .93rem; white-space: pre-line; }
.empty { text-align: center; color: var(--muted); margin-top: 1rem; }
.pager { display: flex; justify-content: space-between; align-items: center; margin-top: 1rem; }

.gen { display: grid; grid-template-columns: 1fr 1fr 1.4fr auto; gap: .75rem; align-items: end; }
.tabs { display: flex; gap: .35rem; margin: 1.25rem 0 .75rem; flex-wrap: wrap; }
.tab { text-decoration: none; color: var(--muted); padding: .4rem .8rem; border-radius: 99px; border: 1px solid var(--line); background: #fff; font-size: .9rem; }
.tab span { font-weight: 600; margin-left: .2rem; }
.tab.on { background: var(--text); color: #fff; border-color: var(--text); }
.table-wrap { padding: 0; overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .92rem; }
th, td { text-align: left; padding: .7rem 1rem; border-bottom: 1px solid var(--line); white-space: nowrap; }
th { font-size: .8rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; }
tbody tr:last-child td { border-bottom: 0; }
.actions { display: flex; gap: .9rem; }
.actions form { margin: 0; }
.pill { font-size: .8rem; padding: .15rem .55rem; border-radius: 99px; }
.pill.free { background: var(--ok-bg); color: var(--ok); }
.pill.used { background: #f2f4f7; color: var(--muted); }

.cred-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .6rem; }
.cred { display: grid; grid-template-columns: auto 1fr; gap: .15rem .6rem; align-items: baseline; padding: .8rem 1rem;
  background: var(--card); border: 1px dashed #98a2b3; border-radius: 10px; break-inside: avoid; }
.cred strong { font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 1.05rem; letter-spacing: .04em; }
.cred-label { color: var(--muted); font-size: .75rem; }

dialog#lightbox { padding: 0; border: 0; background: transparent; max-width: 96vw; max-height: 92vh; }
dialog#lightbox::backdrop { background: rgba(10,14,20,.85); }
dialog#lightbox img { display: block; max-width: 96vw; max-height: 88vh; border-radius: 10px; }
dialog#lightbox .close { position: fixed; top: 12px; right: 16px; width: 40px; height: 40px; border-radius: 50%; border: 0; font-size: 1.6rem; background: rgba(255,255,255,.15); color: #fff; cursor: pointer; }
.lb-nav { position: fixed; inset: 50% 8px auto 8px; display: flex; justify-content: space-between; pointer-events: none; }
.lb-nav button { pointer-events: auto; width: 44px; height: 44px; border-radius: 50%; border: 0; font-size: 1.6rem; background: rgba(255,255,255,.15); color: #fff; cursor: pointer; }

@media (max-width: 720px) {
  .gen { grid-template-columns: 1fr 1fr; }
  .gen button { grid-column: 1 / -1; }
  .stats { grid-template-columns: repeat(3, 1fr); gap: .5rem; }
  .stat { padding: .6rem .7rem; font-size: .75rem; }
  .stat span { font-size: 1.2rem; }
  .sub { flex-direction: column; }
  .nav { gap: .75rem; font-size: .9rem; }
}

@media print {
  .topbar, .no-print { display: none !important; }
  body, .wrap { background: #fff; padding: 0; max-width: none; }
  .cred-grid { grid-template-columns: repeat(3, 1fr); gap: 6px; }
  .cred { border: 1px dashed #000; }
}
