:root {
  --bg: #e4e2d3;
  --panel: #f1efe4;
  --panel-2: #d6d3bd;
  --ink: #23271b;
  --muted: #676b55;
  --line: #b5b394;
  --accent: #4b5a2a;
  --accent-ink: #f3f1e4;
  --ok: #3d6b2a;
  --bad: #a3321f;
  --steel: #6f7d8c;
  --fuel: #c08a1e;
  --ammo: #8a6d3b;
  --grass: #a4a57a;
  --grass-2: #9a9b70;
  --mine: #e0b100;
  --enemy: #b8402c;
  --barb: #5a5f4c;
  --ally: #2f6fb0;
  --bar-dark: #262a1c;
  --bar-mid: #3a4128;
  --bar-text: #e3e3cf;
  --bar-dim: #aeb092;
  --gold: #d9c46a;
  --font: "Segoe UI", "Helvetica Neue", Arial, sans-serif;
  --head: "Impact", "Arial Narrow", "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body { background: var(--bg); color: var(--ink); font: 15px/1.45 var(--font); min-height: 100vh; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); min-height: 1.3em; }
.ok { color: var(--ok); }
.bad { color: var(--bad); }
button { font: inherit; cursor: pointer; border: 1px solid var(--accent); background: var(--accent); color: var(--accent-ink); padding: 6px 12px; border-radius: 4px; }
button:hover:not(:disabled) { filter: brightness(1.1); }
button:disabled { background: var(--panel-2); color: var(--muted); border-color: var(--line); cursor: not-allowed; }
button.secondary { background: transparent; color: var(--accent); }
button.link { background: none; border: none; color: var(--accent); padding: 0; text-decoration: underline; }
button.small { padding: 2px 8px; font-size: 13px; }
input, select { font: inherit; padding: 5px 8px; border: 1px solid var(--line); border-radius: 4px; background: #fffdf7; color: var(--ink); }
input[type=number] { width: 80px; }

/* Logowanie */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 16px;
  background: repeating-linear-gradient(135deg, #3a4128 0 22px, #353b24 22px 44px); }
.auth-card { width: min(380px, 100%); background: var(--panel); border: 1px solid var(--line); border-radius: 8px; padding: 28px; box-shadow: 0 10px 40px rgba(0, 0, 0, .45); border-top: 6px solid var(--accent); }
.auth-card h1 { margin: 0; font: 48px var(--head); letter-spacing: 8px; color: var(--accent); }
.tagline { margin: 4px 0 20px; color: var(--muted); }
.auth-card label { display: grid; gap: 4px; margin-bottom: 12px; }
.auth-tabs { display: flex; gap: 0; margin-bottom: 16px; border-bottom: 2px solid var(--line); }
.auth-tabs button { flex: 1; background: transparent; border: none; border-radius: 0; color: var(--muted); padding: 8px 4px; margin-bottom: -2px; border-bottom: 2px solid transparent; }
.auth-tabs button.active { color: var(--accent); border-bottom-color: var(--accent); font-weight: bold; }
.auth-notice { padding: 10px 12px; border: 1px solid var(--ok); background: #e3ecd0; color: var(--ok); border-radius: 4px; margin-bottom: 14px; }
.auth-notice.err { border-color: var(--bad); background: #f5dcd5; color: var(--bad); }
.auth-form .hint { font-size: 13px; margin: 8px 0 0; }
.auth-form .resend { margin: 0; }
.account-form { display: grid; gap: 10px; max-width: 360px; }
.account-form label { display: grid; gap: 4px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }

/* Górny pasek */
.topbar { display: flex; flex-wrap: wrap; align-items: center; gap: 12px 24px; padding: 10px 16px; background: var(--bar-dark); color: var(--bar-text); }
.brand { font: 26px var(--head); letter-spacing: 4px; color: var(--gold); }
.village-pick select { background: var(--bar-mid); color: var(--bar-text); border-color: #59603f; }
.village-pick .muted { color: var(--bar-dim); margin-left: 6px; }
.resources { display: flex; gap: 16px; flex-wrap: wrap; flex: 1; }
.res { display: flex; align-items: center; gap: 6px; font-variant-numeric: tabular-nums; }
.res .dot { width: 12px; height: 12px; border-radius: 2px; display: inline-block; }
.res.full .val { color: #ff9b7a; }
.res small { color: var(--bar-dim); }
.me { display: flex; gap: 10px; align-items: center; }
.me .link { color: var(--gold); }

.tabs { display: flex; flex-wrap: wrap; gap: 2px; padding: 0 16px; background: var(--bar-mid); }
.tabs button { background: transparent; border: none; border-radius: 0; color: var(--bar-text); padding: 10px 12px; text-transform: uppercase; font-size: 13px; letter-spacing: 1px; white-space: nowrap; }
.tabs button.active { background: var(--bg); color: var(--ink); }
.badge { background: var(--bad); color: #fff; border-radius: 10px; padding: 0 6px; font-size: 12px; margin-left: 4px; }

main { padding: 16px; max-width: 1100px; margin: 0 auto; }
h2 { margin: 4px 0 12px; font: 26px var(--head); letter-spacing: 1.5px; text-transform: uppercase; font-weight: normal; }
h2 .muted { font: 16px var(--font); text-transform: none; letter-spacing: 0; }
h3 { margin: 18px 0 8px; }
.panel { background: var(--panel); border: 1px solid var(--line); border-radius: 6px; padding: 14px; margin-bottom: 14px; }
.grid2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 14px; }

table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { background: var(--panel-2); font-weight: normal; color: var(--muted); font-size: 13px; }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
.cost { display: flex; gap: 10px; flex-wrap: wrap; font-variant-numeric: tabular-nums; font-size: 14px; }
.cost span.lack { color: var(--bad); }
.desc { font-size: 13px; color: var(--muted); }
.table-wrap { overflow-x: auto; }

.queue li { margin: 4px 0; }
.timer { font-variant-numeric: tabular-nums; font-weight: bold; }
.bar { height: 8px; background: var(--panel-2); border-radius: 4px; overflow: hidden; margin-top: 4px; }
.bar > div { height: 100%; background: var(--ok); }

/* Mapa */
.map-wrap { display: grid; grid-template-columns: minmax(0, 1fr) 280px; gap: 14px; }
@media (max-width: 760px) { .map-wrap { grid-template-columns: 1fr; } }
.map-grid { display: grid; gap: 1px; background: var(--line); border: 1px solid var(--line); aspect-ratio: 1; width: 100%; max-width: 640px; }
.tile { background: var(--grass); border: none; border-radius: 0; padding: 0; color: transparent; position: relative; min-width: 0; display: grid; place-items: center; }
.tile:nth-child(odd) { background: var(--grass-2); }
.tile .ic { position: absolute; inset: 14%; width: 72%; height: 72%; filter: drop-shadow(0 1px 0 rgba(0, 0, 0, .35)); }
.tile.v:hover { filter: brightness(1.12); }
.tile.sel { outline: 3px solid var(--accent); outline-offset: -3px; z-index: 1; }
.tile.out { background: #4e533c; }
.map-nav { display: flex; gap: 6px; align-items: center; margin-bottom: 8px; flex-wrap: wrap; }
.legend { display: flex; gap: 12px; flex-wrap: wrap; font-size: 13px; margin-top: 8px; }
.legend .ic { width: 16px; height: 16px; }

.report-row { cursor: pointer; }
.report-row.unread td:first-child { font-weight: bold; }
.won { color: var(--ok); }
.lost { color: var(--bad); }

.toast { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--bar-dark); color: var(--bar-text); padding: 10px 18px; border-radius: 6px; box-shadow: 0 4px 16px rgba(0,0,0,.3); max-width: 90vw; }
.toast.err { background: var(--bad); color: #fff; }

.cls { display: inline-block; font-size: 11px; text-transform: uppercase; letter-spacing: .5px; padding: 0 5px; border-radius: 3px; margin-right: 4px; color: #fff; }
.cls-inf { background: #5b6b35; }
.cls-armor { background: #6a5a3a; }
.cls-air { background: #3e5a78; }

/* ───── Ikony ───── */
.ic { width: 1.15em; height: 1.15em; vertical-align: -0.2em; flex-shrink: 0; }
.ic .cut { fill: #000; fill-opacity: .35; }
.ic-res { width: 20px; height: 20px; }
.ic-row { width: 22px; height: 22px; margin-right: 4px; color: var(--accent); vertical-align: middle; }
.ic-th { width: 26px; height: 26px; color: var(--accent); }
.brand .ic { color: var(--gold); width: 24px; height: 24px; vertical-align: -3px; }
.auth-card h1 .ic { width: 40px; height: 40px; vertical-align: -4px; }
.tabs button .ic { margin-right: 6px; width: 17px; height: 17px; vertical-align: -3px; }
.tabs button.active .ic { color: var(--accent); }
button .ic { vertical-align: -3px; }
.cost .ic { width: 15px; height: 15px; margin-right: 3px; vertical-align: -3px; }
.cost > span[title="Personel"] .ic { color: var(--muted); }
.res .ic-res { color: var(--bar-text); }
.timer + .ic, td.num > .ic { color: var(--muted); }
.with-tile { display: flex; gap: 10px; align-items: center; }
.tile-ic { width: 46px; height: 46px; border-radius: 6px; display: grid; place-items: center; background: var(--panel-2); color: var(--accent); flex-shrink: 0; border: 1px solid var(--line); }
.tile-ic .ic { width: 34px; height: 34px; }
.tile-ic.cls-bg-inf { background: #dfe3c8; color: #4a5a24; }
.tile-ic.cls-bg-armor { background: #e6dcc5; color: #5d4b2c; }
.tile-ic.cls-bg-air { background: #d5dfe8; color: #2f4a66; }
.stats { display: flex; flex-wrap: wrap; gap: 4px 10px; align-items: center; margin-top: 2px; }
.stats .ic { color: var(--ink); opacity: .75; margin-right: 2px; }
.unit-list { display: inline-flex; flex-wrap: wrap; gap: 4px 10px; }
.unit-list .ic { width: 20px; height: 20px; color: var(--accent); margin-right: 2px; }
tr.dim td { opacity: .5; }
.queue .ic { color: var(--accent); width: 20px; height: 20px; }
td.bad .ic, .won .ic, .lost .ic { width: 16px; height: 16px; }
.medal .ic { width: 16px; height: 16px; margin-right: 4px; }
.medal.m1 { color: #c9a227; } .medal.m2 { color: #9aa3ab; } .medal.m3 { color: #a8693a; }
.tile.mine, .legend .mine .ic, .map-title.mine .ic { color: var(--mine); }
.tile.enemy, .legend .enemy .ic, .map-title.enemy .ic { color: var(--enemy); }
.tile.barb, .legend .barb .ic, .map-title.barb .ic { color: var(--barb); }

/* ───── Przejmowanie baz ───── */
.loyalty { margin-top: 12px; padding-top: 10px; border-top: 1px solid var(--line); }
.loyalty .ic { color: var(--accent); margin-right: 4px; }
.loyalty .bar { margin: 6px 0 4px; height: 10px; }
.howto { display: flex; gap: 12px; align-items: flex-start; font-size: 14px; line-height: 1.5; }
.howto .ic-row { width: 40px; height: 40px; flex-shrink: 0; }
.loyalty-report { display: flex; align-items: center; gap: 6px; font-size: 16px; }
.loyalty-report.conquered { background: #e3ecd0; border-color: var(--ok); color: var(--ok); }
.loyalty-report.conquered .ic-row { color: var(--ok); }

/* ───── Drużyny ───── */
.tile.ally, .legend .ally .ic, .map-title.ally .ic { color: var(--ally); }
.tag { display: inline-block; font: 600 11px/1.6 var(--font); letter-spacing: .5px; padding: 0 5px; border-radius: 3px; background: #545b46; color: #fff; vertical-align: 1px; }
.tag.big { font-size: 18px; padding: 0 8px; vertical-align: 3px; background: var(--ally); }
button.danger { background: var(--bad); border-color: var(--bad); }
.admin-ic { color: #c9a227 !important; }
.desc .ic { vertical-align: -3px; color: var(--ally); }

/* ───── Wsparcie ───── */
button.ally-btn { background: var(--ally); border-color: var(--ally); }
button.ally-btn:disabled, button.danger:disabled { background: var(--panel-2); color: var(--muted); border-color: var(--line); }
.ally-text, .ally-text .ic { color: var(--ally); }
.note { display: flex; gap: 8px; align-items: center; border-color: var(--ally); background: #e1e9f2; }
.note .ic-row { color: var(--ally); }
td .unit-list { margin-top: 4px; }

button.secondary:disabled, button.link:disabled { opacity: .4; background: transparent; }

/* ───── Przewijana mapa ───── */
main:has(.map-wrap2) { max-width: 1400px; }
.map-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 8px; }
.map-tools { display: flex; flex-wrap: wrap; align-items: center; gap: 8px; }
.map-tools .zoom-btns button { width: 30px; font-weight: bold; }
.map-jump { display: flex; align-items: center; gap: 4px; }
.map-jump input { width: 64px; padding: 3px 6px; }
.map-wrap2 { display: grid; grid-template-columns: minmax(0, 1fr) 232px; gap: 14px; margin-top: 8px; }
@media (max-width: 820px) { .map-wrap2 { grid-template-columns: 1fr; } .map-side { display: grid; grid-template-columns: 200px 1fr; gap: 10px; } }
.map-view { position: relative; height: min(72vh, 640px); min-height: 360px; overflow: hidden; border: 2px solid #3a4128; border-radius: 6px;
  background: #4e533c repeating-linear-gradient(45deg, transparent 0 10px, rgba(0,0,0,.07) 10px 20px);
  cursor: grab; touch-action: none; user-select: none; outline: none; }
.map-view:focus-visible { border-color: var(--ally); }
.map-view.grabbing { cursor: grabbing; }
.map-layer { position: absolute; left: 0; top: 0; will-change: transform;
  background-color: #a3a672;
  background-image: linear-gradient(rgba(0,0,0,.07) 1px, transparent 1px), linear-gradient(90deg, rgba(0,0,0,.07) 1px, transparent 1px),
    radial-gradient(circle at 30% 40%, rgba(255,255,255,.05), transparent 60%); }
.map-layer .cell { position: absolute; display: grid; place-items: center; pointer-events: none; }
.map-layer .cell .spr { width: 100%; height: 100%; display: block; overflow: visible; }
.map-layer .mv .spr { filter: drop-shadow(0 1px 1px rgba(0,0,0,.35)); }
.map-layer .cell.sel { outline: 2px solid #fff; outline-offset: -2px; box-shadow: inset 0 0 0 4px rgba(0,0,0,.25); background: rgba(255,255,255,.12); }
.map-layer .cell.cur::after { content: ""; position: absolute; inset: 6% 18%; border: 2px dashed var(--mine); border-radius: 50%; animation: curpulse 2s ease-in-out infinite; }
@keyframes curpulse { 50% { opacity: .35; } }
.ruler { position: absolute; background: rgba(38, 42, 28, .82); color: #e3e3cf; font: 11px var(--font); overflow: hidden; pointer-events: none; z-index: 2; }
.ruler-x { left: 22px; right: 0; top: 0; height: 18px; }
.ruler-y { top: 18px; bottom: 0; left: 0; width: 22px; }
.ruler > div { position: absolute; left: 0; top: 0; will-change: transform; }
.ruler-x span, .ruler-y span { position: absolute; display: grid; place-items: center; }
.ruler-x span { top: 0; height: 18px; margin-left: -22px; }
.ruler-y span { left: 0; width: 22px; margin-top: -18px; }
.ruler-corner { position: absolute; left: 0; top: 0; width: 22px; height: 18px; background: #262a1c; z-index: 3; }
.map-tip { position: absolute; z-index: 4; background: rgba(28, 31, 21, .94); color: #eeeedd; padding: 6px 9px; border-radius: 5px; font-size: 12px;
  line-height: 1.45; pointer-events: none; max-width: 260px; box-shadow: 0 4px 14px rgba(0,0,0,.35); }
.map-tip .muted { color: #b9bb9c; }
.map-hint { position: absolute; right: 8px; bottom: 6px; font-size: 11px; color: #f0f0e0; background: rgba(0,0,0,.35); padding: 2px 7px; border-radius: 4px; pointer-events: none; z-index: 2; }
.map-side canvas { width: 200px; height: 200px; border: 2px solid #3a4128; border-radius: 4px; cursor: crosshair; touch-action: none; image-rendering: pixelated; display: block; }
.map-side .legend { margin: 6px 0 10px; }
.map-side .panel { margin: 0; }
.info-sprite { width: 128px; height: 96px; margin: -4px auto 0; background: #a3a672; border-radius: 6px; border: 1px solid var(--line); }
.info-sprite .spr { width: 100%; height: 100%; }

/* ───── Premium ───── */
.pp-chip { background: rgba(217, 196, 106, .15); border: 1px solid rgba(217, 196, 106, .45); color: var(--gold); padding: 2px 9px; border-radius: 12px; cursor: pointer; }
.pp-chip .ic-res { color: var(--gold) !important; }
.pp-chip.on { background: rgba(217, 196, 106, .3); }
.tabs .tab-premium { color: var(--gold); }
.tabs .tab-premium.active { color: #7a5d00; }
button.pp-btn { background: #c9a227; border-color: #a8851a; color: #2b2100; }
button.pp-btn .ic { color: #2b2100; }
.pp-big { font: 44px var(--head); color: #a8851a; display: flex; align-items: center; gap: 10px; }
.pp-big .ic { width: 46px; height: 46px; color: #c9a227; }
.pp-big small { font-size: 18px; color: var(--muted); }
.perks { margin: 6px 0 12px; padding-left: 18px; }
.pp-packs { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 6px; }
.pp-pack { position: relative; text-align: center; display: flex; flex-direction: column; gap: 6px; align-items: center; margin: 0; }
.pp-pack.best { border: 2px solid #c9a227; }
.pp-ribbon { position: absolute; top: -10px; left: 50%; transform: translateX(-50%); background: #c9a227; color: #2b2100; font-size: 11px; padding: 1px 8px; border-radius: 10px; text-transform: uppercase; letter-spacing: .5px; }
.pp-name { font-weight: 600; }
.pp-amount { font: 24px var(--head); color: #8a6c00; display: flex; align-items: center; gap: 6px; }
.pp-amount .ic { color: #c9a227; width: 24px; height: 24px; }
.pp-price { font-size: 20px; font-weight: 600; }
.pay-banner { display: flex; gap: 8px; align-items: center; }
.ok-banner { background: #e3ecd0; border-color: var(--ok); color: var(--ok); }
.err-banner { background: #f3dcd6; border-color: var(--bad); color: var(--bad); }

/* Wiadomości */
.msg-tabs { gap: 4px; }
.msg-form { display: grid; gap: 10px; }
.msg-form label { display: grid; gap: 4px; }
.msg-form .row label { display: flex; gap: 6px; align-items: center; }
.msg-form textarea { font: inherit; padding: 8px; border: 1px solid var(--line); border-radius: 4px; background: #fffdf7; color: var(--ink); resize: vertical; width: 100%; }
.msg-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.55; }
.tag-all { background: var(--accent); color: var(--accent-ink); }
.tag-admin { background: var(--bad); color: #fff; }
button.small-ic { padding: 0 2px; vertical-align: middle; }
button.small-ic .ic { width: 16px; height: 16px; }
.report-row.unread td:nth-child(2) { font-weight: bold; }

/* Portal i światy */
.portal-nav { display: flex; gap: 2px; flex: 1; }
.portal-nav button { background: transparent; border: none; color: var(--bar-text); text-transform: uppercase; letter-spacing: 1px; font-size: 13px; padding: 8px 12px; border-radius: 0; }
.portal-nav button.active { background: var(--panel); color: var(--ink); }
#pview { max-width: 1100px; margin: 0 auto; padding: 16px; }
#portal .me { color: var(--bar-text); }
.worlds { display: grid; grid-template-columns: repeat(auto-fill, minmax(300px, 1fr)); gap: 14px; }
.world-card { display: flex; flex-direction: column; gap: 8px; margin: 0; border-top: 5px solid var(--accent); }
.world-card h3 { margin: 0; }
.world-card.upcoming { border-top-color: var(--gold); }
.world-card.ended { border-top-color: var(--line); opacity: .8; }
.world-card.joined { box-shadow: 0 0 0 2px var(--accent) inset; }
.world-host { font-size: 13px; font-weight: normal; }
.world-status { font-size: 12px; text-transform: uppercase; letter-spacing: 1px; padding: 2px 8px; border-radius: 10px; background: var(--panel-2); }
.world-status.open { background: #e3ecd0; color: var(--ok); }
.world-status.upcoming { background: #f3e7bf; color: #7a5d00; }
.world-facts { list-style: none; padding: 0; margin: 0; display: flex; flex-wrap: wrap; gap: 6px 14px; color: var(--muted); font-size: 14px; }
.world-facts .ic { width: 15px; height: 15px; vertical-align: -2px; }
.world-action { margin-top: auto; }
.world-countdown { font-size: 15px; }
.join-wrap { max-width: 520px; margin: 30px auto; }
.world-chip { background: var(--bar-mid); color: var(--gold); border: 1px solid #59603f; font-size: 13px; padding: 4px 10px; }
.world-chip .ic { width: 15px; height: 15px; vertical-align: -2px; }
.auth-world { margin: 2px 0 0; font-weight: bold; color: var(--accent); letter-spacing: 2px; text-transform: uppercase; }
@media (max-width: 640px) { .portal-nav { order: 3; flex-basis: 100%; overflow-x: auto; } }

/* Panel administracji */
.admin-main { max-width: 1100px; margin: 0 auto; padding: 16px; }
.admin-badge { font: bold 11px var(--font); letter-spacing: 2px; background: var(--bad); color: #fff; padding: 2px 6px; border-radius: 3px; vertical-align: middle; }
.dlg-wrap { position: fixed; inset: 0; background: rgba(0, 0, 0, .45); display: grid; place-items: center; padding: 16px; z-index: 50; }
.dlg { width: min(440px, 100%); display: grid; gap: 10px; margin: 0; }
.dlg label { display: grid; gap: 4px; }
.dlg textarea { font: inherit; padding: 6px 8px; border: 1px solid var(--line); border-radius: 4px; background: #fffdf7; }
button.danger { background: var(--bad); border-color: var(--bad); color: #fff; }
.msg-form label.tr-row { display: flex; align-items: center; gap: 8px; }

/* Zwiad */
.intel p { margin: 6px 0; }
.intel-b { display: inline-flex; align-items: center; gap: 3px; margin-right: 10px; white-space: nowrap; }
.intel-b .ic { width: 16px; height: 16px; }
