/* Пиксельный «Офис» пульта. Шрифты свои (CSP: font-src 'self'), никаких внешних адресов. */
@font-face {
  font-family: 'Tiny5';
  src: url('/static/ofis/fonts/Tiny5.woff2') format('woff2');
  font-display: block;
}
@font-face {
  font-family: 'PressStart2P';
  src: url('/static/ofis/fonts/PressStart2P.woff2') format('woff2');
  font-display: block;
}

:root {
  --ink: #f3e6d0;
  --ink-dim: #b9a896;
  --bg: #201b22;
  --panel: #2a1f2e;
  --panel-2: #36283b;
  --edge-dark: #120c14;
  --edge-light: #e8c89a;
  --edge-mid: #5a3f4f;
  --gold: #f2c14e;
  --ok: #6cd46c;
  --busy: #6cc8ff;
  --warn: #ffae3b;
  --bad: #ff5c5c;
  --off: #9a8f99;
  --px: 3px;
  --safe-top: max(env(safe-area-inset-top, 0px), var(--tg-content-safe-area-inset-top, 0px) + var(--tg-safe-area-inset-top, 0px));
  --safe-bottom: max(env(safe-area-inset-bottom, 0px), var(--tg-safe-area-inset-bottom, 0px));
  --hud-h: 44px;
}

[hidden] { display: none !important; }
* { box-sizing: border-box; }
html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--ink);
  font-family: 'Tiny5', monospace;
  font-size: 16px;
  line-height: 1.25;
  -webkit-text-size-adjust: 100%;
  -webkit-tap-highlight-color: transparent;
}
body { overflow: hidden; }
button, input, textarea, select { font: inherit; color: inherit; }

.sr-only {
  position: absolute; width: 1px; height: 1px; overflow: hidden;
  clip: rect(0 0 0 0); white-space: nowrap; border: 0; padding: 0; margin: -1px;
}
.sr-only button:focus { position: fixed; left: 8px; top: 8px; width: auto; height: auto; clip: auto; z-index: 50; }

/* ---------- пиксельная рамка: ступенчатые углы тенями ---------- */
.px-box {
  background: var(--panel);
  color: var(--ink);
  box-shadow:
    0 calc(var(--px) * -1) 0 0 var(--edge-dark),
    0 var(--px) 0 0 var(--edge-dark),
    calc(var(--px) * -1) 0 0 0 var(--edge-dark),
    var(--px) 0 0 0 var(--edge-dark),
    inset 0 0 0 var(--px) var(--edge-light),
    inset 0 0 0 calc(var(--px) * 2) var(--edge-mid);
}
.ui-sprites .px-box {
  box-shadow: none;
  border: 12px solid transparent;
  border-image: var(--ui-window) 12 fill / 12px stretch;
  image-rendering: pixelated;
}

