:root {
  --bg: #2a1f1a;
  --panel: #0d1220;
  --panel-2: #141b2d;
  --line: #273049;
  --text: #f4f1ea;
  --muted: #9aa3b8;
  --blue: #4c8af7;
  --red: #6b1d22;
  --purple: #4b2a86;
  --gold: #f2c96d;
  --green: #4fd17a;
}
* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--text); font-family: Montserrat, system-ui, sans-serif; overflow: hidden; }
button { font: inherit; cursor: pointer; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.green { color: var(--green); }
.error { color: #ff7b7b; min-height: 1.2em; }

.screen { position: fixed; inset: 0; display: none; }
.screen.active { display: flex; }

.logo { font-family: "Luckiest Guy", cursive; color: var(--gold); letter-spacing: 1px; text-shadow: 0 3px 0 #7a5a1c; font-size: 28px; }
.logo.big { font-size: clamp(36px, 7vw, 72px); margin: 0; }
.logo.huge { font-size: clamp(48px, 10vw, 110px); margin: 0; color: #fff3d6; }

.btn { border: 2px solid var(--line); border-radius: 8px; padding: 14px 20px; font-weight: 800; color: var(--text); background: var(--panel); text-transform: uppercase; transition: transform .08s, filter .15s; }
.btn:hover { filter: brightness(1.2); }
.btn:active { transform: translateY(2px); }
.btn.primary, .btn.blue { background: var(--blue); border-color: #2f5fc0; }
.btn.red { background: var(--red); border-color: #9c3a3f; }
.btn.purple { background: var(--purple); border-color: #8b6ad6; text-transform: none; }
.btn.dark { background: var(--panel); }
.btn.ghost { background: transparent; }
.btn.small { padding: 6px 12px; font-size: 14px; }
.row { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
.panel { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 24px; }

/* İsim ekranı */
#screen-name { align-items: center; justify-content: center; background: radial-gradient(circle at 50% 30%, #1d2944, #0a0d16); }
.name-box { text-align: center; padding: 16px; }
#name-form { display: flex; gap: 10px; margin-top: 24px; justify-content: center; flex-wrap: wrap; }
.auth-tabs { display: flex; gap: 8px; justify-content: center; margin-top: 24px; }
.auth-tabs .on { background: var(--blue); border-color: #2f5fc0; }
.auth-form { display: grid; gap: 10px; margin: 16px auto 0; width: min(320px, 86vw); }
.auth-form input { padding: 14px 16px; border-radius: 8px; border: 2px solid var(--line); background: var(--panel); color: var(--text); font: inherit; font-size: 17px; }

/* Misafir */
.or { display: flex; align-items: center; gap: 12px; color: var(--muted); font-size: 12px; width: min(320px, 86vw); margin: 4px auto 12px; }
.or::before, .or::after { content: ""; flex: 1; height: 1px; background: var(--line); }
.guest-btn { width: min(320px, 86vw); }
.small-note { font-size: 12px; } .small-note a { color: var(--gold); }
.guest-only { display: none; }
body.guest .guest-only { display: inline-block; }
body.guest .topbar .gold { display: none; }
.guest-cta { background: #1b2a52; border: 2px solid var(--blue); border-radius: 12px; padding: 14px 24px; text-align: center; max-width: 440px; }
.guest-cta b { font-size: 20px; color: var(--gold); }
.guest-cta p { margin: 6px 0 12px; }

/* Profil + arkadaşlar */
.badge { display: inline-block; min-width: 18px; padding: 0 5px; border-radius: 9px; background: #e04848; color: #fff; font-size: 11px; line-height: 18px; text-align: center; }
.pstats { display: grid; grid-template-columns: repeat(4, 1fr); gap: 10px; margin-bottom: 16px; }
.pstats div { background: var(--panel-2); border: 2px solid var(--line); border-radius: 8px; padding: 10px; text-align: center; }
.pstats b { display: block; font-size: 24px; } .pstats small { color: var(--muted); font-weight: 700; font-size: 11px; }
.history { width: 100%; border-collapse: collapse; font-size: 14px; }
.history th { color: var(--muted); font-size: 11px; text-align: left; border-bottom: 1px solid var(--line); padding: 4px; }
.history td { padding: 6px 4px; border-bottom: 1px solid var(--line); }
.history .won { color: var(--gold); font-weight: 800; }
.friend-add { display: flex; gap: 8px; margin-bottom: 12px; }
.friend-add input { flex: 1; padding: 10px; border-radius: 6px; border: 2px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; }
.friend-row { display: flex; align-items: center; gap: 8px; padding: 8px; border-bottom: 1px solid var(--line); }
.friend-row .nm { flex: 1; font-weight: 700; background: none; border: none; color: var(--text); text-align: left; padding: 0; }
.dot { width: 10px; height: 10px; border-radius: 50%; background: #555c6e; flex: none; }
.dot.on { background: var(--green); } .dot.match { background: var(--gold); }

/* Menü */
#screen-menu { flex-direction: column; padding: 16px; gap: 16px; }
.topbar { display: flex; align-items: center; gap: 16px; background: var(--panel); border: 2px solid var(--line); border-radius: 10px; padding: 10px 18px; flex-wrap: wrap; }
.clan { color: var(--muted); font-size: 13px; }
.me-name { font-size: 24px; font-weight: 800; flex: 1; }
.gold { color: var(--gold); font-size: 22px; font-weight: 800; }
.menu-grid { flex: 1; display: grid; grid-template-columns: 2fr 1fr; gap: 16px; min-height: 0; }
.side { display: grid; grid-template-rows: 1fr 1fr auto; gap: 16px; min-height: 0; }
.lobby-card { position: relative; background: var(--panel); border: 2px solid var(--line); border-radius: 10px; overflow: hidden; min-height: 120px; }
.lobby-card canvas { position: absolute; inset: 0; width: 100%; height: 100%; image-rendering: pixelated; object-fit: contain; }
.lobby-card .shade { position: absolute; inset: 0; background: linear-gradient(transparent 45%, rgba(8, 11, 20, .95)); }
.lobby-card .join { position: absolute; top: 12px; left: 12px; background: var(--blue); border: none; color: #fff; font-weight: 800; padding: 6px 24px; border-radius: 4px; }
.lobby-card .time { position: absolute; top: 12px; right: 12px; background: var(--blue); padding: 6px 16px; border-radius: 4px; font-weight: 800; }
.lobby-card .count { position: absolute; right: 12px; bottom: 60px; background: #0a0e18cc; padding: 4px 14px; border-radius: 4px; font-weight: 700; }
.lobby-card .info { position: absolute; left: 16px; bottom: 12px; }
.lobby-card .info h3 { margin: 0; font-size: 26px; }
.lobby-card.featured .info h3 { font-size: clamp(28px, 4vw, 48px); text-transform: uppercase; }
.lobby-card .tag { display: inline-block; margin-top: 4px; font-size: 12px; font-weight: 800; background: #9cc7ff; color: #10203a; padding: 3px 12px; border-radius: 3px; }
.lobby-card .arrow { position: absolute; top: 50%; transform: translateY(-50%); background: #5b4514; border: 2px solid #8b6b25; color: #fff; font-size: 28px; font-weight: 800; padding: 18px 12px; border-radius: 6px; z-index: 2; }
.lobby-card .arrow.l { left: 8px; } .lobby-card .arrow.r { right: 8px; }
.lobby-card .tag.diff-easy { background: #8fe3a8; } .lobby-card .tag.diff-hard { background: #f5b971; }
.lobby-card .tag.diff-brutal { background: #ff8b8b; }
.lobby-card.empty { display: flex; align-items: center; justify-content: center; color: var(--muted); }
.all-games { display: flex; flex-direction: column; align-items: center; font-size: 22px; }
.all-games small { font-size: 12px; color: var(--muted); font-weight: 600; }
.bottombar { display: grid; grid-template-columns: repeat(4, 1fr); gap: 16px; }
.bottombar .btn { padding: 22px 8px; font-size: 18px; }

/* Lobi odası */
#screen-lobby, #screen-loading { align-items: center; justify-content: center; flex-direction: column; background: #0a0d16; text-align: center; }
.lobby-room { width: min(480px, 92vw); }
.lobby-room .thumb { width: 100%; aspect-ratio: 220 / 140; image-rendering: pixelated; border-radius: 8px; background: #0a1730; }
.lobby-room h2 { margin: 12px 0 0; }
#lobby-members { list-style: none; padding: 0; text-align: left; max-height: 200px; overflow: auto; }
#lobby-members li { padding: 8px 12px; border-bottom: 1px solid var(--line); }
.code-row b { color: var(--gold); letter-spacing: 3px; }
.timer { font-size: 22px; font-weight: 800; color: var(--gold); min-height: 1.4em; }

/* Modal */
.modal { position: fixed; inset: 0; background: #000a; display: flex; align-items: center; justify-content: center; z-index: 20; padding: 16px; }
.modal-box { background: var(--panel); border: 2px solid var(--line); border-radius: 12px; padding: 24px; width: min(720px, 100%); max-height: 90vh; overflow: auto; }
.modal-box h2 { font-family: "Luckiest Guy", cursive; color: #fff3d6; text-align: center; font-size: 40px; margin: 0 0 16px; }
.form { display: grid; gap: 12px; }
.form label { display: grid; gap: 4px; font-weight: 700; font-size: 14px; }
.form input, .form select { padding: 10px; border-radius: 6px; border: 2px solid var(--line); background: var(--panel-2); color: var(--text); font: inherit; }
.form .check { display: flex; gap: 8px; align-items: center; }
.games-list { display: grid; gap: 10px; }
.game-row { display: grid; grid-template-columns: 120px 1fr auto auto; gap: 16px; align-items: center; background: var(--panel-2); border: 2px solid var(--line); border-radius: 8px; padding: 8px; }
.game-row canvas { width: 120px; height: 76px; image-rendering: pixelated; border-radius: 4px; background: #0a1730; }
.game-row .count { background: #0a0e18; padding: 4px 12px; border-radius: 4px; font-weight: 700; }
.shop-list { display: grid; gap: 10px; margin-bottom: 12px; }
.shop-item { display: grid; grid-template-columns: 48px 1fr auto; gap: 14px; align-items: center; background: var(--panel-2); border: 2px solid var(--line); border-radius: 8px; padding: 10px 14px; }
.shop-item.owned { border-color: var(--gold); }
.shop-item .ico { font-size: 34px; text-align: center; }
.shop-item button:disabled { opacity: .45; cursor: not-allowed; }
.ranks { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 16px; }
.rank { background: var(--panel-2); border: 2px solid var(--line); border-radius: 8px; padding: 8px; text-align: center; font-size: 13px; }
.rank .ico { font-size: 28px; }
.rank b { display: block; }
.rank .cash { color: var(--green); }
.rank.current { border-color: #a07cf0; background: #2a1f4a; }
.tabs { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.tabs .on { background: #6b5214; border-color: #a5832f; }

/* Oyun */
#screen-game { background: #1c1612; }
#map { position: absolute; inset: 0; width: 100%; height: 100%; cursor: crosshair; }
.banner { position: absolute; top: 12px; left: 50%; transform: translateX(-50%); width: min(780px, 70vw); background: var(--panel); border-radius: 6px; text-align: center; padding: 6px; font-weight: 700; }
.land-bar { height: 6px; background: var(--gold); border-radius: 3px; width: 0; margin-bottom: 6px; transition: width .2s; }
.leaderboard { position: absolute; z-index: 4; top: 12px; right: 12px; width: 300px; background: #0d1220e6; border: 2px solid var(--line); border-radius: 6px; padding: 8px 12px; font-size: 13px; }
.leaderboard h4 { margin: 0; }
.lb-head { display: flex; align-items: center; gap: 8px; width: 100%; background: none; border: none; color: inherit; padding: 0 0 6px; text-align: left; }
.lb-head .lb-me { flex: 1; text-align: right; color: var(--gold); font-weight: 800; font-size: 12px; }
.lb-head .chev { transition: transform .15s; }
.leaderboard.collapsed { width: auto; min-width: 150px; }
.leaderboard.collapsed .lb-head { padding: 0; }
.leaderboard.collapsed .chev { transform: rotate(-90deg); }
.leaderboard.collapsed #lb-table { display: none; }
.exit-btn { position: absolute; top: 12px; left: 12px; z-index: 5; width: 40px; height: 40px; border-radius: 8px; border: 2px solid var(--line); background: #0d1220e6; color: var(--text); font-size: 18px; font-weight: 800; }
.exit-btn:hover { background: var(--red); border-color: #9c3a3f; }
.lobbies-btn { top: 60px; }
.lobbies-btn:hover { background: var(--blue); border-color: #2f5fc0; }
.game-row.playing { opacity: .65; }
.game-row button:disabled { cursor: not-allowed; }
.leaderboard table { width: 100%; border-collapse: collapse; }
.leaderboard th { color: var(--muted); font-size: 10px; text-align: left; font-weight: 600; border-bottom: 1px solid var(--line); }
.leaderboard td { padding: 3px 2px; }
.leaderboard tr.me td { color: var(--gold); font-weight: 800; }
.leaderboard tr.dead td { opacity: .4; text-decoration: line-through; }
.leaderboard tr.ally td { color: #8fe3a8; }
.ally-btn { background: #141b2d; border: 1px solid var(--line); color: var(--text); border-radius: 4px; padding: 1px 5px; font-size: 11px; white-space: nowrap; }
.ally-btn:hover { border-color: var(--green); }
.ally-btn.on { border-color: var(--green); }
.ally-req { position: absolute; top: 70px; left: 50%; transform: translateX(-50%); z-index: 6; background: var(--panel); border: 2px solid var(--green); border-radius: 8px; padding: 10px 16px; text-align: center; font-size: 14px; }
.ally-req .row { margin-top: 8px; }
.leaderboard .sw { display: inline-block; width: 10px; height: 10px; border-radius: 2px; margin-right: 6px; }
.hud { position: absolute; bottom: 12px; left: 50%; transform: translateX(-50%); width: min(820px, 94vw); background: #0d1220ee; border: 2px solid var(--line); border-radius: 6px; padding: 10px 16px; }
.hud-row { display: flex; align-items: center; gap: 12px; }
.hud-row.small { font-size: 13px; margin-top: 6px; }
.troops { font-size: 26px; }
.bar { flex: 1; height: 8px; background: #050810; border-radius: 4px; overflow: hidden; }
#hud-troop-bar { height: 100%; width: 0; background: linear-gradient(90deg, #3d7bf0, #79b0ff); }
.coin { font-size: 22px; color: var(--gold); margin-left: 12px; }
.sizes { display: flex; gap: 6px; flex: 1; justify-content: center; }
.sizes button { background: transparent; color: var(--text); border: none; padding: 4px 14px; border-radius: 3px; font-weight: 700; }
.sizes button.on { background: #f3a0a0; color: #2a0a0a; }
.abilities { position: absolute; left: 50%; transform: translateX(-50%); bottom: 132px; display: flex; gap: 6px; max-width: 96vw; overflow-x: auto; }
.ability { position: relative; width: 92px; flex: none; background: #0d1220ee; border: 2px solid var(--line); border-radius: 6px; color: var(--text); padding: 18px 4px 6px; display: flex; flex-direction: column; align-items: center; gap: 2px; }
.ability:hover { filter: brightness(1.25); }
.ability .key { position: absolute; top: 3px; left: 6px; font-size: 10px; color: var(--muted); }
.ability .lvl { position: absolute; top: 3px; right: 6px; font-size: 10px; color: var(--gold); font-weight: 800; }
.ability .ico { font-size: 24px; }
.ability .nm { font-size: 11px; font-weight: 800; text-align: center; line-height: 1.1; }
.ability .cost { font-size: 12px; color: var(--gold); font-weight: 700; }
.ability.off { opacity: .45; }
.ability.armed { border-color: var(--gold); box-shadow: 0 0 0 2px var(--gold) inset; }
#map.aiming { cursor: cell; }
.clock { position: absolute; right: 12px; bottom: 12px; background: var(--panel); border-radius: 6px; padding: 10px 24px; display: flex; flex-direction: column; }
.clock b { font-size: 36px; } .clock small { color: var(--muted); }
.tooltip { position: absolute; pointer-events: none; background: #0d1220ee; border-radius: 4px; padding: 8px 12px; font-size: 13px; min-width: 180px; }
.tooltip .t { font-size: 15px; font-weight: 700; }
.hint { position: absolute; left: 12px; bottom: 12px; font-size: 11px; max-width: 200px; }

/* Zafer */
.victory { position: fixed; inset: 0; background: #070a12cc; z-index: 30; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 18px; padding: 16px; overflow: hidden; }
.victory.lose .logo { color: #ff8b8b; }
.pill { background: var(--panel); padding: 10px 40px; border-radius: 8px; font-size: 20px; font-weight: 800; margin: 0; }
.stats { display: grid; grid-template-columns: repeat(4, minmax(110px, 200px)); gap: 12px; }
.stat { background: var(--panel); border-radius: 10px; padding: 16px; display: flex; flex-direction: column; align-items: center; gap: 4px; }
.stat span { font-size: 26px; } .stat b { font-size: 28px; } .stat small { color: var(--muted); font-size: 11px; font-weight: 800; text-align: center; }
.reward { font-size: 40px; color: var(--gold); margin: 0; font-weight: 800; }
#confetti { position: absolute; inset: 0; pointer-events: none; z-index: -1; }
.conf { position: absolute; top: -20px; width: 10px; height: 16px; animation: fall linear forwards; }
@keyframes fall { to { transform: translateY(110vh) rotate(720deg); } }

.toast { position: fixed; top: 20px; left: 50%; transform: translateX(-50%); background: var(--panel); border: 2px solid var(--gold); border-radius: 8px; padding: 10px 20px; z-index: 40; font-weight: 700; }

@media (max-width: 760px) {
  .menu-grid { grid-template-columns: 1fr; overflow: auto; }
  .bottombar { grid-template-columns: repeat(2, 1fr); }
  .leaderboard { width: 200px; font-size: 11px; }
  /* Üst sıra: ✕ ve sıralama; şerit onların altında, saat sağda şeridin altında. */
  .banner { top: 62px; left: 60px; right: 12px; transform: none; width: auto; font-size: 12px; }
  .clock { bottom: auto; top: 112px; right: 12px; padding: 4px 12px; }
  .clock b { font-size: 20px; }
  .stats { grid-template-columns: repeat(2, 1fr); }
  .pstats { grid-template-columns: repeat(2, 1fr); }
  .topbar .me-name { flex-basis: 100%; }
  .game-row { grid-template-columns: 80px 1fr auto; }
  .game-row canvas { width: 80px; height: 50px; }
  .game-row .count { display: none; }
  .ranks { grid-template-columns: repeat(2, 1fr); }
  .hint { display: none; }
  .abilities { bottom: 150px; }
  .ability { width: 76px; }
  .ability .nm { font-size: 9px; }
}

.version-warning { position: fixed; left: 50%; bottom: 16px; transform: translateX(-50%); z-index: 50; max-width: min(640px, calc(100vw - 32px)); background: #5a1d1d; border: 2px solid #ff8b8b; border-radius: 8px; padding: 10px 14px; font-weight: 700; font-size: 14px; text-align: center; }
.version-warning button { margin-left: 8px; }
