:root {
  color-scheme: dark;
  --bg: #0f0d0c;
  --panel: #171413;
  --panel-2: #1f1b19;
  --panel-3: #282321;
  --line: #2f2926;
  --line-2: #3d3531;
  --text: #f4eee8;
  --muted: #a69c94;
  --faint: #6f6660;
  --accent: #ff7a45;
  --accent-2: #ffb347;
  --accent-ink: #1a110c;
  --accent-soft: rgba(255, 122, 69, 0.14);
  --good: #4fd18b;
  --bad: #ff5d5d;
  --bad-soft: rgba(255, 93, 93, 0.12);
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
  --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "Inter", "Segoe UI", Roboto, sans-serif;
  --settings-w: 340px;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.45 var(--font);
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
  overflow: hidden;
}
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; padding: 0; }
button:disabled { cursor: not-allowed; }
a { color: var(--accent-2); }
svg.i { width: 18px; height: 18px; flex: none; stroke: currentColor; fill: none; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.grad-text { background: linear-gradient(90deg, var(--accent), var(--accent-2)); -webkit-background-clip: text; background-clip: text; color: transparent; }

/* ---------- login ---------- */
.login {
  min-height: 100dvh; display: grid; place-items: center; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 50% -10%, rgba(255, 122, 69, 0.18), transparent 60%), var(--bg);
}
.login-card {
  width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line);
  border-radius: 22px; padding: 32px 26px; box-shadow: var(--shadow);
}
.login-card h1 { margin: 16px 0 4px; font-size: 26px; letter-spacing: -0.02em; }
.login-card p { margin: 0 0 22px; color: var(--muted); }
.field { display: block; margin-bottom: 12px; }
.field span { display: block; font-size: 13px; color: var(--muted); margin-bottom: 6px; }
.input {
  width: 100%; background: var(--panel-2); border: 1px solid var(--line); border-radius: var(--radius-sm);
  padding: 12px 14px; outline: none; transition: border-color .15s;
}
.input:focus { border-color: var(--accent); }
.logo { width: 44px; height: 44px; border-radius: 13px; background: linear-gradient(135deg, var(--accent), var(--accent-2)); display: grid; place-items: center; }
.logo svg { width: 20px; height: 20px; fill: var(--accent-ink); stroke: none; }
.logo.sm { width: 32px; height: 32px; border-radius: 10px; }
.logo.sm svg { width: 14px; height: 14px; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  border-radius: 12px; padding: 11px 16px; font-weight: 600; transition: transform .08s, opacity .15s, background .15s;
}
.btn:active:not(:disabled) { transform: scale(.98); }
.btn-primary { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); }
.btn-primary:disabled { opacity: .45; }
.btn-ghost { background: var(--panel-2); border: 1px solid var(--line); }
.btn-ghost:hover:not(:disabled) { background: var(--panel-3); }
.btn-wide { width: 100%; padding: 13px 16px; }
.btn-danger { background: var(--bad-soft); color: var(--bad); }
.form-error { color: var(--bad); font-size: 14px; min-height: 20px; margin: 4px 0 8px; }

/* ---------- shell ---------- */
.app { height: 100dvh; display: grid; grid-template-rows: auto minmax(0, 1fr); grid-template-columns: minmax(0, 1fr); }
.topbar {
  display: flex; align-items: center; gap: 12px; padding: 10px 16px;
  padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: rgba(15, 13, 12, 0.85); backdrop-filter: blur(12px);
  position: relative; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; letter-spacing: -0.01em; font-size: 17px; }
