@font-face {
    font-family: 'Learninglings';
    src: url('/Learninglings.ttf') format('truetype');
}

body, html {
    margin: 0;
    padding: 0;
    width: 100%;
    height: 100%;
    overflow: hidden;
    background-image: url('download.jpg');
    background-size: cover;
    background-position: center;
    font-family: 'Learninglings', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    touch-action: none;
}

button, input, textarea, select {
    font-family: 'Learninglings', 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
}

#ui-container {
    position: absolute;
    top: 50px; /* Leave space for top bar */
    left: 10px;
    bottom: 10px;
    z-index: 10;
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    pointer-events: none;
    max-width: 420px;
    width: auto;
}

#spawn-controls {
    display: flex;
    flex-direction: column;
    flex: 1;
    min-height: 0; /* Important for flex child scrolling */
    width: 100%;
}

.button-row {
    display: grid;
    grid-template-columns: repeat(auto-fill, 50px);
    gap: 8px;
    pointer-events: auto;
    padding: 8px;
    max-width: 100%;
    overflow-y: auto;
    scrollbar-width: thin;
    background: rgba(255, 255, 255, 0.4);
    border-radius: 15px;
    backdrop-filter: blur(2px);
    box-sizing: border-box;
}

.button-row::-webkit-scrollbar {
    width: 6px;
}

.button-row::-webkit-scrollbar-thumb {
    background: rgba(0,0,0,0.2);
    border-radius: 3px;
}

.spawn-btn {
    width: 50px;
    height: 50px;
    border: 3px solid white;
    border-radius: 12px;
    color: white;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    display: flex;
    justify-content: center;
    align-items: center;
    box-shadow: 0 4px 6px rgba(0,0,0,0.2);
    transition: transform 0.1s;
    user-select: none;
}

.spawn-btn:hover {
    transform: scale(1.1);
    z-index: 15;
}

.spawn-btn:active {
    transform: scale(0.9);
}

.spawn-btn.selected {
    box-shadow: 0 0 15px 5px yellow, 0 4px 6px rgba(0,0,0,0.2);
    border-color: yellow !important;
    transform: scale(1.1);
    z-index: 20;
}

.btn-rainbow {
    background: linear-gradient(180deg, #ff0000, #ff8c00, #ffff00, #00cc00, #0066ff, #4b0082, #ee82ee);
    border: 3px solid white;
}

.btn-light-rainbow {
    background: linear-gradient(180deg, #FFCDD2, #FFF9C4, #B9F6CA, #B3E5FC, #C5CAE9, #F8BBD0);
    border: 3px solid white;
}

.btn-rainbow-pink {
    background: linear-gradient(180deg, #F8BBD0, #FFCDD2, #F48FB1, #F06292);
    border: 3px solid white;
}

.btn-white-blue {
    background: linear-gradient(180deg, #ffffff, #0000ff);
    color: #333;
    border: 3px solid white;
}

.btn-97104 {
    background: linear-gradient(180deg, #607d8b, #9c27b0, #FFCDD2, #00cc00);
    color: #fff;
    text-shadow: 1px 1px 2px rgba(0,0,0,0.8);
    border: 3px solid white;
}



.mode-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 6px;
    pointer-events: auto;
    margin-top: 10px;
    background: rgba(255, 255, 255, 0.4);
    padding: 8px;
    border-radius: 15px;
    backdrop-filter: blur(2px);
    width: calc(100% - 16px);
}

.mode-btn {
    padding: 6px 12px;
    border: 2px solid #555;
    background: white;
    border-radius: 15px;
    font-weight: bold;
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
    flex: 1 1 auto;
    text-align: center;
}

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

.mode-btn.active {
    background: #333;
    color: white;
}

#mode-chat.active {
    background: #ff9800;
    border-color: #ff9800;
}

#mode-say.active {
    background: #e91e63;
    border-color: #e91e63;
}

#mode-merge.active {
    background: #2196f3;
    border-color: #2196f3;
}

#mode-split.active {
    background: #4caf50;
    border-color: #4caf50;
}

#mode-split1s.active {
    background: #cddc39;
    border-color: #afb42b;
    color: #333;
}

#mode-square.active {
    background: #9c27b0;
    border-color: #9c27b0;
}

#mode-cube.active {
    background: #3f51b5;
    border-color: #3f51b5;
}

#mode-factorial.active {
    background: #ff5722;
    border-color: #ff5722;
}

#mode-prime.active {
    background: #00bcd4;
    border-color: #00bcd4;
}

#mode-delete.active {
    background: #f44336;
    border-color: #f44336;
}

#mode-clear {
    color: #f44336;
    border-color: #f44336;
}

#mode-clear:active {
    background: #f44336;
    color: white;
}

