* {
    box-sizing: border-box;
}

body {
    margin: 0;
    padding: 20px;
    background-color: #0d0d12;
    background-image: 
        linear-gradient(rgba(0, 255, 128, 0.03) 1px, transparent 1px),
        linear-gradient(90deg, rgba(0, 255, 128, 0.03) 1px, transparent 1px);
    background-size: 30px 30px;
    color: #fff;
    font-family: 'Exo 2', 'Rajdhani', sans-serif;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    overflow: hidden;
    user-select: none;
}

/* We wrap game-container with drop-shadow so the clip-path doesn't kill the glow */
#game-container {
    display: flex;
    gap: 20px;
    background: #111118;
    padding: 20px;
    clip-path: polygon(25px 0, 100% 0, 100% calc(100% - 25px), calc(100% - 25px) 100%, 0 100%, 0 25px);
    filter: drop-shadow(0 0 10px rgba(0, 255, 128, 0.1));
}

canvas {
    background-color: #050508;
    clip-path: polygon(15px 0, 100% 0, 100% calc(100% - 15px), calc(100% - 15px) 100%, 0 100%, 0 15px);
    cursor: crosshair;
}

#ui-panel {
    width: 270px;
    display: flex;
    flex-direction: column;
    height: 600px;
    overflow-y: auto;
}

h1 {
    font-family: 'Orbitron', 'Exo 2', sans-serif;
    margin: 0 0 10px 0;
    font-size: 28px;
    letter-spacing: 2px;
    text-shadow: 0 0 10px rgba(255, 0, 85, 0.5);
    border-bottom: 2px solid #ff0055;
    padding-bottom: 5px;
    clip-path: polygon(0 0, 100% 0, 100% 100%, 20px 100%, 0 calc(100% - 20px));
}

#resources {
    display: flex;
    justify-content: space-between;
    background: #0a0a0f;
    padding: 8px;
    margin-bottom: 10px;
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
    border-left: 2px solid #0ff;
}

.res {
    font-weight: bold;
    font-size: 18px;
    text-shadow: 0 0 5px currentColor;
    display: flex;
    align-items: center;
    gap: 6px;
}

.res-icon {
    width: 20px;
    height: 20px;
    display: inline-block;
    mask: var(--icon) center/contain no-repeat;
    -webkit-mask: var(--icon) center/contain no-repeat;
}

.res-icon-small {
    width: 12px;
    height: 12px;
    display: inline-block;
    mask: var(--icon) center/contain no-repeat;
    -webkit-mask: var(--icon) center/contain no-repeat;
    vertical-align: middle;
    margin-left: 2px;
    margin-top: -2px;
}

#ui-panel h3 {
    margin: 15px 0 5px 0;
    color: #0ff;
    font-family: 'Orbitron', 'Exo 2', sans-serif;
    font-size: 16px;
    letter-spacing: 1px;
    text-transform: uppercase;
}

h3 {
    margin-bottom: 5px;
    color: #0ff;
    text-transform: uppercase;
    font-size: 13px;
    letter-spacing: 1px;
}

#inventory {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 10px;
    flex-grow: 1;
}

.inv-slot {
    background: #1a1a24;
    height: 70px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    transition: all 0.2s;
    position: relative;
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}

.inv-slot::before { 
    content: ''; 
    position: absolute; 
    inset: 1px; 
    background: #111118; 
    z-index: -1; 
    clip-path: polygon(9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%, 0 9px); 
}

.inv-slot:hover {
    background: #666;
}
.inv-slot:hover::before {
    background: #2a2a3a;
}

.inv-slot.selected {
    background: #0ff;
}
.inv-slot.selected::before {
    background: #222230;
}

@keyframes titanPulse {
    0% { box-shadow: 0 0 5px rgba(255, 215, 0, 0.2); border-color: rgba(255, 215, 0, 0.3); }
    50% { box-shadow: 0 0 15px rgba(255, 215, 0, 0.8); border-color: rgba(255, 215, 0, 1); }
    100% { box-shadow: 0 0 5px rgba(255, 215, 0, 0.2); border-color: rgba(255, 215, 0, 0.3); }
}

.inv-slot.titan-possible {
    animation: titanPulse 2s infinite;
    border: 1px solid rgba(255, 215, 0, 0.5);
    z-index: 5;
}

