:root {
  --bg: #0b1d33;
  --frame: #2f8fc0;
  --frame-dark: #1d5f86;
  --frame-light: #6cc4ea;
  --ink: #140b0b;
  --paper: #fff6d8;
  --orange: #f2883a;
  --orange-dark: #b9581b;
  --green: #74d184;
  --green-dark: #3d8f4c;
  --red: #ff3b2f;
  --red-dark: #b0201a;
  --yellow: #ffd23f;
  --muted: #8fb3d6;
  --panel: #12304f;
  --pix: "Press Start 2P", monospace;
  --body: "Tiny5", "Press Start 2P", monospace;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--paper); font-family: var(--body); overflow: hidden; }
button { font: inherit; color: inherit; cursor: pointer; }
input, select, textarea { font: inherit; }

#app {
  display: flex; flex-direction: column; height: 100%;
  /* В полноэкранном Telegram сверху его кнопки — отступ берём из переменных SDK */
  padding: max(8px, calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px) + 4px), env(safe-area-inset-top)) 8px max(8px, env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px));
  gap: 8px;
  background: var(--frame);
  box-shadow: inset 0 0 0 4px var(--frame-dark), inset 0 0 0 6px var(--frame-light);
}

/* ---------- HUD ---------- */
.hud { display: flex; align-items: center; gap: 8px; padding: 4px 6px; }
.hud-logo { font-family: var(--pix); font-size: 11px; letter-spacing: 1px; text-shadow: 2px 2px 0 var(--frame-dark); flex: 1; white-space: nowrap; }
.logo-x { color: var(--red); text-shadow: 2px 2px 0 var(--ink); }
.hud-timer { font-family: var(--pix); font-size: 9px; background: var(--paper); color: var(--ink); padding: 5px 6px; border: 2px solid var(--ink); }
.hud-avatar {
  width: 38px; height: 38px; border: 3px solid var(--ink); background: var(--orange);
  font-family: var(--pix); font-size: 12px; box-shadow: inset -3px -3px 0 var(--orange-dark);
}

/* ---------- Рамка карты ---------- */
.frame { position: relative; flex: 1; min-height: 0; display: flex; gap: 6px; }
.screen {
  position: relative; flex: 1; min-width: 0;
  border: 4px solid var(--ink); background: var(--bg);
  box-shadow: 0 0 0 3px var(--frame-light), 6px 6px 0 3px var(--frame-dark);
  overflow: hidden;
}
#map2d, #map3d { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; }
#map2d { image-rendering: pixelated; display: block; }
.pixel3d { width: 100% !important; height: 100% !important; image-rendering: pixelated; display: block; touch-action: none; }
.corner-tick { position: absolute; width: 14px; height: 14px; border: 3px solid var(--frame-light); pointer-events: none; opacity: .8; }
.corner-tick.tl { top: 6px; left: 6px; border-right: 0; border-bottom: 0; }
.corner-tick.tr { top: 6px; right: 6px; border-left: 0; border-bottom: 0; }
.corner-tick.bl { bottom: 6px; left: 6px; border-right: 0; border-top: 0; }
.corner-tick.br { bottom: 6px; right: 6px; border-left: 0; border-top: 0; }

.banner {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  background: var(--orange); color: var(--ink); border: 3px solid var(--ink);
  box-shadow: inset -3px -3px 0 var(--orange-dark);
  font-family: var(--pix); font-size: 9px; line-height: 1.6; text-align: center;
  padding: 6px 10px; max-width: 86%; pointer-events: none;
  transition: opacity .2s;
}
.banner:empty { opacity: 0; }
.banner.place { background: var(--green); box-shadow: inset -3px -3px 0 var(--green-dark); pointer-events: auto; }

