/* Шрифты (OFL, assets/fonts): Nunito — текст, Philosopher Bold — заголовки. */
@font-face { font-family: "Nunito"; font-weight: 400 900; font-display: swap; src: url(../assets/fonts/nunito-cyrillic.woff2) format("woff2"); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Nunito"; font-weight: 400 900; font-display: swap; src: url(../assets/fonts/nunito-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Philosopher"; font-weight: 700; font-display: swap; src: url(../assets/fonts/philosopher-bold-cyrillic.woff2) format("woff2"); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: "Philosopher"; font-weight: 700; font-display: swap; src: url(../assets/fonts/philosopher-bold-latin.woff2) format("woff2"); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

/* Палитра: тёмное «стекло» поверх 3D-мира, тёплый светлый текст, золото для акцентов. */
:root {
  --glass: rgba(22, 26, 40, 0.78);
  --panel: rgba(26, 30, 46, 0.94);
  --panel-solid: #1b1f2f; /* шапка окна поверх прокрученного текста */
  --cell: #2b3247;
  --cell-hi: #374060;
  --line: rgba(255, 255, 255, 0.09);
  --text: #f3ead8;
  --muted: #a7a3ae;
  --accent: #f2c14e;
  --bad: #ff6f61;
  --good: #8fd66a;
  --hp: #e5484d;
  --gold: #f2c14e;
  --shadow: 0 8px 24px rgba(0, 0, 0, 0.35);
  --radius: 14px;
  --head: "Philosopher", "Nunito", serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  overflow: hidden;
  background: #151925;
  color: var(--text);
  font-family: "Nunito", system-ui, sans-serif;
  font-size: 14px;
  user-select: none;
}

#game { position: fixed; inset: 0; display: block; touch-action: none; -webkit-tap-highlight-color: transparent; } /* касание ведёт героя, а не листает страницу */
/* Красная вспышка экрана, когда бьют своего героя. */
#hurt { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(transparent 40%, rgb(160, 20, 20)); opacity: 0; }
#hurt.on { animation: hurt 0.2s ease-out; }
@keyframes hurt { from { opacity: 0.45; } to { opacity: 0; } }
/* Ослепление Лихом второго круга: тьма по краям на --ms (view3d.js, fx blind) */
#blind { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(rgb(10, 8, 16, 0.55) 20%, rgb(10, 8, 16) 65%); opacity: 0; }
#blind.on { animation: blind var(--ms, 4s) ease-in-out; }
@keyframes blind { 8%, 80% { opacity: 0.9; } to { opacity: 0; } }
/* Мало здоровья: края экрана пульсируют красным, пока герой не подлечится. */
#lowhp { position: fixed; inset: 0; pointer-events: none; background: radial-gradient(transparent 50%, rgba(170, 20, 20, 0.6)); opacity: 0; }
#lowhp.on { animation: lowhp 1.2s ease-in-out infinite; }
@keyframes lowhp { 50% { opacity: 0.85; } from, to { opacity: 0.25; } }
/* Смерть героя — Навь (лор 15.30): земля сереет, по центру надпись и отсчёт до возрождения,
   красная нить тянется к костру или роднику, где герой встанет. */
#death {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(12, 4, 6, 0.42);
  backdrop-filter: grayscale(1) brightness(0.8);
  animation: death-in 0.8s ease-out;
}
#death[hidden] { display: none; }
#death b { font-family: var(--head); font-size: 42px; color: var(--bad); text-shadow: 0 2px 10px #000; }
#death span { font-size: 16px; color: var(--text); text-shadow: 0 1px 4px #000; }
#death-thread {
  position: fixed;
  left: 0;
  top: 0;
  height: 2px;
  background: linear-gradient(90deg, transparent, var(--bad) 30%);
  box-shadow: 0 0 6px var(--bad);
  transform-origin: 0 50%;
}
#death-thread[hidden] { display: none; }
/* остриё на конце нити */
#death-thread::after {
  content: '';
  position: absolute;
  right: -2px;
  top: -5px;
  border: 6px solid transparent;
  border-left: 10px solid var(--bad);
  border-right: 0;
}
@keyframes death-in { from { opacity: 0; } }
/* Без сил (down.go): земля тускнеет слабее, чем в Нави; надпись сверху, чтобы видна была
   полоска подъёма над лежащим героем; «К роднику» — не ждать товарища. */
#down {
  position: fixed;
  inset: 0;
  z-index: 2;
  pointer-events: none;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 6px;
  padding-top: 14vh;
  background: rgba(8, 10, 24, 0.3);
  backdrop-filter: grayscale(0.6) brightness(0.85);
  animation: death-in 0.6s ease-out;
}
#down[hidden], #lift-hint[hidden] { display: none; }
#down b { font-family: var(--head); font-size: 34px; color: #a8b4d0; text-shadow: 0 2px 10px #000; }
#down span, #down small { color: var(--text); text-shadow: 0 1px 4px #000; }
#down span { font-size: 15px; }
#down small { font-size: 13px; opacity: 0.85; }
#down button { pointer-events: auto; margin-top: 4px; min-height: 40px; padding: 4px 18px; font-size: 15px; color: var(--gold); font-weight: 700; }
/* Товарищу рядом с лежащим без сил: кого поднять и как; под героем, не под окном «Без сил». */
#lift-hint {
  position: fixed;
  left: 50%;
  bottom: 24vh;
  transform: translateX(-50%);
  z-index: 2;
  pointer-events: none;
  padding: 4px 12px;
  border-radius: 6px;
  background: rgba(20, 16, 8, 0.6);
  color: var(--gold);
  font-size: 14px;
  font-weight: 700;
  text-shadow: 0 1px 3px #000;
  white-space: nowrap;
}

/* ---- HUD ---- */

#hud {
  position: fixed;
  top: 12px;
  left: 12px;
  padding: 6px 8px;
  min-width: 160px;
  background: var(--glass);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  backdrop-filter: blur(6px);
}

