/* Тёмный пиксель-арт: палитра из js/palette.js, пиксельные рамки «железо + тёмное дерево». */
:root {
  --void: #07060a; --n0: #0e0c12; --n1: #16131b; --n2: #211c27; --n3: #2f2836; --n4: #433a4a;
  --mist: #33445f; --mist3: #55698a;
  --stone: #6a635a; --stone3: #938a7c;
  --wood: #3a2819; --wood2: #5a3e26; --wood3: #7f5a36;
  --f1: #6b1810; --f2: #a12c14; --f3: #d4511a; --f4: #f08a2a; --f5: #f9c459; --f6: #fff2c6;
  --soul: #a3d6ff; --soul0: #5e8fb8; --blood: #c23b3b;
  --ink: #efe3c8; --ink2: #bfae8c; --ink3: #7d705a;
  --top: 46px; --panel-w: 380px;
  --px: 2px;
  font-family: "Pixelify Sans", "Courier New", monospace;
  font-size: 15px;
  color: var(--ink);
  background: var(--void);
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; overflow: hidden; overscroll-behavior: none; }
body { -webkit-font-smoothing: none; -webkit-tap-highlight-color: transparent; user-select: none; }
img { image-rendering: pixelated; }
h1, h2, h3 { font-weight: 600; margin: 0 0 6px; color: var(--f5); letter-spacing: .5px; }
h1 { font-size: 26px; } h2 { font-size: 19px; } h3 { font-size: 15px; color: var(--ink2); margin-top: 14px; }
.sub { color: var(--ink3); font-size: 13px; }
.bad { color: var(--blood); }
.hint { color: var(--ink3); font-style: italic; margin: 8px 0; }
.empty { color: var(--ink3); padding: 20px 4px; text-align: center; }
[hidden] { display: none !important; }

/* пиксельная рамка: «зубчатые» углы через box-shadow */
.frame {
  background: var(--n1);
  box-shadow:
    0 calc(-1 * var(--px)) 0 0 var(--wood2), 0 var(--px) 0 0 var(--wood),
    calc(-1 * var(--px)) 0 0 0 var(--wood2), var(--px) 0 0 0 var(--wood),
    0 0 0 calc(2 * var(--px)) var(--void);
}

button, input, select {
  font: inherit; color: var(--ink); border: 0; border-radius: 0;
}
button {
  background: var(--wood2); padding: 6px 12px; cursor: pointer; margin: 4px 4px 0 0;
  box-shadow: inset calc(-1 * var(--px)) calc(-1 * var(--px)) 0 0 var(--wood), inset var(--px) var(--px) 0 0 var(--wood3), 0 0 0 var(--px) var(--void);
}
button:hover:not(:disabled) { background: var(--wood3); color: var(--f6); }
button:active:not(:disabled) { transform: translateY(1px); box-shadow: inset var(--px) var(--px) 0 0 var(--wood), 0 0 0 var(--px) var(--void); }
button:disabled { opacity: .45; cursor: default; }
button.ghost { background: var(--n2); box-shadow: inset 0 0 0 var(--px) var(--n3), 0 0 0 var(--px) var(--void); }
input, select { background: var(--n0); padding: 5px 6px; box-shadow: inset 0 0 0 var(--px) var(--n3); }
input[type=number] { width: 52px; }
input[type=checkbox], input[type=radio], input[type=range] { accent-color: var(--f3); box-shadow: none; }
input:focus, select:focus { outline: none; box-shadow: inset 0 0 0 var(--px) var(--f3); }

.ri { width: 18px; height: 18px; vertical-align: -4px; margin-right: 2px; }
.row { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; }
.row.end { justify-content: flex-end; margin-top: 12px; }
.grow { flex: 1; min-width: 0; }
.line { display: block; margin: 6px 0; }

/* ───────── вход ───────── */
#login { position: fixed; inset: 0; display: grid; place-items: center; background: radial-gradient(circle at 50% 60%, #2a120a 0, var(--void) 55%); }
#login-form { display: grid; gap: 10px; padding: 28px; width: min(340px, 90vw); text-align: center; }
#login-form input { width: 100%; padding: 9px; }

