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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    background: #1a1a1a;
    min-height: 100vh;
    color: #e0e0e0;
    margin: 0;
    padding: 0;
    overflow: hidden;
}

.container {
    width: 100vw;
    height: 100vh;
    margin: 0;
    padding: 0;
    display: flex;
    flex-direction: column;
}

header {
    text-align: center;
    color: #e0e0e0;
    margin: 0;
    padding: 8px;
    background: #252525;
    border-bottom: 1px solid #333;
    flex-shrink: 0;
    position: relative;
}

.header-buttons {
    position: absolute;
    top: 8px;
    right: 8px;
    display: flex;
    gap: 8px;
    align-items: center;
}

.header-btn {
    padding: 8px 12px;
    background: #6b5bff;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 0.9em;
    font-weight: 600;
    transition: background-color 0.2s;
    white-space: nowrap;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    text-decoration: none;
    box-sizing: border-box;
    line-height: 1;
    font-family: inherit;
    flex: 0 0 auto;
    width: auto;
    min-width: auto;
    max-width: none;
}

a.header-btn {
    text-decoration: none !important;
    color: white !important;
    border: none;
    outline: none;
}

a.header-btn:focus {
    outline: none;
}

a.header-btn:hover {
    color: white !important;
    text-decoration: none !important;
}

/* Override modal-body link styles for header buttons */
.modal-body a.header-btn {
    color: white !important;
    text-decoration: none !important;
}

.modal-body a.header-btn:hover {
    color: white !important;
    text-decoration: none !important;
}

.header-btn:hover:not(:disabled) {
    background: #00d4aa; /* Contrasting teal highlight */
}

/* Larger icons for Stats and Gallery buttons */
#statsBtn i,
#galleryBtn i {
    font-size: 1.3em;
}

/* Language Selector Styles */
.language-selector {
    position: relative;
    display: inline-block;
}

.language-btn {
    /* Inherits padding and sizing from .header-btn */
}

.language-dropdown {
    position: absolute;
    top: 100%;
    right: 0;
    margin-top: 4px;
    background: #2a2a2a;
    border: 1px solid #444;
    border-radius: 4px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    z-index: 1000;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    gap: 2px;
    padding: 4px;
}

.language-option {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 8px;
    cursor: pointer;
    transition: background-color 0.2s;
    border-radius: 3px;
}

.language-option:hover {
    background: #333;
}

.language-option img {
    flex-shrink: 0;
}

header h1 {
    font-size: 1.5em;
    margin: 0;
    padding: 4px 0;
    text-shadow: none;
}

header p {
    font-size: 0.85em;
    opacity: 0.8;
    margin: 0;
    padding: 0;
}

.main-content {
    display: grid;
    grid-template-columns: 300px 1fr;
    gap: 0;
    height: calc(100vh - 60px);
    flex: 1;
    overflow: hidden;
}

.control-panel {
    background: #2a2a2a;
    border-radius: 0;
    padding: 12px;
    box-shadow: 2px 0 8px rgba(0, 0, 0, 0.3);
    overflow-y: auto;
    border-right: 1px solid #333;
}

.section-header {
    margin-bottom: 12px;
    color: #7c8aff;
    font-size: 1em;
    border-bottom: 1px solid #444;
    padding-bottom: 6px;
}

.section-header h2,
.section-header h3 {
    margin: 0;
    color: #7c8aff;
    font-size: 1em;
    display: inline-block;
}

.collapsible-header {
    cursor: pointer;
    user-select: none;
    display: flex;
    justify-content: space-between;
    align-items: center;
    transition: background-color 0.2s;
    padding: 6px 8px;
    margin: 0 -8px 8px -8px;
    border-radius: 4px;
}

.collapsible-header:hover {
    background-color: rgba(124, 138, 255, 0.15);
}

.toggle-icon {
    font-size: 0.8em;
    color: #7c8aff;
    transition: transform 0.2s;
}

.collapsible-content {
    margin-bottom: 12px;
}

.collapsible-section {
    margin-top: 15px;
    margin-bottom: 15px;
}

.form-row {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

.form-row-2col {
    grid-template-columns: repeat(2, 1fr);
}

.form-group {
    margin-bottom: 12px;
}

.form-group.compact {
    margin-bottom: 8px;
}

.form-group label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    color: #b0b0b0;
    font-size: 0.85em;
}

.form-group input,
.form-group select {
    width: 100%;
    padding: 6px 8px;
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 0.9em;
    transition: border-color 0.3s;
    background: #1f1f1f;
    color: #e0e0e0;
}

.form-group input:focus,
.form-group select:focus {
    outline: none;
    border-color: #7c8aff;
    box-shadow: 0 0 0 2px rgba(124, 138, 255, 0.2);
}

.form-group input:hover,
.form-group select:hover {
    border-color: #555;
}