.topbar .spacer { flex: 1; }
.spent {
  display: flex; align-items: center; gap: 8px; padding: 7px 12px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; white-space: nowrap;
}
.spent b { font-weight: 700; }
.spent .dot { width: 6px; height: 6px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.balances {
  display: flex; align-items: center; gap: 10px; padding: 6px 12px 6px 10px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; white-space: nowrap;
  color: var(--text); transition: border-color .15s; min-width: 0;
}
.balances:hover { border-color: var(--line-2); }
.balances .wal { width: 16px; height: 16px; fill: none; stroke: var(--muted); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; flex: none; }
.bal { display: inline-flex; align-items: baseline; gap: 5px; }
.bal .n { color: var(--muted); font-size: 12px; }
.bal b { font-weight: 700; font-variant-numeric: tabular-nums; }
.bal.low b, .bal.err b { color: var(--bad); }
.bal .free { font-size: 10px; text-transform: uppercase; letter-spacing: .04em; color: var(--muted); border: 1px solid var(--line-2); border-radius: 5px; padding: 0 4px; align-self: center; }
.icon-btn {
  width: 38px; height: 38px; display: grid; place-items: center; border-radius: 11px;
  color: var(--muted); transition: background .15s, color .15s; flex: none;
}
.icon-btn:hover { background: var(--panel-2); color: var(--text); }
.icon-btn.on { color: var(--accent); }

.workspace { display: grid; grid-template-columns: minmax(0, 1fr) var(--settings-w); min-height: 0; }
.feed-col { display: grid; grid-template-rows: minmax(0, 1fr) auto; grid-template-columns: minmax(0, 1fr); min-height: 0; min-width: 0; position: relative; }
.feed { overflow-y: auto; padding: 20px 16px 8px; scroll-behavior: smooth; overscroll-behavior: contain; }
.feed-inner { max-width: 820px; margin: 0 auto; display: flex; flex-direction: column; gap: 18px; }
.feed-tools { display: flex; gap: 8px; justify-content: center; }
.chip-btn {
  display: inline-flex; align-items: center; gap: 6px; padding: 7px 12px; border-radius: 999px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 13px; color: var(--muted);
}
.chip-btn:hover { color: var(--text); }
.chip-btn.on { color: var(--accent-ink); background: var(--accent); border-color: var(--accent); }

/* empty state */
.empty { text-align: center; padding: 8vh 12px 4vh; color: var(--muted); }
.empty .logo { margin: 0 auto 18px; width: 56px; height: 56px; border-radius: 17px; }
.empty h2 { color: var(--text); margin: 0 0 8px; font-size: 22px; letter-spacing: -0.02em; }
.empty p { margin: 0 auto; max-width: 440px; }
.empty-tips { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 10px; margin-top: 24px; text-align: left; }
.tip { background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; font-size: 14px; }
.tip b { display: block; color: var(--text); margin-bottom: 4px; }

/* ---------- run card ---------- */
.run { container-type: inline-size; background: var(--panel); border: 1px solid var(--line); border-radius: 18px; overflow: hidden; }
.run.new { animation: rise .25s ease-out; }
@keyframes rise { from { opacity: 0; transform: translateY(6px); } }
.run-head { display: flex; align-items: center; gap: 8px; padding: 12px 14px 0; flex-wrap: wrap; font-size: 13px; color: var(--muted); }
.tag { display: inline-flex; align-items: center; gap: 5px; padding: 3px 9px; border-radius: 999px; background: var(--panel-2); border: 1px solid var(--line); color: var(--text); font-size: 12.5px; white-space: nowrap; }
.tag.accent { background: var(--accent-soft); border-color: transparent; color: var(--accent-2); }
.run-head .when { margin-left: auto; white-space: nowrap; }
.run-body { display: grid; grid-template-columns: minmax(0, 1fr); gap: 12px; padding: 12px 14px 14px; }
.run-prompt { white-space: pre-wrap; word-break: break-word; font-size: 14.5px; max-height: 7.5em; overflow: hidden; position: relative; }
.run-prompt.open { max-height: none; }
.run-prompt.long:not(.open)::after { content: ""; position: absolute; inset: auto 0 0; height: 2.2em; background: linear-gradient(transparent, var(--panel)); }
.more-link { font-size: 13px; color: var(--accent-2); margin-top: -6px; justify-self: start; }
.ref { color: var(--accent-2); background: var(--accent-soft); border-radius: 6px; padding: 0 4px; font-weight: 600; }
.run-media-row { display: flex; gap: 8px; flex-wrap: wrap; }
.mini { position: relative; width: 52px; height: 52px; border-radius: 10px; overflow: hidden; background: var(--panel-3); border: 1px solid var(--line); }
.mini img { width: 100%; height: 100%; object-fit: cover; display: block; }
.mini .lbl { position: absolute; left: 3px; bottom: 3px; font-size: 10px; font-weight: 700; padding: 1px 4px; border-radius: 5px; background: rgba(0,0,0,.72); color: #fff; }
.mini.audio { display: grid; place-items: center; color: var(--muted); }

.result { position: relative; border-radius: 14px; overflow: hidden; background: #000; width: fit-content; max-width: 100%; }
.result video { display: block; max-width: 100%; max-height: 62vh; width: auto; background: #000; }
.result.portrait video { max-height: 70vh; }
.pending {
  border-radius: 14px; background: var(--panel-2); border: 1px solid var(--line); display: grid; place-items: center;
  width: min(100%, 300px); aspect-ratio: 9 / 16; max-height: 46vh; position: relative; overflow: hidden; color: var(--muted); text-align: center; padding: 16px;
}
.pending.wide { aspect-ratio: 16 / 9; width: min(100%, 460px); }
.pending.square { aspect-ratio: 1; width: min(100%, 320px); }
.pending::before {
  content: ""; position: absolute; inset: 0;
  background: linear-gradient(110deg, transparent 30%, rgba(255, 140, 80, 0.08) 50%, transparent 70%);
  background-size: 250% 100%; animation: shimmer 1.8s linear infinite;
}
@keyframes shimmer { from { background-position: 150% 0; } to { background-position: -100% 0; } }
.pending .spinner { width: 34px; height: 34px; border-radius: 50%; border: 3px solid var(--line-2); border-top-color: var(--accent); animation: spin .9s linear infinite; margin: 0 auto 12px; }
@keyframes spin { to { transform: rotate(360deg); } }
.pending b { color: var(--text); display: block; font-size: 15px; }
.pending small { display: block; margin-top: 4px; }
.bar { height: 4px; border-radius: 4px; background: var(--line); margin-top: 12px; overflow: hidden; width: 140px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); }
.failed { border-radius: 12px; background: var(--bad-soft); color: #ffb3b3; padding: 12px 14px; font-size: 14px; display: flex; gap: 10px; align-items: flex-start; }
.failed svg { color: var(--bad); margin-top: 1px; }

.run-foot { display: flex; align-items: center; gap: 4px; padding: 8px 8px 8px 14px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.cost { font-weight: 700; font-size: 14px; margin-right: auto; display: flex; align-items: baseline; gap: 6px; }
.cost small { font-weight: 500; color: var(--muted); font-size: 12px; }
.act { display: inline-flex; align-items: center; gap: 6px; padding: 7px 10px; border-radius: 10px; color: var(--muted); font-size: 13px; white-space: nowrap; }
.act:hover { background: var(--panel-2); color: var(--text); }
.act.on { color: var(--accent-2); }
.act .t { display: inline; }

/* popover */
.popover {
  position: fixed; z-index: 40; background: var(--panel); border: 1px solid var(--line-2); border-radius: 14px;
  box-shadow: var(--shadow); padding: 6px; min-width: 260px; max-width: calc(100vw - 24px); animation: rise .15s ease-out;
}
.popover h4 { margin: 6px 10px 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 600; }
.pop-item { display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px; border-radius: 10px; text-align: left; }
.pop-item:hover:not(:disabled) { background: var(--panel-2); }
.pop-item:disabled { opacity: .45; }
.pop-item .grow { flex: 1; min-width: 0; }
.pop-item small { display: block; color: var(--muted); font-size: 12px; }
.pop-item .price { font-weight: 700; }

/* ---------- composer ---------- */
.composer-wrap { padding: 8px 16px 16px; padding-bottom: max(16px, env(safe-area-inset-bottom)); }
.composer {
  max-width: 820px; margin: 0 auto; background: var(--panel); border: 1px solid var(--line-2); border-radius: 20px;
  transition: border-color .15s, box-shadow .15s; position: relative;
}
.composer:focus-within { border-color: rgba(255, 122, 69, 0.55); box-shadow: 0 0 0 4px rgba(255, 122, 69, 0.08); }
.composer.drag { border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-soft); }
.mode-hint { padding: 10px 14px 0; font-size: 13px; color: var(--muted); display: flex; gap: 8px; align-items: center; }
.mode-hint b { color: var(--text); font-weight: 600; }
.tray { display: flex; gap: 14px; padding: 12px 14px 2px; overflow-x: auto; scrollbar-width: none; }
.tray::-webkit-scrollbar { display: none; }
.slot { display: flex; flex-direction: column; gap: 6px; flex: none; }
.slot-title { font-size: 11.5px; color: var(--muted); text-transform: uppercase; letter-spacing: .05em; white-space: nowrap; }
.slot-title .req { color: var(--accent); }
.slot-items { display: flex; gap: 8px; }
.att {
  position: relative; width: 76px; height: 76px; border-radius: 12px; overflow: hidden; background: var(--panel-3); border: 1px solid var(--line); flex: none;
}
.att img, .att video { width: 100%; height: 100%; object-fit: cover; display: block; }
.att .lbl {
  position: absolute; left: 4px; bottom: 4px; font-size: 11px; font-weight: 700; padding: 2px 6px; border-radius: 6px;
  background: rgba(0, 0, 0, 0.75); color: #fff; cursor: pointer; border: 1px solid rgba(255,255,255,.12);
}
.att .lbl:hover { background: var(--accent); color: var(--accent-ink); }
.att .dur { position: absolute; left: 4px; top: 4px; font-size: 10.5px; padding: 1px 5px; border-radius: 5px; background: rgba(0,0,0,.7); color: #fff; }
.att .x {
  position: absolute; right: 4px; top: 4px; width: 22px; height: 22px; border-radius: 50%; background: rgba(0, 0, 0, 0.7);
  display: grid; place-items: center; color: #fff;
}
.att .x svg { width: 12px; height: 12px; stroke-width: 2.4; }
.att .up { position: absolute; inset: 0; display: grid; place-items: center; background: rgba(0,0,0,.55); font-size: 12px; font-weight: 600; }
.att.audio { display: grid; place-items: center; color: var(--muted); }
.att.err { border-color: var(--bad); }
.add-tile {
  width: 76px; height: 76px; border-radius: 12px; border: 1.5px dashed var(--line-2); display: grid; place-items: center;
  color: var(--muted); flex: none; transition: border-color .15s, color .15s, background .15s; text-align: center; font-size: 11px; line-height: 1.2; padding: 4px;
}
.add-tile:hover { border-color: var(--accent); color: var(--accent-2); background: var(--accent-soft); }
.add-tile svg { width: 20px; height: 20px; margin: 0 auto 3px; display: block; }

.prompt-box { position: relative; }
.prompt {
  display: block; width: 100%; border: 0; outline: none; background: transparent; padding: 12px 44px 8px 16px;
  min-height: 56px; max-height: 40vh; overflow-y: auto; font-size: 15.5px; line-height: 1.6;
  position: relative; white-space: pre-wrap; overflow-wrap: anywhere; cursor: text;
}
.prompt.empty::before {
  content: attr(data-placeholder); color: var(--faint); position: absolute; left: 16px; right: 44px; top: 12px; pointer-events: none;
}

/* @Image1 / @Video1 as a small picture chip, in the composer and in the history */
.chip {
  display: inline-flex; align-items: center; gap: 5px; vertical-align: -5px; white-space: nowrap;
  padding: 1px 7px 1px 2px; margin: 0 1px; border-radius: 7px; line-height: 20px;
  background: var(--accent-soft); color: var(--accent-2); border: 1px solid rgba(255, 122, 69, 0.32);
  font-weight: 600; font-size: 0.93em; user-select: all; -webkit-user-select: all;
}
.chip-thumb { width: 20px; height: 20px; border-radius: 5px; object-fit: cover; flex: none; display: block; }
.chip-thumb.glyph { display: grid; place-items: center; background: rgba(255, 122, 69, 0.22); font-size: 11px; line-height: 1; }
.chip.missing { background: var(--bad-soft); color: #ff8f8f; border-color: rgba(255, 93, 93, 0.45); }
.chip.missing .chip-thumb { background: rgba(255, 93, 93, 0.2); }

.ref-picker {
  position: fixed; z-index: 70; width: max-content; min-width: 220px; max-width: min(340px, calc(100vw - 16px));
  max-height: 300px; overflow-y: auto; padding: 6px; border-radius: 14px;
  background: var(--panel-3); border: 1px solid var(--line-2); box-shadow: var(--shadow); animation: rise .12s;
}
.ref-item { display: flex; align-items: center; gap: 10px; padding: 6px 10px 6px 6px; border-radius: 10px; cursor: pointer; }
.ref-item.on { background: rgba(255, 255, 255, 0.07); }
.ref-thumb { width: 42px; height: 42px; border-radius: 8px; object-fit: cover; flex: none; display: block; }
.ref-thumb.glyph { display: grid; place-items: center; background: var(--panel-2); color: var(--accent-2); font-size: 16px; }
.ref-text { min-width: 0; }
.ref-text b { display: block; color: var(--accent-2); font-size: 14.5px; }
.ref-text small { display: block; color: var(--muted); font-size: 12px; max-width: 230px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ref-hint { padding: 10px 12px; color: var(--muted); font-size: 13.5px; max-width: 300px; }
.prompt-clear { position: absolute; right: 8px; top: 8px; }
.problems { padding: 0 16px 6px; font-size: 13px; color: #ffb38a; display: flex; flex-direction: column; gap: 2px; }
.composer-bar { display: flex; align-items: center; gap: 6px; padding: 6px 8px 8px 8px; }
.bar-btn {
  display: inline-flex; align-items: center; gap: 6px; height: 36px; padding: 0 11px; border-radius: 11px;
  background: var(--panel-2); border: 1px solid var(--line); color: var(--muted); font-size: 13px; white-space: nowrap;
}
.bar-btn:hover { color: var(--text); background: var(--panel-3); }
.bar-btn.settings-toggle { display: none; color: var(--text); max-width: 46vw; overflow: hidden; text-overflow: ellipsis; }
.bar-btn.settings-toggle span { overflow: hidden; text-overflow: ellipsis; }
.bar .grow, .composer-bar .grow { flex: 1; }
.price-pill { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; margin-right: 4px; min-width: 0; }
.price-pill b { font-size: 15px; }
.price-pill small { font-size: 11.5px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 160px; }
.send {
  width: 44px; height: 44px; border-radius: 14px; display: grid; place-items: center; flex: none;
  background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); transition: transform .08s, opacity .15s;
}
.send svg { width: 20px; height: 20px; stroke-width: 2.2; }
.send:disabled { opacity: .35; }
.send:active:not(:disabled) { transform: scale(.94); }

/* ---------- settings ---------- */
.settings {
  border-left: 1px solid var(--line); background: var(--panel); overflow-y: auto; padding: 16px 16px 28px;
  overscroll-behavior: contain;
}
.sheet-head { display: none; }
.sec { padding: 14px 0; border-bottom: 1px solid var(--line); }
.sec:first-child { padding-top: 2px; }
.sec:last-child { border-bottom: 0; }
.sec-title { display: flex; align-items: center; justify-content: space-between; font-size: 12px; color: var(--muted); text-transform: uppercase; letter-spacing: .06em; font-weight: 600; margin-bottom: 10px; }
.sec-title .val { text-transform: none; letter-spacing: 0; color: var(--text); font-size: 14px; font-weight: 700; }
.models { display: grid; gap: 8px; }
.model-card {
  display: flex; align-items: center; gap: 12px; padding: 11px 12px; border-radius: 13px; background: var(--panel-2);
  border: 1px solid var(--line); text-align: left; transition: border-color .15s, background .15s;
}
.model-card:hover { border-color: var(--line-2); }
.model-card.on { border-color: var(--accent); background: linear-gradient(135deg, rgba(255,122,69,.12), rgba(255,179,71,.05)); }
.model-card .mi { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; background: var(--panel-3); font-weight: 800; font-size: 13px; flex: none; }
.model-card.on .mi { background: linear-gradient(135deg, var(--accent), var(--accent-2)); color: var(--accent-ink); }
.model-card b { display: block; font-size: 14.5px; }
.model-card small { color: var(--muted); font-size: 12px; }
.modes { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.mode-btn {
  display: flex; align-items: center; gap: 8px; padding: 10px; border-radius: 12px; background: var(--panel-2);
  border: 1px solid var(--line); font-size: 13.5px; text-align: left; transition: border-color .15s, background .15s; min-height: 44px;
}
.mode-btn svg { color: var(--muted); }
.mode-btn.on { border-color: var(--accent); background: var(--accent-soft); }
.mode-btn.on svg { color: var(--accent-2); }
.offers { display: grid; gap: 6px; }
.offer {
  display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 12px; background: var(--panel-2);
  border: 1px solid var(--line); text-align: left; transition: border-color .15s;
}
.offer .radio { width: 18px; height: 18px; border-radius: 50%; border: 2px solid var(--line-2); flex: none; display: grid; place-items: center; }
.offer.on { border-color: var(--accent); }
.offer.on .radio { border-color: var(--accent); }
.offer.on .radio::after { content: ""; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); }
.offer .grow { flex: 1; min-width: 0; }
.offer b { font-size: 14px; display: flex; align-items: center; gap: 6px; }
.offer small { display: block; color: var(--muted); font-size: 12px; line-height: 1.3; margin-top: 2px; }
.offer .price { font-weight: 700; font-size: 14px; white-space: nowrap; text-align: right; }
.offer .price small { font-weight: 500; }
.offer:disabled { opacity: .45; }
.best { font-size: 10.5px; font-weight: 700; padding: 2px 6px; border-radius: 6px; background: rgba(79, 209, 139, .14); color: var(--good); text-transform: uppercase; letter-spacing: .04em; }
.seg { display: flex; background: var(--panel-2); border: 1px solid var(--line); border-radius: 12px; padding: 3px; gap: 3px; }
.seg button { flex: 1; padding: 8px 6px; border-radius: 9px; font-size: 13.5px; color: var(--muted); font-weight: 600; }
.seg button.on { background: var(--panel-3); color: var(--text); box-shadow: 0 1px 0 rgba(255,255,255,.05) inset; }
.seg button:disabled { opacity: .35; }
.range { width: 100%; accent-color: var(--accent); height: 28px; }
.range-scale { display: flex; justify-content: space-between; font-size: 11.5px; color: var(--faint); margin-top: -2px; }
.aspects { display: flex; flex-wrap: wrap; gap: 6px; }
.aspect {
  display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 8px 6px 6px; min-width: 50px; border-radius: 11px;
  background: var(--panel-2); border: 1px solid var(--line); font-size: 11.5px; color: var(--muted);
}
.aspect i { display: block; border: 2px solid currentColor; border-radius: 3px; }
.aspect.on { border-color: var(--accent); color: var(--text); }
.aspect.on i { border-color: var(--accent); }
.note { font-size: 13px; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); border-radius: 11px; padding: 10px 12px; }
.row { display: flex; align-items: center; justify-content: space-between; gap: 10px; }
.switch { width: 44px; height: 26px; border-radius: 999px; background: var(--line-2); position: relative; transition: background .15s; flex: none; }
.switch::after { content: ""; position: absolute; left: 3px; top: 3px; width: 20px; height: 20px; border-radius: 50%; background: #fff; transition: transform .15s; }
.switch.on { background: var(--accent); }
.switch.on::after { transform: translateX(18px); }
details.more summary { cursor: pointer; list-style: none; display: flex; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); padding: 4px 0; }
details.more summary::-webkit-details-marker { display: none; }
details.more[open] summary svg { transform: rotate(90deg); }
details.more .body { padding-top: 10px; display: grid; gap: 12px; }

/* ---------- sheets & modals ---------- */
.backdrop { position: fixed; inset: 0; background: rgba(0, 0, 0, 0.55); z-index: 30; animation: fade .15s; }
@keyframes fade { from { opacity: 0; } }
.modal {
  position: fixed; z-index: 31; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(560px, calc(100vw - 24px));
  max-height: min(80dvh, 720px); display: flex; flex-direction: column; background: var(--panel); border: 1px solid var(--line-2);
  border-radius: 20px; box-shadow: var(--shadow); animation: rise .18s ease-out;
}
.modal-head { display: flex; align-items: center; gap: 10px; padding: 16px 16px 12px 20px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; flex: 1; }
.modal-body { padding: 14px 16px; overflow-y: auto; }
.modal-foot { display: flex; gap: 8px; justify-content: flex-end; padding: 12px 16px; border-top: 1px solid var(--line); flex-wrap: wrap; }
.tpl { border: 1px solid var(--line); background: var(--panel-2); border-radius: 14px; padding: 12px 14px; margin-bottom: 10px; }
.tpl-head { display: flex; align-items: center; gap: 8px; }
.tpl-head b { flex: 1; font-size: 14.5px; }
.tpl-text { color: var(--muted); font-size: 13px; white-space: pre-wrap; max-height: 4.4em; overflow: hidden; margin: 6px 0 10px; }
.tpl-actions { display: flex; gap: 6px; flex-wrap: wrap; }
.tpl-actions .btn { padding: 8px 12px; font-size: 13px; }
textarea.input { resize: vertical; min-height: 160px; line-height: 1.45; }

.toasts { position: fixed; left: 50%; top: calc(64px + env(safe-area-inset-top)); transform: translateX(-50%); z-index: 60; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; width: min(520px, calc(100vw - 24px)); }
.toast { background: var(--panel-3); border: 1px solid var(--line-2); color: var(--text); padding: 11px 16px; border-radius: 12px; box-shadow: var(--shadow); font-size: 14px; animation: rise .2s; pointer-events: auto; }
.toast.bad { border-color: rgba(255,93,93,.5); }
.toast.good { border-color: rgba(79,209,139,.45); }

/* ---------- phone ---------- */
@media (max-width: 900px) {
  body { font-size: 15px; }
  .workspace { grid-template-columns: minmax(0, 1fr); }
  .spent .month { display: none; }
  .settings {
    position: fixed; left: 0; right: 0; bottom: 0; z-index: 32; max-height: 86dvh; border-left: 0;
    border-top: 1px solid var(--line-2); border-radius: 22px 22px 0 0; box-shadow: var(--shadow);
    transform: translateY(105%); transition: transform .25s cubic-bezier(.2,.8,.2,1); padding-bottom: max(24px, env(safe-area-inset-bottom));
  }
  .settings.open { transform: none; }
  .sheet-head { display: flex; align-items: center; justify-content: space-between; position: sticky; top: -16px; background: var(--panel); margin: -16px -16px 4px; padding: 10px 12px 8px 18px; z-index: 2; }
  .sheet-head b { font-size: 16px; }
  .sheet-grip { position: absolute; left: 50%; top: 6px; width: 40px; height: 4px; border-radius: 4px; background: var(--line-2); transform: translateX(-50%); }
  .bar-btn.settings-toggle { display: inline-flex; }
  .bar-btn .t { display: none; }
  .feed { padding: 14px 10px 6px; }
  .composer-wrap { padding: 6px 8px 10px; padding-bottom: max(10px, env(safe-area-inset-bottom)); }
  .composer { border-radius: 18px; }
  .act .t { display: none; }
  .act { padding: 9px 10px; }
  .spent .lbl { display: none; }
  .balances { gap: 8px; padding: 6px 10px; }
  .balances .wal, .bal .free { display: none; }
}
@media (max-width: 520px) {
  .balances { flex-direction: column; align-items: flex-end; gap: 0; padding: 3px 10px; border-radius: 12px; }
  .bal { font-size: 11.5px; line-height: 1.3; }
  .bal .n { font-size: 11px; }
  .topbar { padding-left: 12px; padding-right: 8px; gap: 8px; }
  .brand .name { display: none; }
  .att, .add-tile { width: 68px; height: 68px; }
  .mode-hint { display: none; }
  .modal { top: auto; bottom: 0; transform: translateX(-50%); border-radius: 20px 20px 0 0; width: 100vw; max-height: 88dvh; padding-bottom: env(safe-area-inset-bottom); }
}
@container (max-width: 720px) { .act .t { display: none; } .act { padding: 9px 10px; } }
@media (min-width: 1400px) { :root { --settings-w: 380px; } }


/* ---------- «Страница» editor ---------- */
.top-btn {
  display: inline-flex; align-items: center; gap: 7px; height: 38px; padding: 0 12px; border-radius: 11px;
  color: var(--text); background: var(--panel-2); border: 1px solid var(--line); font-size: 13.5px; font-weight: 600; flex: none;
}
.top-btn:hover { background: var(--panel-3); }
.top-btn .i { width: 17px; height: 17px; }
.i.flip { transform: rotate(180deg); }
body.pe-open-body { overflow: hidden; }
.pe { position: fixed; inset: 0; z-index: 40; background: var(--bg); display: grid; grid-template-rows: auto auto minmax(0, 1fr); }
.pe-head {
  display: flex; align-items: center; gap: 10px; padding: 10px 16px; padding-top: max(10px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line); background: rgba(15, 13, 12, 0.9);
}
.pe-back { display: inline-flex; align-items: center; gap: 4px; color: var(--muted); font-weight: 600; font-size: 14px; padding: 8px 8px 8px 2px; border-radius: 10px; }
.pe-back:hover { color: var(--text); }
.pe-back .i { width: 18px; height: 18px; }
.pe-title { flex: 1; min-width: 0; display: flex; align-items: baseline; gap: 10px; }
.pe-title b { font-size: 17px; }
.pe-status { font-size: 12.5px; color: var(--faint); }
.pe-status.warn { color: var(--accent-2); }
.pe-open { padding: 9px 14px; font-size: 13.5px; text-decoration: none; color: var(--text); }
.pe-head .btn-primary { padding: 9px 16px; font-size: 14px; }
.pe-viewseg { display: none; margin: 10px 12px 0; }
.pe-body { display: grid; grid-template-columns: minmax(0, 1fr) minmax(340px, 44%); min-height: 0; }
.pe-form { min-height: 0; overflow-y: auto; border-right: 1px solid var(--line); }
.pe-tabs { position: sticky; top: 0; z-index: 2; display: flex; gap: 4px; padding: 10px 14px; background: var(--bg); border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.pe-tab { padding: 8px 13px; border-radius: 10px; color: var(--muted); font-weight: 600; font-size: 14px; white-space: nowrap; }
.pe-tab.on { background: var(--panel-3); color: var(--text); }
.pe-panel { padding: 6px 18px 40px; max-width: 760px; }
.pe-sec { padding: 14px 0; border-bottom: 1px solid var(--line); }
.pe-sec:last-child { border-bottom: 0; }
.pe-sec-title { font-size: 12px; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); font-weight: 700; margin: 4px 0 12px; }
.pe-lead { margin: 0; color: var(--muted); font-size: 14px; line-height: 1.5; }
.pe-hint { display: block; margin-top: 6px; color: var(--faint); font-size: 12.5px; line-height: 1.45; }
.pe-switch-row { display: flex; align-items: center; justify-content: space-between; width: 100%; gap: 12px; padding: 4px 0; font-size: 15px; color: var(--text); text-align: left; }
.pe-kind { width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center; flex: none; background: var(--accent-soft); color: var(--accent-2); }
.pe-kind svg { width: 18px; height: 18px; }
.pe-kind.sm { width: 22px; height: 22px; border-radius: 7px; background: transparent; }
.pe-kind.sm svg { width: 15px; height: 15px; }
.pe-links { display: flex; flex-direction: column; gap: 10px; margin-top: 12px; }
.pe-link { background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px 9px 6px; transition: box-shadow .15s, border-color .15s; }
.pe-link.off { opacity: .62; }
.pe-link.dragging { border-color: var(--accent); box-shadow: 0 12px 30px rgba(0,0,0,.45); opacity: 1; position: relative; z-index: 3; }
.pe-link-top { display: flex; align-items: center; gap: 8px; }
.pe-link-title { flex: 1; min-width: 0; font-weight: 600; }
.pe-handle { width: 26px; height: 38px; flex: none; color: var(--faint); font-size: 18px; cursor: grab; touch-action: none; border-radius: 8px; }
.pe-handle:active { cursor: grabbing; color: var(--accent-2); }
.pe-eye { flex: none; padding: 8px 10px; border-radius: 10px; font-size: 12.5px; font-weight: 700; color: var(--muted); background: var(--panel-2); border: 1px solid var(--line); }
.pe-eye.on { color: var(--good); border-color: rgba(79,209,139,.35); background: rgba(79,209,139,.08); }
.pe-del { width: 34px; height: 34px; }
.pe-link-bottom { display: flex; gap: 8px; margin: 8px 0 0 34px; }
.pe-link-bottom > .input { flex: 1; min-width: 0; }
.pe-until { display: flex; align-items: center; gap: 6px; color: var(--muted); font-size: 13px; flex: none; }
.pe-until .input { width: 150px; padding: 9px 10px; }
.pe-clear { color: var(--muted); font-size: 18px; width: 24px; }
.pe-link-status { margin: 6px 0 0 34px; font-size: 12.5px; color: var(--faint); }
.pe-link-status.ok { color: var(--good); }
.pe-link-status.warn { color: #ffb38a; }
.pe-add { display: flex; flex-wrap: wrap; align-items: center; gap: 6px; margin-top: 14px; font-size: 13.5px; }
.pe-add .chip-btn { display: inline-flex; align-items: center; gap: 5px; }
.pe-media-row { display: flex; gap: 14px; align-items: flex-start; }
.pe-media { width: 132px; height: 92px; border-radius: 12px; object-fit: cover; background: var(--panel-2); border: 1px solid var(--line); flex: none; display: grid; place-items: center; color: var(--faint); font-size: 13px; }
.pe-avatar { width: 92px; height: 92px; border-radius: 50%; overflow: hidden; flex: none; border: 2px solid var(--line-2); }
.pe-avatar img, .pe-avatar video { width: 100%; height: 100%; object-fit: cover; display: block; border: 0; border-radius: 0; }
.pe-media-actions { display: flex; flex-direction: column; gap: 8px; align-items: flex-start; min-width: 0; }
.pe-media-actions.row { flex-direction: row; flex-wrap: wrap; align-items: center; margin-top: 10px; }
.pe-media-actions .btn { padding: 9px 14px; font-size: 13.5px; }
.pe-phrases { min-height: 210px; }
.pe-bio { min-height: 76px; }
.pe-presets { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 10px; }
.pe-preset { display: flex; align-items: center; gap: 10px; padding: 10px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); font-weight: 600; font-size: 14px; color: var(--text); }
.pe-preset.on { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.pe-swatch { position: relative; width: 34px; height: 34px; border-radius: 50%; flex: none; box-shadow: inset 0 0 0 1px rgba(255,255,255,.2); }
.pe-swatch i { position: absolute; right: -2px; bottom: -2px; width: 14px; height: 14px; border-radius: 50%; border: 2px solid var(--panel); }
.pe-colors { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 10px; }
.pe-color { display: flex; flex-direction: column; align-items: center; gap: 6px; font-size: 13px; color: var(--muted); }
.pe-color input { width: 100%; height: 44px; border: 1px solid var(--line-2); border-radius: 12px; background: var(--panel-2); padding: 3px; cursor: pointer; }
.pe-days { max-width: 280px; }
.pe-kpis { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; margin: 14px 0; }
.pe-kpi { background: var(--panel); border: 1px solid var(--line); border-radius: 14px; padding: 12px 14px; }
.pe-kpi b { display: block; font-size: 24px; font-variant-numeric: tabular-nums; }
.pe-kpi span { color: var(--muted); font-size: 13px; }
.pe-chart { display: flex; align-items: flex-end; gap: 3px; height: 120px; padding: 10px; margin-bottom: 18px; background: var(--panel); border: 1px solid var(--line); border-radius: 14px; }
.pe-bar { flex: 1; height: 100%; display: flex; align-items: flex-end; }
.pe-bar i { display: block; width: 100%; min-height: 2px; border-radius: 4px 4px 1px 1px; background: linear-gradient(180deg, var(--accent-2), var(--accent)); }
.pe-clicks { display: flex; flex-direction: column; gap: 6px; margin-bottom: 12px; }
.pe-clicks div { display: flex; justify-content: space-between; gap: 12px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; font-size: 14px; }
.pe-preview { min-height: 0; display: flex; flex-direction: column; align-items: center; padding: 16px 12px 12px; background:
  radial-gradient(60% 50% at 50% 0%, rgba(255,122,69,.08), transparent 70%), var(--bg); }
.pe-phone-box { flex: 1; min-height: 0; width: 100%; display: flex; justify-content: center; align-items: flex-start; overflow: hidden; }
.pe-phone {
  position: relative; width: 390px; height: 812px; flex: none; transform-origin: top center; border-radius: 52px; padding: 12px;
  background: #0b0a0a; box-shadow: 0 0 0 2px #2a2523, 0 30px 80px rgba(0,0,0,.55);
}
.pe-frame { width: 100%; height: 100%; border: 0; border-radius: 40px; background: #fff; display: block; }
.pe-preview-note { margin-top: 8px; font-size: 12.5px; color: var(--faint); text-align: center; }
@media (max-width: 900px) {
  .top-btn span { display: none; }
  .top-btn { width: 38px; padding: 0; justify-content: center; }
  .pe-head { padding-left: 8px; padding-right: 10px; gap: 6px; }
  .pe-back span, .pe-open { display: none; }
  .pe-viewseg { display: flex; }
  .pe-body { grid-template-columns: minmax(0, 1fr); }
  .pe-form { border-right: 0; }
  .pe[data-view="edit"] .pe-preview { display: none; }
  .pe[data-view="preview"] .pe-form { display: none; }
  .pe-panel { padding: 4px 14px 40px; }
  .pe-link-bottom { flex-wrap: wrap; margin-left: 0; }
  .pe-link-bottom > .input { flex-basis: 100%; }
  .pe-link-status { margin-left: 0; }
  .pe-until .input { width: 160px; }
  .pe-colors { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