/* ───────── верхняя панель ───────── */
#topbar {
  position: fixed; top: 0; left: 0; right: 0; height: var(--top); z-index: 5;
  display: flex; align-items: center; gap: 10px; padding: 0 10px; padding-top: env(safe-area-inset-top);
  background: var(--n0); box-shadow: 0 var(--px) 0 0 var(--wood), 0 calc(2 * var(--px)) 0 0 var(--void);
  white-space: nowrap; overflow-x: auto; scrollbar-width: none;
}
#topbar::-webkit-scrollbar { display: none; }
.flame { display: flex; align-items: center; gap: 6px; margin: 0; padding: 4px 10px; background: var(--f1); }
.flame b { color: var(--f5); font-size: 17px; }
.flame .fuel { font-size: 12px; color: var(--ink2); }
.flame.smolder { background: var(--n3); animation: dim 2s steps(2) infinite; }
@keyframes dim { 50% { opacity: .6; } }
.resources { display: flex; gap: 12px; }
.res { display: flex; align-items: center; gap: 2px; font-size: 15px; }
.res.full span { color: var(--f4); }
.wave { margin-left: auto; font-size: 13px; color: var(--ink2); }
.wave.warned { color: var(--soul); animation: dim 1s steps(2) infinite; }

/* ───────── карта ───────── */
#map { position: fixed; top: var(--top); left: 0; right: var(--panel-w); bottom: 0; width: calc(100% - var(--panel-w)); height: calc(100% - var(--top));
  touch-action: none; image-rendering: pixelated; cursor: grab; display: block; }
#map:active { cursor: grabbing; }

/* ───────── панель ───────── */
#panel { position: fixed; top: calc(var(--top) + 8px); right: 8px; bottom: 8px; width: calc(var(--panel-w) - 16px); z-index: 4;
  display: flex; flex-direction: column; }
#handle { display: none; }
#tabs { display: flex; flex-wrap: nowrap; background: var(--n0); padding: 4px; gap: 2px; }
#tabs button { flex: 1 1 auto; min-width: 0; margin: 0; padding: 6px 4px; font-size: 13px; background: var(--n2); box-shadow: none; position: relative; }
#tabs button.on { background: var(--wood2); color: var(--f5); }
.badge { position: absolute; top: -4px; right: -4px; background: var(--f3); color: var(--void); font-style: normal; font-size: 11px; padding: 0 4px; }
#panel-body { flex: 1; overflow-y: auto; padding: 12px; user-select: text; }

.card { background: var(--n2); padding: 9px 10px; margin: 8px 0; display: block;
  box-shadow: inset var(--px) var(--px) 0 0 var(--n3), inset calc(-1 * var(--px)) calc(-1 * var(--px)) 0 0 var(--n0); }
.card.opt, .card.bld, .card.hero { display: flex; gap: 10px; align-items: flex-start; }
.card.opt { align-items: center; }
.card.soul { border-left: 3px solid var(--soul0); }
.card.boss { border-left: 3px solid var(--blood); }
.card.hero.hollow { opacity: .75; }
.card.exp.waiting { border-left: 3px solid var(--f4); }
.card.exp.failed { opacity: .6; }
.bi { width: 64px; height: 64px; flex: none; }
.portrait { width: 64px; height: 64px; flex: none; box-shadow: 0 0 0 var(--px) var(--void); }
.costs { margin-top: 3px; }
.cost { margin-right: 8px; white-space: nowrap; }
.cost.lack { color: var(--blood); }
.stats { font-size: 13px; color: var(--ink2); margin: 3px 0; }
.slots { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; margin: 4px 0; }
.slot { font-size: 12px; color: var(--ink3); display: grid; gap: 2px; }
.slot select { font-size: 12px; padding: 3px; width: 100%; }
.bar { height: 6px; background: var(--n0); margin: 4px 0; }
.bar i { display: block; height: 100%; background: var(--blood); }
.bar.hp i { background: var(--f2); }
.log { font-size: 12px; color: var(--ink3); margin-top: 4px; }
.chron { padding: 6px 0; border-bottom: 1px dashed var(--n3); font-size: 14px; }
.chron .t { color: var(--ink3); font-size: 12px; margin-right: 6px; }
.chron.lore i { color: var(--ink2); }
.chron.k-wave_result b, .chron.k-flame_out b { color: var(--blood); }
.choice p { margin: 6px 0; font-size: 16px; color: var(--ink); }
.pick { display: flex; align-items: center; gap: 6px; margin: 4px 0; cursor: pointer; }
.pick img { width: 40px; height: 40px; }