.inv-slot canvas {
    background: transparent;
    pointer-events: none;
}

.hotkey-label {
    position: absolute;
    top: 2px;
    left: 4px;
    font-size: 14px;
    color: #aaa;
    font-weight: bold;
    font-family: monospace;
    text-shadow: 1px 1px 0 #000;
}

.cost-label {
    position: absolute;
    bottom: 0px;
    right: 0px;
    font-size: 12px;
    color: #fff;
    font-family: monospace;
    background: rgba(0,0,0,0.8);
    padding: 2px 4px;
    clip-path: polygon(8px 0, 100% 0, 100% 100%, 0 100%);
}

#control-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#control-panel button {
    width: 100%;
    padding: 10px;
    background: #ff0055;
    color: #fff;
    border: none;
    font-family: 'Orbitron', 'Exo 2', sans-serif;
    font-weight: bold;
    cursor: pointer;
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
    transition: all 0.2s;
}

button {
    background: #2a2a3a;
    color: #fff;
    border: none;
    padding: 10px;
    font-family: 'Orbitron', 'Exo 2', sans-serif;
    cursor: pointer;
    text-transform: uppercase;
    transition: 0.2s;
    position: relative;
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
}

button::before {
    content: '';
    position: absolute;
    inset: 1px;
    background: #1a1a24;
    z-index: -1;
    clip-path: polygon(9px 0, 100% 0, 100% calc(100% - 9px), calc(100% - 9px) 100%, 0 100%, 0 9px);
    transition: 0.2s;
}

button:hover {
    background: #0ff;
}

button:hover::before {
    background: #334;
}

#btn-start {
    background: #2a6a3a;
    color: #0f0;
    text-shadow: 0 0 5px #0f0;
}
#btn-start::before {
    background: #112211;
}

#btn-start:hover {
    background: #0f0;
    color: #111;
    text-shadow: none;
}
#btn-start:hover::before {
    background: #228822; /* doesn't show because font colors */
}

#info-text {
    margin-top: 10px;
    color: #aaa;
    font-size: 13px;
    line-height: 1.3;
    min-height: 140px;
    height: auto;
    flex-shrink: 0;
    overflow-y: auto;
    background: #0a0a0f;
    padding: 12px;
    clip-path: polygon(0 0, 100% 0, 100% calc(100% - 15px), calc(100% - 15px) 100%, 0 100%);
    border-right: 2px solid #ff0055;
    scrollbar-width: thin;
    scrollbar-color: #333 #0a0a0f;
}

.draft-card {
    background: #111118;
    border: 2px solid #555;
    border-radius: 8px;
    padding: 15px;
    width: 220px;
    text-align: center;
    cursor: pointer;
    transition: transform 0.2s, border-color 0.2s, box-shadow 0.2s;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.draft-card:hover {
    transform: scale(1.1);
    border-color: #00fa9a;
    box-shadow: 0 0 20px rgba(0, 250, 154, 0.4);
    z-index: 10;
}
.draft-card h3 {
    color: #fff;
    margin: 0 0 10px 0;
    font-family: Orbitron;
    font-size: 16px;
    border-bottom: none;
    clip-path: none;
    padding-bottom: 0;
}
.draft-card .desc {
    color: #aaa;
    font-size: 12px;
    margin-bottom: 10px;
    height: 40px;
}
.draft-card .stats {
    color: #0ff;
    font-size: 11px;
    margin-bottom: 10px;
}
.draft-card .comps {
    font-size: 10px;
    color: #888;
    text-align: left;
    width: 100%;
}
.draft-card .comps div { margin-bottom: 2px; }

/* Modals Refactored */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: rgba(0, 0, 0, 0.85);
    z-index: 500;
    justify-content: center;
    align-items: center;
    backdrop-filter: blur(3px);
}

