/* Marny Rozstrój - retro 8-bit UI v2 */
* { box-sizing: border-box; margin: 0; padding: 0; }
:root {
  --ink: #14100c;
  --paper: #e8d9b0;
  --sea: #1b4d6b;
  --gold: #d9a520;
  --red: #c8342a;
  --green: #2e8b46;
  --ui: #241d14;
  --ui2: #382d1d;
  --ui-border: #6b5636;
  --txt: #e8d9b0;
}
html, body { height: 100%; }
body {
  background: #0d0a07;
  color: var(--txt);
  font-family: 'VT323', monospace;
  font-size: 19px;
  overflow: hidden;
  image-rendering: pixelated;
}
.hidden { display: none !important; }
.screen { position: fixed; inset: 0; }

/* ---------- MENU ---------- */
#screen-menu {
  display: flex; align-items: center; justify-content: center;
  background:
    repeating-linear-gradient(0deg, transparent 0 3px, rgba(0,0,0,.18) 3px 4px),
    radial-gradient(ellipse at 50% 30%, #1e5674 0%, #12374e 55%, #0a1e2c 100%);
}
.menu-box {
  background: var(--ui);
  border: 4px solid var(--ui-border);
  box-shadow: 0 0 0 4px var(--ink), 8px 8px 0 rgba(0,0,0,.5);
  padding: 28px 34px;
  width: min(480px, 92vw);
  max-height: 92vh; overflow-y: auto;
  text-align: center;
}
.title {
  font-family: 'Press Start 2P', monospace;
  font-size: 28px; line-height: 1.4;
  color: var(--gold);
  text-shadow: 3px 3px 0 var(--ink);
  margin-bottom: 8px;
}
.subtitle { color: #9a8f81; margin-bottom: 22px; font-size: 18px; }
input {
  font-family: 'VT323', monospace; font-size: 22px;
  background: var(--ink); color: var(--txt);
  border: 3px solid var(--ui-border);
  padding: 8px 12px; width: 100%; margin-bottom: 12px;
  text-align: center; outline: none;
}
input:focus { border-color: var(--gold); }
.btn {
  font-family: 'Press Start 2P', monospace; font-size: 12px;
  background: var(--gold); color: var(--ink);
  border: 0; border-bottom: 4px solid #7a5a08;
  padding: 12px 16px; cursor: pointer;
  text-transform: uppercase;
  position: relative;
}
.btn:hover { filter: brightness(1.12); }
.btn:active { border-bottom-width: 1px; transform: translateY(3px); }
.btn.big { width: 100%; padding: 15px; font-size: 14px; margin-bottom: 12px; }
.btn.tiny { font-size: 9px; padding: 6px 9px; border-bottom-width: 2px; }
.btn.ghost { background: transparent; color: var(--gold); border: 2px solid var(--gold); }
.btn.danger { background: var(--red); color: #fff; border-bottom-color: #7a1712; }
.badge {
  position: absolute; top: -8px; right: -8px;
  background: var(--red); color: #fff;
  font-family: 'VT323', monospace; font-size: 14px;
  min-width: 18px; height: 18px; line-height: 18px;
  border: 2px solid var(--ink);
}
.join-row { display: flex; gap: 10px; }
.join-row input { width: 40%; margin: 0; text-transform: uppercase; }
.join-row .btn { flex: 1; }
.code { color: var(--gold); font-family: 'Press Start 2P', monospace; font-size: 18px; letter-spacing: 4px; }
#lobby-players { margin: 14px 0; text-align: left; }
.lobby-player { padding: 6px 10px; border: 2px solid var(--ui-border); margin-bottom: 6px; display: flex; align-items: center; gap: 10px; }
.lobby-player .dot { width: 14px; height: 14px; display: inline-block; border: 2px solid var(--ink); }
#faction-pick { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
.fbtn { width: 64px; padding: 6px 2px; font-family: 'VT323', monospace; font-size: 15px; cursor: pointer; border: 3px solid var(--ui-border); background: var(--ink); color: var(--txt); }
.fbtn.mine { border-color: var(--gold); }
.fbtn.taken { opacity: .4; cursor: default; }
.lobby-actions { display: flex; gap: 8px; }
.lobby-actions .btn.big { flex: 1; margin: 0; }
.hint { color: #9a8f81; font-size: 16px; margin-top: 12px; }
.msg { color: var(--red); min-height: 22px; margin-top: 10px; font-size: 18px; }

/* ---------- GRA ---------- */
#screen-game { display: flex; flex-direction: column; }
#topbar {
  height: 58px; flex: none;
  background: var(--ui); border-bottom: 4px solid var(--ui-border);
  display: flex; align-items: center; gap: 14px; padding: 0 14px;
}
#phase-info { display: flex; align-items: baseline; gap: 14px; white-space: nowrap; }
#round-label { color: #9a8f81; }
#phase-label { font-family: 'Press Start 2P', monospace; font-size: 14px; color: var(--gold); }
#phase-timer { font-family: 'Press Start 2P', monospace; font-size: 17px; color: #fff; min-width: 56px; }
#phase-timer.low { color: var(--red); animation: blink .5s steps(2) infinite; }
@keyframes blink { 50% { opacity: .3; } }
#phase-bar { flex: 1; height: 16px; background: var(--ink); border: 2px solid var(--ui-border); min-width: 80px; }
#phase-bar-fill { height: 100%; background: var(--gold); width: 100%; transition: width .3s linear; }
#phase-hint { color: #bdb09a; font-size: 17px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 34vw; }

#main-row { flex: 1; display: flex; min-height: 0; }
#map-wrap { flex: 1; position: relative; overflow: hidden; background: #0f2f42; min-width: 0; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; cursor: grab; }
#map.dragging { cursor: grabbing; }
#map-hint {
  position: absolute; left: 10px; top: 10px;
  background: rgba(20,16,12,.85); padding: 5px 10px; font-size: 17px;
  border: 2px solid var(--ui-border); pointer-events: none;
  min-height: 20px;
}

/* ticker jako nakładka na mapie */
#ticker {
  position: absolute; left: 10px; bottom: 10px;
  width: min(430px, 44%); height: 116px;
  background: rgba(12,9,6,.82);
  border: 2px solid var(--ui-border);
  overflow: hidden;
}
#ticker-lines { position: absolute; inset: 0; overflow-y: auto; padding: 5px 10px; display: flex; flex-direction: column-reverse; }
.tick-line { font-size: 16px; color: #bdb09a; padding: 1px 0; line-height: 1.25; }
.tick-line .rnd { color: #6b5636; }
.tick-line.alert { color: var(--gold); }
.tick-line.chat { color: #7fc7e8; }

/* ---------- boczne paski ---------- */
#side {
  width: 300px; flex: none;
  background: var(--ui); border-left: 4px solid var(--ui-border);
  padding: 8px; display: flex; flex-direction: column; gap: 8px;
  overflow-y: auto;
}
#side-left {
  width: 300px; flex: none;
  background: var(--ui); border-right: 4px solid var(--ui-border);
  padding: 8px; display: flex; flex-direction: column; gap: 8px;
  overflow-y: auto;
}
#side-left .panel { flex: 1; }
.panel { border: 3px solid var(--ui-border); background: rgba(0,0,0,.25); padding: 8px; }
.panel-title { font-family: 'Press Start 2P', monospace; font-size: 10px; color: var(--gold); margin-bottom: 8px; display: flex; justify-content: space-between; align-items: center; }

.pl-row { display: flex; align-items: center; gap: 8px; padding: 3px 6px; border: 2px solid transparent; font-size: 17px; }
.pl-row.me { border-color: var(--gold); }
.pl-row .dot { width: 13px; height: 13px; border: 2px solid var(--ink); flex: none; }
.pl-row .nm { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.pl-row .tr { color: #9a8f81; font-size: 15px; white-space: nowrap; }
.pl-row .off { color: var(--red); font-size: 13px; }

/* tory przywództwa - plansza */
#tracks-board { display: flex; gap: 6px; justify-content: space-between; }
.track {
  flex: 1; position: relative;
  background: var(--ink);
  border: 2px solid var(--ui-border);
  height: 240px;
}
.track .t-name {
  position: absolute; top: 2px; left: 0; right: 0;
  text-align: center;
  font-family: 'Press Start 2P', monospace; font-size: 8px;
  color: var(--gold); z-index: 2;
}
.track .t-holder {
  position: absolute; top: 14px; left: 0; right: 0;
  text-align: center; font-size: 13px; color: #9a8f81; z-index: 2;
  overflow: hidden; white-space: nowrap;
}
.track .t-line { position: absolute; left: 0; right: 0; height: 1px; background: rgba(107,86,54,.4); }
.track .t-lvl { position: absolute; right: 3px; font-size: 11px; color: #6b5636; transform: translateY(-55%); }
.track .t-token {
  position: absolute;
  width: 20px; height: 20px;
  border: 2px solid var(--ink);
  font-family: 'VT323', monospace; font-size: 13px;
  color: #fff; text-align: center; line-height: 17px;
  transition: top .6s ease;
  z-index: 3;
  text-shadow: 1px 1px 0 #000;
}
.track .t-token.leader { box-shadow: 0 0 0 2px var(--gold); z-index: 4; }

/* karty herosów */
#hero-cards { display: grid; grid-template-columns: 1fr; gap: 6px; }
.hero-card {
  border: 2px solid var(--ui-border);
  background: var(--ink);
  padding: 6px 7px;
  font-size: 15px;
  line-height: 1.15;
  cursor: default;
  position: relative;
  min-height: 62px;
}
.hero-card b { color: var(--gold); font-size: 16px; display: block; margin-bottom: 2px; }
.hero-card .hc-desc { color: #bdb09a; font-size: 13px; }
.hero-card .hc-cost {
  position: absolute; top: 4px; right: 5px;
  font-family: 'Press Start 2P', monospace; font-size: 10px;
  color: var(--gold);
}
.hero-card.owned { opacity: .95; }
.hero-card.owned b { color: #bdb09a; }
.hero-card.buyable { cursor: pointer; }
.hero-card.buyable:hover { border-color: var(--gold); }
.hero-card.pyramids { grid-column: 1 / 3; border-color: var(--gold); }
.hero-card .hc-owner { position: absolute; top: 4px; right: 5px; width: 14px; height: 14px; border: 2px solid var(--ink); }

/* ---------- dolny pasek ---------- */
#bottombar {
  height: 168px; flex: none;
  background: var(--ui); border-top: 4px solid var(--ui-border);
  display: flex; gap: 8px; padding: 8px;
}
#inv-panel { flex: 1.1; border: 3px solid var(--ui-border); background: rgba(0,0,0,.25); padding: 8px; overflow-y: auto; }
#inv-hidden-note { font-family: 'VT323', monospace; font-size: 13px; color: #9a8f81; text-transform: none; }
#inv-items { display: flex; flex-wrap: wrap; gap: 8px; align-items: flex-start; }
.inv-item {
  display: flex; flex-direction: column; align-items: center; gap: 2px;
  border: 3px solid var(--ui-border); padding: 6px 8px; font-size: 16px;
  background: var(--ink); cursor: pointer; user-select: none;
  min-width: 74px;
}
.inv-item:hover { border-color: #9a8f81; }
.inv-item.inpay { border-color: var(--gold); background: #3a2f16; }
.inv-item canvas { width: 32px; height: 32px; image-rendering: pixelated; }
.inv-item .n { color: var(--gold); font-size: 18px; }
.inv-item .lbl { font-size: 14px; color: #bdb09a; }
#pay-summary { width: 100%; font-size: 18px; margin-top: 4px; }

#action-panel { flex: 1.6; border: 3px solid var(--ui-border); background: rgba(0,0,0,.25); padding: 8px; overflow-y: auto; }
.shop-grid { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 6px; }
.shop-btn { font-family: 'VT323', monospace; font-size: 17px; background: var(--ink); color: var(--txt); border: 2px solid var(--ui-border); padding: 7px 9px; cursor: pointer; text-align: left; display: flex; justify-content: space-between; gap: 6px; }
.shop-btn:hover { border-color: var(--gold); }
.shop-btn .c { color: var(--gold); }
.shop-btn:disabled { opacity: .35; cursor: default; }
.offer-row { border: 2px solid var(--ui-border); padding: 5px 8px; margin-bottom: 5px; font-size: 17px; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
.offer-row .who { font-weight: bold; }
.res-chip { display: inline-flex; align-items: center; gap: 3px; background: #241d14; border: 1px solid var(--ui-border); padding: 1px 6px; font-size: 15px; }
.picker { display: flex; flex-wrap: wrap; gap: 4px; margin: 6px 0; }
.picker .pick { cursor: pointer; border: 2px solid var(--ui-border); padding: 2px 7px; font-size: 16px; background: var(--ink); user-select: none; }
.picker .pick.sel { border-color: var(--gold); background: #3a2f16; }

/* czat */
#chat-panel {
  position: absolute; right: 10px; bottom: 10px;
  width: 360px; height: 300px;
  background: rgba(20,16,12,.96);
  border: 3px solid var(--ui-border);
  box-shadow: 6px 6px 0 rgba(0,0,0,.5);
  display: flex; flex-direction: column;
  z-index: 35;
}
#chat-tabs { display: flex; gap: 3px; padding: 5px 5px 0; border-bottom: 2px solid var(--ui-border); flex-wrap: wrap; }
.chat-tab {
  font-size: 15px; padding: 3px 9px; cursor: pointer;
  background: var(--ink); border: 2px solid var(--ui-border); border-bottom: 0;
  position: relative; user-select: none;
}
.chat-tab.active { background: var(--ui2); color: var(--gold); }
.chat-tab .badge { top: -7px; right: -7px; }
#chat-msgs { flex: 1; overflow-y: auto; padding: 6px 9px; font-size: 16px; }
.chat-msg { margin-bottom: 3px; line-height: 1.25; }
.chat-msg .cm-from { font-weight: bold; }
.chat-msg.priv { color: #e8c8e0; }
#chat-inputrow { padding: 5px; border-top: 2px solid var(--ui-border); }
#chat-inputrow input { margin: 0; font-size: 18px; padding: 5px 9px; text-align: left; }

/* popup prowincji */
#prov-popup {
  position: fixed; z-index: 30;
  background: var(--ui); border: 3px solid var(--ui-border);
  box-shadow: 6px 6px 0 rgba(0,0,0,.5);
  padding: 10px 12px; min-width: 250px; max-width: 320px; font-size: 17px;
}
#prov-popup h3 { font-family: 'Press Start 2P', monospace; font-size: 11px; color: var(--gold); margin-bottom: 6px; }
#prov-popup .row { margin: 3px 0; display: flex; align-items: center; gap: 6px; flex-wrap: wrap; }
#prov-popup .actions { margin-top: 8px; display: grid; grid-template-columns: 1fr 1fr; gap: 5px; }

/* modal */
#modal-wrap { position: fixed; inset: 0; background: rgba(0,0,0,.6); z-index: 50; display: flex; align-items: center; justify-content: center; }
#modal { background: var(--ui); border: 4px solid var(--ui-border); box-shadow: 8px 8px 0 rgba(0,0,0,.6); padding: 20px; width: min(560px, 94vw); max-height: 90vh; overflow-y: auto; }
#modal h2 { font-family: 'Press Start 2P', monospace; font-size: 13px; color: var(--gold); margin-bottom: 12px; }
#modal .mrow { margin-bottom: 10px; }
#modal select { font-family: 'VT323', monospace; font-size: 19px; background: var(--ink); color: var(--txt); border: 3px solid var(--ui-border); padding: 6px; width: 100%; }
#modal .btns { display: flex; gap: 8px; margin-top: 14px; }
#modal .btns .btn { flex: 1; }
.contract-row { border: 2px solid var(--ui-border); padding: 6px 9px; margin-bottom: 6px; font-size: 17px; }
.contract-row .st { color: #9a8f81; font-size: 14px; }
.contract-row .st.aktywny { color: var(--green); }
.contract-row .st.zerwany { color: var(--red); }
.contract-row .btns { margin-top: 5px; display: flex; gap: 6px; }

/* toast */
#toast {
  position: fixed; top: 70px; left: 50%; transform: translateX(-50%);
  background: var(--red); color: #fff; font-size: 18px;
  padding: 8px 16px; border: 3px solid var(--ink);
  opacity: 0; pointer-events: none; transition: opacity .3s; z-index: 60;
}
#toast.show { opacity: 1; }
#toast.info { background: var(--ui2); color: var(--txt); border-color: var(--gold); }

/* bitwa overlay */
#battle-overlay {
  position: absolute; z-index: 40; left: 50%; top: 44%; transform: translate(-50%, -50%);
  background: rgba(20,16,12,.96); border: 4px solid var(--gold);
  box-shadow: 0 0 0 4px var(--ink), 10px 10px 0 rgba(0,0,0,.6);
  padding: 18px 24px; text-align: center; min-width: 420px; max-width: 60%;
}
#battle-overlay h2 { font-family: 'Press Start 2P', monospace; font-size: 14px; color: var(--red); margin-bottom: 12px; }
.battle-sides { display: flex; justify-content: space-between; gap: 20px; margin-bottom: 10px; }
.battle-side { flex: 1; }
.battle-side .bname { font-size: 19px; margin-bottom: 6px; font-weight: bold; }
.dice-row { display: flex; flex-wrap: wrap; gap: 5px; justify-content: center; min-height: 38px; }
.die { width: 34px; height: 34px; background: #e8d9b0; color: var(--ink); border: 3px solid var(--ink); display: flex; align-items: center; justify-content: center; font-family: 'Press Start 2P', monospace; font-size: 12px; }
.die.sea { background: #9cc7e0; }
.die.rolling { animation: roll .1s steps(2) infinite; }
@keyframes roll { 50% { transform: rotate(12deg) translateY(-3px); } }
.battle-sum { font-size: 21px; margin-top: 6px; }
.battle-sum b { color: var(--gold); }
.battle-result { font-family: 'Press Start 2P', monospace; font-size: 11px; margin-top: 10px; min-height: 30px; line-height: 1.6; }
.conquest-opts { display: flex; flex-direction: column; gap: 8px; margin-top: 10px; }

@media (max-width: 1100px) {
  #side { width: 290px; }
  body { font-size: 17px; }
}
