/* Base styles */
:root {
    --terminal-bg: #282a36;
    --terminal-text: #f8f8f2;
    --terminal-green: #50fa7b;
    --terminal-yellow: #f1fa8c;
    --terminal-blue: #bd93f9;
    --terminal-red: #ff5555;
    --terminal-header: #1a1b26;
    --sidebar-bg: #21222c;
    --sidebar-header: #6272a4;
    --tab-bar-bg: #0a0c16;
    --tab-active-bg: #1e1f2e;
    --tab-inactive-bg: #121320;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'IBM Plex Mono', monospace;
    background-color: #161821;
    color: var(--terminal-text);
    line-height: 1.6;
    height: 100vh;
    overflow: hidden;
    display: flex;
    justify-content: center;
    align-items: center;
}

/* Container layout */
.container {
    display: flex;
    width: 95%;
    max-width: 1200px;
    height: 90vh;
    border-radius: 6px;
    overflow: visible; /* Allow terminal to be visible even if it overflows */
    position: relative;
    will-change: transform; /* Optimize for animation performance */
    margin: 0 auto; /* Center the container */
}

/* Terminal styling */
.terminal-window {
    flex: 3;
    display: flex;
    flex-direction: column;
    background-color: var(--terminal-bg);
    border-radius: 6px 0 0 6px;
    overflow: hidden;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.6);
    position: absolute;
    z-index: 10;
    top: 5%;
    left: 5%;
    width: 65%;
    height: 80%;
    resize: both;
    min-width: 320px;
    min-height: 300px;
    max-height: 90vh;
    transform: translate3d(0, 0, 0); /* Force GPU acceleration for smoother dragging */
}

/* Browser UI components */
.browser-ui {
    display: flex;
    flex-direction: column;
    background-color: var(--tab-bar-bg);
}

.tab-bar {
    display: flex;
    align-items: center;
    background-color: var(--tab-bar-bg);
    padding: 5px 10px 0;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    height: 36px;
    position: relative;
}

.browser-tabs {
    display: flex;
    flex: 1;
    align-items: center;
    padding-left: 10px;
    overflow-x: hidden;
}

.browser-tab {
    padding: 6px 12px;
    background-color: var(--tab-inactive-bg);
    margin-right: 3px;
    border-radius: 4px 4px 0 0;
    font-size: 12px;
    white-space: nowrap;
    max-width: 120px;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
    cursor: pointer;
    height: 29px;
    display: flex;
    align-items: center;
}

.browser-tab.active {
    background-color: var(--tab-active-bg);
    color: white;
    font-weight: bold;
    position: relative;
    z-index: 5;
}

.browser-tab-next, .browser-tab-add {
    padding: 0 10px;
    font-size: 18px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    opacity: 0.7;
    position: relative;
}

.browser-tab-add {
    position: relative;
}

.browser-tab-next:hover, .browser-tab-add:hover {
    opacity: 1;
}

.browser-controls {
    display: flex;
    align-items: center;
    padding-right: 5px;
}

.nav-buttons {
    display: flex;
    align-items: center;
    margin-right: 10px;
}

.nav-button {
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 20px;
    cursor: pointer;
    opacity: 0.7;
    margin-right: 5px;
    border-radius: 50%;
    background: rgba(255, 255, 255, 0.1);
}

.address-bar {
    display: flex;
    align-items: center;
    padding: 5px 10px;
    background-color: var(--tab-bar-bg);
    border-top: 1px solid rgba(255, 255, 255, 0.05);
    border-bottom: 1px solid rgba(0, 0, 0, 0.3);
}

.address-field {
    flex: 1;
    background-color: rgba(0, 0, 0, 0.3);
    padding: 5px 10px;
    border-radius: 4px;
    font-size: 12px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    position: relative;
}

.bookmark-button {
    margin-left: 10px;
    font-size: 16px;
    color: gold;
    opacity: 0.7;
    cursor: pointer;
}