#hud-top { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 4px; }
#hud-name { font-family: var(--head); font-weight: 700; font-size: 13px; }
/* Уровень — кнопка навыков (решение 2026-11-04, 07-ui-decisions): отдельной звезды в HUD нет, точка очков — на уровне. */
#hud-lv { position: relative; margin: 0; padding: 0 3px; min-height: 0; border: 0; border-radius: 4px; background: none; color: var(--gold); font-family: inherit; font-size: 11px; font-weight: 800; line-height: 1.4; cursor: pointer; }
#hud-lv:hover { background: rgba(255, 255, 255, 0.16); }
#hud-xp { margin-left: 4px; color: #a6dd7c; font-size: 11px; font-weight: 800; } /* доля опыта до уровня — вместо полосы опыта */
#hud-path { color: var(--muted); font-size: 11px; font-weight: 600; } /* имя пути рядом с именем героя (лор 8) */
#hud-title { display: block; color: var(--gold); font-size: 11px; font-weight: 600; } /* прозвание ристалища строкой под именем (лор 15.26) */
#hud-title[hidden] { display: none; }
.hud-buttons { display: flex; gap: 4px; }
#home-toggle, #codex-toggle, #journal-toggle, #settings-toggle {
  position: relative; width: 22px; height: 20px; padding: 0; display: grid; place-items: center;
  font-size: 12px; line-height: 1; color: var(--text); background: rgba(255, 255, 255, 0.07); border-color: transparent;
  font-variant-emoji: text;
}
#home-toggle:hover, #codex-toggle:hover, #journal-toggle:hover, #settings-toggle:hover { background: rgba(255, 255, 255, 0.16); }
#home-toggle[hidden] { display: none; }
/* Алатырь-камень из HUD: домой к роднику и назад по следу — только после подтверждения под HUD. */
#home-ask {
  position: absolute; top: calc(100% + 6px); left: 0; width: max-content; max-width: min(300px, 80vw); padding: 8px 10px;
  background: var(--glass); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow);
}
#home-ask[hidden] { display: none; }
#home-ask p { margin: 0 0 8px; font-size: 13px; line-height: 1.35; }
#home-ask div { display: flex; gap: 6px; justify-content: flex-end; }
#home-ask button { min-height: 32px; padding: 2px 12px; font-size: 13px; }
#home-ask-go { color: var(--gold); font-weight: 700; }
#hud-lv.has-points::after { content: ''; position: absolute; top: -2px; right: -3px; width: 7px; height: 7px; border-radius: 50%; background: var(--gold); box-shadow: 0 0 4px var(--gold); }

/* Полоски: скруглённые, с градиентом; число — только у здоровья, выносливость и мана читаются по длине. */
.hp, .bar { position: relative; overflow: hidden; background: rgba(0, 0, 0, 0.45); border-radius: 99px; box-shadow: inset 0 1px 2px rgba(0, 0, 0, 0.5); }
.hp { height: 12px; }
.bar { height: 5px; margin-top: 3px; }
.hp > div, .bar > div { height: 100%; width: 100%; border-radius: inherit; transition: width 0.15s; }
#hp-fill { background: linear-gradient(#ff7a6e, var(--hp) 55%, #b8303a); }
/* Выносливость и мана во всю ширину под здоровьем: вместе они не бывают, имя — в подсказке. */
.bar.sp, .bar.mp { height: 6px; }
.bar.sp > div { background: linear-gradient(#ffe08a, #e8b632); }
.bar.mp > div { background: linear-gradient(#8ab8ff, #3f74e0); }
#hp-text {
  position: absolute; inset: 0; text-align: center; font-weight: 800; color: #fff;
  text-shadow: 0 1px 2px rgba(0, 0, 0, 0.8); font-size: 11px; line-height: 12px;
}
.bar[hidden] { display: none; }

/* Сверхспособность с полным зарядом светится. */
@keyframes ultglow { from { box-shadow: 0 0 2px rgba(242, 193, 78, 0.5); } to { box-shadow: 0 0 14px rgba(242, 193, 78, 1); } }
/* Навык не готов: его кнопка вздрагивает и краснеет вместо сообщения (ui.js deny). */
.nope { animation: nope 0.35s ease-out; }
@keyframes nope { 20%, 60% { translate: -3px 0; } 40%, 80% { translate: 3px 0; } 30% { color: var(--bad); border-color: var(--bad); } }

.hud-stats { display: flex; gap: 10px; margin-top: 4px; font-size: 12px; line-height: 14px; }
.hud-stats .ico { width: 14px; height: 14px; }
.hud-stats span { display: inline-flex; align-items: center; gap: 4px; }
.hud-stats .gold { color: var(--gold); }
/* Значки из спрайта index.html: все одного размера и стоят на одной линии с текстом. */
.ico { flex: none; width: 16px; height: 16px; vertical-align: -3px; }

#corner {
  position: fixed; top: 12px; right: 12px; z-index: 2; pointer-events: none;
  display: flex; flex-direction: column; align-items: flex-end; gap: 8px;
}
/* Трекер свёрнут в строку «задание · счёт»; полный текст — по наведению или касанию (класс open). */
#quest {
  position: relative; max-width: 240px; pointer-events: auto; cursor: pointer;
  padding: 5px 10px 5px 34px; background: var(--glass); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); backdrop-filter: blur(6px); font-size: 13px;
}
#quest-head { display: flex; align-items: baseline; gap: 6px; }
#quest b { min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-family: var(--head); font-weight: 700; color: var(--gold); }
#quest-n { flex: none; font-weight: 800; }
#quest.done #quest-goal, #quest.done #quest-n, #quest-side.done { color: var(--good); }
#quest-goal { display: none; }
#quest-where { display: none; margin-top: 2px; font-size: 11px; color: var(--muted); font-style: italic; }
#quest-side { display: none; margin-top: 3px; font-size: 11px; color: var(--muted); }
#quest .icon { left: 5px; top: 50%; width: 24px; height: 24px; transform: translateY(-50%); }
#quest.open { padding: 7px 12px 7px 46px; }
#quest.open b { white-space: normal; }
#quest.open #quest-n { display: none; }
#quest.open #quest-goal, #quest.open #quest-where, #quest.open #quest-side { display: block; }
#quest.open .icon { left: 6px; width: 34px; height: 34px; }
#quest-side[hidden], #quest-where[hidden], #quest[hidden] { display: none !important; }
/* Ристалище (arena.js): соперник, счёт раундов, время фазы и итог. */
#arena {
  display: flex; align-items: center; gap: 10px; pointer-events: auto;
  padding: 6px 10px; background: var(--glass); border: 1px solid var(--line); border-radius: 12px;
  box-shadow: var(--shadow); backdrop-filter: blur(6px); font-size: 13px;
}
#arena[hidden], #arena-leave[hidden] { display: none; }
#arena-body { display: flex; flex-direction: column; align-items: flex-end; gap: 1px; }
#arena-body b { font-family: var(--head); color: var(--gold); }
#arena-body small { font-size: 11px; color: var(--muted); }
.arena-score { font-family: var(--head); font-weight: 800; font-size: 20px; letter-spacing: 1px; }
.arena-board { width: 100%; border-collapse: collapse; font-size: 13px; }
.arena-board td, .arena-board th { padding: 2px 6px; }
.arena-board th { font-size: 11px; font-weight: 600; color: var(--muted); }
.arena-board :is(td, th):not(:nth-child(2)) { text-align: right; }
.arena-board th:nth-child(2) { text-align: left; }
.arena-board tr.me { color: var(--gold); font-weight: 800; }

