:root {
  --bg: #f6f2fc; --bg2: #ece4f8; --surface: #ffffff; --surface2: #faf7fe; --ink: #1f1535; --muted: #766a92; --line: #e4daf2;
  --primary: #6a2fc9; --primary-ink: #fff; --primary-soft: #efe6fd; --grad: linear-gradient(135deg, #5a2bb8, #8b45dd);
  --accent: #ff6a3d; --accent-soft: #ffe9df; --mint: #2e9d7f; --mint-soft: #dcf3ea;
  --danger: #c0392b; --danger-soft: #fdecea; --warn-soft: #fff4dc; --shadow: 0 6px 24px rgba(70, 30, 130, .12);
  --radius: 16px; --tab-h: 62px; --head-h: 56px;
  --sat: env(safe-area-inset-top, 0px); --sab: env(safe-area-inset-bottom, 0px);
  color-scheme: light;
}
:root[data-theme="dark"] {
  --bg: #130d21; --bg2: #1b1330; --surface: #211737; --surface2: #2a1e45; --ink: #f3edff; --muted: #aa9ec8; --line: #3b2d5c;
  --primary: #a47bf2; --primary-ink: #1a0d33; --primary-soft: #33235a; --grad: linear-gradient(135deg, #9a6df0, #c395ff);
  --accent: #ff8a5c; --accent-soft: #3d2530; --mint: #6fd0b3; --mint-soft: #1e3a33;
  --danger: #ff8a7a; --danger-soft: #3a2220; --warn-soft: #3a3020; --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  color-scheme: dark;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #130d21; --bg2: #1b1330; --surface: #211737; --surface2: #2a1e45; --ink: #f3edff; --muted: #aa9ec8; --line: #3b2d5c;
    --primary: #a47bf2; --primary-ink: #1a0d33; --primary-soft: #33235a; --grad: linear-gradient(135deg, #9a6df0, #c395ff);
    --accent: #ff8a5c; --accent-soft: #3d2530; --mint: #6fd0b3; --mint-soft: #1e3a33;
    --danger: #ff8a7a; --danger-soft: #3a2220; --warn-soft: #3a3020; --shadow: 0 6px 24px rgba(0, 0, 0, .45);
    color-scheme: dark;
  }
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; }
body {
  background: var(--bg); color: var(--ink); font: 16px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  -webkit-font-smoothing: antialiased; overscroll-behavior-y: none; -webkit-text-size-adjust: 100%;
}
a { color: var(--primary); }
button { font: inherit; color: inherit; cursor: pointer; }
input, textarea, select { font: inherit; color: inherit; }
h1, h2, h3 { margin: 0; line-height: 1.2; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.row { display: flex; gap: 10px; align-items: center; }
.row.wrap { flex-wrap: wrap; }
.grow { flex: 1; min-width: 0; }
.spacer { height: 12px; }

/* ---------- shell ---------- */
#app { min-height: 100%; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 12px; padding: calc(var(--sat) + 8px) 16px 8px;
  min-height: calc(var(--head-h) + var(--sat)); background: color-mix(in srgb, var(--bg) 88%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 800; font-size: 19px; letter-spacing: -.2px; text-decoration: none; color: var(--ink); }
.brand img { width: 38px; height: 32px; object-fit: contain; }
.brand i { font-style: normal; color: var(--accent); }
.pill { display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px; background: var(--primary-soft); color: var(--primary); font-weight: 700; border: 0; min-height: 36px; }
.iconbtn { width: 40px; height: 40px; border-radius: 12px; border: 1px solid var(--line); background: var(--surface); display: grid; place-items: center; font-size: 18px; }
main#view { flex: 1; width: 100%; max-width: 1180px; margin: 0 auto; padding: 16px 16px calc(var(--tab-h) + var(--sab) + 96px); }
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: flex; background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--line); padding-bottom: var(--sab);
}
.tab { flex: 1; min-height: var(--tab-h); display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 2px; border: 0; background: none; color: var(--muted); font-size: 11.5px; font-weight: 600; text-decoration: none; }
.tab .ic { font-size: 22px; line-height: 1; }
.tab.active { color: var(--primary); }
@media (min-width: 900px) {
  :root { --tab-h: 0px; }
  .tabbar { position: sticky; top: calc(var(--head-h) + var(--sat)); bottom: auto; border-top: 0; border-bottom: 1px solid var(--line); justify-content: center; z-index: 29; padding: 0; }
  .tab { flex: 0 0 auto; flex-direction: row; gap: 8px; padding: 0 22px; min-height: 48px; font-size: 14.5px; }
  .tab .ic { font-size: 18px; }
  main#view { padding-bottom: 60px; }
}