/* Fullscreen button styling */
.fullscreen-button {
    font-size: 18px;
    color: white;
    padding: 5px 8px;
    cursor: pointer;
    border-radius: 4px;
    background-color: rgba(255, 255, 255, 0.1);
    transition: background-color 0.2s;
    margin-left: 10px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    position: relative;
}

/* Remove mobile fullscreen 7 indicator as it's now on the browser tab add button */

/* Remove duplicate number 7 from desktop fullscreen button */

.fullscreen-button:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

/* Styling for fullscreen state */
.terminal-window:-webkit-full-screen {
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
}

.terminal-window:-moz-full-screen {
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
}

.terminal-window:-ms-fullscreen {
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
}

.terminal-window:fullscreen {
    width: 100% !important;
    height: 100% !important;
    margin: 0 !important;
    padding: 0 !important;
    border-radius: 0 !important;
}

.terminal-header {
    background-color: var(--terminal-header);
    padding: 10px 15px;
    display: flex;
    align-items: center;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.2);
    cursor: move; /* Show move cursor */
    position: relative;
}

.terminal-buttons {
    display: flex;
    margin-right: 15px;
}

.terminal-button {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    margin-right: 8px;
}

.red { background-color: var(--terminal-red); }
.yellow { background-color: var(--terminal-yellow); }
.green { background-color: var(--terminal-green); }

.terminal-title {
    flex-grow: 1;
    text-align: center;
    font-size: 14px;
    opacity: 0.8;
    position: relative;
    padding: 2px 6px;
    border-radius: 4px;
    background: rgba(0, 0, 0, 0.2);
}

.terminal-body {
    flex: 1;
    padding: 15px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
}

/* Output area */
#output {
    flex: 1;
    overflow-y: auto;
    padding-bottom: 10px;
    white-space: pre-wrap;
}

.welcome-message pre {
    color: var(--terminal-green);
    margin-bottom: 15px;
    font-size: 0.7rem;
    line-height: 1.2;
}

.mobile-banner {
    display: none;
    color: var(--terminal-green);
    margin-bottom: 15px;
    font-size: 0.8rem;
    line-height: 1.1;
    position: relative;
}

.cli-ascii {
    color: var(--terminal-green);
    position: relative;
    display: block;
    border: 1px solid rgba(80, 250, 123, 0.3);
    padding: 5px;
    border-radius: 3px;
}

.cli-version {
    color: var(--terminal-red);
    display: inline-block;
    position: relative;
    background-color: rgba(0, 0, 0, 0.4);
    font-style: italic;
    padding: 1px 5px;
    margin-left: 5px;
    border-radius: 3px;
}

.cli-version {
    color: var(--terminal-red);
    display: inline-block;
    position: relative;
    background-color: rgba(0, 0, 0, 0.4);
    font-style: italic;
    padding: 1px 5px;
    margin-left: 5px;
    border-radius: 3px;
}

.welcome-message p {
    margin-bottom: 10px;
}

.welcome-message code {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 2px 4px;
    border-radius: 3px;
    color: var(--terminal-yellow);
}

/* Input line */
.input-line {
    display: flex;
    align-items: center;
    padding-top: 5px;
    border-top: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    bottom: 0;
    background-color: var(--terminal-bg);
}

.prompt {
    color: var(--terminal-green);
    margin-right: 8px;
    font-weight: bold;
}

#commandInput {
    flex: 1;
    background: transparent;
    border: none;
    outline: none;
    color: var(--terminal-text);
    font-family: 'IBM Plex Mono', monospace;
    font-size: 16px; /* Larger default size to prevent iOS zoom */
    -webkit-appearance: none; /* Remove default iOS styling */
    border-radius: 0; /* Remove rounded corners on iOS */
    height: 1.6em; /* Fixed height to prevent layout shifts */
}

