.modal-backdrop {
  position: fixed; inset: 0; z-index: 20;
  background: rgba(0,0,0,0.6);
  display: flex; align-items: center; justify-content: center; padding: 16px;
}
.modal-box {
  background: var(--panel-bg); border: 1px solid var(--panel-border); border-radius: 12px;
  padding: 18px; width: 100%; max-width: 420px; max-height: 85vh; overflow-y: auto;
  touch-action: pan-y; -webkit-overflow-scrolling: touch;
  box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}
.modal-box.wide { max-width: 640px; }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-head h2, .modal-head h3 { margin: 0; color: var(--gold-bright); font-size: 1.15rem; }
.modal-close { font-size: 1.2rem; color: #b8a888; width: 30px; height: 30px; }

.pause-box { text-align: center; }
.pause-box .btn-primary, .pause-box .btn-secondary { width: 100%; margin-top: 8px; padding: 12px; border-radius: 8px; font-weight: 700; letter-spacing: 1px; }
.btn-primary { background: linear-gradient(180deg, #c9401f, #7a2210); color: #fff2d8; }
.btn-secondary { background: linear-gradient(180deg, #3a2f22, #241c14); color: var(--gold-bright); border: 1px solid var(--panel-border); }
.pause-toggles { display: flex; gap: 10px; justify-content: center; margin: 14px 0; }

/* build / tower panels */
.build-options { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; }
.build-option {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  background: #1c1610; border: 1px solid var(--panel-border); border-radius: 8px; padding: 10px 6px;
  min-height: 92px; justify-content: center;
}
.build-option:disabled { opacity: .4; }
.build-option:active:not(:disabled) { transform: scale(0.97); }
.build-swatch { width: 20px; height: 20px; border-radius: 50%; }
.build-name { font-size: .78rem; font-weight: 700; color: var(--gold-bright); }
.build-role { font-size: .64rem; color: #a89878; text-align: center; }
.build-cost { font-size: .74rem; color: var(--warn); }

.tower-stats { display: flex; flex-direction: column; gap: 4px; margin: 10px 0; font-size: .85rem; color: #d8cdb4; }
.tower-actions { display: flex; gap: 8px; margin-top: 10px; }
.tower-actions button { flex: 1; padding: 10px; border-radius: 8px; font-weight: 700; font-size: .8rem; }
#btn-tower-upgrade { background: linear-gradient(180deg, #4a7a3a, #2a4a20); color: #eaffda; }
#btn-tower-sell { background: linear-gradient(180deg, #7a3a2a, #4a2010); color: #ffe0d0; }
.tower-targeting { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.target-btn { font-size: .68rem; padding: 7px 2px; border-radius: 6px; background: #1c1610; border: 1px solid var(--panel-border); color: #b8a888; }
.target-btn.active { background: var(--gold); color: #1a1206; }

/* victory / game over */
#screen-victory, #screen-gameover { text-align: center; gap: 14px; background: radial-gradient(ellipse at 50% 30%, rgba(224,193,90,0.12), transparent 60%), #0a0705; }
.result-title { font-size: 2.2rem; letter-spacing: 2px; }
#screen-victory .result-title { color: var(--gold-bright); text-shadow: 0 0 20px rgba(255,215,90,0.6); }
#screen-gameover .result-title { color: #ff6a6a; text-shadow: 0 0 20px rgba(200,30,30,0.6); }
.stat-row { color: #d8cdb4; margin-bottom: 6px; font-size: .95rem; }
.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 8px; width: min(420px, 90vw); margin: 0 auto 16px; }
.stat-grid div { background: #1c1610; border: 1px solid var(--panel-border); border-radius: 8px; padding: 8px; font-size: .75rem; color: #b8a888; display: flex; flex-direction: column; gap: 2px; }
.stat-grid b { color: var(--gold-bright); font-size: 1rem; }
.nickname-box { width: min(340px, 90vw); display: flex; flex-direction: column; gap: 8px; margin-bottom: 12px; }
.nickname-box input { padding: 10px; border-radius: 8px; border: 1px solid var(--panel-border); background: #140f0a; color: #e8e2d0; text-align: center; font-size: .95rem; }
.nickname-msg { font-size: .78rem; min-height: 16px; color: #b8a888; }
.nickname-msg.ok { color: var(--ok); }
.nickname-msg.error { color: var(--danger); }
.result-buttons { display: flex; flex-direction: column; gap: 10px; width: min(320px, 88vw); }

/* leaderboard */
.lb-tabs { display: flex; gap: 8px; margin-bottom: 10px; }
.lb-tab { padding: 6px 12px; border-radius: 6px; background: #1c1610; border: 1px solid var(--panel-border); font-size: .78rem; color: #b8a888; }
.lb-tab.active { background: var(--gold); color: #1a1206; }
.lb-row { display: grid; grid-template-columns: 40px 1fr 90px 60px; gap: 6px; padding: 7px 4px; border-bottom: 1px solid #241c14; font-size: .82rem; align-items: center; }
.lb-row.top { color: var(--gold-bright); font-weight: 700; }
.lb-rank { color: #a89878; }
.lb-score { text-align: right; color: var(--gold); }
.lb-level { text-align: right; color: #a89878; font-size: .72rem; }
.lb-loading { text-align: center; color: #a89878; padding: 20px; font-size: .85rem; }

/* how to play */
.howto-list { display: flex; flex-direction: column; gap: 8px; margin: 10px 0; padding-left: 20px; color: #d8cdb4; font-size: .88rem; }
.howto-keys { display: grid; grid-template-columns: repeat(2,1fr); gap: 6px; font-size: .78rem; color: #b8a888; margin-top: 10px; }

/* settings */
.settings-row { display: flex; align-items: center; justify-content: space-between; padding: 10px 0; border-bottom: 1px solid #241c14; font-size: .88rem; }
.settings-row:last-child { border-bottom: none; }
.switch { position: relative; width: 42px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-track { position: absolute; inset: 0; background: #3a2f22; border-radius: 11px; transition: .2s; }
.switch-track::after { content: ''; position: absolute; width: 16px; height: 16px; left: 3px; top: 3px; background: #b8a888; border-radius: 50%; transition: .2s; }
.switch input:checked + .switch-track { background: var(--gold); }
.switch input:checked + .switch-track::after { transform: translateX(20px); background: #1a1206; }

#toast { position: fixed; bottom: 24px; left: 50%; transform: translateX(-50%) translateY(20px); background: rgba(10,8,6,0.95); border: 1px solid var(--panel-border); color: var(--gold-bright); padding: 10px 18px; border-radius: 8px; font-size: .85rem; opacity: 0; pointer-events: none; transition: .25s; z-index: 50; white-space: nowrap; }
#toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }
