:root {
  --bg: #f4ede2;
  --panel: #fffaf2;
  --ink: #2b2420;
  --muted: #8a7d70;
  --line: #e6dccd;
  --claude: #e8875a;
  --codex: #5a9be8;
  --ok: #4caf7a;
  --bad: #d9574a;
  --chip: #efe5d6;
  --shadow: 0 6px 24px rgba(60, 40, 20, .14);
}
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    --bg: #17151d;
    --panel: #221f2a;
    --ink: #f1ebe3;
    --muted: #9b93a6;
    --line: #322e3c;
    --chip: #2c2836;
    --shadow: 0 6px 24px rgba(0, 0, 0, .45);
  }
}
:root[data-theme="dark"] {
  --bg: #17151d;
  --panel: #221f2a;
  --ink: #f1ebe3;
  --muted: #9b93a6;
  --line: #322e3c;
  --chip: #2c2836;
  --shadow: 0 6px 24px rgba(0, 0, 0, .45);
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--ink); }
body { font: 14px/1.4 Inter, system-ui, sans-serif; overscroll-behavior: none; }
button { font: inherit; color: inherit; border: 0; background: none; cursor: pointer; }

/* В полноэкранном режиме Telegram рисует свои кнопки поверх верха страницы: отступаем на его безопасную зону. */
#app { max-width: 520px; margin: 0 auto;
  padding: calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)) 0 max(12px, env(safe-area-inset-bottom)); }