#zone-banner {
  position: fixed; top: 22%; left: 50%; transform: translateX(-50%);
  padding: 8px 22px; z-index: 3; pointer-events: none;
  font-family: var(--head); font-weight: 700; color: #fff6e0; font-size: 30px; text-align: center;
  width: max-content; max-width: calc(100vw - 32px); /* длинное название главы переносится на телефоне */
  text-shadow: 0 2px 10px rgba(0, 0, 0, 0.7), 0 1px 2px rgba(0, 0, 0, 0.9);
  transition: opacity 0.8s;
}
#zone-banner i { display: block; margin-top: 2px; font-size: 17px; font-weight: 400; color: var(--text); }
#zone-banner small { display: block; font-size: 15px; color: var(--gold); letter-spacing: 2px; }
#zone-banner.fade { opacity: 0; }

#boss-bar {
  position: fixed; top: 12px; left: 50%; transform: translateX(-50%); z-index: 2;
  width: min(360px, 60vw); text-align: center; font-family: var(--head); font-weight: 700; font-size: 15px;
  text-shadow: 0 1px 3px rgba(0, 0, 0, 0.9);
}
#boss-bar > div { height: 10px; margin-top: 3px; overflow: hidden; border-radius: 99px; background: rgba(0, 0, 0, 0.55); box-shadow: 0 0 0 1px rgba(255, 255, 255, 0.15); }
#boss-fill { height: 100%; background: linear-gradient(#ff7a6e, #c42f3c); transition: width 0.2s; }
#boss-bar[hidden] { display: none; }
/* Узкий экран: вверху место занято HUD и заданием, полоска уходит вниз, чтобы не закрывать поле.
   Мышь — над строкой навыков (предложение поднимается выше неё); касание — между стиком и кнопками. */
@media (max-width: 900px) {
  #boss-bar { top: auto; bottom: calc(86px + var(--help-h, 0px)); width: min(360px, calc(100vw - 32px)); }
  body:not(.touch):has(#boss-bar:not([hidden])) .offer { bottom: calc(130px + var(--help-h, 0px)); }
  body.touch #boss-bar {
    bottom: calc(18px + env(safe-area-inset-bottom));
    width: min(320px, calc(100vw - 2 * (32px + 214px * var(--touch-scale, 0.76))));
  }
  /* Ряд кнопок внизу занимает низ целиком — полоска над ним. */
  body.touch[data-pad="row"] #boss-bar { bottom: calc(24px + 84px * var(--touch-scale, 0.76) + env(safe-area-inset-bottom)); width: min(360px, calc(100vw - 32px)); }
}

#help {
  position: fixed; bottom: 10px; left: 50%; transform: translateX(-50%);
  padding: 4px 12px; background: var(--glass); border-radius: 12px;
  color: var(--muted); font-size: 12px; text-align: center; width: max-content;
  max-width: calc(100vw - 264px); /* не заходит под миникарту справа внизу; узкое окно — в две строки */
}

/* ---- окна ---- */

.panel {
  position: fixed;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: min(380px, calc(100vw - 32px));
  max-height: calc(100vh - 32px);
  overflow-y: auto;
  padding: 0 16px 16px; /* верхний отступ — у шапки */
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 18px;
  box-shadow: 0 18px 50px rgba(0, 0, 0, 0.5);
  backdrop-filter: blur(8px);
  scrollbar-width: thin;
  scrollbar-color: var(--cell-hi) transparent;
}

/* Заголовок с крестиком не уезжает при прокрутке длинного окна. */
.panel-head {
  position: sticky;
  top: 0;
  z-index: 1;
  margin: 0 -16px 8px;
  padding: 14px 16px 6px;
  background: var(--panel-solid);
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-family: var(--head);
  font-size: 20px;
  font-weight: 700;
}
.panel-head button { width: 30px; height: 30px; padding: 0; display: grid; place-items: center; border-radius: 50%; }
.head-actions { display: flex; gap: 8px; align-items: center; }

.muted { color: var(--muted); font-weight: 400; font-size: 13px; }

