/**
 * Eduplayiffy Game Mode: Tower Defense (الدفاع عن البرج)
 * Stylesheet for Tower Defense Arena, Tactical HUD, Towers, Creeps, and Combat FX.
 */

.td-root {
    position: relative;
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    background: #0f172a;
    background: linear-gradient(180deg, #0f172a 0%, #1e293b 100%);
    border-radius: 16px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.4), inset 0 1px 1px rgba(255, 255, 255, 0.1);
    color: #f8fafc;
    font-family: inherit;
    user-select: none;
    -webkit-user-select: none;
    overflow: hidden;
    box-sizing: border-box;
}

.td-root * {
    box-sizing: border-box;
}

/* Top Stats Status Bar */
.td-status-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 8px;
    padding: 10px 16px;
    background: rgba(15, 23, 42, 0.85);
    border-bottom: 1px solid rgba(255, 255, 255, 0.12);
    backdrop-filter: blur(6px);
}

.td-stat-pill {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.18);
    padding: 5px 12px;
    border-radius: 9999px;
    font-weight: 700;
    font-size: 0.85rem;
}

.td-stat-pill.td-energy {
    background: rgba(245, 158, 11, 0.15);
    border-color: rgba(245, 158, 11, 0.4);
    color: #fbbf24;
}

.td-stat-pill.td-health {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.4);
    color: #f87171;
}

.td-stat-pill.td-wave {
    background: rgba(59, 130, 246, 0.15);
    border-color: rgba(59, 130, 246, 0.4);
    color: #60a5fa;
}

.td-stat-pill.td-streak {
    background: rgba(249, 115, 22, 0.18);
    border-color: rgba(249, 115, 22, 0.5);
    color: #fb923c;
    animation: tdPulse 1.2s infinite alternate;
}

@keyframes tdPulse {
    from { transform: scale(1); }
    to { transform: scale(1.05); }
}

/* Question Banner Panel (Educational Hub) */
.td-question-card {
    background: rgba(30, 41, 59, 0.95);
    border: 1.5px solid rgba(99, 102, 241, 0.35);
    border-radius: 12px;
    padding: 12px 16px;
    margin: 10px 14px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.25);
    transition: all 0.2s ease;
}

.td-question-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 8px;
    margin-bottom: 6px;
}

.td-question-badge {
    font-size: 0.72rem;
    font-weight: 800;
    padding: 3px 8px;
    border-radius: 6px;
    background: #4f46e5;
    color: #fff;
    text-transform: uppercase;
}

.td-question-reward-hint {
    font-size: 0.75rem;
    font-weight: 700;
    color: #fbbf24;
    display: inline-flex;
    align-items: center;
    gap: 4px;
}

.td-question-text {
    font-size: clamp(0.95rem, 2.2vw, 1.15rem);
    font-weight: 700;
    color: #ffffff;
    line-height: 1.4;
    margin: 4px 0 10px;
    word-break: break-word;
}

.td-question-image-wrap {
    text-align: center;
    margin-bottom: 10px;
}

.td-question-image {
    max-height: 140px;
    max-width: 100%;
    border-radius: 8px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    object-fit: contain;
    cursor: pointer;
    transition: transform 0.15s ease;
}

.td-question-image:hover {
    transform: scale(1.04);
}

/* Choices Grid */
.td-choices-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
    gap: 8px;
}

.td-choice-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    text-align: center;
    gap: 8px;
    background: #1e293b;
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    color: #f1f5f9;
    padding: 10px 14px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.15s ease-in-out;
    line-height: 1.3;
    outline: none;
}

.td-choice-btn:hover:not(:disabled) {
    background: #334155;
    border-color: #818cf8;
    transform: translateY(-2px);
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.25);
}

.td-choice-btn:active:not(:disabled) {
    transform: translateY(0);
}

.td-choice-btn.is-correct {
    background: #065f46 !important;
    border-color: #10b981 !important;
    color: #ecfdf5 !important;
    box-shadow: 0 0 16px rgba(16, 185, 129, 0.6);
}

.td-choice-btn.is-wrong {
    background: #991b1b !important;
    border-color: #ef4444 !important;
    color: #fee2e2 !important;
    animation: tdShake 0.4s ease;
}

@keyframes tdShake {
    0%, 100% { transform: translateX(0); }
    20%, 60% { transform: translateX(-6px); }
    40%, 80% { transform: translateX(6px); }
}