.top {
  display: flex; align-items: center; justify-content: space-between; gap: 8px;
  padding: 10px 16px 8px;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.logo {
  width: 34px; height: 34px; border-radius: 10px; display: grid; place-items: center;
  background: var(--claude); color: #fff; font-size: 18px; flex: none;
}
.title { font: 600 18px/1.1 "Pixelify Sans", Inter, sans-serif; letter-spacing: .3px; }
.sub { color: var(--muted); font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }

.elevator { display: flex; gap: 4px; background: var(--chip); padding: 3px; border-radius: 12px; flex: none; }
.elevator button {
  padding: 6px 10px; border-radius: 9px; font-size: 12px; font-weight: 600; color: var(--muted);
  display: flex; align-items: center; gap: 6px;
}
.elevator button .n {
  font: 600 13px "Pixelify Sans", sans-serif; width: 18px; height: 18px; border-radius: 5px;
  display: grid; place-items: center; background: rgba(0,0,0,.08);
}
.elevator button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.elevator button.on .n { background: var(--claude); color: #fff; }
.elevator button.on.f1 .n { background: var(--codex); }

.stage { position: relative; margin: 0 8px; border-radius: 16px; overflow: hidden; box-shadow: var(--shadow); background: #2a2320; }
#office { display: block; width: 100%; image-rendering: pixelated; touch-action: manipulation; }
.curtain { position: absolute; inset: 0; background: #120f14; opacity: 0; pointer-events: none; transition: opacity .28s ease; }
.curtain.on { opacity: 1; }

.cards { display: flex; flex-direction: column; gap: 6px; margin: 10px 8px 0; }
.cards:empty { display: none; }
.card {
  background: var(--panel); border-radius: 14px; box-shadow: var(--shadow);
  padding: 10px 12px; animation: drop .25s ease;
}
@keyframes drop { from { transform: translateY(-10px); opacity: 0; } }
.card .who { display: flex; align-items: center; gap: 8px; font-size: 12px; color: var(--muted); }
.card .who b { color: var(--ink); font-weight: 600; }
.card .bot { width: 22px; height: 22px; border-radius: 50%; display: grid; place-items: center; background: var(--claude); color: #fff; font-size: 12px; }
.card .msg { margin: 6px 0 8px; font-size: 13.5px; }
.card code {
  display: block; margin-top: 4px; padding: 6px 8px; border-radius: 8px; background: var(--chip);
  font: 12px ui-monospace, SFMono-Regular, Menlo, monospace; white-space: pre-wrap; word-break: break-all;
}
.card .kb { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.card .kb button {
  padding: 8px; border-radius: 9px; background: var(--chip); font-weight: 600; font-size: 13px;
}
.card .kb button.yes { background: var(--ok); color: #fff; }
.card .kb button.no { color: var(--bad); }
.card .hint { font-size: 11px; color: var(--muted); margin-top: 6px; text-align: center; }
.card.toast { padding: 8px 12px; }

.strip { display: flex; gap: 8px; overflow-x: auto; padding: 12px 16px 4px; scrollbar-width: none; }
.strip::-webkit-scrollbar { display: none; }
.agent-chip {
  flex: none; display: flex; align-items: center; gap: 8px; padding: 8px 12px 8px 8px;
  background: var(--panel); border-radius: 14px; box-shadow: 0 1px 4px rgba(0,0,0,.06); border: 1px solid var(--line);
  max-width: 220px;
}
.agent-chip .av { width: 28px; height: 28px; border-radius: 8px; image-rendering: pixelated; flex: none; background: var(--chip); }
.agent-chip .nm { font-weight: 600; font-size: 13px; line-height: 1.1; }
.agent-chip .st { font-size: 11px; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 150px; }
.agent-chip.wait { border-color: var(--claude); }
.agent-chip.wait.codex { border-color: var(--codex); }
.agent-chip.add { color: var(--muted); padding: 8px 14px; font-weight: 600; border-style: dashed; }
.dot { display: inline-block; width: 7px; height: 7px; border-radius: 50%; margin-right: 5px; vertical-align: 1px; }
.dot.claude { background: var(--claude); }
.dot.codex { background: var(--codex); }

.sheet-backdrop { position: fixed; inset: 0; background: rgba(10, 8, 12, .35); opacity: 0; pointer-events: none; transition: opacity .2s; }
.sheet-backdrop.on { opacity: 1; pointer-events: auto; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto; max-height: 82vh; overflow-y: auto;
  background: var(--panel); border-radius: 20px 20px 0 0; padding: 8px 16px max(16px, env(safe-area-inset-bottom));
  transform: translateY(105%); transition: transform .26s cubic-bezier(.2,.8,.2,1); box-shadow: var(--shadow);
}
.sheet.on { transform: none; }
.sheet .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); margin: 0 auto 12px; }
.sheet h2 { margin: 0; font: 600 22px/1.1 "Pixelify Sans", Inter, sans-serif; display: flex; align-items: center; gap: 10px; }
.sheet h2 canvas { width: 40px; height: 40px; image-rendering: pixelated; background: var(--chip); border-radius: 10px; }
.sheet .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.sheet .block { margin-top: 14px; }
.sheet .label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin-bottom: 6px; }
.sheet .now { background: var(--chip); border-radius: 12px; padding: 10px 12px; font-size: 14px; }
.sheet .plan { list-style: none; margin: 0; padding: 0; }
.sheet .plan li { padding: 4px 0; display: flex; gap: 8px; font-size: 13.5px; }
.sheet .plan li.done { color: var(--muted); text-decoration: line-through; }
.sheet .plan li .box { width: 16px; flex: none; }
.mem { height: 8px; border-radius: 4px; background: var(--chip); overflow: hidden; }
.mem i { display: block; height: 100%; background: var(--ok); border-radius: 4px; }
.mem.warn i { background: var(--claude); }
.compose { display: flex; gap: 8px; margin-top: 8px; }
.compose textarea {
  flex: 1; resize: none; min-height: 44px; max-height: 120px; border-radius: 12px; border: 1px solid var(--line);
  background: var(--bg); color: var(--ink); padding: 10px 12px; font: 14px Inter, sans-serif;
}
.compose button { padding: 0 16px; border-radius: 12px; background: var(--claude); color: #fff; font-weight: 600; }
.compose.codex button { background: var(--codex); }
.private { background: var(--chip); border-radius: 12px; padding: 12px; color: var(--muted); font-size: 13px; }

/* ── дополнения для живой версии ── */
[hidden] { display: none !important; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.conn.on { background: var(--ok); box-shadow: 0 0 0 3px rgba(76,175,122,.2); }
.conn.off { background: var(--bad); }

.street { position: relative; margin: 0 8px; border-radius: 16px; overflow: hidden; min-height: 60vh; box-shadow: var(--shadow); padding: 28px 12px 0; display: flex; flex-direction: column; }
.street.day { background: linear-gradient(#8ecbf0, #d6eef9 70%); }
.street.dusk { background: linear-gradient(#f19a6a, #f7d38a 70%); }
.street.night { background: linear-gradient(#121836, #2b3263 70%); }
.sky .sun { position: absolute; top: 18px; right: 26px; width: 22px; height: 22px; background: #fff3b0; box-shadow: 0 0 0 4px rgba(255,243,176,.35); }
.street.night .sky .sun { background: #fff3c4; box-shadow: -6px -4px 0 0 #121836 inset; }
.buildings { display: flex; gap: 12px; align-items: flex-end; justify-content: center; flex: 1; position: relative; z-index: 1; }
.building { flex: 1; max-width: 200px; display: flex; flex-direction: column; background: #3b404c; border: 3px solid #23262e; border-bottom: 0; image-rendering: pixelated; }
.building:not(.mine) { background: #3d3a4c; }
.building.ghost { opacity: .55; border-style: dashed; }
.building .roof { background: #23262e; color: #fff; padding: 6px 8px; font: 600 13px "Pixelify Sans", sans-serif; display: flex; justify-content: space-between; align-items: center; gap: 4px; }
.building .roof small { font: 10px Inter, sans-serif; color: #f0a35e; }
.storey { position: relative; display: grid; grid-template-columns: 18px 1fr; grid-template-rows: auto auto; gap: 2px 6px; padding: 6px 8px; border-top: 2px solid #23262e; text-align: left; color: #fff; }
.storey:active { background: rgba(255,255,255,.08); }
.storey .no { grid-row: span 2; font: 600 12px "Pixelify Sans", sans-serif; color: #8a909c; align-self: center; }
.storey .wins { display: flex; gap: 3px; }
.storey .wins i { width: 12px; height: 9px; background: #1b1d23; border: 1px solid #15171c; }
.storey .wins i.lit { background: #ffd27a; box-shadow: 0 0 6px rgba(255,210,122,.6); }
.storey .wins i.wait { background: #e8875a; animation: blink 1s steps(2) infinite; }
@keyframes blink { 50% { background: #7a3a20; } }
.storey .lbl { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.storey .lbl em { font-style: normal; font-size: 10px; }
.storey .badge { position: absolute; right: 6px; top: 6px; background: var(--claude); color: #fff; font: 600 11px "Pixelify Sans", sans-serif; width: 16px; height: 16px; display: grid; place-items: center; }
.building.offline .storey { opacity: .7; }
.building .empty { color: #a9adb8; font-size: 12px; padding: 14px 8px; border-top: 2px solid #23262e; }
.building .ground { height: 26px; background: #2c303a; border-top: 2px solid #23262e; display: flex; justify-content: center; align-items: flex-end; }
.building .door { width: 22px; height: 20px; background: #6b4a33; border: 2px solid #23262e; border-bottom: 0; }
.road { height: 22px; margin: 0 -12px; background: #4a4e57; border-top: 4px solid #6b707a; position: relative; }
.road::after { content: ""; position: absolute; left: 0; right: 0; top: 9px; height: 2px; background: repeating-linear-gradient(90deg, #e9e6df 0 14px, transparent 14px 28px); }

.floorbar { display: flex; align-items: center; gap: 8px; padding: 0 16px 8px; }
.fname { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.fname b { font: 600 17px "Pixelify Sans", Inter, sans-serif; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.fname small { color: var(--muted); font-size: 11px; }
.ftools { display: flex; gap: 6px; align-items: center; }
.pill { padding: 6px 10px; border-radius: 10px; background: var(--chip); font-size: 12px; font-weight: 600; white-space: nowrap; }
.switch { display: flex; align-items: center; gap: 4px; font-size: 11px; color: var(--muted); }
.switch input { accent-color: var(--ok); }
.stage { max-height: none; }
.sheet h2 img { width: 40px; height: 40px; image-rendering: pixelated; border-radius: 10px; background: var(--chip); }
.sheet .now.small { font-size: 13px; white-space: pre-wrap; max-height: 180px; overflow: auto; }
/* Ответ агента: Markdown */
.reply { background: var(--chip); border-radius: 12px; padding: 12px 14px; font-size: 14px; line-height: 1.5;
  max-height: 46vh; overflow: auto; overflow-wrap: anywhere; -webkit-overflow-scrolling: touch; }
.reply > :first-child { margin-top: 0; }
.reply > :last-child { margin-bottom: 0; }
.reply p { margin: 0 0 8px; }
.reply h3, .reply h4, .reply h5, .reply h6 { margin: 14px 0 6px; line-height: 1.25; }
.reply h3 { font: 600 17px/1.2 "Pixelify Sans", Inter, sans-serif; }
.reply h4 { font-size: 15px; }
.reply h5, .reply h6 { font-size: 13px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); }
.reply ul, .reply ol { margin: 0 0 8px; padding-left: 20px; }
.reply li { margin: 3px 0; }
.reply li::marker { color: var(--claude); font-weight: 600; }
.reply li.task { list-style: none; margin-left: -20px; display: flex; gap: 8px; }
.reply li.task .box { color: var(--muted); flex: none; }
.reply li.task.done { color: var(--muted); }
.reply li.task.done .box { color: var(--ok); }
.reply code { font: 12.5px/1.4 ui-monospace, SFMono-Regular, Menlo, monospace; background: var(--panel); border: 1px solid var(--line);
  border-radius: 5px; padding: 1px 5px; }
.reply pre { margin: 6px 0 10px; padding: 10px 12px; background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  overflow-x: auto; white-space: pre; position: relative; }
.reply pre code { border: 0; padding: 0; background: none; font-size: 12px; }
.reply pre[data-lang]::before { content: attr(data-lang); position: absolute; top: 4px; right: 8px; font: 10px Inter, sans-serif; color: var(--muted); }
.reply blockquote { margin: 6px 0 10px; padding: 2px 0 2px 10px; border-left: 3px solid var(--line); color: var(--muted); }
.reply hr { border: 0; border-top: 1px solid var(--line); margin: 12px 0; }
.reply a { color: var(--codex); text-decoration: none; border-bottom: 1px solid currentColor; }
.reply .tbl { overflow-x: auto; margin: 6px 0 10px; }
.reply table { border-collapse: collapse; font-size: 12.5px; min-width: 100%; }
.reply th, .reply td { border: 1px solid var(--line); padding: 5px 8px; text-align: left; vertical-align: top; }
.reply th { background: var(--panel); font-weight: 600; }
.sheet .wide.stop { background: var(--bad); color: #fff; }
.wide { width: 100%; padding: 12px; border-radius: 12px; background: var(--claude); color: #fff; font-weight: 600; }
.card .kb { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); }

.hint { text-align: center; color: var(--muted); font-size: 12px; margin: 8px 0 0; }
#city { display: block; image-rendering: pixelated; }
.hscroll { overflow-x: auto; overflow-y: hidden; scrollbar-width: none; overscroll-behavior-x: contain; }
.hscroll::-webkit-scrollbar { display: none; }

.wide.second { margin-top: 8px; background: var(--chip); color: var(--ink); }
.hint.left { text-align: left; margin-top: 8px; }

.seg { display: flex; gap: 4px; background: var(--chip); padding: 3px; border-radius: 12px; margin-top: 12px; }
.seg button { flex: 1; padding: 8px; border-radius: 9px; font-size: 13px; font-weight: 600; color: var(--muted); }
.seg button.on { background: var(--panel); color: var(--ink); box-shadow: 0 1px 4px rgba(0,0,0,.12); }
.wide.codexbtn { background: var(--codex); }

#vcanvas { display: block; width: 100%; image-rendering: pixelated; }
.vpanel { padding: 0 16px; }
.vrow { display: flex; align-items: center; gap: 8px; padding: 6px 0; border-bottom: 1px solid var(--line); font-size: 14px; }
.vrow b { flex: 1; min-width: 0; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; font-weight: 600; }
.vstat { color: var(--muted); font-size: 12px; white-space: nowrap; }
.vrow .place { width: 20px; text-align: center; }
.muted { color: var(--muted); font-size: 13px; padding: 6px 0; }
.vpanel .label { font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: var(--muted); margin: 14px 0 4px; }

.vdrawer { position: fixed; left: 0; right: 0; bottom: 0; max-width: 520px; margin: 0 auto; z-index: 5;
  background: var(--panel); border-radius: 18px 18px 0 0; box-shadow: var(--shadow);
  transform: translateY(calc(100% - 50px)); transition: transform .25s cubic-bezier(.2,.8,.2,1); max-height: 64vh; display: flex; flex-direction: column; }
.vdrawer.open { transform: none; }
.vhead { display: flex; flex-direction: column; align-items: center; gap: 6px; padding: 8px 16px 10px; font-weight: 600; font-size: 13px; width: 100%; }
.vhead .grab { width: 36px; height: 4px; border-radius: 2px; background: var(--line); }
.vdrawer .vpanel { overflow-y: auto; padding: 0 16px max(16px, env(safe-area-inset-bottom)); }
#venue .stage { margin-bottom: 56px; }

.card .pick { width: 100%; margin: 0 0 8px; padding: 8px; border-radius: 9px; border: 1px solid var(--line); background: var(--bg); color: var(--ink); font: 14px Inter, sans-serif; }
.mail { padding: 8px 10px; border-radius: 12px; margin: 6px 0; font-size: 13px; white-space: pre-wrap; background: var(--chip); max-width: 92%; }
.mail.out { margin-left: auto; background: rgba(232,135,90,.18); }
.mail .mhead { font-size: 11px; color: var(--muted); margin-bottom: 2px; font-weight: 600; }

.topbtns { display: flex; align-items: center; gap: 10px; flex: none; }
.compose .peer { background: var(--chip) !important; color: var(--ink); padding: 0 12px; }
