:root {
  --bg: #12161b;
  --panel: rgba(20, 25, 31, 0.94);
  --panel-solid: #161b21;
  --line: rgba(255, 255, 255, 0.09);
  --text: #e6e2d8;
  --muted: #9aa0a6;
  --accent: #e0b050;
  --accent-ink: #1b1406;
  --danger: #e05a4f;
  --ok: #6cc070;
  --west: #5b8fd6;
  --east: #d65b52;
  --neutral: #8fb86a;
  --radius: 12px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --dock-h: 58px;
  --top-h: 46px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0; height: 100%; background: var(--bg); color: var(--text);
  font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  overscroll-behavior: none; -webkit-tap-highlight-color: transparent;
}
body { overflow: hidden; touch-action: none; }
button { font: inherit; color: inherit; }
[hidden] { display: none !important; }

#app { position: fixed; inset: 0; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; cursor: grab; background: #1c3350; }
#map.dragging { cursor: grabbing; }

/* ---------- top bar ---------- */
#topbar {
  position: absolute; top: 0; left: 0; right: 0; z-index: 5;
  padding: calc(var(--safe-top) + 6px) 10px 6px; min-height: calc(var(--top-h) + var(--safe-top));
  display: flex; align-items: center; gap: 8px;
  background: linear-gradient(180deg, rgba(14, 17, 21, 0.95), rgba(14, 17, 21, 0.78));
  border-bottom: 1px solid var(--line); backdrop-filter: blur(6px);
}
.tb-country {
  display: flex; align-items: center; gap: 8px; min-width: 0; flex: 1 1 auto;
  background: none; border: 0; padding: 4px 6px; border-radius: 8px; cursor: pointer; text-align: left;
}
.tb-country:hover { background: rgba(255, 255, 255, 0.05); }
#tb-name { font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.flag { border-radius: 2px; box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.45); flex: none; }
.tb-clock {
  display: flex; align-items: center; gap: 6px; flex: none;
  font-variant-numeric: tabular-nums; background: rgba(255, 255, 255, 0.05);
  border: 1px solid var(--line); border-radius: 999px; padding: 4px 10px;
}
.clock-time { font-weight: 700; color: var(--accent); }
.clock-icon { width: 1.1em; text-align: center; }
.speed { font-size: 11px; font-weight: 700; color: var(--accent-ink); background: var(--accent); border-radius: 6px; padding: 0 5px; }
.tb-money {
  flex: none; display: flex; align-items: center; gap: 5px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 10px; cursor: pointer; font-variant-numeric: tabular-nums; font-weight: 650;
}
.tb-money .sep { color: var(--muted); }
.tb-money .neg { color: var(--danger); }
.conn { width: 9px; height: 9px; border-radius: 50%; background: var(--danger); flex: none; box-shadow: 0 0 6px currentColor; color: var(--danger); }
.conn.on { background: var(--ok); color: var(--ok); }

/* ---------- banner ---------- */
.banner {
  position: absolute; z-index: 4; left: 50%; transform: translateX(-50%);
  top: calc(var(--top-h) + var(--safe-top) + 10px); max-width: calc(100% - 24px);
  background: var(--accent); color: var(--accent-ink); font-weight: 600;
  padding: 8px 14px; border-radius: 999px; box-shadow: 0 6px 20px rgba(0, 0, 0, 0.35); text-align: center;
}

/* ---------- dock ---------- */
#dock {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 5;
  display: flex; gap: 2px; justify-content: center; overflow-x: auto; scrollbar-width: none;
  padding: 4px 6px calc(4px + var(--safe-bottom));
  background: linear-gradient(0deg, rgba(14, 17, 21, 0.96), rgba(14, 17, 21, 0.82));
  border-top: 1px solid var(--line); backdrop-filter: blur(6px);
}
#dock::-webkit-scrollbar { display: none; }
#dock button {
  flex: 0 0 auto; min-width: 64px; display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: none; border: 0; border-radius: 10px; padding: 5px 6px; cursor: pointer; font-size: 11px; color: var(--muted);
}
#dock button .ico { font-size: 19px; line-height: 1.15; }
#dock button:hover, #dock button.active { background: rgba(255, 255, 255, 0.07); color: var(--text); }
#dock button.alert { color: #ff8a80; }
#dock button.alert .ico { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.18); } }
.dbadge { font-style: normal; display: inline-block; min-width: 14px; margin-left: 3px; padding: 0 4px; border-radius: 7px; background: var(--danger); color: #fff; font-size: 10px; line-height: 14px; }
.dbadge:empty { display: none; }

/* ---------- popover ---------- */
.popover {
  position: absolute; z-index: 6; bottom: calc(var(--dock-h) + var(--safe-bottom) + 8px); left: 50%; transform: translateX(-50%);
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 8px 12px;
  display: flex; flex-direction: column; gap: 2px; box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45); min-width: 230px;
}
.popover label { display: flex; align-items: center; gap: 10px; padding: 8px 2px; cursor: pointer; }
.popover input { width: 18px; height: 18px; accent-color: var(--accent); }