/* ---------- elements ---------- */
.card { background: var(--surface); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px; box-shadow: var(--shadow); }
.card + .card { margin-top: 14px; }
.card h2 { font-size: 17px; margin-bottom: 4px; }
.card .hint { color: var(--muted); font-size: 13.5px; margin-bottom: 12px; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 8px; min-height: 46px; padding: 0 18px; border-radius: 14px; border: 1px solid var(--line); background: var(--surface); font-weight: 650; text-decoration: none; color: var(--ink); }
.btn.primary { background: var(--grad); border-color: transparent; color: var(--primary-ink); box-shadow: 0 4px 14px color-mix(in srgb, var(--primary) 35%, transparent); }
.btn.mint { background: var(--mint); border-color: var(--mint); color: #fff; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--danger); }
.btn.sm { min-height: 36px; padding: 0 12px; border-radius: 11px; font-size: 14px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .5; pointer-events: none; }
label.lbl { display: block; font-size: 13px; font-weight: 650; color: var(--muted); margin: 0 0 6px; }
.input, textarea.input, select.input {
  width: 100%; border: 1px solid var(--line); background: var(--surface2); border-radius: 12px; padding: 12px 14px; min-height: 46px; outline: none; font-size: 16px;
}
.input:focus { border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft); }
textarea.input { resize: vertical; min-height: 110px; line-height: 1.45; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { border: 1px solid var(--line); background: var(--surface2); border-radius: 999px; padding: 8px 14px; min-height: 38px; font-size: 14px; font-weight: 600; }
.chip.on { background: var(--primary-soft); color: var(--primary); border-color: var(--primary); }
.badge { display: inline-block; font-size: 11.5px; font-weight: 700; padding: 3px 8px; border-radius: 8px; background: var(--mint-soft); color: var(--mint); }
.badge.pink { background: var(--accent-soft); color: var(--accent); }
.alert { padding: 12px 14px; border-radius: 12px; font-size: 14.5px; background: var(--warn-soft); }
.alert.err { background: var(--danger-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--danger) 40%, transparent); }
.alert.ok { background: var(--mint-soft); }
pre.raw { white-space: pre-wrap; word-break: break-word; background: var(--surface2); border: 1px dashed var(--line); border-radius: 10px; padding: 10px 12px; font: 12.5px/1.4 ui-monospace, Menlo, Consolas, monospace; margin: 8px 0 0; max-height: 220px; overflow: auto; }

