:root {
  --bg: #070c15;
  --panel: #0f1828;
  --panel2: #142036;
  --line: #22324d;
  --text: #e3ebf7;
  --muted: #8a9bb5;
  --accent: #ffd84d;
  --blue: #4db8ff;
  --good: #4ade80;
  --warn: #fbbf24;
  --bad: #f87171;
  color-scheme: dark;
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 13px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100vh;
}
button { font: inherit; color: inherit; cursor: pointer; }
small { color: var(--muted); }
b { font-variant-numeric: tabular-nums; }

/* ---------- header ---------- */
.top {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  padding: 8px 14px; background: linear-gradient(#0d1626, #0a111d);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 10px; margin-right: auto; }
.brand h1 { margin: 0; font-size: 18px; letter-spacing: .5px; }
.brand small { display: block; font-size: 11px; }
.logo {
  width: 34px; height: 34px; display: grid; place-items: center; border-radius: 9px;
  background: linear-gradient(135deg, #0057b7 50%, #ffd700 50%); font-size: 18px;
}
.chip {
  background: var(--panel); border: 1px solid var(--line); border-radius: 10px;
  padding: 5px 12px; min-width: 120px; display: flex; flex-direction: column;
}
.chip b { font-size: 16px; }
.chip small { font-size: 11px; }
.clock { flex-direction: row; align-items: center; gap: 10px; min-width: 170px; }
.clock > span { font-size: 22px; }
.clock div { display: flex; flex-direction: column; }
.money b { color: var(--accent); }
.streak .bar { margin-top: 3px; }
.bar { height: 5px; background: #1d2a40; border-radius: 3px; overflow: hidden; }
.bar.big { height: 8px; margin: 4px 0 6px; }
.bar i { display: block; height: 100%; width: 0; background: var(--good); transition: width .3s; }
.speed { display: flex; gap: 4px; }
.speed button {
  background: var(--panel); border: 1px solid var(--line); border-radius: 8px;
  padding: 7px 10px; min-width: 38px;
}
.speed button.on { background: #1d3b63; border-color: var(--blue); }

/* ---------- layout ---------- */
.layout {
  display: grid; grid-template-columns: minmax(0, 1fr) 370px; gap: 10px; padding: 10px;
  max-width: 1600px; margin: 0 auto;
}
.left { display: flex; flex-direction: column; gap: 10px; min-width: 0; }
.side {
  display: flex; flex-direction: column; gap: 10px;
  position: sticky; top: 66px; align-self: start; max-height: calc(100vh - 76px); overflow-y: auto;
}
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 10px 12px; }
.panel h3 { margin: 0 0 6px; font-size: 13px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .6px; }

/* ---------- map ---------- */
.mapwrap {
  position: relative; border-radius: 12px; overflow: hidden; border: 1px solid var(--line);
  background: #0a111d;
}
#map { display: block; width: 100%; touch-action: manipulation; }
#alert {
  position: absolute; top: 10px; left: 50%; transform: translateX(-50%);
  padding: 6px 16px; border-radius: 20px; font-weight: 700; font-size: 13px;
  background: rgba(20, 30, 50, .85); border: 1px solid var(--line); pointer-events: none;
  white-space: nowrap; z-index: 2;
}
#alert.raid { background: rgba(160, 20, 30, .9); border-color: #ff6b6b; animation: blink 1.2s infinite; }
#alert.calm { color: var(--good); }
@keyframes blink { 50% { box-shadow: 0 0 22px rgba(255, 60, 60, .8); } }
.tip {
  position: absolute; pointer-events: none; display: none; z-index: 3;
  background: rgba(8, 14, 26, .95); border: 1px solid var(--line); border-radius: 8px;
  padding: 6px 9px; font-size: 12px; max-width: 260px;
}
.tip b { display: block; }
.hint {
  position: absolute; left: 50%; top: 46px; transform: translateX(-50%); padding: 6px 10px; border-radius: 8px;
  background: rgba(30, 60, 100, .94); border: 1px solid var(--blue); display: none; font-size: 12px;
  align-items: center; gap: 4px; max-width: calc(100% - 120px); z-index: 4;
}
/* Картка вибраного об'єкта на карті (десктоп) */
.objcard {
  position: absolute; display: none; z-index: 4; width: 280px; max-height: calc(100% - 16px); overflow-y: auto;
  background: rgba(12, 20, 34, .97); border: 1px solid #36507a; border-radius: 12px; padding: 10px 12px;
  font-size: 12px; box-shadow: 0 10px 30px rgba(0, 0, 0, .55);
}
.objcard h4 { margin: 0 22px 2px 0; font-size: 14px; }
.objcard .sub { font-size: 11px; color: var(--muted); margin-bottom: 6px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.objcard .grid { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin-bottom: 8px; font-size: 11.5px; }
.objcard .grid span { color: var(--muted); }
.objcard .grid b { text-align: right; }
.objcard .hpbar { height: 5px; background: #2a1820; border-radius: 3px; overflow: hidden; margin: 2px 0 6px; }
.objcard .hpbar i { display: block; height: 100%; }
.objcard .acts { display: grid; grid-template-columns: 1fr 1fr; gap: 4px; }
.objcard .ex { display: none; }
.objcard .acts[style] { grid-template-columns: 1fr 1fr; }
.objcard .acts button:only-child, .objcard .acts button:last-child:nth-child(odd) { grid-column: 1 / -1; }
.objcard .acts button {
  background: var(--panel2); border: 1px solid #2b4268; border-radius: 7px; padding: 5px 7px; font-size: 11px; line-height: 1.25; text-align: left;
}
.objcard .acts button:hover { border-color: var(--blue); }
.objcard .acts button.danger { border-color: #7a2b36; }
.objcard .x {
  position: absolute; top: 6px; right: 6px; width: 24px; height: 24px; border-radius: 6px;
  background: var(--panel2); border: 1px solid var(--line); font-size: 12px; line-height: 1;
}
.objcard .empty { color: var(--muted); }
.panel.sel { display: none; }   /* на десктопі замість панелі — картка на карті */
.legend {
  position: absolute; left: 0; right: 0; bottom: 0; display: flex; flex-wrap: wrap; gap: 4px 12px;
  padding: 5px 10px; font-size: 11px; color: var(--muted); background: linear-gradient(transparent, rgba(5, 10, 18, .85));
  pointer-events: none;
}
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.lg { width: 10px; height: 10px; display: inline-block; border-radius: 2px; }
.lg.npp { background: #b48cff; border-radius: 50%; }
.lg.tpp { background: #ff9d4d; }
.lg.hpp { background: #4db8ff; }
.lg.sub { background: #e8eef7; transform: rotate(45deg) scale(.8); }
.lg.city { background: #ffd84d; border-radius: 50%; }
.lg.occ { background: repeating-linear-gradient(45deg, rgba(255, 90, 90, .5) 0 2px, rgba(120, 30, 40, .4) 2px 4px); }

/* ---------- log ---------- */
.logpanel { max-height: 240px; display: flex; flex-direction: column; }
#log { list-style: none; margin: 0; padding: 0; overflow-y: auto; font-size: 12px; }
#log li { padding: 3px 0; border-bottom: 1px dashed #1b2840; display: flex; gap: 8px; }
#log li time { color: var(--muted); font-variant-numeric: tabular-nums; flex: 0 0 auto; }
#log li.alert { color: #ff9b9b; }
#log li.hit { color: #ffb38a; }
#log li.aid { color: #8ff0b0; }
#log li.good { color: #9fd8ff; }
#log li.warn { color: #ffe08a; }

/* ---------- stats ---------- */
.freq { display: flex; align-items: center; gap: 10px; }
.fval { display: flex; flex-direction: column; min-width: 100px; }
.fval b { font-size: 30px; line-height: 1.05; }
.fval span { color: var(--muted); font-size: 12px; }
#spark { flex: 1; width: 100%; min-width: 0; height: 60px; background: #0b1322; border-radius: 6px; }
.kv { display: grid; grid-template-columns: 1fr 1fr; gap: 6px; margin: 10px 0; }
.kv div { background: var(--panel2); border-radius: 8px; padding: 5px 8px; display: flex; flex-direction: column; }
.kv small { font-size: 11px; }
.kv b { font-size: 15px; }
.settl .row { display: flex; justify-content: space-between; align-items: center; gap: 8px; padding: 2px 0; }
.settl .row b { font-size: 15px; }
.settl .row.sm b { font-size: 13px; }
.settl .row.sm span { color: var(--muted); }
.dot { width: 8px; height: 8px; border-radius: 50%; display: inline-block; margin-right: 6px; }
.dot.on { background: var(--accent); box-shadow: 0 0 6px var(--accent); }
.dot.off { background: #3a4558; }
.chk input { width: 16px; height: 16px; accent-color: var(--blue); }
.good { color: var(--good) !important; }
.warn { color: var(--warn) !important; }
.bad { color: var(--bad) !important; }

/* ---------- build ---------- */
.tabs { display: flex; gap: 4px; margin-bottom: 8px; }
.tabs button {
  flex: 1; background: var(--panel2); border: 1px solid var(--line); border-radius: 8px; padding: 6px;
}
.tabs button.on { background: #1d3b63; border-color: var(--blue); }
.list { display: flex; flex-direction: column; gap: 5px; max-height: 360px; overflow-y: auto; }
.item {
  display: grid; grid-template-columns: 44px 1fr auto; gap: 8px; align-items: center; text-align: left;
  background: var(--panel2); border: 1px solid transparent; border-radius: 9px; padding: 6px 8px;
}
.item:hover:not(:disabled) { border-color: #36507a; }
.item.on { border-color: var(--accent); background: #2a2a1a; }
.item:disabled { opacity: .45; cursor: not-allowed; }
.item .ic {
  width: 44px; height: 30px; border-radius: 6px; display: grid; place-items: center; font-size: 10px; font-weight: 800;
  background: color-mix(in srgb, var(--c) 22%, transparent); color: var(--c); border: 1px solid var(--c);
}
.item .t b { display: block; font-size: 13px; }
.item .t small { display: block; font-size: 11px; line-height: 1.3; }
.item .p { text-align: right; font-weight: 700; color: var(--accent); white-space: nowrap; font-size: 12px; }
.item .p em { display: block; font-style: normal; color: var(--good); font-size: 11px; }

/* ---------- selection ---------- */
.sel h4 { margin: 0 0 2px; font-size: 15px; }
.sel .sub { color: var(--muted); font-size: 12px; margin-bottom: 8px; }
.sel .grid { display: grid; grid-template-columns: 1fr 1fr; gap: 4px 10px; margin-bottom: 8px; }
.sel .grid span { color: var(--muted); }
.sel .acts { display: flex; flex-wrap: wrap; gap: 5px; }
.sel .acts button {
  background: var(--panel2); border: 1px solid #2b4268; border-radius: 8px; padding: 6px 9px; font-size: 12px;
}
.sel .acts button:hover:not(:disabled) { border-color: var(--blue); }
.sel .acts button:disabled { opacity: .45; cursor: not-allowed; }
.sel .acts button.danger { border-color: #7a2b36; }
.sel .empty { color: var(--muted); font-size: 12px; }
.hpbar { height: 6px; background: #2a1820; border-radius: 3px; overflow: hidden; margin: 2px 0 8px; }
.hpbar i { display: block; height: 100%; }

/* ---------- modal & toast ---------- */
.modal {
  position: fixed; inset: 0; background: rgba(3, 6, 12, .78); display: none; place-items: center;
  z-index: 20; padding: 16px; overflow-y: auto;
}
.modal.show { display: grid; }
.card {
  background: var(--panel); border: 1px solid var(--line); border-radius: 16px; padding: 22px 24px;
  max-width: 640px; width: 100%; box-shadow: 0 20px 60px rgba(0, 0, 0, .6);
}
.card h2 { margin: 0 0 8px; font-size: 22px; }
.card p { color: #c4d0e3; margin: 8px 0; }
.card ul { padding-left: 18px; margin: 8px 0; color: #c4d0e3; }
.card li { margin: 3px 0; }
.card .note { font-size: 11px; color: var(--muted); }
.card .btns { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.card .btns button {
  background: linear-gradient(#ffd84d, #f2b705); color: #1a1400; border: 0; border-radius: 10px;
  padding: 10px 18px; font-weight: 800;
}
.card .btns button.sec { background: var(--panel2); color: var(--text); border: 1px solid var(--line); }
.card .res { display: grid; grid-template-columns: 1fr auto; gap: 4px 16px; margin: 10px 0; }
.card .res b { text-align: right; }
.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px); opacity: 0;
  background: #13233b; border: 1px solid var(--blue); border-radius: 10px; padding: 9px 16px;
  transition: .25s; pointer-events: none; z-index: 30; max-width: 90vw; text-align: center;
}
.toast.show { opacity: 1; transform: translateX(-50%); }
.toast.aid { border-color: var(--good); }
.toast.err { border-color: var(--bad); }


/* ---------- map overlays ---------- */
#map { cursor: default; touch-action: none; }
.mapctl { position: absolute; top: 10px; right: 10px; display: flex; flex-direction: column; gap: 4px; z-index: 2; }
.mapctl button {
  width: 34px; height: 34px; border-radius: 8px; background: rgba(15, 24, 40, .9); border: 1px solid var(--line);
  font-size: 16px; line-height: 1;
}
.mapctl button.on { border-color: var(--blue); background: #1d3b63; }
.abilities {
  position: absolute; left: 50%; bottom: 30px; transform: translateX(-50%); display: flex; gap: 6px; z-index: 2;
}
.abilities button {
  display: flex; flex-direction: column; align-items: center; min-width: 108px; padding: 6px 10px; border-radius: 10px;
  background: rgba(15, 24, 40, .92); border: 1px solid #36507a; font-weight: 700; font-size: 12px;
}
.abilities button small { font-weight: 500; font-size: 10px; }
.abilities button:disabled { opacity: .5; cursor: not-allowed; }
.abilities button.ready { border-color: var(--warn); box-shadow: 0 0 10px rgba(251, 191, 36, .35); }
.tutbox {
  position: absolute; left: 10px; top: 52px; max-width: 340px; display: none; z-index: 3;
  background: rgba(14, 30, 56, .96); border: 1px solid var(--accent); border-radius: 12px; padding: 10px 12px;
  font-size: 12.5px; box-shadow: 0 8px 30px rgba(0, 0, 0, .5);
}
.tutbox .st { color: var(--accent); font-size: 11px; font-weight: 700; margin-bottom: 4px; }
.tutbox .bt { display: flex; gap: 6px; margin-top: 8px; }
.tutbox button { border-radius: 8px; padding: 5px 10px; border: 1px solid var(--line); background: var(--panel2); font-size: 12px; }
.tutbox button.pri { background: var(--accent); color: #1a1400; border: 0; font-weight: 700; }
.pulse { animation: pulse 1.2s infinite; }
@keyframes pulse { 50% { box-shadow: 0 0 0 3px rgba(255, 216, 77, .6); border-color: var(--accent); } }
.speed button.off { opacity: .6; }

/* ---------- setup & records ---------- */
.setup .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin: 12px 0 6px; }
.cards { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.cards button, .seg button {
  text-align: left; background: var(--panel2); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px;
}
.cards button b { display: block; font-size: 13px; }
.cards button small { display: block; font-size: 11px; line-height: 1.3; margin-top: 2px; }
.cards button.on, .seg button.on { border-color: var(--accent); background: #2a2a1a; }
.seg { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.seg button { text-align: center; }
.seg button small { display: block; font-size: 10.5px; }
.setup .chk { display: flex; align-items: center; gap: 8px; margin-top: 10px; color: #c4d0e3; }
.card details { margin-top: 10px; color: #c4d0e3; }
.card summary { cursor: pointer; color: var(--blue); }
.disclaimer {
  margin: 10px 0; padding: 8px 10px; border: 1px solid #5c4a1a; border-left: 3px solid var(--warn);
  border-radius: 6px; background: #1c1a12; color: #d9cfae; font-size: 12px;
}
.disclaimer b { display: block; color: var(--warn); margin-bottom: 2px; }
.memo-scen { font-size: 12px; color: #b9c4d6; margin: 6px 0 0; }
.memo { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.card .memo p { font-size: 12px; color: #b9c4d6; margin: 4px 0; }
.donate { margin-top: 10px; }
.donate > b { display: block; font-size: 12px; margin-bottom: 6px; }
.donate > div { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px; }
.donate a {
  display: block; padding: 7px 9px; border: 1px solid var(--line); border-radius: 6px;
  background: var(--panel2); color: var(--blue); text-decoration: none; font-weight: 600;
}
.donate a:hover { border-color: var(--blue); }
.donate a small { display: block; font-weight: 400; font-size: 11px; line-height: 1.3; margin-top: 2px; }
@media (max-width: 760px) { .donate > div { grid-template-columns: 1fr; } }
.board { width: 100%; border-collapse: collapse; font-size: 12px; margin: 8px 0; }
.board th, .board td { padding: 4px 6px; border-bottom: 1px solid var(--line); text-align: left; }
.board th { color: var(--muted); font-weight: 600; }
.board tr.me td { color: var(--accent); font-weight: 700; }
.achs { display: grid; grid-template-columns: repeat(2, 1fr); gap: 6px; margin: 8px 0; }
.ach { display: flex; gap: 8px; align-items: center; background: var(--panel2); border-radius: 9px; padding: 6px 8px; opacity: .45; }
.ach.on { opacity: 1; border: 1px solid #4a6a3a; }
.ach i { font-style: normal; font-size: 20px; }
.ach b { display: block; font-size: 12px; }
.ach small { font-size: 11px; }
.card .tabs { margin: 8px 0; }
.card .tabs button { padding: 6px; }
.card { max-height: calc(100vh - 32px); overflow-y: auto; }

/* ---------- mobile-only elements (hidden on desktop) ---------- */
.left { position: relative; }
.mstrip, .mtabs, #menuBtn, #spdBtn { display: none; }
button { touch-action: manipulation; }
.hint button {
  margin-left: 8px; border-radius: 7px; padding: 4px 10px; border: 1px solid var(--line);
  background: var(--panel2); font-weight: 700; font-size: 12px;
}
.hint button.ok { background: var(--accent); color: #1a1400; border: 0; }

/* Ноутбуки й планшети горизонтально: та сама розкладка з бічною панеллю, лише вужча — меню завжди поруч із картою */
@media (max-width: 1180px) {
  .chip.streak { display: none; }
  .chip { min-width: 0; }
}
@media (max-width: 1050px) {
  .layout { grid-template-columns: minmax(0, 1fr) 300px; padding: 8px; gap: 8px; }
  .top { padding: 6px 10px; gap: 6px; }
  .brand small { display: none; }
  .clock { min-width: 0; }
  .side { top: 58px; max-height: calc(100vh - 66px); }
  .item .t small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .kv b { font-size: 13px; }
  .speed button { min-width: 34px; padding: 7px 8px; }
}

/* ---------- phone layout: one screen, no page scroll ---------- */
@media (max-width: 760px), (max-width: 1100px) and (orientation: portrait) and (pointer: coarse), (max-height: 520px) and (orientation: landscape) {
  html, body { height: 100%; overflow: hidden; overscroll-behavior: none; }
  body { display: flex; flex-direction: column; height: 100vh; height: 100dvh; }
  .top {
    position: static; flex: 0 0 auto; flex-wrap: nowrap; gap: 6px;
    padding: calc(6px + env(safe-area-inset-top)) 8px 6px;
  }
  .brand, .clock > span, .chip.streak, #muteBtn, #recBtn, #helpBtn { display: none; }
  .chip.clock, .chip.money { flex: 1 1 0; }
  .logo { width: 30px; height: 30px; font-size: 15px; border-radius: 8px; }
  .chip { min-width: 0; flex: 0 1 auto; padding: 3px 8px; border-radius: 8px; }
  .chip b { font-size: 14px; }
  .chip small { font-size: 10px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
  .clock { gap: 6px; min-width: 0; }
  .clock > span { font-size: 16px; }
  .money > small:first-child { display: none; }
  .money b { white-space: nowrap; }
  .seg { grid-template-columns: repeat(3, 1fr); }
  .seg button small { display: none; }
  .speed { margin-left: auto; gap: 3px; flex: 0 0 auto; width: auto; }
  .speed button { min-width: 30px; padding: 6px 5px; flex: 0 0 auto; font-size: 12px; }
  #menuBtn { display: inline-block; font-size: 15px; }

  .layout { flex: 1 1 auto; min-height: 0; display: flex; flex-direction: column; padding: 0; gap: 0; max-width: none; }
  .left, .side { display: contents; }
  .mapwrap { order: 0; flex: 0 0 auto; border-radius: 0; border-left: 0; border-right: 0; }
  .legend, .mapwrap .abilities { display: none; }
  #alert { top: 6px; padding: 4px 10px; font-size: 11px; max-width: calc(100% - 60px); overflow: hidden; text-overflow: ellipsis; }
  .mapctl { top: 6px; right: 6px; gap: 3px; }
  .mapctl button { width: 30px; height: 30px; font-size: 14px; }
  .hint {
    left: 6px; right: 6px; bottom: 6px; top: auto; transform: none; max-width: none; display: none; padding: 6px 8px; font-size: 12px;
    align-items: center; justify-content: space-between; gap: 6px;
  }
  .hint span { flex: 1; }
  .hint button { padding: 7px 12px; margin-left: 0; }
  .tutbox { order: 1; position: static; max-width: none; margin: 0; border-radius: 0; border-left: 0; border-right: 0; box-shadow: none; padding: 8px 12px; font-size: 12px; }
  .tutbox .bt { margin-top: 6px; }

  .mstrip {
    order: 2; display: flex; align-items: stretch; gap: 6px; padding: 6px 8px;
    background: var(--panel); border-bottom: 1px solid var(--line); flex: 0 0 auto;
  }
  .ms { display: flex; flex-direction: column; justify-content: center; min-width: 0; flex: 1; }
  .ms small { font-size: 10px; }
  .ms b { font-size: 15px; line-height: 1.1; }
  .mstrip button {
    flex: 0 0 auto; min-width: 54px; display: flex; flex-direction: column; align-items: center; justify-content: center;
    background: var(--panel2); border: 1px solid #36507a; border-radius: 9px; padding: 3px 6px; font-size: 16px; line-height: 1.1;
  }
  .mstrip button small { font-size: 9.5px; }
  .mstrip button:disabled { opacity: .5; }
  .mstrip button.ready { border-color: var(--warn); box-shadow: 0 0 10px rgba(251, 191, 36, .35); }

  .panel { order: 3; display: none; border-radius: 0; border: 0; padding: 10px 12px; }
  body[data-mtab="build"] .panel.build,
  body[data-mtab="sel"] .panel.sel,
  body[data-mtab="stats"] .panel.stats,
  body[data-mtab="log"] .panel.logpanel {
    display: flex; flex-direction: column; flex: 1 1 auto; min-height: 0; overflow-y: auto; -webkit-overflow-scrolling: touch;
  }
  body[data-mtab="sel"] .panel.sel { display: block; }
  .build .tabs { position: sticky; top: -10px; background: var(--panel); padding: 2px 0 6px; margin-bottom: 4px; z-index: 1; }
  .list { max-height: none; overflow: visible; }
  .item { grid-template-columns: 40px 1fr auto; padding: 8px; }
  .item .ic { width: 40px; }
  .item .t small { display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
  .logpanel { max-height: none; }
  .sel .acts button { padding: 9px 11px; font-size: 13px; }
  .kv b { font-size: 13px; }

  .mtabs {
    order: 4; display: flex; flex: 0 0 auto; background: #0b1424; border-top: 1px solid var(--line);
    padding-bottom: env(safe-area-inset-bottom);
  }
  .mtabs button {
    flex: 1; position: relative; display: flex; flex-direction: column; align-items: center; gap: 1px;
    background: none; border: 0; padding: 7px 2px 6px; font-size: 17px; color: var(--muted);
  }
  .mtabs button span { font-size: 10.5px; }
  .mtabs button.on { color: var(--accent); background: rgba(255, 216, 77, .07); }
  .mtabs button.pulse { animation: pulse 1.2s infinite; }
  #logDot { position: absolute; top: 6px; right: calc(50% - 16px); width: 8px; height: 8px; border-radius: 50%; background: var(--bad); display: none; }
  #logDot.on { display: block; }

  .toast { bottom: calc(70px + env(safe-area-inset-bottom)); }
  .tip, .objcard { display: none !important; }
  .cards, .achs { grid-template-columns: 1fr; }
  .card { padding: 16px; border-radius: 14px; }
  .card > p:first-of-type { font-size: 12.5px; }
}

/* Горизонтальний телефон: карта на всю висоту ліворуч, вузька колонка керування праворуч */
@media (max-height: 520px) and (orientation: landscape) {
  body {
    display: grid; height: 100vh; height: 100dvh;
    grid-template-columns: min(calc(100vh / 0.7), 67vw, calc(100vw - 230px)) minmax(0, 1fr);
    grid-template-columns: min(calc(100dvh / 0.7), 67vw, calc(100vw - 230px)) minmax(0, 1fr);
    grid-template-rows: auto auto auto minmax(0, 1fr) auto;
    padding-left: env(safe-area-inset-left); padding-right: env(safe-area-inset-right);
  }
  .layout { display: contents; }
  .top {
    grid-column: 2; grid-row: 1; padding: calc(4px + env(safe-area-inset-top)) 6px 4px; gap: 4px;
    border-left: 1px solid var(--line);
  }
  .chip { padding: 2px 6px; }
  .chip b { font-size: 13px; }
  .chip.clock { flex: 0 0 auto; }
  .chip.money { flex: 1 1 auto; min-width: 74px; }
  .chip small { font-size: 9.5px; }
  .speed [data-speed="1"], .speed [data-speed="2"], .speed [data-speed="4"] { display: none; }
  #spdBtn { display: inline-block; }
  .speed button { min-width: 28px; padding: 5px 4px; }
  .mapwrap { grid-column: 1; grid-row: 1 / -1; align-self: center; width: 100%; border: 0; }
  .mstrip { grid-column: 2; grid-row: 2; padding: 4px 6px; gap: 4px; border-left: 1px solid var(--line); }
  .ms b { font-size: 13px; }
  .ms small { font-size: 9px; }
  .mstrip button { min-width: 44px; min-height: 30px; padding: 2px 4px; font-size: 14px; }
  .tutbox { grid-column: 2; grid-row: 3; padding: 6px 8px; font-size: 11px; border-left: 1px solid var(--accent); }
  .panel { grid-column: 2; grid-row: 4; padding: 6px 8px; border-left: 1px solid var(--line); }
  .build .tabs { top: -6px; padding-bottom: 4px; }
  .build .tabs button { padding: 4px; font-size: 12px; }
  .item { grid-template-columns: 34px 1fr auto; gap: 6px; padding: 5px 6px; }
  .item .ic { width: 34px; height: 24px; font-size: 9px; }
  .item .t b { font-size: 12px; }
  .item .t small { display: none; }
  .item .p { font-size: 11px; }
  .mtabs { grid-column: 2; grid-row: 5; border-left: 1px solid var(--line); padding-bottom: env(safe-area-inset-bottom); }
  .mtabs button { flex-direction: row; justify-content: center; gap: 3px; font-size: 13px; padding: 5px 2px; }
  .mtabs button span { font-size: 10px; }
  .toast { bottom: 12px; left: auto; right: 8px; transform: none; max-width: 40vw; }
  .toast.show { transform: none; }
}

/* Невеликі телефони горизонтально: права колонка вузька — лишаємо головне */
@media (max-height: 520px) and (orientation: landscape) and (max-width: 740px) {
  .chip small, .mstrip button small, .mtabs button span { display: none; }
  .chip.clock { flex: 0 0 auto; }
  .chip.money { flex: 1 1 auto; min-width: 74px; }
  .top { gap: 3px; padding-left: 4px; padding-right: 4px; }
  .chip { padding: 2px 5px; }
  .chip b { font-size: 12px; }
  .speed { gap: 2px; }
  .speed button { min-width: 28px; padding: 5px 2px; }
  .ms:nth-child(3) { display: none; }
  .mstrip button { min-width: 36px; }
  .mtabs button { font-size: 16px; padding: 6px 2px; }
  .build .tabs button { font-size: 11px; padding: 4px 2px; }
  .item .t b { font-size: 11.5px; }
}

/* Найменші телефони горизонтально (≈568×320): ще вужча колонка, щоб карта лишалася великою */
@media (max-height: 520px) and (orientation: landscape) and (max-width: 600px) {
  body {
    grid-template-columns: min(calc(100vh / 0.7), 67vw, calc(100vw - 205px)) minmax(0, 1fr);
    grid-template-columns: min(calc(100dvh / 0.7), 67vw, calc(100vw - 205px)) minmax(0, 1fr);
  }
  .mapctl { gap: 2px; top: 4px; right: 4px; }
  .mapctl button { width: 26px; height: 26px; font-size: 12px; }
  .item { grid-template-columns: 30px 1fr auto; gap: 4px; }
  .item .ic { width: 30px; }
  .item .p { font-size: 10.5px; white-space: normal; }
  .item .p em { font-size: 9.5px; }
  .chip.clock { display: none; }
  .chip.money { min-width: 0; }
}

/* Кнопка повернення з панелі об'єкта до меню ППО (телефон) */
.panel.sel { position: relative; }
.panel.sel .x {
  position: absolute; top: 8px; right: 10px; padding: 6px 10px; border-radius: 8px; font-size: 12px; font-weight: 700;
  background: var(--panel2); border: 1px solid var(--accent); color: var(--accent);
}
.panel.sel h4 { margin-right: 76px; }

/* ---------- share ---------- */
.share { margin: 12px 0 4px; padding: 10px 12px; background: var(--panel2); border-radius: 12px; }
.share .lbl { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: .6px; margin-bottom: 8px; }
.sbtns { display: flex; flex-wrap: wrap; gap: 6px; }
.sbtns a, .sbtns button {
  display: inline-flex; align-items: center; gap: 4px; padding: 7px 11px; border-radius: 9px; font-size: 12.5px; font-weight: 600;
  background: #1b2a44; border: 1px solid #2f4a74; color: var(--text); text-decoration: none; cursor: pointer;
}
.sbtns a:hover, .sbtns button:hover { border-color: var(--blue); }
.sbtns .pri { background: var(--accent); color: #1a1400; border: 0; }
