:root {
  --bg: var(--tg-theme-bg-color, #ffffff);
  --bg2: var(--tg-theme-secondary-bg-color, #f2f2f5);
  --text: var(--tg-theme-text-color, #111111);
  --hint: var(--tg-theme-hint-color, #8a8a8e);
  --accent: var(--tg-theme-button-color, #fe2c55);
  --accent-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, #2a7de1);
  --danger: #e5484d;
  --ok: #30a46c;
  --line: color-mix(in srgb, var(--text) 12%, transparent);
  --radius: 12px;
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: var(--tg-theme-bg-color, #17171a);
    --bg2: var(--tg-theme-secondary-bg-color, #222226);
    --text: var(--tg-theme-text-color, #f2f2f2);
  }
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
body { padding: 12px 16px 40px; max-width: 760px; margin: 0 auto; }
h1 { font-size: 20px; margin: 4px 0 12px; }
h2 { font-size: 16px; margin: 18px 0 8px; }
.hint { color: var(--hint); font-size: 13px; }
.card { background: var(--bg2); border-radius: var(--radius); padding: 12px; margin: 10px 0; }
.row { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.row > * { min-width: 0; }
.grow { flex: 1; }
button, .btn { appearance: none; border: 0; border-radius: 10px; padding: 9px 14px; font: inherit; cursor: pointer;
  background: var(--accent); color: var(--accent-text); }
button.secondary { background: var(--bg2); color: var(--text); border: 1px solid var(--line); }
button.danger { background: var(--danger); color: #fff; }
button.small { padding: 5px 9px; font-size: 13px; }
button:disabled { opacity: .5; cursor: default; }
input, select, textarea { font: inherit; color: var(--text); background: var(--bg); border: 1px solid var(--line);
  border-radius: 8px; padding: 7px 9px; width: 100%; }
input[type=color] { padding: 2px; height: 34px; width: 48px; }
input[type=checkbox] { width: auto; }
input[type=range] { padding: 0; }
label { display: block; font-size: 13px; color: var(--hint); margin: 8px 0 3px; }
label.inline { display: flex; gap: 6px; align-items: center; color: var(--text); font-size: 14px; margin: 6px 0; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 10px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 0 10px; }
.progress { height: 8px; background: var(--line); border-radius: 4px; overflow: hidden; }
.progress > div { height: 100%; background: var(--accent); width: 0; transition: width .2s; }
.toast { position: fixed; left: 16px; right: 16px; bottom: 16px; padding: 12px 14px; border-radius: 10px;
  background: #222; color: #fff; z-index: 99; box-shadow: 0 6px 24px #0005; }
.toast.error { background: var(--danger); }
.toast.ok { background: var(--ok); }
.stat { background: var(--bg2); border-radius: 10px; padding: 8px 10px; }
.stat b { display: block; font-size: 20px; }
.stats { display: grid; grid-template-columns: repeat(auto-fill, minmax(100px, 1fr)); gap: 8px; }
.feed { height: 46vh; overflow-y: auto; background: var(--bg2); border-radius: var(--radius); padding: 8px; }
.feed div { padding: 3px 2px; border-bottom: 1px solid var(--line); word-wrap: break-word; }
.feed .gift { color: #d18b00; }
.feed .follow { color: var(--ok); }
.list .item { display: flex; gap: 8px; align-items: center; padding: 8px; border-radius: 10px; }
.list .item.sel { background: color-mix(in srgb, var(--accent) 16%, transparent); }
.badge { font-size: 11px; padding: 1px 6px; border-radius: 6px; background: var(--line); color: var(--hint); }
.modal { position: fixed; inset: 0; background: #000c; display: flex; align-items: center; justify-content: center;
  z-index: 50; padding: 16px; }
.modal img { max-width: 100%; max-height: 90vh; border-radius: 8px; }
.modal .panel { background: var(--bg); color: var(--text); border-radius: var(--radius); padding: 14px;
  width: 100%; max-width: 420px; max-height: 85vh; overflow: auto; }

/* editor stage */
.stage-wrap { display: flex; justify-content: center; }
.stage { position: relative; overflow: hidden; background: #000; border-radius: 8px; touch-action: none; isolation: isolate;
  box-shadow: 0 2px 16px #0003; user-select: none; -webkit-user-select: none; }
.stage .lyr { position: absolute; transform-origin: center center; pointer-events: none; }
.stage .hit { position: absolute; transform-origin: center center; }
.stage .hit.sel { outline: 2px solid #00e0ff; outline-offset: 0; }
.stage .handle { position: absolute; width: 22px; height: 22px; border-radius: 50%; background: #00e0ff;
  border: 2px solid #fff; display: none; }
.stage .hit.sel .handle { display: block; }
.stage .handle.resize { right: -11px; bottom: -11px; cursor: nwse-resize; }
.stage .handle.rotate { left: 50%; top: -34px; margin-left: -11px; cursor: grab; background: #ffcc00; }
.ticker { background-repeat: repeat-x; }
