:root {
  --bg: #1d3b2a;
  --panel: #fff8e8;
  --panel-2: #f3e6c8;
  --ink: #3a2a18;
  --muted: #8a7558;
  --gold: #ffcc33;
  --primary: #e8742a;
  --primary-2: #c85a16;
  --danger: #d6453d;
  --ok: #3f9a3a;
  --font: "Nunito", "Segoe UI", system-ui, sans-serif;
  --title: "Lilita One", "Nunito", system-ui, sans-serif;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; height: 100%; background: var(--bg); color: var(--ink); font-family: var(--font); overflow: hidden; }
[hidden] { display: none !important; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: not-allowed; opacity: 0.5; }
.muted { color: var(--muted); }
.err { color: #ffb3a8; min-height: 1.2em; }

/* ---------- butonlar ---------- */
.btn {
  border: 0; border-radius: 12px; padding: 10px 16px; background: var(--panel-2);
  box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25); font-weight: 700;
}
.btn:active:not(:disabled) { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0, 0, 0, 0.25); }
.btn.primary { background: linear-gradient(#f5913f, var(--primary)); color: #fff; box-shadow: 0 3px 0 var(--primary-2); text-shadow: 0 1px 0 rgba(0, 0, 0, 0.3); }
.btn.big { padding: 14px 24px; font-size: 1.1rem; width: 100%; }
.btn.sm { padding: 6px 10px; font-size: 0.85rem; border-radius: 9px; }

/* ---------- giriş ekranı ---------- */
#title {
  position: fixed; inset: 0; display: grid; place-items: center; padding: 16px;
  background: radial-gradient(circle at 50% 30%, #4fae5a, #1f6b3a 55%, #10331f);
}
#title-bg { position: absolute; inset: 0; overflow: hidden; pointer-events: none; }
#title-bg span { position: absolute; bottom: -60px; animation: float linear infinite; opacity: 0.55; }
@keyframes float {
  from { transform: translateY(0) rotate(-10deg); }
  to { transform: translateY(-115vh) rotate(15deg); }
}
.title-card {
  position: relative; width: min(380px, 100%); text-align: center; padding: 28px 22px;
  background: rgba(255, 248, 232, 0.95); border-radius: 24px; border: 4px solid #c9a36a;
  box-shadow: 0 12px 40px rgba(0, 0, 0, 0.45);
}
.logo { font-size: 56px; animation: bounce 2.2s ease-in-out infinite; }
@keyframes bounce { 50% { transform: translateY(-8px) scale(1.05); } }
.title-card h1 {
  margin: 4px 0; font-size: 2.4rem; color: var(--primary); letter-spacing: 1px;
  text-shadow: 0 3px 0 #7a3a10, 0 6px 12px rgba(0, 0, 0, 0.25);
}
.tag { margin: 0 0 18px; color: var(--muted); }
#continue { margin-bottom: 14px; }
.player-list { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin-bottom: 14px; }
.player {
  flex: 1; min-width: 120px; padding: 14px 10px; border-radius: 16px; border: 3px solid transparent;
  background: var(--panel-2); font-weight: 700; font-size: 1.05rem; display: flex; flex-direction: column; align-items: center; gap: 4px;
}
.player .av { font-size: 2.4rem; }
.player.on { border-color: var(--primary); background: #ffe2c4; }
.codebox { display: flex; gap: 8px; align-items: center; }
.codebox input { flex: 1; min-width: 0; padding: 10px 12px; font-size: 1rem; border-radius: 10px; border: 2px solid #d6c29a; text-transform: uppercase; font-family: inherit; }
#pin-box { display: flex; flex-direction: column; gap: 10px; }
#pin { padding: 14px; font-size: 1.3rem; text-align: center; border-radius: 12px; border: 2px solid #d6c29a; letter-spacing: 6px; }

/* ---------- oyun ---------- */
#game { position: fixed; inset: 0; display: flex; flex-direction: column; }
#hud, #bhud {
  display: flex; flex-wrap: wrap; gap: 6px; padding: 8px 10px; padding-top: max(8px, env(safe-area-inset-top));
  background: linear-gradient(rgba(0, 0, 0, 0.55), rgba(0, 0, 0, 0.35)); z-index: 2;
}
.pill {
  background: rgba(20, 14, 8, 0.75); color: #fff; border-radius: 999px; padding: 5px 11px;
  font-size: 0.9rem; white-space: nowrap; border: 1px solid rgba(255, 255, 255, 0.15);
}
.pill b { color: var(--gold); }
.pill small { opacity: 0.6; }
.pill.title { background: var(--danger); }
.stage { position: relative; flex: 1; min-height: 0; }
#cv { position: absolute; inset: 0; width: 100%; height: 100%; touch-action: none; display: block; }
#hint {
  position: absolute; left: 50%; top: 10px; transform: translateX(-50%); width: max-content; max-width: calc(100% - 20px);
  display: flex; gap: 10px; align-items: center; padding: 8px 8px 8px 14px; border-radius: 14px;
  background: rgba(20, 14, 8, 0.85); color: #fff; font-size: 0.9rem;
}

#nav, #bnav {
  display: flex; gap: 6px; padding: 8px; padding-bottom: max(8px, env(safe-area-inset-bottom));
  background: linear-gradient(#5b3d22, #3d2814); border-top: 3px solid #8a6238;
}
#nav button {
  flex: 1; border: 0; border-radius: 12px; padding: 6px 2px; background: linear-gradient(#f6e7c4, #e2c993);
  box-shadow: 0 3px 0 #9b7b48; font-size: 0.78rem; font-weight: 700; display: flex; flex-direction: column; align-items: center; position: relative;
}
#nav button span { font-size: 1.5rem; line-height: 1.2; }
#nav button.hot { background: linear-gradient(#ff9a52, #e2622a); color: #fff; box-shadow: 0 3px 0 #9b3e14; }
#nav button.badge::after {
  content: '!'; position: absolute; top: -4px; right: 6px; width: 20px; height: 20px; border-radius: 50%;
  background: var(--danger); color: #fff; font-size: 0.8rem; line-height: 20px; animation: bounce 1s infinite;
}
#bnav { overflow-x: auto; }
.tbtn {
  min-width: 64px; border: 3px solid transparent; border-radius: 12px; padding: 4px 8px; background: #f6e7c4;
  font-weight: 700; display: flex; flex-direction: column; align-items: center; box-shadow: 0 3px 0 #9b7b48;
}
.tbtn .em { font-size: 1.6rem; }
.tbtn.on { border-color: var(--gold); background: #fff3c9; }
.tbtn.end { margin-left: auto; background: var(--danger); color: #fff; justify-content: center; box-shadow: 0 3px 0 #8e2620; }

/* ---------- paneller ---------- */
#sheet { position: fixed; inset: 0; z-index: 10; background: rgba(0, 0, 0, 0.45); display: flex; align-items: flex-end; justify-content: center; }
.sheet-card {
  width: min(560px, 100%); max-height: 82vh; overflow-y: auto; background: var(--panel);
  border-radius: 22px 22px 0 0; border: 4px solid #c9a36a; border-bottom: 0; padding: 0 16px 20px;
  padding-bottom: max(20px, env(safe-area-inset-bottom)); animation: up 0.18s ease-out;
}
@media (min-width: 700px) {
  #sheet { align-items: center; }
  .sheet-card { border-radius: 22px; border-bottom: 4px solid #c9a36a; }
}
@keyframes up { from { transform: translateY(40px); opacity: 0; } }
.sheet-head { position: sticky; top: 0; background: var(--panel); display: flex; align-items: center; gap: 10px; padding: 14px 0 8px; z-index: 1; }
.sheet-head h2 { flex: 1; margin: 0; font-size: 1.25rem; }
.lvl { font-size: 0.8rem; background: var(--ink); color: var(--gold); border-radius: 8px; padding: 2px 8px; vertical-align: middle; }
#sheet-body h3 { margin: 18px 0 8px; font-size: 1rem; border-bottom: 2px dashed #e0cfa8; padding-bottom: 4px; }
#sheet-body p { margin: 8px 0; line-height: 1.4; }

.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(118px, 1fr)); gap: 8px; }
.card {
  border: 0; border-radius: 14px; padding: 10px 6px; background: #fff; box-shadow: 0 3px 0 #d8c39a;
  display: flex; flex-direction: column; align-items: center; gap: 3px; text-align: center;
}
.card .em { font-size: 2rem; }
.card small { color: var(--muted); font-size: 0.75rem; }
.card.troop small:first-of-type { min-height: 2.4em; }
.cost { font-weight: 700; font-size: 0.85rem; }
.cost.no { color: var(--danger); }
.chips { display: flex; flex-wrap: wrap; gap: 6px; }
.chip { background: #fff; border-radius: 999px; padding: 4px 10px; box-shadow: 0 2px 0 #d8c39a; font-weight: 700; }
.bar { height: 10px; background: #e6d6b3; border-radius: 6px; overflow: hidden; margin: 4px 0 10px; }
.bar i { display: block; height: 100%; background: linear-gradient(90deg, #f5a623, var(--primary)); }
.busy { background: #fff1c2; border-radius: 10px; padding: 8px 10px; }
.upbox { background: #fff; border-radius: 14px; padding: 12px; margin: 10px 0; display: flex; flex-direction: column; gap: 8px; }
.row { display: flex; gap: 8px; flex-wrap: wrap; }
.stats { width: 100%; border-collapse: collapse; }
.stats td { padding: 5px 2px; border-bottom: 1px solid #eadbb8; }
.stats td:last-child { text-align: right; font-weight: 700; }
.tips { background: #e8f4dd; border-radius: 12px; padding: 4px 12px; }

.line { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid #eadbb8; }
.line .em { font-size: 1.8rem; width: 40px; text-align: center; }
.line > span:nth-child(2) { flex: 1; }
.line small { color: var(--muted); }
.acts { display: flex; gap: 6px; flex-shrink: 0; }
.log.def { background: #fdebe8; border-radius: 10px; padding: 8px; }
.up { color: var(--ok); font-weight: 700; }
.down { color: var(--danger); font-weight: 700; }

.result { text-align: center; }
.bigstars { font-size: 3rem; letter-spacing: 6px; }
.bigstars span { filter: grayscale(1) opacity(0.3); display: inline-block; }
.bigstars span.on { filter: none; animation: pop 0.5s ease-out backwards; }
.bigstars span.on:nth-child(2) { animation-delay: 0.25s; }
.bigstars span.on:nth-child(3) { animation-delay: 0.5s; }
@keyframes pop { from { transform: scale(0) rotate(-90deg); } 70% { transform: scale(1.3); } }
.pct { font-size: 1.6rem; font-weight: 800; margin: 4px 0; }

#toast {
  position: fixed; left: 50%; bottom: 100px; transform: translate(-50%, 30px); opacity: 0; pointer-events: none; z-index: 20;
  background: rgba(20, 14, 8, 0.92); color: #fff; padding: 10px 16px; border-radius: 14px; max-width: calc(100% - 32px);
  text-align: center; transition: 0.25s; font-weight: 600;
}
#toast.show { opacity: 1; transform: translate(-50%, 0); }
#toast.bad { background: rgba(160, 30, 25, 0.95); }

/* ---------- 3D sürüm: oyun fontu ve kamera butonları ---------- */
.title-card h1, .sheet-head h2, #nav button, .tbtn, .btn, .pill, .pct, #sheet-body h3 { font-family: var(--title); font-weight: 400; letter-spacing: 0.3px; }
.pill { background: linear-gradient(rgba(40, 28, 16, 0.85), rgba(20, 14, 8, 0.85)); box-shadow: 0 2px 6px rgba(0, 0, 0, 0.3); }
#hud, #bhud { position: absolute; top: 0; left: 0; right: 0; background: linear-gradient(rgba(0, 0, 0, 0.45), transparent); pointer-events: none; }
#game { position: fixed; inset: 0; display: flex; flex-direction: column; }
.stage { position: relative; flex: 1; min-height: 0; }
#camctl { position: absolute; right: 10px; bottom: 10px; display: flex; gap: 6px; }
#camctl button {
  width: 44px; height: 44px; border-radius: 50%; border: 2px solid rgba(255, 255, 255, 0.6); font-size: 1.3rem;
  background: rgba(20, 14, 8, 0.7); color: #fff; box-shadow: 0 3px 8px rgba(0, 0, 0, 0.35);
}
#camctl button:active { transform: scale(0.92); }
#hint { top: 54px; }

/* ---------- küçük harita ve dünya haritası ---------- */
#minimap-wrap { position: absolute; right: 10px; top: 52px; display: flex; flex-direction: column; gap: 6px; align-items: stretch; z-index: 3; }
#minimap { width: 150px; height: 150px; border-radius: 12px; border: 3px solid #c9a36a; box-shadow: 0 4px 14px rgba(0,0,0,0.45); background: #1b5f8f; touch-action: none; cursor: crosshair; display: block; }
#world-btn { border: 0; border-radius: 10px; padding: 6px; font-family: var(--title); color: #fff; background: linear-gradient(#3d8fd6, #2366a8); box-shadow: 0 3px 0 #17497a; cursor: pointer; }
@media (max-width: 600px) { #minimap { width: 104px; height: 104px; } #minimap-wrap { top: 92px; } }
#worldmap { position: fixed; inset: 0; z-index: 12; background: #0c3e6e; }
#worldmap canvas { position: absolute; inset: 0; width: 100%; height: 100%; display: block; }
.wm-top { position: absolute; top: 0; left: 0; right: 0; display: flex; align-items: center; gap: 10px; padding: 12px 16px; padding-top: max(12px, env(safe-area-inset-top)); color: #fff; background: linear-gradient(rgba(0,0,0,0.45), transparent); }
.wm-top h2 { flex: 1; margin: 0; font-family: var(--title); font-weight: 400; text-shadow: 0 2px 4px rgba(0,0,0,0.5); }
.wm-bottom { position: absolute; left: 50%; bottom: 16px; transform: translateX(-50%); width: min(460px, calc(100% - 32px)); padding-bottom: env(safe-area-inset-bottom); text-align: center; }
.wm-info { color: #fff; background: rgba(10,20,40,0.6); border-radius: 12px; padding: 8px 12px; margin: 0 0 8px; }
/* bildirimler üstte: savaşta kıyıya yanaşan gemiyi kapatmasın */
#toast { bottom: auto; top: 64px; transform: translate(-50%, -20px); }
#toast.show { transform: translate(-50%, 0); }

/* ---------- şehir paneli ---------- */
.citytop { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; text-align: center; }
.citytop div { background: #fff; border-radius: 12px; padding: 8px; box-shadow: 0 2px 0 #d8c39a; }
.citytop b { display: block; font-size: 1.3rem; font-family: var(--title); font-weight: 400; }
.citytop small { color: var(--muted); }
.need { display: grid; grid-template-columns: 110px 1fr 44px; align-items: center; gap: 8px; margin: 4px 0; }
.need .bar { margin: 0; }
.need small { grid-column: 1 / -1; margin-top: -2px; }
.taxrow .btn { flex: 1; min-width: 70px; line-height: 1.2; }
.taxrow small { font-family: var(--font); font-size: 0.7rem; opacity: 0.85; }
.card .rank { font-size: 0.78rem; font-weight: 700; color: #7a4a10; background: #ffe9b8; border-radius: 999px; padding: 1px 8px; }
.card .rank small { color: #a07a40; }