.modal-frame {
    background: #11111a;
    padding: 30px;
    position: relative;
    clip-path: polygon(25px 0, 100% 0, 100% calc(100% - 25px), calc(100% - 25px) 100%, 0 100%, 0 25px);
    border: 1px solid rgba(0, 255, 128, 0.2);
    animation: modalScaleIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.modal-frame.red { border-color: #ff0055; filter: drop-shadow(0 0 15px rgba(255, 0, 85, 0.2)); }
.modal-frame.green { border-color: #00fa9a; filter: drop-shadow(0 0 15px rgba(0, 250, 154, 0.2)); }
.modal-frame.yellow { border-color: #ffcc00; filter: drop-shadow(0 0 15px rgba(255, 204, 0, 0.2)); }

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

.modal-title {
    font-family: 'Orbitron', 'Exo 2', sans-serif;
    font-size: 20px;
    font-weight: bold;
    margin-bottom: 20px;
    color: #fff;
    text-align: center;
    letter-spacing: 1px;
}

/* Removed Specific Inner Modals - Consolidated */

.swap-card {
    background: #111118;
    border: 2px solid #333;
    border-radius: 8px;
    padding: 10px 8px;
    text-align: center;
    cursor: pointer;
    transition: all 0.25s cubic-bezier(0.4, 0, 0.2, 1);
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    position: relative;
    overflow: hidden;
}

.swap-card::after {
    content: '';
    position: absolute;
    inset: 0;
    background: radial-gradient(circle at 50% 50%, rgba(0, 250, 154, 0.05), transparent);
    opacity: 0;
    transition: opacity 0.3s;
}

.swap-card:hover {
    transform: translateY(-4px) scale(1.05);
    border-color: #ff0055;
    box-shadow: 0 8px 25px rgba(255, 0, 85, 0.3);
}

.swap-card:hover::after {
    opacity: 1;
}

.swap-card canvas {
    background: transparent;
    pointer-events: none;
}

.swap-card .swap-card-name {
    font-size: 10px;
    color: #fff;
    font-family: Orbitron;
    font-weight: bold;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 100%;
}

.swap-card .swap-card-slot {
    position: absolute;
    top: 3px;
    left: 5px;
    font-size: 11px;
    color: #666;
    font-weight: bold;
    font-family: monospace;
}

.swap-new-preview {
    background: #111118;
    border: 2px solid #00fa9a;
    border-radius: 10px;
    padding: 12px 20px;
    display: flex;
    align-items: center;
    gap: 14px;
    box-shadow: 0 0 20px rgba(0, 250, 154, 0.15);
    animation: newTowerGlow 2s infinite;
}

@keyframes newTowerGlow {
    0%, 100% { box-shadow: 0 0 15px rgba(0, 250, 154, 0.15); }
    50% { box-shadow: 0 0 25px rgba(0, 250, 154, 0.4); }
}

.swap-new-preview .swap-new-name {
    font-family: Orbitron;
    color: #00fa9a;
    font-size: 14px;
    font-weight: bold;
}

.swap-new-preview canvas {
    background: transparent !important;
    pointer-events: none;
}

#btn-page-prev:hover, #btn-page-next:hover {
    color: #0ff !important;
    text-shadow: 0 0 5px #0ff;
}

/* Achievements Modal Refactored to Modal-Frame */

.achievement-item {
    display: flex;
    align-items: center;
    gap: 12px;
    background: #1a1a24;
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 6px;
    opacity: 0.5;
    filter: grayscale(1);
    transition: 0.3s;
}

.achievement-item.unlocked {
    opacity: 1;
    filter: none;
    border-left: 3px solid #ffcc00;
}

.achievement-icon {
    font-size: 24px;
    width: 32px;
    text-align: center;
}

.achievement-info {
    flex-grow: 1;
}

.achievement-title {
    font-weight: bold;
    color: #fff;
    font-size: 14px;
}

.achievement-desc {
    font-size: 11px;
    color: #888;
}

/* Toast Notification */
#achievement-toast-container {
    position: fixed;
    top: 20px;
    right: 20px;
    z-index: 1000;
    pointer-events: none;
}

.achievement-toast {
    background: #111118;
    border: 2px solid #ffcc00;
    border-radius: 8px;
    padding: 12px 18px;
    margin-bottom: 10px;
    display: flex;
    align-items: center;
    gap: 15px;
    box-shadow: 0 5px 25px rgba(0,0,0,0.5);
    animation: toastSlideIn 0.5s cubic-bezier(0.18, 0.89, 0.32, 1.28) forwards;
    pointer-events: auto;
}

@keyframes toastSlideIn {
    from { transform: translateX(120%); opacity: 0; }
    to { transform: translateX(0); opacity: 1; }
}

.achievement-toast.fadeOut {
    animation: toastFadeOut 0.5s ease-in forwards;
}

@keyframes toastFadeOut {
    to { transform: translateX(120%); opacity: 0; }
}

/* Custom scrollbar for achievement list */
#achievements-list::-webkit-scrollbar {
    width: 6px;
}
#achievements-list::-webkit-scrollbar-track {
    background: #0a0a0f;
}
#achievements-list::-webkit-scrollbar-thumb {
    background: #333;
    border-radius: 3px;
}
#achievements-list::-webkit-scrollbar-thumb:hover {
    background: #444;
}