/* Battle Arena Map */
.td-arena-wrap {
    position: relative;
    width: 100%;
    height: 380px;
    background-color: #14532d;
    background-image:
        radial-gradient(#15803d 12%, transparent 14%),
        radial-gradient(#166534 12%, transparent 14%);
    background-size: 32px 32px;
    background-position: 0 0, 16px 16px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    overflow: hidden;
}

.td-canvas {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Strategic Building Slots */
.td-slot {
    position: absolute;
    width: 56px;
    height: 56px;
    margin-left: -28px;
    margin-top: -28px;
    border-radius: 50%;
    background: radial-gradient(circle, rgba(30, 41, 59, 0.95) 0%, rgba(15, 23, 42, 0.95) 100%);
    border: 2.5px dashed rgba(251, 191, 36, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    z-index: 5;
    transition: all 0.2s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5), inset 0 2px 4px rgba(255, 255, 255, 0.1);
}

.td-slot:hover {
    transform: scale(1.18);
    background: rgba(15, 23, 42, 0.95);
    border-color: #f59e0b;
    border-style: solid;
    box-shadow: 0 0 20px rgba(245, 158, 11, 0.8), inset 0 0 8px rgba(245, 158, 11, 0.4);
}

.td-slot.has-tower {
    border-style: solid;
    border-width: 3px;
    border-color: rgba(255, 255, 255, 0.6);
    background: radial-gradient(circle, #334155 0%, #0f172a 100%);
}

.td-slot.has-tower.is-archer {
    border-color: #38bdf8;
    box-shadow: 0 0 18px rgba(56, 189, 248, 0.6), inset 0 2px 6px rgba(56, 189, 248, 0.3);
}

.td-slot.has-tower.is-cannon {
    border-color: #f97316;
    box-shadow: 0 0 18px rgba(249, 115, 22, 0.6), inset 0 2px 6px rgba(249, 115, 22, 0.3);
}

.td-slot.has-tower.is-frost {
    border-color: #67e8f9;
    box-shadow: 0 0 18px rgba(103, 232, 249, 0.7), inset 0 2px 6px rgba(103, 232, 249, 0.4);
}

.td-slot.has-tower.is-tesla {
    border-color: #facc15;
    box-shadow: 0 0 18px rgba(250, 204, 21, 0.7), inset 0 2px 6px rgba(250, 204, 21, 0.4);
}

@keyframes tdRecoil {
    0% { transform: scale(1); }
    35% { transform: scale(1.25); }
    100% { transform: scale(1); }
}

.td-slot.is-firing {
    animation: tdRecoil 0.22s ease-out;
}

.td-slot-icon {
    font-size: 2rem;
    pointer-events: none;
    filter: drop-shadow(0 2px 4px rgba(0, 0, 0, 0.7));
    transition: transform 0.15s;
}

.td-slot:hover .td-slot-icon {
    transform: scale(1.1);
}

.td-tower-badge {
    position: absolute;
    bottom: -6px;
    right: -4px;
    background: #4f46e5;
    background: linear-gradient(135deg, #6366f1 0%, #4338ca 100%);
    color: #fff;
    font-size: 0.68rem;
    font-weight: 800;
    border-radius: 9999px;
    padding: 1.5px 6px;
    border: 1.5px solid #fff;
    pointer-events: none;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.5);
}

.td-stat-pill.td-creeps {
    background: rgba(168, 85, 247, 0.15);
    border-color: rgba(168, 85, 247, 0.4);
    color: #c084fc;
}

/* Boss Warning Banner */
.td-boss-banner {
    position: absolute;
    top: 16px;
    left: 50%;
    transform: translateX(-50%);
    background: linear-gradient(90deg, rgba(220, 38, 38, 0.95), rgba(234, 88, 12, 0.95), rgba(220, 38, 38, 0.95));
    border: 2px solid #fef08a;
    color: #ffffff;
    font-size: 1.15rem;
    font-weight: 900;
    padding: 8px 24px;
    border-radius: 9999px;
    z-index: 30;
    box-shadow: 0 0 25px rgba(239, 68, 68, 0.8), 0 4px 10px rgba(0, 0, 0, 0.5);
    animation: tdBossWarning 0.8s infinite alternate;
    pointer-events: none;
    white-space: nowrap;
}

@keyframes tdBossWarning {
    from { transform: translateX(-50%) scale(0.96); box-shadow: 0 0 15px rgba(239, 68, 68, 0.6); }
    to { transform: translateX(-50%) scale(1.04); box-shadow: 0 0 30px rgba(245, 158, 11, 0.9); }
}

/* How to Play Button & Controls Footer */
.td-controls-footer {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 10px 16px;
    background: rgba(15, 23, 42, 0.95);
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.td-btn-group {
    display: inline-flex;
    align-items: center;
    gap: 8px;
}

.td-launch-btn {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: #10b981;
    background: linear-gradient(135deg, #10b981 0%, #059669 100%);
    border: none;
    color: #fff;
    font-weight: 800;
    font-size: 1rem;
    padding: 8px 22px;
    border-radius: 10px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(16, 185, 129, 0.35);
    transition: all 0.15s ease;
}

.td-launch-btn:hover:not(:disabled) {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(16, 185, 129, 0.5);
}

.td-launch-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
    background: #475569;
}

.td-speed-btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: #1e293b;
    border: 1.5px solid rgba(255, 255, 255, 0.2);
    color: #f1f5f9;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 8px 12px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
}

.td-speed-btn:hover {
    border-color: #818cf8;
    background: #334155;
}

.td-speed-btn.is-active {
    background: #4f46e5;
    border-color: #a5b4fc;
    color: #fff;
    box-shadow: 0 0 12px rgba(79, 70, 229, 0.5);
}

.td-how-btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    background: rgba(255, 255, 255, 0.08);
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: #cbd5e1;
    font-weight: 700;
    font-size: 0.85rem;
    padding: 8px 14px;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.15s;
}

.td-how-btn:hover {
    background: rgba(255, 255, 255, 0.16);
    color: #fff;
    border-color: #38bdf8;
    transform: translateY(-1px);
}

.td-shop-hint {
    font-size: 0.8rem;
    font-weight: 600;
    color: #94a3b8;
}

/* Tower Build & Upgrade Modal / Radial Popover */
.td-modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.88);
    backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
}

.td-modal-card {
    background: #1e293b;
    border: 1.5px solid rgba(255, 255, 255, 0.25);
    border-radius: 18px;
    width: 100%;
    max-width: 460px;
    padding: 20px;
    box-shadow: 0 20px 45px rgba(0, 0, 0, 0.7);
    animation: tdPopIn 0.2s cubic-bezier(0.16, 1, 0.3, 1);
}

@keyframes tdPopIn {
    from { transform: scale(0.9); opacity: 0; }
    to { transform: scale(1); opacity: 1; }
}

.td-modal-title {
    font-size: 1.15rem;
    font-weight: 800;
    color: #fff;
    margin: 0 0 12px;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.td-modal-close-btn {
    background: none;
    border: none;
    color: #94a3b8;
    font-size: 1.3rem;
    cursor: pointer;
    padding: 0 4px;
    line-height: 1;
}

.td-modal-close-btn:hover {
    color: #fff;
}

/* Shop Tower Options */
.td-tower-options-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 10px;
}

.td-tower-option-card {
    background: #0f172a;
    border: 1.5px solid rgba(255, 255, 255, 0.12);
    border-radius: 12px;
    padding: 10px;
    cursor: pointer;
    transition: all 0.15s;
    text-align: center;
}

.td-tower-option-card:hover:not(.is-disabled) {
    border-color: #38bdf8;
    background: #1e293b;
    transform: translateY(-2px);
}

.td-tower-option-card.is-disabled {
    opacity: 0.45;
    cursor: not-allowed;
    border-color: rgba(255, 255, 255, 0.05);
}

.td-tower-option-icon {
    font-size: 2rem;
    display: block;
    margin-bottom: 4px;
}

.td-tower-option-name {
    font-size: 0.85rem;
    font-weight: 800;
    color: #f8fafc;
    margin-bottom: 2px;
}

.td-tower-option-cost {
    font-size: 0.75rem;
    font-weight: 700;
    color: #fbbf24;
}

/* Floating Combat Notifications */
.td-float-notice {
    position: absolute;
    pointer-events: none;
    font-weight: 800;
    font-size: 1.1rem;
    z-index: 40;
    animation: tdFloatUp 1.2s forwards;
    text-shadow: 0 2px 4px rgba(0, 0, 0, 0.7);
}

@keyframes tdFloatUp {
    0% { transform: translateY(0); opacity: 1; }
    100% { transform: translateY(-40px); opacity: 0; }
}

/* Banner Overlay (Victory / Defeat) */
.td-banner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(15, 23, 42, 0.88);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    text-align: center;
    z-index: 60;
    padding: 20px;
}

