@font-face { font-family: 'PT Serif'; src: url('../fonts/PTSerif-Regular.ttf') format('truetype'); font-weight: normal; font-display: swap; }
@font-face { font-family: 'PT Serif'; src: url('../fonts/PTSerif-Bold.ttf') format('truetype'); font-weight: bold; font-display: swap; }
@font-face { font-family: 'Kurale'; src: url('../fonts/Kurale-Regular.ttf') format('truetype'); font-display: swap; }
@font-face { font-family: 'Ruslan Display'; src: url('../fonts/RuslanDisplay-Regular.ttf') format('truetype'); font-display: swap; }

:root {
  --bg0: #0e0a07;
  --bg1: #1a130d;
  --bg2: #251b12;
  --bg3: #33261a;
  --line: #5a4128;
  --line-hi: #8a6a42;
  --gold: #e4b434;
  --gold-hi: #f6d458;
  --text: #e8dcc0;
  --text-dim: #a8957a;
  --red: #e0583a;
  --green: #8eab4c;
  --purple: #9c7ae6;
  --wood-tex: none;
  --plank-tex: none;
  /* скобы по углам досок */
  --staples:
    radial-gradient(circle, #e4dcc8 0 1px, #14100b 1.5px 2.6px, transparent 3px) left 1px top 1px / 7px 7px no-repeat,
    radial-gradient(circle, #e4dcc8 0 1px, #14100b 1.5px 2.6px, transparent 3px) right 1px top 1px / 7px 7px no-repeat,
    radial-gradient(circle, #e4dcc8 0 1px, #14100b 1.5px 2.6px, transparent 3px) left 1px bottom 1px / 7px 7px no-repeat,
    radial-gradient(circle, #e4dcc8 0 1px, #14100b 1.5px 2.6px, transparent 3px) right 1px bottom 1px / 7px 7px no-repeat;
  --planks: var(--staples), var(--plank-tex), #2a1e14;
  --parch-tex: none;
}

* { box-sizing: border-box; }

html, body {
  margin: 0; height: 100%;
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent; -webkit-touch-callout: none; -webkit-text-size-adjust: 100%;
  background: var(--bg0);
  color: var(--text);
  font-family: 'PT Serif', 'Kurale', 'Palatino Linotype', Palatino, Georgia, serif;
  font-size: 14px;
  user-select: none;
  overflow: hidden;
}

img { image-rendering: pixelated; }
kbd {
  font-family: 'PT Serif', Georgia, serif; font-size: 11px;
  background: var(--bg0); border: 1px solid var(--line); border-bottom-width: 2px;
  padding: 0 4px; color: var(--gold);
}
.small { font-size: 12px; }
.muted { color: var(--text-dim); }
.warn { color: var(--red); font-weight: bold; }
.good { color: var(--green); }
.hidden { display: none !important; }

#app { display: flex; height: 100%; }

/* ---------- Пиксельная рамка ---------- */

.pframe {
  background: var(--bg1);
  border: 2px solid #0a0705;
  box-shadow: inset 0 0 0 1px var(--line), inset 0 0 0 2px #0a0705, inset 0 2px 0 2px rgba(255,220,160,0.06);
}

/* ---------- Левая колонка ---------- */

#panel {
  width: 316px; flex: none;
  display: flex; flex-direction: column;
  background:
    linear-gradient(90deg, rgba(0,0,0,0.4), rgba(0,0,0,0) 8%, rgba(0,0,0,0) 92%, rgba(0,0,0,0.45)),
    var(--plank-tex), #5a3e22;
  image-rendering: pixelated;
  border-right: 3px solid #0a0705;
  box-shadow: 3px 0 10px rgba(0,0,0,0.7), inset -1px 0 0 var(--line);
  padding: 8px 10px 10px;
  gap: 7px;
  position: relative;
  z-index: 2;
  min-height: 0;
}
#panel > * { flex-shrink: 0; }

#logo {
  text-align: center; font-size: 26px; letter-spacing: 4px; font-weight: bold;
  background: linear-gradient(#fff2a0, #e4b434 55%, #8e5a18);
  -webkit-background-clip: text; background-clip: text;
  -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 0 1px #000) drop-shadow(0 0 2px #000) drop-shadow(0 2px 0 #000);
  line-height: 1.1;
}

.mm-wrap {
  padding: 4px;
  background: linear-gradient(#5a4128, #2a1e14);
  border: 2px solid #0a0705;
  box-shadow: inset 0 0 0 1px #a07a48, 0 3px 6px rgba(0,0,0,0.6);
}
#minimap { width: 100%; height: auto; aspect-ratio: 4 / 3; display: block; cursor: pointer; image-rendering: pixelated; border: 1px solid #0a0705; }

/* ---------- Кнопки ---------- */

button {
  font-family: inherit; font-size: 13px;
  color: var(--text);
  background: linear-gradient(#5a4128, #3a2a1a);
  border: 2px solid #0a0705;
  border-radius: 0;
  box-shadow: inset 0 1px 0 rgba(255,220,160,0.22), inset 0 -2px 0 rgba(0,0,0,0.4), inset 0 0 0 1px #6a4e30;
  padding: 4px 8px;
  cursor: pointer;
  text-shadow: 0 1px 0 #000;
  display: inline-flex; align-items: center; justify-content: center; gap: 5px;
}
button:hover { background: linear-gradient(#5e4530, #3e2d1f); color: #fff6dc; }
button:active { box-shadow: inset 0 2px 0 rgba(0,0,0,0.5), inset 0 0 0 1px #6a4e30; }
button.active {
  background: linear-gradient(#7a5a2c, #4e3816);
  box-shadow: inset 0 0 0 1px var(--gold), inset 0 1px 0 rgba(255,240,180,0.4);
  color: #fff6dc;
}
button:disabled { opacity: 0.4; cursor: default; }
button img { width: 18px; height: 18px; }

/* ---------- Вкладки-иконки ---------- */

#tabs { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; }
.tab-btn { height: 44px; padding: 0; position: relative; }
.tab-btn img { width: 36px; height: 36px; }
.badge {
  position: absolute; top: -4px; right: -4px;
  min-width: 18px; height: 18px; padding: 0 4px;
  background: var(--red); color: #fff; font-size: 11px; font-weight: bold;
  border: 2px solid #0a0705; display: flex; align-items: center; justify-content: center;
}

#tab-area {
  flex: 1 1 auto; min-height: 120px;
  overflow-y: auto; overflow-x: hidden;
  padding: 6px;
  scrollbar-width: thin; scrollbar-color: #6a4e30 #120c08;
}
#tab-area { background: rgba(10,7,5,0.62); border: 2px solid #0a0705; box-shadow: inset 0 0 0 1px var(--line); }
.tab { display: none; }
.tab.active { display: block; }

.tools { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; margin-bottom: 6px; }   /* два ряда по две кнопки: дорога, снос / пшеница, хмель */
.tools button { font-size: 12px; padding: 4px 3px; }

#build-cats { display: flex; gap: 2px; margin-bottom: 6px; }
#build-cats button { flex: 1; font-size: 11.5px; padding: 3px 2px; }
#build-cats button kbd { display: none; }

#build-list { display: grid; grid-template-columns: repeat(3, 1fr); gap: 4px; }
.bbtn {
  display: flex; flex-direction: column; align-items: center; gap: 1px;
  padding: 3px 2px 4px; font-size: 11px; line-height: 1.1;
  min-height: 92px; text-align: center;
}
.bbtn .bimg { width: 72px; height: 54px; object-fit: contain; image-rendering: auto; filter: drop-shadow(0 2px 0 rgba(0,0,0,0.6)); }
.bbtn .bname { min-height: 24px; display: flex; align-items: center; }
.cost { display: flex; gap: 4px; justify-content: center; font-size: 11px; color: #e0cc98; }
.cost span { display: inline-flex; align-items: center; gap: 1px; }
.cost img { width: 18px; height: 18px; }

/* ---------- Слоты товаров ---------- */

.group-title {
  font-size: 12px; color: var(--gold); letter-spacing: 1px; text-transform: uppercase;
  margin: 6px 0 3px; border-bottom: 1px solid var(--line); padding-bottom: 1px;
}
.slots { display: grid; grid-template-columns: repeat(auto-fill, minmax(44px, 1fr)); gap: 3px; }
.slot {
  position: relative; height: 44px;
  background: #120c08; border: 2px solid #0a0705; box-shadow: inset 0 0 0 1px #4a3524;
  display: flex; align-items: center; justify-content: center; cursor: default;
}
.slot img { width: 36px; height: 36px; }
.slot .n {
  position: absolute; right: 2px; bottom: 0; font-size: 12px; font-weight: bold;
  color: #fff; text-shadow: 1px 1px 0 #000, -1px 0 0 #000;
  font-family: 'PT Serif', Georgia, serif;
}
.slot.zero img { opacity: 0.35; }
.slot.blocked::after {
  content: ''; position: absolute; inset: 4px;
  background: linear-gradient(45deg, transparent 45%, var(--red) 45%, var(--red) 55%, transparent 55%);
}
.slot.click { cursor: pointer; }
.slot.click:hover { box-shadow: inset 0 0 0 1px var(--gold); }

/* ---------- Жители ---------- */

.prow {
  display: grid; grid-template-columns: 40px 1fr auto auto; gap: 6px; align-items: center;
  padding: 3px; border-bottom: 1px solid rgba(90,65,40,0.5);
}
.portrait {
  width: 40px; height: 40px; background: #120c08; border: 2px solid #0a0705;
  box-shadow: inset 0 0 0 1px #4a3524; image-rendering: pixelated;
}
.prow .pn { font-size: 13px; }
.prow .pc { font-family: 'PT Serif', Georgia, serif; font-size: 13px; color: var(--gold); text-align: right; }
.prow button { padding: 1px 7px; }

/* ---------- Хозяйство ---------- */

.alert {
  display: flex; gap: 6px; align-items: center; padding: 4px; cursor: pointer;
  border-bottom: 1px solid rgba(90,65,40,0.5); font-size: 13px;
}
.alert:hover { background: rgba(228,180,52,0.08); }
.alert img { width: 24px; height: 24px; flex: none; }
.stat-row { display: flex; align-items: center; gap: 6px; font-size: 12.5px; padding: 1px 0; }
.stat-row img { width: 20px; height: 20px; }
.stat-row .v { margin-left: auto; font-family: 'PT Serif', Georgia, serif; color: var(--gold); }

.menu-list { display: grid; gap: 4px; }
.menu-list button { justify-content: flex-start; padding: 6px 8px; font-size: 14px; }
.menu-list button kbd { margin-left: auto; }
.hotkeys { margin-top: 10px; font-size: 12px; color: var(--text-dim); display: grid; gap: 3px; }

/* ---------- Нижнее окно здания ---------- */

#info-wrap {
  flex: 0 0 auto;
  height: clamp(220px, 40vh, 360px);
  display: flex; flex-direction: column;
  background: linear-gradient(rgba(0,0,0,0.35), rgba(0,0,0,0.55)), var(--plank-tex), #3a2a1a;
  border: 2px solid #0a0705;
  box-shadow: inset 0 0 0 1px var(--line-hi), inset 0 0 0 3px #0a0705, inset 0 0 18px rgba(0,0,0,0.6), 0 -2px 8px rgba(0,0,0,0.5);
  min-height: 0;
}
#info-bar {
  flex: none; display: flex; align-items: center; gap: 6px;
  padding: 3px 4px 2px 9px; font-size: 11.5px; letter-spacing: 1px; text-transform: uppercase;
  color: var(--text-dim); border-bottom: 1px solid rgba(90,65,40,0.6);
}
#info-bar span { flex: 1; }
#info-bar button { padding: 0 6px; font-size: 13px; line-height: 18px; }
#info {
  flex: 1 1 auto; min-height: 0;
  overflow-y: auto;
  padding: 6px 9px 8px;
  scrollbar-width: thin; scrollbar-color: #6a4e30 #120c08;
}

/* разделитель между вкладками и окном здания */
#split {
  flex: none; height: 7px; margin: -3px 0; cursor: ns-resize; position: relative; z-index: 1;
}
#split::after {
  content: ''; position: absolute; left: 40%; right: 40%; top: 2px; height: 3px;
  background: #6a4e30; box-shadow: 0 1px 0 #0a0705;
}
#split:hover::after, #split.drag::after { background: var(--gold); }

/* ширина колонки — за правый край */
#panel-resize {
  position: absolute; top: 0; bottom: 0; right: -6px; width: 9px; cursor: ew-resize; z-index: 3;
}
#panel-resize:hover, #panel-resize.drag { background: rgba(228,180,52,0.25); }

/* миникарта сворачивается */
.mm-wrap { position: relative; }
#mm-fold { position: absolute; top: 6px; right: 6px; padding: 0 5px; font-size: 11px; line-height: 16px; opacity: 0.75; }
#mm-fold:hover { opacity: 1; }
body.mm-folded #minimap { display: none; }
body.mm-folded .mm-wrap { min-height: 26px; }

/* открепленное окно здания — поверх карты, тянется за шапку, растягивается за угол */
body.info-float #info-wrap {
  position: fixed; z-index: 6;
  resize: both; overflow: hidden;
  min-width: 260px; min-height: 160px;
  box-shadow: inset 0 0 0 1px var(--line-hi), inset 0 0 0 3px #0a0705, 0 8px 30px rgba(0,0,0,0.8);
}
body.info-float #info-bar { cursor: move; background: rgba(0,0,0,0.35); }
body.info-float #split { display: none; }
body.info-float #tab-area { flex: 1 1 auto; }
.ihead { display: grid; grid-template-columns: 64px 1fr; gap: 8px; align-items: center; margin-bottom: 6px; }
.ihead .bpic {
  width: 64px; height: 56px; object-fit: contain; image-rendering: auto;
  background: #120c08; border: 2px solid #0a0705; box-shadow: inset 0 0 0 1px #4a3524; padding: 2px;
}
.ihead h3 { margin: 0; font-size: 17px; color: var(--gold-hi); text-shadow: 0 1px 0 #000; line-height: 1.1; }
.chip {
  display: inline-block; margin-top: 3px; padding: 1px 6px; font-size: 11.5px;
  border: 1px solid #0a0705; box-shadow: inset 0 0 0 1px rgba(255,255,255,0.15);
}
.chip.ok { background: #2f4a26; color: #c8da84; }
.chip.bad { background: #6a2018; color: #f0a070; }
.chip.wait { background: #5a3a10; color: #f6d458; }
.chip.off { background: #3a3632; color: #cec6ba; }
.iactions { display: flex; gap: 3px; margin: 4px 0 6px; }
.iactions button { padding: 2px 5px; }
.iactions .grow { flex: 1; }
.bar {
  height: 10px; background: #120c08; border: 2px solid #0a0705; box-shadow: inset 0 0 0 1px #4a3524;
  margin: 3px 0 6px; position: relative;
}
.bar > div { height: 100%; background: linear-gradient(#a8c060, #4a6e30); }
.bar.mana > div { background: linear-gradient(#bea4f6, #6440a8); }
.irow { display: flex; align-items: center; gap: 6px; margin: 4px 0; font-size: 13px; }
.irow .portrait { width: 36px; height: 36px; }
.isec { font-size: 11.5px; color: var(--gold); letter-spacing: 1px; text-transform: uppercase; margin: 7px 0 3px; }
.recipe {
  display: flex; align-items: center; gap: 4px; padding: 3px 4px; margin: 2px 0;
  background: rgba(0,0,0,0.3); border: 1px solid #0a0705; box-shadow: inset 0 0 0 1px #3a2a1a;
  font-family: 'PT Serif', Georgia, serif; font-size: 12px;
}
.recipe.off { opacity: 0.45; }
.recipe img { width: 22px; height: 22px; }
.recipe .arrow { color: var(--gold); font-weight: bold; padding: 0 2px; }
.recipe .t { margin-left: auto; color: var(--text-dim); }
.recipe input { accent-color: var(--gold); margin: 0 0 0 4px; }
.idesc { font-size: 12px; font-style: italic; color: var(--text-dim); margin-top: 8px; }
.tip { font-size: 12.5px; color: var(--text-dim); line-height: 1.45; }
.tip b { color: var(--text); }
.train-grid { display: grid; grid-template-columns: repeat(5, 1fr); gap: 3px; }
.tbtn { flex-direction: column; padding: 2px 1px; font-size: 10px; gap: 0; position: relative; }
.tbtn img { width: 32px; height: 32px; }
.tbtn .q { position: absolute; top: 0; right: 2px; color: var(--gold-hi); font-weight: bold; font-size: 11px; }
.queue { display: flex; gap: 2px; flex-wrap: wrap; min-height: 30px; }
.queue img { width: 28px; height: 28px; background: #120c08; border: 1px solid #4a3524; cursor: pointer; }

/* ---------- Игровое поле ---------- */

#view { position: relative; flex: 1; overflow: hidden; }
#game { display: block; width: 100%; height: 100%; image-rendering: pixelated; filter: saturate(1.16) contrast(1.06); }   /* сочные краски в духе «Героев III» */

#vignette {
  position: absolute; inset: 0; pointer-events: none;
  background: radial-gradient(ellipse at center, rgba(0,0,0,0) 62%, rgba(8,5,2,0.5) 100%);
}

#topbar {
  position: absolute; top: 8px; right: 8px; left: 8px;
  display: flex; gap: 8px; align-items: center; justify-content: flex-end;
  pointer-events: none; z-index: 7;
}
#topbar > * { pointer-events: auto; }
#clock, .speed, .dd-t, .dd-menu {
  background: var(--leather);
  image-rendering: pixelated;
  border: 2px solid #0a0705;
  box-shadow: inset 0 0 0 1px #9a6c3c, inset 0 0 0 2px rgba(0,0,0,0.35), 0 2px 0 rgba(0,0,0,0.5);
  padding: 8px 11px; display: flex; align-items: center; gap: 4px;
}
.dd { position: relative; display: inline-flex; }
.dd-l { margin-right: auto; }
.dd-t { cursor: pointer; color: var(--text); font-family: 'PT Serif', Georgia, serif; font-size: 13px; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 1px 0 #000; gap: 7px; min-height: 30px; }
.dd-t:hover { filter: brightness(1.25); }
.dd-t::after { content: '▾'; font-size: 10px; color: var(--gold); margin-left: 1px; }
.dd.open > .dd-t { box-shadow: inset 0 0 0 1px var(--gold), 0 2px 0 rgba(0,0,0,0.5); }
.dd.open > .dd-t::after { content: '▴'; }
.dd-t span { display: inline-flex; align-items: center; gap: 2px; }
.dd-t img { width: 20px; height: 20px; }
.dd-menu { display: none; position: absolute; top: calc(100% + 4px); right: 0; z-index: 8; gap: 3px; box-shadow: inset 0 0 0 1px #9a6c3c, inset 0 0 0 2px rgba(0,0,0,0.35), 0 6px 14px rgba(0,0,0,0.7); transform-origin: top center; }
/* кусок кожи разворачивается сверху вниз; сверху остаётся свёрнутый валик */
.dd.open > .dd-menu { animation: leather-unroll 0.4s cubic-bezier(.22,.8,.3,1) both; }
#dd-res.open > .dd-menu { animation: leather-unroll 0.4s cubic-bezier(.22,.8,.3,1) both; }
.dd-menu::before { content: ''; position: absolute; left: -3px; right: -3px; top: -7px; height: 9px; pointer-events: none;
  background: linear-gradient(#e0b078, #a8703c 35%, #6a4220 70%, #3a2210); border: 2px solid #0a0705; box-shadow: 0 2px 0 rgba(0,0,0,0.5); }
@keyframes leather-unroll { from { clip-path: inset(-10px -4px 100% -4px); } to { clip-path: inset(-10px -4px -4px -4px); } }
.dd-l .dd-menu { right: auto; left: 0; }
.dd.open > .dd-menu { display: flex; }
#res-bar { flex-direction: column; align-items: stretch; gap: 2px; min-width: 160px; padding: 14px 12px 10px; }
.res-row { display: flex; align-items: center; gap: 8px; font-family: 'PT Serif', Georgia, serif; font-size: 13px; padding: 1px 2px; border-bottom: 1px dotted rgba(20,10,4,0.6); text-shadow: 0 0 3px #000, 0 0 3px #000, 0 1px 0 #000; }
.res-row:last-child { border-bottom: 0; }
.res-row img { width: 22px; height: 22px; }
.res-row .rn { flex: 1; font-family: inherit; }
.res-row b { color: var(--gold-hi); }
#clock { font-family: 'PT Serif', Georgia, serif; color: var(--gold); font-size: 15px; min-width: 64px; justify-content: center; text-shadow: 0 0 3px #000, 0 0 3px #000, 0 1px 0 #000; }
.speed { gap: 2px; padding: 3px 6px; }
.speed button, .dd-menu button { padding: 2px 7px; }
.dd-menu button { min-width: 34px; min-height: 30px; }
.dd-menu { padding-top: 11px; }

#toasts {
  position: absolute; left: 50%; top: 52px; transform: translateX(-50%);
  display: flex; flex-direction: column; gap: 4px; align-items: center;
}
/* ===== Оповещения: обожжённый пергамент (чистый CSS, без картинок и фильтров) ===== */
#toasts { pointer-events: none; z-index: 18; }
.toast, .ach-toast {
  --wax: #b3261e; --wax-hi: #e8624f; --wax-lo: #5e100b; --ribbon: #8c2a1c; --mark: '✦';
  position: relative; box-sizing: border-box; pointer-events: auto; cursor: pointer; transform-origin: 50% 0;
  background:
    radial-gradient(circle at 9% 78%, #1d0e05 0 2.2px, #6a3310 3px, rgba(120,60,18,0.55) 4.8px, transparent 6.5px),
    radial-gradient(circle at 93% 24%, #1d0e05 0 1.6px, #6a3310 2.4px, rgba(120,60,18,0.5) 4px, transparent 5.5px),
    radial-gradient(ellipse at 3% 3%, rgba(70,28,6,0.75), transparent 38%),
    radial-gradient(ellipse at 97% 100%, rgba(70,28,6,0.8), transparent 40%),
    radial-gradient(ellipse at 100% 0%, rgba(90,40,10,0.45), transparent 30%),
    radial-gradient(ellipse at 0% 100%, rgba(90,40,10,0.45), transparent 30%),
    radial-gradient(ellipse 22px 9px at 62% 30%, rgba(150,100,40,0.22), transparent),
    radial-gradient(ellipse 30px 10px at 34% 74%, rgba(140,90,30,0.2), transparent),
    linear-gradient(97deg, transparent 41%, rgba(120,80,30,0.16) 42%, transparent 44%),
    linear-gradient(172deg, transparent 58%, rgba(120,80,30,0.13) 59%, transparent 61%),
    linear-gradient(90deg, var(--ribbon) 0 100%) 0 0 / 100% 3px no-repeat,
    radial-gradient(ellipse at 50% 45%, #f1deaa 0%, #e6cd92 60%, #cfae6c 100%);
  box-shadow: inset 0 0 0 4px #24110a, inset 0 0 0 5px rgba(150,70,20,0.7), inset 0 0 14px 6px rgba(80,32,8,0.78), inset 0 0 26px 8px rgba(120,70,20,0.28);
  clip-path: var(--c0);
  color: #2a1608; text-shadow: 0 0 1px rgba(255,238,190,0.55);
  display: flex; align-items: center; gap: 10px; text-align: left;
  padding: 12px 24px 13px 52px; min-height: 52px; max-width: min(440px, 92vw);
  font-family: 'Ruslan Display', 'Kurale', Georgia, serif; font-size: 15px; line-height: 1.25; letter-spacing: 0.01em;
  animation: pUnfold 0.42s cubic-bezier(.2,.8,.3,1) both, pBurn 0.5s ease-in var(--life, 2.9s) forwards;
  -webkit-tap-highlight-color: transparent;
}
.toast::before, .ach-cup::before {
  content: var(--mark); position: absolute; left: 11px; top: 50%; width: 30px; height: 30px; margin-top: -15px;
  display: flex; align-items: center; justify-content: center; border-radius: 50% 46% 52% 48%;
  font: 15px/1 Georgia, serif; color: rgba(255,225,190,0.92); text-shadow: 0 -1px 0 rgba(0,0,0,0.5), 0 1px 0 rgba(255,255,255,0.18);
  background: radial-gradient(circle at 34% 30%, var(--wax-hi) 0, var(--wax) 55%, var(--wax-lo) 100%);
  box-shadow: inset 0 0 0 2px rgba(0,0,0,0.18), inset 0 0 0 3px rgba(255,200,160,0.14), 0 1px 2px rgba(40,10,0,0.6);
}
.toast::after, .ach-toast::after { content: ''; position: absolute; inset: 0; pointer-events: none; background: radial-gradient(ellipse at 50% 50%, rgba(40,14,2,0), rgba(40,14,2,0.9)); opacity: 0; animation: pChar 0.5s ease-in var(--life, 2.9s) forwards; }
.toast.burn, .ach-toast.burn { animation: pBurn 0.3s ease-in forwards; }
.toast.burn::after, .ach-toast.burn::after { animation: pChar 0.3s ease-in forwards; }
/* типы: цвет сургуча и ленты */
.toast.imp, .ach-toast { --wax: #c28a14; --wax-hi: #f6d458; --wax-lo: #6c4706; --ribbon: #b8861c; --mark: '!'; }
.toast.night { --wax: #4b3a82; --wax-hi: #8a78c8; --wax-lo: #1e1640; --ribbon: #3f3070; --mark: '☾'; }
.toast.coop { --wax: #2f6f54; --wax-hi: #6fbf94; --wax-lo: #123524; --ribbon: #2c6a4e; --mark: '⚑'; }
.toast.imp::before { color: #3a2204; text-shadow: 0 1px 0 rgba(255,240,180,0.4); font-weight: bold; }
.toast.link:hover { filter: none; box-shadow: inset 0 0 0 4px #24110a, inset 0 0 0 5px #e4b434, inset 0 0 14px 6px rgba(80,32,8,0.78); }
.toast:active, .ach-toast:active { transform: scale(0.98); }
@keyframes pUnfold { 0% { opacity: 0; transform: translateY(-8px) scaleY(0.25); } 60% { opacity: 1; } 100% { opacity: 1; transform: none; } }
@keyframes pBurn { 0% { clip-path: var(--c0); opacity: 1; } 100% { clip-path: var(--c1); opacity: 0; } }
@keyframes pChar { 0% { opacity: 0; } 100% { opacity: 0.95; } }
@media (prefers-reduced-motion: reduce) { .toast, .ach-toast { animation-duration: 0.01s, 0.3s; } }
.toast.v0, .ach-toast.v0 { --c0: polygon(0% 5px, 11.1% 0px, 22.2% 2.2px, 33.3% 2.4px, 44.4% 2.6px, 55.6% 3.1px, 66.7% 3.8px, 77.8% 0.2px, 88.9% 3.5px, 100% 5px, calc(100% - 1.2px) 33.3%, calc(100% - 2.8px) 66.7%, 100% calc(100% - 5px), 88.9% calc(100% - 2px), 77.8% calc(100% - 1.7px), 66.7% calc(100% - 3.9px), 55.6% calc(100% - 2.3px), 44.4% calc(100% - 1.8px), 33.3% calc(100% - 2.8px), 22.2% calc(100% - 0.6px), 11.1% calc(100% - 2.8px), 0% calc(100% - 5px), 1.7px 66.7%, 3.4px 33.3%); --c1: polygon(calc(0% + 10px) 16px, calc(11.1% + 10px) 11px, calc(22.2% + 10px) 13.2px, calc(33.3% + 10px) 13.4px, calc(44.4% + 10px) 13.6px, calc(55.6% + -10px) 14.1px, calc(66.7% + -10px) 14.8px, calc(77.8% + -10px) 11.2px, calc(88.9% + -10px) 14.5px, calc(100% + -10px) 16px, calc(100% - 17.2px) calc(33.3% + 6px), calc(100% - 18.8px) calc(66.7% + -6px), calc(100% + -10px) calc(100% - 16.0px), calc(88.9% + -10px) calc(100% - 13.0px), calc(77.8% + -10px) calc(100% - 12.7px), calc(66.7% + -10px) calc(100% - 14.9px), calc(55.6% + -10px) calc(100% - 13.3px), calc(44.4% + 10px) calc(100% - 12.8px), calc(33.3% + 10px) calc(100% - 13.8px), calc(22.2% + 10px) calc(100% - 11.6px), calc(11.1% + 10px) calc(100% - 13.8px), calc(0% + 10px) calc(100% - 16.0px), 17.7px calc(66.7% + -6px), 19.4px calc(33.3% + 6px)); }
.toast.v1, .ach-toast.v1 { --c0: polygon(0% 5px, 11.1% 0px, 22.2% 2.7px, 33.3% 3.1px, 44.4% 3.9px, 55.6% 3.2px, 66.7% 3.3px, 77.8% 2.7px, 88.9% 0.5px, 100% 5px, calc(100% - 2.4px) 33.3%, calc(100% - 2.7px) 66.7%, 100% calc(100% - 5px), 88.9% calc(100% - 0.1px), 77.8% calc(100% - 1.6px), 66.7% calc(100% - 3.8px), 55.6% calc(100% - 0.9px), 44.4% calc(100% - 2.3px), 33.3% calc(100% - 1.9px), 22.2% calc(100% - 3.3px), 11.1% calc(100% - 1.2px), 0% calc(100% - 5px), 3.8px 66.7%, 4px 33.3%); --c1: polygon(calc(0% + 10px) 16px, calc(11.1% + 10px) 11px, calc(22.2% + 10px) 13.7px, calc(33.3% + 10px) 14.1px, calc(44.4% + 10px) 14.9px, calc(55.6% + -10px) 14.2px, calc(66.7% + -10px) 14.3px, calc(77.8% + -10px) 13.7px, calc(88.9% + -10px) 11.5px, calc(100% + -10px) 16px, calc(100% - 18.4px) calc(33.3% + 6px), calc(100% - 18.7px) calc(66.7% + -6px), calc(100% + -10px) calc(100% - 16.0px), calc(88.9% + -10px) calc(100% - 11.1px), calc(77.8% + -10px) calc(100% - 12.6px), calc(66.7% + -10px) calc(100% - 14.8px), calc(55.6% + -10px) calc(100% - 11.9px), calc(44.4% + 10px) calc(100% - 13.3px), calc(33.3% + 10px) calc(100% - 12.9px), calc(22.2% + 10px) calc(100% - 14.3px), calc(11.1% + 10px) calc(100% - 12.2px), calc(0% + 10px) calc(100% - 16.0px), 19.8px calc(66.7% + -6px), 20px calc(33.3% + 6px)); }
.toast.v2, .ach-toast.v2 { --c0: polygon(0% 5px, 11.1% 0px, 22.2% 3.2px, 33.3% 3.9px, 44.4% 1.1px, 55.6% 3.3px, 66.7% 2.7px, 77.8% 1.2px, 88.9% 1.6px, 100% 5px, calc(100% - 3.6px) 33.3%, calc(100% - 2.5px) 66.7%, 100% calc(100% - 5px), 88.9% calc(100% - 2.2px), 77.8% calc(100% - 1.6px), 66.7% calc(100% - 3.7px), 55.6% calc(100% - 3.6px), 44.4% calc(100% - 2.8px), 33.3% calc(100% - 1.1px), 22.2% calc(100% - 2px), 11.1% calc(100% - 3.5px), 0% calc(100% - 5px), 1.8px 66.7%, 0.5px 33.3%); --c1: polygon(calc(0% + 10px) 16px, calc(11.1% + 10px) 11px, calc(22.2% + 10px) 14.2px, calc(33.3% + 10px) 14.9px, calc(44.4% + 10px) 12.1px, calc(55.6% + -10px) 14.3px, calc(66.7% + -10px) 13.7px, calc(77.8% + -10px) 12.2px, calc(88.9% + -10px) 12.6px, calc(100% + -10px) 16px, calc(100% - 19.6px) calc(33.3% + 6px), calc(100% - 18.5px) calc(66.7% + -6px), calc(100% + -10px) calc(100% - 16.0px), calc(88.9% + -10px) calc(100% - 13.2px), calc(77.8% + -10px) calc(100% - 12.6px), calc(66.7% + -10px) calc(100% - 14.7px), calc(55.6% + -10px) calc(100% - 14.6px), calc(44.4% + 10px) calc(100% - 13.8px), calc(33.3% + 10px) calc(100% - 12.1px), calc(22.2% + 10px) calc(100% - 13.0px), calc(11.1% + 10px) calc(100% - 14.5px), calc(0% + 10px) calc(100% - 16.0px), 17.8px calc(66.7% + -6px), 16.5px calc(33.3% + 6px)); }


#help {
  position: absolute; left: 50%; top: 50%; transform: translate(-50%, -50%);
  width: min(560px, 92%);
  padding: 16px 20px;
  background: linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.5)), var(--wood-tex), #2a1e14;
  border: 2px solid #0a0705; box-shadow: inset 0 0 0 1px var(--line-hi), 0 10px 40px #000;
  z-index: 5;
}
#help h3 { margin-top: 0; color: var(--gold-hi); }
#help li { margin: 4px 0; line-height: 1.4; }

#loading {
  position: fixed; inset: 0; z-index: 10; overflow: hidden; background: #0a0d24;
}
#load-cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
#loading .load-title {
  position: absolute; left: 0; right: 0; top: 5vh; text-align: center; pointer-events: none;
}
#loading h1, #loading h2 { opacity: 0; }   /* заголовок рисуется пиксельными буквами на холсте, элемент задаёт размер и место */
#loading h1 {
  margin: 0; font-family: "Ruslan Display", Georgia, serif; font-size: clamp(64px, 13vw, 170px); letter-spacing: 0.06em; font-weight: bold; line-height: 1.1;
  background: linear-gradient(#fff2a0, #e4b434 55%, #8e5a18);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
  filter: drop-shadow(0 3px 0 #000) drop-shadow(0 0 18px rgba(255,170,60,0.45));
}
#loading h2 {
  margin: 2px 0 0; font-size: clamp(14px, 2.4vw, 26px); letter-spacing: 0.5em; font-weight: normal;
  color: #d8c088; text-shadow: 0 2px 0 #000, 0 0 12px rgba(255,170,60,0.4);
}
#loading .load-msg {
  position: absolute; left: 0; right: 0; bottom: 4vh; text-align: center;
  color: #e8d4a0; font-style: italic; text-shadow: 0 2px 0 #000;
}
#loading .load-msg::after { content: ''; animation: load-dots 1.4s steps(4, end) infinite; }
@keyframes load-dots { 0% { content: ''; } 25% { content: '.'; } 50% { content: '..'; } 75% { content: '...'; } }
#logo small { display: block; font-size: 11px; letter-spacing: 0.5em; font-weight: normal; -webkit-text-fill-color: #d8c088; margin-top: 2px; }

/* ---------- Телефон ----------
   Карта на весь экран, вкладки — нижняя панель, содержимое — выезжающая шторка.
   Класс body.mobile ставит js/mobile.js по ширине экрана и сенсорному вводу. */

.m-only, #mtool { display: none; }
button { touch-action: manipulation; }
#game, #minimap { touch-action: none; }

.m-li { display: none; }
body.mobile .m-li { display: list-item; }
body.mobile #help { max-height: 86%; overflow-y: auto; padding: 12px 14px; font-size: 13px; }
body.mobile #help-close { padding: 8px 18px; }

body.mobile #app { display: block; position: relative; height: 100%; height: 100dvh; }
body.mobile #view { position: absolute; inset: 0; }
body.mobile .m-only { display: inline-flex; }
body.mobile #logo { display: none; }

body.mobile #panel {
  position: absolute; left: 0; right: 0; bottom: 0; width: auto;
  padding: 4px 6px calc(5px + env(safe-area-inset-bottom));
  gap: 5px; z-index: 4;
  border-right: none; border-top: 3px solid #0a0705;
  box-shadow: 0 -4px 14px rgba(0,0,0,0.7), inset 0 1px 0 var(--line);
  max-height: 100%;
}
body.mobile #sheet-close { order: 0; display: none; padding: 2px; font-size: 13px; }
body.mobile #tab-area { order: 1; display: none; height: 48vh; flex: none; }
body.mobile #info-wrap { order: 2; display: none; height: auto !important; max-height: 50vh; overflow-y: auto; }
body.mobile #info-bar, body.mobile #split, body.mobile #panel-resize, body.mobile #mm-fold { display: none; }
body.mobile #tabs { order: 3; }
body.mobile .tab-btn { height: 46px; }
body.mobile.sheet-tab #tab-area,
body.mobile.sheet-info #info-wrap,
body.mobile.sheet-tab #sheet-close,
body.mobile.sheet-info #sheet-close { display: block; }

/* миникарта поверх карты по кнопке ▦ */
body.mobile .mm-wrap { display: none; }
body.mobile.show-mm .mm-wrap {
  display: block; position: fixed; z-index: 5;
  top: calc(84px + env(safe-area-inset-top)); left: 8px; width: min(52vw, 260px);
}

body.mobile #topbar {
  top: calc(4px + env(safe-area-inset-top)); left: 4px; right: 4px;
  flex-wrap: nowrap; gap: 3px;
}
body.mobile #clock { font-size: 12px; min-width: 0; padding: 4px 11px; margin-right: auto; margin-left: auto; }
body.mobile .dd-t { min-height: 28px; padding: 4px 7px; font-size: 12px; gap: 3px; }
body.mobile .dd-t img { width: 16px; height: 16px; }
body.mobile .speed { padding: 4px 6px; }
body.mobile .speed button { padding: 2px 8px; min-height: 26px; }
body.mobile .dd-menu button { min-height: 38px; min-width: 42px; }
body.mobile #topbar .m-only { order: 0; }
body.mobile #dd-res .dd-t span:nth-child(n+3) { display: none; }   /* на телефоне в кнопке — дерево и камень, остальное в списке */
body.mobile #dd-snd .dd-menu, body.mobile #dd-speed .dd-menu { right: 0; }
body.mobile #toasts { top: calc(96px + env(safe-area-inset-top)); width: 94%; z-index: 21; }   /* под верхней полосой, поверх целей и вызова дня */
body.mobile .toast, body.mobile .ach-toast { font-family: 'PT Serif', Georgia, serif; line-height: 1.3; letter-spacing: 0; }   /* Ruslan Display в мелком кегле плохо читается */
body.mobile #view #hero-card .hc-body { zoom: .9; }
body.mobile .toast, body.mobile .ach-toast { font-size: 14.5px; padding: 9px 18px 10px 46px; min-height: 44px; gap: 8px; }
body.mobile .toast::before, body.mobile .ach-cup::before { left: 9px; width: 28px; height: 28px; margin-top: -14px; }

body.mobile #build-list { grid-template-columns: repeat(auto-fill, minmax(96px, 1fr)); }
body.mobile #build-cats { overflow-x: auto; scrollbar-width: none; }
body.mobile #build-cats button { flex: 1 0 auto; padding: 6px 8px; font-size: 12.5px; }
body.mobile .tools button { padding: 8px 3px; }
body.mobile .menu-list button { padding: 10px 10px; }
body.mobile .hotkeys { display: none; }
body.mobile .iactions button { padding: 6px 8px; }

/* панель инструмента: «коснитесь карты», поставить, повернуть, отмена */
body.mobile #mtool:not(.hidden) {
  display: flex; flex-direction: column; align-items: stretch; gap: 6px;   /* кнопки колонкой у правого края — не под пальцем посередине */
  position: absolute; left: auto; right: 8px; transform: none;
  bottom: calc(86px + env(safe-area-inset-bottom));
  width: 132px;
  padding: 6px; z-index: 3;
  background: var(--planks);
  border: 2px solid #0a0705; box-shadow: inset 0 0 0 1px var(--line-hi), 0 3px 8px rgba(0,0,0,0.6);
}
#mtool-text { font-size: 12px; line-height: 1.2; white-space: normal; overflow-wrap: anywhere; }
#mtool button { min-width: 40px; min-height: 36px; font-size: 18px; padding: 0 8px; }

/* телефон боком: панель слева узкой колонкой, карта справа */
@media (orientation: landscape) {
  body.mobile #panel { right: auto; width: min(400px, 52vw); }
  body.mobile #tab-area { height: calc(100dvh - 120px); }
  body.mobile #info-wrap { max-height: calc(100dvh - 120px); }
  body.mobile #mtool:not(.hidden) { bottom: 8px; }
  body.mobile #topbar { left: auto; width: calc(100% - min(400px, 52vw) - 14px); }
  body.mobile.show-mm .mm-wrap { left: auto; right: 8px; width: min(36vw, 240px); }
}

/* ---------- Доставки: большая кнопка ---------- */
.deliv {
  display: flex; align-items: center; gap: 8px; width: 100%;
  margin: 2px 0 8px; padding: 6px 10px; text-align: left;
  border: 2px solid #0a0705; cursor: pointer; color: var(--text);
}
.deliv img { width: 32px; height: 32px; image-rendering: pixelated; flex: none; }
.deliv span { display: flex; flex-direction: column; line-height: 1.2; }
.deliv b { font-size: 14px; }
.deliv small { font-size: 11px; opacity: 0.75; }
.deliv.open { background: linear-gradient(#36502a, #243a1c); box-shadow: inset 0 0 0 1px #6e9a4a; }
.deliv.open b { color: #c8e090; }
.deliv.closed { background: linear-gradient(#7a2418, #4e140c); box-shadow: inset 0 0 0 1px #e0583a; animation: delivPulse 1.6s ease-in-out infinite; }
.deliv.closed b { color: #ffd0b0; }
.deliv:hover { filter: brightness(1.15); }
@keyframes delivPulse { 50% { box-shadow: inset 0 0 0 1px #e0583a, 0 0 10px rgba(224,88,58,0.6); } }

/* ---------- Журнал событий ---------- */
.log-filters { display: flex; flex-wrap: wrap; gap: 3px; margin-bottom: 6px; }
.log-filters button { padding: 2px 7px; font-size: 12px; }
.log-filters button.active { background: #5a3a10; color: var(--gold-hi); }
.log-list { display: flex; flex-direction: column; }
.log-row { display: flex; gap: 6px; align-items: baseline; padding: 3px 4px; border-bottom: 1px solid rgba(90,65,40,0.45); font-size: 13px; line-height: 1.3; }
.log-row.click { cursor: pointer; }
.log-row.click:hover { background: rgba(228,180,52,0.12); }
.log-t { color: var(--text-dim); font-size: 11px; font-variant-numeric: tabular-nums; flex: none; width: 38px; }
.log-i { flex: none; width: 18px; text-align: center; }
.log-x b { color: var(--gold-hi); }


/* подсказка о повороте при постройке */
#tool-hint {
  position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 4;
  padding: 6px 14px; background: rgba(20,14,8,0.88); border: 1px solid var(--line-hi);
  color: var(--text); font-size: 13px; pointer-events: none; white-space: nowrap;
}
#tool-hint.hidden { display: none; }
#tool-hint kbd { padding: 1px 6px; border: 1px solid var(--gold); border-radius: 3px; background: #1a130d; color: var(--gold-hi); font-weight: bold; }

/* кнопка достройки до уровня 2 */
.upg { display: flex; width: 100%; text-align: left; margin: 6px 0; padding: 7px 10px; border: 2px solid #c89226; border-radius: 4px; background: linear-gradient(#4a3a1c, #2e2410); color: #ffe9b0; cursor: pointer; }
.upg span { display: flex; flex-direction: column; line-height: 1.25; }
.upg b { font-size: 13px; display: flex; gap: 4px; align-items: center; }
.upg b img { width: 18px; height: 18px; image-rendering: pixelated; }
.upg small { font-size: 11px; opacity: 0.8; font-style: italic; }
.upg:hover { filter: brightness(1.15); }
.upg.no { border-color: #6a5a3a; color: #b4a37a; filter: grayscale(0.5); }
.lvl { font-size: 11px; background: #c89226; color: #2a1c08; border-radius: 3px; padding: 1px 5px; vertical-align: middle; }

/* журнал: пиксельные иконки вместо эмодзи */
.log-filters button { display: inline-flex; align-items: center; gap: 4px; }
.log-filters button img, .log-i img { width: 16px; height: 16px; image-rendering: pixelated; display: block; }
.log-i { align-self: center; }
.log-s { display: block; color: var(--text-dim); font-size: 11px; opacity: 0.85; margin-top: 1px; }

/* ---------- Постепенно открывающееся меню ---------- */
#build-cats { justify-content: safe center; }
#build-cats button { flex: 0 1 auto; min-width: 56px; padding-left: 8px; padding-right: 8px; }
.tools button.locked { display: none; }
@keyframes menu-pop { 0% { opacity: 0; transform: scale(0.6); filter: brightness(2); } 60% { opacity: 1; transform: scale(1.08); } 100% { opacity: 1; transform: none; filter: none; } }
#build-cats button.enter, .bbtn.enter, .tools button.enter { animation: menu-pop 0.6s ease-out both; }

/* фильтры журнала — строго в одну строку */
.log-filters { flex-wrap: nowrap; gap: 2px; }
.log-filters button { flex: 1 1 0; min-width: 0; justify-content: center; padding: 2px 3px; font-size: 11px; white-space: nowrap; gap: 3px; }
.log-filters button img { width: 14px; height: 14px; flex: none; }

/* кнопки журнала: компактнее, буквы не вылезают за границы */
.log-filters button { padding: 1px 2px; font-size: 10px; gap: 2px; overflow: hidden; text-overflow: ellipsis; letter-spacing: -0.2px; }
.log-filters button img { width: 12px; height: 12px; }
.log-filters button { flex: 1 1 auto; }

/* миникарта: по умолчанию маленькая, можно увеличить */
#minimap { width: 60%; margin: 0 auto; }
body.mm-big #minimap { width: 100%; }
#mm-size { position: absolute; top: 6px; right: 28px; padding: 0 5px; font-size: 11px; line-height: 16px; opacity: 0.75; }
#mm-size:hover { opacity: 1; }
body.mm-folded #mm-size { display: none; }

/* кнопка субботника */
#sub-btn { display: inline-flex; align-items: center; gap: 4px; }
.menu-list #sub-btn { display: flex; width: 100%; }
#sub-btn img { width: 16px; height: 16px; image-rendering: pixelated; }
#sub-btn.sub-ready { border-color: #a8d060; box-shadow: 0 0 8px rgba(168,208,96,0.6); animation: subpulse 1.6s ease-in-out infinite; }
#sub-btn.sub-on { background: #3a5a1c; color: #e8ffc0; }
@keyframes subpulse { 50% { box-shadow: 0 0 14px rgba(168,208,96,0.95); } }

/* ---------- Стартовый экран (js/startmenu.js) ---------- */
#loading.leaving { opacity: 0; transition: opacity 0.6s; pointer-events: none; }
#start-menu {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 2;
  padding: 36px 16px calc(18px + env(safe-area-inset-bottom));
  background: linear-gradient(rgba(8,6,12,0), rgba(8,6,12,0.82) 38%);
  display: flex; justify-content: center;
}
#loading:not(.with-menu) #start-menu { display: none; }
#loading.with-menu .load-msg { display: none; }
.sm-panel { display: flex; flex-direction: column; gap: 10px; width: min(92vw, 380px); }
.sm-panel.hidden { display: none; }
.sm-btn {
  display: flex; flex-direction: column; align-items: center; gap: 2px; padding: 11px 16px; min-height: 48px;
  font: inherit; color: #f6e8c0; cursor: pointer; border-radius: 6px;
  background: linear-gradient(#5a4220, #3a2a14); border: 1px solid #b8902c; box-shadow: 0 3px 0 #1a1008, 0 0 12px rgba(255,170,60,0.12);
}
.sm-btn b { font-size: 18px; letter-spacing: 0.04em; }
.sm-btn small { font-size: 12px; opacity: 0.75; }
.sm-btn.primary { background: linear-gradient(#a87a22, #6a4a14); border-color: #f0c860; box-shadow: 0 3px 0 #1a1008, 0 0 18px rgba(255,190,70,0.35); }
.sm-btn.ghost { background: rgba(20,14,8,0.55); border-color: #6a5430; }
.sm-btn:hover:not(:disabled) { filter: brightness(1.15); transform: translateY(-1px); }
.sm-btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 #1a1008; }
.sm-btn:disabled { opacity: 0.45; cursor: default; }
.sm-panel label { display: flex; flex-direction: column; gap: 4px; color: #d8c088; font-size: 13px; }
.sm-panel input {
  padding: 10px 12px; font: inherit; font-size: 16px; color: #f6e8c0; background: rgba(12,8,4,0.8);
  border: 1px solid #7a5f28; border-radius: 5px;
}
.sm-msg { min-height: 1.2em; color: #f0c880; font-size: 13px; text-align: center; }
.sm-help { margin: 0; padding: 12px 14px 12px 28px; color: #e8dcc0; font-size: 14px; line-height: 1.4; background: rgba(12,8,4,0.7); border: 1px solid #5a4620; border-radius: 6px; }
@media (max-height: 520px) {
  #start-menu { padding-top: 14px; }
  .sm-panel { flex-direction: row; flex-wrap: wrap; width: min(96vw, 640px); justify-content: center; }
  .sm-btn { flex: 1 1 44%; min-height: 40px; padding: 6px 10px; }
  .sm-btn b { font-size: 15px; }
  .sm-btn small { display: none; }
}
@media (min-width: 700px) and (min-height: 521px) {
  .sm-panel[data-panel="main"] { flex-direction: row; width: min(94vw, 980px); }
  .sm-panel[data-panel="main"] .sm-btn { flex: 1; }
  #start-menu { padding-top: 28px; }
}
.sm-btn { position: relative; }
.sm-vine { position: absolute; pointer-events: none; overflow: visible; z-index: 3; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.55)); }
@media (max-width: 700px) { .sm-panel { gap: 20px; } }

/* ---------- Телефон: меньше всего на экране ---------- */
#res-btn { display: none !important; }
body.mobile #hero-btn { left: 8px; bottom: calc(66px + env(safe-area-inset-bottom)); padding: 2px; gap: 0; border-radius: 8px; }
body.mobile #hero-btn img { width: 38px; height: 38px; }
body.mobile #hero-btn .hb-t { display: none; }
body.mobile #hero-btn .hb-lv { display: block; position: absolute; right: -4px; bottom: -4px; min-width: 16px; padding: 0 3px; border-radius: 8px; background: #b8902c; color: #1a1008; font-size: 11px; font-weight: bold; text-align: center; }
#hero-btn .hb-lv { display: none; }
body.mobile.sheet-tab #hero-btn, body.mobile.sheet-info #hero-btn { display: none; }
#res-btn { padding: 0 !important; }
#res-btn img { width: 20px; height: 20px; vertical-align: middle; }
body.mobile #dd-zoom { display: none; }

/* выбор кнопки стартового меню: стебель обвивает кнопку, искры (js/startmenu.js) */
.sm-grow { position: absolute; pointer-events: none; z-index: 4; }
.sm-grow svg { position: absolute; left: 0; top: 0; filter: drop-shadow(0 2px 2px rgba(0,0,0,0.55)); }
.sm-stem { fill: none; stroke-linecap: round; stroke-dasharray: 1 1; stroke-dashoffset: 1; animation: sm-stem 0.55s ease-out forwards; }
.sm-g { transform-box: fill-box; transform-origin: center; opacity: 0; animation: sm-pop 0.28s ease-out forwards; }
.sm-spark { position: absolute; width: 4px; height: 4px; margin: -2px 0 0 -2px; background: #ffe27a; box-shadow: 0 0 5px 1px #ffb040; opacity: 0; animation: sm-spark 0.7s ease-out forwards; }
.sm-btn.sm-picked { filter: brightness(1.2); box-shadow: 0 3px 0 #1a1008, 0 0 22px rgba(255,200,80,0.6); }
@keyframes sm-stem { to { stroke-dashoffset: 0; } }
@keyframes sm-pop { 0% { opacity: 0; transform: scale(0.1); } 70% { opacity: 1; transform: scale(1.25); } 100% { opacity: 1; transform: scale(1); } }
@keyframes sm-spark { 0% { opacity: 0; transform: translate(0,0) scale(1); } 20% { opacity: 1; } 100% { opacity: 0; transform: translate(var(--dx), var(--dy)) scale(0.3); } }

/* ---------- Выслуга трудяг и работяг (вкладка «Жители») ---------- */
.lvls { padding: 2px 4px 5px 46px; border-bottom: 1px solid rgba(90,65,40,0.5); }
.xpbars { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 3px; align-items: center; }
.xpbar { position: relative; display: inline-block; width: 34px; height: 10px; background: #1a120a; border: 1px solid #4a3524; box-shadow: inset 0 0 0 1px #0a0705; overflow: hidden; }
.xpbar i { position: absolute; left: 0; top: 0; bottom: 0; background: linear-gradient(#8ab048, #4e8a2a); }
.xpbar.l2 i { background: linear-gradient(#e8c860, #b08a2a); }
.xpbar.l3 i { background: linear-gradient(#ffe070, #d8a020); }
.xpbar b { position: absolute; right: 2px; top: -1px; font-size: 9px; line-height: 10px; color: #f6eccc; text-shadow: 0 0 2px #000, 0 0 2px #000; font-family: 'PT Serif', Georgia, serif; }

/* телефон в портрете: название не шире экрана, меню ниже — больше места костру */
@media (max-width: 600px) {
  #loading h1 { font-size: 12.5vw; }
  #start-menu { padding-top: 20px; }
  .sm-panel { gap: 20px; }
  .sm-btn { padding: 5px 14px; min-height: 40px; }
  .sm-btn b { font-size: 16px; }
  .sm-btn small { font-size: 11px; }
}
.sm-btn b, .sm-btn small { position: relative; z-index: 5; }

/* кнопки меню выплывают вбок, лоза прорастает следом (js/startmenu.js) */
.sm-in-l, .sm-in-r { animation: sm-slide-l 0.55s cubic-bezier(.2,.8,.3,1) var(--d, 0s) both; }
.sm-in-r { animation-name: sm-slide-r; }
.sm-in-l .sm-vine { animation: sm-vine-l 0.9s ease-out calc(var(--d, 0s) + 0.35s) both; }
.sm-in-r .sm-vine { animation: sm-vine-r 0.9s ease-out calc(var(--d, 0s) + 0.35s) both; }
@keyframes sm-slide-l { from { transform: translateX(-120vw); } to { transform: none; } }
@keyframes sm-slide-r { from { transform: translateX(120vw); } to { transform: none; } }
@keyframes sm-vine-l { from { clip-path: inset(-40px 100% -40px -40px); } to { clip-path: inset(-40px -40px -40px -40px); } }
@keyframes sm-vine-r { from { clip-path: inset(-40px -40px -40px 100%); } to { clip-path: inset(-40px -40px -40px -40px); } }
/* телефон: кнопки по две в ряд, меню вдвое ниже */
@media (max-width: 600px) {
  .sm-panel[data-panel="main"] { flex-direction: row; flex-wrap: wrap; justify-content: space-between; row-gap: 14px; column-gap: 8px; width: min(96vw, 420px); }
  .sm-panel[data-panel="main"] .sm-btn { flex: 0 0 calc(50% - 6px); min-width: 0; padding: 4px 8px; }
  .sm-panel[data-panel="main"] .sm-btn.sm-wide { flex-basis: 100%; }
  .sm-panel[data-panel="main"] .sm-btn b { font-size: 14px; }
  .sm-panel[data-panel="main"] .sm-btn small { font-size: 10px; max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
}

/* пиксельная лоза: холст растягивается без сглаживания, рост — ступенчатая «развёртка» вдоль кнопки */
canvas.sm-vine { filter: none; }
.sm-grow-cv { position: absolute; left: 0; top: 0; image-rendering: pixelated; animation: sm-wipe 0.55s steps(14) both; }
@keyframes sm-wipe { from { clip-path: inset(0 100% 0 0); } to { clip-path: inset(0 0 0 0); } }
.sm-spark { border-radius: 0; box-shadow: none; width: 3px; height: 3px; }

/* выпадающий список «Мультиплеер» (js/startmenu.js) */
.sm-sub { position: absolute; z-index: 8; display: flex; flex-direction: column; gap: 14px; padding: 12px; background: rgba(10,7,4,0.94); border: 1px solid #b8902c; border-radius: 8px; box-shadow: 0 6px 24px rgba(0,0,0,0.8); }
.sm-sub.hidden { display: none; }
.sm-panel[data-panel="main"] .sm-sub .sm-btn, .sm-sub .sm-btn { flex: 0 0 auto; width: 100%; }
.sm-sub .sm-btn small { max-width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* нажатие: лоза сползает с кнопки вниз (ступенчато, как пиксель-арт) и отрастает снова */
.sm-peel canvas.sm-vine { animation: sm-peel 0.62s steps(10) forwards !important; }
.sm-regrow canvas.sm-vine { animation: sm-vine-l 0.65s steps(12) both !important; }
@keyframes sm-peel { from { transform: none; clip-path: inset(-40px -40px -40px -40px); } to { transform: translateY(34px); clip-path: inset(100% -40px -40px -40px); } }

/* рост лозы рисуется покадрово на холсте (js/startmenu.js) — CSS-развёртки для неё больше нет */
.sm-in-l canvas.sm-vine, .sm-in-r canvas.sm-vine { animation: none; }

/* заголовки — уставный средневековый шрифт */
h1, h2, h3, #logo, .ihead h3, #help h3 { font-family: 'Ruslan Display', 'Kurale', Georgia, serif; font-weight: normal; letter-spacing: 0.02em; }

/* карточка героя (справа сверху): воронёная сталь в латунной окантовке с четырьмя заклёпками */
#view #hero-card {
  background: radial-gradient(circle at 8px 8px, #fff3c4 0 1px, #d2a73c 2px, #7a5a14 3.4px, #1a1308 4px, transparent 4.6px), radial-gradient(circle at calc(100% - 8px) 8px, #fff3c4 0 1px, #d2a73c 2px, #7a5a14 3.4px, #1a1308 4px, transparent 4.6px), radial-gradient(circle at 8px calc(100% - 8px), #fff3c4 0 1px, #d2a73c 2px, #7a5a14 3.4px, #1a1308 4px, transparent 4.6px), radial-gradient(circle at calc(100% - 8px) calc(100% - 8px), #fff3c4 0 1px, #d2a73c 2px, #7a5a14 3.4px, #1a1308 4px, transparent 4.6px),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.035) 0 1px, rgba(0,0,0,0.06) 1px 3px), linear-gradient(180deg, #3a3e47 0%, #23262d 40%, #181a1f 100%);
  border: 2px solid #0a0705; border-radius: 3px; color: #e9e2cf;
  box-shadow: inset 0 0 0 1px #d2a73c, inset 0 0 0 3px #15120e, inset 0 0 0 4px rgba(210,167,60,0.45), inset 0 8px 14px rgba(255,255,255,0.05), 0 5px 16px rgba(0,0,0,0.7);
}
body.mobile #view #hero-card.mini { background: none; border: 0; box-shadow: none; }
#view #hero-card h3 { color: #f0d27a; text-shadow: 0 1px 0 #000; }

/* онлайн: время нельзя менять, остаётся только указатель скорости */

/* верхняя панель (ресурсы, масштаб, звук, время, скорость): воронёная сталь в латунной окантовке, как карточка героя */
#clock, .speed, .dd-t, .dd-menu {
  background: radial-gradient(circle at 6px 6px, #fff3c4 0 .8px, #d2a73c 1.6px, #7a5a14 2.6px, #1a1308 3px, transparent 3.4px), radial-gradient(circle at calc(100% - 6px) 6px, #fff3c4 0 .8px, #d2a73c 1.6px, #7a5a14 2.6px, #1a1308 3px, transparent 3.4px), radial-gradient(circle at 6px calc(100% - 6px), #fff3c4 0 .8px, #d2a73c 1.6px, #7a5a14 2.6px, #1a1308 3px, transparent 3.4px), radial-gradient(circle at calc(100% - 6px) calc(100% - 6px), #fff3c4 0 .8px, #d2a73c 1.6px, #7a5a14 2.6px, #1a1308 3px, transparent 3.4px),
    repeating-linear-gradient(90deg, rgba(255,255,255,0.035) 0 1px, rgba(0,0,0,0.06) 1px 3px), linear-gradient(180deg, #3a3e47 0%, #23262d 45%, #181a1f 100%);
  border-radius: 3px;
  box-shadow: inset 0 0 0 1px #d2a73c, inset 0 0 0 2px #15120e, inset 0 6px 8px rgba(255,255,255,0.05), 0 3px 8px rgba(0,0,0,0.6);
  padding: 8px 14px;
}


/* лоза вырастает только при нажатии и потом отцветает */
canvas.sm-vine { transition: opacity 0.6s; }
canvas.sm-vine.sm-fade { opacity: 0; }

/* ---------- Помощь новичку (js/guide.js) ---------- */
.why { display: flex; gap: 8px; align-items: flex-start; margin: 6px 0; padding: 7px 8px; background: rgba(106,32,24,0.45); border: 1px solid #8a3a28; border-radius: 3px; font-size: 12.5px; line-height: 1.4; }
.why img { width: 24px; height: 24px; flex: none; }
.why b { color: #f4c8a0; font-weight: normal; }
.why-a { color: var(--text); margin-top: 2px; }
.why-wrap { margin: 2px 0 4px; }
.g-link { font-size: 12px; color: var(--gold); cursor: pointer; text-decoration: underline dotted; }
.alert-a { font-size: 11.5px; color: var(--text-dim); margin-top: 1px; line-height: 1.35; }
.bal { margin: 2px 0 4px; }
.bal-row { display: flex; align-items: center; gap: 5px; font-size: 12.5px; padding: 2px 3px; border-bottom: 1px solid rgba(90,65,40,0.35); cursor: pointer; }
.bal-row img { width: 18px; height: 18px; flex: none; }
.bal-row .bn { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.bal-row .bp { color: #a8d070; min-width: 34px; text-align: right; }
.bal-row .bc { color: #e8946a; min-width: 34px; text-align: right; }
.bal-row .bs { color: var(--text-dim); min-width: 28px; text-align: right; }
.bal-row .bd { background: #6a2018; color: #f0a070; border-radius: 2px; padding: 0 4px; font-size: 11px; }
.bal-row.def { background: rgba(106,32,24,0.25); }

#guide { position: absolute; inset: 0; z-index: 6; background: rgba(0,0,0,0.55); display: flex; align-items: center; justify-content: center; }
#guide.hidden { display: none; }
.g-box { width: min(620px, 94%); height: min(560px, 88%); display: flex; flex-direction: column; padding: 10px 12px;
  background: linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.5)), var(--wood-tex), #2a1e14; border: 2px solid #0a0705; box-shadow: inset 0 0 0 1px var(--line-hi), 0 10px 40px #000; }
.g-head { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.g-head b { color: var(--gold-hi); font-size: 17px; }
#g-q { flex: 1; min-width: 0; padding: 6px 8px; font: inherit; font-size: 14px; background: #1a130d; color: var(--text); border: 1px solid var(--line-hi); border-radius: 3px; user-select: text; }
#g-x { padding: 4px 10px; }
#g-cats { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 8px; }
#g-cats button { padding: 4px 9px; font-size: 13px; }
#g-cats button.on { background: #5a3e22; color: var(--gold-hi); box-shadow: inset 0 0 0 1px var(--gold); }
#g-list { flex: 1; overflow-y: auto; -webkit-overflow-scrolling: touch; }
.g-card { border-bottom: 1px solid rgba(90,65,40,0.6); cursor: pointer; }
.g-t { display: flex; align-items: center; gap: 8px; padding: 6px 4px; min-height: 40px; }
.g-t img { width: 32px; height: 32px; object-fit: contain; flex: none; }
.g-t span { color: var(--text); font-size: 14px; }
.g-t i { margin-left: auto; font-style: normal; color: var(--text-dim); font-size: 11.5px; }
.g-dot { width: 8px; height: 8px; background: var(--gold); border-radius: 50%; margin: 0 12px; flex: none; }
.g-b { display: none; padding: 0 6px 8px 44px; font-size: 13px; line-height: 1.45; color: var(--text-dim); }
.g-card.open .g-b { display: block; }
.g-card.open .g-t span { color: var(--gold-hi); }
.g-b p { margin: 3px 0; }
.g-b .gk { color: var(--text); }
.g-b .g-s { color: #c8a870; font-style: italic; }

#hint { position: absolute; left: 50%; bottom: 14px; transform: translateX(-50%); z-index: 4; width: min(400px, calc(100% - 24px));
  display: flex; flex-wrap: wrap; gap: 8px; align-items: center; padding: 8px 10px; font-size: 12.5px; line-height: 1.4;
  background: linear-gradient(rgba(0,0,0,0.35), rgba(0,0,0,0.55)), var(--wood-tex), #3a2a1a; border: 2px solid #0a0705; box-shadow: inset 0 0 0 1px var(--line-hi), 0 6px 18px rgba(0,0,0,0.7);
  animation: hint-in 0.35s ease-out both; }
#hint.hidden { display: none; }
#hint img { width: 28px; height: 28px; flex: none; }
#hint .h-t { flex: 1; min-width: 0; }
#hint .h-b { width: 100%; display: flex; gap: 6px; justify-content: flex-end; }
#hint .h-b button { padding: 3px 12px; font-size: 12.5px; min-height: 28px; }
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, 8px); } to { opacity: 1; transform: translate(-50%, 0); } }
body.mobile #hint { bottom: calc(114px + env(safe-area-inset-bottom)); }
body.mobile.sheet-tab #hint, body.mobile.sheet-info #hint { display: none; }
body.mobile .g-box { width: 98%; height: 92%; }
body.mobile .g-t { min-height: 46px; }
body.mobile #g-q { font-size: 16px; }
/* выбор сложности в меню «Новая игра» */
.sm-title { width: 100%; flex: none; text-align: center; color: #f0c880; font-size: 17px; letter-spacing: 0.06em; text-shadow: 0 2px 0 #1a1008; }
.sm-panel[data-panel="diff"] .sm-btn small { white-space: normal; text-align: center; line-height: 1.25; }
.sm-btn[data-diff="calm"] { border-color: #7ab85a; }
.sm-btn[data-diff="survival"] { border-color: #c4504a; }
@media (min-width: 700px) and (min-height: 521px) {
  .sm-panel[data-panel="diff"] { flex-direction: row; flex-wrap: wrap; width: min(94vw, 980px); }
  .sm-panel[data-panel="diff"] .sm-btn { flex: 1 1 0; }
}
@media (max-height: 520px) { .sm-panel[data-panel="diff"] .sm-btn small { display: block; font-size: 10px; } }
.diff-chip { display: inline-block; padding: 1px 8px; border-radius: 9px; font-size: 12px; color: #1a1008; font-weight: bold; }

/* Выбор карты в «Новой игре» */
.sm-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.sm-sizes { grid-template-columns: repeat(3, 1fr); }
.sm-chip { padding: 6px 8px; min-width: 0; }
.sm-chip b { font-size: 15px; }
.sm-sizes .sm-chip small { font-size: 10px; }
.sm-seedrow { display: flex; gap: 8px; }
.sm-seedrow input { flex: 1; min-width: 0; }
.sm-dice { flex: 0 0 auto; min-height: 0; padding: 4px 12px; }
.sm-panel[data-panel="map"] { width: min(94vw, 460px); }
@media (max-height: 520px) { .sm-panel[data-panel="map"] .sm-chip small { display: none; } .sm-panel[data-panel="map"] { gap: 6px; } }
.sm-panel[data-panel="map"] .sm-msg { min-height: 2.4em; }
.sm-btn.sm-sel { filter: brightness(1.2); border-color: #f0c860; box-shadow: 0 3px 0 #1a1008, 0 0 16px rgba(255,200,80,0.55); }

/* карта на телефоне: по ▦ открывается крупнее, а ⤢ разворачивает её почти на весь экран */
body.mobile.show-mm #minimap { width: 100%; }
body.mobile.show-mm .mm-wrap { z-index: 30; }   /* выше панели целей (z 20), иначе карту не видно */
body.mobile #mm-size { min-width: 34px; min-height: 30px; font-size: 16px; top: 4px; right: 4px; opacity: 0.95; }
body.mobile.show-mm.mm-big .mm-wrap { left: 50%; right: auto; transform: translateX(-50%); width: min(96vw, calc((100dvh - 230px) * 4 / 3)); }

/* телефон: подтверждение «Взять в команду?» — сверху, кнопки разнесены */
.team-ask {
  position: fixed; top: calc(64px + env(safe-area-inset-top)); left: 50%; transform: translateX(-50%); z-index: 40;
  display: flex; align-items: center; gap: 22px; padding: 8px 10px 8px 12px; max-width: calc(100% - 16px);
  background: var(--planks); border: 2px solid #0a0705; box-shadow: inset 0 0 0 1px var(--line-hi), 0 3px 8px rgba(0,0,0,0.6);
  font-size: 14px;
}
.team-ask button { min-width: 44px; min-height: 40px; font-size: 20px; }

/* меню игры: четыре кнопки, группы раскрываются плавно (js/menugroups.js) */
.mg.hidden { display: none; }
.mg-h { width: 100%; }
.mg-h .mg-n { margin-left: auto; min-width: 20px; padding: 0 5px; font-size: 11px; color: var(--text-dim); border: 1px solid var(--line); border-radius: 9px; }
.mg-h .mg-arr { margin-left: 6px; transition: transform .3s cubic-bezier(.22, .9, .26, 1); }
.mg.open > .mg-h { background: linear-gradient(#7a5a2c, #4e3816); box-shadow: inset 0 0 0 1px var(--gold), inset 0 1px 0 rgba(255,240,180,0.4); color: #fff6dc; }
.mg.open .mg-arr { transform: rotate(90deg); }
.mg-wrap { display: grid; grid-template-rows: 0fr; transition: grid-template-rows .32s cubic-bezier(.22, .9, .26, 1); }
.mg.open .mg-wrap { grid-template-rows: 1fr; }
.mg-body { min-height: 0; overflow: hidden; display: grid; gap: 4px; padding-left: 12px; opacity: 0; transform: translateY(-6px); transition: opacity .25s ease, transform .32s cubic-bezier(.22, .9, .26, 1); }
.mg.open .mg-body { opacity: 1; transform: none; padding-top: 4px; padding-bottom: 2px; }
.mg-body button { font-size: 13px; }
@media (prefers-reduced-motion: reduce) { .mg-wrap, .mg-body, .mg-arr { transition: none; } }
/* «Графика» больше не показывается: на слабых телефонах экономный режим включается сам */
#eco-btn { display: none !important; }
/* стартовое меню: «Продолжить», «Новая игра», «Мультиплеер» и «Ещё»; остальное — после «Ещё» (js/startmenu.js) */
.sm-panel[data-panel="main"]:not(.sm-more) > .sm-btn:not([data-sm="continue"]):not([data-sm="new"]):not([data-sm="mp"]):not([data-sm="more"]),
.sm-panel[data-panel="main"].sm-more > .sm-btn:is([data-sm="continue"], [data-sm="new"], [data-sm="mp"]) { display: none; }