.px-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  min-height: 36px; padding: 6px 12px;
  background: var(--panel-2); color: var(--ink);
  border: 0; border-radius: 0; cursor: pointer; text-decoration: none;
  font-family: 'Tiny5', monospace; font-size: 16px; line-height: 1;
  box-shadow:
    0 calc(var(--px) * -1) 0 0 var(--edge-dark), 0 var(--px) 0 0 var(--edge-dark),
    calc(var(--px) * -1) 0 0 0 var(--edge-dark), var(--px) 0 0 0 var(--edge-dark),
    inset 0 calc(var(--px) * -1) 0 0 #1f1623, inset 0 var(--px) 0 0 #5c4863;
  user-select: none; -webkit-user-select: none;
}
.px-btn:hover { background: #45334b; }
.px-btn:active, .px-btn.pressed {
  transform: translateY(2px);
  box-shadow:
    0 calc(var(--px) * -1) 0 0 var(--edge-dark), 0 var(--px) 0 0 var(--edge-dark),
    calc(var(--px) * -1) 0 0 0 var(--edge-dark), var(--px) 0 0 0 var(--edge-dark),
    inset 0 var(--px) 0 0 #1f1623;
}
.px-btn:focus-visible { outline: 2px solid var(--gold); outline-offset: 4px; }
.px-btn[disabled] { opacity: .5; cursor: default; transform: none; }
.px-btn.gold { background: #8a6a1e; }
.px-btn.gold:hover { background: #9c7a26; }
.px-btn.danger { background: #7a2630; }
.px-btn.danger:hover { background: #8e2e3a; }
.px-btn.current { background: #2e5a34; }
.px-btn.small { min-height: 30px; padding: 4px 8px; font-size: 14px; }

/* ---------- верхняя панель ---------- */
#hud {
  position: fixed; left: 0; right: 0; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  min-height: calc(var(--hud-h) + var(--safe-top));
  padding: calc(var(--safe-top) + 4px) max(8px, env(safe-area-inset-right, 0px)) 4px max(8px, env(safe-area-inset-left, 0px));
  background: #140e17;
  box-shadow: 0 3px 0 0 var(--edge-dark), 0 6px 0 0 rgba(0, 0, 0, .25);
}
.hud-title {
  font-family: 'PressStart2P', monospace; font-size: 11px; color: var(--gold);
  letter-spacing: 1px; flex: none;
}
.hud-chips {
  display: flex; gap: 6px; flex: 1 1 auto; min-width: 0; white-space: nowrap;
  overflow-x: auto; overflow-y: hidden; scrollbar-width: none; padding: 2px;
}
.hud-chips::-webkit-scrollbar { display: none; }
.chip {
  display: inline-flex; align-items: center; gap: 4px; flex: none;
  padding: 3px 6px; background: #2a1f2e; color: var(--ink);
  border: 0; font: inherit; font-size: 16px; line-height: 1.1; cursor: pointer;
  box-shadow: inset 0 0 0 2px #4a3552;
}
.chip b { font-weight: normal; }
.chip .dot { width: 8px; height: 8px; display: inline-block; background: var(--off); }
.chip.ok .dot { background: var(--ok); }
.chip.busy .dot { background: var(--busy); }
.chip.warn { box-shadow: inset 0 0 0 2px #8a5a1e; }
.chip.warn .dot { background: var(--warn); }
.chip.bad { box-shadow: inset 0 0 0 2px #8e2e3a; color: #ffd0d0; }
.chip.bad .dot { background: var(--bad); }
.chip:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
.hud-net {
  flex: none; font-size: 16px; color: #ffd0d0; background: #5a1e26; padding: 3px 6px;
  animation: blink 1.2s steps(2, start) infinite;
}
.hud-classic, .hud-city { flex: none; min-height: 30px; padding: 4px 10px; font-size: 16px; }
@keyframes blink { to { visibility: hidden; } }

/* ---------- сцена ---------- */
#stage {
  position: fixed; left: 0; right: 0; bottom: 0;
  top: calc(var(--hud-h) + var(--safe-top));
  overflow-x: hidden; overflow-y: auto;
  overscroll-behavior: contain;
  -webkit-overflow-scrolling: touch;
  background: #362a2b;
}
/* Холст размером с окно «липнет» к верху прокрутки, высоту прокрутки задаёт #spacer:
   рисуем только видимую часть офиса, как бы длинно он ни тянулся вниз. */
#scene {
  position: sticky; top: 0;
  display: block;
  margin: 0 auto;
  image-rendering: pixelated;
  image-rendering: crisp-edges;
  touch-action: pan-y;
  cursor: default;
}
#spacer { width: 1px; }
#scene.hot { cursor: pointer; }

/* ---------- окна-диалоги ---------- */
.dlg {
  position: fixed; inset: 0; z-index: 20;
  display: flex; align-items: flex-end; justify-content: center;
  padding: calc(var(--safe-top) + 12px) 10px calc(var(--safe-bottom) + 12px);
  background: rgba(10, 6, 12, .62);
}
@media (min-width: 640px) { .dlg { align-items: center; } }
.win {
  width: 100%; max-width: 520px; max-height: 100%;
  display: flex; flex-direction: column;
  padding: 14px 14px 12px;
}
.win-h { display: flex; align-items: flex-start; gap: 10px; margin: 2px 2px 8px; }
.win-h h2 {
  flex: 1 1 auto; margin: 0; min-width: 0;
  font-family: 'PressStart2P', monospace; font-size: 12px; line-height: 1.5; color: var(--gold);
  overflow-wrap: anywhere;
}
.win-x { flex: none; min-width: 36px; min-height: 32px; padding: 2px 8px; font-size: 18px; }
.win-b { overflow-y: auto; padding: 2px; margin: 0 -2px; overscroll-behavior: contain; }
.win-b p { margin: 6px 0; }
.muted { color: var(--ink-dim); }
.rows { display: grid; grid-template-columns: auto 1fr; gap: 3px 10px; margin: 6px 0 10px; }
.rows dt { color: var(--ink-dim); }
.rows dd { margin: 0; overflow-wrap: anywhere; }
.st { display: inline-block; padding: 1px 6px; font-size: 14px; background: #3a2b40; }
.st.ok { color: #0e2a10; background: var(--ok); }
.st.busy { color: #0a2130; background: var(--busy); }
.st.warn { color: #2e1a00; background: var(--warn); }
.st.bad { color: #300a0a; background: var(--bad); }
.st.off { color: #1c1420; background: var(--off); }
.bar { height: 10px; background: #140e17; box-shadow: inset 0 0 0 2px #4a3552; position: relative; margin-top: 4px; }
.bar i { position: absolute; left: 2px; top: 2px; bottom: 2px; background: var(--ok); max-width: calc(100% - 4px); }
.bar.warn i { background: var(--warn); }
.bar.bad i { background: var(--bad); }
.btns { display: flex; flex-wrap: wrap; gap: 10px; margin: 10px 2px 4px; }
.pick { display: flex; flex-wrap: wrap; gap: 8px; margin: 8px 2px; }
.ask {
  margin: 10px 0 4px; padding: 10px; background: #3a1e2a; box-shadow: inset 0 0 0 2px #7a2e40;
}
.ask p { margin: 0 0 8px; }
.ask label { display: flex; gap: 8px; align-items: center; margin: 6px 0; cursor: pointer; }
.ask input[type=checkbox] { width: 18px; height: 18px; accent-color: var(--gold); }
.res { margin: 10px 0 2px; padding: 8px 10px; background: #1f2a1f; box-shadow: inset 0 0 0 2px #3f6a3f; overflow-wrap: anywhere; white-space: pre-wrap; }
.res.bad { background: #2e1a1e; box-shadow: inset 0 0 0 2px #7a2e40; }
.res.wait { background: #22202e; box-shadow: inset 0 0 0 2px #4a4a6a; }
textarea, input[type=text], input.code {
  width: 100%; padding: 8px; background: #140e17; color: var(--ink); border: 0; border-radius: 0;
  box-shadow: inset 0 0 0 2px #5a3f4f; font-family: 'Tiny5', monospace; font-size: 16px;
}
textarea:focus, input:focus { outline: 2px solid var(--gold); outline-offset: 0; }
textarea { min-height: 96px; resize: vertical; }
input.code { font-size: 24px; letter-spacing: 8px; text-align: center; max-width: 220px; }
ul.list { list-style: none; padding: 0; margin: 6px 0; }
ul.list li { display: flex; gap: 8px; align-items: baseline; padding: 4px 0; border-bottom: 2px solid #34263a; }
ul.list li:last-child { border-bottom: 0; }
ul.list .sq { flex: none; width: 10px; height: 10px; background: var(--off); align-self: center; }
ul.list .sq.ok { background: var(--ok); }
ul.list .sq.busy { background: var(--busy); }
ul.list .sq.warn { background: var(--warn); }
ul.list .sq.bad { background: var(--bad); }
ul.list .t { flex: 1 1 auto; min-width: 0; overflow-wrap: anywhere; }
/* сжимается до длинного слова: иначе длинный вердикт сминал название в столбик (обложка Fold) */
ul.list .v { flex: 0 1 auto; color: var(--ink-dim); text-align: right; }
h3 { font-family: 'PressStart2P', monospace; font-size: 10px; color: var(--ink-dim); margin: 14px 0 4px; font-weight: normal; }

/* ---------- выбор облика: сетка 20 персонажей (превью sprites/avatars 160×160; сторону --look ставит ofis.js —
   целое число пикселей экрана на точку рисунка, около 64 CSS px) ----------
   Не больше 4 столбцов (16 сотрудников — 4 строки, роботы — пятая), уже 4 не влезают — по 72 px. */
.looks { display: grid; grid-template-columns: repeat(auto-fill, minmax(max(72px, calc(25% - 3px)), 1fr)); gap: 4px; margin: 8px 0 4px; }
.win.win-looks { max-width: 440px; }
button.look {
  position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px; min-width: 0;
  padding: 4px 2px 5px; background: #3a2b40; color: var(--ink); border: 0; cursor: pointer;
  font-family: 'Tiny5', monospace; font-size: 12px; line-height: 1.15; box-shadow: inset 0 0 0 2px #5a3f4f;
}
button.look img { display: block; width: var(--look, 64px); height: var(--look, 64px); image-rendering: pixelated; image-rendering: crisp-edges; }
button.look .n { min-height: 2.3em; max-width: 100%; text-align: center; overflow-wrap: break-word; }
button.look:hover { filter: brightness(1.08); }
button.look:focus-visible { outline: 2px solid var(--gold); outline-offset: 2px; }
button.look.current { background: #4a3b24; box-shadow: inset 0 0 0 3px var(--gold); }
button.look.current::after {
  content: '✓'; position: absolute; top: 3px; right: 4px; padding: 0 3px; font-size: 12px; line-height: 1.3;
  color: #201b22; background: var(--gold);
}
button.look[aria-busy=true] { opacity: .55; cursor: progress; }
.ui-art button.look { background: #fff0c9; color: #201b22; box-shadow: inset 0 0 0 2px #edbb74; }
.ui-art button.look.current { background: #f4d59c; box-shadow: inset 0 0 0 3px #6b994a; }
.ui-art button.look.current::after { color: #fff0c9; background: #6b994a; }
@media (prefers-reduced-motion: reduce) { button.look:hover { filter: none; } }

/* ---------- вход ---------- */
.login {
  position: fixed; inset: 0; z-index: 30;
  display: flex; align-items: center; justify-content: center; padding: 16px;
  background: var(--bg);
}
.login .win { max-width: 380px; text-align: center; }
.login .win-h h2 { text-align: center; }
.login .btns { justify-content: center; }
.login .msg { min-height: 1.4em; }
.login .msg.bad { color: #ffb0b0; }
.login input.code { margin: 8px auto; display: block; }
.noscript { padding: 20px; }

@media (prefers-reduced-motion: reduce) {
  .hud-net { animation: none; }
  .px-btn:active, .px-btn.pressed { transform: none; }
}
/* лёгкий режим (?lite=1, экономия заряда): и в разметке ничего не мигает */
.lite .hud-net { animation: none; }

/* ---------- узкий экран (обложка Fold): значки переносятся второй строкой, не обрезаются ---------- */
@media (max-width: 599px) {
  #hud { flex-wrap: wrap; row-gap: 4px; }
  .hud-chips { order: 3; flex: 1 1 100%; flex-wrap: wrap; overflow: visible; white-space: normal; }
  .hud-title { flex: 1 1 auto; }
}

/* ---------- графика 07_ui (Pixel_Office_v5): окна-пергамент и кнопки ----------
   --u — CSS-пикселей на пиксель рисунка (целое число пикселей экрана, ставит ofis.js).
   Рамки режутся border-image по толщине рисунка: окно 18/13/14/13, кнопка 4/4/10/4 (снизу тень). */
.ui-art .px-box {
  box-shadow: none;
  background: none;
  border-style: solid;
  border-width: calc(var(--u) * 18) calc(var(--u) * 13) calc(var(--u) * 14) calc(var(--u) * 13);
  border-image: var(--ui-dialog) 18 13 14 13 fill / calc(var(--u) * 18) calc(var(--u) * 13) calc(var(--u) * 14) calc(var(--u) * 13) stretch;
  image-rendering: pixelated;
  color: #201b22;
  --ink: #201b22;
  --ink-dim: #774526;
}
.ui-art .win { padding: 4px 6px 6px; }
.ui-art .win-h h2 { color: #762d3a; }
.ui-art .muted, .ui-art .rows dt, .ui-art h3 { color: #774526; }
.ui-art ul.list li { border-bottom-color: #edbb74; }
.ui-art .res { background: #fff0c9; box-shadow: inset 0 0 0 2px #6b994a; color: #201b22; }
.ui-art .res.bad { background: #fff0c9; box-shadow: inset 0 0 0 2px #bb4543; }
.ui-art .res.wait { background: #fff0c9; box-shadow: inset 0 0 0 2px #969aaa; }
.ui-art .ask { background: #fff0c9; box-shadow: inset 0 0 0 2px #bb4543; }
.ui-art textarea, .ui-art input[type=text], .ui-art input.code {
  background: #fff0c9; color: #201b22; box-shadow: inset 0 0 0 2px #995c30;
}
.ui-art .bar { background: #362a2b; box-shadow: inset 0 0 0 2px #57372a; }
.ui-art .bar i { background: #6b994a; }
.ui-art .bar.warn i { background: #da9a52; }
.ui-art .bar.bad i { background: #bb4543; }
.ui-art .login .msg.bad { color: #bb4543; }
.ui-art .px-btn {
  box-shadow: none;
  background: none;
  color: #201b22;
  border-style: solid;
  border-width: calc(var(--u) * 4) calc(var(--u) * 4) calc(var(--u) * 10) calc(var(--u) * 4);
  border-image: var(--ui-button-normal) 4 4 10 4 fill / calc(var(--u) * 4) calc(var(--u) * 4) calc(var(--u) * 10) calc(var(--u) * 4) stretch;
  image-rendering: pixelated;
  padding: 2px 8px;
  min-height: 34px;
}
.ui-art .px-btn:hover { background: none; filter: brightness(1.06); }
.ui-art .px-btn:active, .ui-art .px-btn.pressed {
  transform: none;
  box-shadow: none;
  border-width: calc(var(--u) * 7) calc(var(--u) * 7) calc(var(--u) * 7) calc(var(--u) * 7);
  border-image: var(--ui-button-pressed) 7 fill / calc(var(--u) * 7) stretch;
}
.ui-art .px-btn.danger { background: none; color: #762d3a; }
.ui-art .px-btn.gold { background: none; color: #201b22; font-weight: bold; }
.ui-art .px-btn.current { background: none; color: #23483b; }
.ui-art .px-btn.small { min-height: 28px; padding: 0 6px; }
.ui-art .win-x { min-width: 34px; }
