:root {
  --bg: var(--tg-theme-bg-color, #17212b);
  --bg2: var(--tg-theme-secondary-bg-color, #0e1621);
  --text: var(--tg-theme-text-color, #f5f5f5);
  --hint: var(--tg-theme-hint-color, #8696a4);
  --link: var(--tg-theme-link-color, #6ab3f3);
  --btn: var(--tg-theme-button-color, #5288c1);
  --btn-text: var(--tg-theme-button-text-color, #ffffff);
  --line: rgba(127, 127, 127, .25);
  --bubble: var(--tg-theme-secondary-bg-color, #182533);
}
* { box-sizing: border-box; }
html, body { margin: 0; background: var(--bg2); color: var(--text);
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif; }
.hidden { display: none !important; }
#app { margin: 0 auto; padding: calc(8px + var(--safe-top, 0px)) 10px 40px; max-width: 760px; }
.brand { display: none; font-weight: 700; letter-spacing: .02em; margin-right: auto; }
.tabs .icon { flex: 0 0 auto; padding: 8px 10px; }
.card-title { font-weight: 600; margin-bottom: 4px; }
.empty { display: flex; align-items: center; justify-content: center; color: var(--hint); min-height: 50vh;
  border: 1px dashed var(--line); border-radius: 14px; }
h2.section { margin: 18px 4px 8px; font-size: 14px; color: var(--hint); text-transform: uppercase; letter-spacing: .04em; }
button { background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 10px;
  padding: 8px 12px; font: inherit; cursor: pointer; }
button:active { opacity: .7; }
button.primary { background: var(--btn); color: var(--btn-text); border-color: transparent; }
input, textarea, select { width: 100%; background: var(--bg); color: var(--text); border: 1px solid var(--line);
  border-radius: 10px; padding: 9px 11px; font: inherit; }
textarea { resize: vertical; }
.row { display: flex; gap: 8px; align-items: center; margin: 8px 0; }
.row.wrap { flex-wrap: wrap; }
.row.top { justify-content: space-between; }
.card { background: var(--bg); border-radius: 14px; padding: 10px; margin: 10px 0; }
.muted { color: var(--hint); }
.small { font-size: 13px; }
.error { color: #ef5b5b; }
.tabs { display: flex; gap: 6px; position: sticky; top: 0; background: var(--bg2); padding: 6px 0; z-index: 5; }
.tabs button { flex: 1; }
.tabs button.active { background: var(--btn); color: var(--btn-text); }

.draft-item { background: var(--bg); border-radius: 12px; padding: 10px 12px; margin: 6px 0; cursor: pointer; }
.draft-item .t { font-weight: 600; }
.draft-item .m { color: var(--hint); font-size: 13px; }

.toolbar { display: flex; gap: 4px; flex-wrap: wrap; position: sticky; top: 44px; background: var(--bg2);
  padding: 4px 0; z-index: 4; }
.toolbar button { padding: 6px 10px; min-width: 38px; }
.post { background: var(--bubble); border-radius: 14px 14px 14px 4px; padding: 12px 14px; min-height: 160px;
  white-space: pre-wrap; word-wrap: break-word; outline: none; line-height: 1.45; }
.post:focus { box-shadow: 0 0 0 2px var(--btn); }
.post a { color: var(--link); }
.post blockquote { margin: 4px 0; padding: 4px 10px; border-left: 3px solid var(--link); background: rgba(106, 179, 243, .08);
  border-radius: 6px; white-space: pre-wrap; }
.post .spoiler { background: var(--hint); color: transparent; border-radius: 4px; }
.post .spoiler:hover { color: inherit; background: rgba(127, 127, 127, .3); }
.tge { display: inline-block; width: 1.25em; height: 1.25em; vertical-align: -0.25em; line-height: 1.25em;
  text-align: center; user-select: all; }
.tge img, .tge video, .tge svg { width: 100% !important; height: 100% !important; object-fit: contain; }

#checks .warn { background: rgba(239, 91, 91, .12); color: #ef8b8b; border-radius: 8px; padding: 6px 10px; margin: 6px 0; font-size: 13px; }
.notes { background: rgba(227, 179, 65, .1); border-radius: 8px; padding: 8px 10px; margin: 8px 0;
  font-size: 13px; white-space: pre-wrap; }
.actions button { flex: 1; }

.emoji-row { display: grid; grid-template-columns: 44px 1fr; gap: 8px; background: var(--bg); border-radius: 12px;
  padding: 8px; margin: 6px 0; align-items: start; }
.emoji-row .big { width: 40px; height: 40px; font-size: 30px; }
.emoji-row .fields { display: grid; gap: 6px; }
.emoji-row .meta { color: var(--hint); font-size: 12px; }
.emoji-row .fields .row { margin: 0; }

.modal { position: fixed; inset: 0; background: rgba(0, 0, 0, .5); z-index: 20; display: flex; align-items: flex-end; }
.modal-box { background: var(--bg); width: 100%; max-height: 75vh; border-radius: 16px 16px 0 0; padding: 10px;
  display: flex; flex-direction: column; }
.chips { display: flex; gap: 6px; overflow-x: auto; padding: 4px 0; }
.chips button { white-space: nowrap; padding: 4px 10px; font-size: 13px; }
.chips button.active { background: var(--btn); color: var(--btn-text); }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(46px, 1fr)); gap: 4px; overflow-y: auto; padding: 6px 0; }
.grid .cell { height: 46px; display: flex; align-items: center; justify-content: center; border-radius: 8px; cursor: pointer; }
.grid .cell:hover { background: var(--bg2); }
.grid .cell .tge { width: 34px; height: 34px; font-size: 28px; }

.toast { position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); background: #000c; color: #fff;
  padding: 10px 16px; border-radius: 12px; z-index: 30; max-width: 90vw; }
.busy { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); z-index: 25; display: flex; flex-direction: column;
  align-items: center; justify-content: center; color: #fff; }
.spinner { width: 42px; height: 42px; border: 4px solid #fff4; border-top-color: #fff; border-radius: 50%;
  animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }
.screen { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px; }
.login-box { max-width: 380px; text-align: center; }

/* ---------------------------------------------------------------- широкий экран (ПК, полноэкранный Mini App) */
@media (min-width: 980px) {
  #app { max-width: none; padding-left: 16px; padding-right: 16px; height: 100vh; display: flex; flex-direction: column; }
  .tabs { padding: 8px 0; }
  .tabs button { flex: 0 0 auto; min-width: 120px; }
  .brand { display: block; }
  #tab-posts { flex: 1; min-height: 0; display: grid; grid-template-columns: 320px minmax(0, 1fr); gap: 16px; }
  #tab-posts > #list-view, #tab-posts > #editor-view, #tab-posts > #empty-editor { overflow-y: auto; min-height: 0; }
  body.wide #list-view.hidden { display: block !important; }
  #list-view { padding-right: 4px; }
  .new-post .row { flex-direction: column; align-items: stretch; }
  #editor-view { display: grid; grid-template-columns: minmax(0, 1fr); gap: 16px; align-content: start; }
  #btn-back { display: none; }
  .row.top { justify-content: flex-end; }
  .toolbar { top: 0; }
  .post { min-height: 60vh; font-size: 16px; max-width: 860px; }
  .draft-item.active { outline: 2px solid var(--btn); }
  #tab-emoji { flex: 1; min-height: 0; overflow-y: auto; }
  #tab-emoji > .row { max-width: 900px; }
  #emoji-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(380px, 1fr)); gap: 8px; }
  #emoji-list .emoji-row { margin: 0; }
  .modal { align-items: center; justify-content: center; }
  .modal-box { max-width: 760px; border-radius: 16px; max-height: 80vh; }
  .grid { grid-template-columns: repeat(auto-fill, minmax(52px, 1fr)); }
}
@media (min-width: 1360px) {
  #editor-view { grid-template-columns: minmax(0, 1fr) 340px; }
  .ed-tools { position: sticky; top: 0; align-self: start; }
  .ed-tools .row.wrap button { flex: 1 1 45%; }
  .actions { flex-direction: column; }
  .actions button { width: 100%; }
}