/* ---------- studio ---------- */
.studio { display: grid; gap: 14px; grid-template-columns: 1fr; }
@media (min-width: 980px) { .studio { grid-template-columns: minmax(0, 1.15fr) minmax(0, 1fr); align-items: start; } .studio .side { position: sticky; top: 110px; } }
.models { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.model { text-align: left; border: 1.5px solid var(--line); background: var(--surface2); border-radius: 14px; padding: 10px 12px; display: flex; flex-direction: column; gap: 3px; min-height: 72px; }
.model.on { border-color: var(--primary); background: var(--primary-soft); }
.model b { font-size: 14px; line-height: 1.2; }
.model small { color: var(--muted); font-size: 12px; }
.mgroup { font-size: 12px; font-weight: 800; letter-spacing: .6px; text-transform: uppercase; color: var(--muted); margin: 12px 0 6px; }
.mgroup:first-child { margin-top: 0; }
.photos { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.ph { border: 1px solid var(--line); border-radius: 14px; background: var(--surface2); overflow: hidden; display: flex; flex-direction: column; }
.ph .img { position: relative; aspect-ratio: 1; background: var(--bg2); }
.ph img { width: 100%; height: 100%; object-fit: cover; display: block; }
.ph .num { position: absolute; left: 8px; top: 8px; background: rgba(0,0,0,.65); color: #fff; font-weight: 800; font-size: 12px; padding: 3px 8px; border-radius: 8px; }
.ph .acts { position: absolute; right: 6px; top: 6px; display: flex; gap: 4px; }
.ph .acts button { width: 30px; height: 30px; border-radius: 9px; border: 0; background: rgba(0,0,0,.6); color: #fff; font-size: 14px; }
.ph input { border: 0; border-top: 1px solid var(--line); background: transparent; padding: 9px 10px; font-size: 14px; outline: none; width: 100%; }
.ph input:focus { background: var(--primary-soft); }
.add { border: 2px dashed var(--line); border-radius: 14px; min-height: 150px; display: grid; place-items: center; text-align: center; color: var(--muted); background: transparent; padding: 10px; }
.add.drag { border-color: var(--primary); color: var(--primary); }
.add .plus { font-size: 30px; line-height: 1; }
.genbar { position: fixed; left: 0; right: 0; bottom: calc(var(--tab-h) + var(--sab)); z-index: 35; padding: 10px 16px; background: color-mix(in srgb, var(--bg) 92%, transparent); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px); border-top: 1px solid var(--line); }
.genbar .inner { max-width: 1180px; margin: 0 auto; display: flex; gap: 10px; align-items: center; }
.genbar .btn.primary { flex: 1; min-height: 52px; font-size: 17px; }
@media (min-width: 900px) { .genbar { bottom: 0; } }
.result { min-height: 220px; display: grid; place-items: center; text-align: center; }
.result img.out { max-width: 100%; max-height: 70vh; border-radius: 14px; display: block; margin: 0 auto; background: repeating-conic-gradient(#d9d9d9 0 25%, #fff 0 50%) 0 0 / 16px 16px; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 5px solid var(--primary-soft); border-top-color: var(--primary); animation: spin 0.9s linear infinite; margin: 0 auto 14px; }
@keyframes spin { to { transform: rotate(360deg); } }
.preview-prompt { white-space: pre-wrap; font-size: 13.5px; background: var(--surface2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 12px; max-height: 260px; overflow: auto; margin: 8px 0 0; }

/* ---------- sheets / modals ---------- */
.overlay { position: fixed; inset: 0; z-index: 80; background: rgba(20, 12, 24, .55); display: flex; align-items: flex-end; justify-content: center; }
.sheet { background: var(--surface); width: 100%; max-width: 640px; max-height: 88vh; overflow: auto; border-radius: 22px 22px 0 0; padding: 18px 16px calc(18px + var(--sab)); box-shadow: var(--shadow); }
@media (min-width: 700px) { .overlay { align-items: center; } .sheet { border-radius: 22px; } }
.sheet h2 { font-size: 19px; margin-bottom: 12px; }
.sheet .close { float: right; }
.tpl { display: flex; gap: 12px; align-items: flex-start; width: 100%; text-align: left; border: 1px solid var(--line); background: var(--surface2); border-radius: 14px; padding: 12px; margin-bottom: 8px; }
.tpl .em { font-size: 26px; line-height: 1; }
.tpl b { display: block; font-size: 15px; }
.tpl small { color: var(--muted); }
.toast { position: fixed; left: 50%; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--sab) + 90px); z-index: 99; background: #2b2430; color: #fff; padding: 11px 16px; border-radius: 12px; font-size: 14.5px; max-width: 90vw; box-shadow: var(--shadow); }

/* ---------- gallery ---------- */
.gal { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.gal button { padding: 0; border: 1px solid var(--line); border-radius: 14px; overflow: hidden; background: var(--bg2); aspect-ratio: 1; }
.gal img { width: 100%; height: 100%; object-fit: cover; display: block; }
.viewer img { max-width: 100%; max-height: 62vh; display: block; margin: 0 auto 12px; border-radius: 12px; }

/* ---------- auth ---------- */
.authwrap { max-width: 440px; margin: 4vh auto 0; }
.authwrap .logo { width: 132px; height: 106px; object-fit: contain; display: block; margin: 0 auto 8px; }
.authwrap h1 i { font-style: normal; color: var(--accent); }
.authwrap h1 { text-align: center; font-size: 26px; margin-bottom: 4px; }
.authwrap .sub { text-align: center; color: var(--muted); margin-bottom: 18px; }
.seg { display: flex; background: var(--bg2); border-radius: 12px; padding: 4px; margin-bottom: 14px; }
.seg button { flex: 1; border: 0; background: transparent; border-radius: 9px; padding: 10px; font-weight: 700; color: var(--muted); }
.seg button.on { background: var(--surface); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.field { margin-bottom: 12px; }
.check { display: flex; gap: 10px; align-items: flex-start; font-size: 14px; margin: 12px 0; }
.check input { width: 22px; height: 22px; margin-top: 1px; accent-color: var(--primary); flex: none; }
.codein { text-align: center; font-size: 28px; letter-spacing: 10px; font-weight: 800; }

/* ---------- balance ---------- */
.packs { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; }
.pack { border: 1.5px solid var(--line); border-radius: 16px; padding: 16px; background: var(--surface2); text-align: center; }
.pack.best { border-color: var(--accent); background: var(--accent-soft); }
.pack .n { font-size: 34px; font-weight: 800; line-height: 1; }
.pack .p { font-size: 20px; font-weight: 700; margin: 8px 0 2px; }
table.t { width: 100%; border-collapse: collapse; font-size: 14px; }
table.t th, table.t td { text-align: left; padding: 9px 6px; border-bottom: 1px solid var(--line); }
table.t th { color: var(--muted); font-weight: 650; font-size: 12.5px; }
.tip { display: flex; gap: 10px; align-items: center; background: var(--mint-soft); border-radius: 14px; padding: 12px 14px; font-size: 14px; margin-bottom: 14px; }
.tip button { margin-left: auto; border: 0; background: none; font-size: 18px; }
.build-grid { display: grid; gap: 12px; }
@media (min-width: 760px) { .build-grid { grid-template-columns: 1fr 1fr; } }
@media (prefers-reduced-motion: reduce) { .spinner { animation-duration: 3s; } }
