/* Freight Empire – układ, zmienne, pasek górny, nawigacja, lobby */
:root {
  --bg: #f3f5f3;
  --surface: #ffffff;
  --ink: #16304a;
  --ink-2: #51627a;
  --ink-3: #8794a6;
  --line: #e2e8e4;
  --route: #0e8fb0;
  --route-d: #0a6f8a;
  --navy: #16304a;
  --pos: #1f9d62;
  --neg: #d64545;
  --warn: #e8883a;
  --info: #3b6ea5;
  --shadow: 0 1px 2px rgba(22, 48, 74, 0.06), 0 4px 14px rgba(22, 48, 74, 0.07);
  --shadow-lg: 0 10px 40px rgba(22, 48, 74, 0.22);
  --r: 14px;
  --topbar: 56px;
  --safe-b: env(safe-area-inset-bottom, 0px);
}

* { box-sizing: border-box; }
html, body { height: 100%; margin: 0; }
body {
  font-family: system-ui, -apple-system, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, sans-serif;
  font-size: 15px;
  line-height: 1.4;
  color: var(--ink);
  background: var(--bg);
  overscroll-behavior: none;
  -webkit-tap-highlight-color: transparent;
  font-variant-numeric: tabular-nums;
}
h1, h2, h3, h4, p { margin: 0; }
button { font: inherit; color: inherit; }
b { font-weight: 650; }
.muted { color: var(--ink-2); }
.small { font-size: 12.5px; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.warn { color: var(--warn); }

#app { position: relative; height: 100dvh; display: flex; flex-direction: column; overflow: hidden; }

/* ---------- pasek górny */
.topbar {
  flex: none; height: var(--topbar); display: flex; align-items: center; justify-content: space-between; gap: 10px;
  padding: 0 12px; background: var(--navy); color: #fff; z-index: 30;
}
.brand { display: flex; align-items: center; gap: 10px; min-width: 0; }
.brand-text { display: flex; flex-direction: column; min-width: 0; line-height: 1.15; }
.brand-text b { font-size: 15px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw; }
.room-chip {
  all: unset; cursor: pointer; font-size: 11.5px; color: #a9c1d8; display: inline-flex; gap: 5px; align-items: center; letter-spacing: 0.04em;
}
.room-chip:hover { color: #fff; }
.version { margin-left: 4px; color: #4f6f8f; }
.clock { display: flex; flex-direction: column; align-items: flex-end; line-height: 1.15; color: #c8d8e8; font-variant-numeric: tabular-nums; }
.clock b { font-size: 14px; color: #fff; }
.clock small { font-size: 11px; }
.logo { width: 40px; height: 40px; border-radius: 12px; background: linear-gradient(135deg, #0e8fb0, #16578a); display: grid; place-items: center; color: #fff; flex: none; }
.logo.sm { width: 34px; height: 34px; border-radius: 10px; }
.top-right { display: flex; align-items: center; gap: 10px; }
.conn { display: flex; align-items: center; gap: 6px; font-size: 12px; color: #c8d8e8; }
.conn i { width: 9px; height: 9px; border-radius: 50%; background: var(--pos); box-shadow: 0 0 0 3px rgba(31, 157, 98, 0.25); }
.conn.wait i { background: #f2b84b; box-shadow: 0 0 0 3px rgba(242, 184, 75, 0.25); animation: pulse 1s infinite; }
.conn.bad i { background: var(--neg); box-shadow: 0 0 0 3px rgba(214, 69, 69, 0.25); }
@keyframes pulse { 50% { opacity: 0.4; } }
.players { display: flex; align-items: center; gap: 4px; }
.players .pc { font-size: 12px; color: #c8d8e8; margin-left: 4px; }
.avatar {
  width: 28px; height: 28px; border-radius: 50%; background: var(--c); color: #fff; display: grid; place-items: center;
  font-weight: 700; font-size: 13px; border: 2px solid var(--navy); box-shadow: 0 0 0 1.5px transparent; transition: box-shadow 0.2s;
}
.avatar.off { filter: grayscale(1); opacity: 0.45; }
.avatar.rdy { box-shadow: 0 0 0 2px var(--pos); }
.btn.ready { background: #fff; color: var(--navy); height: 38px; font-size: 13px; padding: 0 12px; white-space: nowrap; }
.btn.ready.on { background: var(--pos); color: #fff; }
.btn.ready:disabled { opacity: 0.5; }

.offline-banner {
  display: none; position: absolute; top: var(--topbar); left: 0; right: 0; z-index: 29; background: #8a2d2d; color: #fff;
  padding: 7px 14px; font-size: 13px; align-items: center; gap: 8px; justify-content: center;
}
.offline-banner.show { display: flex; }

/* ---------- układ główny */
.main { flex: 1; min-height: 0; display: flex; position: relative; }
.stage { position: relative; flex: 1; min-width: 0; overflow: hidden; background: #dfe8ee; }
.sidenav { display: none; }
.bottomnav {
  flex: none; display: grid; grid-template-columns: repeat(5, 1fr); background: #fff; border-top: 1px solid var(--line);
  padding-bottom: var(--safe-b); z-index: 25;
}
.bn-item {
  all: unset; box-sizing: border-box; position: relative; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 8px 2px 7px; font-size: 11px; color: var(--ink-2); cursor: pointer; min-height: 56px; justify-content: center;
}
.bn-item.on { color: var(--route-d); font-weight: 650; }
.bn-item.on::before { content: ''; position: absolute; top: 0; left: 28%; right: 28%; height: 3px; border-radius: 0 0 3px 3px; background: var(--route); }
.nbadge {
  position: absolute; top: 4px; left: calc(50% + 6px); min-width: 17px; height: 17px; border-radius: 9px; background: var(--warn); color: #fff;
  font-style: normal; font-size: 10.5px; font-weight: 700; display: grid; place-items: center; padding: 0 4px;
}
.nbadge.hot { background: var(--neg); }

/* panel: na telefonie nakładka lub dolny arkusz, na komputerze kolumna po prawej */
.panel { position: absolute; inset: 0; background: var(--bg); z-index: 20; display: none; }
#app:not([data-section='map']) .panel { display: block; }
#app[data-section='map'][data-city='1'] .panel {
  display: block; inset: auto 0 0 0; height: 58%; border-radius: 20px 20px 0 0; box-shadow: var(--shadow-lg); animation: slideUp 0.25s ease;
}
.panel-body { height: 100%; overflow-y: auto; overflow-x: hidden; padding: 14px 14px 24px; -webkit-overflow-scrolling: touch; }
@keyframes slideUp { from { transform: translateY(40px); opacity: 0; } to { transform: none; opacity: 1; } }

.view { display: flex; flex-direction: column; gap: 12px; max-width: 760px; margin: 0 auto; }
.view-head { display: flex; justify-content: space-between; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.view-head h2 { font-size: 20px; letter-spacing: -0.01em; }

@media (min-width: 900px) {
  :root { --topbar: 60px; }
  .sidenav {
    display: flex; flex-direction: column; gap: 4px; width: 86px; flex: none; background: #fff; border-right: 1px solid var(--line);
    padding: 10px 6px; overflow-y: auto; z-index: 15;
  }
  .nav-item {
    all: unset; box-sizing: border-box; position: relative; display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 10px 2px;
    border-radius: 12px; font-size: 11.5px; color: var(--ink-2); cursor: pointer; text-align: center;
  }
  .nav-item:hover { background: #f1f5f3; }
  .nav-item.on { background: #e3f3f7; color: var(--route-d); font-weight: 650; }
  .nav-item .nbadge { top: 4px; left: auto; right: 10px; }
  .bottomnav { display: none; }
  .panel, #app:not([data-section='map']) .panel, #app[data-section='map'][data-city='1'] .panel {
    display: block; position: relative; inset: auto; height: auto; width: clamp(400px, 34vw, 500px); flex: none; border-radius: 0; box-shadow: none;
    border-left: 1px solid var(--line); animation: none;
  }
  .brand-text b { max-width: 300px; }
}
@media (max-width: 899px) {
  .topbar { padding: 0 8px; }
  .conn span { display: none; }
  .players .pc { display: none; }
  .btn.ready { padding: 0 10px; font-size: 12px; height: 36px; }
  .btn.ready span { max-width: 38vw; overflow: hidden; text-overflow: ellipsis; }
  .logo.sm { display: none; }
  .brand-text b { max-width: 30vw; }
}
@media (max-width: 380px) {
  .players { display: none; }
}

/* ---------- lobby */
.lobby {
  min-height: 100dvh; display: grid; place-items: center; padding: 20px;
  background: radial-gradient(1200px 600px at 20% -10%, #cfe6ee 0%, transparent 60%), radial-gradient(900px 500px at 110% 110%, #dbe9d3 0%, transparent 55%), var(--bg);
}
.lobby-card { width: min(440px, 100%); background: #fff; border-radius: 22px; padding: 24px; box-shadow: var(--shadow-lg); display: flex; flex-direction: column; gap: 14px; }
.logo-row { display: flex; gap: 14px; align-items: center; }
.logo-row h1 { font-size: 24px; letter-spacing: -0.02em; }
.logo-row p { color: var(--ink-2); font-size: 13.5px; }
.form-error { color: var(--neg); min-height: 18px; font-size: 13.5px; }
.code-input { text-transform: uppercase; letter-spacing: 0.4em; text-align: center; font-weight: 700; font-size: 22px; }
.lobby .btn { width: 100%; }

.perf-btn { width: 38px; height: 38px; border-radius: 11px; border: 1.5px solid rgba(255,255,255,0.28); background: transparent; color: #c8d8e8; display: grid; place-items: center; cursor: pointer; flex: none; padding: 0; }
.perf-btn.on { background: #f2b84b; border-color: #f2b84b; color: var(--navy); }
@media (max-width: 899px) { .perf-btn { width: 36px; height: 36px; } .top-right { gap: 6px; } }

/* ---------- konta, profil, czat */
.form-info { color: var(--pos); min-height: 0; font-size: 13.5px; }
.form-info:empty { display: none; }
.auth form { display: flex; flex-direction: column; gap: 12px; }
.auth h2 { font-size: 18px; }
.check { display: flex; align-items: center; gap: 8px; font-size: 13.5px; color: var(--ink-2); cursor: pointer; }
.check input { width: 18px; height: 18px; accent-color: var(--route); }
.lobby-user { display: flex; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 12px; background: #f1f5f3; }
.lobby-user > div { flex: 1; min-width: 0; }
.avatar-img { display: block; border-radius: 50%; flex: none; }
.avatar.pic { padding: 0; overflow: hidden; background: #fff; cursor: pointer; }
.avatar.pic img { width: 100%; height: 100%; }
button.avatar { cursor: pointer; }
.profile-head { display: flex; gap: 14px; align-items: center; }
.profile-head h2 { font-size: 20px; }
.profile-head .bio { margin-top: 6px; color: var(--ink-2); white-space: pre-wrap; overflow-wrap: anywhere; }
.avatar-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 8px; max-width: 320px; }
.avatar-pick { all: unset; box-sizing: border-box; cursor: pointer; border-radius: 50%; padding: 3px; border: 2.5px solid transparent; justify-self: center; }
.avatar-pick.on { border-color: var(--route); }
.avatar-pick:focus-visible { outline: 2px solid var(--route); outline-offset: 2px; }
.badges { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 8px; }
.badge-item { display: flex; gap: 10px; align-items: flex-start; padding: 8px 10px; border-radius: 12px; background: #fbf6ea; }
.badge-item small { display: block; }
.badge-ico { width: 28px; height: 28px; border-radius: 50%; background: #f2b84b; color: #fff; display: grid; place-items: center; flex: none; }
.link.inline { padding: 0; font-size: inherit; }
.chat-view { height: 100%; }
.chat-list { flex: 1; min-height: 260px; max-height: calc(100dvh - 330px); overflow-y: auto; display: flex; flex-direction: column; gap: 10px; padding: 10px; background: #fff; border-radius: var(--r); box-shadow: var(--shadow); }
.chat-msg { display: flex; gap: 8px; align-items: flex-start; }
.chat-msg p { margin-top: 2px; overflow-wrap: anywhere; white-space: pre-wrap; }
.chat-msg.mine b { color: var(--route-d); }
.chat-meta { display: flex; gap: 8px; align-items: baseline; }
.chat-ava { all: unset; cursor: pointer; border-radius: 50%; }
.chat-ava:focus-visible { outline: 2px solid var(--route); }
.chat-empty { margin: auto; }
.chat-form { display: flex; gap: 8px; }
.chat-form input { flex: 1; }
.chat-form .btn { width: 48px; padding: 0; flex: none; }
.nbadge.inline { position: static; display: inline-grid; margin-left: 6px; vertical-align: middle; }
