:root {
  --wood: #a1683a;
  --wood-d: #7c4e2a;
  --cream: #fff7e6;
  --ink: #3a2a1a;
  --accent: #ef8b3c;
  --green: #5fb14a;
  --red: #e05656;
  --panel: #fffaf0;
  --shadow: 0 10px 30px rgba(60, 40, 20, .35);
  font-family: 'Nunito', 'Segoe UI', system-ui, -apple-system, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  background: radial-gradient(1200px 700px at 50% -10%, #cfe8ff, #9ec9e8 40%, #6a97bd 100%);
  color: var(--ink);
  overflow: hidden;
  -webkit-user-select: none; user-select: none;
}

#stage {
  position: fixed; inset: 0;
  display: grid; place-items: center;
  padding: 12px;
}

/* 16:9 sahne, ekrana sığacak şekilde ölçeklenir */
#app {
  position: relative;
  width: min(100vw - 24px, (100vh - 24px) * (16 / 9));
  aspect-ratio: 16 / 9;
  border-radius: 22px;
  overflow: hidden;
  box-shadow: var(--shadow), inset 0 0 0 6px rgba(255,255,255,.15);
  background: #79b148;
}
#game { display: block; width: 100%; height: 100%; }

/* ---------------- HUD ---------------- */
#hud {
  position: absolute; top: 0; left: 0; right: 0;
  display: flex; align-items: center; gap: 10px;
  padding: 12px 14px;
  background: linear-gradient(to bottom, rgba(40,26,12,.55), rgba(40,26,12,0));
  pointer-events: none;
}
#hud .grow { flex: 1; }
#hud > * { pointer-events: auto; }