.form-group input[type="range"] {
    width: 100%;
    padding: 0;
    height: 6px;
    cursor: pointer;
}

.form-group input[type="range"] {
    background: #333;
}

.form-group input[type="range"]::-webkit-slider-thumb {
    appearance: none;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #7c8aff;
    cursor: pointer;
}

.form-group input[type="range"]::-moz-range-thumb {
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: #7c8aff;
    cursor: pointer;
    border: none;
}

.form-group input[type="checkbox"] {
    width: auto;
    margin-right: 6px;
    cursor: pointer;
}

.button-group {
    display: flex;
    gap: 8px;
    margin-top: 15px;
}

button {
    flex: 1;
    padding: 8px 12px;
    border: none;
    border-radius: 4px;
    font-size: 0.9em;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

button i {
    font-size: 1.4em;
}

/* Icon-only buttons - make icons larger */
.button-group button i {
    font-size: 1.6em;
}

#generateBtn {
    background: #6b5bff;
    color: white;
}

#generateBtn:hover:not(:disabled) {
    background: #00d4aa; /* Contrasting teal highlight */
}

#exportBtn {
    background: #6b5bff;
    color: white;
}

#exportBtn:hover:not(:disabled) {
    background: #00d4aa; /* Contrasting teal highlight */
}

#zoomResetBtn {
    background: #6b5bff;
    color: white;
}

#zoomResetBtn:hover:not(:disabled) {
    background: #00d4aa; /* Contrasting teal highlight */
}

#saveImageBtn {
    background: #6b5bff;
    color: white;
}

#saveImageBtn:hover:not(:disabled) {
    background: #00d4aa; /* Contrasting teal highlight */
}

button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* On-canvas status message */
.status-canvas-message {
    position: absolute;
    top: 20px;
    left: 20px;
    padding: 12px 16px;
    padding-right: 36px;
    border-radius: 6px;
    font-size: 0.9em;
    min-height: 40px;
    display: flex;
    align-items: center;
    max-width: 400px;
    z-index: 1000;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.5);
    pointer-events: auto;
}

.status-canvas-message.info {
    background: #2a3a4a;
    color: #7c8aff;
    border: 1px solid #444;
}

.status-canvas-message.success {
    background: #2a4a3a;
    color: #7cff8a;
    border: 1px solid #444;
}

.status-canvas-message.error {
    background: #4a2a2a;
    color: #ff7c7c;
    border: 1px solid #444;
}

.status-close {
    position: absolute;
    top: 8px;
    right: 8px;
    background: transparent;
    border: none;
    color: inherit;
    font-size: 20px;
    font-weight: bold;
    cursor: pointer;
    padding: 0;
    width: 24px;
    height: 24px;
    display: flex;
    align-items: center;
    justify-content: center;
    line-height: 1;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.status-close:hover {
    opacity: 1;
}

#statusText {
    flex: 1;
    line-height: 1.4;
}

.visualization-area {
    background: #1a1a1a;
    border-radius: 0;
    box-shadow: none;
    position: relative;
    overflow: hidden;
}

#canvasContainer {
    width: 100%;
    height: 100%;
    position: relative;
}

.controls-hint {
    position: absolute;
    bottom: 15px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.7);
    color: white;
    padding: 8px 15px;
    border-radius: 6px;
    font-size: 0.85em;
    pointer-events: none;
}

.controls-hint p {
    margin: 0;
}

/* Canvas Button (On-Canvas Controls) */
.canvas-button {
    position: absolute;
    bottom: 20px;
    left: 20px;
    width: 48px;
    height: 48px;
    background: #6b5bff;
    color: white;
    border: none;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.4em;
    z-index: 150;
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.4);
    transition: all 0.3s ease;
}

.canvas-button:hover {
    background: #00d4aa; /* Contrasting teal highlight */
    transform: scale(1.1);
}

.canvas-button:active {
    transform: scale(0.95);
}

/* Block tooltip styles */
.block-tooltip {
    position: fixed;
    background: rgba(0, 0, 0, 0.9);
    color: white;
    padding: 10px 12px;
    border-radius: 6px;
    font-size: 0.85em;
    pointer-events: none;
    z-index: 1000;
    max-width: 250px;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.tooltip-header {
    font-weight: 600;
    margin-bottom: 8px;
    padding-bottom: 6px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.2);
    color: #667eea;
}

.tooltip-row {
    margin: 4px 0;
    display: flex;
    justify-content: space-between;
    gap: 10px;
}

.tooltip-label {
    color: #aaa;
    font-weight: 500;
}

.tooltip-value {
    color: white;
    text-align: right;
    font-weight: 400;
}

/* Scrollbar styling for control panel */
.control-panel::-webkit-scrollbar {
    width: 8px;
}

.control-panel::-webkit-scrollbar-track {
    background: #1f1f1f;
    border-radius: 4px;
}

