/* Стрекозиная Военная Операция — оформление: тёмное дерево, золочёные рамки, пергамент.
 * Только свои рисунки (CSS и встроенные SVG), без эмодзи и чужой графики.
 */
:root {
  --wood1: #4a321c;
  --wood2: #2a1b0e;
  --wood3: #170e06;
  --gold1: #f0d488;
  --gold2: #c49a48;
  --gold3: #7a5622;
  --parch1: #f4e9cc;
  --parch2: #e1cd9f;
  --parch3: #c9b07a;
  --ink: #2a1c0c;
  --ink2: #5e4a2c;
  --good: #2f7d32;
  --bad: #a3281a;
  --warn: #9a6a00;
  --side-w: 262px;
  --top-h: 36px;
  --serif: Georgia, 'PT Serif', 'Times New Roman', serif;
  --sans: Tahoma, Verdana, 'Segoe UI', sans-serif;
  --woodbg: repeating-linear-gradient(92deg, rgba(255, 220, 160, 0.035) 0 2px, rgba(0, 0, 0, 0.05) 2px 5px, rgba(255, 220, 160, 0.02) 5px 9px),
            linear-gradient(180deg, var(--wood1), var(--wood2));
  --parchbg: radial-gradient(ellipse at 50% 40%, var(--parch1) 0%, var(--parch2) 75%, var(--parch3) 100%);
  --corner: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24'%3E%3Cpath d='M2 22V6a4 4 0 0 1 4-4h16' fill='none' stroke='%23f0d488' stroke-width='2'/%3E%3Cpath d='M6 22V10a4 4 0 0 1 4-4h12' fill='none' stroke='%237a5622' stroke-width='1.2'/%3E%3Ccircle cx='6' cy='6' r='2.6' fill='%23c49a48' stroke='%237a5622'/%3E%3C/svg%3E");
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--wood3); color: var(--ink); font: 12px var(--sans); overflow: hidden; -webkit-user-select: none; user-select: none; -webkit-tap-highlight-color: transparent; }
button, input, select { font: inherit; }
.ico { width: 16px; height: 16px; vertical-align: -3px; flex: none; }
.bad { color: var(--bad); }
.good { color: var(--good); }
.dim { color: var(--ink2); }
.nowrap { white-space: nowrap; }