.stat {
  display: flex; align-items: center; gap: 7px;
  background: var(--cream);
  border: 3px solid #fff;
  border-radius: 999px;
  padding: 6px 14px 6px 10px;
  font-size: clamp(14px, 1.6vw, 20px);
  font-weight: 800;
  box-shadow: 0 4px 0 rgba(0,0,0,.12);
  color: var(--ink);
}
.stat .ic { font-size: 1.1em; }
.stat.gold b { color: #b8860b; }
.stat.lives b { color: var(--red); }

.btn {
  font-family: inherit;
  font-weight: 800;
  font-size: clamp(13px, 1.5vw, 18px);
  color: var(--ink);
  background: var(--cream);
  border: 3px solid #fff;
  border-radius: 14px;
  padding: 8px 14px;
  cursor: pointer;
  box-shadow: 0 4px 0 rgba(0,0,0,.18);
  transition: transform .06s, box-shadow .06s, filter .1s;
}
.btn:hover { filter: brightness(1.05); }
.btn:active { transform: translateY(3px); box-shadow: 0 1px 0 rgba(0,0,0,.18); }
.btn.primary { background: linear-gradient(180deg, #ffb04d, var(--accent)); color: #fff; border-color: #ffd9a8; }
.btn.on { background: linear-gradient(180deg, #7fd36a, var(--green)); color: #fff; border-color: #cdeec2; }
.btn.hidden { display: none; }

/* ---------------- Popup (kur / yükselt) ---------------- */
#popup {
  position: fixed; z-index: 40;
  background: var(--panel);
  border: 4px solid #fff;
  border-radius: 18px;
  box-shadow: var(--shadow);
  padding: 12px;
  width: min(360px, 92vw);
  animation: pop .12s ease-out;
}
@keyframes pop { from { transform: scale(.9); opacity: 0; } to { transform: scale(1); opacity: 1; } }
#popup.hidden { display: none; }
#popup::after {
  content: ''; position: absolute; left: 50%; bottom: -12px; transform: translateX(-50%);
  border: 10px solid transparent; border-top-color: #fff;
}
.pop-head { font-weight: 900; font-size: 18px; margin-bottom: 8px; display: flex; align-items: center; gap: 8px; }

.tw-list { display: flex; flex-direction: column; gap: 8px; }
.tw-card {
  display: flex; align-items: center; gap: 10px; text-align: left;
  background: #fff; border: 2px solid #f0e6d2; border-radius: 14px;
  padding: 8px; cursor: pointer; font-family: inherit;
  transition: transform .06s, border-color .1s;
}
.tw-card:hover { border-color: var(--accent); transform: translateY(-1px); }
.tw-card.poor { opacity: .55; }
.tw-card.locked { opacity: .5; filter: grayscale(.5); cursor: not-allowed; }
.locktag { font-size: 10px; color: #c0392b; font-weight: 800; }
.tw-ic {
  width: 42px; height: 42px; flex: 0 0 42px; border-radius: 12px;
  display: grid; place-items: center; font-size: 22px;
  box-shadow: inset 0 -3px 0 rgba(0,0,0,.2);
}
.tw-info { flex: 1; min-width: 0; }
.tw-name { font-weight: 900; font-size: 15px; }
.tw-sub { font-size: 11px; color: #8a7a63; line-height: 1.2; }
.tw-stats { display: flex; gap: 8px; font-size: 11px; font-weight: 700; color: #6b5b45; margin-top: 3px; }
.tw-stats.big { gap: 14px; font-size: 15px; margin: 6px 0 10px; justify-content: center; }
.tw-cost { font-weight: 900; font-size: 14px; color: #b8860b; white-space: nowrap; }
.tw-cost.no { color: var(--red); }

.lvl { display: inline-flex; gap: 3px; margin-left: auto; }
.dot { width: 9px; height: 9px; border-radius: 50%; background: #e5dccb; box-shadow: inset 0 0 0 1px #d3c6ab; }
.dot.on { background: #f2c94c; box-shadow: inset 0 0 0 1px #b8901a; }

.pop-actions { display: flex; gap: 8px; }
.pop-actions .up { flex: 1; background: linear-gradient(180deg, #7fd36a, var(--green)); color: #fff; border-color: #cdeec2; }
.pop-actions .up.poor { background: #cfc7b6; color: #7a6f5a; border-color: #fff; }
.pop-actions .up.maxed { flex: 1; background: linear-gradient(180deg, #ffd97a, #f2b53c); color: #6b4e11; }
.pop-actions .sell { background: #fff; }
.pop-actions .up b { font-weight: 900; }

/* ---------------- Radial menü (kule etrafı) ---------------- */
#radial { position: fixed; z-index: 45; width: 0; height: 0; }
#radial.hidden { display: none; }
.rad-btn {
  position: absolute; transform: translate(-50%, -50%);
  width: 54px; height: 54px; border-radius: 50%;
  background: var(--cream); border: 3px solid #fff;
  box-shadow: 0 4px 0 rgba(0,0,0,.22);
  font-size: 19px; cursor: pointer; font-family: inherit;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 0;
  animation: pop .12s ease-out;
  line-height: 1;
}
.rad-btn small { font-size: 9px; font-weight: 900; color: var(--ink); margin-top: 1px; }
.rad-btn:active { transform: translate(-50%, calc(-50% + 2px)); box-shadow: 0 2px 0 rgba(0,0,0,.22); }
.rad-btn.up { left: 0; top: -66px; background: linear-gradient(180deg, #7fd36a, var(--green)); border-color: #cdeec2; }
.rad-btn.up small { color: #fff; }
.rad-btn.up.poor { filter: grayscale(.6); opacity: .7; }
.rad-btn.up.maxed { background: linear-gradient(180deg, #ffd97a, #f2b53c); }
.rad-btn.promote { left: -64px; top: -8px; background: linear-gradient(180deg, #ffe08a, #ffb04d); border-color: #ffe9b8; box-shadow: 0 0 12px rgba(255,213,74,.8), 0 4px 0 rgba(0,0,0,.22); }
.rad-btn.sell { left: 64px; top: -8px; }
.rad-name {
  position: absolute; left: 0; top: -108px; transform: translateX(-50%);
  white-space: nowrap; background: var(--panel); border: 2px solid #fff;
  border-radius: 999px; padding: 5px 12px; font-size: 12px; color: var(--ink);
  box-shadow: 0 3px 0 rgba(0,0,0,.15);
}
.rad-name .rad-vet { color: #f2b53c; margin: 0 4px; letter-spacing: 1px; }
.rad-name .rad-kills { color: #8a7a63; font-weight: 800; }

/* ---------------- Beceri Ağacı ---------------- */
.card.skills { width: min(520px, 92%); }
.sk-list { display: flex; flex-direction: column; gap: 8px; max-height: 46vh; overflow-y: auto; padding: 2px; }
.sk-row { display: flex; align-items: center; gap: 10px; background: #fff; border: 2px solid #f0e6d2; border-radius: 12px; padding: 7px 10px; text-align: left; }
.sk-ic { width: 38px; height: 38px; flex: 0 0 38px; border-radius: 10px; display: grid; place-items: center; font-size: 19px; box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); }
.sk-info { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.sk-info b { font-size: 14px; }
.sk-info span { font-size: 11px; color: #8a7a63; }
.sk-pips { font-size: 13px; letter-spacing: 2px; color: #f2b53c; }
.sk-buy { padding: 6px 12px; font-size: 13px; }
.sk-buy.poor { opacity: .55; }
.sk-buy.maxed { background: linear-gradient(180deg, #ffd97a, #f2b53c); color: #6b4e11; }
.medal-line { font-size: clamp(17px, 2.6vw, 24px); font-weight: 900; color: #6b4e11; margin: 2px 0 4px; }
.score-line { font-size: clamp(13px, 1.9vw, 17px); font-weight: 800; color: #8a7a63; margin-bottom: 8px; }
#btn-music.off { opacity: .45; filter: grayscale(.8); }

/* ---------------- Overlay (başlangıç / bitiş) ---------------- */
#overlay {
  position: absolute; inset: 0; z-index: 50;
  display: grid; place-items: center;
  background: rgba(30, 20, 10, .5);
  backdrop-filter: blur(3px);
}
#overlay.hidden { display: none; }
.card {
  background: var(--panel);
  border: 5px solid #fff;
  border-radius: 26px;
  box-shadow: var(--shadow);
  padding: clamp(18px, 3vw, 34px);
  text-align: center;
  width: min(440px, 88%);
  animation: pop .18s ease-out;
}
.card .logo { font-size: clamp(48px, 8vw, 74px); line-height: 1; }
.card h1 { font-size: clamp(26px, 4vw, 40px); margin: 6px 0; color: var(--wood-d); }
.card .tag { color: #7a6a52; font-weight: 600; margin-bottom: 14px; }
.card .stars { font-size: clamp(30px, 6vw, 48px); color: #f2b53c; letter-spacing: 6px; margin: 4px 0 8px; }
.how { list-style: none; text-align: left; display: grid; gap: 8px; margin: 4px auto 18px; width: fit-content; font-weight: 700; color: #5a4a33; }
.how li { font-size: clamp(13px, 1.8vw, 16px); }
.diff-label { font-size: 11px; font-weight: 800; color: #8a7a5c; margin: 2px 0 6px; letter-spacing: .06em; text-transform: uppercase; }
.diff-row { display: flex; gap: 8px; justify-content: center; margin-bottom: 16px; flex-wrap: wrap; }
.diff-btn { font-family: inherit; font-weight: 800; font-size: 14px; color: var(--ink); background: #fff;
  border: 2px solid #e5dccb; border-radius: 12px; padding: 8px 14px; cursor: pointer; box-shadow: 0 3px 0 rgba(0,0,0,.12);
  transition: transform .06s, border-color .1s; }
.diff-btn:hover { border-color: var(--accent); }
.diff-btn:active { transform: translateY(2px); box-shadow: 0 1px 0 rgba(0,0,0,.12); }
.diff-btn.on { background: linear-gradient(180deg, #ffb04d, var(--accent)); color: #fff; border-color: #ffd9a8; }
.btn.big { font-size: clamp(16px, 2.4vw, 22px); padding: 12px 26px; }
.card.win h1 { color: var(--green); }
.card.lose h1 { color: var(--red); }

/* ---------------- Sıradaki dalga önizlemesi ---------------- */
#wavePreview {
  position: absolute; top: 58px; left: 50%; transform: translateX(-50%); z-index: 25;
  background: rgba(38,24,10,.80); border: 2px solid rgba(255,255,255,.25);
  border-radius: 14px; padding: 7px 14px 9px; text-align: center; max-width: 94%;
  box-shadow: 0 6px 20px rgba(0,0,0,.3); animation: pop .18s ease-out;
}
#wavePreview.hidden { display: none; }
.wp-head { font-size: 12px; font-weight: 800; color: #ffe6c2; letter-spacing: .03em; }
.wp-head .wp-num { color: #fff; }
.wp-enemies { display: flex; gap: 6px; justify-content: center; flex-wrap: wrap; margin: 6px 0; }
.wp-chip { display: inline-flex; align-items: center; gap: 4px; background: #fff8ec; border: 2px solid var(--c);
  border-radius: 999px; padding: 3px 9px 3px 6px; font-size: 12px; font-weight: 800; color: var(--ink); }
.wp-chip i { font-style: normal; font-size: 14px; }
.wp-chip b { color: var(--c); }
.wp-chip.boss { background: #2c3e50; color: #fff; border-color: #f2c94c; }
.wp-chip.boss b, .wp-chip.boss em { color: #f2c94c; }
.wp-timer { height: 6px; background: rgba(255,255,255,.2); border-radius: 4px; overflow: hidden; margin: 1px auto 5px; width: 100%; }
.wp-bar { height: 100%; background: linear-gradient(90deg, #7fd36a, #f2c94c); width: 100%; }
.wp-hint { font-size: 10px; color: #ffd9a8; font-weight: 600; }
@media (max-width: 640px) {
  .wp-chip em { display: none; }
  #wavePreview { top: 52px; padding: 6px 10px 8px; }
}

/* ---------------- Alt bar (dock) ---------------- */
#dock {
  position: absolute; left: 0; right: 0; bottom: 0; z-index: 30;
  display: flex; align-items: stretch; gap: 10px;
  padding: 7px 12px 9px;
  background: linear-gradient(to top, rgba(38,24,10,.82), rgba(38,24,10,.30));
}
.dock-group { display: flex; flex-direction: column; gap: 4px; }
.dock-group:first-child { flex: 1; }
.dock-label { font-size: clamp(9px, 1vw, 11px); font-weight: 800; letter-spacing: .04em; color: #ffe6c2; padding-left: 4px; text-shadow: 0 1px 2px #0007; }
.dock-row { display: flex; gap: 8px; overflow-x: auto; overflow-y: hidden; padding: 4px 2px 3px; scrollbar-width: thin; scrollbar-color: rgba(255,255,255,.35) transparent; }
.dock-row::-webkit-scrollbar { height: 5px; }
.dock-row::-webkit-scrollbar-thumb { background: rgba(255,255,255,.32); border-radius: 3px; }
.dock-sep { width: 2px; background: rgba(255,255,255,.18); border-radius: 2px; margin: 16px 2px 4px; }

.dock-card {
  position: relative; width: clamp(58px, 6vw, 76px);
  background: var(--cream); border: 2px solid #fff; border-radius: 12px;
  padding: 6px 4px 5px; text-align: center;
  cursor: grab; touch-action: none;
  box-shadow: 0 3px 0 rgba(0,0,0,.22);
  transition: transform .07s, box-shadow .07s, filter .1s;
}
.dock-card:hover { transform: translateY(-2px); filter: brightness(1.05); }
.dock-card:active { transform: translateY(1px); box-shadow: 0 1px 0 rgba(0,0,0,.22); }
.dock-card.ability { cursor: pointer; }
.dock-card.poor { opacity: .5; filter: grayscale(.35); }
.dock-card.armed { border-color: #ffd54a; box-shadow: 0 0 0 3px rgba(255,213,74,.6), 0 3px 0 rgba(0,0,0,.22); }
.dc-ic { width: clamp(30px, 3.4vw, 38px); height: clamp(30px, 3.4vw, 38px); margin: 0 auto 3px; border-radius: 10px; display: grid; place-items: center; font-size: clamp(16px, 2vw, 20px); box-shadow: inset 0 -3px 0 rgba(0,0,0,.2); }
.dc-name { font-size: clamp(9px, 1vw, 11px); font-weight: 900; color: var(--ink); line-height: 1.05; }
.dc-cost { font-size: clamp(9px, 1vw, 11px); font-weight: 800; color: #b8860b; margin-top: 2px; }
.dc-cd { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; font-size: 24px; font-weight: 900; color: #fff; background: rgba(20,20,30,.62); border-radius: 12px; }
.dc-cd.show { display: flex; }
.dc-lock { position: absolute; inset: 0; display: none; align-items: center; justify-content: center; font-size: 15px; font-weight: 900; color: #fff; background: rgba(20,20,30,.66); border-radius: 12px; }
.dock-card.locked .dc-lock { display: flex; }
.dock-card.locked { cursor: not-allowed; filter: grayscale(.6); opacity: .62; }

body.dragging, body.dragging * { cursor: grabbing !important; }

@media (max-width: 640px) {
  .tw-sub { display: none; }
  .dock-label { font-size: 8px; }
  #dock { gap: 6px; padding: 5px 8px 7px; }
  .dock-row { gap: 5px; }
}

/* Ana sayfaya dönüş bağlantısı (başlangıç/bitiş kartlarında) */
.home-link {
  display: inline-block;
  margin-top: 14px;
  color: rgba(255, 255, 255, 0.55);
  font-size: 13px;
  font-weight: 600;
  text-decoration: none;
  transition: color 0.2s;
}
.home-link:hover { color: #fff; }