button,
a.button {
  display: inline-block;
  text-decoration: none;
  font: inherit;
  font-weight: 700;
  color: var(--text);
  background: linear-gradient(#3d4664, #2e3550);
  border: 1px solid rgba(255, 255, 255, 0.12);
  border-radius: 10px;
  padding: 4px 12px;
  cursor: pointer;
  box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
}
button:hover { background: linear-gradient(#4a5578, #384063); }
button:active { transform: translateY(1px); }
button:disabled { opacity: 0.4; cursor: default; transform: none; }
button .ico { vertical-align: -3px; }

#dialog { width: min(440px, 94vw); max-height: 80vh; }
#dialog p { margin: 4px 0 10px; line-height: 1.45; }
.side-quest { margin-bottom: 10px; padding: 8px 10px; border: 1px solid var(--line); border-radius: 10px; }
.side-quest b { font-family: var(--head); color: var(--gold); }
.side-quest p { margin: 4px 0 6px; }
.side-quest .shop-row { border-top: 0; padding: 0; }
.topics { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 10px; }
/* Окно жителя: вкладки по смыслу блоков (04-plan, 2026-11-04) и заголовки групп одним стилем. */
.dlg-tabs { display: flex; margin: 0 0 10px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
.dlg-tabs button { flex: none; padding: 6px 10px; background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; color: var(--muted); font-weight: 700; }
.dlg-tabs button:hover { background: none; color: var(--text); }
.dlg-tabs button.on { color: var(--gold); border-bottom-color: var(--gold); }
.dlg-tabs button small { margin-left: 5px; padding: 0 6px; border-radius: 99px; background: var(--gold); color: var(--panel-solid); font-size: 11px; }
.dlg-head { margin: 10px 0 4px; font-family: var(--head); font-weight: 700; color: var(--gold); }
.dlg-head small { font-family: "Nunito", sans-serif; font-weight: 400; }
.shop-row { display: flex; align-items: center; gap: 8px; padding: 4px 0; border-top: 1px solid var(--line); }
.shop-row .icon { position: relative; flex: none; width: 32px; height: 32px; }
.shop-row > span:not(.btns) { flex: 1; }
.shop-row .btns { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 4px; }
.shop-row .unfit { color: var(--muted); }
.shop-row .why { display: block; font-size: 11px; color: var(--bad); } /* почему кнопки погашены */
.shop-row .say { display: block; font-size: 11px; font-style: italic; color: var(--muted); } /* слово жителя под заказом и рецептом */
.shop-row button { padding: 3px 10px; white-space: nowrap; }
#trade { width: min(440px, 94vw); max-height: 80vh; }
#trade-oath { margin: 0 0 8px; font-style: italic; } /* слово Прохора над столом (лор 15.26) */
.trade-side { margin-bottom: 8px; padding: 6px 10px; border: 1px solid var(--line); border-radius: 10px; }
.trade-side > b { font-family: var(--head); color: var(--gold); }
.trade-side .good { color: var(--good); }
.trade-side .shop-row:first-of-type { border-top: 0; }
#trade-coins-row input { width: 90px; font: inherit; padding: 3px 8px; color: var(--text); background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line); border-radius: 8px; }
#trade-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 6px; margin-top: 8px; }

/* Выбор пути и имени — окна, которые нельзя закрыть: остальное затемнено и не нажимается. */
.modal { z-index: 4; box-shadow: 0 0 0 100vmax rgba(0, 0, 0, 0.45), 0 18px 50px rgba(0, 0, 0, 0.5); }
body:has(.modal:not([hidden])) #hud { pointer-events: none; }
body:has(.modal:not([hidden])) #touch { display: none; }
.modal p { margin: 4px 0 12px; line-height: 1.4; }
#class-picker { width: min(640px, 94vw); }
#class-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); gap: 8px; }
#class-list button { display: flex; gap: 10px; align-items: center; text-align: left; padding: 8px; font-size: 15px; border-radius: 12px; }
#class-list .icon { position: relative; flex: none; width: 48px; height: 48px; border-radius: 10px; background-color: rgba(0, 0, 0, 0.25); }
#class-list small { display: block; color: var(--muted); font-size: 11px; font-weight: 600; line-height: 1.3; }
#class-list .nw, #inv-party .nw, #inv-clan .nw { white-space: nowrap; }
#class-list small.role { color: var(--text); font-size: 12px; font-style: italic; } /* роль пути второй строкой */
/* Низкий экран: пять узких карточек в ряд, значок над текстом. */
@media (max-height: 500px) {
  #class-picker { width: min(820px, calc(100vw - 24px)); }
  #class-picker p { margin-bottom: 8px; }
  #class-list { grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 6px; }
  #class-list button { flex-direction: column; align-items: center; gap: 4px; padding: 6px; text-align: center; font-size: 14px; }
  #class-list .icon { width: 40px; height: 40px; }
}

/* Имя и облик: портрет слева, имя и ряды выбора справа. */
#name-picker { width: min(520px, 94vw); }
#name-picker .look-body { display: flex; flex-wrap: wrap; justify-content: center; gap: 14px; align-items: center; }
#name-picker .look-body > div { flex: 1 1 220px; min-width: 0; } /* узкий экран: портрет над выбором */
.look-preview { flex: none; width: 160px; height: 160px; border-radius: 12px; background: rgba(0, 0, 0, 0.25); }
#name-picker input { width: 100%; box-sizing: border-box; font: inherit; font-size: 17px; padding: 6px 10px; color: var(--text); background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line); border-radius: 8px; }
.look-parts { display: grid; grid-template-columns: auto 1fr; gap: 6px 10px; align-items: center; }
.look-parts > span { color: var(--muted); font-size: 13px; }
.look-parts div { display: flex; gap: 6px; }
.look-parts button { width: 30px; height: 30px; padding: 0; border-radius: 50%; }
.look-parts button[data-part='0'] { display: grid; place-items: center; width: 44px; height: 44px; border-radius: 10px; }
.look-parts .icon { position: relative; width: 36px; height: 36px; }
.look-parts button[aria-pressed='true'] { box-shadow: 0 0 0 2px var(--accent), 0 0 10px rgba(242, 193, 78, 0.45); }
#name-picker .name-why { min-height: 1.4em; margin: 8px 0; color: var(--bad); }
#name-picker button[type='submit'] { width: 100%; padding: 8px; font-size: 15px; }
@media (max-height: 500px) {
  #name-picker { width: min(600px, calc(100vw - 24px)); }
  .look-preview { width: 120px; height: 120px; }
  #name-picker p { margin: 2px 0 6px; }
  #name-picker .name-why { margin: 4px 0; }
  #name-picker button[type='submit'] { padding: 6px; }
}

#settings fieldset { display: flex; flex-wrap: wrap; gap: 6px 14px; margin: 0 0 10px; padding: 8px 12px 10px; border: 1px solid var(--line); border-radius: 12px; }
#settings legend { padding: 0 4px; color: var(--muted); }
#settings label { display: flex; align-items: center; gap: 6px; cursor: pointer; }
#settings input { accent-color: var(--accent); }
#settings p { margin: 6px 0 0; font-size: 12px; line-height: 1.4; }
#settings .recovery { margin: 12px 0 0; align-items: center; }
#settings .recovery p { flex-basis: 100%; }
#recovery-code { flex-basis: 100%; padding: 6px 8px; border-radius: 8px; background: rgba(0, 0, 0, 0.3); font-size: 13px; letter-spacing: 0.04em; word-break: break-all; user-select: all; }
.code-login { display: flex; flex-wrap: wrap; gap: 6px; flex-basis: 100%; }
.code-login input { flex: 1; min-width: 0; font: inherit; font-size: 13px; padding: 4px 8px; color: var(--text); background: rgba(0, 0, 0, 0.3); border: 1px solid var(--line); border-radius: 8px; }
.code-login .code-status { flex-basis: 100%; }
.code-status:empty, #recovery-copied:empty, #transfer-status:empty { display: none; }
#settings .transfer { margin: 12px 0 0; align-items: center; }
#settings .transfer p, #transfer-status { flex-basis: 100%; }
#transfer-box { display: flex; flex-wrap: wrap; gap: 6px 10px; align-items: center; flex-basis: 100%; }
#transfer-box[hidden] { display: none; }
/* Модули QR-кода — чёткие квадраты; белое поле нужно камере, чтобы найти код. */
#transfer-qr { flex-basis: 100%; max-width: 200px; aspect-ratio: 1; image-rendering: pixelated; border-radius: 8px; }
#transfer-url { flex-basis: 100%; padding: 6px 8px; border-radius: 8px; background: rgba(0, 0, 0, 0.3); font-size: 12px; word-break: break-all; user-select: all; }

/* ---- бестиарий ---- */

.codex-tabs { display: flex; gap: 6px; margin-bottom: 6px; }
.codex-tabs button { flex: 1; }
.codex-tabs button[aria-pressed='true'] { box-shadow: 0 0 0 2px var(--accent); }
#codex-tales article { padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--text); }
#codex-tales article:last-child { border-bottom: 0; }
#codex-tales h3 { margin: 0 0 4px; font-family: var(--head); font-size: 16px; color: var(--gold); }
#codex-tales p { margin: 0; font-size: 13px; line-height: 1.5; font-style: italic; }
#codex-list article { display: flex; gap: 10px; align-items: flex-start; padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--text); }
#codex-list article > div { flex: 1; min-width: 0; }
#codex-list img { flex: none; border-radius: 12px; background: radial-gradient(circle at 50% 60%, rgba(255, 255, 255, 0.12), transparent 70%); }
#codex-list article:last-child { border-bottom: 0; }
#codex-list h3 { display: flex; justify-content: space-between; gap: 8px; margin: 0 0 4px; font-family: var(--head); font-size: 16px; }
#codex-list h3 .muted { font-family: inherit; font-size: 12px; font-weight: 400; }
#codex-list .boss h3 { color: #ff9a6a; }
#codex-list p { margin: 0; font-size: 13px; line-height: 1.45; }
/* опись Прохора: счёт по землям, разделы, записи со значком; закрытая — силуэтом */
#codex-lands { margin: 0 0 6px; font-size: 12px; line-height: 1.5; }
#codex-ledger h3.sec, #codex-ledger h4 { display: flex; justify-content: space-between; gap: 8px; margin: 10px 0 2px; font-family: var(--head); color: var(--gold); }
#codex-ledger h3.sec { font-size: 17px; }
#codex-ledger h4 { font-size: 14px; }
#codex-ledger h3.sec .muted, #codex-ledger h4 .muted { font-family: inherit; font-size: 12px; font-weight: 400; }
#codex-ledger article { display: flex; gap: 10px; align-items: flex-start; padding: 6px 0; border-bottom: 1px solid var(--line); color: var(--text); }
#codex-ledger article > div { flex: 1; min-width: 0; }
#codex-ledger article h3 { margin: 0 0 2px; font-family: var(--head); font-size: 15px; }
#codex-ledger p { margin: 0; font-size: 13px; line-height: 1.45; }
.ledger-icon { position: relative; flex: none; width: 48px; height: 48px; }
#codex-ledger .shut .icon { filter: brightness(0); opacity: 0.7; }
#codex-ledger .shut h3 { color: var(--muted); }
/* подвиги (feat.go): невыполненные приглушены, выполненный золотом и с кнопкой прозвища */
#codex-feats h3.sec { display: flex; justify-content: space-between; gap: 8px; margin: 10px 0 2px; font-family: var(--head); font-size: 17px; color: var(--gold); }
#codex-feats article { padding: 6px 0; border-bottom: 1px solid var(--line); color: var(--muted); }
#codex-feats article.done { color: var(--text); }
#codex-feats article h3 { display: flex; justify-content: space-between; gap: 8px; margin: 0 0 2px; font-family: var(--head); font-size: 15px; }
#codex-feats article.done h3 { color: var(--gold); }
#codex-feats h3 .muted { font-family: inherit; font-size: 12px; font-weight: 400; }
#codex-feats p { margin: 0 0 4px; font-size: 13px; line-height: 1.45; }
#codex-feats button { margin-right: 6px; }

/* Журнал событий: время, текст, счёт повторов. */
#journal-list > div { display: flex; gap: 8px; align-items: baseline; padding: 5px 0; border-bottom: 1px solid var(--line); color: var(--text); font-size: 13px; line-height: 1.4; }
#journal-list > div:last-child { border-bottom: 0; }
#journal-list time { flex: none; color: var(--muted); font-size: 12px; font-variant-numeric: tabular-nums; }
#journal-list span { flex: 1; min-width: 0; overflow-wrap: anywhere; }
#journal-list b { flex: none; color: var(--gold); font-size: 12px; }

/* Что нового: выпуски — дата, заголовок, строки. Кнопка открытия — первой строкой настроек. */
#news-open, #name-open { width: 100%; margin-bottom: 10px; }
#news { width: min(440px, calc(100vw - 32px)); }
#news-list article { padding: 8px 0; border-bottom: 1px solid var(--line); color: var(--text); }
#news-list article:last-child { border-bottom: 0; }
#news-list time { color: var(--muted); font-size: 12px; }
#news-list h3 { margin: 0 0 4px; font-family: var(--head); font-size: 16px; color: var(--gold); }
#news-list h4 { margin: 8px 0 2px; font-size: 13px; color: var(--text); letter-spacing: .02em; }
#news-list ul { margin: 0; padding-left: 18px; }
#news-list li { margin: 4px 0; font-size: 13px; line-height: 1.45; overflow-wrap: anywhere; }

/* ---- навыки ---- */

#skills { width: min(560px, calc(100vw - 32px)); }
.skill-slots { display: flex; flex-wrap: wrap; gap: 2px 12px; font-size: 13px; margin-bottom: 4px; }
.skill-slots b { min-width: 76px; color: var(--gold); }
.skill-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; border-top: 1px solid var(--line); }
.skill-row.unlearned .icon { opacity: 0.45; }
.skill-row .icon { position: relative; flex: none; width: 32px; height: 32px; }
.skill-text { flex: 1; min-width: 0; font-size: 14px; }
.skill-text small { display: block; font-size: 12px; line-height: 1.3; }
.skill-text .skill-lore { color: var(--muted); font-style: italic; } /* лорная строка навыка (лор 15.27) */
.skill-row .btns { display: flex; gap: 4px; flex: none; }
.skill-row button { min-width: 30px; padding: 3px 8px; }
.skill-row button.on { background: var(--accent); color: #1b1724; opacity: 1; }
.skill-foot { margin: 8px 0 0; line-height: 1.5; }

/* ---- инвентарь ---- */

#equipment { display: flex; gap: 12px; margin-bottom: 8px; }
.equip-slot .label { font-size: 12px; color: var(--muted); margin-bottom: 2px; }
#inv-stats { margin-bottom: 4px; }
#inv-passives { margin-bottom: 10px; font-size: 12px; }
#inv-party, #inv-clan { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; font-size: 12px; }
#inv-party[hidden], #inv-clan[hidden] { display: none; }
.clan-form { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 6px; }
.clan-form input, .clan-form select { flex: 1 1 120px; min-width: 0; }

/* Вкладки сумки: по виду вещи; на телефоне ряд прокручивается вбок, если не влез. */
/* Вкладки сумки — строка-закладки над сеткой, а не крупные кнопки: высота окна на телефоне дорога. */
#inv-tabs { display: flex; margin-bottom: 6px; border-bottom: 1px solid var(--line); overflow-x: auto; scrollbar-width: none; }
#inv-tabs button {
  flex: none; min-height: 30px; margin-bottom: -1px; padding: 2px 10px;
  background: none; border: 0; border-bottom: 2px solid transparent; border-radius: 0; box-shadow: none;
  color: var(--muted); font-size: 13px;
}
#inv-tabs button:hover { background: none; color: var(--text); }
#inv-tabs button small { margin-left: 2px; font-weight: 400; opacity: 0.8; }
#inv-tabs button.on { color: var(--gold); border-bottom-color: var(--gold); }

#inv-grid {
  display: grid;
  grid-template-columns: repeat(6, 52px);
  gap: 5px;
  justify-content: center;
}

.cell {
  position: relative;
  width: 52px;
  height: 52px;
  background: var(--cell);
  border-radius: 10px;
  box-shadow: inset 0 0 0 1px var(--line);
  cursor: pointer;
}
.cell:hover { background: var(--cell-hi); }
/* рамка снаряжения по редкости: простая, добротная, заговорённая, чудесная */
.cell.r0 { box-shadow: inset 0 0 0 1px rgba(243, 234, 216, 0.6); }
.cell.r1 { box-shadow: inset 0 0 0 2px #5fc95a; }
.cell.r2 { box-shadow: inset 0 0 0 2px #4f9dff; }
.cell.r3 { box-shadow: inset 0 0 0 2px var(--gold), 0 0 8px rgba(242, 193, 78, 0.35); }
.rar1 { color: #7fdc6f; }
.rar2 { color: #78b4ff; }
.rar3 { color: var(--gold); }
.cell.empty { cursor: default; background: rgba(43, 50, 71, 0.45); }
.cell.selected { box-shadow: inset 0 0 0 2px var(--accent), 0 0 10px rgba(242, 193, 78, 0.35); }
.cell .icon { left: 2px; top: 2px; }
.cell .plus { position: absolute; left: 4px; top: 2px; font-size: 11px; font-weight: 800; color: var(--good); text-shadow: 0 1px 2px #000; }
.cell.unfit .icon { opacity: 0.45; }
.cell.unfit::after { content: '✕'; position: absolute; right: 4px; top: 1px; font-size: 11px; color: var(--bad); }
.cell.junk { background: #33302f; }
.cell .cmp { position: absolute; right: 4px; top: 1px; font-size: 11px; text-shadow: 0 1px 2px #000; } /* лучше/хуже надетого */
.cell .cmp.up, #inv-details .good { color: var(--good); }
/* подклеть Прохора в разговоре: ячейки-кнопки, как в сумке */
.stash-grid { display: grid; grid-template-columns: repeat(auto-fill, 52px); gap: 5px; justify-content: center; margin: 4px 0 8px; }
.stash-grid button.cell { padding: 0; border: 0; border-radius: 10px; font-weight: 400; }
/* узоры Прохора: цвет нити и кнопки перекраски */
.swatch { display: inline-block; width: 12px; height: 12px; margin-right: 6px; border-radius: 3px; vertical-align: -1px; box-shadow: 0 0 0 1px #0006; }
button.swatch-btn { padding: 4px 6px; }
button.swatch-btn .swatch { margin: 0; width: 16px; height: 16px; }
.cell .cmp.down, #inv-details .bad { color: var(--bad); }
.tier { color: var(--accent); }

.icon {
  position: absolute;
  left: 0;
  top: 0;
  width: 48px;
  height: 48px;
  background: url(../assets/icons/icons.png) no-repeat;
  background-size: var(--icon-grid, 1000% 900%);
}

/* Значок пути (analytics/07 §3) в строке перед именем пути или героя: размер — от шрифта строки. */
.path-icon {
  display: inline-block;
  width: 1.6em;
  height: 1.6em;
  margin-right: 2px;
  vertical-align: -0.45em;
  background: url(../assets/icons/icons.png) no-repeat;
  background-size: var(--icon-grid, 1000% 900%);
}
#hud-path .path-icon { width: 20px; height: 20px; vertical-align: -6px; }

.qty {
  position: absolute;
  right: 4px;
  bottom: 1px;
  font-size: 12px;
  font-weight: 800;
  color: #fff;
  text-shadow: 0 1px 2px #000, 0 0 3px #000;
}

#inv-details { min-height: 40px; margin-top: 12px; line-height: 1.4; }
#inv-actions { display: flex; gap: 6px; margin-top: 8px; }
#inv-actions .muted { align-self: center; margin-right: 2px; }

/* Низкий экран (телефон лёжа): две колонки — слева сетка, справа надетое, описание и кнопки; всё видно без прокрутки. */
@media (max-height: 500px) {
  #inventory {
    width: min(760px, calc(100vw - 24px)); display: grid; column-gap: 16px; align-content: start;
    grid-template-columns: auto 1fr;
    grid-template-areas: 'head head' 'tabs equip' 'grid equip' 'grid stats' 'grid passives' 'grid party' 'grid details' 'grid actions' 'grid .';
  }
  #inventory[hidden] { display: none; }
  #inventory .panel-head { grid-area: head; }
  #equipment { grid-area: equip; }
  #inv-stats { grid-area: stats; }
  #inv-passives { grid-area: passives; }
  #inv-party { grid-area: party; }
  #inv-tabs { grid-area: tabs; }
  #inv-grid { grid-area: grid; align-self: start; grid-template-columns: repeat(8, 52px); }
  #inv-details { grid-area: details; margin-top: 0; }
  #inv-actions { grid-area: actions; }
}

/* ---- сообщения ---- */

#toasts { display: flex; flex-direction: column; align-items: flex-end; gap: 6px; max-width: min(360px, calc(100vw - 24px)); }

.toast {
  padding: 6px 12px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  font-weight: 600;
  transition: opacity 0.5s;
}
.toast { display: flex; align-items: center; gap: 6px; }
.toast .icon { position: static; flex: none; width: 24px; height: 24px; margin: -3px 0; }
.toast.fade { opacity: 0; }
.toast .n { color: var(--gold); font-size: 12px; } /* «×3»: столько раз пришло то же сообщение */
.toast .n:empty { display: none; }

#status {
  position: fixed;
  top: 40%;
  left: 50%;
  transform: translateX(-50%);
  padding: 10px 16px;
  max-width: calc(100vw - 32px);
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: var(--shadow);
}

/* Отладочный экран (debug.js, F3): мелкий моноширинный текст в углу, щелчки проходят насквозь. */
#debug {
  position: fixed; left: 12px; bottom: 44px; z-index: 2; margin: 0; padding: 6px 8px;
  background: rgba(0, 0, 0, 0.68); border-radius: 8px; color: #d6f0c8;
  max-width: calc(100vw - 24px); font: 11px/1.35 ui-monospace, Menlo, Consolas, monospace; white-space: pre-wrap; pointer-events: none;
}

#minimap {
  position: fixed;
  right: 12px;
  bottom: 12px;
  width: 108px;
  height: 108px;
  border: 2px solid rgba(255, 255, 255, 0.18);
  border-radius: 14px;
  box-shadow: var(--shadow);
  opacity: 0.92;
}
body.touch #minimap { bottom: auto; top: 12px; width: 88px; height: 88px; }

/* Карта земли (zonemap.js): холст по месту в окне, на телефоне окно во весь экран. */
#zonemap { display: flex; flex-direction: column; width: min(760px, calc(100vw - 32px)); height: min(620px, calc(100vh - 32px)); overflow: hidden; }
#zonemap[hidden] { display: none; }
#zonemap-goal { margin: 0 0 8px; font-size: 13px; line-height: 1.35; }
#zonemap-goal:empty { display: none; }
#zonemap-box { flex: 1; min-height: 0; display: grid; place-items: center; }
#zonemap-canvas { display: block; border-radius: 8px; }
#zonemap-mini { margin-top: 10px; }
body.touch #zonemap {
  inset: 0; transform: none; width: auto; height: auto; max-height: none; border-radius: 0;
  padding: 0 calc(12px + env(safe-area-inset-right)) calc(10px + env(safe-area-inset-bottom)) calc(12px + env(safe-area-inset-left));
}
body.touch #zonemap .panel-head { margin: 0 -12px 4px; padding: 6px 12px; }
body.touch #zonemap-mini { display: none; } /* на телефоне миникарта — вход в карту, её не прячут */
/* Лёжа высота дороже всего: карта во всю высоту слева, имя земли и цель — колонкой справа. */
@media (orientation: landscape) {
  body.touch #zonemap { display: grid; grid-template: auto 1fr / 1fr minmax(180px, 32%); grid-template-areas: 'box head' 'box goal'; column-gap: 12px; padding-top: calc(8px + env(safe-area-inset-top)); }
  body.touch #zonemap[hidden] { display: none; }
  body.touch #zonemap .panel-head { grid-area: head; margin: 0; padding: 0; background: none; border: 0; }
  body.touch #zonemap-goal { grid-area: goal; }
  body.touch #zonemap-box { grid-area: box; }
}
#minimap { cursor: pointer; }

.offer {
  position: fixed;
  left: 50%;
  bottom: 72px; /* над полосой подсказок, даже двухстрочной */
  transform: translateX(-50%);
  z-index: 2;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 8px 10px 8px 14px;
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 14px;
  box-shadow: var(--shadow);
  white-space: nowrap;
}
.offer button[data-mode="all"] { color: #2a1f10; background: linear-gradient(#ffd977, #e8a92e); }
body:not(.touch) .offer { bottom: calc(92px + var(--help-h, 0px)); } /* над строкой навыков */
body.touch .offer { top: 40%; bottom: auto; }
.offer[hidden] { display: none; }

/* ---- сенсорное управление ---- */

#hud, #minimap, #status { z-index: 2; }
.panel { z-index: 3; }
.modal { z-index: 4; }
/* Открытое окно (лавка, кузня, инвентарь, разговор) не должна закрывать миникарта, особенно на телефоне. */
body:has(.panel:not([hidden])) #minimap { display: none; }

#touch { position: fixed; inset: 0; z-index: 1; pointer-events: none; }
#touch button { pointer-events: auto; touch-action: none; -webkit-tap-highlight-color: transparent; }

/* Настройка размера (settings.js) масштабирует кнопки. */
#touch-buttons { transform: scale(var(--touch-scale, 0.76)); transform-origin: 100% 100%; }

#touch-buttons {
  position: absolute;
  right: calc(16px + env(safe-area-inset-right));
  bottom: calc(16px + env(safe-area-inset-bottom));
  width: 214px;
  height: 170px;
}

#touch-buttons button {
  position: absolute;
  width: 58px;
  height: 58px;
  padding: 0;
  border-radius: 50%;
  color: var(--text);
  background: rgba(22, 26, 40, 0.62);
  border: 2px solid rgba(255, 255, 255, 0.2);
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.35);
  user-select: none;
  -webkit-user-select: none;
  -webkit-touch-callout: none;
}
#touch-buttons button:active { background: rgba(60, 68, 100, 0.85); transform: scale(0.94); }
#touch-buttons button.warn { border-color: var(--bad); box-shadow: 0 0 14px rgba(255, 111, 97, 0.75); } /* мало здоровья: пора пить */
#touch-buttons .icon { left: 14px; top: 6px; width: 30px; height: 30px; }
/* Пустая ячейка или значок ещё не пришёл: без координат атлас показал бы первую клетку, монету. */
#touch-buttons .icon:not([style*="background-position"]) { background: none; }
/* Подпись шире кнопки: длинные имена навыков («Неистовство») не обрезаются. */
#touch-buttons .cap {
  position: absolute;
  left: -10px;
  right: -10px;
  bottom: 5px;
  font-size: 12px;
  font-weight: 800;
  line-height: 12px;
  white-space: nowrap;
  letter-spacing: -0.2px;
  text-shadow: 0 1px 2px #000;
}
#touch-buttons .qty { right: 6px; bottom: 14px; }
#touch-buttons .big { right: 0; bottom: 0; width: 84px; height: 84px; border-color: rgba(242, 193, 78, 0.7); }
#touch-buttons .big .icon { left: 16px; top: 16px; width: 48px; height: 48px; }
#touch-buttons :is([data-act^="skill"], [data-act="potion"]) { background-image: conic-gradient(rgba(201, 228, 255, 0.35) calc(var(--cd, 1) * 360deg), transparent 0); }
#touch-buttons :is([data-act^="skill"], [data-act="potion"]).cooling, #touch-buttons [data-act^="skill"].locked { opacity: 0.5; }
#touch-buttons .big .cap { bottom: 7px; }
#touch-buttons [data-act="ult"] { border-color: rgba(242, 193, 78, 0.7); background-image: conic-gradient(rgba(242, 193, 78, 0.4) calc(var(--cd, 0) * 360deg), transparent 0); }
#touch-buttons [data-act="ult"]:not(.ready) { opacity: 0.6; }
#touch-buttons [data-act="ult"].cooling { opacity: 0.5; background-image: conic-gradient(rgba(201, 228, 255, 0.35) calc(var(--cd, 1) * 360deg), transparent 0); }
#touch-buttons [data-act="ult"].ready { border-color: var(--gold); animation: ultglow 0.9s ease-in-out infinite alternate; }
[data-act="ult"] { right: 150px; bottom: 70px; }
[data-act="skill2"] { right: 94px; bottom: 0; }
[data-act="potion"] { right: 10px; bottom: 96px; }
[data-act="bag"] { right: 80px; bottom: 70px; }
#touch-buttons [data-act="phrase"] { right: 162px; bottom: 4px; width: 50px; height: 50px; background-image: conic-gradient(rgba(201, 228, 255, 0.35) calc(var(--cd, 1) * 360deg), transparent 0); }
#touch-buttons [data-act="phrase"] .ico { position: absolute; left: 13px; top: 7px; width: 22px; height: 22px; }
#touch-buttons [data-act="phrase"].cooling { opacity: 0.5; }
#touch-buttons .key { display: none; }
/* Раскладка «слева» (settings.js, body[data-pad]): то же гнездо зеркально, под левую руку. */
body.touch[data-pad="left"] #touch-buttons { right: auto; left: calc(16px + env(safe-area-inset-left)); transform-origin: 0 100%; }
body.touch[data-pad="left"] #touch-buttons button { right: auto; }
body.touch[data-pad="left"] #touch-buttons [data-act="ult"] { left: 150px; }
body.touch[data-pad="left"] #touch-buttons [data-act="skill2"] { left: 94px; }
body.touch[data-pad="left"] #touch-buttons [data-act="potion"] { left: 10px; }
body.touch[data-pad="left"] #touch-buttons [data-act="bag"] { left: 80px; }
body.touch[data-pad="left"] #touch-buttons .big { left: 0; }
body.touch[data-pad="left"] #touch-buttons [data-act="phrase"] { left: 162px; }
/* «Строкой внизу»: кнопки в ряд в правом нижнем углу, большая — у края; над рядом поле открыто. */
body.touch[data-pad="row"] #touch-buttons { width: auto; height: auto; display: flex; align-items: flex-end; gap: 10px; }
body.touch[data-pad="row"] #touch-buttons button { position: relative; inset: auto; flex: none; }
/* Своя расстановка поверх раскладки (touch.js layout): left/top — центр кнопки в координатах гнезда. */
body.touch #touch-buttons button.placed { position: absolute; right: auto; bottom: auto; translate: -50% -50%; }
#pad-edit-open { width: 100%; }
/* Правка расстановки: поле затенено и не принимает касаний, скрытые до изучения навыки видны. */
body.pad-edit #touch { z-index: 3; pointer-events: auto; background: rgba(0, 0, 0, 0.35); }
body.pad-edit #touch-buttons button { outline: 2px dashed rgba(242, 193, 78, 0.8); outline-offset: 3px; }
body.pad-edit #touch-buttons button[hidden] { display: block; opacity: 0.6; }
#pad-edit {
  position: absolute; top: calc(12px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%);
  display: flex; align-items: center; gap: 10px; padding: 8px 12px; border-radius: 12px;
  background: var(--panel-solid); border: 1px solid var(--line); white-space: nowrap;
}
#pad-edit[hidden] { display: none; }
/* На телефоне подпись не мельче 11 px на экране при любом размере кнопок (--touch-scale); одно слово
   в одну строку (skills.js CAPS). */
body.touch #touch-buttons .cap { left: -20px; right: -20px; font-size: max(12px, calc(11px / var(--touch-scale, 0.76))); line-height: 1; }

/* Компьютер: те же кнопки навыков строкой внизу по центру, над полосой подсказок (--help-h ставит
   touch.js); зелье и сумка — клавишами. В углу кнопки — цифра клавиши. */
body:not(.touch) #touch-buttons {
  left: 50%; right: auto; bottom: calc(18px + var(--help-h, 0px)); width: auto; height: auto;
  display: flex; gap: 24px; transform: translateX(-50%);
}
body:not(.touch) #touch-buttons button { position: relative; inset: auto; width: 58px; height: 58px; cursor: pointer; }
body:not(.touch) #touch-buttons :is([data-act="bag"], [data-act="potion"]) { display: none; }
body:not(.touch) #touch-buttons [data-act="skill1"] { order: -1; border-color: rgba(255, 255, 255, 0.2); }
body:not(.touch) #touch-buttons [data-act="ult"] { order: 1; }
body:not(.touch) #touch-buttons [data-act="phrase"] { order: 2; width: 46px; height: 46px; align-self: flex-end; }
body:not(.touch) #touch-buttons [data-act="phrase"] .ico { left: 11px; top: 5px; }
body:not(.touch) #touch-buttons .big .icon { left: 14px; top: 6px; width: 30px; height: 30px; }
body:not(.touch) #touch-buttons .big .cap { bottom: 5px; }
body:not(.touch) #touch-buttons .key {
  display: block; position: absolute; left: -5px; top: -5px; min-width: 18px; height: 18px; padding: 0 4px;
  border: 1px solid rgba(255, 255, 255, 0.3); border-radius: 9px; background: var(--panel-solid);
  font-size: 11px; font-weight: 800; line-height: 16px; color: var(--text);
}