/* ---------- Рамки ---------- */
.gold-frame { border: 2px solid var(--gold2); box-shadow: 0 0 0 1px #000, inset 0 0 0 1px var(--gold3), inset 0 0 0 2px rgba(255, 230, 160, 0.25); }

/* ---------- Окна ---------- */
.kwin { position: relative; background: var(--woodbg); border: 2px solid var(--gold2); padding: 4px; box-shadow: 0 0 0 1px #000, inset 0 0 0 1px var(--gold3), 3px 6px 22px rgba(0, 0, 0, 0.6); }
.kwin::before, .kwin::after { content: ''; position: absolute; width: 22px; height: 22px; background: var(--corner) no-repeat center / contain; pointer-events: none; z-index: 2; }
.kwin::before { left: -3px; top: -3px; }
.kwin::after { right: -3px; bottom: -3px; transform: rotate(180deg); }
.ktitle { display: flex; align-items: center; gap: 8px; min-height: 30px; padding: 2px 6px 4px 14px; color: var(--gold1); font: bold 15px var(--serif); letter-spacing: 0.3px; text-shadow: 0 1px 0 #000, 0 0 6px rgba(0, 0, 0, 0.6); cursor: default; touch-action: none; }
.kt-ic .ico { width: 18px; height: 18px; }
.kt-tx { flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.kclose { width: 24px; height: 24px; flex: none; border-radius: 50%; border: 1px solid #3a0a04; padding: 0; cursor: pointer; color: #ffd9c0; font: bold 14px/20px var(--sans);
  background: radial-gradient(circle at 38% 32%, #e0533a, #9c2414 60%, #5e1008); box-shadow: inset 0 0 0 2px rgba(255, 200, 160, 0.25), 0 1px 2px #000; }
.kclose:hover { filter: brightness(1.15); }
.kbody { background: var(--parchbg); border: 1px solid var(--gold3); box-shadow: inset 0 0 18px rgba(110, 70, 20, 0.35); padding: 10px 12px; max-height: calc(100dvh - 110px); overflow: auto; -webkit-user-select: text; user-select: text; color: var(--ink); }
.kwin.float { position: fixed; z-index: 60; }
.kbtn { display: inline-flex; align-items: center; justify-content: center; gap: 5px; min-height: 26px; padding: 2px 12px; cursor: pointer; color: var(--gold1); font: bold 12px var(--serif); text-shadow: 0 1px 0 #000;
  background: linear-gradient(180deg, #6a4826, #3e2812 55%, #2c1c0c); border: 1px solid var(--gold2); border-radius: 2px; box-shadow: 0 0 0 1px #000, inset 0 1px 0 rgba(255, 220, 150, 0.25); }
.kbtn:hover:not(:disabled) { filter: brightness(1.18); }
.kbtn:active:not(:disabled) { background: linear-gradient(180deg, #2c1c0c, #4a321a); }
.kbtn:disabled { color: #9a8a6a; border-color: #6a5a3a; cursor: default; filter: saturate(0.4); }
.kbtn.big { font-size: 15px; padding: 6px 26px; min-height: 34px; }
.kbtn.small { min-height: 22px; padding: 1px 8px; font-size: 11px; }
.kbtn.on { box-shadow: 0 0 0 1px #000, inset 0 0 0 2px var(--gold1); color: #fff; }
.kbtn .ico { width: 14px; height: 14px; }
.btnrow { display: flex; flex-wrap: wrap; gap: 6px; margin: 6px 0; align-items: center; }
.btnrow.right { justify-content: flex-end; }
.btnrow.col { flex-direction: column; align-items: stretch; }
.note { color: var(--ink); line-height: 1.5; margin: 0 0 8px; }
fieldset { border: 1px solid var(--parch3); border-radius: 2px; margin: 0 0 10px; padding: 8px 10px; background: rgba(255, 250, 230, 0.25); }
legend { color: var(--bad); padding: 0 6px; font: bold 13px var(--serif); }
.ktable { width: 100%; border-collapse: collapse; background: rgba(255, 252, 238, 0.45); border: 1px solid var(--parch3); }
.ktable th { text-align: left; font: bold 12px var(--serif); color: var(--ink2); border-bottom: 1px solid var(--parch3); padding: 4px 6px; }
.ktable td { padding: 4px 6px; border-bottom: 1px solid rgba(160, 130, 80, 0.3); vertical-align: middle; }
.ktable td .kbtn { margin: 1px 2px; }
.sw { display: inline-block; width: 12px; height: 12px; border: 1px solid #000; vertical-align: -2px; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35); }
.rel-war { color: var(--bad); font-weight: bold; }
.rel-pact { color: var(--good); font-weight: bold; }
.rel-breaking { color: var(--warn); font-weight: bold; }
.rel-self { color: var(--ink2); }
.form label { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin: 5px 0; }
.form select, .form input { width: 170px; }
input[type=number], input:not([type]), select { border: 1px solid var(--gold3); padding: 3px 5px; background: #fffaf0; color: var(--ink); border-radius: 1px; }

/* ---------- Экран «Новая колония» ---------- */
.startwin { position: fixed; left: 50%; top: 50%; transform: translate(-50%, -50%); width: min(860px, calc(100vw - 16px)); max-height: calc(100dvh - 16px); display: flex; flex-direction: column; }
body { background: radial-gradient(ellipse at 50% 30%, #3a2a18, #120a04 75%); }
.startwin .kbody { overflow: auto; max-height: none; }
.start-head { display: flex; gap: 14px; align-items: center; margin-bottom: 10px; }
.logo-frame { flex: none; width: 84px; height: 84px; padding: 4px; background: var(--parchbg); border: 2px solid var(--gold2); box-shadow: 0 0 0 1px #000, inset 0 0 0 1px var(--gold3); }
.logo-frame canvas { width: 72px; height: 72px; display: block; }
.start-head h1 { font: bold 22px var(--serif); margin: 0 0 4px; color: var(--bad); }
.start-head p { margin: 0; color: var(--ink); line-height: 1.45; }
.fcards { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.fcard { display: flex; gap: 10px; align-items: flex-start; text-align: left; padding: 6px; border: 1px solid var(--parch3); background: rgba(255, 252, 238, 0.55); cursor: pointer; color: var(--ink); }
.fcard canvas { width: 72px; height: 72px; flex: none; background: radial-gradient(circle, #f6edd4, #d8c391); border: 1px solid var(--gold3); }
.fcard b { display: block; font: bold 14px var(--serif); color: var(--ink); }
.fcard .proto { display: block; color: var(--ink2); font-size: 11px; margin-bottom: 2px; font-style: italic; }
.fcard .fdesc { display: block; font-size: 11px; line-height: 1.35; }
.fcard:hover { background: rgba(255, 252, 238, 0.8); }
.fcard.on { border-color: var(--gold3); box-shadow: 0 0 0 2px var(--gold2), inset 0 0 12px rgba(196, 154, 72, 0.4); background: #fff8e2; }
.sgrid { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 12px; }
.sgrid label { display: flex; flex-direction: column; gap: 2px; color: var(--ink2); }
.seedrow { display: flex; gap: 4px; }
.seedrow input { width: 100%; }
.chkrow { display: flex; flex-wrap: wrap; gap: 4px 18px; margin-top: 8px; }
.chk { display: flex; gap: 6px; align-items: center; }
.loadnote { margin-right: auto; color: var(--ink2); font-style: italic; }

/* ---------- Игра ---------- */
#game { position: fixed; inset: 0; flex-direction: column; background: var(--wood3); }
.topbar { flex: none; display: flex; align-items: stretch; gap: 6px; height: calc(var(--top-h) + env(safe-area-inset-top)); padding: env(safe-area-inset-top) 6px 0 4px; background: var(--woodbg); border-bottom: 2px solid var(--gold2); box-shadow: 0 1px 0 #000, inset 0 -1px 0 var(--gold3); position: relative; z-index: 3; }
.resbar { flex: 1; min-width: 0; display: flex; align-items: center; gap: 2px; overflow-x: auto; scrollbar-width: none; }
.resbar::-webkit-scrollbar { display: none; }
.res { display: flex; align-items: center; gap: 4px; height: 28px; padding: 0 8px 0 3px; white-space: nowrap; color: var(--parch1); text-shadow: 0 1px 0 #000; border-right: 1px solid rgba(240, 212, 136, 0.18); }
.res .medal { display: flex; align-items: center; justify-content: center; width: 24px; height: 24px; border-radius: 50%; background: radial-gradient(circle at 40% 35%, #f6ecd0, #cdb47c 70%, #8a6a30); border: 1px solid var(--gold3); box-shadow: 0 0 0 1px #000; }
.res .medal .ico { width: 16px; height: 16px; }
.res.shield { padding-left: 8px; color: #a8e6a0; }
.res b { font: bold 13px var(--serif); min-width: 34px; color: var(--gold1); }
.res i { font-style: normal; font-size: 11px; color: #d9c79a; }
.res.minus i, .res.minus b { color: #ff8a6a; }
.res.bad b { color: #ff6a50; animation: blink 1s infinite; }
.res.btn { cursor: pointer; }
.res.btn:hover { background: rgba(240, 212, 136, 0.12); }
.res.wallet { border-right: none; }
@keyframes blink { 50% { opacity: 0.45; } }
.tb-btns { flex: none; display: flex; gap: 3px; align-items: center; }
.tbb { height: 26px; min-width: 30px; padding: 0 6px; display: inline-flex; align-items: center; justify-content: center; gap: 4px; cursor: pointer; color: var(--gold1); font: bold 12px var(--serif); text-shadow: 0 1px 0 #000;
  background: linear-gradient(180deg, #6a4826, #3a2410); border: 1px solid var(--gold2); box-shadow: 0 0 0 1px #000, inset 0 1px 0 rgba(255, 220, 150, 0.25); border-radius: 2px; }
.tbb .ico { width: 16px; height: 16px; filter: drop-shadow(0 1px 0 #000); }
.tbb:hover { filter: brightness(1.2); }
.tbb.wide { padding: 0 12px; }
.main { flex: 1; min-height: 0; display: flex; }
.view { position: relative; flex: 1; min-width: 0; min-height: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: default; }

/* нижняя панель (как на образце владельца): слева две рамки — портрет и кнопки, над ними название и строка подсказки; справа — мини-карта */
.hud { position: absolute; left: 0; right: 0; bottom: 0; display: flex; align-items: flex-end; justify-content: space-between; gap: 8px;
  padding: 0 calc(6px + env(safe-area-inset-right)) calc(6px + env(safe-area-inset-bottom)) calc(6px + env(safe-area-inset-left)); pointer-events: none; z-index: 3; }
.hud > * { pointer-events: auto; }
.hud-left { display: flex; flex-direction: column; gap: 0; min-width: 0; max-width: calc(100% - 262px); }
.hud-top { display: flex; align-items: flex-end; gap: 8px; min-height: 26px; }
.hud-name { padding: 3px 14px 2px; background: var(--woodbg); border: 2px solid var(--gold2); border-bottom: none; color: var(--gold1); font: bold 14px var(--serif); text-shadow: 0 1px 0 #000;
  box-shadow: 0 0 0 1px #000; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 100%; visibility: hidden; }
.hud-name .hn-sub { font: italic 11px var(--serif); color: #d9c79a; margin-left: 6px; }
.hud-name .hn-cnt { color: #fff; }
.hud-q { display: flex; flex-wrap: nowrap; gap: 2px; margin-bottom: 2px; overflow: hidden; }
.hud-row { display: flex; gap: 6px; align-items: stretch; }
.hud-frame { position: relative; background: var(--woodbg); border: 2px solid var(--gold2); padding: 4px; box-shadow: 0 0 0 1px #000, inset 0 0 0 1px var(--gold3), 2px 3px 10px rgba(0, 0, 0, 0.5); }
.hud-frame::before, .hud-frame::after { content: ''; position: absolute; width: 18px; height: 18px; background: var(--corner) no-repeat center / contain; pointer-events: none; z-index: 2; }
.hud-frame::before { left: -4px; top: -4px; }
.hud-frame::after { right: -4px; bottom: -4px; transform: rotate(180deg); }
.hud-port { flex: none; width: 232px; height: 152px; overflow: hidden; background: var(--parchbg); color: var(--ink); padding: 5px; scrollbar-width: thin; }
.hud-cmdbox { flex: 0 1 auto; min-width: 0; height: 152px; display: flex; flex-direction: column; gap: 3px; }
.hud-tip { flex: none; height: 36px; overflow: hidden; background: var(--parchbg); border: 1px solid var(--gold3); padding: 2px 6px; font-size: 11px; line-height: 15px; color: var(--ink); }
.hud-tip .tl { display: flex; align-items: center; gap: 8px; white-space: nowrap; overflow: hidden; }
.hud-tip b { font: bold 12px var(--serif); }
.hud-tip .cs { display: inline-flex; gap: 2px 7px; }
.hud-tip .cs .c { display: inline-flex; align-items: center; gap: 2px; font-weight: bold; }
.hud-tip .cs .c.no { color: var(--bad); }
.hud-tip .cs .ico { width: 13px; height: 13px; }
.hud-tip .why { color: var(--bad); font-weight: bold; }
.hud-tip .ds { color: var(--ink2); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.hud-right { flex: none; }
.mini-frame { width: 248px; height: 176px; padding: 3px; background: #050403; border: 2px solid var(--gold2); box-shadow: 0 0 0 1px #000, inset 0 0 0 1px var(--gold3), 2px 3px 10px rgba(0, 0, 0, 0.5); position: relative; }
.mini-frame::before, .mini-frame::after { content: ''; position: absolute; width: 18px; height: 18px; background: var(--corner) no-repeat center / contain; pointer-events: none; }
.mini-frame::before { left: -4px; top: -4px; }
.mini-frame::after { right: -4px; bottom: -4px; transform: rotate(180deg); }
#mini { width: 100%; height: 100%; display: block; touch-action: none; cursor: crosshair; }
.selinfo { }
.hp-row { display: flex; gap: 6px; align-items: flex-start; }
.hp-col { flex: 1; min-width: 0; }
.hp-num { display: flex; align-items: center; gap: 3px; font: bold 11px var(--serif); color: var(--ink); }
.hp-num .ico { width: 12px; height: 12px; }
.hs { display: grid; grid-template-columns: 1fr 1fr; gap: 1px 6px; margin-top: 3px; font-size: 11px; }
.hs span { display: flex; align-items: center; gap: 3px; white-space: nowrap; overflow: hidden; }
.hs .ico { width: 14px; height: 14px; }
.hs b { font: bold 11px var(--serif); }
.hs b.up, .up { color: #8fe36a; }
.si-head { display: flex; gap: 8px; align-items: center; }
.si-port { flex: none; padding: 2px; background: radial-gradient(circle, #fbf4e0, #d9c493); border: 2px solid var(--gold2); box-shadow: 0 0 0 1px var(--gold3); }
.si-port canvas { display: block; }
.si-txt { flex: 1; min-width: 0; }
.si-name { font: bold 13px var(--serif); color: var(--ink); line-height: 1.2; }
.si-cls { color: var(--ink2); font-size: 11px; font-style: italic; }
.si-stats { display: grid; grid-template-columns: 1fr 1fr; gap: 1px 8px; margin-top: 5px; font-size: 11px; }
.si-stats span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.si-stats em { font-style: normal; color: var(--ink2); }
.si-lines { margin-top: 4px; font-size: 11px; line-height: 1.4; color: var(--ink); }
.si-lines .ico { width: 13px; height: 13px; }
.si-empty { color: var(--ink2); font-size: 11px; line-height: 1.5; font-style: italic; }
.si-grid { display: flex; flex-wrap: wrap; gap: 3px; }
.si-cell { position: relative; padding: 1px; border: 1px solid var(--gold3); background: rgba(255, 252, 238, 0.6); cursor: pointer; }
.si-cell span { position: absolute; right: 1px; bottom: -1px; font: bold 11px var(--serif); color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000, 0 0 2px #000; }
.si-queue { display: flex; flex-wrap: nowrap; gap: 2px; }
.q-cell { position: relative; padding: 1px; border: 1px solid var(--gold3); background: rgba(255, 252, 238, 0.85); cursor: pointer; overflow: hidden; box-shadow: 0 0 0 1px #000; }
.q-cell i { position: absolute; left: 0; bottom: 0; height: 3px; background: #2f6fdb; }
.q-cell.wait { background: #f4c8b8; }
.bar { height: 7px; background: #2a1a10; border: 1px solid #000; margin: 3px 0; min-width: 60px; box-shadow: 0 0 0 1px var(--gold3); }
.bar i { display: block; height: 100%; background: linear-gradient(180deg, #8ee07a, #2e8a2a); }
.bar i.blue { background: linear-gradient(180deg, #9fc8ff, #2f6fdb); }
.bar.red i { background: linear-gradient(180deg, #ff9a7a, #a3281a); }

/* кнопки приказов — квадратные */
.cmds { flex: 1; min-height: 0; display: grid; grid-template-columns: repeat(10, 48px); grid-auto-rows: 48px; gap: 3px; justify-content: start; align-content: start; overflow-y: auto; overflow-x: hidden; padding: 1px; scrollbar-width: thin; }
.cmd { position: relative; display: flex; flex-direction: column; align-items: center; justify-content: center; padding: 0; cursor: pointer; overflow: hidden;
  background: radial-gradient(circle at 50% 40%, #fbf3dc, #dcc591 70%, #b8995c); border: 2px solid var(--gold2); box-shadow: 0 0 0 1px #000, inset 0 0 0 1px rgba(255, 245, 210, 0.7), inset 0 -6px 10px rgba(120, 80, 30, 0.25); }
.cmd:hover { box-shadow: 0 0 0 1px #000, 0 0 8px rgba(240, 212, 136, 0.8), inset 0 0 0 1px #fff; border-color: var(--gold1); }
.cmd:active { transform: translateY(1px); }
.cmd.on { box-shadow: 0 0 0 1px #000, inset 0 0 0 2px #2f7d32, inset 0 0 12px rgba(47, 125, 50, 0.45); }
.cmd.off { filter: grayscale(0.85) brightness(0.72); }
.cmd .ic { display: flex; }
.cmd .ic .ico { width: 28px; height: 28px; }
.cmd canvas { display: block; }
.cmd .lb { display: none; }
.cmd .hk { position: absolute; right: 2px; top: 0; font: bold 10px var(--serif); color: var(--ink2); text-shadow: 0 0 2px #fff; }
.cmd .x5 { font: bold 15px var(--serif); color: var(--bad); }
.cmd .cnt { position: absolute; left: 2px; bottom: 0; font: bold 11px var(--serif); color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000; }
.q-cell .qn { position: absolute; right: 1px; top: 0; font: bold 10px var(--serif); color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000; }
.cmd .rom { position: absolute; right: 2px; bottom: 0; font: bold 12px var(--serif); color: #ffe27a; text-shadow: 0 0 2px #000, 0 0 2px #000, 0 0 3px #000; letter-spacing: -0.5px; }
.cmd .bic { position: absolute; left: 1px; top: 1px; display: flex; }
.cmd .bic .ico { width: 14px; height: 14px; filter: drop-shadow(0 0 1px #fff); }
.cmd canvas, .si-port canvas, .si-cell canvas, .q-cell canvas { image-rendering: pixelated; }
body.panel-min .hud-left { display: none; }
/* админка */
.atabs { display: flex; flex-wrap: wrap; gap: 4px; margin-bottom: 6px; }
.abody { max-height: min(62vh, 560px); overflow: auto; padding-right: 4px; }
.acard { border: 1px solid var(--parch3); background: rgba(255, 252, 238, 0.45); padding: 5px 6px; margin: 6px 0; }
.ahead { font: 13px var(--serif); margin-bottom: 4px; }
.arow { display: flex; flex-wrap: wrap; gap: 4px; align-items: center; margin: 4px 0; }
.arow input[type=number] { width: 66px; }
.agrid { display: grid; grid-template-columns: repeat(auto-fill, minmax(160px, 1fr)); gap: 3px 10px; margin: 6px 0; }
.afield { display: flex; justify-content: space-between; align-items: center; gap: 6px; font-size: 12px; }
.afield input[type=number] { width: 76px; }
.afield.changed span { color: var(--bad); font-weight: bold; }
#cv { image-rendering: auto; }

/* средние экраны: кнопок в ряд меньше */
@media (max-width: 1180px) {
  .cmds { grid-template-columns: repeat(auto-fill, 46px); grid-auto-rows: 46px; }
  .hud-cmdbox { width: calc(100vw - 262px - 232px - 30px); }
}
@media (max-width: 900px) {
  .mini-frame { width: 190px; height: 136px; }
  .hud-left { max-width: calc(100% - 204px); }
  .hud-port { width: 196px; }
  .hud-cmdbox { width: calc(100vw - 204px - 196px - 30px); }
}

/* генерал — табличка в углу поля */
.genchip { position: absolute; left: 8px; top: 8px; display: flex; gap: 6px; align-items: center; padding: 4px 8px 4px 4px; min-width: 196px; cursor: pointer; z-index: 2;
  background: var(--parchbg); border: 2px solid var(--gold2); box-shadow: 0 0 0 1px #000, 2px 3px 8px rgba(0, 0, 0, 0.5); }
.genchip.dead { background: radial-gradient(ellipse at 50% 40%, #f6d6c8, #d8a08a); }
.gc-port { flex: none; border: 1px solid var(--gold3); background: radial-gradient(circle, #fbf4e0, #d9c493); }
.gc-port canvas { width: 42px; height: 42px; display: block; }
.gc-name { font: bold 13px var(--serif); }
.gc-sub { font-size: 11px; color: var(--ink2); }
.gc-body .kbtn { margin-top: 3px; }
.modehint { position: absolute; left: 50%; top: 8px; transform: translateX(-50%); display: none; padding: 5px 14px; color: var(--gold1); max-width: calc(100% - 240px); z-index: 2;
  background: rgba(30, 18, 8, 0.9); border: 1px solid var(--gold2); box-shadow: 0 0 0 1px #000; font: bold 13px var(--serif); text-align: center; pointer-events: none; text-shadow: 0 1px 0 #000; }
.toasts { position: absolute; left: 50%; top: 46px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 4px; align-items: center; pointer-events: none; width: min(560px, calc(100% - 20px)); z-index: 5; }
.toast { padding: 5px 14px; background: var(--parchbg); border: 1px solid var(--gold3); border-left: 4px solid var(--gold2); box-shadow: 0 0 0 1px #000, 2px 3px 8px rgba(0, 0, 0, 0.45); transition: opacity 0.5s, transform 0.5s; text-align: center; color: var(--ink); }
.toast.warn { border-left-color: #c08a00; }
.toast.bad { border-left-color: var(--bad); color: #6a1408; font-weight: bold; }
.toast.event { border-left-color: #2f6fdb; font-weight: bold; }
.toast.out { opacity: 0; transform: translateY(-6px); }
/* ---------- Телефон: панель приказов, отряды, тревога (0.4.39) ---------- */
.touchbar { position: absolute; right: calc(8px + env(safe-area-inset-right)); top: 8px; display: none; flex-direction: column; gap: 5px; z-index: 2; touch-action: manipulation; }
.touchbar button { display: flex; align-items: center; gap: 5px; min-width: 76px; height: 40px; padding: 0 8px 0 5px; color: var(--gold1); font: bold 12px var(--serif); text-shadow: 0 1px 0 #000;
  background: linear-gradient(180deg, #6a4826, #3a2410); border: 1px solid var(--gold2); border-radius: 3px; box-shadow: 0 0 0 1px #000, 1px 2px 4px rgba(0, 0, 0, 0.4); -webkit-tap-highlight-color: transparent; transition: transform 0.08s, filter 0.15s, opacity 0.2s; }
.touchbar button .ico { width: 22px; height: 22px; flex: none; }
.touchbar button:active { transform: scale(0.94); filter: brightness(1.25); }
.touchbar button.on { box-shadow: 0 0 0 1px #000, inset 0 0 0 2px var(--gold1), 0 0 10px rgba(240, 212, 136, 0.55); color: #fff; }
.touchbar button.need-sel { opacity: 0.45; }
body.has-sel .touchbar button.need-sel { opacity: 1; }
body.touch .touchbar { display: flex; }
.tgroups { position: absolute; left: calc(8px + env(safe-area-inset-left)); top: 56px; display: none; gap: 5px; z-index: 2; touch-action: manipulation; }
body.touch .tgroups { display: flex; }
.tg { position: relative; width: 40px; height: 40px; display: flex; align-items: center; justify-content: center; color: var(--gold1); font: bold 17px var(--serif); text-shadow: 0 1px 0 #000;
  background: linear-gradient(180deg, #5a3c1e, #2e1d0c); border: 1px solid var(--gold3); border-radius: 3px; box-shadow: 0 0 0 1px #000; opacity: 0.55; -webkit-tap-highlight-color: transparent; transition: transform 0.08s, opacity 0.2s; }
.tg.set { opacity: 1; border-color: var(--gold2); }
.tg.cur { box-shadow: 0 0 0 1px #000, inset 0 0 0 2px var(--gold1); color: #fff; }
.tg:active { transform: scale(0.92); }
.tg i { position: absolute; right: 2px; bottom: 0; font: bold 10px var(--serif); font-style: normal; color: #fff; text-shadow: 0 0 2px #000, 0 0 2px #000; }
.tg.saved { animation: sdo-tg-saved 0.6s ease-out; }
@keyframes sdo-tg-saved { 0% { box-shadow: 0 0 0 1px #000, 0 0 0 0 rgba(240, 212, 136, 0.9); } 100% { box-shadow: 0 0 0 1px #000, 0 0 0 14px rgba(240, 212, 136, 0); } }
.alertbar { position: absolute; left: 50%; top: 8px; z-index: 6; display: none; align-items: center; gap: 10px; width: min(520px, calc(100% - 20px)); padding: 7px 8px 7px 10px;
  transform: translate(-50%, -8px); opacity: 0; color: #fff3e0; background: linear-gradient(180deg, rgba(122, 22, 10, 0.97), rgba(70, 10, 4, 0.97)); border: 2px solid #e0a040;
  box-shadow: 0 0 0 1px #000, 0 6px 24px rgba(0, 0, 0, 0.6), 0 0 22px rgba(255, 70, 40, 0.35); transition: transform 0.25s ease-out, opacity 0.25s; }
.alertbar.show { display: flex; }
.alertbar.in { transform: translate(-50%, 0); opacity: 1; }
.alertbar.calm { background: linear-gradient(180deg, rgba(30, 62, 26, 0.97), rgba(14, 34, 12, 0.97)); border-color: var(--gold2); box-shadow: 0 0 0 1px #000, 0 6px 24px rgba(0, 0, 0, 0.6); }
.alertbar.attack { animation: sdo-alarm 1.1s ease-in-out 3; }
@keyframes sdo-alarm { 50% { box-shadow: 0 0 0 1px #000, 0 6px 24px rgba(0, 0, 0, 0.6), 0 0 34px rgba(255, 70, 40, 0.85); } }
.ab-ico { flex: none; width: 30px; height: 30px; display: flex; align-items: center; justify-content: center; }
.ab-ico .ico { width: 28px; height: 28px; }
.ab-text { flex: 1; min-width: 0; line-height: 1.25; }
.ab-text b { display: block; font: bold 14px var(--serif); text-shadow: 0 1px 0 #000; }
.ab-text span { display: block; font-size: 11px; color: #f2d7b0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ab-x { flex: none; width: 30px; height: 30px; color: #f2d7b0; font: bold 20px/1 var(--serif); background: none; border: 0; cursor: pointer; }
@media (max-height: 560px) and (orientation: landscape) {
  .touchbar { display: none; flex-direction: row; flex-wrap: wrap; width: 92px; gap: 4px; top: 6px; }
  body.touch .touchbar { display: flex; }
  .touchbar button { min-width: 0; width: 44px; height: 40px; padding: 0; justify-content: center; font-size: 0; }
  .touchbar button .ico { width: 24px; height: 24px; }
  .tgroups { top: 48px; }
  .tg { width: 36px; height: 36px; font-size: 15px; }
  .alertbar { width: min(480px, calc(100% - 250px)); padding: 4px 6px; }
}
@media (max-width: 760px) and (orientation: portrait) {
  .touchbar button { min-width: 0; width: 46px; height: 42px; padding: 0; justify-content: center; font-size: 0; }
  .touchbar button .ico { width: 24px; height: 24px; }
  .toasts { top: 104px; }
  .alertbar { left: calc(50% - 30px); width: calc(100% - 80px); padding: 5px 4px 5px 6px; gap: 6px; }
  .alertbar .kbtn { padding: 2px 7px; }
  .ab-text b { font-size: 13px; }
}

.wallet-big { font: bold 15px var(--serif); padding: 6px 10px; margin-bottom: 8px; background: rgba(255, 248, 220, 0.7); border: 1px solid var(--gold2); display: flex; gap: 6px; align-items: center; }
.wallet-big .ico { width: 20px; height: 20px; }
.logbox { max-height: 50vh; overflow: auto; background: rgba(255, 252, 238, 0.5); border: 1px solid var(--parch3); padding: 4px 6px; font-size: 11px; line-height: 1.5; }
.log-bad { color: var(--bad); }
.log-warn { color: #7a5000; }
.log-event { color: #1a3a7a; font-weight: bold; }
.help h4 { margin: 10px 0 3px; font: bold 14px var(--serif); color: var(--bad); }
.help p { margin: 0; line-height: 1.5; }
.help kbd { display: inline-block; min-width: 18px; padding: 0 4px; border: 1px solid var(--gold3); background: #fff8e2; font: bold 11px var(--sans); text-align: center; border-radius: 2px; }
.dbg-stats { background: rgba(255, 252, 238, 0.6); border: 1px solid var(--parch3); padding: 5px 7px; font-size: 11px; line-height: 1.6; }
.dbg-h { margin-top: 8px; font: bold 12px var(--serif); color: var(--bad); }
#fatal { display: none; position: fixed; left: 8px; bottom: 8px; right: 8px; z-index: 999; padding: 8px; background: #ffe0d8; border: 1px solid var(--bad); color: #6a1408; font-weight: bold; }

/* ---------- Телефон стоя: кнопки снизу во всю ширину, мини-карта справа ---------- */
@media (max-width: 760px) and (orientation: portrait) {
  :root { --top-h: 32px; }
  .hud { gap: 4px; padding-left: 4px; padding-right: 4px; }
  .hud-left { max-width: calc(100% - 128px); flex: 1; }
  .hud-top { min-height: 0; }
  .hud-name { font-size: 12px; padding: 2px 8px; }
  .hud-port, .hud-tip, .hud-q { display: none; }
  .hud-cmdbox { width: auto; height: 118px; flex: 1; }
  .cmds { grid-template-columns: repeat(auto-fill, 46px); grid-auto-rows: 52px; gap: 3px; }
  .mini-frame { width: 120px; height: 92px; }
  .genchip { min-width: 0; padding: 3px 6px 3px 3px; }
  .gc-port canvas { width: 32px; height: 32px; }
  .modehint { top: auto; bottom: 150px; max-width: calc(100% - 20px); font-size: 11px; }
  .toasts { top: 58px; width: calc(100% - 16px); }
  .fcards { grid-template-columns: 1fr; }
  .sgrid { grid-template-columns: 1fr 1fr; }
  .start-head h1 { font-size: 17px; }
  .logo-frame { width: 58px; height: 58px; padding: 3px; }
  .logo-frame canvas { width: 48px; height: 48px; }
  .kbody { padding: 8px; }
}
/* ---------- Телефон лёжа: панель ниже и уже ---------- */
@media (max-height: 560px) and (orientation: landscape) {
  :root { --top-h: 30px; }
  .hud-port { width: 150px; height: 100px; }
  .hud-port .hs, .hud-port .si-lines { display: none; }
  .hud-cmdbox { height: 100px; width: calc(100vw - 150px - 140px - 40px); }
  .hud-tip { display: none; }
  .hud-left { max-width: calc(100% - 146px); }
  .cmds { grid-template-columns: repeat(auto-fill, 44px); grid-auto-rows: 46px; }
  .mini-frame { width: 136px; height: 96px; }
  .genchip { min-width: 0; padding: 2px 6px 2px 2px; }
  .gc-port canvas { width: 30px; height: 30px; }
  .toasts { top: 8px; }
  .startwin .kbody { padding: 8px; }
}
/* общее для обоих телефонных видов */
@media (max-width: 760px) and (orientation: portrait), (max-height: 560px) and (orientation: landscape) {
  .si-port canvas { width: 40px !important; height: 40px !important; }
  .cmd .ic .ico { width: 22px; height: 22px; }
  .cmd canvas { width: 30px !important; height: 30px !important; }
  .cmd .lb { display: block; max-width: 44px; font-size: 8px; line-height: 1.05; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; color: var(--ink); margin-top: 1px; }
  .cmd .hk { display: none; }
  .cmd .cnt { top: 0; bottom: auto; }
  .res { padding: 0 5px 0 2px; gap: 2px; height: 26px; }
  .res .medal { width: 20px; height: 20px; }
  .res .medal .ico { width: 13px; height: 13px; }
  .res b { min-width: 0; font-size: 12px; }
  .res i { font-size: 10px; }
  .tbb { height: 24px; min-width: 26px; padding: 0 4px; }
  .tbb.wide { padding: 0 6px; font-size: 11px; }
  .tb-btns #tb-log, .tb-btns #tb-debug, .tb-btns #tb-help { display: none; }
  .toast { font-size: 11px; padding: 4px 8px; }
}

/* ---------- Экран входа: фон с пыльцой и светлячками, вход в общий мир ---------- */
#entrybg { position: fixed; inset: 0; width: 100%; height: 100%; pointer-events: none; z-index: 0; }
body { background: radial-gradient(ellipse at 50% 18%, #4a3418 0%, #24170a 45%, #0c0703 85%); }
.startwin { z-index: 1; animation: sdo-rise 0.6s ease-out both; }
@keyframes sdo-rise { from { opacity: 0; transform: translate(-50%, calc(-50% + 14px)); } to { opacity: 1; transform: translate(-50%, -50%); } }
.net-only { display: none; }
body.net .net-only { display: block; }
body.net .poly-only { display: none !important; }
body.net .startwin { width: min(780px, calc(100vw - 16px)); box-shadow: 0 0 0 1px #000, inset 0 0 0 1px var(--gold3), 0 0 60px rgba(240, 190, 90, 0.18), 3px 6px 22px rgba(0, 0, 0, 0.6); }
body.net .start-head h1 { font-size: 26px; letter-spacing: 0.3px; }
body.net #s-go { font-size: 17px; padding: 8px 34px; min-height: 42px; box-shadow: 0 0 0 1px #000, 0 0 18px rgba(240, 200, 100, 0.35); }
.n-online { display: flex; align-items: center; gap: 6px; margin: 0 0 8px; color: var(--ink2); font-style: italic; }
.n-online .dot { width: 9px; height: 9px; border-radius: 50%; background: #3fa34d; box-shadow: 0 0 0 0 rgba(63, 163, 77, 0.7); animation: sdo-pulse 1.8s infinite; }
.n-online.down { color: var(--bad); }
.n-site { margin: 0 0 8px; padding: 6px 10px; border-left: 3px solid #3fa34d; color: var(--ink); }
@keyframes sdo-pulse { 70% { box-shadow: 0 0 0 7px rgba(63, 163, 77, 0); } 100% { box-shadow: 0 0 0 0 rgba(63, 163, 77, 0); } }
.n-tips { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin-bottom: 8px; }
.n-tip { padding: 6px 8px; border: 1px solid var(--parch3); border-left: 3px solid var(--gold2); background: rgba(255, 252, 238, 0.55); line-height: 1.35; font-size: 11px; }
.n-tip b { display: block; font: bold 13px var(--serif); color: var(--bad); margin-bottom: 2px; }
.n-grid { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 8px 16px; margin-bottom: 6px; }
.n-grid label { display: flex; flex-direction: column; gap: 2px; font-weight: bold; }
.n-grid input#n-name { font-size: 15px; padding: 4px 8px; min-width: 220px; }
.n-grid .chk { flex-direction: row; align-items: center; gap: 6px; font-weight: normal; }

/* заставка «Подключение к миру» */
.connecting { display: none; position: absolute; inset: 0; z-index: 8; align-items: center; justify-content: center; background: radial-gradient(ellipse at 50% 40%, rgba(58, 42, 24, 0.92), rgba(12, 7, 3, 0.97)); }
.connecting.on { display: flex; }
.cn-box { display: flex; flex-direction: column; align-items: center; gap: 12px; color: var(--gold1); font: bold 15px var(--serif); text-shadow: 0 1px 0 #000; text-align: center; padding: 0 16px; }
.cn-spin { width: 36px; height: 36px; border-radius: 50%; border: 3px solid rgba(240, 212, 136, 0.25); border-top-color: var(--gold1); animation: sdo-spin 0.9s linear infinite; }
@keyframes sdo-spin { to { transform: rotate(360deg); } }

/* ---------- Общий чат ---------- */
.tbb { position: relative; }
.tbb.on { box-shadow: inset 0 0 0 2px var(--gold1); }
.tb-badge { position: absolute; right: -4px; top: -4px; min-width: 14px; height: 14px; padding: 0 3px; border-radius: 7px; background: var(--bad); color: #fff; font: bold 9px/14px var(--sans); text-shadow: none; box-shadow: 0 0 0 1px #000; }
.chattick, .chat { position: absolute; left: calc(8px + env(safe-area-inset-left)); bottom: 196px; width: min(380px, calc(100% - 16px)); z-index: 4; }
.chattick { display: flex; flex-direction: column; gap: 2px; pointer-events: none; }
.chattick .cm { align-self: flex-start; max-width: 100%; padding: 2px 8px; background: rgba(12, 7, 3, 0.62); border-radius: 3px; transition: opacity 0.6s; }
.chattick .cm.out { opacity: 0; }
.cm { color: #f2ead4; font-size: 12px; line-height: 1.35; text-shadow: 0 1px 0 #000; word-wrap: break-word; overflow-wrap: anywhere; -webkit-user-select: text; user-select: text; }
.cm b { font-family: var(--serif); text-shadow: 0 1px 0 #000, 0 0 3px rgba(0, 0, 0, 0.8); }
.cm .ct { color: #b8a77e; font-size: 10px; margin-right: 5px; }
.cm.sys i { color: var(--gold1); }
.cm.mine { color: #fff; }
.chat { display: none; flex-direction: column; background: rgba(20, 12, 5, 0.86); border: 2px solid var(--gold2); box-shadow: 0 0 0 1px #000, inset 0 0 0 1px var(--gold3), 2px 3px 10px rgba(0, 0, 0, 0.5); }
.chat.on { display: flex; }
.chatlog { height: 180px; overflow-y: auto; padding: 4px 6px; display: flex; flex-direction: column; gap: 1px; scrollbar-width: thin; }
.chatform { display: flex; gap: 4px; padding: 4px; border-top: 1px solid var(--gold3); }
.chatform input { flex: 1; min-width: 0; font-size: 13px; padding: 3px 6px; -webkit-user-select: text; user-select: text; }
body.touch .chatform input { font-size: 16px; }
@media (max-width: 760px) and (orientation: portrait) {
  .chattick, .chat { bottom: 136px; }
  .chatlog { height: 140px; }
  .n-tips { grid-template-columns: 1fr; }
  .n-tip { padding: 4px 6px; }
  body.net .start-head h1 { font-size: 19px; }
  .n-grid input#n-name { min-width: 0; width: 100%; }
  .n-grid label:first-child { flex: 1 1 100%; }
}
@media (max-height: 560px) and (orientation: landscape) {
  .chattick, .chat { bottom: 118px; width: min(340px, calc(100% - 16px)); }
  .chatlog { height: 90px; }
  .n-tips { display: none; }
}
/* ---------- Редактор флага колонии (js/client/flag.js) ---------- */
#flag-ed { position: fixed; inset: 0; z-index: 200; display: flex; align-items: center; justify-content: center; padding: 16px; background: rgba(0, 0, 0, 0.6); }
.fe-win { max-width: 100%; }
.fe-note { margin: 0 0 8px; max-width: 420px; }
.fe-tools, .fe-row { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.fe-row { margin: 8px 0 0; justify-content: flex-end; }
.fe-cv { display: block; width: 384px; max-width: 100%; height: auto; image-rendering: pixelated; border: 2px solid var(--gold3); cursor: crosshair; touch-action: none; }
.fe-pal { display: grid; grid-template-columns: repeat(8, 1fr); gap: 4px; margin-top: 8px; max-width: 384px; }
.fe-sw { height: 26px; border: 1px solid #000; border-radius: 2px; cursor: pointer; box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.35); }
.fe-sw.on { outline: 3px solid var(--gold1); outline-offset: 1px; }
.sndrow { display: flex; align-items: center; gap: 8px; margin: 10px 0 6px; }
.sndrow input[type=range] { flex: 1; accent-color: #c8a040; }