#canvas-container {
    width: 100%;
    height: 100%;
    /* Ensure the canvas rests visually on the wood floor drawn by the renderer */
    position: relative;
}
#units-badge {
    pointer-events: none;
}

#loading-overlay {
    z-index: 10000;
    background: white;
    transition: opacity 1s ease-out;
}

#loading-overlay.fade-out {
    opacity: 0;
    pointer-events: none;
}

.loading-content {
    text-align: center;
    max-width: 600px;
}

.rainbow-text-animated {
    font-size: 48px;
    background: linear-gradient(to right, #ff0000, #ff8c00, #ffff00, #00cc00, #0066ff, #4b0082, #ee82ee);
    background-size: 200% auto;
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
    animation: rainbow-shift 3s linear infinite;
    margin-bottom: 10px;
    padding: 0 20px;
}

#loading-spinner-container {
    height: 100px;
    display: flex;
    justify-content: center;
    align-items: center;
    margin: 15px 0;
}

#loading-spinner-block {
    width: 70px;
    height: 70px;
    border: 4px solid #333;
    border-radius: 12px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-weight: bold;
    font-size: 32px;
    animation: loading-spin 3s ease-in-out infinite;
    box-shadow: 0 6px 15px rgba(0,0,0,0.15);
}

@keyframes loading-spin {
    0% { transform: rotate(0deg) scale(1); }
    50% { transform: rotate(180deg) scale(1.15); }
    100% { transform: rotate(360deg) scale(1); }
}

@keyframes rainbow-shift {
    to { background-position: 200% center; }
}

.loader-bar {
    width: 100%;
    height: 12px;
    background: #eee;
    border-radius: 6px;
    overflow: hidden;
    margin: 20px 0;
}

.loader-progress {
    width: 0%;
    height: 100%;
    background: #2196f3;
}

#disclaimer-overlay {
    z-index: 9999;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(5px);
}

.disclaimer-box {
    max-width: 450px;
    border: 5px solid #333;
    padding: 30px;
}

.disclaimer-box h2 {
    margin-top: 0;
    color: #f44336;
    font-size: 28px;
}

.disclaimer-box p {
    font-size: 18px;
    line-height: 1.5;
    color: #333;
    margin: 20px 0;
}

#disclaimer-btn {
    background: #4caf50;
    color: white;
    padding: 15px 30px;
    font-size: 20px;
    border: none;
    border-radius: 12px;
    cursor: pointer;
    font-weight: bold;
    box-shadow: 0 4px 0 #2e7d32;
    transition: transform 0.1s, box-shadow 0.1s;
}

#disclaimer-btn:active {
    transform: translateY(2px);
    box-shadow: 0 2px 0 #2e7d32;
}

#top-bar-actions {
    position: fixed;
    top: 10px;
    right: 10px;
    z-index: 1001;
    display: flex;
    gap: 8px;
    pointer-events: auto;
}

/* Zoom button sizing to match top-bar */
#zoom-in-btn, #zoom-out-btn {
    width: 44px;
    height: 36px;
    padding: 4px 8px;
    font-size: 20px;
    line-height: 1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}

.top-btn {
    padding: 8px 15px;
    background: rgba(255, 255, 255, 0.9);
    border: 2px solid #333;
    border-radius: 20px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
    transition: all 0.2s;
}

.top-btn:hover {
    background: #f0f0f0;
    transform: scale(1.05);
}

#ui-container.gui-hidden #spawn-controls,
#ui-container.gui-hidden .mode-row,
#chat-container.gui-hidden {
    display: none !important;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.6);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    pointer-events: auto;
}

.modal-content {
    background: white;
    padding: 20px;
    border-radius: 15px;
    box-shadow: 0 10px 25px rgba(0,0,0,0.3);
    text-align: center;
    width: 80%;
    max-width: 300px;
}

.modal-content h3 {
    margin-top: 0;
    color: #333;
}

#custom-number-input {
    width: 100%;
    padding: 10px;
    font-size: 18px;
    border: 2px solid #ddd;
    border-radius: 8px;
    margin-bottom: 15px;
    box-sizing: border-box;
    text-align: center;
}

.modal-actions {
    display: flex;
    gap: 10px;
    justify-content: center;
}

.modal-actions button {
    padding: 10px 20px;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
}

#modal-cancel {
    background: #eee;
    color: #555;
}

#modal-spawn {
    background: #2196f3;
    color: white;
}

.modal-hint {
    font-size: 11px;
    color: #888;
    margin-top: 10px;
}

.setting-item {
    text-align: left;
    margin: 15px 0;
    font-size: 16px;
    display: flex;
    flex-direction: column;
    gap: 5px;
}