/* Make terminal text selectable/copy-pastable */
body {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

.terminal-body {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

.command-output {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

#output {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

.sidebar-section {
    user-select: text;
    -webkit-user-select: text;
    -moz-user-select: text;
    -ms-user-select: text;
}

/* Command output styling */
.command-output {
    padding: 5px 0;
    position: relative;
}

.directory {
    color: var(--terminal-blue);
    font-weight: bold;
}

.file {
    color: var(--terminal-text);
}

.error {
    color: var(--terminal-red);
    font-weight: bold;
}

.success {
    color: var(--terminal-green);
}

/* Sidebar styling */
.sidebar {
    position: absolute;
    right: 0;
    top: 0;
    width: 25%;
    height: 100%;
    background-color: var(--sidebar-bg);
    padding: 20px;
    border-left: 1px solid rgba(255, 255, 255, 0.1);
    overflow-y: auto;
    box-shadow: -5px 0 15px rgba(0, 0, 0, 0.3);
}

.sidebar-section {
    margin-bottom: 30px;
}

.sidebar-section h3 {
    color: var(--sidebar-header);
    margin-bottom: 15px;
    padding-bottom: 5px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    position: sticky;
    top: 0;
    background-color: var(--sidebar-bg);
    padding-top: 10px;
    z-index: 5;
}

.command-list, .tips-list {
    list-style: none;
}

.command-list li, .tips-list li {
    margin-bottom: 8px;
}

.command-list code {
    background-color: rgba(0, 0, 0, 0.3);
    padding: 2px 4px;
    border-radius: 3px;
    color: var(--terminal-yellow);
    font-weight: bold;
}

.sidebar-section {
    max-height: 300px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--terminal-header) transparent;
}

.sidebar-section::-webkit-scrollbar {
    width: 6px;
}

.sidebar-section::-webkit-scrollbar-track {
    background: transparent;
}

.sidebar-section::-webkit-scrollbar-thumb {
    background-color: var(--terminal-header);
    border-radius: 3px;
}

.tips-list li {
    position: relative;
    padding-left: 15px;
}

.tips-list li:before {
    content: '>';
    position: absolute;
    left: 0;
    color: var(--terminal-green);
    font-weight: bold;
}

/* Challenge section */
#current-challenge {
    background-color: rgba(0, 0, 0, 0.2);
    padding: 12px;
    border-radius: 4px;
    border-left: 3px solid var(--terminal-green);
    margin-bottom: 15px;
    position: relative;
    font-size: 1.05rem;
}

.hint {
    margin-top: 12px;
}

.hint-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 6px;
    background-color: rgba(0, 0, 0, 0.15);
    padding: 8px 12px;
    border-radius: 4px;
    border-left: 3px solid var(--terminal-blue);
}

.hint-toggle {
    color: var(--terminal-green);
    font-weight: bold;
    position: relative;
}

.hint-text {
    display: block; /* Always visible by default */
    padding: 10px 12px;
    background-color: rgba(0, 0, 0, 0.2);
    border-radius: 4px;
    border-left: 3px solid var(--terminal-green);
    color: var(--terminal-yellow);
    font-style: italic;
    position: relative;
    font-size: 0.95rem;
    line-height: 1.4;
}

/* Accordion styling */
.accordion-toggle {
    cursor: pointer;
    color: var(--terminal-green);
    transition: 0.3s;
    font-size: 1.1rem;
}

.sidebar-section h3.accordion-toggle {
    color: var(--sidebar-header);
    position: relative;
    padding-right: 20px;
}

.sidebar-section h3.accordion-toggle::after {
    content: '▾';
    position: absolute;
    right: 0;
    top: 50%;
    transform: translateY(-50%);
    transition: transform 0.3s;
    color: var(--terminal-green);
}

.sidebar-section h3.accordion-toggle.active::after {
    transform: translateY(-50%) rotate(180deg);
}

.accordion-content {
    max-height: 1000px;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out;
    opacity: 1;
}

.accordion-content.hidden {
    max-height: 0;
    overflow: hidden;
    transition: max-height 0.3s ease-in-out, opacity 0.3s ease-in-out;
    opacity: 0;
    margin: 0;
    padding: 0;
}

/* Terminal separator */
.terminal-separator {
    height: 1px;
    background: linear-gradient(to right, transparent, rgba(255, 255, 255, 0.3), transparent);
    margin: 15px 10px;
    position: relative;
}

