/* Reset & Basic Setup */
body {
    margin: 0;
    overflow: hidden; /* Prevent scrollbars */
    background-color: #1e1e1e; /* Dark theme background */
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    color: #eee;
    touch-action: none; /* Prevent browser gestures */
    user-select: none;
    -webkit-user-select: none;
}

/* Canvas Fullscreen */
canvas {
    display: block;
    width: 100vw;
    height: 100vh;
    touch-action: none;
}

/* Utility Classes */
.hidden {
    display: none !important;
}

/* UI Container - Overlay on top of canvas */
#ui-container {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none; /* Let clicks pass through to canvas */
    display: flex;
    flex-direction: column;
    justify-content: space-between;
}

/* Top Controls Bar */
#top-controls {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.6);
    padding: 10px;
    display: flex;
    align-items: center;
    gap: 15px;
    backdrop-filter: blur(5px);
}

#mode-toggle {
    background: #2196F3;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    font-weight: bold;
}

#toggle-axes-btn {
    background: #607D8B;
    color: white;
    border: none;
    padding: 5px 10px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 16px;
}

#toggle-axes-btn.active {
    background: #FFC107;
    color: black;
}

#mode-indicator {
    font-weight: bold;
    color: #4CAF50; /* Green for Wiring, will change via JS */
}

#coords-display {
    font-family: monospace;
    color: #ffcc00;
    margin-left: 20px;
}

#clear-btn.danger-btn {
    background: #ff4444;
    color: white;
    border: none;
    padding: 8px 16px;
    border-radius: 4px;
    cursor: pointer;
    margin-left: auto; /* Push to right */
}

/* Icon Button (Generic) */
.icon-btn {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #607D8B;
    color: white;
    border: none;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    transition: transform 0.2s, background 0.2s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.icon-btn:hover {
    transform: scale(1.1);
    background: #78909C;
}

/* Help Content Popup (Floating above bottom bar) */
#help-content {
    position: absolute;
    bottom: 90px; /* Above bottom controls */
    left: 20px; /* Default position */
    width: 250px;
    background: rgba(0, 0, 0, 0.85);
    padding: 15px;
    border-radius: 8px;
    backdrop-filter: blur(10px);
    border: 1px solid #444;
    transition: opacity 0.3s, transform 0.3s;
    transform-origin: bottom left;
    z-index: 200;
    pointer-events: auto;
}

#help-content.hidden {
    opacity: 0;
    transform: scale(0.8);
    pointer-events: none;
}

#info {
    margin-bottom: 15px;
    font-size: 14px;
    line-height: 1.4;
    color: #ddd;
}

.help-actions {
    display: flex;
    gap: 10px;
}

.help-actions button {
    flex: 1;
    padding: 8px;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 12px;
}

#show-answer-btn {
    background: #FF9800; /* Orange */
    color: white;
}

#check-circuit-btn {
    background: #4CAF50; /* Green */
    color: white;
}

/* Bottom Controls (Compact Palette) */
#bottom-controls {
    pointer-events: auto;
    background: rgba(0, 0, 0, 0.7);
    padding: 10px 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 20px;
    backdrop-filter: blur(5px);
    border-top: 1px solid #333;
}

.component-group, .camera-group, .control-group {
    display: flex;
    gap: 10px;
}

.component-btn {
    width: 50px;
    height: 50px;
    border: none;
    border-radius: 8px;
    background: #333;
    color: white;
    font-size: 24px;
    cursor: pointer;
    transition: background 0.2s, transform 0.1s;
    display: flex;
    justify-content: center;
    align-items: center;
}

.component-btn:hover {
    background: #444;
    transform: translateY(-2px);
}

.component-btn:active {
    transform: translateY(0);
}

/* Camera buttons slightly smaller/different style */
#cam-reset, #cam-top {
    width: 40px;
    height: 40px;
    border-radius: 50%;
    background: #555;
    border: none;
    font-size: 18px;
    cursor: pointer;
    color: white;
}

/* Popup */
.popup {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
}

.popup.hidden {
    display: none;
}

.popup-content {
    background: #333;
    padding: 30px;
    border-radius: 10px;
    text-align: center;
    max-width: 400px;
    box-shadow: 0 10px 20px rgba(0,0,0,0.5);
    color: white;
}

.popup-actions {
    display: flex;
    gap: 20px;
    justify-content: center;
    margin-top: 20px;
}

.popup-actions button {
    padding: 10px 20px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    font-size: 16px;
}

#btn-next-level {
    background: #4CAF50;
    color: white;
}

#btn-stay-level {
    background: #607D8B;
    color: white;
}

