:root {
  --bg: #0f1b2b;
  --bg2: #16263b;
  --card: #1b2e47;
  --line: #2c4566;
  --text: #e8eef6;
  --muted: #9fb2c8;
  --accent: #f2b33d;
  --accent2: #e08a1e;
  --danger: #e5534b;
  --ok: #4caf50;
  --radius: 12px;
  font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); }
body { overflow: hidden; -webkit-tap-highlight-color: transparent; }
a { color: var(--accent); }
h1, h2 { margin: 0; }
.muted { color: var(--muted); }
[hidden] { display: none !important; }

#app { height: 100%; }
.screen { display: none; height: 100%; }
.screen.active { display: flex; }

/* ---- Menü ---- */
#screen-menu, #screen-lobby {
  justify-content: center;
  gap: 24px;
  overflow-y: auto;
  padding: 24px 16px;
  background: radial-gradient(1200px 600px at 50% -10%, #23406a 0%, var(--bg) 60%);
}
.menu { width: 100%; max-width: 460px; display: flex; flex-direction: column; gap: 16px; }
.brand { display: flex; align-items: center; gap: 14px; }
.brand-mark { width: 56px; height: 56px; color: var(--accent); flex: none; }
.site-name { font-size: 40px; letter-spacing: .5px; line-height: 1; }
.tagline { margin: 6px 0 0; color: var(--muted); font-size: 15px; }
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 18px;
  display: flex;
  flex-direction: column;
  gap: 12px;
  box-shadow: 0 10px 30px rgba(0,0,0,.25);
}
.field { display: flex; flex-direction: column; gap: 6px; font-size: 13px; color: var(--muted); }
input, select {
  font: inherit; font-size: 16px; color: var(--text);
  background: var(--bg2); border: 1px solid var(--line); border-radius: 8px; padding: 10px 12px; width: 100%;
}
input:focus, select:focus { outline: 2px solid var(--accent); outline-offset: 1px; }
.colors { display: flex; flex-wrap: wrap; gap: 8px; }
.colors button {
  width: 28px; height: 28px; border-radius: 50%; border: 2px solid transparent; cursor: pointer; padding: 0;
}
.colors button.sel { border-color: #fff; box-shadow: 0 0 0 2px var(--bg); }
.btn {
  font: inherit; font-size: 15px; font-weight: 600; color: var(--text);
  background: var(--bg2); border: 1px solid var(--line); border-radius: 10px;
  padding: 11px 14px; cursor: pointer; transition: transform .05s, background .15s;
}
.btn:hover { background: #20354f; }
.btn:active { transform: translateY(1px); }
.btn:disabled { opacity: .5; cursor: default; }
.btn-primary { background: linear-gradient(180deg, var(--accent), var(--accent2)); color: #1a1205; border-color: transparent; }
.btn-primary:hover { background: linear-gradient(180deg, #f7c25a, #e8952a); }
.btn-big { font-size: 20px; padding: 16px; }
.btn-big small { display: block; font-size: 12px; font-weight: 500; opacity: .75; }
.btn-small { padding: 6px 10px; font-size: 13px; }
.btn-link { background: none; border: none; color: var(--muted); font-weight: 500; }
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.opts summary { cursor: pointer; color: var(--muted); font-size: 14px; }
.opts[open] { display: flex; flex-direction: column; gap: 10px; }
.join { display: flex; gap: 8px; }
.join input { text-transform: uppercase; letter-spacing: 3px; }
.howto { background: rgba(27,46,71,.6); border: 1px solid var(--line); border-radius: var(--radius); padding: 16px 18px; font-size: 14px; line-height: 1.55; }
.howto h2 { font-size: 17px; margin-bottom: 6px; }
.howto ol { padding-left: 20px; margin: 6px 0; }
.foot { text-align: center; font-size: 13px; color: var(--muted); }

.code-box { display: flex; align-items: center; justify-content: space-between; gap: 10px; background: var(--bg2); border-radius: 8px; padding: 10px 12px; }
.code-box b { font-size: 20px; letter-spacing: 3px; color: var(--accent); }
.plist { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 6px; max-height: 40vh; overflow-y: auto; }
.plist li { display: flex; align-items: center; gap: 8px; background: var(--bg2); padding: 8px 10px; border-radius: 8px; font-size: 14px; }
.plist li .r { margin-left: auto; color: var(--muted); font-variant-numeric: tabular-nums; }
.dot { width: 12px; height: 12px; border-radius: 50%; display: inline-block; flex: none; }

/* ---- Reklam alanları (yalnızca menü, lobi ve maç sonu) ---- */
.ad-rail { display: none; width: 300px; flex: none; padding-top: 70px; }
.ad-slot { display: none; }
.ad-slot.ready { display: block; overflow: hidden; }
.ad-slot.placeholder {
  display: flex; align-items: center; justify-content: center;
  border: 1px dashed var(--line); border-radius: 8px; color: var(--muted); font-size: 12px;
}
.ad-slot.placeholder::after { content: "Reklam alanı (" attr(data-slot) ")"; }
.ad-tall { width: 300px; min-height: 600px; position: sticky; top: 24px; }
.ad-wide { width: 100%; min-height: 100px; }
.ad-rect { width: 100%; min-height: 250px; }
@media (min-width: 1180px) {
  .ad-rail { display: block; }
  .ad-mobile-only { display: none !important; }
}

/* ---- Oyun ---- */
#screen-game { position: relative; background: #0b2238; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; cursor: crosshair; }
#map.dragging { cursor: grabbing; }
.hud-top { position: absolute; top: 8px; left: 8px; right: 8px; display: flex; justify-content: space-between; align-items: flex-start; pointer-events: none; }
.hud-top > * { pointer-events: auto; }
.me-box {
  display: flex; align-items: center; gap: 12px; flex-wrap: wrap;
  background: rgba(15,27,43,.85); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px; font-size: 14px;
  backdrop-filter: blur(4px);
}
#me-name { font-weight: 700; max-width: 160px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stat b { font-variant-numeric: tabular-nums; }
.stat i { font-style: normal; color: var(--muted); font-size: 12px; margin-left: 2px; }
.banner {
  position: absolute; top: 64px; left: 50%; transform: translateX(-50%);
  background: rgba(242,179,61,.95); color: #1a1205; font-weight: 700; padding: 10px 18px; border-radius: 10px; font-size: 16px;
  pointer-events: none; text-align: center; box-shadow: 0 6px 20px rgba(0,0,0,.3);
}
.board {
  position: absolute; top: 56px; right: 8px; margin: 0; padding: 8px; list-style: none; width: 210px;
  background: rgba(15,27,43,.8); border: 1px solid var(--line); border-radius: 10px; font-size: 13px;
  pointer-events: none;
}
.board li { display: flex; align-items: center; gap: 6px; padding: 2px 0; }
.board li.me { color: var(--accent); font-weight: 700; }
.board li .n { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.board li .v { color: var(--muted); font-variant-numeric: tabular-nums; }
.tip {
  position: absolute; pointer-events: none; background: rgba(15,27,43,.92); border: 1px solid var(--line);
  border-radius: 8px; padding: 6px 9px; font-size: 13px; white-space: nowrap; transform: translate(14px, 14px);
}
.hud-bottom {
  position: absolute; left: 50%; bottom: 10px; transform: translateX(-50%);
  display: flex; flex-direction: column; align-items: center; gap: 8px; width: min(420px, calc(100% - 16px));
}
.ratio {
  width: 100%; background: rgba(15,27,43,.88); border: 1px solid var(--line); border-radius: 10px; padding: 8px 12px;
  display: flex; flex-direction: column; gap: 4px; font-size: 13px; color: var(--muted);
}
.ratio b { color: var(--accent); }
.ratio input { padding: 0; accent-color: var(--accent); border: none; background: none; }
.attacks { display: flex; gap: 6px; flex-wrap: wrap; justify-content: center; }
.attacks span { background: rgba(15,27,43,.88); border: 1px solid var(--line); border-radius: 999px; padding: 3px 9px; font-size: 12px; display: flex; gap: 5px; align-items: center; }

.overlay { position: fixed; inset: 0; background: rgba(5,10,18,.6); display: flex; align-items: center; justify-content: center; padding: 16px; z-index: 10; }
.end-card { width: 100%; max-width: 440px; max-height: calc(100vh - 32px); overflow-y: auto; }
.end-card h2 { font-size: 26px; }
.toast {
  position: fixed; left: 50%; top: 18%; transform: translateX(-50%); z-index: 20;
  background: rgba(15,27,43,.95); border: 1px solid var(--line); padding: 10px 16px; border-radius: 10px; font-size: 14px;
  pointer-events: none;
}

@media (max-width: 640px) {
  .board { width: 150px; font-size: 12px; top: auto; bottom: 120px; }
  .board li:nth-child(n+6):not(.me) { display: none; }
  .me-box { gap: 8px; font-size: 13px; padding: 6px 10px; }
  #me-name { max-width: 90px; }
  .site-name { font-size: 32px; }
}

/* ---- Bilgi sayfaları ---- */
.page { overflow: auto; }
.page main { max-width: 760px; margin: 0 auto; padding: 32px 16px 64px; line-height: 1.65; }
.page h1 { font-size: 30px; margin-bottom: 12px; }
.page h2 { font-size: 20px; margin: 28px 0 8px; }
.page .back { display: inline-block; margin-bottom: 18px; }

/* ---- Yapı/füze çubuğu ---- */
.buildbar { display: flex; gap: 6px; justify-content: flex-start; max-width: 100%; overflow-x: auto; padding: 2px; scrollbar-width: none; }
.buildbar::-webkit-scrollbar { display: none; }
.bb {
  flex: none; width: 66px; display: flex; flex-direction: column; align-items: center; gap: 1px;
  background: rgba(15,27,43,.9); border: 1px solid var(--line); border-radius: 10px; padding: 5px 3px 4px; color: var(--text); cursor: pointer;
  font: inherit;
}
.bb canvas { width: 28px; height: 28px; }
.bb-name { font-size: 10.5px; line-height: 1.1; text-align: center; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 62px; }
.bb-cost { font-size: 11px; font-weight: 700; color: var(--accent); font-variant-numeric: tabular-nums; }
.bb-cost::before { content: "◉ "; font-size: 9px; }
.bb:hover { background: #20354f; }
.bb.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(242,179,61,.45); }
.bb.off { opacity: .45; }
.stat.gold b { color: var(--accent); }
.stat.gold b::before { content: "◉ "; font-size: 11px; }
.banner-mode { top: auto; bottom: 190px; background: rgba(15,27,43,.92); color: var(--text); border: 1px solid var(--accent); font-weight: 600; font-size: 14px; }
#map.placing { cursor: copy; }
.hud-bottom { width: min(560px, calc(100% - 16px)); }
@media (max-width: 640px) {
  .bb { width: 54px; padding: 4px 2px; }
  .bb canvas { width: 22px; height: 22px; }
  .bb-name { font-size: 9px; max-width: 50px; }
  .banner-mode { bottom: 170px; font-size: 12px; }
}
.buildbar > :first-child { margin-left: auto; }
.buildbar > :last-child { margin-right: auto; }

/* ======== v3: piksel tema ve yeni bileşenler ======== */
@font-face { font-family: "Pixelify Sans"; src: url(/fonts/pixelify-latin.woff2) format("woff2"); font-weight: 400 700; font-display: swap;
  unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: "Pixelify Sans"; src: url(/fonts/pixelify-latin-ext.woff2) format("woff2"); font-weight: 400 700; font-display: swap;
  unicode-range: U+0100-02AF, U+0304, U+0308, U+0329, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C0, U+2113, U+2C60-2C7F, U+A720-A7FF; }
:root { --pixel: "Pixelify Sans", system-ui, sans-serif; }
h1, h2, .btn, .bb-name, .lvl, .map-card span, .pm-head b, #me-name { font-family: var(--pixel); }
/* Rakamlar okunaklı kalsın diye sayısal alanlarda sistem yazı tipi */
.seg button, .btn-big small, .bb-cost, .me-box .stat { font-family: system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; }
.site-name { font-size: 36px; letter-spacing: 0; }
.brand-mark { image-rendering: pixelated; }
canvas, .map-card img { image-rendering: pixelated; }
.small { font-size: 12.5px; }
.menu-wide { max-width: 720px; }

/* Profil */
.profile { gap: 10px; padding: 14px 16px; }
.prof-top { display: flex; align-items: center; gap: 12px; }
.lvl { flex: none; width: 44px; height: 44px; display: grid; place-items: center; font-size: 22px; font-weight: 700; color: #1a1205;
  background: linear-gradient(180deg, var(--accent), var(--accent2)); border-radius: 10px; box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); }
.prof-info { flex: 1; min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.xpbar { height: 8px; background: var(--bg2); border-radius: 4px; overflow: hidden; }
.xpbar i { display: block; height: 100%; background: linear-gradient(90deg, #66bb6a, #c0ca33); width: 0; }
.daily { font-size: 13.5px; }
.daily .tag { display: inline-block; background: #2f5d8a; color: #fff; border-radius: 6px; padding: 1px 7px; font-size: 12px; margin-right: 4px; }
.daily b { color: var(--ok); margin-left: 6px; }

/* Ayar ekranı */
#screen-setup { justify-content: center; overflow-y: auto; padding: 24px 16px;
  background: radial-gradient(1200px 600px at 50% -10%, #23406a 0%, var(--bg) 60%); }
.map-cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 8px; }
.map-card { background: var(--bg2); border: 2px solid var(--line); border-radius: 10px; padding: 6px; cursor: pointer; color: var(--text);
  display: flex; flex-direction: column; gap: 4px; align-items: stretch; }
.map-card img { width: 100%; aspect-ratio: 2 / 1; object-fit: cover; border-radius: 6px; background: #1a3c62; }
.map-card span { font-size: 13px; text-align: center; }
.map-card.sel { border-color: var(--accent); box-shadow: 0 0 0 2px rgba(242,179,61,.35); }
.seg { display: flex; flex-wrap: wrap; gap: 6px; }
.seg button { flex: 1 1 auto; background: var(--bg2); border: 1px solid var(--line); color: var(--text); border-radius: 8px; padding: 8px 10px; cursor: pointer; font-size: 14px; }
.seg button.sel { background: linear-gradient(180deg, var(--accent), var(--accent2)); color: #1a1205; border-color: transparent; }
input[type=range] { padding: 0; accent-color: var(--accent); border: none; background: none; }

/* Oyun içi */
.hud-btns { display: flex; gap: 6px; }
.feed { position: absolute; top: 56px; left: 8px; margin: 0; padding: 0; list-style: none; display: flex; flex-direction: column; gap: 4px;
  max-width: min(380px, 60vw); pointer-events: none; }
.feed li { background: rgba(15,27,43,.85); border: 1px solid var(--line); border-left: 3px solid #5c7da6; border-radius: 8px; padding: 5px 9px;
  font-size: 13px; transition: opacity 1.4s; }
.feed li.good { border-left-color: var(--ok); }
.feed li.bad { border-left-color: var(--danger); }
.feed li.fade { opacity: 0; }
.board { pointer-events: auto; }
.board li { cursor: pointer; border-radius: 4px; }
.board li:hover { background: rgba(255,255,255,.06); }
.minimap { position: absolute; left: 8px; bottom: 10px; width: 200px; border: 2px solid var(--line); border-radius: 6px; background: #10243e;
  cursor: pointer; box-shadow: 0 6px 18px rgba(0,0,0,.35); }
.pmenu { position: fixed; z-index: 15; min-width: 220px; background: rgba(15,27,43,.97); border: 1px solid var(--accent); border-radius: 10px;
  padding: 8px; display: flex; flex-direction: column; gap: 4px; box-shadow: 0 10px 30px rgba(0,0,0,.45); }
.pm-head { display: flex; align-items: center; gap: 6px; font-size: 15px; }
.pm-sub { font-size: 12px; margin-bottom: 4px; }
.pmenu button { text-align: left; background: var(--bg2); border: 1px solid var(--line); color: var(--text); border-radius: 7px; padding: 8px 10px;
  cursor: pointer; font: inherit; font-size: 14px; }
.pmenu button:hover { background: #22395a; }
.allyreq { position: absolute; top: 64px; left: 50%; transform: translateX(-50%); z-index: 12; background: rgba(15,27,43,.97);
  border: 1px solid #66bb6a; border-radius: 10px; padding: 10px 12px; display: flex; flex-direction: column; gap: 8px; font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,.4); }
.end-xp:empty { display: none; }
.end-xp { background: var(--bg2); border-radius: 8px; padding: 10px 12px; display: flex; flex-direction: column; gap: 4px; }
.xp-gain { font-size: 18px; color: var(--accent); }
.ach-new { font-size: 13.5px; color: #c5e1a5; }
.ach-list { list-style: none; margin: 0; padding: 0; display: grid; grid-template-columns: 1fr 1fr; gap: 6px; }
.ach-list li { background: var(--bg2); border-radius: 8px; padding: 8px 10px; display: flex; flex-direction: column; gap: 2px; font-size: 13px; opacity: .55; }
.ach-list li.got { opacity: 1; border: 1px solid #8bc34a; }
.ach-list li span { color: var(--muted); font-size: 12px; }
@media (max-width: 640px) {
  .minimap { width: 120px; bottom: 150px; }
  .feed { top: 50px; font-size: 12px; max-width: 70vw; }
  .ach-list { grid-template-columns: 1fr; }
  .site-name { font-size: 28px; }
}

/* ======== v4 ======== */
input.invalid { outline: 2px solid var(--danger); border-color: var(--danger); animation: shake .3s; }
@keyframes shake { 25% { transform: translateX(-4px); } 75% { transform: translateX(4px); } }
.attacks .chip { background: rgba(15,27,43,.9); border: 1px solid var(--line); border-radius: 999px; padding: 3px 10px; font-size: 12px;
  display: flex; gap: 5px; align-items: center; color: var(--text); font-family: system-ui, sans-serif; }
.attacks button.chip { cursor: pointer; }
.attacks button.chip:hover { border-color: var(--danger); }
.attacks button.chip b { color: var(--danger); font-weight: 700; }
.attacks span { display: none; }
.attacks span.chip { display: flex; opacity: .75; }
.bb canvas { width: 30px; height: 30px; }
.bb { width: 62px; }
.pmenu button:disabled { opacity: .45; cursor: default; }
.lvl-tag { font-size: 12px; background: #ffca28; color: #1a1205; border-radius: 6px; padding: 1px 6px; margin-left: 4px; }
.pause-card { text-align: center; align-items: center; }
#me-name, #me-dot { cursor: pointer; }
#me-name:hover { text-decoration: underline; }
@media (max-width: 640px) { .bb { width: 52px; } .bb canvas { width: 24px; height: 24px; } }