.control-panel::-webkit-scrollbar-thumb {
    background: #444;
    border-radius: 4px;
}

.control-panel::-webkit-scrollbar-thumb:hover {
    background: #555;
}

/* About Modal Styles */
.modal {
    display: none;
    position: fixed;
    z-index: 2000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.7);
    animation: fadeIn 0.2s;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

.modal-content {
    background-color: #2a2a2a;
    margin: 10% auto;
    padding: 0;
    border: 1px solid #444;
    border-radius: 8px;
    width: 90%;
    max-width: 500px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    animation: slideDown 0.3s;
}

@keyframes slideDown {
    from {
        transform: translateY(-50px);
        opacity: 0;
    }
    to {
        transform: translateY(0);
        opacity: 1;
    }
}

.modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    border-bottom: 1px solid #444;
    background-color: #252525;
    border-radius: 8px 8px 0 0;
}

.modal-header h2 {
    margin: 0;
    color: #7c8aff;
    font-size: 1.5em;
}

.modal-close {
    color: #aaa;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
    transition: color 0.2s;
}

.modal-close:hover,
.modal-close:focus {
    color: #fff;
}

.modal-body {
    padding: 20px;
    color: #e0e0e0;
    line-height: 1.6;
}

.modal-body p {
    margin: 10px 0;
}

.modal-body strong {
    color: #7c8aff;
}

.modal-body a {
    color: #7c8aff;
    text-decoration: none;
    transition: color 0.2s;
}

.modal-body a:hover {
    color: #9ba3ff;
    text-decoration: underline;
}

.modal-body button {
    margin-top: 10px;
    padding: 10px 20px;
}

/* Stats Table */
.stats-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9em;
    margin-top: 8px;
}

.stats-table th {
    background-color: rgba(124, 138, 255, 0.2);
    color: #7c8aff;
    padding: 8px 12px;
    text-align: left;
    font-weight: 600;
    border-bottom: 1px solid rgba(255, 255, 255, 0.1);
    font-size: 0.95em;
}

.stats-table td {
    padding: 6px 12px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    color: #e0e0e0;
}

.stats-table tr:last-child td {
    border-bottom: none;
}

.stats-table td:first-child {
    color: #aaa;
    width: 50%;
}

.stats-table td:last-child {
    text-align: right;
    color: #e0e0e0;
}

.stats-table strong {
    color: #7c8aff;
}

/* Hide Memory and Docs buttons on small screens */
@media (max-width: 768px) {
    #memoryBtn,
    #docsBtn {
        display: none;
    }
    
    /* On small screens, move title below buttons */
    header {
        display: flex;
        flex-direction: column;
        align-items: center;
        padding-top: 50px; /* Space for buttons at top */
    }
    
    .header-buttons {
        position: absolute;
        top: 8px;
        right: 8px;
        left: auto;
    }
    
    header h1 {
        margin-top: 8px;
        order: 2;
    }
    
    header p {
        order: 3;
    }
}

/* Memory Panel (Non-modal) */
.memory-panel {
    display: none;
    position: fixed;
    z-index: 1500;
    top: 60px;
    right: 20px;
    width: 350px;
    max-height: 500px;
    pointer-events: auto;
}

.memory-panel-content {
    background-color: #2a2a2a;
    border: 1px solid #444;
    border-radius: 8px;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    overflow: hidden;
    animation: slideInRight 0.3s;
}

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

.memory-panel-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 16px;
    border-bottom: 1px solid #444;
    background-color: #252525;
}

.memory-panel-header h3 {
    margin: 0;
    color: #7c8aff;
    font-size: 1.2em;
}

.memory-panel-close {
    color: #aaa;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    line-height: 20px;
    transition: color 0.2s;
}

.memory-panel-close:hover,
.memory-panel-close:focus {
    color: #fff;
}

.memory-panel-body {
    padding: 16px;
    color: #e0e0e0;
    line-height: 1.6;
    max-height: 400px;
    overflow-y: auto;
}

/* Gallery panel body: flex layout, no overflow (galleryContent handles scrolling) */
#galleryPanel .memory-panel-body {
    display: flex;
    flex-direction: column;
    overflow-y: visible;
    max-height: none;
    height: 400px;
}

/* Gallery content should scroll independently, keeping button visible */
#galleryContent {
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.memory-panel-body p {
    margin: 8px 0;
}

.memory-panel-body strong {
    color: #7c8aff;
}

/* Responsive design */
@media (max-width: 1024px) {
    .main-content {
        grid-template-columns: 1fr;
        grid-template-rows: auto 1fr;
    }
    
    .control-panel {
        max-height: 40vh;
        border-right: none;
        border-bottom: 1px solid #333;
    }
    
    .modal-content {
        width: 95%;
        margin: 20% auto;
    }
}