.setting-item label {
    display: flex;
    align-items: center;
    gap: 10px;
    cursor: pointer;
}

.setting-item input[type="range"] {
    width: 100%;
}

canvas {
    display: block;
}

#fps-counter {
    position: fixed;
    top: 10px;
    left: 10px;
    background: rgba(0, 0, 0, 0.4);
    color: #00ff00;
    padding: 2px 8px;
    border-radius: 8px;
    font-size: 14px;
    z-index: 10001;
    pointer-events: none;
    font-family: monospace;
    backdrop-filter: blur(2px);
    border: 1px solid rgba(255, 255, 255, 0.2);
}

/* AI Chat UI */
#chat-container {
    position: fixed;
    bottom: 20px;
    right: 20px;
    width: 280px;
    background: rgba(255, 255, 255, 0.95);
    border: 3px solid #333;
    border-radius: 15px;
    z-index: 1000;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    box-shadow: 0 5px 20px rgba(0,0,0,0.3);
    transition: transform 0.3s ease-in-out, height 0.3s ease-in-out;
    pointer-events: auto;
}

#chat-container.chat-collapsed {
    height: 45px;
}

#chat-container:not(.chat-collapsed) {
    height: 350px;
}

#chat-header {
    background: #333;
    color: white;
    padding: 10px 15px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    cursor: pointer;
}

#chat-header-actions {
    display: flex;
    gap: 5px;
}

#chat-title {
    font-weight: bold;
    font-size: 14px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    flex: 1;
}

#chat-toggle, #chat-pick-btn {
    background: transparent;
    border: 1px solid white;
    color: white;
    border-radius: 5px;
    cursor: pointer;
    font-size: 12px;
    padding: 2px 6px;
}

#chat-picker-overlay {
    position: absolute;
    top: 45px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255,255,255,0.95);
    z-index: 10;
    display: flex;
    flex-direction: column;
    padding: 10px;
}

#chat-picker-content {
    display: flex;
    flex-direction: column;
    height: 100%;
}

#chat-picker-content h4 {
    margin: 0 0 10px 0;
    font-size: 14px;
}

#chat-picker-list {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
    align-content: flex-start;
}

.picker-item {
    padding: 5px 10px;
    background: #eee;
    border-radius: 5px;
    font-size: 12px;
    cursor: pointer;
    border: 1px solid #ccc;
}

.picker-item:hover {
    background: #ddd;
}

#chat-picker-close {
    margin-top: 10px;
    padding: 5px;
    cursor: pointer;
}

#chat-body {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 10px;
    gap: 10px;
    overflow: hidden;
}

#chat-history {
    flex: 1;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 8px;
    font-size: 14px;
    padding-right: 5px;
}

.chat-msg {
    padding: 6px 10px;
    border-radius: 10px;
    max-width: 85%;
    word-wrap: break-word;
}

.chat-msg.user {
    align-self: flex-end;
    background: #e1f5fe;
    color: #01579b;
}

.chat-msg.ai {
    align-self: flex-start;
    background: #f5f5f5;
    color: #333;
    border: 1px solid #ddd;
}

#chat-input-area {
    display: flex;
    gap: 5px;
}

#chat-input {
    flex: 1;
    padding: 8px;
    border: 2px solid #ddd;
    border-radius: 8px;
}

#chat-send {
    padding: 8px 12px;
    background: #2196f3;
    color: white;
    border: none;
    border-radius: 8px;
    font-weight: bold;
    cursor: pointer;
}

#chat-send:disabled {
    background: #ccc;
}

@media (max-width: 600px) {
    #ui-container {
        max-width: 140px; /* Reduced to fit alongside chat on small screens */
    }
    .button-row {
        grid-template-columns: repeat(2, 50px); /* Fixed 2 columns on mobile */
        justify-content: center;
        max-height: 40vh; /* Prevent it from taking over the whole height */
    }
    .mode-row {
        grid-template-columns: repeat(2, 1fr); /* 2 columns for modes too */
        font-size: 11px;
    }
    .mode-btn {
        padding: 4px 6px;
        font-size: 11px;
    }
    
    /* Smaller Chat GUI for mobile */
    #chat-container {
        width: 160px;
        right: 10px;
        bottom: 10px;
    }
    #chat-container:not(.chat-collapsed) {
        height: 220px;
    }
    #chat-header {
        padding: 6px 10px;
    }
    #chat-title {
        font-size: 11px;
    }
    #chat-body {
        padding: 6px;
        gap: 5px;
    }
    #chat-history {
        font-size: 12px;
    }
    #chat-input {
        font-size: 12px;
        padding: 4px;
    }
    #chat-send {
        padding: 4px 8px;
        font-size: 12px;
    }
    #chat-picker-overlay {
        top: 35px;
    }
}