/* Братва и Кольцо: помощник. Тёмная тема в тон игре (пергамент, бронза).
   Мобильная ширина первична: 320-430, на десктопе колонка до 640. */
:root {
  --bg: #15110d;
  --bg2: #1e1812;
  --card: #261e16;
  --card2: #2f251b;
  --line: #3d3125;
  --text: #f1e6d4;
  --muted: #a8977f;
  --faint: #6f604e;
  --gold: #e3b45a;
  --gold2: #c8923a;
  --green: #79c26b;
  --red: #e0685a;
  --blue: #6fb0e0;
  --ink: #3b2614;            /* текст по пергаменту игры */
  --violet: #b58be0;
  --r: 14px;
  --r-sm: 10px;
  --shadow: 0 6px 20px rgba(0, 0, 0, .35);
  --tap: 44px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; padding: 0; background: var(--bg); color: var(--text); }
/* прокрутка к элементу не прячет его под закреплённой шапкой и нижним меню */
html { scroll-padding-top: 140px; scroll-padding-bottom: 90px; }
body {
  font: 15px/1.4 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  min-height: 100vh; overflow-x: hidden;
}
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--gold); }
img { max-width: 100%; }
code { background: #00000040; padding: 1px 5px; border-radius: 5px; font-size: .92em; }

#app { max-width: 640px; margin: 0 auto; padding: 0 12px calc(84px + var(--safe-b)); }

/* ---------------------------------------------------------------- шапка */
.top {
  position: sticky; top: 0; z-index: 20; margin: 0 -12px; padding: 10px 12px 8px;
  background: linear-gradient(180deg, #1e1812 70%, #1e1812ee);
  border-bottom: 1px solid var(--line);
}
.top-row { display: flex; align-items: center; gap: 10px; }
.ava { width: 42px; height: 42px; border-radius: 50%; object-fit: cover; flex: none;
  border: 2px solid var(--gold2); background: var(--card2); }
.who { min-width: 0; flex: 1; }
.who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.who small { color: var(--muted); }
.bar { height: 6px; border-radius: 4px; background: #00000055; overflow: hidden; margin-top: 4px; }
.bar > i { display: block; height: 100%; background: linear-gradient(90deg, var(--gold2), var(--gold)); }
.bar.life > i { background: linear-gradient(90deg, #a83b30, var(--red)); }
.bar.en > i { background: linear-gradient(90deg, #3a7fb0, var(--blue)); }
.curs { display: flex; flex-wrap: wrap; gap: 6px; margin-top: 8px; }
.cur { display: inline-flex; align-items: center; gap: 4px; padding: 3px 8px 3px 4px;
  border-radius: 20px; background: var(--card); border: 1px solid var(--line);
  font-size: 13px; font-weight: 600; white-space: nowrap; }
.cur img { width: 18px; height: 18px; object-fit: contain; }
.vitals { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; margin-top: 6px; font-size: 12px; color: var(--muted); }
.vitals [data-until] { white-space: nowrap; }
/* выпадающий список настройки не растягивает экран на 320 px */
.opts .o > span { flex: 1; min-width: 0; }
.opts .o select { max-width: 58%; text-overflow: ellipsis; }

/* ----------------------------------------------------------- навигация */
.nav {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; justify-content: center; gap: 2px;
  padding: 6px 6px calc(6px + var(--safe-b)); background: #1a140fee;
  border-top: 1px solid var(--line); backdrop-filter: blur(8px);
}
.nav button { flex: 1; max-width: 128px; min-height: 52px; border: 0; background: none;
  color: var(--muted); display: flex; flex-direction: column; align-items: center;
  justify-content: center; gap: 2px; font-size: 11px; border-radius: 10px; cursor: pointer; }
.nav button .ic { width: 28px; height: 28px; object-fit: contain; }
.nav button:not(.on) .ic { filter: saturate(.55) brightness(.85); }
.nav button.on { color: var(--gold); background: #ffffff0a; }

/* -------------------------------------------------------------- блоки */
h1 { font-size: 20px; margin: 16px 0 10px; }
h2 { font-size: 17px; margin: 18px 0 8px; }
h3 { font-size: 15px; margin: 12px 0 6px; }
.muted { color: var(--muted); }
.faint { color: var(--faint); }
.ok { color: var(--green); }
.bad { color: var(--red); }
.gold { color: var(--gold); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 8px; }
.row.wrap { flex-wrap: wrap; }
.row.between { justify-content: space-between; }
.grow { flex: 1; min-width: 0; }
.stack > * + * { margin-top: 8px; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.grid3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
@media (max-width: 360px) { .grid3 { grid-template-columns: 1fr 1fr; } }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--r);
  padding: 12px; margin: 10px 0; }
.card.tight { padding: 10px; }
.card.hl { border-color: var(--gold2); box-shadow: 0 0 0 1px #c8923a33 inset; }
.card h3:first-child, .card h2:first-child { margin-top: 0; }
.kv { display: flex; justify-content: space-between; gap: 10px; padding: 5px 0;
  border-bottom: 1px dashed #ffffff12; }
.kv:last-child { border-bottom: 0; }
.kv > span:first-child { color: var(--muted); }
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 20px;
  font-size: 12px; background: #ffffff10; color: var(--muted); white-space: nowrap; }
.pill.ok { background: #79c26b22; color: var(--green); }
.pill.bad { background: #e0685a22; color: var(--red); }
.pill.gold { background: #e3b45a22; color: var(--gold); }
.pill.blue { background: #6fb0e022; color: var(--blue); }
.ico { width: 20px; height: 20px; object-fit: contain; vertical-align: -4px; }
.ico.sm { width: 14px; height: 14px; vertical-align: -2px; }
.ico.lg { width: 36px; height: 36px; }
.ico.xl { width: 64px; height: 64px; }
.thumb { width: 56px; height: 56px; object-fit: contain; border-radius: 10px; background: #00000030; flex: none; }

/* ------------------------------------------------------------- кнопки */
.btn { min-height: var(--tap); padding: 0 16px; border-radius: var(--r-sm); border: 1px solid var(--line);
  background: var(--card2); color: var(--text); font-weight: 600; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center; gap: 6px; text-align: center; }
.btn:active { transform: translateY(1px); }
.btn.main { background: linear-gradient(180deg, var(--gold), var(--gold2)); color: #2a1c0c; border-color: #00000030; }
.btn.danger { background: #5a2420; border-color: #7c332c; }
.btn.ghost { background: transparent; }
.btn.sm { min-height: 34px; padding: 0 12px; font-size: 13px; }
.btn.block { display: flex; width: 100%; }
/* выключенная кнопка: серый фон и текст, но иконки валют остаются своего цвета */
.btn[disabled] { opacity: .55; background: var(--card2); color: var(--muted); border-color: var(--line); pointer-events: none; }
.btn.busy { opacity: .6; pointer-events: none; }
.btn .ico { width: 18px; height: 18px; }

/* --------------------------------------------------------- переключатель */
.sw { position: relative; width: 56px; height: 34px; flex: none; }
.sw input { opacity: 0; width: 0; height: 0; }
.sw i { position: absolute; inset: 0; background: #ffffff1a; border-radius: 20px; transition: .2s; cursor: pointer; }
.sw i::after { content: ""; position: absolute; left: 4px; top: 4px; width: 26px; height: 26px;
  border-radius: 50%; background: #d9cbb5; transition: .2s; }
.sw input:checked + i { background: var(--green); }
.sw input:checked + i::after { transform: translateX(22px); background: #fff; }

input[type=text], input[type=number], textarea, select {
  width: 100%; min-height: var(--tap); padding: 10px 12px; border-radius: var(--r-sm);
  border: 1px solid var(--line); background: #00000035; outline: none; }
textarea { min-height: 96px; resize: vertical; word-break: break-all; }
input:focus, textarea:focus, select:focus { border-color: var(--gold2); }
label.f { display: block; margin: 8px 0 4px; color: var(--muted); font-size: 13px; }

/* ------------------------------------------------------- боковое меню */
.drawer { position: fixed; inset: 0; z-index: 40; pointer-events: none; }
.drawer .dr-bg { position: absolute; inset: 0; background: #000000a0; opacity: 0; transition: opacity .2s; }
.drawer .dr-panel { position: absolute; top: 0; bottom: 0; left: 0; width: min(84vw, 330px); background: var(--bg2);
  border-right: 1px solid var(--line); transform: translateX(-102%); transition: transform .22s ease-out;
  display: flex; flex-direction: column; overflow-y: auto; padding-bottom: calc(80px + var(--safe-b)); }
.drawer.open { pointer-events: auto; }
.drawer.open .dr-bg { opacity: 1; }
.drawer.open .dr-panel { transform: none; box-shadow: var(--shadow); }
body.noscroll { overflow: hidden; }
.dr-head { display: flex; align-items: center; gap: 10px; padding: 14px 12px 10px; border-bottom: 1px solid var(--line); }
.dr-head .who { flex: 1; min-width: 0; }
.dr-head .who b { display: block; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.dr-head .who small { color: var(--muted); }
.dr-x { width: 40px; height: 40px; flex: none; border: 0; background: none; padding: 4px; cursor: pointer; }
.dr-x img { width: 100%; height: 100%; object-fit: contain; }
.dr-list { padding: 6px 8px; }
.dr-sep { margin: 14px 8px 4px; font-size: 12px; color: var(--faint); text-transform: uppercase; letter-spacing: .06em; }
.dr-it, .dr-gh { width: 100%; min-height: 44px; display: flex; align-items: center; gap: 10px; padding: 6px 10px;
  border: 0; border-radius: 10px; background: none; color: var(--text); text-align: left; cursor: pointer; font-size: 15px; }
.dr-it img, .dr-gh img { width: 28px; height: 28px; object-fit: contain; flex: none; }
.dr-it.on { background: linear-gradient(180deg, var(--gold), var(--gold2)); color: #2a1c0c; font-weight: 600; }
.dr-it.on .faint { color: #4a3417; }
.dr-it small { font-size: 11px; white-space: nowrap; }
.dr-gh { font-weight: 600; }
.dr-chev { color: var(--muted); font-size: 20px; line-height: 1; transition: transform .2s; }
.dr-g.open .dr-chev { transform: rotate(90deg); }
.dr-items { display: none; margin: 2px 0 6px 22px; padding-left: 8px; border-left: 1px solid var(--line); }
.dr-g.open .dr-items { display: block; }
.dr-items .dr-it { min-height: 40px; font-size: 14px; }
.dr-items .dr-it img { width: 24px; height: 24px; }
.dr-it .dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green); flex: none; }

/* ------------------------------------------------------------- задачи */
.task { display: flex; gap: 10px; align-items: flex-start; }
.task .ti { flex: 1; min-width: 0; }
.task .ti b { display: block; }
.task .st { font-size: 13px; margin-top: 3px; }
.opts { margin-top: 8px; padding-top: 8px; border-top: 1px dashed #ffffff14; }
.opts .o { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 6px 0; }
.opts .o input[type=number] { width: 96px; min-height: 36px; padding: 6px 8px; }
.opts .o select { width: auto; min-height: 36px; padding: 6px 8px; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { min-height: 34px; display: inline-flex; align-items: center; padding: 6px 12px; border-radius: 20px; border: 1px solid var(--line); background: #00000025;
  font-size: 13px; cursor: pointer; user-select: none; }
.chip.on { background: #e3b45a26; border-color: var(--gold2); color: var(--gold); }

/* ------------------------------------------------------------- список */
.list > .it { display: flex; align-items: center; gap: 10px; padding: 9px 0; border-bottom: 1px solid #ffffff0d; }
.list > .it:last-child { border-bottom: 0; }
.it .grow small { display: block; color: var(--muted); }
.log .it { align-items: flex-start; font-size: 13px; }
.log time { color: var(--faint); font-size: 12px; white-space: nowrap; min-width: 44px; }

.tabs { display: flex; gap: 6px; overflow-x: auto; padding: 2px 0 6px; scrollbar-width: none; }
.tabs::-webkit-scrollbar { display: none; }
.tabs button { flex: none; min-height: 36px; padding: 0 14px; border-radius: 20px; border: 1px solid var(--line);
  background: var(--card); color: var(--muted); cursor: pointer; }
.tabs button.on { color: #2a1c0c; background: var(--gold); border-color: var(--gold); font-weight: 600; }

/* ----------------------------------------------------- переключатель вкладок */
.seg { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; padding: 4px; margin: 10px 0;
  background: var(--card); border: 1px solid var(--line); border-radius: var(--r); }
.seg button { min-height: 52px; border: 0; border-radius: 10px; background: transparent; color: var(--muted);
  cursor: pointer; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 1px; }
.seg button small { font-size: 11px; color: var(--faint); }
.seg button.on { background: linear-gradient(180deg, var(--gold), var(--gold2)); color: #2a1c0c; }
.seg button.on small { color: #4a3417; }

/* ------------------------------------------------------- тосты, модалки */
#toast { position: fixed; left: 50%; bottom: calc(84px + var(--safe-b)); transform: translateX(-50%);
  z-index: 60; display: flex; flex-direction: column; gap: 6px; width: min(92vw, 520px); pointer-events: none; }
#toast > div { background: #2b2219f2; border: 1px solid var(--line); border-radius: 12px; padding: 10px 14px;
  box-shadow: var(--shadow); animation: tin .2s ease-out; }
#toast > div.ok { border-color: #79c26b88; }
#toast > div.bad { border-color: #e0685a99; }
@keyframes tin { from { opacity: 0; transform: translateY(8px); } }
.modal-bg { position: fixed; inset: 0; z-index: 50; background: #000000a0; display: flex; align-items: flex-end;
  justify-content: center; }
.modal { width: min(100%, 640px); max-height: 88vh; overflow: auto; background: var(--bg2);
  border-radius: 18px 18px 0 0; border: 1px solid var(--line); padding: 16px 16px calc(16px + var(--safe-b)); }
@media (min-width: 700px) { .modal-bg { align-items: center; } .modal { border-radius: 18px; } }
.modal h2 { margin-top: 0; }
.modal ol { padding-left: 20px; } .modal li { margin: 6px 0; }

.empty { text-align: center; color: var(--muted); padding: 28px 10px; }
.spin { width: 28px; height: 28px; border-radius: 50%; border: 3px solid #ffffff20; border-top-color: var(--gold);
  animation: sp 0.8s linear infinite; margin: 30px auto; }
@keyframes sp { to { transform: rotate(360deg); } }
.err { background: #e0685a1a; border: 1px solid #e0685a55; color: #f3b0a8; border-radius: var(--r-sm); padding: 10px 12px; margin: 10px 0; }
.note { background: #e3b45a14; border: 1px solid #e3b45a40; border-radius: var(--r-sm); padding: 10px 12px; margin: 10px 0; }
.hero { border-radius: var(--r); overflow: hidden; position: relative; margin: 10px 0; }
/* свиток игры (ui/tavern-top.png и подобные) рамкой: завитки по краям картинки
   целиком, тянется только середина - на узком экране ничего не режется */
.scroll-bar { border: solid transparent; border-width: 0 26px; border-image-slice: 0 50 0 50 fill;
  border-image-width: 0 26px; border-image-repeat: stretch; min-height: 58px; margin: 10px 0;
  display: flex; align-items: center; justify-content: space-around; flex-wrap: wrap; gap: 4px 10px;
  padding: 8px 2px; color: var(--ink); font-weight: 600; font-size: 14px; }
.scroll-bar > span { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; }
.hero img { display: block; width: 100%; max-height: 160px; object-fit: cover; }
.hero .cap { position: absolute; left: 0; right: 0; bottom: 0; padding: 18px 12px 10px;
  background: linear-gradient(0deg, #000000c0, transparent); font-weight: 700; font-size: 17px; }
.back { display: inline-flex; align-items: center; gap: 4px; margin: 8px 0 0; min-height: 36px; color: var(--muted);
  background: none; border: 0; padding: 4px 8px 4px 0; cursor: pointer; }
.money { display: inline-flex; align-items: center; gap: 3px; vertical-align: -5px; }
.task .desc { font-size: 12px; color: var(--faint); margin-top: 2px; }
#sec.loading { min-height: 260px; }
table.t { width: 100%; border-collapse: collapse; font-size: 13px; }
table.t td, table.t th { padding: 6px 4px; border-bottom: 1px solid #ffffff0f; text-align: left; }
table.t th { color: var(--muted); font-weight: 500; }
.num { font-variant-numeric: tabular-nums; }