.terminal-separator::before {
    content: '';
    position: absolute;
    left: 50%;
    top: -4px;
    width: 8px;
    height: 8px;
    background-color: var(--terminal-header);
    border: 1px solid rgba(255, 255, 255, 0.3);
    border-radius: 50%;
    transform: translateX(-50%);
    box-shadow: 0 0 5px rgba(255, 255, 255, 0.2);
}

/* Cycling alert styling */
.cycling-alert {
    position: relative;
    margin: 10px auto;
    background-color: var(--terminal-green);
    color: #000;
    padding: 8px 12px;
    border-radius: 4px;
    font-weight: bold;
    text-align: center;
    box-shadow: 0 2px 5px rgba(0,0,0,0.3);
    width: auto;
    max-width: 80%;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background-color 0.5s;
    font-size: 0.9rem;
    letter-spacing: 0.5px;
    display: inline-block;
}

/* Dragging state */
.terminal-window.dragging {
    opacity: 0.8;
    box-shadow: 0 15px 40px rgba(0, 0, 0, 0.8);
}

/* Resize handle */
.terminal-window::after {
    content: '';
    position: absolute;
    right: 0;
    bottom: 0;
    width: 15px;
    height: 15px;
    background: linear-gradient(135deg, transparent 50%, var(--terminal-blue) 50%);
    cursor: nwse-resize;
    opacity: 0.7;
}

/* Responsive adjustments */
@media (max-width: 768px) {
    body {
        overflow-y: auto;
        height: auto;
        min-height: 100vh;
        overflow-x: hidden; /* Prevent horizontal scrolling */
        position: relative;
        /* Fix for iOS input zoom issues */
        -webkit-text-size-adjust: 100%;
        -ms-text-size-adjust: 100%;
    }
    
    /* Desktop fullscreen button is shown on mobile */
    .fullscreen-button {
        display: flex !important;
        font-size: 22px !important; /* Larger tap target */
        padding: 8px 10px !important;
    }
    
    .browser-ui {
        display: none; /* Hide browser UI on mobile */
    }
    
    .container {
        flex-direction: column;
        height: auto;
        min-height: 100vh;
        width: 100%;
        max-width: none;
        position: static;
        padding-bottom: 30px;
        display: flex;
        flex-direction: column-reverse; /* Show sidebar first on mobile */
    }
    
    .terminal-window {
        width: 90%;
        height: auto; /* Let content determine height */
        max-height: 60vh; /* Cap maximum height */
        position: relative; /* Initial position is relative */
        top: 0;
        left: 0;
        margin: 0 auto 20px auto;
        border-radius: 6px;
        min-width: 280px;
        min-height: 300px;
        z-index: 50; /* High z-index to stay above other elements */
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.8); /* Stronger shadow for visibility */
    }
    
    /* Add the fullscreen button back to the terminal header on mobile */
    .terminal-header {
        justify-content: space-between;
    }
    
    .terminal-header .fullscreen-button {
        display: flex !important;
    }
    
    /* Styles for terminal when it's being dragged */
    .terminal-window.dragging {
        opacity: 0.9;
        box-shadow: 0 15px 40px rgba(0, 0, 0, 0.9);
        transition: none; /* Disable transitions during drag */
    }
    
    /* When positioned absolutely (during/after drag) */
    .terminal-window[style*="position: absolute"] {
        min-width: 280px;
        min-height: 200px;
        max-width: 95vw;
        max-height: 80vh;
    }
    
    .sidebar {
        width: 90%;
        height: auto;
        position: relative;
        padding: 15px;
        margin: 20px auto 0 auto;
        border-radius: 6px;
        z-index: 1; /* Lower z-index than terminal */
        order: -1; /* Ensures sidebar is shown first */
    }
    
    /* Ensure terminal body scrolls properly on mobile */
    .terminal-body {
        max-height: calc(100% - 40px); /* Subtract header height */
        overflow-y: auto;
        height: auto;
        min-height: 250px; /* Ensure enough space to see commands */
        display: flex;
        flex-direction: column;
    }
    
    /* Make sure the output area takes available space */
    #output {
        flex: 1;
        min-height: 200px;
    }
    
    /* Make sure text input works well on mobile */
    #commandInput {
        font-size: 16px; /* Prevent zoom on iOS */
    }
    
    /* Prevent zoom-in on input focus */
    input[type="text"] {
        font-size: 16px; /* iOS requires at least 16px to prevent zoom */
        max-height: 100%;
    }
}