/* Tower Component Table */
.comp-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 5px;
}
.comp-row {
    border-bottom: 1px solid #222;
    transition: background 0.2s;
}
.comp-row:hover {
    background: rgba(0, 255, 255, 0.05);
}
.comp-icon-cell {
    width: 24px;
    padding: 6px 0;
    vertical-align: top;
}
.comp-icon-img {
    width: 20px;
    height: 20px;
    object-fit: contain;
    filter: brightness(0) invert(1) drop-shadow(0 0 2px rgba(255,255,255,0.7));
}
.comp-info-cell {
    padding: 4px 4px 6px 6px;
    vertical-align: top;
}
.comp-header {
    display: flex;
    align-items: center;
    gap: 6px;
    margin-bottom: 2px;
}
.comp-name {
    font-weight: bold;
    color: #0ff;
    text-transform: uppercase;
    font-size: 10px;
    letter-spacing: 0.5px;
}
.comp-count {
    color: #111;
    background: #0ff;
    padding: 0px 5px;
    border-radius: 10px;
    font-size: 9px;
    font-weight: bold;
    font-family: Orbitron;
}
.comp-desc {
    color: #bbb;
    font-size: 10px;
    display: block;
    line-height: 1.2;
}

/* Titan Draft Premium Styles */
.titan-card-premium {
    background: linear-gradient(135deg, #1a1a2e 0%, #0a0a12 100%) !important;
    border-width: 3px !important;
    width: 280px !important;
    min-height: 380px !important;
    justify-content: center !important;
    position: relative;
    overflow: hidden;
    animation: titanCardGlow 3s infinite alternate;
}

.titan-card-premium::before {
    content: '';
    position: absolute;
    top: -50%;
    left: -50%;
    width: 200%;
    height: 200%;
    background: conic-gradient(transparent, rgba(255, 215, 0, 0.1), transparent 30%);
    animation: rotateGlow 10s linear infinite;
    pointer-events: none;
}

@keyframes rotateGlow {
    from { transform: rotate(0deg); }
    to { transform: rotate(360deg); }
}

@keyframes titanCardGlow {
    0% { transform: scale(1); filter: brightness(1); }
    100% { transform: scale(1.02); filter: brightness(1.2); }
}

.titan-card-premium:hover {
    transform: scale(1.08) translateY(-10px) !important;
    box-shadow: 0 0 40px currentColor !important;
    z-index: 100;
}

.titan-card-premium h2 {
    text-shadow: 0 0 10px currentColor;
    margin-top: 0;
}

.titan-bg-icon {
    position: absolute;
    top: 50%;
    left: 50%;
    width: 200px;
    height: 200px;
    transform: translate(-50%, -50%);
    background-size: contain;
    background-position: center;
    background-repeat: no-repeat;
    opacity: 0.15;
    filter: brightness(0) invert(1);
    z-index: 1;
    pointer-events: none;
}

/* Assistant styles */
.assistant-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    z-index: 2000;
    pointer-events: none; /* Let clicks pass through unless on bubble */
}

#cube-assistant-container {
    position: absolute;
    width: 400px;
    height: 400px;
    pointer-events: none;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
}

.assistant-bubble {
    position: absolute;
    width: 400px;
    background: rgba(10, 10, 20, 0.95);
    border: 2px solid #00ffcc;
    border-radius: 15px;
    padding: 20px;
    box-shadow: 0 0 30px rgba(0, 255, 204, 0.2);
    display: flex;
    flex-direction: column;
    gap: 15px;
    pointer-events: auto;
    transition: all 0.5s cubic-bezier(0.4, 0, 0.2, 1);
    z-index: 2001;
}

