/* Игра занимает весь экран без полей и полос прокрутки: на zloy.net она
   открывается во фрейме во весь экран.
   ВЕРХ ПО ЦЕНТРУ ЗАНЯТ: там «чёлка» платформы (240×28) — ничего важного
   туда не кладём, всё по краям и снизу. */
:root {
  --sl: env(safe-area-inset-left, 0px);
  --sr: env(safe-area-inset-right, 0px);
  --st: env(safe-area-inset-top, 0px);
  --sb: env(safe-area-inset-bottom, 0px);
  --glass: rgba(18, 22, 34, .62);
  --glass2: rgba(255, 255, 255, .1);
  --line: rgba(255, 255, 255, .14);
  --accent: #ffb347;
  --accent2: #ff6b4a;
  --ok: #5fd17a;
  --btn: 52px;
}
html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #05060a;
  color: #fff;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  -webkit-user-select: none;
  user-select: none;
  -webkit-tap-highlight-color: transparent;
  touch-action: none;
  overscroll-behavior: none;
}
#game { display: block; position: fixed; inset: 0; width: 100vw; height: 100vh; touch-action: none; outline: none; }
#ui { position: fixed; inset: 0; pointer-events: none; z-index: 5; font-size: 14px; }
#ui button, #ui input, #ui textarea, #ui .sheet, #ui .share, #ui form { pointer-events: auto; }
/* сброс для кнопок — с нулевой специфичностью, чтобы классы ниже его перекрывали */
:where(#ui) button { font: inherit; color: inherit; cursor: pointer; border: 0; background: none; padding: 0; }
input, textarea { -webkit-user-select: text; user-select: text; }

/* ---------- меню слева ---------- */
.toolbar {
  position: absolute; left: calc(10px + var(--sl)); top: calc(12px + var(--st));
  display: flex; flex-direction: column; gap: 6px;
}
.tb-btn {
  width: var(--btn); height: var(--btn); border-radius: 16px;
  background: var(--glass); border: 1px solid var(--line) !important;
  backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px;
  box-shadow: 0 6px 18px rgba(0, 0, 0, .25);
  transition: transform .12s, background .15s;
}
.tb-btn svg { width: 24px; height: 24px; }
.tb-btn span { font-size: 9.5px; font-weight: 700; opacity: .85; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; padding: 0 2px; }
.tb-btn:active { transform: scale(.94); }
.tb-btn.on { background: linear-gradient(160deg, var(--accent), var(--accent2)); color: #1b1006; }
.mode-desktop .chat-btn { display: none; }

/* ---------- чат ---------- */
.chat { position: absolute; left: calc(var(--btn) + 22px + var(--sl)); top: calc(40px + var(--st)); width: min(360px, 42vw); }
.chat-log {
  max-height: 150px; overflow: hidden;
  -webkit-mask-image: linear-gradient(to bottom, transparent 0, #000 22px); mask-image: linear-gradient(to bottom, transparent 0, #000 22px); display: flex; flex-direction: column; gap: 3px;
  font-size: 13px; line-height: 1.35; transition: opacity .4s;
}
.msg { background: rgba(0, 0, 0, .38); padding: 4px 9px; border-radius: 10px; align-self: flex-start; max-width: 100%; word-break: break-word; text-shadow: 0 1px 2px rgba(0,0,0,.5); }
.msg b { color: #ffd98a; }
.msg.me b { color: #8fd3ff; }
.msg.system { color: #c8f7c5; font-style: italic; }
.chat-form { display: none; margin-top: 6px; }
.chat-open .chat-form { display: block; }
.chat-open .chat-log { max-height: 220px; overflow-y: auto; }
.chat-input {
  width: 100%; box-sizing: border-box; height: 42px; border-radius: 12px; border: 1px solid var(--line);
  background: rgba(10, 12, 20, .85); color: #fff; padding: 0 12px; font-size: 16px; outline: none;
}

/* ---------- справа сверху ---------- */
.top-right { position: absolute; right: calc(10px + var(--sr)); top: calc(10px + var(--st)); display: flex; flex-direction: column; align-items: flex-end; gap: 6px; }
.tr-row { display: flex; align-items: center; gap: 8px; }
.pill {
  background: var(--glass); border: 1px solid var(--line); backdrop-filter: blur(10px); -webkit-backdrop-filter: blur(10px);
  border-radius: 999px; padding: 7px 14px 7px 10px; font-weight: 800; font-size: 15px; display: flex; align-items: center; gap: 6px;
  position: relative; white-space: nowrap;
}
.pill svg { width: 20px; height: 20px; color: #ffd166; }
.status { background: rgba(160, 20, 20, .8); color: #fff; padding: 6px 12px; font-size: 13px; animation: pulse 1s infinite alternate; }
@keyframes pulse { to { background: rgba(220, 40, 40, .9); } }
.money-pop { position: absolute; right: 8px; top: 100%; color: #7dffa0; font-weight: 900; animation: pop 1.4s forwards; text-shadow: 0 1px 3px #000; }
@keyframes pop { from { transform: translateY(0); opacity: 1; } to { transform: translateY(26px); opacity: 0; } }

/* кнопка записи: ● / ■ со счётчиком / кольцо загрузки / ✓ / ! */
.rec-btn {
  width: 48px; height: 48px; border-radius: 50%; position: relative;
  background: var(--glass) !important; border: 1px solid var(--line) !important;
  display: flex; align-items: center; justify-content: center;
}
.rec-btn .ico { font-size: 20px; color: #ff3b30; line-height: 1; position: relative; z-index: 1; }
.rec-btn[data-state="rec"] { background: rgba(255, 59, 48, .9) !important; width: auto; min-width: 48px; border-radius: 24px; padding: 0 12px; gap: 6px; }
.rec-btn[data-state="rec"] .ico { color: #fff; font-size: 14px; }
.rec-btn .sec { font-weight: 800; font-size: 13px; font-variant-numeric: tabular-nums; }
.rec-btn[data-state="ok"] .ico { color: var(--ok); font-size: 22px; font-weight: 900; }
.rec-btn[data-state="fail"] .ico { color: #ffb300; font-size: 22px; font-weight: 900; }
.rec-btn .ring { position: absolute; inset: 0; width: 100%; height: 100%; transform: rotate(-90deg); display: none; }
.rec-btn[data-state="upload"] .ring { display: block; }
.rec-btn.spin .ring { animation: spin 1s linear infinite; }
.rec-btn .ring circle { fill: none; stroke-width: 4; }
.rec-btn .ring .track { stroke: rgba(255, 255, 255, .15); }
.rec-btn .ring .prog { stroke: var(--ok); stroke-linecap: round; transition: stroke-dashoffset .2s; }
.rec-btn.spin .ring .prog { stroke-dasharray: 30 90 !important; stroke-dashoffset: 0 !important; }
@keyframes spin { to { transform: rotate(270deg); } }

/* ---------- подсказка действия ---------- */
.prompt {
  position: absolute; left: 0; top: 0; display: none; align-items: center; gap: 8px;
  background: rgba(14, 16, 26, .82) !important; border: 1px solid rgba(255, 255, 255, .22) !important;
  padding: 8px 16px 8px 8px; border-radius: 14px; font-weight: 800; font-size: 15px; min-height: 48px;
  box-shadow: 0 8px 22px rgba(0, 0, 0, .35); overflow: hidden; white-space: nowrap;
}
.prompt.show { display: flex; }
.prompt kbd { background: #fff; color: #111; border-radius: 8px; padding: 4px 9px; font: 900 14px system-ui; box-shadow: 0 3px 0 #aaa; }
.prompt .hold { position: absolute; left: 0; bottom: 0; height: 4px; background: var(--accent); width: 0; }
.mode-touch .prompt { padding: 12px 22px; font-size: 17px; min-height: 52px; border-radius: 18px; background: linear-gradient(160deg, rgba(255, 179, 71, .95), rgba(255, 107, 74, .95)) !important; color: #1b1006; }

/* ---------- хотбар ---------- */
.hotbar {
  position: absolute; left: 50%; bottom: calc(12px + var(--sb)); transform: translateX(-50%);
  display: flex; gap: 6px; padding: 6px; border-radius: 18px; background: rgba(10, 12, 20, .35);
}
.slot {
  width: 50px; height: 50px; border-radius: 13px; background: var(--glass) !important; border: 1px solid var(--line) !important;
  position: relative; display: flex; align-items: center; justify-content: center;
}
.slot i { font-style: normal; font-size: 24px; }
.slot kbd { position: absolute; left: 4px; top: 2px; font: 700 10px system-ui; opacity: .7; }
.slot em { position: absolute; right: 4px; bottom: 2px; font: 800 10px system-ui; font-style: normal; }
.slot.on { border-color: var(--accent) !important; box-shadow: 0 0 0 2px var(--accent) inset; background: rgba(255, 179, 71, .2) !important; }
.slot.bag svg { width: 24px; height: 24px; }
.mode-touch .slot kbd { display: none; }

/* ---------- сенсорное управление ---------- */
.touch { display: none; }
.mode-touch .touch { display: block; }
.joy-base {
  position: absolute; width: 130px; height: 130px; margin: -65px 0 0 -65px; border-radius: 50%;
  border: 2px solid rgba(255, 255, 255, .35); background: rgba(255, 255, 255, .08);
  left: calc(var(--btn) + 120px + var(--sl)); top: calc(100% - 120px - var(--sb)); opacity: .55; transition: opacity .2s;
}
.joy-base.active { opacity: 1; }
.joy-knob { position: absolute; left: 50%; top: 50%; width: 58px; height: 58px; margin: -29px 0 0 -29px; border-radius: 50%; background: rgba(255, 255, 255, .85); box-shadow: 0 4px 14px rgba(0, 0, 0, .3); }
.touch-btns {
  position: absolute; right: calc(16px + var(--sr)); bottom: calc(18px + var(--sb));
  display: grid; grid-template-columns: repeat(3, 58px); grid-auto-rows: 58px; gap: 12px; direction: rtl;
}
.tbtn {
  width: 58px; height: 58px; border-radius: 50%; background: rgba(18, 22, 34, .55) !important; border: 2px solid rgba(255, 255, 255, .35) !important;
  display: flex; align-items: center; justify-content: center; direction: ltr;
}
.tbtn svg { width: 26px; height: 26px; }
.tbtn.big { width: 76px; height: 76px; grid-row: span 2; align-self: end; }
.tbtn.big svg { width: 34px; height: 34px; }
.tbtn.down, .tbtn.on { background: rgba(255, 179, 71, .85) !important; color: #1b1006; }
.mode-touch .hotbar { bottom: calc(10px + var(--sb)); left: 50%; }
.mode-touch .keys-hint { display: none; }

/* ---------- подсказка клавиш ---------- */
.keys-hint {
  position: absolute; left: calc(14px + var(--sl)); bottom: calc(14px + var(--sb)); max-width: calc(50vw - 200px);
  font-size: 12px; opacity: .75; text-align: left; text-shadow: 0 1px 3px #000; line-height: 1.4;
}

/* ---------- уведомления (под чёлкой, не в ней) ---------- */
.toasts { position: absolute; z-index: 20; left: 50%; top: calc(64px + var(--st)); transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; width: min(90vw, 460px); }
.toast {
  background: rgba(14, 16, 26, .86); border: 1px solid var(--line); padding: 9px 16px; border-radius: 14px;
  font-weight: 700; text-align: center; animation: tin .25s; transition: opacity .4s, transform .4s; max-width: 100%;
}
.toast.out { opacity: 0; transform: translateY(-8px); }
@keyframes tin { from { opacity: 0; transform: translateY(-8px); } }

/* ---------- окно-панель ---------- */
.sheet {
  position: absolute; z-index: 10; right: calc(12px + var(--sr)); top: calc(66px + var(--st)); bottom: calc(12px + var(--sb));
  width: min(420px, 46vw); display: flex; flex-direction: column;
  background: rgba(16, 19, 30, .9); border: 1px solid var(--line); border-radius: 22px;
  backdrop-filter: blur(16px); -webkit-backdrop-filter: blur(16px); box-shadow: 0 20px 60px rgba(0, 0, 0, .45);
  animation: sin .22s ease-out;
}
.sheet.hidden { display: none; }
@keyframes sin { from { opacity: 0; transform: translateX(20px); } }
.sheet[data-panel="emotes"] { top: auto; height: auto; max-height: 50vh; }
.sheet-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 14px 6px 20px; }
.sheet-head h2 { margin: 0; font-size: 20px; font-weight: 900; }
.icon-btn { width: 48px; height: 48px; border-radius: 12px; display: flex; align-items: center; justify-content: center; background: var(--glass2) !important; }
.icon-btn svg { width: 22px; height: 22px; }
.sheet-body { overflow-y: auto; padding: 4px 18px 18px; -webkit-overflow-scrolling: touch; touch-action: pan-y; }
.sheet-body h3 { font-size: 12px; text-transform: uppercase; letter-spacing: .08em; opacity: .6; margin: 16px 0 8px; }
.lead { font-size: 15px; line-height: 1.45; margin: 6px 0 12px; }
.note { font-size: 12.5px; opacity: .7; line-height: 1.45; }
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(112px, 1fr)); gap: 8px; }
.grid.small { grid-template-columns: repeat(auto-fill, minmax(92px, 1fr)); }
.card {
  background: var(--glass2) !important; border: 1px solid var(--line) !important; border-radius: 16px; padding: 10px 8px;
  display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center; min-height: 92px; transition: transform .1s;
}
.card:active { transform: scale(.96); }
.card i { font-style: normal; font-size: 30px; line-height: 1.2; }
.card b { font-size: 13px; line-height: 1.2; }
.card small { font-size: 11px; opacity: .7; line-height: 1.2; }
.card.on { border-color: var(--accent) !important; background: rgba(255, 179, 71, .18) !important; box-shadow: 0 0 0 2px var(--accent) inset; }
.card.disabled { opacity: .4; }
.swatches { display: flex; flex-wrap: wrap; gap: 8px; }
.sw { width: 48px; height: 48px; border-radius: 50%; border: 3px solid rgba(255, 255, 255, .25) !important; }
.sw.on { border-color: #fff !important; box-shadow: 0 0 0 3px var(--accent); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 48px; padding: 0 14px; border-radius: 999px; background: var(--glass2) !important; border: 1px solid var(--line) !important; font-weight: 700; font-size: 13px; }
.chip.on { background: linear-gradient(160deg, var(--accent), var(--accent2)) !important; color: #1b1006; border-color: transparent !important; }
.tabs { display: flex; gap: 4px; overflow-x: auto; padding-bottom: 4px; }
.tab { flex: 1 0 auto; min-height: 48px; padding: 0 12px; border-radius: 12px; font-weight: 800; font-size: 13px; background: var(--glass2) !important; }
.tab.on { background: #fff !important; color: #111; }
.row { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 14px; }
.btn { min-height: 48px; padding: 0 18px; border-radius: 14px; font-weight: 800; background: var(--glass2) !important; border: 1px solid var(--line) !important; flex: 1 1 auto; }
.btn.primary { background: linear-gradient(160deg, var(--accent), var(--accent2)) !important; color: #1b1006; border: 0 !important; }
.btn.danger { background: rgba(220, 50, 50, .25) !important; border-color: rgba(255, 90, 90, .5) !important; }
.btn.ghost { background: transparent !important; }
.field { width: 100%; box-sizing: border-box; height: 48px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, .3); color: #fff; padding: 0 12px; font-size: 16px; outline: none; }
.range { width: 100%; accent-color: var(--accent); height: 48px; }

/* ---------- окно «Поделиться» ---------- */
.share { position: absolute; inset: 0; background: rgba(0, 0, 0, .6); display: flex; align-items: center; justify-content: center; z-index: 30; }
.share.hidden { display: none; }
.share-box {
  width: min(560px, 92vw); max-height: 92vh; overflow-y: auto; box-sizing: border-box; padding: 18px; border-radius: 22px;
  background: rgba(18, 21, 32, .97); border: 1px solid var(--line);
}
.share-box h2 { margin: 0 0 12px; font-size: 20px; }
.share-media video, .share-media img { width: 100%; max-height: 40vh; border-radius: 14px; background: #000; display: block; object-fit: contain; }
.share-box textarea { width: 100%; box-sizing: border-box; min-height: 110px; margin-top: 12px; border-radius: 12px; border: 1px solid var(--line); background: rgba(0, 0, 0, .35); color: #fff; padding: 10px; font: 14px/1.4 ui-monospace, Menlo, monospace; resize: vertical; }
.share-err { color: #ffb4a8; font-weight: 700; min-height: 1em; }

/* ---------- вспышка камеры телефона ---------- */
#flash { position: absolute; inset: 0; background: #fff; opacity: 0; pointer-events: none; }
#flash.on { animation: flash .5s; }
@keyframes flash { from { opacity: .9; } to { opacity: 0; } }

/* ---------- песочница (только dev=1) ---------- */
.dev-tag { position: absolute; right: calc(200px + var(--sr)); top: calc(40px + var(--st)); background: #ff3b30; color: #fff; font-weight: 900; font-size: 11px; padding: 3px 8px; border-radius: 6px; letter-spacing: .05em; }
.dev-stats { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(84px + var(--sb)); white-space: nowrap; font: 11px ui-monospace, Menlo, monospace; background: rgba(0, 0, 0, .55); padding: 4px 8px; border-radius: 6px; max-width: 60vw; }
.dev-console { position: absolute; left: 50%; transform: translateX(-50%); bottom: calc(110px + var(--sb)); }
.dev-console input { width: 200px; height: 30px; border-radius: 8px; border: 1px solid var(--line); background: rgba(0, 0, 0, .6); color: #fff; padding: 0 8px; font: 12px ui-monospace, Menlo, monospace; }

/* ---------- узкие и низкие экраны ---------- */
@media (max-height: 600px) {
  :root { --btn: 48px; }
  .toolbar { gap: 4px; top: calc(8px + var(--st)); flex-wrap: wrap; max-height: calc(100vh - 150px); align-content: flex-start; }
  .chat { left: calc(var(--btn) * 2 + 26px + var(--sl)); }
  .tb-btn span { display: none; }
  .sheet { top: calc(36px + var(--st)); bottom: calc(8px + var(--sb)); }
  .touch-btns { grid-template-columns: repeat(3, 52px); grid-auto-rows: 52px; gap: 10px; }
  .tbtn { width: 52px; height: 52px; }
  .joy-base { left: calc(var(--btn) * 2 + 120px + var(--sl)); }
  .tbtn.big { width: 66px; height: 66px; }
  .chat-log { max-height: 96px; }
}
@media (max-width: 640px) {
  .sheet { left: calc(8px + var(--sl)); right: calc(8px + var(--sr)); width: auto; top: auto; bottom: calc(8px + var(--sb)); max-height: 72vh; border-radius: 22px; }
  .sheet[data-panel="avatar"] { max-height: 52vh; }
  .chat { width: calc(100vw - var(--btn) - 90px); top: calc(36px + var(--st)); }
  .chat-log { max-height: 110px; font-size: 12px; }
  .hotbar { bottom: calc(150px + var(--sb)); }
  .mode-touch .hotbar { bottom: calc(160px + var(--sb)); left: auto; right: calc(8px + var(--sr)); transform: none; flex-direction: column; padding: 4px; }
  .mode-touch .hotbar .slot:not(.on):not(.bag) { display: none; }
  .slot { width: 48px; height: 48px; }
  .toasts { top: calc(56px + var(--st)); }
}
@media (max-width: 640px) and (max-height: 700px) {
  .tb-btn span { display: none; }
}

/* за рулём рюкзак не нужен; на телефоне — не больше четырёх вещей + сумка */
.in-vehicle .hotbar { display: none; }
.mode-touch .hotbar .slot.extra:not(.on) { display: none; }

/* подсказки первых минут (что делать новичку) */
.goals {
  position: absolute; left: calc(var(--btn) + 22px + var(--sl)); bottom: calc(70px + var(--sb));
  background: rgba(14, 16, 26, .78); border: 1px solid var(--line); border-radius: 16px; padding: 10px 12px; max-width: min(300px, 40vw);
  font-size: 13px; line-height: 1.35; pointer-events: auto;
}
.goals h4 { margin: 0 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; opacity: .7; }
.goals button { display: flex; align-items: center; gap: 8px; min-height: 48px; width: 100%; text-align: left; font-weight: 700; }
.goals button i { font-style: normal; width: 22px; height: 22px; border-radius: 50%; border: 2px solid rgba(255,255,255,.5); display: inline-flex; align-items: center; justify-content: center; font-size: 13px; flex: 0 0 auto; }
.goals button.done { opacity: .55; text-decoration: line-through; }
.goals button.done i { background: var(--ok); border-color: var(--ok); color: #0b1a0e; }
.mode-touch .goals { left: auto; right: calc(12px + var(--sr)); bottom: auto; top: calc(150px + var(--st)); max-width: min(250px, 42vw); }
.goals.hidden { display: none; }
