:root {
  --bg: #090b10;
  --surface: #11141b;
  --surface2: #181c26;
  --surface3: #212634;
  --border: #272c3a;
  --text: #eef0f6;
  --muted: #8b93a8;
  --faint: #596079;
  --accent: #25f4ee;
  --accent2: #fe2c55;
  --good: #2ee6a6;
  --bad: #ff5370;
  --warn: #ffb84d;
  --radius: 16px;
  --radius-sm: 11px;
  --tab-h: 62px;
  --top-h: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
  --safe-t: env(safe-area-inset-top, 0px);
  font-family: -apple-system, BlinkMacSystemFont, 'SF Pro Text', 'Segoe UI', Roboto, Inter, system-ui, sans-serif;
  color-scheme: dark;
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.35; }
body { min-height: 100dvh; overflow-x: hidden; -webkit-font-smoothing: antialiased; }
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; border: 0; background: none; }
a { color: var(--accent); text-decoration: none; }
.num { font-variant-numeric: tabular-nums; letter-spacing: -0.01em; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.hidden { display: none !important; }
.good { color: var(--good); } .bad { color: var(--bad); } .warn { color: var(--warn); }
.row { display: flex; align-items: center; gap: 10px; }
.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.wrap { flex-wrap: wrap; }
.mt { margin-top: 14px; } .mt-s { margin-top: 8px; } .mb { margin-bottom: 14px; }
.ellipsis { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.small { font-size: 12.5px; }
.tiny { font-size: 11px; }
h2 { font-size: 13px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); margin: 22px 0 10px; font-weight: 600; }
h3 { margin: 0 0 4px; font-size: 16px; }
svg.i { width: 20px; height: 20px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; flex: none; }

/* ---------- shell ---------- */
.shell { min-height: 100dvh; }
.topbar {
  position: sticky; top: 0; z-index: 30; display: flex; align-items: center; gap: 10px;
  padding: calc(var(--safe-t) + 8px) 14px 8px; min-height: calc(var(--top-h) + var(--safe-t));
  background: rgba(9, 11, 16, .86); backdrop-filter: blur(14px); -webkit-backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
}
.brand { font-weight: 800; letter-spacing: -.02em; display: flex; align-items: center; gap: 8px; font-size: 16px; }
.logo { width: 26px; height: 26px; border-radius: 8px; background: linear-gradient(135deg, var(--accent), var(--accent2)); display: grid; place-items: center; color: #05070b; }
.logo svg { width: 15px; height: 15px; stroke-width: 2.6; }
.chip {
  display: inline-flex; align-items: center; gap: 7px; padding: 7px 12px; border-radius: 999px;
  background: var(--surface2); border: 1px solid var(--border); font-weight: 600; font-size: 13.5px; white-space: nowrap;
}
.chip.low { border-color: var(--bad); color: var(--bad); background: rgba(255, 83, 112, .1); }
.chip small { font-weight: 500; color: var(--muted); font-size: 11.5px; }
.icon-btn { width: 40px; height: 40px; border-radius: 12px; display: grid; place-items: center; background: var(--surface2); border: 1px solid var(--border); position: relative; }
.icon-btn:active { background: var(--surface3); }
.badge { position: absolute; top: -4px; right: -4px; background: var(--accent2); color: #fff; font-size: 10px; font-weight: 700; min-width: 17px; height: 17px; border-radius: 9px; display: grid; place-items: center; padding: 0 4px; }
.sync-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--good); }
.sync-dot.err { background: var(--bad); } .sync-dot.busy { background: var(--warn); animation: pulse 1s infinite; }
@keyframes pulse { 50% { opacity: .35; } }

main { padding: 14px 14px calc(var(--tab-h) + var(--safe-b) + 90px); max-width: 1180px; margin: 0 auto; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 40; display: grid; grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tab-h) + var(--safe-b)); padding-bottom: var(--safe-b);
  background: rgba(14, 16, 23, .94); backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); border-top: 1px solid var(--border);
}
.tab { display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 3px; color: var(--faint); font-size: 11px; font-weight: 600; position: relative; }
.tab.on { color: var(--text); }
.tab.on::before { content: ''; position: absolute; top: 0; width: 28px; height: 3px; border-radius: 0 0 4px 4px; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
.tab svg { width: 22px; height: 22px; }

@media (min-width: 900px) {
  .shell { display: grid; grid-template-columns: 200px 1fr; grid-template-rows: auto 1fr; }
  .topbar { grid-column: 1 / -1; padding-left: 20px; padding-right: 20px; }
  .tabbar { position: sticky; top: calc(var(--top-h) + var(--safe-t)); grid-column: 1; grid-row: 2; display: flex; flex-direction: column; align-self: start; height: auto; padding: 14px 10px; gap: 4px; background: none; border: 0; border-right: 1px solid var(--border); min-height: calc(100dvh - var(--top-h)); backdrop-filter: none; }
  .tab { flex-direction: row; justify-content: flex-start; gap: 12px; height: 44px; padding: 0 14px; border-radius: 12px; font-size: 14px; }
  .tab.on { background: var(--surface2); }
  .tab.on::before { display: none; }
  main { grid-column: 2; padding: 22px 28px 60px; width: 100%; margin: 0; max-width: 1240px; }
  .brand span { display: inline; }
}
@media (max-width: 899px) { .brand .bn { display: none; } }

/* ---------- controls ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; padding: 12px 18px; border-radius: 13px;
  background: var(--surface3); border: 1px solid var(--border); font-weight: 650; font-size: 14.5px; min-height: 44px; transition: transform .08s, background .15s;
}
.btn:active { transform: scale(.97); }
.btn.primary { background: linear-gradient(135deg, #25f4ee, #19c7e0 40%, #fe2c55 130%); color: #04060a; border: 0; box-shadow: 0 6px 22px rgba(37, 244, 238, .18); }
.btn.danger { background: rgba(255, 83, 112, .14); color: var(--bad); border-color: rgba(255, 83, 112, .4); }
.btn.ghost { background: transparent; }
.btn.sm { padding: 8px 12px; min-height: 36px; font-size: 13px; border-radius: 10px; }
.btn.block { width: 100%; }
.btn[disabled] { opacity: .45; pointer-events: none; }
.chips { display: flex; gap: 8px; overflow-x: auto; scrollbar-width: none; padding: 2px 0; }
.chips::-webkit-scrollbar { display: none; }
.pill { padding: 8px 14px; border-radius: 999px; background: var(--surface2); border: 1px solid var(--border); font-weight: 600; font-size: 13.5px; color: var(--muted); white-space: nowrap; }
.pill.on { background: var(--text); color: #090b10; border-color: var(--text); }
.field { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; }
.field > label, .lbl { font-size: 12px; color: var(--muted); font-weight: 600; letter-spacing: .02em; }
.field .hint { font-size: 11.5px; color: var(--faint); }
input[type=text], input[type=password], input[type=number], input[type=url], input[type=search], select, textarea {
  width: 100%; background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 12px 14px; font-size: 16px; min-height: 46px; outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(37, 244, 238, .12); }
textarea { min-height: 90px; font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (max-width: 420px) { .grid2.stack { grid-template-columns: 1fr; } }

/* switch */
.sw { position: relative; display: block; width: 52px; height: 30px; flex: none; }
.sw input { position: absolute; inset: 0; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; z-index: 2; }
.sw i { position: absolute; inset: 0; background: var(--surface3); border: 1px solid var(--border); border-radius: 999px; transition: background .18s; }
.sw i::after { content: ''; position: absolute; top: 3px; left: 3px; width: 22px; height: 22px; background: #aeb5c8; border-radius: 50%; transition: transform .18s, background .18s; }
.sw input:checked + i { background: rgba(46, 230, 166, .22); border-color: rgba(46, 230, 166, .6); }
.sw input:checked + i::after { transform: translateX(22px); background: var(--good); }
.sw.busy { opacity: .5; pointer-events: none; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; }
.card + .card { margin-top: 10px; }

/* ---------- today ---------- */
.metrics { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.metric { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; position: relative; overflow: hidden; }
.metric.wide { grid-column: 1 / -1; }
.metric .lab { font-size: 12px; color: var(--muted); font-weight: 650; text-transform: uppercase; letter-spacing: .06em; display: flex; justify-content: space-between; }
.metric .big { font-size: 30px; font-weight: 750; margin-top: 6px; letter-spacing: -.03em; }
.metric .cost { margin-top: 4px; font-size: 13.5px; font-weight: 650; color: var(--muted); }
.metric .cost b { color: var(--text); font-size: 16px; }
.metric.k-spend { background: linear-gradient(160deg, rgba(37, 244, 238, .08), transparent 60%), var(--surface); }
.metric.k-pur { background: linear-gradient(160deg, rgba(254, 44, 85, .1), transparent 60%), var(--surface); }
.metric .bar { height: 5px; background: var(--surface3); border-radius: 3px; margin-top: 10px; overflow: hidden; }
.metric .bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); }
@media (min-width: 700px) { .metrics { grid-template-columns: repeat(5, 1fr); } .metric.wide { grid-column: auto; } .metric .big { font-size: 28px; } }
.mini-ad { display: flex; align-items: center; gap: 10px; padding: 12px 14px; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.mini-ad + .mini-ad { margin-top: 8px; }
.mini-ad .nm { font-weight: 600; font-size: 14px; }
.mini-ad .st { font-size: 12.5px; color: var(--muted); }
.banner { border-radius: var(--radius); padding: 12px 14px; border: 1px solid var(--border); background: var(--surface2); font-size: 13.5px; display: flex; gap: 10px; align-items: flex-start; }
.banner.warn { border-color: rgba(255, 184, 77, .5); background: rgba(255, 184, 77, .09); }
.banner.bad { border-color: rgba(255, 83, 112, .5); background: rgba(255, 83, 112, .1); }
.banner.good { border-color: rgba(46, 230, 166, .4); background: rgba(46, 230, 166, .08); }
.stack > * + * { margin-top: 10px; }

/* ---------- ads list ---------- */
.toolbar { position: sticky; top: calc(var(--top-h) + var(--safe-t)); z-index: 20; background: var(--bg); padding: 6px 0 10px; }
.list-head { display: none; }
.selecting .ad { grid-template-columns: auto 1fr auto; }
.ad { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 12px; display: grid; grid-template-columns: 1fr auto; gap: 6px 12px; align-items: center; position: relative; user-select: none; -webkit-user-select: none; }
.ad + .ad { margin-top: 8px; }
.ad.sel { border-color: var(--accent); background: rgba(37, 244, 238, .06); }
.ad.losing { box-shadow: inset 3px 0 0 var(--bad); }
.ad.off .nm { color: var(--muted); }
.ad .pick { width: 22px; height: 22px; border-radius: 7px; border: 2px solid var(--faint); display: none; place-items: center; }
.selecting .ad .pick { display: grid; }
.ad.sel .pick { background: var(--accent); border-color: var(--accent); color: #04060a; }
.ad .pick svg { width: 14px; height: 14px; stroke-width: 3; visibility: hidden; }
.ad.sel .pick svg { visibility: visible; }
.ad .nm { font-weight: 650; font-size: 14.5px; }
.ad .sub { font-size: 12px; color: var(--faint); display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
.ad .mx { grid-column: 1 / -1; display: grid; grid-template-columns: repeat(auto-fit, minmax(60px, 1fr)); gap: 8px 4px; margin-top: 4px; padding-top: 10px; border-top: 1px dashed var(--border); }
.ad .m { min-width: 0; }
.ad .m .l { font-size: 10px; color: var(--faint); text-transform: uppercase; letter-spacing: .05em; font-weight: 650; }
.ad .m .v { font-weight: 700; font-size: 14.5px; margin-top: 1px; }
.ad .m .c { font-size: 11.5px; color: var(--muted); margin-top: 1px; }
.tag { font-size: 10.5px; font-weight: 700; padding: 2px 7px; border-radius: 6px; background: var(--surface3); color: var(--muted); text-transform: uppercase; letter-spacing: .04em; }
.tag.bad { background: rgba(255, 83, 112, .15); color: var(--bad); }
.tag.warn { background: rgba(255, 184, 77, .15); color: var(--warn); }
.tag.good { background: rgba(46, 230, 166, .13); color: var(--good); }
.tag.star { background: rgba(255, 214, 80, .15); color: #ffd650; }
.bulkbar {
  position: fixed; left: 10px; right: 10px; bottom: calc(var(--tab-h) + var(--safe-b) + 10px); z-index: 45; background: var(--surface3); border: 1px solid var(--border);
  border-radius: 18px; padding: 10px; display: flex; gap: 8px; align-items: center; overflow-x: auto; box-shadow: 0 12px 40px rgba(0, 0, 0, .6);
}
.bulkbar .cnt { font-weight: 700; padding: 0 8px; white-space: nowrap; }
@media (min-width: 900px) { .bulkbar { left: 220px; right: 28px; max-width: 900px; margin: 0 auto; bottom: 20px; } }
@media (min-width: 900px) {
  .list-head, .ad, .selecting .ad { grid-template-columns: 34px minmax(190px, 1.7fr) repeat(var(--nc, 5), minmax(78px, 1fr)) 60px; }
  .list-head { display: grid; gap: 6px 12px; padding: 0 12px 8px; font-size: 11px; font-weight: 700; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }
  .list-head button { text-align: left; color: inherit; font: inherit; text-transform: inherit; letter-spacing: inherit; }
  .list-head button.on { color: var(--accent); }
  .ad { padding: 10px 12px; align-items: center; }
  .ad .mx { display: contents; border: 0; padding: 0; margin: 0; }
  .ad .m .l { display: none; }
  .ad .pickcell { order: -1; }
  .ad > .toggle-cell { order: 99; justify-self: end; }
  .ad .main { min-width: 0; }
  .ad .pick { display: grid; border-color: var(--border); visibility: hidden; }
  .selecting .ad .pick { visibility: visible; }
  .mobile-sort { display: none !important; }
}

/* ---------- launch ---------- */
.cgrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 10px; }
.ctile { background: var(--surface); border: 2px solid var(--border); border-radius: var(--radius); overflow: hidden; position: relative; }
.ctile.sel { border-color: var(--accent); }
.ctile.dead { opacity: .55; }
.ctile .thumb { aspect-ratio: 4/5; background: linear-gradient(160deg, #1b2030, #0d1017); position: relative; display: grid; place-items: center; overflow: hidden; }
.ctile video { width: 100%; height: 100%; object-fit: cover; display: block; }
.ctile .ph { color: var(--faint); font-size: 12px; text-align: center; padding: 10px; }
.ctile .ck { position: absolute; top: 8px; left: 8px; width: 24px; height: 24px; border-radius: 8px; background: rgba(0, 0, 0, .55); border: 2px solid #fff6; display: grid; place-items: center; }
.ctile.sel .ck { background: var(--accent); border-color: var(--accent); color: #04060a; }
.ctile .ck svg { width: 14px; height: 14px; stroke-width: 3; display: none; }
.ctile.sel .ck svg { display: block; }
.ctile .play { position: absolute; right: 8px; top: 8px; width: 30px; height: 30px; border-radius: 50%; background: rgba(0, 0, 0, .55); display: grid; place-items: center; }
.ctile .play svg { width: 14px; height: 14px; }
.ctile .info { padding: 9px 10px 10px; }
.ctile .cn { font-weight: 650; font-size: 13px; }
.ctile .cs { font-size: 11.5px; color: var(--muted); margin-top: 2px; }
.stepper { display: flex; align-items: center; gap: 0; margin-top: 8px; background: var(--surface2); border-radius: 10px; border: 1px solid var(--border); overflow: hidden; }
.stepper button { width: 36px; height: 36px; font-size: 18px; font-weight: 700; color: var(--text); }
.stepper input { text-align: center; border: 0; background: transparent; min-height: 36px; padding: 0; width: 100%; border-radius: 0; font-weight: 700; }
.stepper input:focus { box-shadow: none; }
.upload-tile { aspect-ratio: auto; min-height: 180px; border: 2px dashed var(--border); border-radius: var(--radius); display: grid; place-items: center; color: var(--muted); text-align: center; padding: 14px; font-weight: 600; font-size: 13.5px; }
.upload-tile:active { background: var(--surface2); }
.summary-bar {
  position: fixed; left: 10px; right: 10px; bottom: calc(var(--tab-h) + var(--safe-b) + 10px); z-index: 44; background: #1a1f2c; border: 1px solid var(--border); border-radius: 18px;
  padding: 10px 10px 10px 16px; display: flex; gap: 10px; align-items: center; box-shadow: 0 12px 40px rgba(0, 0, 0, .65);
}
@media (min-width: 900px) { .summary-bar { left: 220px; right: 28px; max-width: 900px; margin: 0 auto; bottom: 20px; } }
.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
@media (min-width: 900px) { .tools { grid-template-columns: repeat(4, 1fr); } }
.tool { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 14px; text-align: left; display: flex; flex-direction: column; gap: 6px; min-height: 96px; }
.tool:active { background: var(--surface2); }
.tool b { font-size: 14px; }
.tool span { font-size: 12px; color: var(--muted); }
.tool svg { color: var(--accent); }
.progress { height: 10px; background: var(--surface3); border-radius: 6px; overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent2)); transition: width .3s; }
.logbox { background: var(--surface2); border-radius: 12px; padding: 10px 12px; font-size: 12px; color: var(--muted); max-height: 160px; overflow: auto; font-family: ui-monospace, Menlo, monospace; }

/* ---------- sheet / toast ---------- */
.overlay { position: fixed; inset: 0; background: rgba(0, 0, 0, .6); z-index: 90; opacity: 0; transition: opacity .2s; }
.overlay.show { opacity: 1; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 91; background: var(--surface); border-top-left-radius: 24px; border-top-right-radius: 24px; border: 1px solid var(--border); border-bottom: 0;
  max-height: 92dvh; display: flex; flex-direction: column; transform: translateY(100%); transition: transform .26s cubic-bezier(.2, .8, .2, 1); padding-bottom: var(--safe-b);
  max-width: 640px; margin: 0 auto;
}
.sheet.show { transform: none; }
.sheet .grab { width: 40px; height: 4px; background: var(--border); border-radius: 2px; margin: 8px auto 2px; }
.sheet .sh-head { display: flex; align-items: center; justify-content: space-between; padding: 8px 18px 6px; gap: 10px; }
.sheet .sh-head h3 { font-size: 18px; margin: 0; }
.sheet .sh-body { overflow-y: auto; padding: 8px 18px 20px; -webkit-overflow-scrolling: touch; }
@media (min-width: 900px) { .sheet { bottom: auto; top: 50%; border-radius: 22px; border-bottom: 1px solid var(--border); transform: translateY(-46%) scale(.97); opacity: 0; transition: transform .2s, opacity .2s; max-height: 86dvh; left: 50%; right: auto; width: 620px; margin-left: -310px; } .sheet.show { transform: translateY(-50%); opacity: 1; } .sheet .grab { display: none; } }

#toasts { position: fixed; left: 12px; right: 12px; bottom: calc(var(--tab-h) + var(--safe-b) + 16px); z-index: 120; display: flex; flex-direction: column; gap: 8px; align-items: center; pointer-events: none; }
.toast { pointer-events: auto; background: #2a3042; border: 1px solid var(--border); border-radius: 14px; padding: 11px 14px; display: flex; gap: 12px; align-items: center; max-width: 520px; width: 100%; box-shadow: 0 10px 30px rgba(0, 0, 0, .5); animation: tin .22s ease; font-size: 14px; }
.toast.err { border-color: rgba(255, 83, 112, .6); }
.toast .undo { margin-left: auto; color: var(--accent); font-weight: 700; padding: 6px 4px; }
@keyframes tin { from { transform: translateY(14px); opacity: 0; } }

/* ---------- settings ---------- */
.sect { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; overflow: hidden; }
.sect > summary { list-style: none; padding: 16px; display: flex; align-items: center; gap: 12px; font-weight: 650; cursor: pointer; }
.sect > summary::-webkit-details-marker { display: none; }
.sect > summary .ch { margin-left: auto; transition: transform .2s; color: var(--faint); }
.sect[open] > summary .ch { transform: rotate(90deg); }
.sect > .in { padding: 4px 16px 16px; border-top: 1px solid var(--border); padding-top: 14px; }
.rule { background: var(--surface2); border-radius: 12px; padding: 12px; display: flex; align-items: center; gap: 12px; }
.rule + .rule { margin-top: 8px; }
.seg { display: inline-flex; background: var(--surface2); border: 1px solid var(--border); border-radius: 12px; padding: 3px; }
.seg button { padding: 8px 16px; border-radius: 9px; font-weight: 650; font-size: 13.5px; color: var(--muted); }
.seg button.on { background: var(--text); color: #090b10; }
.kv { display: flex; justify-content: space-between; gap: 12px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: 13.5px; }
.kv:last-child { border: 0; }
.login { min-height: 100dvh; display: grid; place-items: center; padding: 20px; }
.login .box { width: 100%; max-width: 380px; }
.login .logo { width: 56px; height: 56px; border-radius: 18px; margin-bottom: 16px; }
.login .logo svg { width: 30px; height: 30px; }
.empty { text-align: center; padding: 36px 16px; color: var(--muted); }
.spinner { width: 20px; height: 20px; border: 2.5px solid var(--border); border-top-color: var(--accent); border-radius: 50%; animation: spin .7s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.demo-ribbon { background: linear-gradient(90deg, rgba(254, 44, 85, .18), rgba(37, 244, 238, .14)); border: 1px solid var(--border); border-radius: 12px; padding: 9px 12px; font-size: 12.5px; margin-bottom: 12px; }
