/* =========================================================================
   UnderCut AI Studio — design system
   Dark editorial · blue → violet · Sora + Inter + IBM Plex Sans Thai
   ========================================================================= */

:root {
  color-scheme: dark;
  --bg: #06070b;
  --bg-2: #090b12;
  --panel: #0d101a;
  --panel-2: #121725;
  --panel-3: #171d2d;
  --line: rgba(255, 255, 255, 0.07);
  --line-2: rgba(255, 255, 255, 0.14);
  --text: #f3f6fc;
  --text-2: #bcc4d8;
  --muted: #7f8aa3;
  --brand: #5b8cff;
  --brand-2: #8b5cf6;
  --brand-3: #22d3ee;
  --grad: linear-gradient(120deg, #3f7bf6 0%, #6d5ef0 52%, #a855f7 100%);
  --grad-soft: linear-gradient(120deg, rgba(63, 123, 246, 0.18), rgba(168, 85, 247, 0.14));
  --gold: #f5b942;
  --ok: #2fd48a;
  --warn: #f6b73c;
  --bad: #ff6b6b;
  --ok-soft: rgba(47, 212, 138, 0.13);
  --warn-soft: rgba(246, 183, 60, 0.13);
  --bad-soft: rgba(255, 107, 107, 0.13);
  --accent-soft: rgba(91, 140, 255, 0.13);
  --r-sm: 10px;
  --r-md: 14px;
  --r-lg: 20px;
  --r-xl: 28px;
  --shadow-lg: 0 30px 80px rgba(0, 0, 0, 0.55);
  --shadow-md: 0 16px 40px rgba(0, 0, 0, 0.35);
  --shadow-glow: 0 16px 44px rgba(91, 140, 255, 0.28);
  --nav-h: 54px;
  --tab-h: 64px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  --font-body: "Inter", "IBM Plex Sans Thai", system-ui, -apple-system, "Segoe UI", sans-serif;
  --font-display: "Sora", "IBM Plex Sans Thai", system-ui, sans-serif;
  --ease: cubic-bezier(0.22, 0.7, 0.24, 1);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0; padding: 0;
  background: var(--bg); color: var(--text);
  font-family: var(--font-body); font-size: 15px; line-height: 1.55;
  -webkit-font-smoothing: antialiased; text-rendering: optimizeLegibility;
  font-variant-numeric: tabular-nums;
}
body { min-height: 100vh; overflow-x: hidden; }
img { max-width: 100%; display: block; }
a { color: inherit; text-decoration: none; }
button { font-family: inherit; color: inherit; }
h1, h2, h3, h4 { font-family: var(--font-display); letter-spacing: -0.025em; line-height: 1.14; margin: 0; }
p { margin: 0; }
:focus-visible { outline: 2px solid var(--brand); outline-offset: 3px; border-radius: 6px; }
::selection { background: rgba(139, 92, 246, 0.45); color: #fff; }
code { font-family: ui-monospace, "Cascadia Code", monospace; font-size: 0.9em; background: var(--panel-3); padding: 2px 6px; border-radius: 6px; }

::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: #222a3d; border-radius: 99px; border: 2px solid var(--bg); }
::-webkit-scrollbar-track { background: transparent; }

/* ------------------------------------------------------------- ambient --- */
.ambient { position: fixed; inset: 0; z-index: 0; pointer-events: none; overflow: hidden; }
.ambient-orb { position: absolute; border-radius: 50%; filter: blur(90px); opacity: 0.55; }
.orb-a { width: 420px; height: 420px; top: -200px; left: -120px; background: radial-gradient(circle, rgba(63, 123, 246, 0.42), transparent 65%); }
.orb-b { width: 380px; height: 380px; top: -160px; right: -120px; background: radial-gradient(circle, rgba(168, 85, 247, 0.34), transparent 65%); }
.ambient-grid {
  position: absolute; inset: 0;
  background-image: linear-gradient(rgba(255,255,255,0.028) 1px, transparent 1px),
                    linear-gradient(90deg, rgba(255,255,255,0.028) 1px, transparent 1px);
  background-size: 64px 64px;
  mask-image: radial-gradient(ellipse 80% 55% at 50% 0%, #000 30%, transparent 75%);
  -webkit-mask-image: radial-gradient(ellipse 80% 55% at 50% 0%, #000 30%, transparent 75%);
}
#appRoot { position: relative; z-index: 1; }

/* ---------------------------------------------------------------- boot --- */
.boot { position: fixed; inset: 0; z-index: 200; display: grid; place-content: center; justify-items: center; gap: 18px; background: var(--bg); transition: opacity 0.35s var(--ease), visibility 0.35s; }
.boot.hide { opacity: 0; visibility: hidden; }
.boot-mark { width: 64px; height: 64px; display: grid; place-items: center; border-radius: 20px; background: var(--grad); box-shadow: 0 20px 50px rgba(91,140,255,.4); animation: pulse 1.8s var(--ease) infinite; }
.boot-text { color: var(--muted); font-size: 13.5px; letter-spacing: 0.04em; }
@keyframes pulse { 50% { transform: translateY(-5px) scale(0.98); } }

/* -------------------------------------------------------------- layout --- */
.shell { width: min(1220px, calc(100% - 48px)); margin: 0 auto; }

/* -------------------------------------------------------------- buttons --- */
.btn {
  --btn-bg: var(--panel-2);
  display: inline-flex; align-items: center; justify-content: center; gap: 9px;
  min-height: 44px; padding: 0 20px; border-radius: 12px; border: 1px solid transparent;
  font-weight: 600; font-size: 14.5px; line-height: 1; cursor: pointer;
  background: var(--btn-bg); color: var(--text);
  transition: transform 0.12s var(--ease), background 0.16s, border-color 0.16s, box-shadow 0.2s, opacity 0.16s;
  white-space: nowrap;
}
.btn:hover { transform: translateY(-1px); }
.btn:active { transform: translateY(0) scale(0.985); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: 0.45; pointer-events: none; }
.btn i { font-size: 0.95em; }
.btn-primary { background: var(--grad); color: #fff; box-shadow: var(--shadow-glow); }
.btn-primary:hover { box-shadow: 0 22px 54px rgba(91, 140, 255, 0.4); }
.btn-ghost { background: rgba(255, 255, 255, 0.04); border-color: var(--line-2); color: var(--text); }
.btn-ghost:hover { background: rgba(255, 255, 255, 0.08); }
.btn-outline { background: transparent; border-color: rgba(255, 255, 255, 0.32); color: var(--text); }
.btn-outline:hover { background: rgba(255, 255, 255, 0.1); border-color: rgba(255, 255, 255, 0.55); }
.btn-quiet { background: transparent; color: var(--text-2); padding: 0 14px; }
.btn-quiet:hover { color: var(--text); background: rgba(255,255,255,0.05); }
.btn-danger { background: rgba(255, 107, 107, 0.12); border-color: rgba(255, 107, 107, 0.4); color: #ffc9c9; }
.btn-danger:hover { background: rgba(255, 107, 107, 0.2); }
.btn-ok { background: rgba(47, 212, 138, 0.14); border-color: rgba(47, 212, 138, 0.4); color: #b6f5d8; }
.btn-lg { min-height: 54px; padding: 0 28px; font-size: 15.5px; border-radius: 14px; }
.btn-sm { min-height: 36px; padding: 0 14px; font-size: 13px; border-radius: 10px; }
.btn-block { width: 100%; }
.btn-icon { width: 42px; min-height: 42px; padding: 0; }

/* -------------------------------------------------------- typography ----- */
.grad-text { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; }
.eyebrow {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 7px 14px; border-radius: 99px; border: 1px solid var(--line-2);
  background: rgba(255, 255, 255, 0.035); color: var(--text-2);
  font-size: 11.5px; font-weight: 700; letter-spacing: 0.16em;
}
.eyebrow i { color: var(--brand); }
.kicker { display: block; font-size: 11.5px; font-weight: 700; letter-spacing: 0.2em; text-transform: uppercase; color: var(--brand); margin-bottom: 12px; }
.lede { color: var(--text-2); font-size: 17px; line-height: 1.72; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.center { text-align: center; }
.right { text-align: right; }

/* ---------------------------------------------------------------- forms --- */
.field { display: block; margin-bottom: 16px; }
.field > span { display: block; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 8px; letter-spacing: 0.01em; }
.input, .select, .textarea {
  width: 100%; min-height: 46px; padding: 11px 14px;
  border-radius: 11px; border: 1px solid var(--line-2);
  background: var(--panel-2); color: var(--text); font-family: inherit; font-size: 14.5px;
  transition: border-color 0.15s, box-shadow 0.15s, background 0.15s;
}
.input::placeholder, .textarea::placeholder { color: #5d6880; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--brand); box-shadow: 0 0 0 3px rgba(91, 140, 255, 0.18); background: var(--panel-3); }
.textarea { min-height: 106px; resize: vertical; line-height: 1.6; }
.select { appearance: none; background-image: linear-gradient(45deg, transparent 50%, var(--muted) 50%), linear-gradient(135deg, var(--muted) 50%, transparent 50%); background-position: calc(100% - 18px) 21px, calc(100% - 13px) 21px; background-size: 5px 5px, 5px 5px; background-repeat: no-repeat; }
.input-icon { position: relative; }
.input-icon i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); font-size: 13px; pointer-events: none; }
.input-icon .input { padding-left: 38px; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.form-note { font-size: 12px; color: var(--muted); margin-top: 6px; }
.error-text { display: none; margin-top: 10px; padding: 10px 13px; border-radius: 10px; background: var(--bad-soft); border: 1px solid rgba(255,107,107,.35); color: #ffc9c9; font-size: 13px; }
.error-text.show { display: block; }
.captcha-box { display: flex; align-items: center; gap: 12px; padding: 12px 14px; border-radius: 11px; border: 1px solid var(--line-2); background: var(--panel-2); }
.captcha-box .q { font-family: var(--font-display); font-weight: 600; font-size: 15px; min-width: 92px; }
.captcha-box .input { min-height: 40px; }
.captcha-box .reload { background: none; border: 0; color: var(--muted); cursor: pointer; padding: 6px; }
.captcha-box .reload:hover { color: var(--text); }

.avatar { display: grid; place-items: center; width: 38px; height: 38px; flex: none; border-radius: 50%; background: var(--grad); color: #fff; font-weight: 700; font-size: 14px; text-transform: uppercase; }
.engine-pill { display: inline-flex; align-items: center; gap: 7px; padding: 6px 12px; border-radius: 99px; border: 1px solid var(--line); background: rgba(255,255,255,.03); font-size: 11.5px; color: var(--text-2); }
.dot { width: 7px; height: 7px; border-radius: 50%; background: var(--muted); }
.dot.on { background: var(--ok); box-shadow: 0 0 0 3px var(--ok-soft); }
.dot.busy { background: var(--warn); box-shadow: 0 0 0 3px var(--warn-soft); }
.dot.off { background: var(--bad); box-shadow: 0 0 0 3px var(--bad-soft); }
.engine-pill[data-state="busy"] { border-color: rgba(246,183,60,.35); }
.engine-pill[data-state="offline"], .engine-pill[data-state="maintenance"] { border-color: rgba(255,107,107,.35); }
.credits-pill { display: inline-flex; align-items: center; gap: 8px; height: 38px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line-2); background: var(--panel-2); font-weight: 700; font-size: 13.5px; }
.credits-pill i { color: var(--gold); }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; flex-wrap: wrap; margin-bottom: 26px; }
.page-head h1 { font-size: clamp(1.5rem, 2.4vw, 2rem); font-weight: 700; margin-bottom: 6px; }
.page-head p { color: var(--muted); font-size: 13.5px; }
.page-head .actions { display: flex; gap: 10px; }
/* --------------------------------------------------------------- panels --- */
.panel { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); }
.panel-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.panel-head h2, .panel-head h3 { font-size: 14.5px; font-weight: 600; letter-spacing: -0.01em; }
.panel-head .sub { font-size: 12px; color: var(--muted); }
.panel-head .right { margin-left: auto; }
.panel-body { padding: 20px; }
.divider { height: 1px; background: var(--line); margin: 18px 0; }

/* --------------------------------------------------------------- studio --- */
.studio-grid { display: grid; grid-template-columns: minmax(0, 1fr) 372px; gap: 22px; align-items: start; }
.studio-stack { display: flex; flex-direction: column; gap: 16px; }
.step-panel { border: 1px solid var(--line); border-radius: var(--r-lg); background: var(--panel); overflow: hidden; }
.step-head { display: flex; align-items: center; gap: 12px; padding: 16px 20px; }
.step-index { display: grid; place-items: center; width: 26px; height: 26px; flex: none; border-radius: 8px; background: rgba(255,255,255,.06); border: 1px solid var(--line-2); font-size: 12px; font-weight: 700; color: var(--text-2); }
.step-panel.done .step-index { background: var(--accent-soft); border-color: rgba(91,140,255,.4); color: #9db8ff; }
.step-head h2 { font-size: 14.5px; font-weight: 600; }
.step-done-ic { color: var(--ok); font-size: 11px; margin-left: 3px; }
.step-head .hint { margin-left: auto; font-size: 11.5px; color: var(--muted); }
.step-body { padding: 0 20px 20px; }

.mode-grid { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 12px; }
.mode-tile { position: relative; display: flex; gap: 14px; align-items: flex-start; padding: 16px; border-radius: var(--r-md); border: 1px solid var(--line-2); background: var(--panel-2); cursor: pointer; text-align: left; transition: border-color .18s, background .18s, box-shadow .2s; }
.mode-tile:hover { background: var(--panel-3); }
.mode-tile.sel { border-color: rgba(91,140,255,.65); background: linear-gradient(140deg, rgba(63,123,246,.16), rgba(168,85,247,.1)), var(--panel-2); box-shadow: 0 0 0 3px rgba(91,140,255,.1); }
.mode-tile .mt-ic { display: grid; place-items: center; width: 40px; height: 40px; flex: none; border-radius: 11px; background: rgba(255,255,255,.05); color: var(--text-2); font-size: 16px; }
.mode-tile.sel .mt-ic { background: var(--grad); color: #fff; }
.mode-tile b { display: block; font-size: 14px; font-weight: 600; margin-bottom: 2px; }
.mode-tile small { display: block; font-size: 11.5px; color: var(--muted); line-height: 1.5; }
.hot-tag { display: inline-flex; align-items: center; margin-left: 6px; padding: 1px 6px; border-radius: 5px; font-size: 8.5px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; vertical-align: middle; color: #ff6b8a; background: rgba(255,107,138,.14); border: 1px solid rgba(255,107,138,.42); box-shadow: 0 0 10px rgba(255,107,138,.18); }
.mode-tile .tick { position: absolute; top: 12px; right: 12px; color: var(--brand); font-size: 12px; opacity: 0; }
.mode-tile.sel .tick { opacity: 1; }

.preset-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 12px; }
.preset-card { position: relative; padding: 0; overflow: hidden; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; text-align: left; transition: border-color .18s, transform .18s var(--ease); }
.preset-card:hover { border-color: var(--line-2); transform: translateY(-2px); }
.preset-card.sel { border-color: rgba(91,140,255,.75); box-shadow: 0 0 0 3px rgba(91,140,255,.12); }
.preset-thumb { position: relative; aspect-ratio: 4 / 3; background: linear-gradient(135deg, #1a2030, #10131d); overflow: hidden; }
.preset-thumb img { width: 100%; height: 100%; object-fit: cover; object-position: center top; transition: transform .4s var(--ease); }
.preset-card:hover .preset-thumb img { transform: scale(1.04); }
.preset-thumb .ph { position: absolute; inset: 0; display: grid; place-items: center; color: #4d5a75; font-size: 26px; }
.preset-thumb .ptag { position: absolute; left: 8px; top: 8px; font-size: 9.5px; font-weight: 700; letter-spacing: .08em; padding: 3px 7px; border-radius: 5px; background: rgba(6,7,11,.72); border: 1px solid var(--line-2); color: #cfd7e8; backdrop-filter: blur(6px); }
.preset-meta { padding: 9px 11px 10px; }
.preset-meta b { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 2px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.preset-meta small { font-size: 10.5px; color: var(--muted); }
.preset-card .tick { position: absolute; top: 8px; right: 8px; display: grid; place-items: center; width: 20px; height: 20px; border-radius: 50%; background: var(--grad); color: #fff; font-size: 9px; opacity: 0; transition: opacity .15s; }
.preset-card.sel .tick { opacity: 1; }

.dropzone { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 8px; min-height: 190px; padding: 22px; border-radius: var(--r-md); border: 1.5px dashed var(--line-2); background: linear-gradient(160deg, rgba(255,255,255,.022), transparent), var(--panel-2); cursor: pointer; text-align: center; transition: border-color .18s, background .18s; overflow: hidden; }
.dropzone:hover, .dropzone.drag { border-color: rgba(91,140,255,.6); background: rgba(91,140,255,.06); }
.dropzone .dz-ic { display: grid; place-items: center; width: 48px; height: 48px; border-radius: 14px; background: var(--accent-soft); color: var(--brand); font-size: 19px; }
.dropzone b { font-size: 14px; font-weight: 600; }
.dropzone small { font-size: 12px; color: var(--muted); }
.dropzone.has { padding: 0; border-style: solid; border-color: rgba(47,212,138,.45); min-height: 0; }
.dropzone.has img { width: 100%; max-height: 330px; object-fit: contain; background: #05060a; }
.drop-badge { position: absolute; left: 10px; bottom: 10px; display: inline-flex; align-items: center; gap: 6px; padding: 5px 11px; border-radius: 99px; background: rgba(9,11,18,.82); border: 1px solid var(--line-2); font-size: 11.5px; font-weight: 600; backdrop-filter: blur(8px); }
.drop-badge i { color: var(--ok); }
.drop-clear { position: absolute; top: 10px; right: 10px; width: 30px; height: 30px; border-radius: 50%; border: 1px solid var(--line-2); background: rgba(9,11,18,.8); color: var(--text-2); cursor: pointer; }
.drop-clear:hover { color: var(--bad); }

.custom-upload-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; align-items: start; }
.custom-upload-grid .dropzone { min-height: 230px; }
.custom-upload-grid .dropzone.has img { max-height: 260px; }
.dropzone.add-ref { font: inherit; color: var(--text-2); }

.ref-row { display: flex; gap: 14px; align-items: flex-start; }
.ref-preview { width: 118px; flex: none; aspect-ratio: 3 / 4; border-radius: 12px; overflow: hidden; border: 1px solid var(--line-2); background: var(--panel-3); }
.ref-preview img { width: 100%; height: 100%; object-fit: cover; }
.ref-info { flex: 1; min-width: 0; }
.ref-info b { display: block; font-size: 13px; margin-bottom: 3px; }
.ref-info p { font-size: 12px; color: var(--muted); line-height: 1.6; margin-bottom: 10px; }
.chips { display: flex; flex-wrap: wrap; gap: 8px; }
.chip { min-height: 36px; padding: 0 14px; border-radius: 99px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text-2); font-size: 13px; font-weight: 500; cursor: pointer; transition: all .15s var(--ease); }
.chip:hover { background: var(--panel-3); color: var(--text); }
.chip.sel { background: var(--grad); border-color: transparent; color: #fff; box-shadow: 0 6px 18px rgba(91,140,255,.26); }
.extra-group { margin-bottom: 16px; }
.extra-group:last-child { margin-bottom: 0; }
.extra-label { display: flex; align-items: center; gap: 8px; font-size: 12.5px; font-weight: 600; color: var(--text-2); margin-bottom: 9px; }
.extra-label small { font-weight: 400; color: var(--muted); font-size: 11px; }

.toggle-row { display: flex; align-items: center; gap: 14px; padding: 14px 16px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--panel-2); }
.toggle-row .tr-ic { display: grid; place-items: center; width: 38px; height: 38px; border-radius: 10px; background: rgba(168,85,247,.14); color: #b98cff; font-size: 15px; }
.toggle-row b { display: block; font-size: 13.5px; font-weight: 600; }
.toggle-row small { display: block; font-size: 11.5px; color: var(--muted); }
.switch { position: relative; margin-left: auto; width: 44px; height: 26px; flex: none; border-radius: 99px; border: 1px solid var(--line-2); background: var(--panel-3); cursor: pointer; transition: background .2s, border-color .2s; }
.switch::after { content: ""; position: absolute; top: 3px; left: 3px; width: 18px; height: 18px; border-radius: 50%; background: #8b96ad; transition: transform .2s var(--ease), background .2s; }
.switch.on { background: linear-gradient(100deg, #3f7bf6, #8b5cf6); border-color: transparent; }
.switch.on::after { transform: translateX(18px); background: #fff; }

/* summary */
.summary { position: sticky; top: 90px; border: 1px solid var(--line); border-radius: var(--r-lg); background: linear-gradient(170deg, var(--panel-2), var(--panel)); overflow: hidden; }
.summary-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--line); }
.summary-head b { font-size: 14px; font-weight: 600; }
.summary-body { padding: 18px 20px; }
.thumb-pair { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; margin-bottom: 16px; }
.thumb-pair figure { margin: 0; }
.thumb-pair figure:only-child { grid-column: 1 / -1; }
.thumb-box { aspect-ratio: 3 / 4; border-radius: 12px; border: 1px solid var(--line); background: var(--panel-3); overflow: hidden; display: grid; place-items: center; color: #495569; font-size: 20px; position: relative; }
.thumb-box img { width: 100%; height: 100%; object-fit: cover; object-position: center top; }
.thumb-box .tb-tag { position: absolute; left: 6px; bottom: 6px; font-size: 9.5px; font-weight: 700; letter-spacing: .06em; padding: 2px 6px; border-radius: 4px; background: rgba(6,7,11,.75); border: 1px solid var(--line); }
.thumb-pair figcaption { margin-top: 6px; font-size: 11px; color: var(--muted); }
.summary-list { display: flex; flex-direction: column; gap: 9px; }
.summary-row { display: flex; align-items: baseline; justify-content: space-between; gap: 14px; font-size: 12.5px; }
.summary-row span { color: var(--muted); }
.summary-row b { font-weight: 600; text-align: right; }
.summary-total { display: flex; align-items: center; justify-content: space-between; margin-top: 16px; padding-top: 14px; border-top: 1px dashed var(--line-2); }
.summary-total span { font-size: 12.5px; color: var(--muted); }
.summary-total b { display: inline-flex; align-items: center; gap: 7px; font-family: var(--font-display); font-size: 20px; font-weight: 700; }
.summary-total i { color: var(--gold); }
.summary-foot { padding: 0 20px 18px; }
.summary-foot .btn { width: 100%; }
.summary-foot .note { margin-top: 10px; text-align: center; font-size: 11.5px; color: var(--muted); }
.summary-alert { margin: 16px 0 12px; padding: 10px 12px; border-radius: 10px; font-size: 12px; display: none; }
.summary-alert.show { display: block; }
.summary-alert.warn { background: var(--warn-soft); border: 1px solid rgba(246,183,60,.35); color: #ffe0aa; }

/* ------------------------------------------------------------- job view --- */
.job-view { max-width: 980px; margin: 0 auto; }
.job-card { border: 1px solid var(--line); border-radius: var(--r-xl); background: var(--panel); overflow: hidden; }
.job-state { padding: 30px; display: flex; flex-direction: column; gap: 18px; }
.job-state-top { display: flex; align-items: center; gap: 16px; }
.spinner { width: 34px; height: 34px; flex: none; border-radius: 50%; border: 2.5px solid var(--panel-3); border-top-color: var(--brand); animation: spin .9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.job-state-top b { display: block; font-family: var(--font-display); font-size: 19px; font-weight: 600; }
.job-state-top small { font-size: 12.5px; color: var(--muted); }
.job-pct { margin-left: auto; font-family: var(--font-display); font-size: 26px; font-weight: 700; color: var(--brand); }
.progress { height: 8px; border-radius: 99px; background: var(--panel-3); overflow: hidden; }
.progress > i { display: block; height: 100%; width: 0%; border-radius: 99px; background: var(--grad); transition: width .4s var(--ease); }
.job-meta { display: flex; flex-wrap: wrap; gap: 10px 26px; font-size: 12px; color: var(--muted); }
.job-meta b { color: var(--text-2); font-weight: 600; }
.job-timeline { display: flex; gap: 0; border-top: 1px solid var(--line); }
.job-timeline .jt { flex: 1; padding: 14px 18px; border-right: 1px solid var(--line); font-size: 11.5px; color: var(--muted); }
.job-timeline .jt:last-child { border-right: 0; }
.job-timeline .jt.on { color: var(--text); background: rgba(91,140,255,.06); }
.job-timeline .jt b { display: block; font-size: 12px; color: inherit; margin-bottom: 2px; }
.result-stage { position: relative; display: grid; place-items: center; min-height: 320px; background: radial-gradient(circle at 50% 40%, rgba(63,123,246,.12), transparent 65%), #05060a; }
.result-stage img { max-height: 72vh; width: auto; max-width: 100%; object-fit: contain; }
.result-actions { display: flex; flex-wrap: wrap; gap: 10px; padding: 18px 20px; border-top: 1px solid var(--line); }
.result-actions .spacer { flex: 1; }
.result-fail { padding: 34px; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.result-fail .rf-ic { display: grid; place-items: center; width: 56px; height: 56px; border-radius: 50%; background: var(--bad-soft); color: var(--bad); font-size: 22px; }
.result-fail p { font-size: 13px; color: var(--muted); max-width: 46ch; }

/* -------------------------------------------------------------- history --- */
.filter-row { display: flex; flex-wrap: wrap; gap: 8px; margin-bottom: 20px; }
.history-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.hist-card { position: relative; border-radius: var(--r-md); overflow: hidden; border: 1px solid var(--line); background: var(--panel); cursor: pointer; transition: border-color .18s, transform .2s var(--ease); }
.hist-card:hover { border-color: var(--line-2); transform: translateY(-2px); }
.hist-thumb { position: relative; aspect-ratio: 3 / 4; background: var(--panel-3); display: grid; place-items: center; color: #4b566b; overflow: hidden; }
.hist-thumb img { width: 100%; height: 100%; object-fit: cover; }
.hist-thumb .badge-float { position: absolute; top: 8px; left: 8px; }
.hist-meta { padding: 10px 12px; display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.hist-meta b { display: block; font-size: 12.5px; font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.hist-meta small { font-size: 10.5px; color: var(--muted); }
.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 99px; font-size: 10.5px; font-weight: 700; border: 1px solid var(--line); background: rgba(255,255,255,.04); color: var(--text-2); white-space: nowrap; }
.badge.ok { color: var(--ok); background: var(--ok-soft); border-color: rgba(47,212,138,.3); }
.badge.run { color: #9db8ff; background: var(--accent-soft); border-color: rgba(91,140,255,.3); }
.badge.bad { color: #ffb3b3; background: var(--bad-soft); border-color: rgba(255,107,107,.3); }
.badge.warn { color: #ffd68a; background: var(--warn-soft); border-color: rgba(246,183,60,.3); }

/* -------------------------------------------------------------- credits --- */
.credits-layout { display: grid; grid-template-columns: minmax(0, 1.35fr) minmax(0, 1fr); gap: 22px; align-items: start; }
.pkg-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px; }
.pkg-card { position: relative; padding: 18px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--panel-2); cursor: pointer; text-align: left; transition: border-color .18s, background .18s, transform .18s var(--ease); }
.pkg-card:hover { transform: translateY(-2px); border-color: var(--line-2); }
.pkg-card.sel { border-color: rgba(91,140,255,.7); background: linear-gradient(150deg, rgba(63,123,246,.14), rgba(168,85,247,.08)), var(--panel-2); box-shadow: 0 0 0 3px rgba(91,140,255,.1); }
.pkg-card b { display: flex; align-items: baseline; gap: 6px; font-family: var(--font-display); font-size: 24px; font-weight: 700; }
.pkg-card b span { font-family: var(--font-body); font-size: 11.5px; font-weight: 500; color: var(--muted); }
.pkg-card .thb { font-size: 13px; color: var(--gold); font-weight: 600; margin-top: 4px; }
.pkg-card small { display: block; font-size: 11px; color: var(--muted); margin-top: 2px; }
.stepper-row { display: flex; align-items: center; gap: 10px; margin-top: 14px; }
.stepper { display: flex; align-items: center; gap: 0; border: 1px solid var(--line-2); border-radius: 11px; overflow: hidden; background: var(--panel-2); }
.stepper button { width: 40px; height: 44px; border: 0; background: transparent; color: var(--text-2); font-size: 16px; cursor: pointer; }
.stepper button:hover { background: rgba(255,255,255,.06); color: var(--text); }
.stepper input { width: 86px; height: 44px; border: 0; border-left: 1px solid var(--line); border-right: 1px solid var(--line); background: transparent; color: var(--text); text-align: center; font-family: var(--font-display); font-size: 16px; font-weight: 600; -moz-appearance: textfield; }
.stepper input::-webkit-outer-spin-button, .stepper input::-webkit-inner-spin-button { -webkit-appearance: none; }
.pay-summary { display: flex; align-items: baseline; justify-content: space-between; padding: 14px 0 0; margin-top: 14px; border-top: 1px dashed var(--line-2); font-size: 13px; color: var(--muted); }
.pay-summary b { font-family: var(--font-display); font-size: 22px; color: var(--text); }
.qr-box { display: grid; place-items: center; padding: 16px; border-radius: var(--r-md); background: #fff; width: 232px; margin: 0 auto; }
.qr-box img { width: 100%; }
.pay-steps { display: flex; flex-direction: column; gap: 10px; margin: 18px 0; }
.pay-step { display: flex; gap: 12px; font-size: 12.5px; color: var(--text-2); }
.pay-step .n { display: grid; place-items: center; width: 22px; height: 22px; flex: none; border-radius: 50%; background: rgba(255,255,255,.06); border: 1px solid var(--line-2); font-size: 10.5px; font-weight: 700; }
.upload-slip { border: 1.5px dashed var(--line-2); border-radius: var(--r-md); padding: 16px; display: flex; align-items: center; gap: 12px; cursor: pointer; background: var(--panel-2); transition: border-color .18s; }
.upload-slip:hover { border-color: rgba(91,140,255,.5); }
.upload-slip i { color: var(--brand); font-size: 17px; }
.upload-slip b { display: block; font-size: 13px; }
.upload-slip small { font-size: 11px; color: var(--muted); }

/* ---------------------------------------------------------------- table --- */
.table-wrap { overflow-x: auto; border-radius: var(--r-md); }
table.table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 560px; }
.table th { text-align: left; padding: 11px 14px; color: var(--muted); font-weight: 600; font-size: 11px; letter-spacing: .05em; text-transform: uppercase; border-bottom: 1px solid var(--line); white-space: nowrap; }
.table td { padding: 12px 14px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tr:hover td { background: rgba(255,255,255,.02); }
.table .cell-user b { display: block; }
.table .cell-user small { color: var(--muted); font-size: 11px; }
.table-actions { display: flex; gap: 6px; justify-content: flex-end; }
.tiny-input { width: 82px; min-height: 32px; padding: 5px 8px; font-size: 12.5px; border-radius: 8px; border: 1px solid var(--line-2); background: var(--panel-3); color: var(--text); }

/* ---------------------------------------------------------------- admin --- */
.admin-tabs { display: flex; gap: 4px; padding: 4px; border-radius: 12px; border: 1px solid var(--line); background: var(--panel); margin-bottom: 20px; overflow-x: auto; }
.admin-tabs button { flex: none; min-height: 36px; padding: 0 14px; border: 0; border-radius: 9px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 600; cursor: pointer; }
.admin-tabs button:hover { color: var(--text); }
.admin-tabs button.active { background: var(--panel-3); color: var(--text); }
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { padding: 18px; border-radius: var(--r-md); border: 1px solid var(--line); background: var(--panel); }
.stat-card small { display: flex; align-items: center; gap: 7px; font-size: 11.5px; color: var(--muted); }
.stat-card small i { color: var(--brand); }
.stat-card b { display: block; font-family: var(--font-display); font-size: 26px; font-weight: 700; margin-top: 6px; }
.admin-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); gap: 16px; }
.extra-editor { border: 1px solid var(--line); border-radius: var(--r-md); padding: 16px; background: var(--panel-2); margin-bottom: 12px; }
.extra-editor h4 { font-size: 13px; margin-bottom: 10px; display: flex; gap: 8px; align-items: center; }
.extra-editor .opt-row { display: grid; grid-template-columns: 90px 1fr 1fr; gap: 8px; margin-bottom: 8px; }
.extra-editor .opt-row.prompt-only { grid-template-columns: 90px 90px 1fr; }
.slip-thumb { width: 46px; height: 46px; object-fit: cover; border-radius: 7px; border: 1px solid var(--line-2); cursor: zoom-in; background: var(--panel-3); }

/* ---------------------------------------------------------------- modal --- */
.modal-back { position: fixed; inset: 0; z-index: 120; display: grid; place-items: center; padding: 20px; background: rgba(3, 4, 8, 0.78); backdrop-filter: blur(8px); animation: fadeIn .18s var(--ease); }
.modal { width: min(560px, 100%); max-height: 90vh; overflow: auto; border-radius: var(--r-lg); border: 1px solid var(--line-2); background: var(--panel); box-shadow: var(--shadow-lg); animation: rise .22s var(--ease); }
.modal.wide { width: min(860px, 100%); }
.modal-head { display: flex; align-items: center; gap: 12px; padding: 18px 20px; border-bottom: 1px solid var(--line); position: sticky; top: 0; background: var(--panel); z-index: 2; }
.modal-head b { font-family: var(--font-display); font-size: 15px; font-weight: 600; }
.modal-head .close { margin-left: auto; width: 34px; height: 34px; border-radius: 9px; border: 1px solid var(--line-2); background: transparent; color: var(--text-2); cursor: pointer; }
.modal-head .close:hover { color: var(--text); background: rgba(255,255,255,.06); }
.modal-body { padding: 20px; }
.modal-img { background: #000; display: grid; place-items: center; }
.modal-img img { max-height: 72vh; width: auto; max-width: 100%; }
@keyframes fadeIn { from { opacity: 0; } }
@keyframes rise { from { opacity: 0; transform: translateY(10px); } }

/* ---------------------------------------------------------------- toast --- */
.toast { position: fixed; left: 50%; bottom: 26px; z-index: 150; transform: translateX(-50%); display: flex; align-items: center; gap: 10px; max-width: min(90vw, 460px); padding: 12px 18px; border-radius: 12px; background: #10141f; border: 1px solid var(--line-2); box-shadow: var(--shadow-md); font-size: 13.5px; font-weight: 500; animation: toastIn .22s var(--ease); }
.toast i { color: var(--ok); }
.toast.err { border-color: rgba(255,107,107,.5); }
.toast.err i { color: var(--bad); }
.toast[hidden] { display: none; }
@keyframes toastIn { from { opacity: 0; transform: translate(-50%, 10px); } }

/* --------------------------------------------------------------- empty --- */
.empty { display: flex; flex-direction: column; align-items: center; gap: 10px; padding: 48px 24px; text-align: center; border: 1px dashed var(--line-2); border-radius: var(--r-lg); color: var(--muted); }
.empty i { font-size: 26px; color: #4b566b; }
.empty b { color: var(--text-2); font-size: 14px; font-weight: 600; }
.empty small { font-size: 12.5px; max-width: 40ch; }

/* --------------------------------------------------------------- prompt --- */
.prompt-count { display: flex; justify-content: space-between; gap: 10px; margin-top: 6px; font-size: 11px; color: var(--muted); }

/* ---------------------------------------------------------------- legal --- */
.legal-box { display: grid; gap: 10px; margin: 4px 0 14px; padding: 14px 16px; border: 1px solid var(--line-2); border-radius: 14px; background: var(--panel-2); }
.legal-check { display: flex; gap: 10px; align-items: flex-start; font-size: 13px; color: var(--text-2); line-height: 1.55; cursor: pointer; }
.legal-check input { flex: none; width: 16px; height: 16px; margin-top: 2px; accent-color: var(--brand); }
.legal-check a { color: #cfe0ff; text-decoration: underline; text-underline-offset: 2px; margin: 0 3px; }
.legal-scroll { max-height: min(58vh, 520px); overflow: auto; white-space: pre-wrap; font-size: 14px; line-height: 1.7; color: var(--text-2); padding-right: 6px; }
.legal-foot { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-top: 16px; padding-top: 14px; border-top: 1px solid var(--line); }
.legal-foot-actions { display: flex; gap: 8px; }
.consent-bar { position: fixed; left: 50%; bottom: calc(16px + env(safe-area-inset-bottom)); transform: translateX(-50%); z-index: 80; width: min(calc(100% - 24px), 880px); padding: 14px 18px; border-radius: 16px; border: 1px solid var(--line-2); background: rgba(10,12,19,.96); backdrop-filter: saturate(160%) blur(18px); box-shadow: var(--shadow-md); }
.consent-inner { display: flex; align-items: center; justify-content: space-between; gap: 16px; flex-wrap: wrap; }
.consent-inner p { margin: 0; font-size: 13px; color: var(--text-2); flex: 1 1 320px; }
.consent-inner p i { color: var(--brand-3); margin-right: 6px; }
.consent-inner a { color: #cfe0ff; text-decoration: underline; }
.consent-actions { display: flex; gap: 8px; flex: 0 0 auto; }

/* ---- rewards (daily gift, referral) ---- */
.rewards-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 16px; margin-bottom: 22px; }
.reward-card { display: flex; align-items: center; gap: 16px; padding: 18px 20px; flex-wrap: wrap; }
.reward-ic { width: 46px; height: 46px; border-radius: 14px; display: grid; place-items: center; font-size: 19px; color: var(--gold); background: var(--grad-soft); flex: none; }
.reward-main { flex: 1; min-width: 200px; }
.reward-main h2 { font-size: 16px; margin-bottom: 4px; }
.reward-act { display: flex; flex-direction: column; align-items: center; gap: 6px; min-width: 150px; }
.reward-act .btn { min-width: 150px; font-variant-numeric: tabular-nums; }
.ref-row { display: flex; gap: 8px; margin: 10px 0 6px; }
.ref-row .input { flex: 1; min-width: 0; font-size: 12.5px; }
.ref-note { margin: 0 0 14px; padding: 10px 12px; border-radius: var(--r-sm); background: var(--accent-soft); color: var(--text-2); font-size: 13px; }
.ref-note i { color: var(--gold); margin-right: 6px; }
.hide { display: none !important; }


/* =========================================================================
   MOBILE-FIRST LAYER — Telegram Mini App (single column, bottom tab bar)
   ========================================================================= */
html, body { overscroll-behavior-y: none; }
body { min-height: 100dvh; padding: 0; }
input, textarea, select { font-size: 16px !important; }              /* no iOS zoom on focus */
.btn { min-height: 46px; border-radius: 14px; }
.btn-sm { min-height: 38px; }
.btn-lg { min-height: 52px; font-size: 16px; }

/* --- top bar --- */
.app-topbar {
  position: sticky; top: 0; z-index: 40; display: flex; align-items: center; gap: 10px;
  height: calc(var(--nav-h) + var(--safe-t)); padding: var(--safe-t) 14px 0;
  background: rgba(9, 11, 18, .86); backdrop-filter: saturate(160%) blur(16px);
  border-bottom: 1px solid var(--line);
}
.brand { display: flex; align-items: center; gap: 9px; font-family: var(--font-display); font-weight: 700; font-size: 16px; }
.brand img { border-radius: 9px; }
.topbar-actions { display: flex; align-items: center; gap: 8px; margin-left: auto; }
.engine-pill { width: 30px; height: 30px; padding: 0; justify-content: center; }
.credits-pill { height: 34px; padding: 0 12px; font-weight: 700; font-size: 14px; }

/* --- page --- */
.app-main { width: 100%; max-width: 560px; margin: 0 auto; padding: 14px 14px calc(var(--tab-h) + var(--safe-b) + 22px); }
.page-head { margin: 4px 0 14px; }
.page-head h1 { font-size: 22px; margin: 0; }
.page-head p { display: none; }
.page-head .actions { width: 100%; }
.center { text-align: center; }

/* --- bottom tab bar --- */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 50; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + var(--safe-b)); padding: 6px 8px var(--safe-b);
  background: rgba(12, 14, 22, .94); backdrop-filter: saturate(160%) blur(18px); border-top: 1px solid var(--line);
}
.tabbar a { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--muted); font-size: 10.5px; font-weight: 600; letter-spacing: .02em; border-radius: 14px; transition: color .15s; }
.tabbar a i { font-size: 19px; transition: transform .2s var(--ease); }
.tabbar a.active { color: #fff; }
.tabbar a.active i { background: var(--grad); -webkit-background-clip: text; background-clip: text; color: transparent; transform: translateY(-1px) scale(1.08); }
.tabbar a.active::before { content: ""; position: absolute; top: -7px; width: 26px; height: 3px; border-radius: 0 0 4px 4px; background: var(--grad); }

/* --- full-screen gates (consent, errors) --- */
.gate { min-height: 100dvh; display: grid; place-items: center; padding: 22px; }
.gate-card { width: min(420px, 100%); text-align: center; display: flex; flex-direction: column; gap: 14px; padding: 30px 22px; border: 1px solid var(--line); border-radius: 26px; background: linear-gradient(170deg, var(--panel-2), var(--panel)); box-shadow: var(--shadow-md); }
.gate-logo { margin: 0 auto 4px; border-radius: 20px; box-shadow: var(--shadow-glow); }
.gate-card h1 { font-size: 24px; }
.gate-card p { color: var(--text-2); font-size: 14px; }
.gate .legal-box { text-align: left; margin: 4px 0; }
.error-text { display: none; color: #ff9d9d; font-size: 13px; }
.error-text.show { display: block; }

/* --- cards / panels --- */
.panel, .step-panel { border-radius: 20px; }
.panel + .panel, .stat-grid + .panel, .profile-card + .stat-grid { margin-top: 14px; }
.panel-head, .step-head { padding: 14px 16px; }
.panel-body { padding: 16px; }
.step-body { padding: 0 16px 16px; }
.step-head .hint { font-size: 11px; }
.profile-card { display: flex; align-items: center; gap: 14px; padding: 18px; border-radius: 22px; border: 1px solid var(--line); background: radial-gradient(120% 140% at 0% 0%, rgba(63,123,246,.2), transparent 60%), var(--panel); margin-bottom: 14px; }
.avatar.xl { width: 58px; height: 58px; font-size: 22px; }
.pc-info { min-width: 0; flex: 1; }
.pc-info b { display: block; font-family: var(--font-display); font-size: 17px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pc-info small { color: var(--muted); font-size: 12.5px; }
.menu-list { display: flex; flex-direction: column; }
.menu-item { display: flex; align-items: center; gap: 14px; width: 100%; min-height: 54px; padding: 0 16px; background: none; border: 0; border-bottom: 1px solid var(--line); color: var(--text); font-size: 15px; font-weight: 500; text-align: left; cursor: pointer; }
.menu-item:last-child { border-bottom: 0; }
.menu-item > i:first-child { width: 22px; text-align: center; color: var(--brand); }
.menu-item > span { flex: 1; }
.menu-item > i:last-child { color: var(--muted); font-size: 12px; }

/* --- studio: one column, big touch targets --- */
.studio-grid { display: flex; flex-direction: column; gap: 14px; max-width: none; }
.studio-stack { gap: 14px; }
#studioSummary { align-self: auto; }
.mode-grid { grid-template-columns: 1fr; gap: 10px; }
.mode-tile { padding: 14px; align-items: center; }
.mode-tile .tick { top: 50%; transform: translateY(-50%); }
.preset-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.preset-grid.portrait .preset-thumb { aspect-ratio: 3 / 4; }
.preset-card:hover { transform: none; }
.extras-grid { display: flex !important; flex-direction: column !important; flex-wrap: nowrap; gap: 10px; }
.extras-grid .extra-group { display: block; width: 100%; min-width: 0; padding: 12px 14px; flex: none; }
.extras-grid .extra-label { flex-direction: row; align-items: baseline; gap: 6px; margin: 0 0 9px; }
.extras-grid .extra-label i { display: none; }
.chips { gap: 8px; }
.chip { min-height: 40px; padding: 0 16px; }
.dropzone { min-height: 190px; }
.summary { position: static; border-radius: 20px; overflow: visible; }
.summary-head { border-radius: 20px 20px 0 0; }
.summary-body { padding: 16px; }
.summary-body .thumb-pair { max-width: none; }
.thumb-pair { gap: 10px; }
.summary-foot {
  position: sticky; bottom: calc(var(--tab-h) + var(--safe-b) + 8px); z-index: 20; padding: 12px 16px 14px;
  background: linear-gradient(0deg, var(--panel) 70%, rgba(13,16,26,0)); border-radius: 0 0 20px 20px;
}

/* --- history / credits / admin --- */
.history-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.credits-layout { display: flex; flex-direction: column; gap: 14px; max-width: none; }
.credits-layout > .panel { display: block; }
.stat-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; margin-bottom: 14px; }
.pkg-grid { grid-template-columns: 1fr; gap: 10px; }
.table-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; }
.table th, .table td { white-space: nowrap; }
.admin-tabs { display: flex; gap: 8px; overflow-x: auto; margin: 0 -14px 14px; padding: 0 14px; scrollbar-width: none; }
.admin-tabs::-webkit-scrollbar { display: none; }
.admin-tabs button { flex: none; }
.admin-grid, .form-row, .custom-upload-grid { grid-template-columns: 1fr !important; }

/* --- bottom-sheet modal --- */
.modal-back { align-items: flex-end !important; justify-content: center; padding: 0 !important; }
.modal, .modal.wide { width: 100%; max-width: 560px; max-height: 92dvh; border-radius: 24px 24px 0 0; padding-bottom: var(--safe-b); animation: sheetUp .28s var(--ease); }
.modal-body { overflow-y: auto; -webkit-overflow-scrolling: touch; }
@keyframes sheetUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

/* --- toast above the tab bar --- */
#toast { left: 50%; right: auto; transform: translateX(-50%); bottom: calc(var(--tab-h) + var(--safe-b) + 16px); max-width: calc(100% - 28px); }
.boot { background: var(--bg); }

/* --- refinements after on-device preview --- */
.mode-tile { padding: 12px 14px; gap: 12px; }
.mode-tile .mt-ic { width: 38px; height: 38px; }
.mode-tile small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; font-size: 12px; }
.mode-tile b { font-size: 15px; }
.summary-body .thumb-pair { max-width: 250px; }
.summary-foot { background: var(--panel); border-top: 1px solid var(--line-2); box-shadow: 0 -14px 24px rgba(6, 7, 11, .55); }
.summary-foot .note { font-size: 11.5px; }
.summary-alert { font-size: 13px; }
.credits-layout { align-items: stretch !important; }
.credits-layout > .panel { width: 100%; }
.page-head .actions { display: none; }
.rewards-grid { grid-template-columns: 1fr !important; gap: 12px; margin-bottom: 14px; }
.reward-card { border-radius: 20px; }
.filter-row { display: flex !important; flex-wrap: nowrap !important; overflow-x: auto; gap: 8px; margin: 0 -14px 14px; padding: 0 14px; scrollbar-width: none; }
.filter-row::-webkit-scrollbar { display: none; }
.filter-row .chip { flex: none; white-space: nowrap; }

/* --- never wider than the screen --- */
html, body { width: 100%; max-width: 100%; overflow-x: hidden; }
#appRoot, .app-main, .panel, .step-panel, .summary, .studio-grid, .studio-stack { max-width: 100%; min-width: 0; }
.app-main > *, .panel *, .step-panel *, .summary * { min-width: 0; }
img, video, canvas, svg { max-width: 100%; }
.panel-body, .step-body, .summary-body { overflow-wrap: anywhere; }
.ref-row { display: flex; gap: 8px; } .ref-row .input { flex: 1; min-width: 0; }
.table-wrap { max-width: 100%; }

/* =========================================================================
   POLISH v2 — native-app feel: floating tab bar, softer depth, motion
   ========================================================================= */
:root {
  --bg: #07080d; --panel: #10131d; --panel-2: #161a27; --panel-3: #1c2132;
  --line: rgba(255,255,255,.06); --line-2: rgba(255,255,255,.11);
  --grad: linear-gradient(135deg, #4f7cff 0%, #7a5cff 50%, #b25cff 100%);
  --tab-h: 62px; --gap: 14px;
  --card-bg: linear-gradient(180deg, rgba(255,255,255,.028), rgba(255,255,255,0) 40%), var(--panel);
  --card-shadow: 0 1px 0 rgba(255,255,255,.04) inset, 0 10px 30px rgba(0,0,0,.28);
}
body { background: radial-gradient(120% 60% at 50% -10%, rgba(91,110,255,.14), transparent 60%), var(--bg); -webkit-tap-highlight-color: transparent; }
.ambient { opacity: .6; }
::selection { background: rgba(122,92,255,.35); }

/* top bar: clean, no hard line */
.app-topbar { background: linear-gradient(180deg, rgba(7,8,13,.92), rgba(7,8,13,.72)); border-bottom: 0; box-shadow: 0 1px 0 var(--line); padding-left: 16px; padding-right: 16px; }
.brand b { font-size: 17px; letter-spacing: -.02em; }
.brand img { width: 30px; height: 30px; border-radius: 10px; box-shadow: 0 6px 16px rgba(91,110,255,.35); }
.credits-pill { height: 34px; border: 0; background: linear-gradient(135deg, rgba(245,185,66,.18), rgba(245,185,66,.06)); box-shadow: inset 0 0 0 1px rgba(245,185,66,.28); color: #ffe2a3; }
.credits-pill i { filter: drop-shadow(0 0 6px rgba(245,185,66,.5)); }
.engine-pill { width: 34px; height: 34px; border-radius: 50%; background: var(--panel-2); border: 1px solid var(--line-2); display: grid; place-items: center; }

/* page */
.app-main { padding: 16px 16px calc(var(--tab-h) + var(--safe-b) + 34px); animation: pageIn .32s var(--ease) both; }
@keyframes pageIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }
.page-head { margin: 2px 2px 16px; }
.page-head h1 { font-size: 26px; font-weight: 700; letter-spacing: -.035em; }

/* floating glass tab bar */
.tabbar {
  left: 12px; right: 12px; bottom: calc(10px + var(--safe-b)); height: var(--tab-h); padding: 6px;
  border-radius: 22px; border: 1px solid var(--line-2);
  background: rgba(18,21,32,.78); backdrop-filter: saturate(180%) blur(22px); -webkit-backdrop-filter: saturate(180%) blur(22px);
  box-shadow: 0 18px 40px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.05);
  max-width: 536px; margin: 0 auto; gap: 4px;
}
.tabbar a { border-radius: 16px; font-size: 10.5px; gap: 2px; transition: color .2s, background .25s var(--ease); }
.tabbar a:active { transform: scale(.94); }
.tabbar a.active { background: linear-gradient(135deg, rgba(79,124,255,.22), rgba(178,92,255,.16)); box-shadow: inset 0 0 0 1px rgba(122,92,255,.28); }
.tabbar a.active::before { display: none; }
.tabbar a.active i { transform: translateY(-1px); }
#toast { bottom: calc(var(--tab-h) + var(--safe-b) + 24px); }
.summary-foot { bottom: calc(var(--tab-h) + var(--safe-b) + 18px); }

/* cards */
.panel, .step-panel, .summary, .reward-card, .profile-card, .stat-card, .extras-grid .extra-group {
  background: var(--card-bg); border: 1px solid var(--line); box-shadow: var(--card-shadow);
}
.panel, .step-panel, .summary { border-radius: 22px; }
.studio-stack, .studio-grid, .credits-layout { gap: var(--gap); }
.step-head { padding: 16px 16px 12px; }
.step-head h2, .panel-head h2, .panel-head h3 { font-size: 15.5px; font-weight: 650; letter-spacing: -.015em; }
.step-index { width: 28px; height: 28px; border-radius: 10px; font-size: 12.5px; background: var(--panel-3); }
.step-panel.done .step-index { background: var(--grad); color: #fff; border-color: transparent; box-shadow: 0 6px 14px rgba(91,110,255,.35); }
.panel-head { border-bottom-color: var(--line); }

/* selectable tiles */
.mode-tile, .preset-card { border-radius: 18px; border-color: var(--line-2); background: var(--panel-2); transition: transform .15s var(--ease), border-color .2s, box-shadow .2s, background .2s; }
.mode-tile:active, .preset-card:active, .chip:active, .menu-item:active { transform: scale(.98); }
.mode-tile .mt-ic { width: 42px; height: 42px; border-radius: 13px; }
.mode-tile.sel, .preset-card.sel { border-color: rgba(122,92,255,.7); box-shadow: 0 0 0 3px rgba(122,92,255,.14), 0 12px 28px rgba(60,50,160,.22); }
.preset-card .tick { width: 22px; height: 22px; font-size: 10px; box-shadow: 0 4px 10px rgba(0,0,0,.35); }
.preset-thumb img { transition: transform .4s var(--ease); }
.chip { border-color: var(--line-2); background: var(--panel-2); font-weight: 550; }
.chip.sel { box-shadow: 0 8px 20px rgba(91,110,255,.3); }
.extras-grid .extra-group { border-radius: 18px; }

/* buttons */
.btn { font-weight: 650; letter-spacing: -.005em; transition: transform .12s var(--ease), box-shadow .2s, opacity .2s; }
.btn:active:not(:disabled) { transform: scale(.97); }
.btn-primary { background: var(--grad); box-shadow: 0 10px 26px rgba(91,100,255,.38), inset 0 1px 0 rgba(255,255,255,.18); }
.btn-primary:disabled { box-shadow: none; filter: saturate(.4); opacity: .55; }
.btn-ghost { background: var(--panel-2); border: 1px solid var(--line-2); }

/* inputs */
.input, .textarea, select.input { background: var(--panel-2); border: 1px solid var(--line-2); border-radius: 14px; transition: border-color .2s, box-shadow .2s; }
.input:focus, .textarea:focus { border-color: rgba(122,92,255,.7); box-shadow: 0 0 0 3px rgba(122,92,255,.15); outline: none; }
.dropzone { border-radius: 18px; border: 1.5px dashed rgba(255,255,255,.14); background: rgba(255,255,255,.02); }

/* summary sticky footer */
.summary-foot { border-radius: 0 0 22px 22px; background: rgba(16,19,29,.96); backdrop-filter: blur(12px); }
.summary-total b, .summary-total strong { font-size: 18px; }

/* account */
.profile-card { border-radius: 24px; padding: 20px; background: radial-gradient(120% 160% at 0% 0%, rgba(79,124,255,.28), transparent 55%), radial-gradient(100% 120% at 100% 100%, rgba(178,92,255,.18), transparent 55%), var(--panel); }
.avatar.xl { box-shadow: 0 0 0 3px rgba(255,255,255,.08), 0 10px 24px rgba(0,0,0,.35); }
.menu-list { border-radius: 20px; overflow: hidden; }
.menu-item { min-height: 56px; transition: background .15s; }
.menu-item:active { background: rgba(255,255,255,.03); }
.menu-item > i:first-child { display: grid; place-items: center; width: 34px; height: 34px; border-radius: 11px; background: var(--accent-soft); font-size: 14px; }
.stat-grid { gap: 10px; }
.stat-card { border-radius: 18px; }

/* history */
.history-grid { gap: 12px; }
.history-grid > * { border-radius: 18px; overflow: hidden; }

/* credits packages */
.pkg-grid > * { border-radius: 18px; transition: transform .15s var(--ease), border-color .2s, box-shadow .2s; }
.pkg-grid > *:active { transform: scale(.98); }

/* consent gate */
.gate { background: radial-gradient(90% 50% at 50% 0%, rgba(91,110,255,.22), transparent 70%); }
.gate-card { border-radius: 28px; padding: 32px 22px 24px; background: var(--card-bg); box-shadow: 0 30px 70px rgba(0,0,0,.5), inset 0 1px 0 rgba(255,255,255,.05); animation: pageIn .4s var(--ease) both; }
.gate-logo { width: 76px; height: 76px; border-radius: 24px; box-shadow: 0 18px 40px rgba(91,110,255,.45); }
.gate-card h1 { font-size: 26px; letter-spacing: -.035em; }
.legal-check { border-radius: 16px; }

/* bottom sheet */
.modal { background: var(--panel); border: 1px solid var(--line-2); box-shadow: 0 -20px 60px rgba(0,0,0,.55); }
.modal::before { content: ""; display: block; width: 40px; height: 5px; border-radius: 99px; background: rgba(255,255,255,.18); margin: 8px auto 0; }

.preset-thumb { background: var(--panel-3); }

@media (prefers-reduced-motion: reduce) { *:not(.spinner):not(.fa-spin), *::before, *::after { animation: none !important; transition: none !important; } }

/* =========================================================================
   RESPONSIVE FIX — fill any Mini App width (phone → Telegram Desktop)
   ========================================================================= */
/* overflow:hidden on body made it a scroll container → sticky header/footer broke */
html, body { overflow-x: clip; }
:root { --max: 680px; }
.app-main { max-width: var(--max) !important; margin-inline: auto; }
.app-topbar { padding-inline: max(16px, calc((100% - var(--max)) / 2 + 16px)); }
.tabbar { max-width: calc(var(--max) - 24px); }
/* flex column + align-items:start shrank every card to its content */
.studio-grid, .studio-stack, .credits-layout, .menu-list { align-items: stretch !important; }
.studio-grid > *, .studio-stack > *, #studioSummary, #studioSummary > .summary { width: 100%; }
.summary-body .thumb-pair { max-width: 320px; }
@media (min-width: 560px) {
  .preset-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .history-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .pkg-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .stat-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
  .mode-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
  .mode-tile { flex-direction: column; align-items: flex-start; }
  .mode-tile .tick { top: 12px; transform: none; }
}
@media (max-width: 360px) {
  .app-main { padding-inline: 12px; }
  .page-head h1 { font-size: 23px; }
}

/* job summary thumbs: fill the card width, height capped so they stay balanced */
.summary-body .thumb-pair { max-width: none !important; width: 100%; gap: 12px; }
.summary-body .thumb-box { aspect-ratio: auto; height: clamp(190px, 52vw, 280px); border-radius: 16px; }
.summary-body .thumb-box img { object-position: center top; }

/* engine status: dot + text */
.engine-pill { width: auto !important; height: 34px; padding: 0 12px 0 10px !important; border-radius: 99px !important; display: inline-flex !important; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--text-2); white-space: nowrap; }
.engine-pill[data-state="ready"] { color: #8ff0bf; background: var(--ok-soft); border-color: rgba(47,212,138,.3); }
.engine-pill[data-state="busy"], .engine-pill[data-state="warming"], .engine-pill[data-state="maintenance"] { color: #ffd98a; background: var(--warn-soft); border-color: rgba(246,183,60,.3); }
.engine-pill[data-state="offline"] { color: #ffaaaa; background: var(--bad-soft); border-color: rgba(255,107,107,.3); }
@media (max-width: 340px) { .engine-pill .ep-label { display: none; } .engine-pill { padding: 0 !important; width: 34px !important; justify-content: center; } }

/* credits: full-width stepper, card list history, slip-only card */
.stepper-row { flex-direction: column; align-items: stretch; gap: 8px; }
.stepper { width: 100%; border-radius: 14px; }
.stepper button { width: 56px; height: 50px; flex: none; }
.stepper input { flex: 1; width: auto; min-width: 0; height: 50px; font-size: 18px !important; }
.stepper-row .muted { text-align: center; }
.pay-summary { display: flex; justify-content: space-between; align-items: center; margin-top: 14px; padding: 12px 14px; border-radius: 14px; background: var(--panel-2); }
#slipOnlyPanel { margin-top: 0; }
.topup-list { display: flex; flex-direction: column; }
.topup-item { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 6px 10px; align-items: center; padding: 14px 16px; border-bottom: 1px solid var(--line); }
.topup-item:last-child { border-bottom: 0; }
.ti-main b { display: block; font-size: 15px; }
.ti-main small { color: var(--muted); font-size: 12px; }
.ti-actions { grid-column: 1 / -1; display: flex; gap: 8px; }
.ti-actions .btn { flex: 1; }
.ti-cancel { color: #ffaaaa; }
/* stat cards always fill the row, however many there are */
.stat-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)) !important; }

/* =========================================================================
   ADMIN (inside the Mini App)
   ========================================================================= */
.adm-tabs { margin-bottom: 14px; }
.adm-tabs .chip i { font-size: 12px; margin-right: 2px; }
.adm-badge { font-style: normal; min-width: 18px; height: 18px; padding: 0 5px; border-radius: 99px; background: var(--bad); color: #fff; font-size: 10.5px; font-weight: 700; line-height: 18px; margin-left: 4px; }
.adm-badge:empty { display: none; }
#admBody { display: flex; flex-direction: column; gap: 14px; }
#admBody > .panel + .panel { margin-top: 0; }
#admBody .stat-grid { margin: 0; }
#admBody .filter-row { margin-bottom: 0; }
.adm-list { display: flex; flex-direction: column; padding: 2px 16px; }
.adm-item { display: grid; grid-template-columns: auto minmax(0, 1fr) auto; gap: 4px 12px; align-items: center; width: 100%; padding: 13px 0; border: 0; border-bottom: 1px solid var(--line); background: none; color: var(--text); text-align: left; font: inherit; cursor: pointer; }
.adm-item:last-child { border-bottom: 0; }
button.adm-item:active { opacity: .7; }
.adm-av { width: 40px; height: 40px; border-radius: 13px; display: grid; place-items: center; background: var(--panel-3); color: var(--text-2); font-weight: 700; }
.adm-main { min-width: 0; }
.adm-main b { display: block; font-size: 14.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.adm-main small { display: block; color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.adm-end { text-align: right; }
.adm-end b { display: block; font-size: 14px; white-space: nowrap; }
.adm-end small { color: var(--muted); font-size: 12px; }
.adm-gem { color: var(--gold); font-size: 11px; }
.adm-foot { grid-column: 2 / -1; display: flex; gap: 8px; }
.adm-note { grid-column: 1 / -1; display: block; font-size: 12px; color: var(--muted); background: var(--panel-2); border-radius: 12px; padding: 8px 10px; margin: 4px 0 12px; overflow-wrap: anywhere; }
.adm-empty { text-align: center; color: var(--muted); padding: 26px 10px; font-size: 13.5px; }
.adm-empty i { display: block; font-size: 24px; margin-bottom: 8px; opacity: .6; }
.adm-hint { margin: 0; padding: 10px 14px; border-radius: 14px; background: var(--accent-soft); color: var(--text-2); font-size: 13px; }
.adm-hint i { color: var(--brand); margin-right: 4px; }
.adm-search { position: relative; }
.adm-search i { position: absolute; left: 14px; top: 50%; transform: translateY(-50%); color: var(--muted); }
.adm-search .input { padding-left: 40px; }
.adm-slip img { width: 100%; border-radius: 16px; display: block; margin-bottom: 12px; }
.adm-g2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.adm-row { display: flex; align-items: center; justify-content: space-between; margin: 2px 0 14px; }
.adm-actions { display: flex; gap: 10px; }
.adm-actions .btn { flex: 1; }
.adm-bad { color: #ffaaaa !important; border-color: rgba(255,107,107,.35) !important; }
.adm-code { min-height: 150px; font-family: ui-monospace, Consolas, monospace; font-size: 13px !important; }
.adm-switch { display: flex; align-items: center; justify-content: space-between; gap: 12px; min-height: 54px; cursor: pointer; }
.adm-switch span small { display: block; color: var(--muted); font-size: 12px; }
.adm-switch input { appearance: none; -webkit-appearance: none; width: 50px; height: 30px; flex: none; border-radius: 99px; background: var(--panel-3); position: relative; cursor: pointer; transition: background .2s; }
.adm-switch input::after { content: ""; position: absolute; top: 3px; left: 3px; width: 24px; height: 24px; border-radius: 50%; background: #fff; transition: transform .2s; }
.adm-switch input:checked { background: var(--grad); }
.adm-switch input:checked::after { transform: translateX(20px); }
.adm-switch input:disabled { opacity: .4; }
/* 5 tabs in the tab bar for admins */
.tabbar a span { white-space: nowrap; }

/* admin mode chrome */
.adm-back { display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 14px 0 10px; border-radius: 99px; border: 1px solid var(--line-2); background: var(--panel-2); color: var(--text); font: inherit; font-weight: 650; font-size: 14px; cursor: pointer; }
.adm-back:active { transform: scale(.96); }
.adm-mode { display: inline-flex; align-items: center; gap: 6px; font-size: 14px; color: #c9bbff; }
.adm-bar { border-color: rgba(122,92,255,.35); }
.adm-bar a { position: relative; cursor: pointer; }
.adm-bar .adm-badge { position: absolute; top: 3px; right: calc(50% - 22px); margin: 0; }
#admExtras .page-head { display: none; }
.adm-mode { margin-left: 4px; padding: 2px 8px; border-radius: 99px; background: rgba(122,92,255,.18); font-size: 11.5px; font-weight: 700; }
.adm-backtab { color: var(--text-2) !important; }
.adm-backtab i { color: var(--muted); }
.adm-bar a span { font-size: 10px; }

/* admin filters: equal segments that always fit the screen (no side scroll) */
#admBody .filter-row { display: grid !important; grid-auto-flow: column; grid-auto-columns: minmax(0, 1fr); gap: 4px; margin: 0 !important; padding: 4px !important; overflow: visible; border-radius: 16px; background: var(--panel-2); border: 1px solid var(--line); }
#admBody .filter-row .chip { min-width: 0; min-height: 36px; padding: 0 4px; border: 0; background: transparent; box-shadow: none; font-size: 12.5px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
#admBody .filter-row .chip.sel { background: var(--grad); color: #fff; box-shadow: 0 6px 16px rgba(91,110,255,.3); }

/* package editor */
.pk-head, .pk-row { display: grid; grid-template-columns: minmax(0,1fr) minmax(0,1fr) 44px; gap: 8px; align-items: center; }
.pk-head { margin-bottom: 6px; font-size: 11.5px; font-weight: 700; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; }
.pk-row { margin-bottom: 8px; }
.pk-row .input { text-align: center; font-weight: 600; }
.pk-del { height: 44px; border-radius: 12px; border: 1px solid rgba(255,107,107,.3); background: rgba(255,107,107,.08); color: #ffaaaa; cursor: pointer; }
.pk-del:active { transform: scale(.94); }
#pkList:empty::before { content: "No packages — users can still type any amount"; display: block; text-align: center; color: var(--muted); font-size: 13px; padding: 10px 0 14px; }
#pkAdd { margin-top: 4px; }

/* slip upload box: centered */
.upload-slip { flex-direction: column; justify-content: center; align-items: center; text-align: center; gap: 8px; }
.upload-slip > div { display: flex; flex-direction: column; align-items: center; }
.upload-slip > i { font-size: 22px; }
