@font-face { font-family: 'Rubik'; font-weight: 700; font-display: swap; src: url(fonts/rubik-cyrillic-700-normal.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Rubik'; font-weight: 700; font-display: swap; src: url(fonts/rubik-latin-700-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }
@font-face { font-family: 'Rubik'; font-weight: 900; font-display: swap; src: url(fonts/rubik-cyrillic-900-normal.woff2) format('woff2'); unicode-range: U+0301, U+0400-045F, U+0490-0491, U+04B0-04B1, U+2116; }
@font-face { font-family: 'Rubik'; font-weight: 900; font-display: swap; src: url(fonts/rubik-latin-900-normal.woff2) format('woff2'); unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD; }

:root {
  --panel: rgba(22, 26, 42, 0.82);
  --panel-solid: #232a43;
  --edge: rgba(255, 255, 255, 0.1);
  --gold: #ffd23f;
  --ink: #24304a;
  --top: max(10px, env(safe-area-inset-top), calc(var(--tg-safe-area-inset-top, 0px) + var(--tg-content-safe-area-inset-top, 0px)));
  --bottom: max(12px, env(safe-area-inset-bottom), calc(var(--tg-safe-area-inset-bottom, 0px) + var(--tg-content-safe-area-inset-bottom, 0px)));
  --left: max(10px, env(safe-area-inset-left), calc(var(--tg-safe-area-inset-left, 0px) + var(--tg-content-safe-area-inset-left, 0px)));
  --right: max(10px, env(safe-area-inset-right), calc(var(--tg-safe-area-inset-right, 0px) + var(--tg-content-safe-area-inset-right, 0px)));
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body {
  margin: 0; height: 100%; overflow: hidden; background: #2d5a33; color: #fff;
  font-family: 'Rubik', system-ui, sans-serif; font-weight: 700;
  user-select: none; -webkit-user-select: none; -webkit-touch-callout: none;
  touch-action: none; overscroll-behavior: none;
}
canvas#scene { position: fixed; inset: 0; width: 100%; height: 100%; display: block; touch-action: none; outline: none; }
button { font: inherit; color: inherit; cursor: pointer; }
button:disabled { cursor: default; }
[hidden] { display: none !important; }
.ico, .ico svg, button svg { display: block; }

#hud { position: fixed; inset: 0; pointer-events: none; z-index: 5; }
.topbar { position: absolute; top: var(--top); left: var(--left); right: var(--right); display: flex; gap: 8px; align-items: center; }
.stat {
  display: flex; align-items: center; gap: 6px; padding: 5px 12px 5px 7px; border-radius: 13px;
  background: var(--panel); border: 2px solid var(--edge); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
  font-weight: 900; font-size: clamp(15px, 1.4vw + 9px, 22px); line-height: 1; white-space: nowrap;
}
.stat .ico svg { width: 1.4em; height: 1.4em; }
.stat.bump { animation: bump 0.35s ease-out; }
@keyframes bump { 40% { transform: scale(1.14); } }
.round-btn {
  pointer-events: auto; width: 46px; height: 46px; border-radius: 14px; padding: 0; display: grid; place-items: center;
  background: var(--panel); border: 2px solid var(--edge); box-shadow: 0 3px 0 rgba(0, 0, 0, 0.25);
}
.round-btn svg { width: 26px; height: 26px; }
.round-btn:active { transform: translateY(2px); }
#btn-pause { margin-left: auto; }
.round-btn.lang { width: auto; padding: 0 14px 0 10px; display: flex; align-items: center; gap: 6px; font-weight: 900; font-size: 16px; }

#boss-bar {
  position: absolute; top: calc(var(--top) + 52px); left: 50%; transform: translateX(-50%); width: min(70vw, 420px);
  display: flex; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 12px; background: var(--panel);
}
#boss-bar .ico svg { width: 24px; height: 24px; }
#boss-name { font-size: 14px; white-space: nowrap; }
#boss-bar .track { flex: 1; height: 12px; border-radius: 6px; background: rgba(0, 0, 0, 0.5); overflow: hidden; }
#boss-fill { height: 100%; width: 100%; background: linear-gradient(#ff7a8f, #e0284a); transition: width 0.2s; }

#wave-call { position: absolute; top: calc(var(--top) + 54px); left: 50%; transform: translateX(-50%); width: max-content; max-width: calc(100vw - 32px); display: flex; flex-direction: column; align-items: center; gap: 8px; }
#wave-label { padding: 5px 14px; border-radius: 11px; background: var(--panel); font-size: 15px; white-space: nowrap; }
.wave-buttons { display: flex; flex-wrap: wrap; justify-content: center; gap: 8px; align-items: center; }
.wave-buttons .btn { white-space: nowrap; }

.btn {
  pointer-events: auto; border: 0; border-radius: 16px; padding: 11px 22px; display: inline-flex; align-items: center; justify-content: center; gap: 10px;
  font-weight: 900; font-size: 19px; color: #fff; text-shadow: 0 2px 0 rgba(0, 0, 0, 0.28); line-height: 1.05;
  box-shadow: 0 5px 0 var(--shade, #1d4a99), 0 9px 18px rgba(0, 0, 0, 0.25); transition: transform 0.08s, box-shadow 0.08s;
}
.btn svg { width: 24px; height: 24px; flex: none; }
.btn small { display: block; font-size: 12px; font-weight: 700; opacity: 0.88; margin-top: 3px; }
.btn > span:not(.ico) { display: flex; flex-direction: column; align-items: center; }
.btn:active:not(:disabled) { transform: translateY(4px); box-shadow: 0 1px 0 var(--shade, #1d4a99), 0 4px 8px rgba(0, 0, 0, 0.2); }
.btn:disabled { filter: grayscale(0.7); opacity: 0.6; }
.btn.big { font-size: 22px; padding: 14px 26px; min-width: min(78vw, 270px); }
.btn.small { font-size: 15px; padding: 9px 14px; }
.btn.small svg { width: 20px; height: 20px; }
.btn-green { background: linear-gradient(#72d944, #45a92a); --shade: #2c7419; }
.btn-orange { background: linear-gradient(#ffb43c, #f2870f); --shade: #b05a05; }
.btn-blue { background: linear-gradient(#55a0ff, #2f6fd6); --shade: #1d4a99; }
.btn-ad { background: linear-gradient(#a174ff, #6d3fe0); --shade: #4523a3; }
.btn-red { background: linear-gradient(#ff7a5c, #d9402c); --shade: #8f1f14; }
.btn-teal { background: linear-gradient(#5fe0d0, #1f9c92); --shade: #136b64; }
#btn-wave { animation: pulse 1.6s ease-in-out infinite; }
@keyframes pulse { 50% { transform: scale(1.06); } }

#hint {
  position: absolute; top: calc(var(--top) + 150px); left: 50%; transform: translateX(-50%); width: max-content; max-width: min(92vw, 560px);
  padding: 10px 16px; border-radius: 14px; background: rgba(255, 255, 255, 0.95); color: var(--ink);
  font-size: 16px; text-align: center; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.18), 0 10px 24px rgba(0, 0, 0, 0.2);
}
#hint.pop { animation: hint-in 0.35s ease-out; }
@keyframes hint-in { from { opacity: 0; transform: translate(-50%, -10px); } }

#panel { position: absolute; bottom: var(--bottom); left: 50%; transform: translateX(-50%); }
.panel-row { display: flex; gap: 10px; align-items: stretch; }
.build-card, .action-card, .tower-card {
  pointer-events: auto; position: relative; width: clamp(92px, 9vw + 40px, 122px); padding: 4px 6px 8px; border-radius: 16px;
  display: flex; flex-direction: column; align-items: center; gap: 2px; text-align: center;
  background: var(--panel); border: 3px solid #3d4868; box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3); color: #fff;
}
.build-card img, .action-card img, .tower-card img { width: 100%; aspect-ratio: 1; object-fit: contain; margin: -6px 0 -4px; pointer-events: none; }
.build-card .name, .action-card .name, .tower-card .name { font-size: 15px; font-weight: 900; }
.build-card .info, .tower-card .info { font-size: 11px; opacity: 0.75; line-height: 1.1; }
.cost { display: flex; align-items: center; gap: 4px; margin-top: auto; padding: 3px 9px 3px 4px; border-radius: 10px; background: rgba(0, 0, 0, 0.35); font-weight: 900; font-size: 15px; }
.cost svg { width: 18px; height: 18px; }
.key { position: absolute; top: 5px; left: 5px; padding: 1px 6px; border-radius: 6px; background: #fff; color: #222; font-size: 12px; font-weight: 900; }
.build-card:not(:disabled):hover, .action-card:not(:disabled):hover { border-color: var(--gold); }
.build-card:not(:disabled):active, .action-card:not(:disabled):active { transform: translateY(3px); }
.build-card:disabled, .action-card:disabled { opacity: 0.55; filter: grayscale(0.6); }
.action-card { justify-content: center; }
.action-card.sell { width: clamp(80px, 6vw + 40px, 100px); }
.action-card.temper:not(:disabled) { border-color: var(--gold); }
.tower-card .info.temper { color: var(--gold); opacity: 1; }
.action-card.sell.armed { border-color: #ff5a5a; background: rgba(120, 24, 24, 0.92); }
.tower-card { border-color: #55638c; }
.tower-card .ammo { width: 80%; height: 8px; margin-top: 4px; border-radius: 4px; background: rgba(0, 0, 0, 0.5); overflow: hidden; }
.ammo-fill { display: block; height: 100%; width: 100%; background: var(--gold); }

#toasts { position: absolute; top: 34%; left: 50%; transform: translateX(-50%); display: flex; flex-direction: column; align-items: center; gap: 6px; }
.toast { padding: 8px 18px; border-radius: 12px; background: var(--panel); font-weight: 900; font-size: 19px; white-space: nowrap; animation: toast 2.4s forwards; }
.toast.good { color: #a6ff7d; }
.toast.bad { color: #ff8080; }
@keyframes toast { 0% { opacity: 0; transform: scale(0.8); } 10%, 75% { opacity: 1; transform: none; } 100% { opacity: 0; transform: translateY(-14px); } }
.floater { position: absolute; transform: translate(-50%, -50%); font-weight: 900; font-size: 21px; color: var(--gold); text-shadow: 0 2px 0 #6b4a00, 0 0 6px rgba(0, 0, 0, 0.45); animation: float 0.95s ease-out forwards; white-space: nowrap; }
.floater.red { color: #ff6464; text-shadow: 0 2px 0 #5a0d0d, 0 0 6px rgba(0, 0, 0, 0.45); }
.floater.purple { color: #d6a8ff; text-shadow: 0 2px 0 #3a1460; }
@keyframes float { from { opacity: 1; margin-top: 0; } to { opacity: 0; margin-top: -48px; } }

.edge-arrow { position: absolute; left: 0; top: 0; width: 0; height: 0; }
.edge-arrow .pointer { position: absolute; left: -22px; top: -22px; width: 44px; height: 44px; }
.edge-arrow .pointer svg { width: 26px; height: 26px; margin: 9px; transform: translateY(-27px); }
.edge-arrow .glyph { position: absolute; left: -19px; top: -19px; width: 38px; height: 38px; padding: 6px; border-radius: 50%; border: 3px solid #fff; animation: pulse 0.9s ease-in-out infinite; }
.edge-arrow .glyph svg { width: 100%; height: 100%; }
.edge-arrow.ammo .glyph { background: #ff9b1f; }
.edge-arrow.repair .glyph { background: #ef3e3e; }
.edge-arrow.thief .glyph { background: #9b51e0; }
.edge-arrow.bug .glyph { background: #4fae2f; }
.edge-arrow.ice .glyph { background: #3f9fe0; }
.edge-arrow.curse .glyph { background: #7a3fb0; }

#stick { position: absolute; left: 0; top: 0; width: 0; height: 0; }
#stick::before { content: ''; position: absolute; left: -62px; top: -62px; width: 124px; height: 124px; border-radius: 50%; background: rgba(255, 255, 255, 0.14); border: 3px solid rgba(255, 255, 255, 0.4); }
#stick-knob { position: absolute; left: -27px; top: -27px; width: 54px; height: 54px; border-radius: 50%; background: rgba(255, 255, 255, 0.8); box-shadow: 0 3px 8px rgba(0, 0, 0, 0.3); }

#screens { position: fixed; inset: 0; z-index: 10; }
/* a window taller than the screen starts at the top and scrolls instead of losing its title above the edge */
.screen { position: absolute; inset: 0; display: flex; flex-direction: column; align-items: center; justify-content: center; justify-content: safe center; gap: 18px; padding: var(--top) max(14px, var(--right)) var(--bottom) max(14px, var(--left)); overflow-y: auto; }
.screen.modal { background: rgba(10, 14, 26, 0.55); }
.screen .panel {
  width: 100%; max-width: min(94vw, 440px); padding: 22px 22px 24px; border-radius: 24px; text-align: center;
  background: linear-gradient(#2c3554, #1e2439); border: 3px solid #44507a; box-shadow: 0 10px 0 rgba(0, 0, 0, 0.3), 0 24px 60px rgba(0, 0, 0, 0.45);
  animation: panel-in 0.25s ease-out;
}
.screen .panel.wide { max-width: min(96vw, 840px); }
@keyframes panel-in { from { opacity: 0; transform: scale(0.92); } }
.screen h2 { margin: 0 0 14px; font-size: clamp(24px, 2vw + 16px, 34px); font-weight: 900; text-shadow: 0 3px 0 rgba(0, 0, 0, 0.3); }
.screen .sub { margin: 0 0 16px; font-size: 16px; opacity: 0.85; }
.stack { display: flex; flex-direction: column; align-items: center; gap: 14px; }
.stack .btn:not(.big) { min-width: min(70vw, 220px); }

.menu { gap: 24px; }
.logo { text-align: center; animation: panel-in 0.4s ease-out; }
.logo h1 {
  margin: 0; font-size: clamp(42px, 8vmin, 86px); font-weight: 900; color: var(--gold); line-height: 1;
  -webkit-text-stroke: 7px #5c2a06; paint-order: stroke fill; text-shadow: 0 7px 0 #3a1a04, 0 12px 26px rgba(0, 0, 0, 0.35);
}
.logo p { margin: 10px 0 0; font-size: clamp(17px, 2.4vmin + 6px, 26px); font-weight: 900; color: #fff; -webkit-text-stroke: 4px #2a3020; paint-order: stroke fill; }
.toggles { display: flex; gap: 10px; justify-content: center; margin-top: 6px; }
.stars-total { display: flex; align-items: center; gap: 6px; padding: 6px 14px 6px 8px; border-radius: 12px; background: var(--panel); font-size: 18px; }
.stars-total svg { width: 26px; height: 26px; }

.level-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(138px, 1fr)); gap: 12px; margin-bottom: 18px; }
.level-card {
  position: relative; padding: 12px 8px 10px; border-radius: 18px; border: 3px solid rgba(255, 255, 255, 0.28); color: #fff;
  display: flex; flex-direction: column; align-items: center; gap: 4px; box-shadow: 0 5px 0 rgba(0, 0, 0, 0.3);
  background: linear-gradient(#5fbf47, #3a8f2f); text-shadow: 0 2px 0 rgba(0, 0, 0, 0.3);
}
.level-card.theme-farm { background: linear-gradient(#c7c04a, #8e9a2c); }
.level-card.theme-rocky { background: linear-gradient(#8c9aaf, #5c6a80); }
.level-card.theme-lake { background: linear-gradient(#4fb5d8, #2f7fae); }
.level-card.theme-autumn { background: linear-gradient(#f0913a, #c0521f); }
.level-card .num { font-size: 36px; font-weight: 900; line-height: 1; height: 38px; display: grid; place-items: center; }
.level-card .num svg { width: 34px; height: 34px; }
.level-card .name { font-size: 16px; font-weight: 900; }
.level-card .meta { font-size: 12px; opacity: 0.9; }
.level-card .stars { display: flex; gap: 2px; }
.level-card .stars svg { width: 24px; height: 24px; }
.level-card .resume { position: absolute; top: -10px; right: -6px; padding: 3px 8px; border-radius: 10px; background: var(--gold); color: #4a2d00; font-size: 12px; text-shadow: none; }
.level-card.locked { filter: grayscale(0.85); opacity: 0.7; }
.level-card:not(.locked):active { transform: translateY(3px); }

.card-row { display: flex; gap: 14px; justify-content: center; flex-wrap: wrap; }
.upgrade-card {
  width: 214px; padding: 12px 14px 16px; border-radius: 20px; border: 4px solid var(--gold); background: #fffaf0; color: var(--ink);
  display: flex; flex-direction: column; align-items: center; gap: 6px; box-shadow: 0 6px 0 #b8860b; animation: panel-in 0.3s ease-out backwards;
}
.upgrade-card:nth-child(2) { animation-delay: 0.08s; }
.upgrade-card:nth-child(3) { animation-delay: 0.16s; }
.upgrade-card img { width: 96px; height: 96px; object-fit: contain; }
.upgrade-card .card-icon { width: 96px; height: 96px; display: grid; place-items: center; }
.upgrade-card .card-icon svg { width: 70px; height: 70px; }
.upgrade-card .text { display: flex; flex-direction: column; gap: 6px; }
.upgrade-card b { font-size: 19px; font-weight: 900; }
.upgrade-card .text span { font-size: 14px; line-height: 1.25; }
.upgrade-card:hover { transform: translateY(-3px); }
.upgrade-card:active { transform: translateY(3px); }

.big-stars { display: flex; justify-content: center; gap: 6px; margin-bottom: 8px; }
.big-stars span { animation: star-pop 0.45s ease-out backwards; }
.big-stars span:nth-child(2) { transform: translateY(-10px); }
.big-stars svg { width: 68px; height: 68px; }
@keyframes star-pop { from { opacity: 0; transform: scale(0.2) rotate(-30deg); } }
.result.win h2 { color: var(--gold); }
.result.lose h2 { color: #ff7a7a; }

#loading { position: fixed; inset: 0; z-index: 20; display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 16px; background: radial-gradient(#3f7b45, #24452a); font-size: 20px; }
#boot-error { max-width: min(90vw, 560px); margin: 0; padding: 0 16px; text-align: center; font-size: 18px; line-height: 1.4; }
.spinner { width: 54px; height: 54px; border-radius: 50%; border: 6px solid rgba(255, 255, 255, 0.25); border-top-color: var(--gold); animation: spin 0.9s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 560px), (max-height: 520px) {
  .stat { padding: 4px 9px 4px 5px; gap: 4px; }
  .round-btn { width: 40px; height: 40px; }
  .round-btn svg { width: 22px; height: 22px; }
  #hint { font-size: 14px; top: calc(var(--top) + 140px); }
  .panel-row { gap: 7px; }
  .build-card .info { display: none; }
  .upgrade-card { width: min(84vw, 300px); flex-direction: row; text-align: left; gap: 12px; }
  .upgrade-card img, .upgrade-card .card-icon { width: 64px; height: 64px; flex: none; }
  .upgrade-card .card-icon svg { width: 48px; height: 48px; }
  .card-row { flex-direction: column; align-items: center; }
}
/* on low landscape screens the three cards stand side by side: in a column they would not fit */
@media (max-height: 520px) and (min-width: 700px) {
  .card-row { flex-direction: row; flex-wrap: nowrap; }
  .upgrade-card { width: min(30vw, 240px); flex-direction: column; text-align: center; gap: 4px; padding: 8px 10px 10px; }
  .upgrade-card .text span { font-size: 12px; }
}
@media (max-height: 520px) {
  #hint { top: calc(var(--top) + 52px); left: auto; right: 12px; transform: none; max-width: 34vw; font-size: 13px; padding: 7px 11px; }
  #hint.pop { animation: none; }
  .screen .panel { padding: 14px 18px 16px; }
  .screen h2 { margin-bottom: 8px; }
  .stack { gap: 9px; }
  .btn.big { font-size: 18px; padding: 10px 20px; }
}
.sell-icon { display: grid; place-items: center; flex: 1; width: 100%; }
.sell-icon svg { width: 44px; height: 44px; opacity: 0.9; }
img { -webkit-user-drag: none; user-select: none; }

.btn .badge { margin-left: 2px; min-width: 24px; padding: 2px 7px; border-radius: 12px; background: #ff4d5e; font-size: 14px; text-shadow: none; }
.world-list { max-height: min(62vh, 640px); overflow-y: auto; margin-bottom: 16px; padding-right: 4px; }
.world-title { margin: 6px 0 10px; font-size: 18px; font-weight: 900; text-align: left; opacity: 0.9; }
.level-card.theme-snow { background: linear-gradient(#8fc3e8, #5a8fc2); }
.level-card.theme-canyon { background: linear-gradient(#e0904a, #b0562a); }
.level-card.theme-swamp { background: linear-gradient(#7d9a4a, #4f6a2e); }
.level-card.theme-volcano { background: linear-gradient(#a3433a, #5a2228); }
.level-card.theme-cove { background: linear-gradient(#5fd0d8, #2a8fa8); }
.level-card.theme-graveyard { background: linear-gradient(#6a6a8e, #3e3e5e); }
.level-card.theme-sky { background: linear-gradient(#8fd0ff, #4f9fe0); }
.level-card.theme-desert { background: linear-gradient(#e8bf6a, #b8843e); }
.level-card.theme-jungle { background: linear-gradient(#5aae46, #2f7a2c); }
.level-card.theme-mines { background: linear-gradient(#7a7488, #4a4458); }
.level-card.theme-clockwork { background: linear-gradient(#d8a84a, #8a6a30); }
.level-card.theme-enchanted { background: linear-gradient(#7a5ac8, #3a2a6a); }
.level-card.theme-inferno { background: linear-gradient(#c83a22, #5a1410); }
.forge-stars { display: inline-flex; align-items: center; gap: 6px; padding: 6px 14px 6px 8px; margin-bottom: 14px; border-radius: 12px; background: rgba(0, 0, 0, 0.3); font-size: 18px; }
.forge-stars svg { width: 26px; height: 26px; }
.perk-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(300px, 1fr)); gap: 10px; margin-bottom: 16px; max-height: min(52vh, 520px); overflow-y: auto; }
.perk { display: flex; align-items: center; gap: 10px; padding: 10px 12px; border-radius: 16px; background: rgba(255, 255, 255, 0.06); border: 2px solid rgba(255, 255, 255, 0.08); text-align: left; }
.perk.owned { border-color: rgba(255, 210, 63, 0.45); }
.perk-icon { flex: none; width: 46px; height: 46px; padding: 8px; border-radius: 12px; background: rgba(0, 0, 0, 0.3); }
.perk-icon svg { width: 100%; height: 100%; }
.perk-text { flex: 1; display: flex; flex-direction: column; gap: 3px; font-size: 13px; }
.perk-text b { font-size: 16px; font-weight: 900; }
.pips { display: flex; gap: 4px; }
.pips i { width: 16px; height: 6px; border-radius: 3px; background: rgba(255, 255, 255, 0.18); }
.pips i.on { background: var(--gold); }
.perk .btn.small { flex: none; min-width: 74px; }
.perk-max { flex: none; color: var(--gold); font-weight: 900; padding: 0 8px; }
.row-buttons { display: flex; gap: 12px; justify-content: center; flex-wrap: wrap; }
@media (max-width: 700px) and (orientation: portrait) {
  .panel-row.wide { flex-wrap: wrap; justify-content: center; gap: 7px; width: min(96vw, 420px); }
  .panel-row.wide .build-card { width: calc((100% - 14px) / 3); }
}
@media (max-height: 520px) {
  .panel-row.wide .build-card { width: min(clamp(84px, 9vw + 40px, 122px), calc((100vw - 24px - (var(--n, 7) - 1) * 7px) / var(--n, 7))); }
  .panel-row.wide .build-card .name { font-size: clamp(11px, 1.6vw, 15px); letter-spacing: -0.3px; white-space: nowrap; }
  .perk-grid { max-height: 34vh; }
}
@media (max-width: 560px) {
  .perk-grid { grid-template-columns: 1fr; }
}

.modes { gap: 10px; }
.modes .btn { min-width: 0; padding: 9px 16px; font-size: 16px; }
.modes .btn small { font-size: 11px; }
.stars-total small { font-size: 14px; color: var(--gold); }
.head-row { align-items: center; margin-bottom: 14px; }
.head-row .forge-stars { margin: 0; }
.daily-rule { display: flex; flex-direction: column; gap: 6px; padding: 12px 14px; margin-bottom: 12px; border-radius: 16px; background: rgba(0, 0, 0, 0.3); border: 2px solid rgba(95, 224, 208, 0.45); font-size: 14px; }
.daily-rule b { font-size: 17px; }
.rule-name { display: inline-flex; align-items: center; justify-content: center; gap: 6px; font-weight: 900; font-size: 16px; color: #7ff0e3; }
.rule-name svg { width: 20px; height: 20px; }
.daily-stats { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; font-size: 14px; opacity: 0.9; }
.daily-stats span { display: inline-flex; align-items: center; justify-content: center; gap: 6px; }
.daily-stats svg { width: 20px; height: 20px; }
.big-number { margin: 0 0 8px; font-size: clamp(22px, 2vw + 14px, 30px); font-weight: 900; color: var(--gold); }
.result .record { color: #a6ff7d; font-weight: 900; }
.result .record svg { width: 22px; height: 22px; vertical-align: -5px; margin-right: 4px; }
.lb-list { display: flex; flex-direction: column; gap: 6px; margin-bottom: 14px; max-height: min(48vh, 420px); overflow-y: auto; }
.lb-row { display: grid; grid-template-columns: 34px 32px 1fr auto; align-items: center; gap: 8px; padding: 6px 10px; border-radius: 12px; background: rgba(255, 255, 255, 0.06); font-size: 15px; text-align: left; }
.lb-row.me { background: rgba(255, 210, 63, 0.18); border: 2px solid rgba(255, 210, 63, 0.6); }
.lb-rank { font-weight: 900; text-align: center; opacity: 0.85; }
.lb-avatar { width: 32px; height: 32px; border-radius: 50%; background: rgba(255, 255, 255, 0.15); object-fit: cover; }
.lb-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.lb-score { font-weight: 900; color: var(--gold); white-space: nowrap; }
@media (max-height: 520px) {
  .modes .btn { padding: 7px 12px; font-size: 14px; }
  .lb-list { max-height: 30vh; }
}

.shop .panel { display: flex; flex-direction: column; max-height: calc(100dvh - var(--top) - var(--bottom) - 26px); min-height: 0; }
.shop .panel > * { flex: none; }
.shop .panel > .shop-list { min-height: 0; flex: 1 1 auto; }
.shop-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 14px; max-height: min(56vh, 520px); overflow-y: auto; padding-right: 4px; }
.shop-row { display: grid; grid-template-columns: 46px 1fr auto; align-items: center; gap: 10px; padding: 8px 10px; border-radius: 14px; background: rgba(255, 255, 255, 0.06); border: 2px solid rgba(255, 255, 255, 0.08); text-align: left; }
.shop-row.owned { border-color: rgba(255, 210, 63, 0.45); }
.shop-icon { width: 46px; height: 46px; padding: 8px; border-radius: 12px; background: rgba(0, 0, 0, 0.3); }
.shop-icon svg { width: 100%; height: 100%; }
.shop-icon img { width: 100%; height: 100%; object-fit: contain; image-rendering: pixelated; }
.shop-text { display: flex; flex-direction: column; gap: 2px; font-size: 13px; }
.shop-text b { font-size: 16px; font-weight: 900; }
.shop-row .btn.small { min-width: 92px; }
.shop-row .price { display: inline-flex; align-items: center; gap: 4px; }
.shop-row .price img { width: 18px; height: 18px; }
.shop-owned { color: var(--gold); font-weight: 900; padding: 0 8px; }
.btn-ad.tiny { font-size: 14px; padding: 7px 12px; }

#btn-cry {
  pointer-events: auto; position: absolute; right: 12px; top: calc(var(--top) + 60px); width: 64px; height: 64px; padding: 0;
  border-radius: 50%; border: 3px solid var(--gold); background: var(--panel); box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3); overflow: hidden;
}
#btn-cry .ico { position: relative; width: 36px; height: 36px; margin: 0 auto; }
#btn-cry .ico svg { width: 100%; height: 100%; }
#btn-cry .cd { position: absolute; inset: 0; background: conic-gradient(rgba(0, 0, 0, 0.62) calc(var(--p, 0) * 1%), transparent 0); }
#btn-cry .key { position: absolute; top: 4px; right: 8px; font-size: 12px; color: #fff; opacity: 0.8; }
#btn-cry.ready { animation: cry-ready 1.4s ease-in-out infinite; }
#btn-cry.ready .cd { display: none; }
#btn-cry:not(.ready) { border-color: rgba(255, 255, 255, 0.3); }
#btn-cry:active { transform: translateY(3px); }
@keyframes cry-ready { 50% { box-shadow: 0 4px 0 rgba(0, 0, 0, 0.3), 0 0 18px rgba(255, 210, 63, 0.7); } }
@media (max-width: 560px), (max-height: 520px) {
  #btn-cry { width: 54px; height: 54px; right: 10px; top: calc(var(--top) + 52px); }
  #btn-cry .ico { width: 30px; height: 30px; }
  #btn-cry .key { display: none; }
}

.hero-pick { min-width: min(78vw, 270px); }
.hero-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; margin-bottom: 16px; max-height: min(62vh, 640px); overflow-y: auto; padding: 4px; }
.hero-card { display: flex; flex-direction: column; align-items: center; gap: 5px; padding: 12px 12px 14px; border-radius: 18px; background: rgba(255, 255, 255, 0.06); border: 3px solid rgba(255, 255, 255, 0.1); text-align: center; }
.hero-card.picked { border-color: var(--gold); background: rgba(255, 210, 63, 0.1); }
.hero-card.locked { filter: grayscale(0.8); opacity: 0.7; }
.hero-card img { width: 120px; height: 120px; object-fit: contain; }
.hero-name { font-size: 19px; font-weight: 900; }
.hero-line { font-size: 12.5px; line-height: 1.25; opacity: 0.9; }
.hero-line.cry { color: #7ff0e3; }
.hero-bars { display: flex; flex-direction: column; gap: 3px; width: 100%; margin: 4px 0 6px; }
.hero-stat { display: grid; grid-template-columns: 74px 1fr; align-items: center; gap: 6px; font-size: 11px; text-align: left; }
.hero-stat i { font-style: normal; opacity: 0.8; }
.hero-stat b { display: block; height: 8px; border-radius: 4px; background: rgba(0, 0, 0, 0.4); overflow: hidden; }
.hero-stat u { display: block; height: 100%; background: linear-gradient(90deg, #72d944, #ffd23f); text-decoration: none; }
.hero-locked { display: inline-flex; align-items: center; gap: 4px; font-size: 13px; opacity: 0.85; }
.hero-locked svg { width: 18px; height: 18px; }
.hero-card .look { margin-top: 4px; }
@media (max-width: 560px) {
  .hero-grid { grid-template-columns: 1fr 1fr; gap: 8px; }
  .hero-card img { width: 84px; height: 84px; }
  .hero-card { padding: 8px 6px 10px; }
  .hero-line { font-size: 11px; }
}
.loadout-count { display: block; margin: -4px 0 10px; color: var(--gold); font-weight: 900; }
.loadout-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 10px; margin-bottom: 16px; max-height: min(58vh, 560px); overflow-y: auto; padding: 4px; }
.tower-pick { display: flex; flex-direction: column; align-items: center; gap: 3px; padding: 8px 6px 10px; border-radius: 16px; background: rgba(255, 255, 255, 0.06); border: 3px solid rgba(255, 255, 255, 0.1); color: inherit; font: inherit; text-align: center; cursor: pointer; }
.tower-pick.picked { border-color: var(--gold); background: rgba(255, 210, 63, 0.14); }
.tower-pick:disabled { opacity: 0.45; cursor: default; }
.tower-pick img { width: 72px; height: 72px; object-fit: contain; }
.tower-pick b { max-width: 100%; font-size: 15px; font-weight: 900; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.tower-pick span { font-size: 11px; line-height: 1.2; opacity: 0.85; }
@media (max-width: 700px) {
  .loadout-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 8px; }
  .tower-pick { padding: 6px 4px 8px; }
  .tower-pick img { width: 48px; height: 48px; }
  .tower-pick b { font-size: 12.5px; letter-spacing: -0.3px; }
  .tower-pick span { font-size: 10px; }
}
@media (max-height: 520px) {
  .loadout-grid { grid-template-columns: repeat(5, minmax(0, 1fr)); max-height: 52vh; }
  .tower-pick { padding: 4px 4px 6px; }
  .tower-pick img { width: 40px; height: 40px; }
  .tower-pick span { display: none; }
}
@keyframes tower-tutorial-pulse { 50% { outline-color: #fff9d0; outline-offset: 6px; } }
.tutorial-focus { outline: 3px solid #ffd75e !important; outline-offset: 3px; animation: tower-tutorial-pulse 1.2s ease-in-out infinite; }
.screen .panel { position: relative; }
.modal-close { position: absolute; right: 8px; top: 8px; z-index: 3; font-size: 26px; }
@media (prefers-reduced-motion: reduce) { .tutorial-focus { animation: none; } }
.purchase-terms { white-space: pre-line; text-align: left; font-size: .85em; line-height: 1.4; }
.board-privacy { display: flex; gap: 10px; align-items: center; text-align: left; margin: 16px 0 6px; }
.board-privacy input { width: 22px; height: 22px; flex-shrink: 0; accent-color: #659a30; }
.board-categories { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.board-categories .btn { min-width: 0; white-space: normal; padding: 8px 6px; font-size: 14px; }
.bonuses .panel { display: flex; flex-direction: column; max-height: calc(100dvh - var(--top) - var(--bottom) - 26px); min-height: 0; }
.bonuses .panel > * { flex: none; }
.bonuses .panel > .shop-list { min-height: 0; flex: 1 1 auto; max-height: min(64dvh, 540px); padding-right: 0; }
.bonuses .shop-row { grid-template-columns: minmax(0, 1fr) auto; }
.bonuses .shop-icon { display: none; }
.bonuses .shop-text { min-width: 0; overflow-wrap: anywhere; }
.bonuses .shop-row .btn.small { min-width: 76px; padding: 8px 10px; font-size: 14px; }