/* Phone Overlay */
#phone-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    display: flex;
    justify-content: center;
    align-items: center;
    flex-direction: column;
    z-index: 1000;
}

#phone-overlay.hidden {
    display: none;
}

.phone-case {
    width: 300px;
    height: 600px;
    background: #111;
    border-radius: 40px;
    padding: 15px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    position: relative;
    border: 5px solid #333;
}

.phone-screen {
    width: 100%;
    height: 100%;
    background: #fff;
    border-radius: 30px;
    overflow: hidden;
    position: relative;
    display: flex;
    flex-direction: column;
}

.status-bar {
    height: 24px;
    background: #000;
    color: #fff;
    display: flex;
    justify-content: space-between;
    padding: 0 10px;
    font-size: 12px;
    align-items: center;
}

.phone-page {
    flex: 1;
    display: flex;
    flex-direction: column;
    padding: 10px;
    background: #f5f5f5;
    overflow-y: auto;
}

.phone-page.hidden {
    display: none;
}

.app-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    padding-top: 20px;
}

#phone-home {
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%); /* Default Wallpaper */
    padding-top: 40px; /* Space for widgets */
}

.home-widgets {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    margin-bottom: 20px;
    color: white;
}

.weather-widget {
    display: flex;
    align-items: center;
    gap: 10px;
}

.weather-icon {
    font-size: 32px;
}

.weather-info {
    display: flex;
    flex-direction: column;
}

.weather-temp {
    font-size: 20px;
    font-weight: bold;
}

.weather-desc {
    font-size: 12px;
    opacity: 0.8;
}

.clock-widget {
    text-align: right;
}

.clock-time {
    font-size: 32px;
    font-weight: bold;
}

.clock-date {
    font-size: 12px;
    opacity: 0.8;
}

.app-grid {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    padding: 10px;
}

.app-icon {
    display: flex;
    flex-direction: column;
    align-items: center;
    cursor: pointer;
    transition: transform 0.2s;
}

.app-icon:hover {
    transform: scale(1.1);
}

.app-icon .icon {
    width: 50px;
    height: 50px;
    border-radius: 12px;
    background: #ccc;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 24px;
    margin-bottom: 5px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.store-icon { background: #2196F3 !important; color: white; }
.browser-icon { background: #4CAF50 !important; color: white; }
.deepseek-icon { background: #1a237e !important; color: white; }
.game-icon { background: #ff9800 !important; color: white; }

.app-icon span {
    font-size: 11px;
    color: white; /* Changed to white for better visibility on wallpaper */
    text-shadow: 0 1px 2px rgba(0,0,0,0.5);
    text-align: center;
    margin-top: 5px;
}

/* Android Mode (Default) Adjustments */
.phone-case:not(.iphone-mode) .phone-page {
    padding-bottom: 60px; /* Space for Android Nav Bar */
    box-sizing: border-box; /* Ensure padding is included in height */
}

/* Slide Up Animation for Lock Screen */
.slide-up {
    transform: translateY(-100%);
    transition: transform 0.5s ease-in-out;
}

#phone-lock {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 20;
    background: linear-gradient(rgba(0,0,0,0.3), rgba(0,0,0,0.3)), url('https://images.unsplash.com/photo-1550684848-fac1c5b4e853?ixlib=rb-1.2.1&auto=format&fit=crop&w=1350&q=80') no-repeat center center/cover;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    color: white;
    text-shadow: 0 2px 4px rgba(0,0,0,0.5);
}

#phone-lock.hidden {
    display: none;
}

.app-header {
    height: 50px;
    background: #2196F3;
    color: white;
    display: flex;
    align-items: center;
    padding: 0 10px;
    font-size: 18px;
    margin: -10px -10px 10px -10px;
}

.back-btn {
    background: none;
    border: none;
    color: white;
    font-size: 20px;
    margin-right: 10px;
    cursor: pointer;
}

.store-search {
    display: flex;
    gap: 5px;
    margin-bottom: 15px;
}

.store-search input {
    flex: 1;
    padding: 8px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
}

.app-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.app-item {
    display: flex;
    align-items: center;
    background: white;
    padding: 10px;
    border-radius: 8px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
}

.app-item .icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    margin-right: 10px;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
}

.app-info {
    flex: 1;
}

.app-name { font-weight: bold; font-size: 14px; color: #333; }
.app-desc { font-size: 12px; color: #666; }

.install-btn {
    background: #4CAF50;
    color: white;
    border: none;
    padding: 5px 15px;
    border-radius: 15px;
    cursor: pointer;
    font-size: 12px;
}

.install-btn:disabled {
    background: #ccc;
    cursor: not-allowed;
}

/* Phone Home Button */
#phone-home-btn {
    position: absolute;
    bottom: 15px; /* Adjusted to be higher */
    left: 50%;
    transform: translateX(-50%);
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background-color: rgba(255, 255, 255, 0.2);
    border: 2px solid rgba(255, 255, 255, 0.5);
    cursor: pointer;
    transition: transform 0.1s, background-color 0.2s;
    display: none; /* Hidden by default */
    z-index: 30; /* Ensure above screen */
}

/* iPhone Mode Adjustments */
.phone-case.iphone-mode {
    padding-bottom: 80px; /* Increase bottom padding to create chin */
    height: 535px; /* Reduce content height to maintain total size (600+30 = 535+15+80) */
}

.phone-case.iphone-mode .phone-screen {
    border-bottom-left-radius: 0;
    border-bottom-right-radius: 0;
    height: 100%; /* Fill the available content area */
}

.phone-case.iphone-mode #phone-home-btn {
    display: block;
    bottom: 15px; /* Position in the chin area */
}


#phone-home-btn:active {
    transform: translateX(-50%) scale(0.95);
    background-color: rgba(255, 255, 255, 0.4);
}

/* Android Navigation Bar */
#android-nav-bar {
    width: 100%;
    height: 60px;
    background-color: #000;
    display: flex;
    justify-content: space-around;
    align-items: center;
    position: absolute;
    bottom: 0;
    left: 0;
    border-bottom-left-radius: 30px; /* Match phone case */
    border-bottom-right-radius: 30px;
    padding-bottom: 10px; /* Adjust for case curve */
    box-sizing: border-box;
}