/* ───────── развилка поверх карты ───────── */
#choice-banner { position: fixed; top: calc(var(--top) + 14px); left: 14px; width: min(460px, calc(100% - var(--panel-w) - 40px)); padding: 10px 12px; z-index: 6; }

/* ───────── окно похода ───────── */
#modal { position: fixed; inset: 0; z-index: 20; background: rgba(7, 6, 10, .78); display: grid; place-items: center; }
.modal-box { width: min(420px, 94vw); max-height: 86vh; overflow-y: auto; padding: 16px; background: var(--n1);
  box-shadow: 0 0 0 var(--px) var(--wood2), 0 0 0 calc(2 * var(--px)) var(--void); }

/* ───────── тосты и всплывающие числа ───────── */
#toasts { position: fixed; left: 14px; bottom: 14px; z-index: 30; display: grid; gap: 6px; width: min(420px, calc(100% - var(--panel-w) - 40px)); pointer-events: none; }
.toast { background: var(--n1); padding: 8px 11px; font-size: 14px; box-shadow: 0 0 0 var(--px) var(--wood2), 0 0 0 calc(2 * var(--px)) var(--void);
  animation: in .25s steps(3); transition: opacity .8s steps(4); }
.toast.lore { font-style: italic; color: var(--ink2); box-shadow: 0 0 0 var(--px) var(--n3), 0 0 0 calc(2 * var(--px)) var(--void); }
.toast.err { box-shadow: 0 0 0 var(--px) var(--blood), 0 0 0 calc(2 * var(--px)) var(--void); }
.toast.out { opacity: 0; }
@keyframes in { from { transform: translateY(8px); opacity: 0; } }
.floater { position: fixed; z-index: 40; pointer-events: none; font-weight: 600; font-size: 14px; transform: translateX(-50%);
  animation: float 1.4s steps(7) forwards; text-shadow: 2px 2px 0 var(--void); }
.floater.up { color: var(--f5); } .floater.down { color: var(--blood); }
@keyframes float { to { transform: translate(-50%, -26px); opacity: 0; } }
body.busy { cursor: progress; }

/* ───────── телефон: карта на весь экран + выдвижная панель снизу ───────── */
@media (max-width: 899px) {
  :root { --panel-w: 0px; font-size: 14px; }
  .resources { gap: 8px; } .res { font-size: 13px; } .ri { width: 14px; height: 14px; vertical-align: -2px; }
  .wave { display: none; } .wave.warned { display: block; }
  #map { width: 100%; right: 0; bottom: 0; }
  #panel { left: 0; right: 0; top: auto; bottom: 0; width: auto; height: calc(58px + env(safe-area-inset-bottom));
    padding-bottom: env(safe-area-inset-bottom); transition: height .2s steps(4); }
  body.sheet-open #panel { height: 62vh; }
  #handle { display: block; height: 14px; margin: 0; padding: 0; background: var(--n1); box-shadow: none; position: relative; }
  #handle::after { content: ""; position: absolute; left: 50%; top: 5px; width: 40px; height: 4px; margin-left: -20px; background: var(--n4); }
  #tabs { justify-content: space-between; flex-wrap: nowrap; }
  #tabs button { flex: 1; padding: 8px 4px; }
  #panel-body { display: none; }
  body.sheet-open #panel-body { display: block; }
  #choice-banner { left: 8px; right: 8px; width: auto; }
  #toasts { left: 8px; right: 8px; width: auto; bottom: calc(72px + env(safe-area-inset-bottom)); }
  body.sheet-open #choice-banner { display: none; }
}
