:root {
  --bg: #04050d;
  --panel: #0c1022;
  --panel-2: #141a33;
  --line: #232b4d;
  --text: #dfe6ff;
  --muted: #8890b3;
  --accent: #4fa3ff;
  --good: #78ffaa;
  font: 14px/1.45 system-ui, -apple-system, 'Segoe UI', Roboto, sans-serif;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { display: flex; flex-direction: column; overflow: hidden; }
h1 { margin: 0 0 8px; font-size: 26px; letter-spacing: .04em; }
h2 { margin: 0; font-size: 19px; }
h3 { margin: 18px 0 8px; font-size: 12px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); }
a { color: var(--accent); }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; }

button, input, select {
  font: inherit;
  color: var(--text);
  background: var(--panel-2);
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 5px 10px;
}
button { cursor: pointer; }
button:hover:not(:disabled) { border-color: var(--accent); }
button:disabled { opacity: .4; cursor: not-allowed; }
button.on { background: var(--accent); border-color: var(--accent); color: #041022; font-weight: 600; }
button.danger { border-color: #ff5d73; color: #ffb3c1; }
button.link { background: none; border: 0; padding: 0; color: var(--accent); text-decoration: underline; font: inherit; cursor: pointer; }
:focus-visible { outline: 2px solid var(--accent); outline-offset: 1px; }

/* ---------------------------------------------------------- top bar */
#topbar {
  display: flex; align-items: center; gap: 18px; flex-wrap: wrap;
  padding: 8px 14px; background: var(--panel); border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; letter-spacing: .08em; color: var(--accent); white-space: nowrap; }
#stats { display: flex; gap: 16px; flex: 1; flex-wrap: wrap; font-variant-numeric: tabular-nums; }
.stat.cash { color: #ffd76a; font-weight: 600; }
.controls { display: flex; gap: 8px; align-items: center; }
.seg { display: flex; }
.seg button { border-radius: 0; margin-left: -1px; min-width: 40px; }
.seg button:first-child { border-radius: 6px 0 0 6px; margin-left: 0; }
.seg button:last-child { border-radius: 0 6px 6px 0; }

/* ---------------------------------------------------------- layout */
main { flex: 1; display: flex; min-height: 0; }
#map-wrap { flex: 1; position: relative; min-width: 0; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; display: block; cursor: crosshair; touch-action: none; }
#map.dragging { cursor: grabbing; }
#hint {
  position: absolute; top: 12px; left: 50%; transform: translateX(-50%);
  max-width: calc(100% - 32px); padding: 6px 12px; border-radius: 6px;
  background: rgba(10, 40, 25, .85); border: 1px solid rgba(120, 255, 170, .5); color: var(--good);
  font-size: 13px; pointer-events: none;
  display: flex; align-items: center; gap: 10px;
}
#hint[hidden] { display: none; }
#hint-done { pointer-events: auto; padding: 3px 12px; background: rgba(120, 255, 170, .15); border-color: rgba(120, 255, 170, .6); color: var(--good); font-weight: 600; flex: none; }
#map-tools { position: absolute; right: 12px; bottom: 12px; display: flex; flex-direction: column; gap: 6px; }
#map-tools button { width: 34px; height: 34px; padding: 0; font-size: 18px; background: rgba(20, 26, 51, .85); }

#panel { width: 350px; background: var(--panel); border-left: 1px solid var(--line); display: flex; flex-direction: column; min-height: 0; }
#tabs { display: flex; border-bottom: 1px solid var(--line); }
#tabs button { flex: 1; border: 0; border-radius: 0; background: none; padding: 10px 4px; color: var(--muted); border-bottom: 2px solid transparent; }
#tabs button.on { color: var(--text); border-bottom-color: var(--accent); font-weight: 600; }
#tabs #panel-toggle { display: none; flex: 0 0 44px; font-size: 16px; color: var(--muted); }
#panel-body { flex: 1; overflow: auto; padding: 14px 16px 24px; }

/* ---------------------------------------------------------- panel content */
.title { display: flex; align-items: center; gap: 8px; }
.sub { color: var(--muted); margin: 2px 0 10px; }
.dot { display: inline-block; width: 10px; height: 10px; border-radius: 50%; margin-right: 6px; flex: none; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 4px 14px; margin: 10px 0; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; }
.btns { display: flex; gap: 6px; flex-wrap: wrap; margin-top: 8px; }
.btns.end { justify-content: flex-end; margin-top: 18px; }
.btns.tight button { padding: 5px 8px; flex: 1; }
.list { display: flex; flex-direction: column; gap: 4px; }
.row-btn { display: flex; justify-content: space-between; align-items: center; gap: 8px; text-align: left; width: 100%; }
.row-btn > span:first-child { display: flex; align-items: center; }
.row-btn > span.game-name { flex-direction: column; align-items: flex-start; }
.nowrap { white-space: nowrap; }
.account-line { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 8px; margin: 0 0 12px; }
.account-line button { margin-left: auto; }
.infra { width: 100%; border-collapse: collapse; margin-top: 6px; }
.infra td { padding: 5px 0; border-top: 1px solid var(--line); }
.infra td:last-child { text-align: right; }
.infra .num { padding-right: 14px; font-weight: 600; }
.route { margin: 0; padding-left: 20px; }
.route li span:last-child { float: right; }
.transfer { display: flex; justify-content: space-between; padding: 4px 2px; }

.techs { display: flex; flex-direction: column; gap: 10px; }
.tech { border: 1px solid var(--line); border-radius: 8px; padding: 10px; background: var(--panel-2); }
.tech.current { border-color: var(--accent); }
.tech-head, .tech-foot { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.tech-foot button { padding: 3px 8px; font-size: 12px; }
.bar { height: 5px; background: var(--line); border-radius: 3px; margin: 8px 0 6px; overflow: hidden; }
.bar span { display: block; height: 100%; background: var(--accent); }

.board { width: 100%; border-collapse: collapse; }
.board th, .board td { padding: 5px 4px; border-bottom: 1px solid var(--line); text-align: left; }
.board th { color: var(--muted); font-weight: 500; font-size: 12px; }
.board .num { text-align: right; }
.board tr.dead { opacity: .4; text-decoration: line-through; }
.log { display: flex; flex-direction: column; gap: 8px; font-size: 13px; }

/* ---------------------------------------------------------- chat */
.badge { padding: 0 6px; border-radius: 9px; font-size: 11px; border: 1px solid var(--line); color: var(--muted); }
#tabs .unread { margin-left: 5px; padding: 0 5px; border-radius: 9px; background: #ff5a5a; color: #fff; font-size: 11px; font-weight: 700; }
#tabs .unread[hidden] { display: none; }
.chat-list { display: flex; flex-direction: column; gap: 8px; padding-bottom: 8px; }
.msg { padding: 6px 9px; border-radius: 8px; background: var(--panel-2); border: 1px solid var(--line); }
.msg.mine { border-color: rgba(79, 163, 255, .45); }
.msg.private { border-style: dashed; }
.msg .meta { display: flex; align-items: center; gap: 4px 6px; flex-wrap: wrap; font-size: 12px; }
.msg .meta .small { margin-left: auto; }
.msg .text { margin-top: 3px; white-space: pre-wrap; overflow-wrap: anywhere; }
button.link { background: none; border: 0; padding: 0 2px; color: var(--accent); font-size: 12px; }
/* Stays at the bottom of the scrolling panel (which has 24px bottom padding). */
.chat-form { position: sticky; bottom: -24px; display: flex; flex-direction: column; gap: 6px; padding: 8px 0 10px; background: var(--panel); border-top: 1px solid var(--line); }
.chat-input { display: flex; gap: 6px; }
.chat-input input { flex: 1; min-width: 0; }
#lobby-chat .chat-list { max-height: 180px; overflow: auto; }
#lobby-chat .chat-form { position: static; }

/* ---------------------------------------------------------- overlays */
#toast {
  position: fixed; left: 50%; bottom: 24px; transform: translate(-50%, 20px);
  max-width: calc(100% - 32px); padding: 10px 16px; border-radius: 8px;
  background: #2a1320; border: 1px solid #ff6f8f; color: #ffd4de;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#modal { position: fixed; inset: 0; background: rgba(2, 3, 10, .7); display: grid; place-items: center; padding: 16px; backdrop-filter: blur(2px); }
#modal[hidden] { display: none; }
#modal-card { width: min(480px, 100%); max-height: 100%; overflow: auto; background: var(--panel); border: 1px solid var(--line); border-radius: 12px; padding: 22px; box-shadow: 0 20px 60px rgba(0, 0, 0, .6); }
#modal-card form { display: flex; flex-direction: column; gap: 12px; margin-top: 16px; }
#modal-card label { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
#modal-card label input, #modal-card label select { width: 60%; }
#modal-card details { margin-top: 18px; color: var(--muted); }
#modal-card summary { cursor: pointer; color: var(--text); }
#modal-card li { margin: 6px 0; }

@media (max-width: 760px) {
  main { flex-direction: column; }
  #panel { width: auto; height: 42vh; border-left: 0; border-top: 1px solid var(--line); }
  #panel.collapsed { height: auto; }
  #panel.collapsed #panel-body { display: none; }
  #panel.collapsed #tabs button.on { border-bottom-color: transparent; }
  #tabs #panel-toggle { display: block; }
  #tabs button { padding: 12px 4px; }
  #topbar { gap: 6px 10px; padding: 6px 16px; }
  #stats { order: 3; flex-basis: 100%; gap: 12px; font-size: 13px; }
  .brand { flex: 1; font-size: 18px; }
  .brand .name { display: none; }
  #stats { font-size: 12px; gap: 4px 12px; }
  .seg button { min-width: 34px; padding: 5px 6px; }
  .controls { gap: 6px; }
  .controls > button { padding: 5px 8px; }
  #hint { top: 8px; left: 8px; right: 8px; transform: none; max-width: none; justify-content: space-between; font-size: 12px; padding: 5px 6px 5px 10px; }
  #modal-card label { flex-direction: column; align-items: stretch; }
  #modal-card label input, #modal-card label select { width: 100%; }
}