.td-banner-icon {
    font-size: 4rem;
    margin-bottom: 8px;
    animation: tdBob 1.5s ease-in-out infinite alternate;
}

@keyframes tdBob {
    from { transform: translateY(-6px); }
    to { transform: translateY(6px); }
}

.td-banner-title {
    font-size: 1.8rem;
    font-weight: 800;
    color: #fff;
    margin: 0 0 8px;
}

.td-banner-msg {
    font-size: 1rem;
    color: #cbd5e1;
    max-width: 440px;
    margin: 0 0 16px;
    line-height: 1.5;
}

.td-banner-btn {
    background: #4f46e5;
    border: none;
    color: #fff;
    font-weight: 800;
    font-size: 1.05rem;
    padding: 10px 28px;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.5);
    transition: transform 0.15s;
}

.td-banner-btn:hover {
    transform: scale(1.05);
}

/* How To Play Modal */
.td-help-modal {
    width: 95%;
    max-width: 680px;
    max-height: 88vh;
    overflow-y: auto;
    padding: 22px 24px;
    border-radius: 20px;
    box-shadow: 0 25px 50px rgba(0, 0, 0, 0.8), 0 0 25px rgba(99, 102, 241, 0.25);
    border: 1.5px solid rgba(255, 255, 255, 0.25);
}