.assistant-text {
    font-family: 'Rajdhani', sans-serif;
    font-size: 18px;
    line-height: 1.4;
    color: #e0ffff;
    min-height: 50px;
    text-shadow: 0 0 10px rgba(0, 255, 204, 0.3);
}

.assistant-text::after {
    content: '|';
    animation: cursor-blink 0.8s infinite;
    margin-left: 2px;
    color: #00ffcc;
}

@keyframes cursor-blink {
    0%, 100% { opacity: 0; }
    50% { opacity: 1; }
}

.tutorial-highlight-cell {
    position: absolute;
    background: rgba(255, 215, 0, 0.2);
    border: 2px solid #ffd700;
    box-shadow: 0 0 15px rgba(255, 215, 0, 0.5);
    animation: tutorial-pulse 1.5s infinite alternate;
    pointer-events: none;
    z-index: 100;
}

.tutorial-target-highlight {
    animation: titanPulse 1.5s infinite alternate !important;
    border: 2px solid #ffd700 !important;
    box-shadow: 0 0 15px #ffd700, inset 0 0 10px #ffd700 !important;
}

@keyframes tutorial-pulse {
    from { opacity: 0.4; transform: scale(0.98); }
    to { opacity: 0.9; transform: scale(1.02); }
}

.tutorial-arrow {
    position: absolute;
    width: 0;
    height: 0;
    border-left: 20px solid transparent;
    border-right: 20px solid transparent;
    border-top: 30px solid #00ffcc;
    filter: drop-shadow(0 0 10px #00ffcc);
    animation: arrow-bounce 0.6s infinite alternate;
    z-index: 2200;
    pointer-events: none;
}

@keyframes arrow-bounce {
    from { transform: translateY(0); }
    to { transform: translateY(-20px); }
}

#color-wheel-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(90deg);
    width: 300px;
    height: 300px;
    background: conic-gradient(
        #FF0000, #FF4500, #FFA500, #FFD700, #FFFF00, #ADFF2F, #00FF00, #00FA9A, #0000FF, #8A2BE2, #EE82EE, #C71585, #FF0000
    );
    border-radius: 50%;
    border: 5px solid rgba(0, 255, 204, 0.4);
    box-shadow: 0 0 50px rgba(0, 255, 204, 0.3);
    z-index: 2300;
    display: none;
}

#color-wheel-overlay::before {
    content: '';
    position: absolute;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    border-radius: 50%;
    z-index: 1;
}

#color-wheel-overlay::after {
    content: '';
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 60px;
    height: 60px;
    background: #0a0a0f;
    border-radius: 50%;
    border: 2px solid #00ffcc;
    z-index: 2;
}

.assistant-next-btn {
    align-self: flex-end;
    background: #00ffcc;
    color: #fff !important; /* Force white text */
    border: none;
    padding: 8px 24px;
    font-family: 'Orbitron', sans-serif;
    font-weight: bold;
    font-size: 14px;
    cursor: pointer;
    clip-path: polygon(10px 0, 100% 0, 100% calc(100% - 10px), calc(100% - 10px) 100%, 0 100%, 0 10px);
    transition: all 0.2s;
    box-shadow: 0 0 15px rgba(0, 255, 204, 0.4);
}

.synergy-line-good, .synergy-line-bad {
    position: absolute;
    top: 50%;
    left: 50%;
    height: 4px;
    border-radius: 2px;
    transform-origin: left center;
    z-index: 5;
    pointer-events: none;
}

.synergy-line-good {
    background: #0f0;
    box-shadow: 0 0 10px #0f0;
    width: 60px; /* Red to Orange distance center-to-center is root(2 - 2cos(60)) = 1 unit = ~130px? No. */
}

/* Red center (15deg): 150 + 130*cos(15), 150 + 130*sin(15) */
/* Orange center (75deg): 150 + 130*cos(75), 150 + 130*sin(75) */
/* Dist = 130 * sqrt(2 - 2*cos(60)) = 130. Correct. */

.synergy-line-good {
    width: 130px;
    transform: rotate(15deg) translate(0, 0) rotate(30deg);
    /* This calculation is complex for pure CSS, I'll use simple absolute positions or SVG */
}

#color-wheel-overlay svg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    z-index: 5;
}

.assistant-next-btn:hover {
    background: #fff;
    transform: scale(1.05);
    box-shadow: 0 0 25px rgba(0, 255, 204, 0.6);
}