#android-nav-bar button {
    background: transparent;
    border: none;
    color: rgba(255, 255, 255, 0.7);
    font-size: 24px;
    width: 60px;
    height: 100%;
    cursor: pointer;
    transition: color 0.2s;
}

#android-nav-bar button:active {
    color: #fff;
    background-color: rgba(255, 255, 255, 0.1);
}

.close-overlay-btn {
    margin-top: 20px;
    padding: 10px 20px;
    background: #f44336;
    color: white;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 16px;
}

.close-overlay-btn:hover {
    background: #d32f2f;
}
/* Phone Lock Screen */
#phone-lock {
    display: flex;
    flex-direction: column;
    align-items: center;
    color: white;
    padding-top: 60px;
    background: linear-gradient(135deg, #1e3c72 0%, #2a5298 100%);
}

.lock-clock {
    font-size: 64px;
    font-weight: 300;
}

.lock-date {
    font-size: 18px;
    margin-bottom: 40px;
}

.lock-hint {
    margin-top: auto;
    margin-bottom: 30px;
    font-size: 14px;
    opacity: 0.7;
    animation: bounce 2s infinite;
}

@keyframes bounce {
    0%, 20%, 50%, 80%, 100% {transform: translateY(0);}
    40% {transform: translateY(-10px);}
    60% {transform: translateY(-5px);}
}

/* DeepSeek Chat App */
.chat-container {
    display: flex;
    flex-direction: column;
    height: 100%;
    background: #f5f5f5;
}

.chat-messages {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.message {
    display: flex;
    gap: 10px;
    max-width: 80%;
}

.bot-message {
    align-self: flex-start;
}

.user-message {
    align-self: flex-end;
    flex-direction: row-reverse;
}

.msg-avatar {
    width: 36px;
    height: 36px;
    background: #e0e0e0;
    border-radius: 50%;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: 20px;
}

.msg-content {
    background: white;
    padding: 10px 15px;
    border-radius: 18px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.1);
    color: #333;
    font-size: 14px;
    line-height: 1.4;
}

.user-message .msg-content {
    background: #1a237e;
    color: white;
}

.chat-input-area {
    padding: 10px;
    background: white;
    border-top: 1px solid #eee;
}

.quick-replies {
    display: flex;
    gap: 8px;
    overflow-x: auto;
    padding-bottom: 10px;
    margin-bottom: 5px;
}

.reply-chip {
    white-space: nowrap;
    background: #e8eaf6;
    color: #1a237e;
    border: 1px solid #c5cae9;
    border-radius: 16px;
    padding: 6px 12px;
    font-size: 12px;
    cursor: pointer;
}

.reply-chip:hover {
    background: #c5cae9;
}

.input-box {
    display: flex;
    gap: 10px;
}

.input-box input {
    flex: 1;
    padding: 8px 12px;
    border: 1px solid #ddd;
    border-radius: 20px;
    outline: none;
}

.send-btn {
    background: #1a237e;
    color: white;
    border: none;
    border-radius: 20px;
    padding: 0 20px;
    cursor: pointer;
}