.td-help-steps {
    display: flex;
    flex-direction: column;
    gap: 12px;
    margin: 16px 0;
}

.td-help-step-card {
    background: #0f172a;
    border: 1px solid rgba(255, 255, 255, 0.12);
    border-radius: 14px;
    padding: 14px 16px;
    display: flex;
    align-items: flex-start;
    gap: 14px;
    transition: transform 0.15s ease;
}

.td-help-step-card:hover {
    transform: translateY(-2px);
    border-color: rgba(99, 102, 241, 0.4);
}

.td-step-icon {
    font-size: 1.8rem;
    line-height: 1;
    background: rgba(255, 255, 255, 0.06);
    padding: 10px;
    border-radius: 12px;
    flex-shrink: 0;
}

.td-step-title {
    font-weight: 800;
    font-size: 1rem;
    color: #f8fafc;
    margin-bottom: 4px;
}

.td-step-desc {
    font-size: 0.88rem;
    color: #cbd5e1;
    line-height: 1.5;
    margin: 0;
}

.td-help-towers-title {
    font-size: 0.9rem;
    font-weight: 800;
    color: #e2e8f0;
    margin: 16px 0 8px;
    display: flex;
    align-items: center;
    gap: 6px;
}

.td-help-towers-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 8px;
    margin-bottom: 14px;
}

.td-help-tower-pill {
    background: rgba(15, 23, 42, 0.8);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 10px;
    padding: 8px 10px;
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.8rem;
    font-weight: 700;
}

.td-help-tower-pill.is-archer { border-color: rgba(56, 189, 248, 0.4); color: #38bdf8; }
.td-help-tower-pill.is-cannon { border-color: rgba(249, 115, 22, 0.4); color: #f97316; }
.td-help-tower-pill.is-frost { border-color: rgba(103, 232, 249, 0.4); color: #67e8f9; }
.td-help-tower-pill.is-tesla { border-color: rgba(250, 204, 21, 0.4); color: #facc15; }

.td-help-tips-box {
    background: rgba(245, 158, 11, 0.1);
    border: 1px dashed rgba(245, 158, 11, 0.4);
    border-radius: 10px;
    padding: 10px 14px;
    font-size: 0.8rem;
    color: #fde68a;
    line-height: 1.4;
    margin-bottom: 16px;
}

.td-help-action-btn {
    width: 100%;
    background: #4f46e5;
    background: linear-gradient(135deg, #6366f1 0%, #4f46e5 100%);
    border: none;
    color: #fff;
    font-weight: 800;
    font-size: 1rem;
    padding: 12px;
    border-radius: 12px;
    cursor: pointer;
    box-shadow: 0 4px 14px rgba(79, 70, 229, 0.4);
    transition: transform 0.15s;
}

.td-help-action-btn:hover {
    transform: translateY(-2px);
}

/* Mobile responsive adjustments */
@media (max-width: 640px) {
    .td-arena-wrap {
        height: 290px;
    }
    .td-slot {
        width: 44px;
        height: 44px;
        margin-left: -22px;
        margin-top: -22px;
    }
    .td-slot-icon {
        font-size: 1.5rem;
    }
    .td-choices-grid {
        grid-template-columns: 1fr;
    }
    .td-help-towers-grid {
        grid-template-columns: 1fr;
    }
}