.side-tabs { display: flex; flex-direction: column; gap: 6px; width: 40px; }
.tab-btn {
  height: 38px; border: 3px solid var(--ink); background: var(--red);
  font-family: var(--pix); font-size: 10px; color: var(--paper);
  box-shadow: inset -3px -3px 0 var(--red-dark);
  clip-path: polygon(0 0, 78% 0, 100% 50%, 78% 100%, 0 100%);
  padding-right: 6px;
}
.tab-btn.on { background: var(--yellow); color: var(--ink); box-shadow: inset -3px -3px 0 #b89418; }
.tab-btn:active { transform: translate(2px, 2px); }

/* ---------- Нижние кнопки ---------- */
.dock { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.pbtn {
  position: relative; min-height: 42px; padding: 6px 4px;
  border: 3px solid var(--ink); background: var(--green); color: var(--ink);
  font-family: var(--pix); font-size: 8px; line-height: 1.4;
  box-shadow: inset -3px -3px 0 var(--green-dark);
  border-radius: 10px;
}
.pbtn.orange { background: var(--orange); box-shadow: inset -3px -3px 0 var(--orange-dark); }
.pbtn.red { background: var(--red); color: var(--paper); box-shadow: inset -3px -3px 0 var(--red-dark); }
.pbtn.ghost { background: var(--panel); color: var(--paper); box-shadow: inset -3px -3px 0 #071526; }
.pbtn.on { outline: 3px solid var(--yellow); outline-offset: -7px; }
.pbtn:active { transform: translate(2px, 2px); box-shadow: none; }
.pbtn:disabled { opacity: .45; pointer-events: none; }
.pbtn .ico { display: block; font-size: 14px; margin-bottom: 2px; font-family: initial; }
.badge {
  position: absolute; top: -8px; right: -6px; min-width: 20px; height: 20px; padding: 0 4px;
  background: var(--yellow); border: 2px solid var(--ink); color: var(--ink);
  font-family: var(--pix); font-size: 8px; line-height: 16px;
}
.badge:empty { display: none; }

/* ---------- Шторка ---------- */
.sheet-back { position: fixed; inset: 0; background: rgba(3, 10, 20, .55); opacity: 0; pointer-events: none; transition: opacity .2s; z-index: 10; }
.sheet {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 11;
  max-height: 78vh; display: flex; flex-direction: column;
  background: var(--panel); border-top: 4px solid var(--ink);
  box-shadow: 0 -3px 0 var(--frame-light) inset, 0 -6px 0 var(--frame);
  transform: translateY(105%); transition: transform .22s steps(6);
  padding-bottom: env(safe-area-inset-bottom);
}
body.sheet-open .sheet { transform: none; }
body.sheet-open .sheet-back { opacity: 1; pointer-events: auto; }
.sheet-bar {
  display: flex; align-items: center; gap: 8px; padding: 10px 12px;
  background: var(--frame); border-bottom: 3px solid var(--ink);
  font-family: var(--pix); font-size: 10px;
}
.sheet-bar span { flex: 1; text-shadow: 2px 2px 0 var(--frame-dark); }
.x-btn { width: 30px; height: 30px; border: 3px solid var(--ink); background: var(--red); font-family: var(--pix); font-size: 10px; box-shadow: inset -2px -2px 0 var(--red-dark); }
.sheet-body { overflow-y: auto; padding: 12px; display: flex; flex-direction: column; gap: 10px; font-size: 15px; }

/* ---------- Карточки ---------- */
.card {
  background: #0d2540; border: 3px solid var(--ink); padding: 10px;
  box-shadow: inset 0 0 0 2px #24507c;
  display: flex; flex-direction: column; gap: 8px;
}
.row { display: flex; align-items: center; gap: 10px; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.emoji { font-size: 28px; width: 44px; height: 44px; display: grid; place-items: center; background: var(--paper); border: 3px solid var(--ink); font-family: initial; flex: none; }
.title { font-family: var(--pix); font-size: 10px; line-height: 1.5; }
.sub { color: var(--muted); font-size: 14px; }
.price { font-family: var(--pix); font-size: 11px; color: var(--yellow); white-space: nowrap; }
.note { font-size: 14px; background: #08192c; padding: 6px 8px; border-left: 4px solid var(--orange); }
.empty { text-align: center; color: var(--muted); padding: 24px 8px; font-family: var(--pix); font-size: 9px; line-height: 1.8; }
.section { font-family: var(--pix); font-size: 9px; color: var(--frame-light); margin-top: 4px; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; }
.btns .pbtn { flex: 1; min-width: 90px; }

.stepper { display: flex; align-items: center; border: 3px solid var(--ink); background: var(--paper); color: var(--ink); }
.stepper button { width: 32px; height: 32px; border: 0; background: var(--orange); font-family: var(--pix); font-size: 12px; }
.stepper span { min-width: 34px; text-align: center; font-family: var(--pix); font-size: 10px; }

.status { font-family: var(--pix); font-size: 8px; padding: 4px 6px; border: 2px solid var(--ink); color: var(--ink); white-space: nowrap; }
.status.new { background: var(--yellow); }
.status.accepted { background: var(--frame-light); }
.status.done { background: var(--green); }
.status.cancelled { background: #8a8a8a; }

.tiles { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.tile { background: #0d2540; border: 3px solid var(--ink); padding: 10px; box-shadow: inset -3px -3px 0 #071526; }
.tile b { display: block; font-family: var(--pix); font-size: 14px; color: var(--yellow); margin-bottom: 6px; }
.tile small { color: var(--muted); font-size: 13px; }
.bar { height: 12px; background: #08192c; border: 2px solid var(--ink); }
.bar i { display: block; height: 100%; background: repeating-linear-gradient(90deg, var(--orange) 0 6px, var(--orange-dark) 6px 8px); }

.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted); }
.field input, .field select, .field textarea {
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink);
  padding: 8px; font-size: 16px; border-radius: 0; width: 100%;
}
.field textarea { min-height: 64px; resize: vertical; }
.emoji-pick { display: flex; flex-wrap: wrap; gap: 4px; }
.emoji-pick button { width: 38px; height: 38px; border: 3px solid var(--ink); background: var(--paper); font-size: 20px; font-family: initial; }
.emoji-pick button.on { background: var(--yellow); outline: 2px solid var(--orange); }

.seg { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 2px; }
.seg button { flex: none; border: 3px solid var(--ink); background: var(--panel); padding: 8px 10px; font-family: var(--pix); font-size: 8px; }
.seg button.on { background: var(--yellow); color: var(--ink); }
.mini { font-size: 12px; padding: 4px 8px; border: 2px solid var(--ink); background: var(--orange); color: var(--ink); font-family: var(--pix); font-size: 8px; }
.mini.red { background: var(--red); color: var(--paper); }
.mini.green { background: var(--green); }
table.list { width: 100%; border-collapse: collapse; font-size: 14px; }
table.list td { padding: 6px 4px; border-bottom: 2px solid #0a1a2e; vertical-align: middle; }

/* ---------- Вход ---------- */
.gate {
  position: fixed; inset: 0; z-index: 20; background: var(--bg);
  display: flex; flex-direction: column; align-items: center; justify-content: safe center; overflow-y: auto;
  gap: 14px; padding: 24px; text-align: center;
  background-image: linear-gradient(#10294a 2px, transparent 2px), linear-gradient(90deg, #10294a 2px, transparent 2px);
  background-size: 22px 22px;
}
.gate h1 { font-family: var(--pix); font-size: 16px; line-height: 1.6; margin: 0; text-shadow: 3px 3px 0 var(--red-dark); }
.gate p { color: var(--muted); margin: 0; max-width: 320px; }
.gate .card { width: 100%; max-width: 360px; text-align: left; }
.gate .pbtn { width: 100%; }

.toast {
  position: fixed; left: 50%; top: 18px; transform: translate(-50%, -200%); z-index: 30;
  background: var(--paper); color: var(--ink); border: 3px solid var(--ink);
  box-shadow: 4px 4px 0 var(--ink); font-family: var(--pix); font-size: 9px; line-height: 1.6;
  padding: 10px 12px; max-width: 90vw; transition: transform .2s steps(4);
}
.toast.show { transform: translate(-50%, 0); }
.toast.err { background: var(--red); color: var(--paper); }

@media (min-width: 720px) {
  #app { max-width: 720px; margin: 0 auto; }
  .sheet { max-width: 720px; margin: 0 auto; }
  .hud-logo { font-size: 14px; }
}

[hidden] { display: none !important; }

/* ---------- Адрес, эмодзи ---------- */
.addr { font-size: 14px; color: var(--paper); }
.emoji.big { width: 56px; height: 56px; font-size: 36px; }
.banner small { font-family: var(--body); font-size: 12px; }
.emoji-pick { max-height: none; }

/* ---------- Чат ---------- */
.chat-log { display: flex; flex-direction: column; gap: 6px; max-height: 52vh; overflow-y: auto; padding: 4px 0; }
.msg {
  align-self: flex-start; max-width: 82%; padding: 8px 10px 6px;
  background: #0d2540; border: 3px solid var(--ink); font-size: 15px; line-height: 1.3;
  box-shadow: 3px 3px 0 #071526; word-break: break-word;
}
.msg span { display: block; margin-top: 3px; font-size: 11px; color: var(--muted); text-align: right; }
.msg.me { align-self: flex-end; background: var(--orange); color: var(--ink); box-shadow: 3px 3px 0 var(--orange-dark); }
.msg.me span { color: #5a2a0a; }
.msg.sys { align-self: center; max-width: 94%; background: #08192c; border-style: dashed; border-color: var(--frame-light); color: var(--frame-light); font-size: 13px; text-align: center; box-shadow: none; }
.chat-bar { display: flex; gap: 6px; align-items: stretch; position: sticky; bottom: 0; background: var(--panel); padding-top: 6px; }
.chat-bar textarea { flex: 1; background: var(--paper); color: var(--ink); border: 3px solid var(--ink); padding: 8px; font-size: 16px; resize: none; min-height: 44px; max-height: 120px; }
.chat-bar .pbtn { width: 52px; font-size: 16px; }

/* ---------- Оплата, приглашения ---------- */
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { border: 3px solid var(--ink); background: var(--panel); color: var(--paper); padding: 8px 9px; font-family: var(--pix); font-size: 8px; line-height: 1.6; box-shadow: inset -2px -2px 0 #071526; }
.chip.on { background: var(--yellow); color: var(--ink); box-shadow: inset -2px -2px 0 #b89418; }
.chip-input { background: var(--paper); color: var(--ink); border: 3px solid var(--ink); padding: 8px; font-size: 16px; width: 100%; }
.pay-box { background: #08192c; border-left: 4px solid var(--green); padding: 8px; display: flex; flex-direction: column; gap: 4px; }
.check { display: flex; align-items: center; gap: 10px; font-size: 16px; }
.check input { width: 22px; height: 22px; accent-color: var(--orange); }
.tree { font-size: 15px; padding: 3px 0; }
.banner.tap { pointer-events: auto; }
.banner .mini { margin-top: 6px; }
#map2d { -webkit-touch-callout: none; user-select: none; -webkit-user-select: none; }

/* ---------- Темы ---------- */
.fx { position: fixed; inset: 0; pointer-events: none; z-index: 25; }

/* ---------- Шторка: без горизонтального растягивания, «назад» ---------- */
.sheet, .sheet-body { overflow-x: hidden; max-width: 100vw; }
.sheet-body > * { min-width: 0; max-width: 100%; }
.sheet-body select { max-width: 100%; }
.sheet-bar { position: sticky; top: 0; z-index: 2; }
.sheet-bar span { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.back-btn { width: 34px; height: 30px; border: 3px solid var(--ink); background: var(--yellow); color: var(--ink); font-family: var(--pix); font-size: 12px; box-shadow: inset -2px -2px 0 #b89418; flex: none; }
.x-btn { flex: none; }
.card, .tile, .note, .addr, .sub, .title { overflow-wrap: anywhere; }
.seg { max-width: 100%; }

/* ---------- Выбор товара в форме отметки ---------- */
.pick-list { display: flex; flex-direction: column; gap: 6px; }
.pick { display: flex; align-items: center; gap: 10px; text-align: left; padding: 6px 8px; border: 3px solid var(--ink); background: #0d2540; color: var(--paper); box-shadow: inset -3px -3px 0 #071526; font-family: var(--body); font-size: 15px; }
.pick .emoji { width: 40px; height: 40px; font-size: 24px; }
.pick.on { background: var(--yellow); color: var(--ink); box-shadow: inset -3px -3px 0 #b89418; }
.pick.on .sub { color: #5a4300; }
.pick .tick { font-family: var(--pix); font-size: 14px; }
input.emoji.big { text-align: center; padding: 0; font-size: 30px; }

/* Вкладки переносятся на новые строки, а не уезжают за край */
.seg { flex-wrap: wrap; overflow-x: visible; }
.seg button { flex: 1 1 auto; }

/* фото товара, рейтинг, звёзды */
.emoji img { width: 100%; height: 100%; object-fit: cover; display: block; }
.rate { color: var(--yellow); white-space: nowrap; }
.rate small { opacity: .7; }
.stars { display: flex; gap: 4px; }
.star { width: 40px; height: 40px; border: 3px solid var(--ink); background: var(--paper); font-size: 22px; color: #9a9a9a; font-family: initial; }
.star.on { color: #f5b400; background: var(--yellow); }

/* Читаемость: пиксельный шрифт — для заголовков и кнопок, а вводимый и длинный текст — обычным шрифтом */
:root { --text: ui-sans-serif, -apple-system, "SF Pro Text", system-ui, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif; }
input, select, textarea, .field, .sub, .note, .addr, .msg, .gate p, .tile small, .banner small, .list td { font-family: var(--text); }
.field { font-size: 14px; font-weight: 500; gap: 5px; }
.field input, .field select, .field textarea, .chip-input, .chat-bar textarea {
  font-size: 16px; font-weight: 600; line-height: 1.3; letter-spacing: 0; padding: 11px 10px;
}
.field input::placeholder, .field textarea::placeholder, .chip-input::placeholder, .chat-bar textarea::placeholder { color: #7d7566; opacity: 1; font-weight: 400; }
.sub { font-size: 15px; line-height: 1.4; }
.note, .addr { font-size: 15px; line-height: 1.4; }
.msg { font-size: 15px; line-height: 1.4; }
.msg span { font-size: 12px; }
.msg.sys { font-size: 14px; }
input.emoji.big, .emoji, .emoji-pick button, .star { font-family: initial; }

/* переключатель языка */
.hud-lang { font-family: var(--pix); font-size: 9px; background: var(--paper); color: var(--ink); border: 2px solid var(--ink); padding: 5px 6px; margin-right: 6px; box-shadow: 2px 2px 0 var(--ink); }
.langbar { display: flex; gap: 6px; justify-content: center; margin-top: 12px; flex-wrap: wrap; }
.langbar .mini.on { background: var(--yellow); outline: 2px solid var(--orange); }
.gate .langbar { margin-top: 18px; }

/* тестовый кабинет */
.actas { background: var(--yellow); color: var(--ink); font-family: var(--text, var(--body)); font-weight: 700; font-size: 13px; padding: 6px 10px; display: flex; align-items: center; justify-content: space-between; gap: 8px; border-bottom: 3px solid var(--ink); }
.actas[hidden] { display: none; }

/* значки монет */
img.coin { width: 18px; height: 18px; vertical-align: -4px; margin-right: 6px; border-radius: 50%; }
img.coin.big { width: 26px; height: 26px; vertical-align: -7px; }
.chip img.coin { width: 16px; height: 16px; vertical-align: -3px; }

.card .card { background: transparent; border-style: dashed; }

/* обучение по шагам */
.tour { position: fixed; inset: 0; z-index: 9999; }
.tour-hole { position: fixed; border-radius: 8px; box-shadow: 0 0 0 9999px rgba(5, 10, 20, .78), 0 0 0 3px var(--yellow), 0 0 18px 4px rgba(255, 210, 63, .6); pointer-events: none; transition: all .25s; }
.tour-card { position: fixed; width: min(330px, calc(100vw - 16px)); background: var(--bg); border: 3px solid var(--yellow); box-shadow: 4px 4px 0 var(--ink); padding: 12px; display: flex; flex-direction: column; gap: 10px; color: var(--paper); }
.tour-text { font-family: var(--text, var(--body)); font-size: 15px; line-height: 1.45; }

/* много кнопок внизу — компактнее */
#dock.dense .pbtn { font-size: 7px; padding-left: 2px; padding-right: 2px; letter-spacing: 0; }
#dock.dense .pbtn .ico { font-size: 13px; }

.stock-btns { margin-top: 8px; }
.stock-btns .mini { flex: 1; min-height: 40px; font-size: 10px; padding: 8px 6px; }
.stock-btns .mini.red { flex: 0 0 52px; }

/* Свайп по чату */
.swipe { position: relative; overflow: hidden; }
.swipe .swipe-row { position: relative; margin: 0; transition: transform .2s; touch-action: pan-y; }
.swipe-actions { position: absolute; right: 0; top: 0; bottom: 0; width: 150px; display: flex; gap: 4px; }
.swb { flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px; border: 3px solid var(--ink); background: var(--orange); color: var(--ink); font-size: 18px; }
.swb.red { background: var(--red); color: var(--paper); }
.swb small { font-family: var(--pix); font-size: 7px; }

/* Бонус дня */
.spin-dots { display: flex; gap: 6px; margin: 6px 0; }
.spin-dots .dot { flex: 1; height: 22px; border: 2px solid var(--ink); background: var(--panel); text-align: center; font-size: 12px; line-height: 18px; }
.spin-dots .dot.on { background: var(--yellow); }
.spin-roll { font-size: 34px; text-align: center; animation: spin-roll .5s linear infinite; }
@keyframes spin-roll { to { transform: rotate(360deg); } }
.spin-res { font-family: var(--pix); font-size: 13px; text-align: center; padding: 10px 0; animation: spin-pop .35s ease-out; }
@keyframes spin-pop { from { transform: scale(.6); opacity: 0; } }
