:root {
  --bg:      var(--tg-theme-bg-color, #0e1014);
  --surface: var(--tg-theme-secondary-bg-color, #171a20);
  --text:    var(--tg-theme-text-color, #e8ebf0);
  --muted:   var(--tg-theme-hint-color, #7c8492);
  --link:    var(--tg-theme-link-color, #5aa2f0);
  --btn:     var(--tg-theme-button-color, #2f7fe0);
  --btn-tx:  var(--tg-theme-button-text-color, #ffffff);

  --signal:  #ffb020;
  --ok:      #35b880;
  --bad:     #ff6b6b;
  --line:    color-mix(in srgb, var(--muted) 26%, transparent);

  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 24px; --s6: 32px;
  --r: 14px;

  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, monospace;
  --ui: "Inter Tight", -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

/* The browser's default [hidden] rule is display:none, but the author styles
   below set display on .sheet, .modal and .scrim — and author styles win.
   Without !important those panels render on load with no handlers attached,
   which looks like a frozen dialog. */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding-bottom: 96px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--ui);
  font-size: 15px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; letter-spacing: -0.02em; }

.eyebrow {
  margin: 0 0 2px;
  font-family: var(--mono);
  font-size: 10px; font-weight: 500;
  letter-spacing: 0.14em; text-transform: uppercase;
  color: var(--muted);
}

/* ---------------------------------------------------------- header */

.console { padding: var(--s5) var(--s4) var(--s3); border-bottom: 1px solid var(--line); }
.console__row { display: flex; align-items: flex-start; justify-content: space-between; gap: var(--s3); }
.account { font-size: 22px; font-weight: 800; letter-spacing: -0.03em; }

.chip {
  flex: none; padding: 3px 9px;
  border: 1px solid var(--line); border-radius: 999px;
  font-family: var(--mono); font-size: 10px;
  letter-spacing: 0.08em; text-transform: uppercase; color: var(--muted);
}
.chip--premium { color: var(--signal); border-color: color-mix(in srgb, var(--signal) 45%, transparent); }

.statusline { margin: var(--s3) 0 0; font-family: var(--mono); font-size: 12px; color: var(--muted); }
.statusline b { color: var(--signal); font-weight: 500; }

.gauge { position: relative; height: 14px; margin-top: var(--s2); border-radius: 7px; background: var(--surface); overflow: hidden; }
.gauge__fill { height: 100%; width: 0; background: color-mix(in srgb, var(--signal) 55%, transparent); transition: width .4s ease; }
.gauge__label { position: absolute; inset: 0; display: grid; place-items: center; font-family: var(--mono); font-size: 9px; letter-spacing: .08em; color: var(--text); }

/* ---------------------------------------------------------- tabs */

.tabs {
  display: flex; gap: var(--s5);
  overflow-x: auto; scrollbar-width: none;
  padding: 0 var(--s4);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5; background: var(--bg);
}
.tab {
  appearance: none; background: none; border: 0;
  border-bottom: 2px solid transparent;
  padding: var(--s3) 0; margin-bottom: -1px;
  color: var(--muted); font-family: var(--ui);
  font-size: 14px; font-weight: 500; cursor: pointer;
}
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; }
.tab.is-active { color: var(--text); border-bottom-color: var(--signal); }

.view { padding: var(--s4); display: grid; gap: var(--s3); }

/* ---------------------------------------------------------- cards */

.card { background: var(--surface); border: 1px solid transparent; border-radius: var(--r); padding: var(--s4); }
.card--armed { border-color: color-mix(in srgb, var(--signal) 38%, transparent); }
.card__top { display: flex; justify-content: space-between; align-items: baseline; gap: var(--s3); }
.card__name { font-size: 17px; font-weight: 600; }
.card__preview {
  margin: var(--s2) 0 0; color: var(--muted); font-size: 13px;
  overflow: hidden; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.card__meta { margin-top: var(--s3); display: flex; flex-wrap: wrap; gap: var(--s1) var(--s4); font-family: var(--mono); font-size: 11px; color: var(--muted); }
.card__meta b { color: var(--text); font-weight: 500; }
.card__actions { display: flex; gap: var(--s2); margin-top: var(--s4); }

.warn {
  margin-top: var(--s3); padding: var(--s2) var(--s3);
  border-radius: 8px; font-size: 12px;
  background: color-mix(in srgb, var(--signal) 14%, transparent);
  color: var(--signal);
}

.rail { display: flex; gap: 2px; margin-top: var(--s3); height: 3px; }
.rail i { flex: 1; background: var(--line); border-radius: 2px; transition: background .2s; }
.rail i.on { background: var(--signal); }
.rail--idle i.on { background: color-mix(in srgb, var(--signal) 40%, transparent); }

.state { font-family: var(--mono); font-size: 10px; letter-spacing: 0.12em; text-transform: uppercase; white-space: nowrap; }
.state--armed { color: var(--signal); }
.state--paused { color: var(--muted); }
.state--posting { color: var(--ok); }

/* ---------------------------------------------------------- rows */

.row { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) var(--s4); background: var(--surface); border-radius: var(--r); }
.row__main { min-width: 0; flex: 1; }
.row__title { font-size: 15px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__sub { font-family: var(--mono); font-size: 11px; color: var(--muted); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row__sub.bad { color: var(--bad); }
.row--off .row__title { color: var(--muted); }
.row__tags { display: flex; gap: 4px; margin-top: 3px; flex-wrap: wrap; }
.tagpill { font-family: var(--mono); font-size: 9px; letter-spacing: .06em; text-transform: uppercase; padding: 1px 6px; border-radius: 999px; background: color-mix(in srgb, var(--link) 20%, transparent); color: var(--link); }

/* ---------------------------------------------------------- virtual list */

.vlist { position: relative; overflow-y: auto; overscroll-behavior: contain; -webkit-overflow-scrolling: touch; }
.vlist--page { height: calc(100vh - 250px); }
.vlist__spacer { position: relative; width: 100%; }
.vlist__row { position: absolute; left: 0; right: 0; }

/* ---------------------------------------------------------- log */

.log { display: grid; gap: 1px; font-family: var(--mono); font-size: 12px; }
.log__line { display: grid; grid-template-columns: 52px 58px 1fr; gap: var(--s2); padding: 7px 0; border-bottom: 1px solid var(--line); }
.log__t { color: var(--muted); }
.log__s { letter-spacing: 0.06em; text-transform: uppercase; font-size: 10px; align-self: center; }
.log__s.sent { color: var(--ok); }
.log__s.failed { color: var(--bad); }
.log__s.skipped, .log__s.info { color: var(--muted); }
.log__d { overflow: hidden; text-overflow: ellipsis; }

/* ---------------------------------------------------------- controls */

button { font-family: var(--ui); }

.btn { appearance: none; border: 0; border-radius: 10px; padding: 9px 14px; font-size: 13px; font-weight: 500; background: var(--btn); color: var(--btn-tx); cursor: pointer; }
.btn--quiet { background: color-mix(in srgb, var(--muted) 18%, transparent); color: var(--text); }
.btn--danger { background: color-mix(in srgb, var(--bad) 20%, transparent); color: var(--bad); }
.btn--wide { width: 100%; padding: 13px; font-size: 15px; }
.btn:disabled { opacity: .45; }

.ghost { appearance: none; background: none; border: 0; color: var(--link); font-size: 14px; cursor: pointer; padding: 4px; }

.fab {
  position: fixed; left: var(--s4); right: var(--s4);
  bottom: calc(var(--s4) + env(safe-area-inset-bottom));
  z-index: 6; padding: 15px; border: 0; border-radius: 12px;
  background: var(--btn); color: var(--btn-tx);
  font-size: 15px; font-weight: 600; cursor: pointer;
  box-shadow: 0 8px 24px rgba(0,0,0,.35);
}

label { display: block; }
.field { margin-bottom: var(--s4); }
.field > .eyebrow { margin-bottom: var(--s2); }

input[type=text], input[type=number], textarea, select {
  width: 100%; padding: 11px 12px;
  background: var(--bg); border: 1px solid var(--line); border-radius: 10px;
  color: var(--text); font-family: var(--ui); font-size: 15px;
}
textarea { min-height: 130px; font-family: var(--mono); font-size: 13px; resize: vertical; }
input:focus-visible, textarea:focus-visible, select:focus-visible, button:focus-visible {
  outline: 2px solid var(--signal); outline-offset: 2px;
}

.hint { margin: var(--s2) 0 0; font-size: 12px; color: var(--muted); }
.hint code { font-family: var(--mono); font-size: 11px; }

.seg { display: flex; border: 1px solid var(--line); border-radius: 10px; overflow: hidden; }
.seg button { flex: 1; padding: 10px; border: 0; background: none; color: var(--muted); font-size: 13px; cursor: pointer; }
.seg button.on { background: color-mix(in srgb, var(--signal) 16%, transparent); color: var(--signal); }

.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: var(--s3); }

.switch { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); padding: var(--s3) 0; border-bottom: 1px solid var(--line); }
.switch span { font-size: 14px; }
.switch input { width: 44px; height: 26px; }

.chips { display: flex; gap: var(--s2); overflow-x: auto; padding-bottom: var(--s1); scrollbar-width: none; }
.chips::-webkit-scrollbar { display: none; }
.chips button {
  flex: none; padding: 6px 12px; border-radius: 999px;
  border: 1px solid var(--line); background: none;
  color: var(--muted); font-size: 12px; white-space: nowrap; cursor: pointer;
}
.chips button.on { background: color-mix(in srgb, var(--signal) 18%, transparent); color: var(--signal); border-color: transparent; }

.picker { max-height: 260px; }
.picker label { display: flex; gap: var(--s3); align-items: center; padding: 10px 12px; border-bottom: 1px solid var(--line); }
.picker input { width: 18px; height: 18px; flex: none; }
.picker span { font-size: 14px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.picker__head { display: flex; align-items: center; gap: var(--s2); margin-bottom: var(--s2); }
.picker__head input { flex: 1; padding: 8px 10px; font-size: 14px; }
.picker__count { font-family: var(--mono); font-size: 11px; color: var(--signal); white-space: nowrap; }
.boxed { border: 1px solid var(--line); border-radius: 10px; }

.empty { text-align: center; padding: var(--s6) var(--s4); color: var(--muted); }
.empty h3 { color: var(--text); margin-bottom: var(--s2); }

/* ---------------------------------------------------------- skeletons */

.skel { border-radius: var(--r); background: var(--surface); overflow: hidden; position: relative; }
.skel::after {
  content: ''; position: absolute; inset: 0;
  background: linear-gradient(90deg, transparent, color-mix(in srgb, var(--muted) 12%, transparent), transparent);
  animation: sweep 1.3s infinite;
}
@keyframes sweep { from { transform: translateX(-100%) } to { transform: translateX(100%) } }
.skel--card { height: 148px; }
.skel--row { height: 62px; }

/* ---------------------------------------------------------- ad editor */

.toolbar { display: flex; flex-wrap: wrap; gap: var(--s1); margin-bottom: var(--s2); }
.toolbar button {
  appearance: none; padding: 6px 10px;
  border: 1px solid var(--line); border-radius: 8px; background: none;
  color: var(--muted); font-family: var(--mono); font-size: 11px; cursor: pointer;
}
.toolbar button:active { background: color-mix(in srgb, var(--signal) 16%, transparent); }
.toolbar button.accent { color: var(--signal); border-color: color-mix(in srgb, var(--signal) 45%, transparent); }

.thumbs { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }
.thumb { position: relative; width: 62px; height: 62px; border-radius: 10px; overflow: hidden; background: var(--surface); }
.thumb img { width: 100%; height: 100%; object-fit: cover; }
.thumb button { position: absolute; top: 2px; right: 2px; width: 20px; height: 20px; padding: 0; border: 0; border-radius: 50%; background: rgba(0,0,0,.65); color: #fff; font-size: 13px; line-height: 20px; cursor: pointer; }
.thumb--add { display: grid; place-items: center; border: 1px dashed var(--line); color: var(--muted); font-size: 22px; cursor: pointer; }
.thumb--add input { display: none; }

.bubble { margin-top: var(--s2); padding: var(--s3); border-radius: 4px 14px 14px 14px; background: var(--surface); font-size: 14px; white-space: pre-wrap; word-break: break-word; }
.bubble:empty::after { content: 'Nothing to preview yet.'; color: var(--muted); }
.bubble img.ce { width: 1.15em; height: 1.15em; vertical-align: -0.18em; }
.bubble .spoiler { background: var(--muted); border-radius: 3px; color: transparent; }
.bubble .spoiler:active { background: none; color: inherit; }
.bubble .lnk { color: var(--link); }
.bubble blockquote { margin: 4px 0; padding-left: 10px; border-left: 2px solid var(--signal); }
.bubble code, .bubble pre { font-family: var(--mono); font-size: 12px; }
.bubble .shots { display: flex; gap: 4px; margin-bottom: var(--s2); }
.bubble .shots img { width: 64px; height: 64px; border-radius: 8px; object-fit: cover; }

/* ---------------------------------------------------------- emoji picker */

.sheet--short { inset: 42% 0 0; }
.emoji-pack { margin-bottom: var(--s4); }
.emoji-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: var(--s1); margin-top: var(--s2); }
.emoji-grid button { aspect-ratio: 1; display: grid; place-items: center; border: 0; border-radius: 8px; background: var(--surface); font-size: 22px; line-height: 1; cursor: pointer; }
.emoji-grid img { width: 28px; height: 28px; }

/* ---------------------------------------------------------- modal */

.modal { position: fixed; inset: 0; z-index: 40; display: grid; place-items: center; background: rgba(0,0,0,.55); padding: var(--s4); }
.modal__box { width: 100%; max-width: 340px; padding: var(--s4); border-radius: 14px; background: var(--bg); border: 1px solid var(--line); }
.modal__box h3 { margin-bottom: var(--s3); font-size: 16px; }
.modal__row { display: flex; gap: var(--s2); margin-top: var(--s4); }
.modal__row .btn { flex: 1; }

/* ---------------------------------------------------------- sheet */

.sheet {
  position: fixed; inset: 8% 0 0; z-index: 20;
  background: var(--bg); border-radius: 20px 20px 0 0; border-top: 1px solid var(--line);
  display: flex; flex-direction: column; animation: rise .22s ease-out;
}
@keyframes rise { from { transform: translateY(14px); opacity: 0 } }
.sheet__grip { width: 36px; height: 4px; border-radius: 3px; background: var(--line); margin: var(--s2) auto 0; }
.sheet__head { display: flex; align-items: center; justify-content: space-between; padding: var(--s3) var(--s4); border-bottom: 1px solid var(--line); }
.sheet__body { padding: var(--s4); overflow-y: auto; padding-bottom: calc(var(--s6) + env(safe-area-inset-bottom)); }

.scrim { position: fixed; inset: 0; z-index: 15; background: rgba(0,0,0,.5); }

.toast {
  position: fixed; left: 50%; bottom: calc(84px + env(safe-area-inset-bottom));
  transform: translateX(-50%); z-index: 30;
  display: flex; align-items: center; gap: var(--s3);
  max-width: 88vw; padding: 10px 16px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--line);
  font-size: 13px; box-shadow: 0 10px 30px rgba(0,0,0,.4);
}
.toast.bad { color: var(--bad); border-color: color-mix(in srgb, var(--bad) 40%, transparent); }
.toast button { background: none; border: 0; color: var(--link); font-size: 13px; font-weight: 600; cursor: pointer; }

.draft { border-left: 2px solid var(--signal); }

@media (prefers-reduced-motion: reduce) { * { animation: none !important; transition: none !important; } }

/* ---------------------------------------------------------- rails */

.rail-group { margin-bottom: var(--s5); }
.rail-group__blurb { margin: var(--s1) 0 var(--s3); font-size: 13px; color: var(--muted); }
.rail-item { padding: var(--s4) 0; border-bottom: 1px solid var(--line); }
.rail-item:last-child { border-bottom: 0; }
.rail-item__head { display: flex; align-items: center; justify-content: space-between; gap: var(--s3); }
.rail-item__label { font-size: 15px; font-weight: 500; }
.rail-item__desc { margin: var(--s2) 0 0; font-size: 12.5px; line-height: 1.5; color: var(--muted); }
.rail-item__input { display: flex; align-items: center; gap: var(--s2); flex: none; }
.rail-item__input input[type=number] { width: 84px; text-align: right; font-family: var(--mono); font-size: 14px; padding: 8px 10px; }
.rail-item__unit { font-family: var(--mono); font-size: 10px; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); min-width: 52px; }
.rail-item__range { font-family: var(--mono); font-size: 10px; color: var(--muted); margin-top: var(--s1); }
.rail-dirty { color: var(--signal); }

.toggle { position: relative; width: 46px; height: 27px; flex: none; }
.toggle input { position: absolute; opacity: 0; width: 100%; height: 100%; margin: 0; cursor: pointer; }
.toggle span { position: absolute; inset: 0; border-radius: 999px; background: color-mix(in srgb, var(--muted) 30%, transparent); transition: background .18s; pointer-events: none; }
.toggle span::after { content: ''; position: absolute; top: 3px; left: 3px; width: 21px; height: 21px; border-radius: 50%; background: #fff; transition: transform .18s; }
.toggle input:checked + span { background: var(--signal); }
.toggle input:checked + span::after { transform: translateX(19px); }

/* ---------------------------------------------------------- onboarding */

.onboard { padding: var(--s5) var(--s4); max-width: 460px; margin: 0 auto; }
.onboard h2 { font-size: 24px; font-weight: 800; letter-spacing: -0.03em; margin-bottom: var(--s2); }
.onboard__lede { color: var(--muted); font-size: 14px; margin: 0 0 var(--s5); line-height: 1.55; }
.onboard__step { font-family: var(--mono); font-size: 10px; letter-spacing: .14em; text-transform: uppercase; color: var(--signal); margin-bottom: var(--s3); }
.onboard input { font-size: 17px; padding: 14px; text-align: center; letter-spacing: .04em; }
.onboard input[inputmode=numeric] { font-family: var(--mono); letter-spacing: .3em; }
.onboard .btn--wide { margin-top: var(--s4); }
.onboard__note { margin-top: var(--s4); padding: var(--s3); border-radius: 10px; background: var(--surface); font-size: 12.5px; line-height: 1.55; color: var(--muted); }
.onboard__back { margin-top: var(--s3); text-align: center; }

.danger-note {
  margin-top: var(--s3); padding: var(--s3);
  border-radius: 10px; font-size: 12.5px; line-height: 1.55;
  background: color-mix(in srgb, var(--bad) 12%, transparent);
  color: var(--bad);
}

.secret {
  margin-top: var(--s3); padding: var(--s3);
  border-radius: 10px; background: var(--bg); border: 1px solid var(--line);
  font-family: var(--mono); font-size: 11px; line-height: 1.5;
  word-break: break-all; user-select: all;
}

/* ---------------------------------------------------------- scheduling */

.times { display: flex; flex-wrap: wrap; gap: var(--s2); margin-top: var(--s2); }
.time-chip {
  display: inline-flex; align-items: center; gap: var(--s2);
  padding: 6px 10px 6px 12px; border-radius: 999px;
  background: color-mix(in srgb, var(--signal) 16%, transparent);
  color: var(--signal); font-family: var(--mono); font-size: 12px;
}
.time-chip button { background: none; border: 0; color: inherit; font-size: 15px; line-height: 1; cursor: pointer; padding: 0 2px; }

.days { display: flex; gap: var(--s1); margin-top: var(--s2); }
.days button {
  flex: 1; padding: 8px 0; border: 1px solid var(--line); border-radius: 8px;
  background: none; color: var(--muted);
  font-family: var(--mono); font-size: 11px; cursor: pointer;
}
.days button.on { background: color-mix(in srgb, var(--signal) 18%, transparent); color: var(--signal); border-color: transparent; }

.plan {
  margin-top: var(--s3); padding: var(--s3);
  border-radius: 10px; background: var(--surface);
  font-family: var(--mono); font-size: 11.5px; line-height: 1.7; color: var(--muted);
}
.plan b { color: var(--text); font-weight: 500; }
.plan .stamp { color: var(--signal); }
.plan--warn { background: color-mix(in srgb, var(--bad) 12%, transparent); color: var(--bad); }

.gdetail { display: grid; gap: var(--s3); }
.gstat { display: flex; justify-content: space-between; font-family: var(--mono); font-size: 11px; color: var(--muted); }
.gstat b { color: var(--text); font-weight: 500; }
.pill-row { display: flex; gap: var(--s2); flex-wrap: wrap; }
.pill-row button {
  padding: 7px 12px; border: 1px solid var(--line); border-radius: 999px;
  background: none; color: var(--muted); font-size: 12px; cursor: pointer;
}
.pill-row button.on { background: color-mix(in srgb, var(--signal) 18%, transparent); color: var(--signal); border-color: transparent; }
.row--paused { opacity: .55; }