/* ---------- panel (bottom sheet on phones, side panel on wide screens) ---------- */
.panel {
  position: absolute; z-index: 6; left: 0; right: 0; bottom: calc(var(--dock-h) + var(--safe-bottom));
  max-height: 58vh; overflow-y: auto; overscroll-behavior: contain; touch-action: pan-y;
  background: var(--panel); border-top: 1px solid var(--line); border-radius: 16px 16px 0 0;
  padding: 14px 16px 18px; box-shadow: 0 -10px 30px rgba(0, 0, 0, 0.4);
}
@media (min-width: 820px) {
  .panel {
    left: auto; right: 12px; top: calc(var(--top-h) + var(--safe-top) + 12px); bottom: calc(var(--dock-h) + var(--safe-bottom) + 12px);
    width: 380px; max-height: none; border: 1px solid var(--line); border-radius: var(--radius);
  }
}
.panel-close {
  position: sticky; float: right; top: 0; z-index: 1; width: 32px; height: 32px; border-radius: 50%;
  border: 1px solid var(--line); background: var(--panel-solid); cursor: pointer; color: var(--muted);
}
.panel h2 { margin: 0 0 2px; font-size: 18px; line-height: 1.25; padding-right: 40px; }
.panel h3 { margin: 16px 0 6px; font-size: 12px; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.panel .head { display: flex; gap: 12px; align-items: center; margin-bottom: 10px; }
.panel .head .flag { width: 60px; height: 40px; }
.muted { color: var(--muted); }
.chip { display: inline-block; font-size: 12px; padding: 1px 8px; border-radius: 999px; border: 1px solid currentColor; margin-top: 4px; }
.chip.west { color: var(--west); } .chip.east { color: var(--east); } .chip.neutral { color: var(--neutral); }
.chip.you { color: var(--accent); }
.stats { display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.stat { background: rgba(255, 255, 255, 0.04); border: 1px solid var(--line); border-radius: 10px; padding: 8px 10px; }
.stat .k { font-size: 11px; color: var(--muted); }
.stat .v { font-size: 16px; font-weight: 650; font-variant-numeric: tabular-nums; }
.res-list { display: flex; flex-wrap: wrap; gap: 6px; }
.res { display: inline-flex; align-items: center; gap: 6px; padding: 4px 9px 4px 4px; border-radius: 999px; background: rgba(255, 255, 255, 0.05); border: 1px solid var(--line); font-size: 13px; }
.res .g { width: 20px; height: 20px; border-radius: 6px; display: inline-grid; place-items: center; font-size: 11px; font-weight: 800; }
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px; width: 100%;
  padding: 11px 14px; border-radius: 10px; border: 1px solid var(--line); background: rgba(255, 255, 255, 0.06);
  cursor: pointer; font-weight: 650; margin-top: 12px;
}
.btn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.btn.danger { background: var(--danger); color: #fff; border-color: transparent; }
.btn:disabled { opacity: 0.5; cursor: default; }
.journal { list-style: none; margin: 0; padding: 0; }
.journal li { padding: 9px 0; border-bottom: 1px solid var(--line); }
.journal li:last-child { border-bottom: 0; }
.journal .d { font-size: 12px; color: var(--accent); font-variant-numeric: tabular-nums; }
.note { font-size: 13px; color: var(--muted); background: rgba(224, 176, 80, 0.08); border: 1px solid rgba(224, 176, 80, 0.25); border-radius: 10px; padding: 8px 10px; margin-top: 12px; }

/* ---------- overlays ---------- */
.overlay {
  position: absolute; inset: 0; z-index: 20; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 50% 35%, #1d2733, #0d1014 70%);
}
.login-card, .loading-card { width: min(360px, 100%); text-align: center; }
.login-card h1 { margin: 6px 0 4px; letter-spacing: 0.18em; text-transform: uppercase; font-size: 26px; }
.login-star { font-size: 46px; color: var(--accent); text-shadow: 0 0 24px rgba(224, 176, 80, 0.45); }
.login-star.spin { animation: spin 2.4s linear infinite; display: inline-block; }
@keyframes spin { to { transform: rotate(360deg); } }
.login-card input {
  width: 100%; margin-top: 18px; padding: 12px 14px; border-radius: 10px; border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.06); color: var(--text); font-size: 16px;
}
.error { color: var(--danger); }

.toast {
  position: absolute; z-index: 30; left: 50%; transform: translateX(-50%);
  bottom: calc(var(--dock-h) + var(--safe-bottom) + 14px); max-width: calc(100% - 24px);
  background: var(--panel-solid); border: 1px solid var(--line); border-radius: 10px; padding: 10px 14px;
  box-shadow: 0 10px 30px rgba(0, 0, 0, 0.45);
}

@media (max-width: 480px) {
  #topbar { gap: 6px; padding-left: 6px; padding-right: 8px; }
  .tb-country { flex: 0 0 auto; padding: 4px 2px; }
  #tb-name { display: none; }
  .tb-money { padding: 3px 8px; font-size: 13px; }
  .tb-clock { padding: 3px 8px; gap: 5px; font-size: 13px; }
  #dock { justify-content: flex-start; }
  #dock button { min-width: 54px; padding: 5px 3px; font-size: 10px; }
}

/* ---------- panels: shared building blocks ---------- */
body.panel-wide .panel { }
@media (min-width: 820px) { body.panel-wide .panel { width: 440px; } }
@media (max-width: 819px) { body.panel-wide .panel { max-height: 72vh; } }
.panel h2 { margin-bottom: 6px; }
.tabs { display: flex; gap: 4px; overflow-x: auto; scrollbar-width: none; margin: 4px 0 12px; position: sticky; top: -14px; z-index: 2; background: var(--panel-solid); padding: 6px 0; }
.tabs::-webkit-scrollbar { display: none; }
.tab { flex: none; border: 1px solid var(--line); background: rgba(255,255,255,0.04); color: var(--muted); border-radius: 999px; padding: 6px 12px; cursor: pointer; font-weight: 600; }
.tab.active { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.badge { display: inline-block; margin-left: 5px; min-width: 16px; padding: 0 5px; border-radius: 8px; background: var(--danger); color: #fff; font-size: 11px; }
.section { margin-top: 14px; }
.section h3 { margin: 0 0 8px; }
.hint { font-size: 12.5px; color: var(--muted); margin: 6px 0 10px; }
.small { font-size: 12.5px; }
.muted.small, .small.muted { color: var(--muted); }
.empty { color: var(--muted); padding: 10px 0; font-size: 13px; }
.error { color: var(--danger); }
.pos { color: var(--ok); }
.neg { color: var(--danger); }
.stat.neg .v { color: var(--danger); }
.stat.pos .v { color: var(--ok); }
.bar { position: relative; height: 16px; border-radius: 8px; background: rgba(255,255,255,0.07); overflow: hidden; margin: 4px 0; }
.bar .fill { height: 100%; border-radius: 8px; transition: width 0.4s; }
.bar .fill.ok { background: #4f9d55; }
.bar .fill.warn { background: #c8962e; }
.bar .fill.bad { background: #c0453b; }
.bar-label { position: absolute; inset: 0; display: flex; align-items: center; padding-left: 8px; font-size: 11px; font-weight: 650; color: #fff; text-shadow: 0 1px 2px rgba(0,0,0,0.6); }
.need { display: grid; grid-template-columns: 1fr 1.2fr; gap: 10px; align-items: center; font-size: 13px; }
.ledger { display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.lrow { display: flex; justify-content: space-between; gap: 10px; padding: 3px 0; border-bottom: 1px dashed var(--line); }
.lrow.total { font-weight: 700; border-bottom: 0; }
.tax { display: flex; align-items: center; gap: 10px; }
.slider { flex: 1; accent-color: var(--accent); }
.table { display: flex; flex-direction: column; font-size: 13px; }
.tr { display: grid; grid-template-columns: 1.3fr 1fr 1fr; gap: 6px; padding: 7px 4px; border-bottom: 1px solid var(--line); align-items: center; }
.tr.th { color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: 0.05em; }
.tr small { color: var(--muted); }
.click { cursor: pointer; }
.click:hover { background: rgba(255,255,255,0.04); }
.tr.sel { background: rgba(224,176,80,0.12); }
.brow { border: 1px solid var(--line); border-radius: 10px; padding: 9px 10px; margin-bottom: 8px; background: rgba(255,255,255,0.025); display: flex; flex-direction: column; gap: 4px; }
.brow.disabled { opacity: 0.55; }
.brow.mine { border-color: rgba(224,176,80,0.45); }
.btitle { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.btitle a { color: var(--text); }
.lvl { font-size: 12px; color: var(--muted); white-space: nowrap; }
.problem { font-size: 12.5px; color: #f0b35a; }
.row { display: flex; flex-wrap: wrap; gap: 6px; align-items: center; }
.sbtn { border: 1px solid var(--line); background: rgba(255,255,255,0.06); color: var(--text); border-radius: 8px; padding: 6px 10px; cursor: pointer; font-size: 12.5px; font-weight: 600; }
.sbtn.primary { background: var(--accent); color: var(--accent-ink); border-color: transparent; }
.sbtn.muted { opacity: 0.6; cursor: default; }
.sbtn:disabled { opacity: 0.5; }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip-good { font-size: 12px; padding: 3px 8px; border-radius: 999px; background: rgba(255,255,255,0.06); border: 1px solid var(--line); }
.chip.muted { color: var(--muted); }
.inp { width: 100%; padding: 9px 11px; border-radius: 9px; border: 1px solid var(--line); background: rgba(255,255,255,0.06); color: var(--text); font-size: 15px; margin-top: 8px; }
.inp.small { font-size: 14px; padding: 7px 9px; margin-top: 4px; }
select.inp { appearance: auto; }
.tradebox { border: 1px solid rgba(224,176,80,0.4); border-radius: 12px; padding: 10px; margin-bottom: 10px; background: rgba(224,176,80,0.06); }
.seggroup { display: flex; gap: 0; margin-top: 8px; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; }
.seg { flex: 1; padding: 8px; border: 0; background: transparent; color: var(--muted); cursor: pointer; font-weight: 650; }
.seg.on { background: var(--accent); color: var(--accent-ink); }
.autorow { display: grid; grid-template-columns: 1fr 1fr auto; gap: 8px; align-items: end; font-size: 12px; color: var(--muted); }
.autorow label { display: flex; flex-direction: column; }
@media (max-width: 480px) { .autorow { grid-template-columns: 1fr 1fr; } .autorow .sbtn { grid-column: span 2; } }
.drow { display: flex; gap: 10px; align-items: center; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.drow .dmain { flex: 1; min-width: 0; }
.relbox { display: grid; grid-template-columns: auto auto 1fr auto; gap: 8px; align-items: center; margin-top: 10px; font-size: 13px; }
.actions { display: flex; flex-direction: column; gap: 0; }
.actions .btn { margin-top: 8px; }
.actionbar { position: sticky; top: 34px; z-index: 1; display: flex; flex-wrap: wrap; gap: 6px; align-items: center; padding: 8px; margin-bottom: 8px; border-radius: 10px; background: #232a33; border: 1px solid rgba(224,176,80,0.4); }
.actionbar .inp { margin-top: 0; width: auto; flex: 1; min-width: 150px; }
.tri { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; font-size: 11px; color: var(--muted); }
.tri .bar { height: 7px; }
.toggle { display: flex; gap: 10px; align-items: flex-start; padding: 9px 0; border-bottom: 1px solid var(--line); cursor: pointer; }
.toggle input { width: 20px; height: 20px; accent-color: var(--accent); margin-top: 2px; }
.toggle small { display: block; color: var(--muted); font-weight: 400; }
.field { display: flex; flex-direction: column; padding: 9px 0; border-bottom: 1px solid var(--line); font-weight: 600; font-size: 13.5px; }
.srow { display: flex; flex-direction: column; gap: 2px; padding: 8px 4px; border-bottom: 1px solid var(--line); }
.banner.war { background: #c0453b; color: #fff; }
.banner .sbtn { margin-left: 8px; padding: 3px 9px; }
.toast.error { border-color: rgba(224,90,79,0.7); color: #ffb4ab; }
.journal li.k-war .d, .journal li.k-alert .d { color: #ff8a80; }
.journal li.k-peace .d { color: var(--ok); }
.res-list .res { font-size: 12.5px; }
.note { margin-top: 10px; }