/* Toast Notification */
#toast-container {
    position: absolute;
    top: 80px;
    left: 50%;
    transform: translateX(-50%);
    display: flex;
    flex-direction: column;
    gap: 10px;
    z-index: 2000;
    pointer-events: none;
}

.toast {
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 10px 20px;
    border-radius: 4px;
    font-size: 14px;
    box-shadow: 0 4px 6px rgba(0,0,0,0.3);
    animation: fadeIn 0.3s ease-out, fadeOut 0.3s ease-in 2.7s forwards;
    pointer-events: auto;
    display: flex;
    align-items: center;
    gap: 10px;
}

.toast.error {
    border-left: 4px solid #f44336;
}

.toast.success {
    border-left: 4px solid #4CAF50;
}

.toast.info {
    border-left: 4px solid #2196F3;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(-20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes fadeOut {
    from { opacity: 1; }
    to { opacity: 0; }
}

/* Step Hints Sidebar */
#step-hints {
    position: absolute;
    top: 50%;
    right: 20px;
    transform: translateY(-50%);
    background: rgba(0, 0, 0, 0.8);
    padding: 20px;
    border-radius: 10px;
    color: white;
    max-width: 300px;
    z-index: 2000;
    box-shadow: 0 4px 15px rgba(0,0,0,0.5);
    border: 1px solid #444;
}

#step-hints h3 {
    margin-top: 0;
    border-bottom: 1px solid #555;
    padding-bottom: 10px;
    margin-bottom: 15px;
    color: #4CAF50;
    text-align: center;
}

#hint-list {
    list-style: none;
    padding: 0;
    margin: 0;
}

#hint-list li {
    padding: 10px;
    margin-bottom: 8px;
    border-radius: 5px;
    background: rgba(255, 255, 255, 0.05);
    transition: all 0.3s;
    font-size: 14px;
    line-height: 1.4;
    opacity: 0.5;
}

#hint-list li.active {
    background: rgba(76, 175, 80, 0.3);
    border-left: 4px solid #4CAF50;
    opacity: 1;
    font-weight: bold;
    transform: translateX(-5px);
}

#hint-list li.completed {
    text-decoration: line-through;
    opacity: 0.3;
}

.start-game-btn {
    width: 100%;
    margin-top: 15px;
    padding: 10px;
    background: #4CAF50;
    color: white;
    border: none;
    border-radius: 5px;
    font-size: 16px;
    font-weight: bold;
    cursor: pointer;
    transition: background 0.3s;
    text-transform: uppercase;
    letter-spacing: 1px;
}

.start-game-btn:hover {
    background: #45a049;
    box-shadow: 0 2px 5px rgba(0,0,0,0.2);
}

.start-game-btn:active {
    transform: translateY(1px);
}

/* Home Hint on Phone Wallpaper */
.home-hint {
    background: rgba(255, 255, 255, 0.15);
    backdrop-filter: blur(5px);
    margin: 10px;
    padding: 15px;
    border-radius: 12px;
    text-align: center;
    color: white;
    border: 1px solid rgba(255,255,255,0.2);
}

.hint-title {
    font-size: 16px;
    font-weight: bold;
    margin-bottom: 5px;
    color: #FFC107;
}

.hint-desc {
    font-size: 12px;
    line-height: 1.4;
    opacity: 0.9;
}

#phone-guide-hint {
    position: absolute;
    top: -50px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(33, 150, 243, 0.9);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 16px;
    font-weight: bold;
    white-space: nowrap;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    z-index: 100;
    border: 2px solid white;
    animation: bounce 2s infinite;
}

/* Responsive Adjustments */
@media (max-width: 768px) {
    #top-controls {
        flex-wrap: wrap;
    }
    
    .desktop-hint {
        display: none;
    }
}

@media (max-width: 600px) {
    #top-controls {
        font-size: 12px;
        padding: 8px;
    }
    
    #mode-toggle, #clear-btn {
        padding: 6px 10px;
    }

    #bottom-controls {
        padding: 8px;
        gap: 10px;
        overflow-x: auto; /* Allow scroll if too many items */
        justify-content: flex-start; /* Align left if scrolling */
    }

    .component-btn {
        width: 44px;
        height: 44px;
        font-size: 20px;
    }
}

#phone-bottom-hint {
    background: rgba(33, 150, 243, 0.9);
    color: white;
    padding: 10px 20px;
    border-radius: 20px;
    font-size: 16px;
    font-weight: bold;
    white-space: nowrap;
    box-shadow: 0 4px 8px rgba(0,0,0,0.3);
    z-index: 100;
    border: 2px solid white;
    animation: bounce 2s infinite;
    margin-top: 20px;
    margin-bottom: 10px;
}