/* Narrow viewport optimizations - disable dragging and fix position */
@media (max-width: 960px) {
    .desktop-banner {
        display: none;
    }
    
    .mobile-banner {
        display: block;
    }
    
    .terminal-body {
        padding: 10px;
    }
    
    #output {
        padding-bottom: 5px;
    }
    
    .welcome-message p {
        font-size: 0.9rem;
    }
    
    /* Fixed positioning for narrow viewport - prevent dragging issues */
    .terminal-window {
        position: relative !important; /* Force relative positioning */
        top: auto !important;
        left: auto !important;
        margin: 0 auto 20px auto !important;
        transform: none !important;
        width: 90% !important;
        height: auto !important; /* Allow content to determine height */
        min-height: 300px; /* Ensure minimum height */
        max-height: 60vh !important; /* Cap maximum height */
    }
    
    /* Remove draggable appearance */
    .terminal-header {
        cursor: default !important;
    }
    
    /* Ensure sidebar is fully visible */
    .sidebar {
        display: block !important;
        position: relative !important;
        right: auto !important;
        top: auto !important;
        order: -1 !important;
        margin-bottom: 20px !important;
    }
}

/* Ensure minimum height for smaller screens */
@media (max-height: 600px) {
    .terminal-window {
        height: 70%;
        min-height: 300px;
    }
    
    .welcome-message p {
        margin-bottom: 5px;
        font-size: 0.85rem;
    }
    
    .sidebar-section {
        margin-bottom: 15px;
    }
}

/* Ultra-compact mode for very small screens */
@media (max-width: 400px), (max-height: 500px) {
    .terminal-window {
        min-width: 280px;
        min-height: 300px; /* Increased to ensure content is visible */
        width: 95%;
        max-height: 60vh !important; /* Allow more space for terminal */
    }
    
    .mobile-banner {
        font-size: 0.7rem;
        line-height: 1;
        margin-bottom: 8px;
    }
    
    .welcome-message p {
        font-size: 0.9rem; /* Slightly larger text for better readability */
        margin-bottom: 6px;
        line-height: 1.3;
    }
    
    /* Ensure hint section is always visible */
    .sidebar-section:first-child {
        display: block !important;
        margin-bottom: 15px;
        padding-bottom: 10px;
        border-bottom: 1px solid rgba(255,255,255,0.1);
    }
    
    /* Make challenge text stand out */
    #current-challenge {
        font-weight: bold;
        font-size: 0.9rem;
        margin-bottom: 10px;
        padding: 8px;
    }
    
    .terminal-body {
        padding: 8px;
    }
    
    .prompt {
        margin-right: 5px;
    }
    
    #commandInput {
        font-size: 16px; /* Keep at 16px to prevent zoom on iOS */
    }
    
    .command-output {
        padding: 3px 0;
        font-size: 0.8rem;
    }
    
    .sidebar {
        padding: 10px;
        width: 95% !important;
        margin: 0 auto 20px auto !important;
    }
    
    .sidebar-section h3 {
        font-size: 1rem;
        margin-bottom: 8px;
    }
    
    .command-list li, .tips-list li {
        font-size: 0.8rem;
        margin-bottom: 4px;
    }
    
    /* Ensure hint text is visible */
    .hint-text {
        display: block !important;
        font-size: 0.8rem;
        padding: 5px;
        background-color: rgba(0, 0, 0, 0.3);
        border-left: 2px solid var(--terminal-green);
        margin-top: 3px;
    }
    
    /* Add spacing between sections */
    .container {
        padding-top: 10px;
    }
}