/* Колесо фраз (phrases.js): прозрачная подложка ловит касание мимо, фразы кругом около --x, --y. */
#phrase-wheel { position: fixed; inset: 0; z-index: 3; touch-action: none; }
#phrase-wheel .phrase-ring { position: absolute; left: var(--x); top: var(--y); width: 0; height: 0; }
#phrase-wheel .phrase-ring::before {
  content: ''; position: absolute; left: -128px; top: -128px; width: 256px; height: 256px; border-radius: 50%;
  background: radial-gradient(circle, transparent 34px, rgba(14, 16, 26, 0.55) 35px, rgba(14, 16, 26, 0.55) 70%, transparent 71%);
}
#phrase-wheel button {
  position: absolute; transform: translate(-50%, -50%); min-width: 84px; height: 34px; padding: 0 10px;
  border-radius: 17px; border: 2px solid rgba(255, 255, 255, 0.25); background: rgba(22, 26, 40, 0.88);
  color: var(--text); font-size: 13px; font-weight: 800; white-space: nowrap; touch-action: none;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
}
#phrase-wheel button.hot, #phrase-wheel button:hover { border-color: var(--gold); background: rgba(60, 68, 100, 0.95); }

/* Тексты под устройство: на телефоне нет мыши и клавиш, на компьютере — касаний. */
body.touch .desk-only, body:not(.touch) .touch-only { display: none; }
body.touch #help { display: none; }
body.touch #corner { right: 120px; } /* слева от миникарты: под ней кнопки */
body.touch #quest { font-size: 12px; max-width: 180px; }
/* На телефоне имя героя и пути не нужно (от пути — лишь значок), а кнопки HUD — цели под палец: видимые 32 px, касание ловится на 44 px. */
body.touch #hud-name, body.touch #hud-path > span, body.touch #hud-title { display: none; }
body.touch .hud-buttons { gap: 12px; }
body.touch :is(#home-toggle, #codex-toggle, #journal-toggle, #settings-toggle) { width: 32px; height: 32px; font-size: 16px; }
body.touch #hud-lv { font-size: 13px; padding: 2px 5px; }
body.touch :is(#home-toggle, #codex-toggle, #journal-toggle, #settings-toggle)::after,
body.touch #hud-lv::before { content: ''; position: absolute; inset: -6px; } /* у уровня ::after — точка очков */
body.touch .hp { height: 15px; }
body.touch #hp-text { line-height: 15px; }
body.touch .hud-stats { font-size: 13px; }

@media (max-width: 700px) {
  #help { display: none; }
}
@media (max-width: 600px) {
  #inv-grid { grid-template-columns: repeat(5, 52px); }
}

/* Телефон держат вертикально: игра только альбомная, её закрывает просьба повернуть (orientation.js). */
#rotate { display: none; }
@media (orientation: portrait) and (pointer: coarse) {
  #rotate {
    position: fixed; inset: 0; z-index: 10; display: flex; flex-direction: column; align-items: center; justify-content: center;
    gap: 10px; padding: 24px; background: #151925; text-align: center;
  }
  #rotate svg { width: 72px; height: 72px; }
  #rotate b { font-family: var(--head); font-size: 22px; }
  #rotate .muted { max-width: 280px; line-height: 1.4; }
  /* Главная кнопка экрана: полный экран с альбомной блокировкой там, где браузер её даёт. */
  #rotate-full {
    display: flex; align-items: center; gap: 10px; margin-top: 10px; padding: 14px 28px;
    font-size: 19px; color: #241a05; background: linear-gradient(#ffd877, var(--gold)); border-color: #fff3c4;
    border-radius: 14px; animation: ultglow 1.2s ease-in-out infinite alternate;
  }
  #rotate-full svg { width: 24px; height: 24px; }
  #rotate-full[hidden], #rotate-full-hint[hidden] { display: none; }
}
