* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

body {
    font-family: 'Press Start 2P', monospace;
    background: linear-gradient(135deg, #0d0d1a 0%, #1a1a2e 50%, #16213e 100%);
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 20px;
    color: #fff;
    overflow-x: hidden;
}

#console-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 20px;
    width: 100%;
    height: 100%;
    max-width: 100%;
}

#console-body {
    background: linear-gradient(180deg, #3d3d3d 0%, #2a2a2a 50%, #1a1a1a 100%);
    border-radius: 20px;
    padding: 20px;
    box-shadow: 
        0 10px 40px rgba(0, 0, 0, 0.5),
        inset 0 2px 0 rgba(255, 255, 255, 0.1),
        inset 0 -2px 0 rgba(0, 0, 0, 0.3);
    position: relative;
    display: flex;
    flex-direction: column;
    width: 100%;
    max-width: 800px;
    height: calc(100vh - 100px);
    max-height: 900px;
}

#console-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 15px;
    padding: 0 10px;
    gap: 10px;
    flex-shrink: 0;
}

#logo {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

#logo .star {
    color: #ffd700;
    font-size: 16px;
    text-shadow: 0 0 10px #ffd700;
    animation: pulse 2s ease-in-out infinite;
}

#logo .title {
    font-size: 18px;
    background: linear-gradient(180deg, #fff 0%, #ccc 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    text-shadow: none;
    letter-spacing: 2px;
}

@keyframes pulse {
    0%, 100% { opacity: 1; transform: scale(1); }
    50% { opacity: 0.7; transform: scale(1.1); }
}

#game-title {
    font-size: 8px;
    color: #888;
    letter-spacing: 1px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
    max-width: 120px;
}

/* Auth Status */
#auth-status {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 7px;
}

.auth-user {
    color: #8f8;
}

.auth-btn {
    padding: 4px 8px;
    background: linear-gradient(180deg, #4a5a6a 0%, #3a4a5a 100%);
    border: 1px solid #5a6a7a;
    border-radius: 4px;
    color: #adf;
    font-family: 'Press Start 2P', monospace;
    font-size: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.auth-btn:hover {
    background: linear-gradient(180deg, #5a6a7a 0%, #4a5a6a 100%);
}

#screen-bezel {
    background: #111;
    border-radius: 10px;
    padding: 15px;
    box-shadow: 
        inset 0 4px 10px rgba(0, 0, 0, 0.8),
        0 2px 0 rgba(255, 255, 255, 0.05);
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 0;
    overflow: hidden;
}

#screen-container {
    position: relative;
    width: 100%;
    height: 100%;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 8px;
    overflow: hidden;
    box-shadow: 0 0 30px rgba(100, 200, 255, 0.2);
    background: #000;
}

#game-canvas {
    display: block;
    /* Use the full container while maintaining aspect ratio */
    width: 100%;
    height: 100%;
    max-width: 100%;
    max-height: 100%;
    object-fit: contain;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
}

#scanlines {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    pointer-events: none;
    /* Scanlines will be dynamically set by JS to match pixel scale */
    /* Default fallback - will be overridden */
    background: repeating-linear-gradient(
        0deg,
        rgba(0, 0, 0, 0.15) 0px,
        rgba(0, 0, 0, 0.15) 1px,
        transparent 1px,
        transparent 2px
    );
}

#crt-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: radial-gradient(ellipse at center, transparent 0%, rgba(0, 0, 0, 0.3) 100%);
    pointer-events: none;
}

#click-to-start {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    font-size: 10px;
    color: #fff;
    text-shadow: 0 0 10px #fff;
    animation: blink 1s infinite;
    pointer-events: none;
}

#click-to-start.hidden {
    display: none;
}

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

#status-bar {
    display: flex;
    justify-content: space-around;
    padding: 15px 20px;
    margin-top: 10px;
    flex-shrink: 0;
}

.score-display {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
}

.score-display .label {
    font-size: 8px;
    color: #888;
}

.score-display .value {
    font-size: 16px;
    color: #0f0;
    text-shadow: 0 0 10px #0f0;
    font-family: 'Courier New', monospace;
}

/* Touch controls - hidden on desktop by default */
#controls,
#start-select {
    display: none;
}

#controls {
    justify-content: space-between;
    padding: 20px;
    margin-top: 10px;
}

#dpad {
    display: grid;
    grid-template-columns: repeat(3, 40px);
    grid-template-rows: repeat(3, 40px);
    gap: 2px;
}

.dpad-btn {
    background: #1a1a1a;
    border: none;
    border-radius: 5px;
    color: #666;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 
        0 3px 0 #000,
        inset 0 1px 0 rgba(255, 255, 255, 0.1);
    transition: all 0.1s;
}

.dpad-btn:active {
    transform: translateY(2px);
    box-shadow: 0 1px 0 #000;
}

#btn-up { grid-column: 2; grid-row: 1; }
#btn-left { grid-column: 1; grid-row: 2; }
#btn-right { grid-column: 3; grid-row: 2; }
#btn-down { grid-column: 2; grid-row: 3; }

#action-buttons {
    display: flex;
    gap: 15px;
    align-items: center;
    transform: rotate(-20deg);
}

.action-btn {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    background: linear-gradient(180deg, #e63946 0%, #a62633 100%);
    border: none;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 12px;
    cursor: pointer;
    box-shadow: 
        0 5px 0 #7a1d25,
        0 8px 15px rgba(0, 0, 0, 0.4);
    transition: all 0.1s;
}

.action-btn:active {
    transform: translateY(3px);
    box-shadow: 0 2px 0 #7a1d25;
}

#btn-b { margin-top: 20px; }

#start-select {
    justify-content: center;
    gap: 30px;
    padding: 15px;
}

.sys-btn {
    padding: 8px 20px;
    background: #444;
    border: none;
    border-radius: 15px;
    color: #888;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    cursor: pointer;
    box-shadow: 0 2px 0 #222;
    transition: all 0.1s;
}

.sys-btn:active {
    transform: translateY(2px);
    box-shadow: none;
}

/* Fullscreen button */
#fullscreen-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    width: 32px;
    height: 32px;
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid #444;
    border-radius: 5px;
    color: #fff;
    font-size: 14px;
    cursor: pointer;
    z-index: 50;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

#fullscreen-btn:hover {
    background: rgba(0, 0, 0, 0.8);
    border-color: #666;
}

/* Fullscreen mode styles */
body.fullscreen-mode {
    padding: 0;
    background: #000;
}

body.fullscreen-mode #console-container {
    height: 100vh;
    width: 100vw;
    gap: 0;
    justify-content: center;
    align-items: center;
}

body.fullscreen-mode #console-body {
    display: none;
}

body.fullscreen-mode footer {
    display: none;
}

/* Fullscreen screen container - fills viewport while maintaining aspect ratio */
body.fullscreen-mode .fullscreen-screen-wrapper {
    display: flex !important;
    position: fixed;
    top: 0;
    left: 0;
    width: 100vw;
    height: 100vh;
    background: #000;
    align-items: center;
    justify-content: center;
    z-index: 100;
}

body.fullscreen-mode .fullscreen-screen-wrapper #screen-container {
    /* Calculate size to fill viewport while maintaining 1:1 aspect ratio */
    width: min(100vw, 100vh);
    height: min(100vw, 100vh);
    max-width: 100vw;
    max-height: 100vh;
    border-radius: 0;
}

body.fullscreen-mode .fullscreen-screen-wrapper #game-canvas {
    width: 100%;
    height: 100%;
}

body.fullscreen-mode .fullscreen-screen-wrapper #scanlines,
body.fullscreen-mode .fullscreen-screen-wrapper #crt-overlay,
body.fullscreen-mode .fullscreen-screen-wrapper #click-to-start,
body.fullscreen-mode .fullscreen-screen-wrapper #fullscreen-btn {
    display: block;
}

body.fullscreen-mode .fullscreen-screen-wrapper #fullscreen-btn {
    position: absolute;
    top: 10px;
    right: 10px;
    z-index: 200;
}

/* Mobile touch controls in fullscreen */
body.fullscreen-mode .fullscreen-touch-controls {
    display: flex;
}

.fullscreen-touch-controls {
    display: none;
    position: fixed;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 20px;
    justify-content: space-between;
    z-index: 150;
    pointer-events: none;
}

.fullscreen-touch-controls > * {
    pointer-events: auto;
}

.fullscreen-touch-controls #dpad,
.fullscreen-touch-controls #action-buttons {
    display: flex;
}

.fullscreen-touch-controls #dpad {
    display: grid;
    grid-template-columns: repeat(3, 50px);
    grid-template-rows: repeat(3, 50px);
    gap: 2px;
}

.fullscreen-touch-controls .dpad-btn {
    width: 50px;
    height: 50px;
    font-size: 20px;
    background: rgba(26, 26, 26, 0.8);
}

.fullscreen-touch-controls #action-buttons {
    gap: 15px;
    align-items: center;
    transform: rotate(-20deg);
}

.fullscreen-touch-controls .action-btn {
    width: 60px;
    height: 60px;
    font-size: 14px;
    opacity: 0.9;
}

/* Hide panels/overlays in fullscreen */
body.fullscreen-mode #generator-panel,
body.fullscreen-mode #settings-panel,
body.fullscreen-mode #debug-panel,
body.fullscreen-mode #library-panel,
body.fullscreen-mode #community-panel,
body.fullscreen-mode #select-menu,
body.fullscreen-mode #help-modal,
body.fullscreen-mode #source-modal {
    z-index: 300;
}

/* Select Menu (mobile popup) */
#select-menu {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 250;
}

#select-menu.hidden {
    display: none;
}

#select-menu-content {
    background: linear-gradient(180deg, #2a2a3e 0%, #1a1a2e 100%);
    border-radius: 15px;
    width: 90%;
    max-width: 300px;
    overflow: hidden;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6);
}

#select-menu-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px;
    background: #1d3557;
}

#select-menu-header span {
    font-size: 12px;
    letter-spacing: 2px;
}

#close-select-menu {
    background: none;
    border: none;
    color: #f88;
    font-size: 16px;
    cursor: pointer;
    padding: 5px;
}

#select-menu-buttons {
    display: flex;
    flex-direction: column;
    gap: 10px;
    padding: 15px;
}

.select-menu-btn {
    padding: 15px 20px;
    background: linear-gradient(180deg, #3a3a4a 0%, #2a2a3a 100%);
    border: 1px solid #4a4a5a;
    border-radius: 8px;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 9px;
    cursor: pointer;
    text-align: left;
    transition: all 0.2s;
}

.select-menu-btn:hover,
.select-menu-btn:active {
    background: linear-gradient(180deg, #4a4a5a 0%, #3a3a4a 100%);
    border-color: #5a5a6a;
}

/* Generator Panel - now a modal */
#generator-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(180deg, #2a2a3e 0%, #1a1a2e 100%);
    border-radius: 15px;
    width: 90%;
    max-width: 400px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6);
    z-index: 200;
}

#generator-panel.hidden {
    display: none;
}

#generator-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px;
    background: #1d3557;
}

#generator-header span {
    font-size: 10px;
}

.gen-icon {
    font-size: 14px;
}

#close-generator {
    background: none;
    border: none;
    color: #f88;
    font-size: 14px;
    cursor: pointer;
    padding: 5px;
}

#close-generator:hover {
    color: #faa;
}

#generator-content {
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    overflow-y: auto;
    max-height: calc(80vh - 60px);
}

#generator-content.generating {
    opacity: 0.6;
    pointer-events: none;
}

#generator-content.generating::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: repeating-linear-gradient(
        45deg,
        transparent,
        transparent 10px,
        rgba(0, 0, 0, 0.1) 10px,
        rgba(0, 0, 0, 0.1) 20px
    );
    pointer-events: none;
    animation: generating-stripes 1s linear infinite;
}

@keyframes generating-stripes {
    0% { background-position: 0 0; }
    100% { background-position: 28px 0; }
}

/* Edit controls section */
#edit-controls {
    margin-bottom: 5px;
}

#edit-controls.hidden {
    display: none;
}

#version-info {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 10px 12px;
    background: linear-gradient(180deg, #3a4a3a 0%, #2a3a2a 100%);
    border: 1px solid #4a5a4a;
    border-radius: 8px;
}

#version-info.hidden {
    display: none;
}

#version-text {
    font-size: 8px;
    color: #8f8;
}

#version-buttons {
    display: flex;
    gap: 8px;
}

.version-btn {
    width: 32px;
    height: 32px;
    background: linear-gradient(180deg, #4a5a4a 0%, #3a4a3a 100%);
    border: 1px solid #5a6a5a;
    border-radius: 5px;
    color: #8f8;
    font-size: 14px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.version-btn:hover:not(:disabled) {
    background: linear-gradient(180deg, #5a6a5a 0%, #4a5a4a 100%);
}

.version-btn:disabled {
    opacity: 0.4;
    cursor: not-allowed;
}

#api-selector {
    display: flex;
    gap: 15px;
    font-size: 8px;
    flex-wrap: wrap;
}

#api-selector label {
    display: flex;
    align-items: center;
    gap: 5px;
    cursor: pointer;
}

#api-selector input:disabled + span,
#api-selector label:has(input:disabled) {
    opacity: 0.5;
    cursor: not-allowed;
}

#grok-options,
#openrouter-options,
#pollinations-options {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

#grok-options.hidden,
#openrouter-options.hidden,
#pollinations-options.hidden {
    display: none;
}

#api-key-container,
#openrouter-key-container {
    display: flex;
    gap: 8px;
}

#api-key,
#openrouter-key {
    flex: 1;
    padding: 10px;
    background: #111;
    border: 2px solid #333;
    border-radius: 5px;
    color: #fff;
    font-family: monospace;
    font-size: 12px;
}

#api-key:disabled,
#openrouter-key:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#toggle-key-visibility,
#toggle-openrouter-key-visibility {
    padding: 10px;
    background: #333;
    border: none;
    border-radius: 5px;
    cursor: pointer;
}

#toggle-key-visibility:disabled,
#toggle-openrouter-key-visibility:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#model-selector,
#openrouter-model-selector,
#pollinations-model-selector {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

#model-selector label,
#openrouter-model-selector label,
#pollinations-model-selector label {
    font-size: 8px;
    color: #888;
}

#grok-model,
#pollinations-model {
    padding: 10px;
    background: #111;
    border: 2px solid #333;
    border-radius: 5px;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    cursor: pointer;
}

#grok-model:disabled,
#pollinations-model:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#grok-model:focus,
#pollinations-model:focus {
    border-color: #e63946;
    outline: none;
}

#grok-model option,
#pollinations-model option {
    background: #1a1a2e;
    padding: 8px;
}

#openrouter-model {
    padding: 10px;
    background: #111;
    border: 2px solid #333;
    border-radius: 5px;
    color: #fff;
    font-family: monospace;
    font-size: 10px;
}

#openrouter-model:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#openrouter-model:focus {
    border-color: #e63946;
    outline: none;
}

.model-hint {
    font-size: 6px;
    color: #666;
    font-style: italic;
}

#game-prompt {
    width: 100%;
    height: 80px;
    padding: 10px;
    background: #111;
    border: 2px solid #333;
    border-radius: 5px;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    line-height: 1.5;
    resize: none;
}

#game-prompt:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#game-prompt:focus {
    border-color: #e63946;
    outline: none;
}

#char-count {
    font-size: 8px;
    color: #666;
    text-align: right;
}

/* Image upload section */
#image-upload-section {
    background: #111;
    border: 2px solid #333;
    border-radius: 5px;
    padding: 10px;
}

#image-upload-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 8px;
}

#image-upload-header span {
    font-size: 8px;
    color: #888;
}

#image-upload-btn {
    padding: 6px 12px;
    background: linear-gradient(180deg, #4a5a6a 0%, #3a4a5a 100%);
    border: 1px solid #5a6a7a;
    border-radius: 4px;
    color: #adf;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    cursor: pointer;
    transition: all 0.2s;
}

#image-upload-btn:hover:not(:disabled) {
    background: linear-gradient(180deg, #5a6a7a 0%, #4a5a6a 100%);
}

#image-upload-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

#reference-images {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.reference-image {
    position: relative;
    width: 60px;
    height: 60px;
    border-radius: 5px;
    overflow: hidden;
    border: 2px solid #444;
}

.reference-image img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.remove-image-btn {
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    background: rgba(200, 50, 50, 0.9);
    border: none;
    border-radius: 50%;
    color: #fff;
    font-size: 10px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.remove-image-btn:hover {
    background: rgba(230, 70, 70, 1);
}

#generate-btn {
    padding: 15px;
    background: linear-gradient(180deg, #e63946 0%, #a62633 100%);
    border: none;
    border-radius: 8px;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    cursor: pointer;
    box-shadow: 0 4px 0 #7a1d25;
    transition: all 0.1s;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 10px;
}

#generate-btn:hover:not(:disabled) {
    background: linear-gradient(180deg, #ff4d5a 0%, #c62d3b 100%);
}

#generate-btn:active:not(:disabled) {
    transform: translateY(3px);
    box-shadow: 0 1px 0 #7a1d25;
}

#generate-btn:disabled {
    opacity: 0.7;
    cursor: not-allowed;
}

.loading-spinner {
    animation: spin 0.5s linear infinite;
}

.loading-spinner.hidden {
    display: none;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

#generation-status {
    padding: 10px;
    background: #111;
    border-radius: 5px;
}

#generation-status.hidden {
    display: none;
}

.status-text {
    font-size: 8px;
    color: #0f0;
    margin-bottom: 8px;
}

.progress-bar {
    height: 8px;
    background: #333;
    border-radius: 4px;
    overflow: hidden;
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #0f0, #0ff);
    width: 0%;
    transition: width 0.3s;
}

/* Pollinations Ad Display */
#pollinations-ad {
    padding: 10px 12px;
    background: linear-gradient(180deg, #2a3a4a 0%, #1a2a3a 100%);
    border: 1px solid #3a4a5a;
    border-radius: 8px;
    display: flex;
    align-items: center;
    gap: 8px;
}

#pollinations-ad.hidden {
    display: none;
}

#pollinations-ad .ad-icon {
    font-size: 14px;
}

#pollinations-ad .ad-text {
    font-size: 7px;
    color: #8af;
    line-height: 1.4;
}

#pollinations-ad .ad-text a {
    color: #adf;
    text-decoration: underline;
}

#pollinations-ad .ad-text a:hover {
    color: #cef;
}

/* Game Library Panel */
#library-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(180deg, #2a3a2a 0%, #1a2a1a 100%);
    border-radius: 15px;
    width: 90%;
    max-width: 450px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6);
    z-index: 200;
    display: flex;
    flex-direction: column;
}

#library-panel.hidden {
    display: none;
}

#library-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px;
    background: #2d4a2d;
    flex-shrink: 0;
}

#library-header span {
    font-size: 10px;
    color: #8f8;
}

.lib-icon {
    font-size: 14px;
}

#close-library {
    background: none;
    border: none;
    color: #f88;
    font-size: 14px;
    cursor: pointer;
    padding: 5px;
}

#close-library:hover {
    color: #faa;
}

#library-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

#library-games {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.library-empty {
    text-align: center;
    padding: 30px 20px;
    color: #6a8;
    font-size: 8px;
    line-height: 1.8;
}

.library-game {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: linear-gradient(180deg, #2a3a2a 0%, #1a2a1a 100%);
    border: 1px solid #3d5a3d;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.library-game:hover {
    background: linear-gradient(180deg, #3a4a3a 0%, #2a3a2a 100%);
    border-color: #4d6a4d;
}

.library-game.active {
    border-color: #8f8;
    box-shadow: 0 0 10px rgba(136, 255, 136, 0.2);
}

.library-game-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.library-game-title {
    font-size: 9px;
    color: #8f8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    display: flex;
    align-items: center;
    gap: 6px;
}

.shared-badge {
    font-size: 10px;
    flex-shrink: 0;
}

.library-game-prompt {
    font-size: 7px;
    color: #6a8;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 200px;
}

.library-game-meta {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
}

.library-game-date {
    font-size: 6px;
    color: #4a6;
}

.library-game-versions {
    font-size: 6px;
    color: #8af;
    background: rgba(100, 150, 255, 0.15);
    padding: 2px 5px;
    border-radius: 3px;
}

.library-game-images {
    font-size: 6px;
    color: #fa8;
}

.library-game-model {
    font-size: 6px;
    color: #af8;
    background: rgba(150, 255, 150, 0.15);
    padding: 2px 5px;
    border-radius: 3px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    max-width: 80px;
}

.library-game-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

.library-btn {
    width: 32px;
    height: 32px;
    border: none;
    border-radius: 5px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.library-btn.play {
    background: linear-gradient(180deg, #4a8 0%, #286 100%);
    color: #fff;
}

.library-btn.play:hover {
    background: linear-gradient(180deg, #5b9 0%, #397 100%);
}

.library-btn.share {
    background: linear-gradient(180deg, #48a 0%, #268 100%);
    color: #fff;
}

.library-btn.share:hover {
    background: linear-gradient(180deg, #59b 0%, #379 100%);
}

.library-btn.share svg {
    display: block;
    width: 14px;
    height: 14px;
}

.library-btn.share.shared {
    background: linear-gradient(180deg, #4a8 0%, #286 100%);
}

.library-btn.share.shared:hover {
    background: linear-gradient(180deg, #5b9 0%, #397 100%);
}

.library-btn.edit {
    background: linear-gradient(180deg, #48a 0%, #268 100%);
    color: #fff;
}

.library-btn.edit:hover {
    background: linear-gradient(180deg, #59b 0%, #379 100%);
}

.library-btn.delete {
    background: linear-gradient(180deg, #844 0%, #622 100%);
    color: #faa;
}

.library-btn.delete:hover {
    background: linear-gradient(180deg, #955 0%, #733 100%);
}

/* Community Games Panel */
#community-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: linear-gradient(180deg, #2a2a4a 0%, #1a1a3a 100%);
    border-radius: 15px;
    width: 90%;
    max-width: 450px;
    max-height: 80vh;
    overflow: hidden;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6);
    z-index: 200;
    display: flex;
    flex-direction: column;
}

#community-panel.hidden {
    display: none;
}

#community-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px;
    background: #2d2d5a;
    flex-shrink: 0;
}

#community-header span {
    font-size: 10px;
    color: #aaf;
}

.community-icon {
    font-size: 14px;
}

#close-community {
    background: none;
    border: none;
    color: #f88;
    font-size: 14px;
    cursor: pointer;
    padding: 5px;
}

#close-community:hover {
    color: #faa;
}

#community-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

#community-games {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.community-empty,
.loading-community {
    text-align: center;
    padding: 30px 20px;
    color: #88a;
    font-size: 8px;
    line-height: 1.8;
}

.community-game {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: linear-gradient(180deg, #2a2a4a 0%, #1a1a3a 100%);
    border: 1px solid #3d3d6a;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.community-game:hover {
    background: linear-gradient(180deg, #3a3a5a 0%, #2a2a4a 100%);
    border-color: #4d4d7a;
}

.community-game-info {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.community-game-title {
    font-size: 9px;
    color: #aaf;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.community-game-author {
    font-size: 7px;
    color: #8af;
}

.community-game-date {
    font-size: 6px;
    color: #668;
}

.community-play-btn {
    width: 36px;
    height: 36px;
    border: none;
    border-radius: 50%;
    background: linear-gradient(180deg, #4a8 0%, #286 100%);
    color: #fff;
    font-size: 16px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
}

.community-play-btn:hover {
    background: linear-gradient(180deg, #5b9 0%, #397 100%);
    transform: scale(1.1);
}

/* Share Dialog */
#share-dialog {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

#share-dialog.hidden {
    display: none;
}

#share-dialog-content {
    background: linear-gradient(180deg, #2a3a4a 0%, #1a2a3a 100%);
    border-radius: 15px;
    width: 90%;
    max-width: 360px;
    overflow: hidden;
    box-shadow: 0 10px 50px rgba(0, 0, 0, 0.6);
}

#share-dialog-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 15px;
    background: #1d3557;
}

#share-dialog-header span {
    font-size: 11px;
    color: #adf;
    letter-spacing: 1px;
}

#close-share-dialog {
    background: none;
    border: none;
    color: #f88;
    font-size: 16px;
    cursor: pointer;
    padding: 5px;
}

#close-share-dialog:hover {
    color: #faa;
}

#share-dialog-body {
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

#share-game-title {
    font-size: 10px;
    color: #fff;
    text-align: center;
    padding: 10px;
    background: rgba(0, 0, 0, 0.3);
    border-radius: 8px;
    word-break: break-word;
}

#share-status-badge {
    text-align: center;
    font-size: 8px;
    padding: 6px 12px;
    border-radius: 20px;
    display: inline-block;
    margin: 0 auto;
}

#share-status-badge.published {
    background: rgba(100, 200, 100, 0.2);
    color: #8f8;
    border: 1px solid #4a6a4a;
}

#share-status-badge.unpublished {
    background: rgba(150, 150, 150, 0.2);
    color: #aaa;
    border: 1px solid #4a4a4a;
}

#share-link-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

#share-link-section.hidden {
    display: none;
}

#share-link-section label {
    font-size: 8px;
    color: #8af;
}

#share-link-container {
    display: flex;
    gap: 8px;
}

#share-link-input {
    flex: 1;
    padding: 10px;
    background: #111;
    border: 2px solid #333;
    border-radius: 5px;
    color: #fff;
    font-family: monospace;
    font-size: 9px;
}

#copy-share-link-btn {
    padding: 10px 15px;
    background: linear-gradient(180deg, #4a8 0%, #286 100%);
    border: none;
    border-radius: 5px;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s;
}

#copy-share-link-btn:hover {
    background: linear-gradient(180deg, #5b9 0%, #397 100%);
}

#copy-share-link-btn.copied {
    background: linear-gradient(180deg, #8f8 0%, #4a8 100%);
}

#share-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-top: 5px;
}

.share-action-btn {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 6px;
    padding: 15px;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    transition: all 0.2s;
}

.share-action-btn.hidden {
    display: none;
}

.share-action-btn.publish {
    background: linear-gradient(180deg, #48a 0%, #268 100%);
    border: 1px solid #5a9acf;
}

.share-action-btn.publish:hover {
    background: linear-gradient(180deg, #59b 0%, #379 100%);
}

.share-action-btn.unpublish {
    background: linear-gradient(180deg, #654 0%, #432 100%);
    border: 1px solid #765;
}

.share-action-btn.unpublish:hover {
    background: linear-gradient(180deg, #765 0%, #543 100%);
}

.share-action-btn .btn-icon {
    font-size: 20px;
}

.share-action-btn .btn-label {
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
    color: #fff;
}

.share-action-btn .btn-desc {
    font-family: 'Press Start 2P', monospace;
    font-size: 6px;
    color: rgba(255, 255, 255, 0.6);
}

/* Toast Notifications */
.toast {
    position: fixed;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    padding: 12px 20px;
    background: linear-gradient(180deg, #2a2a3e 0%, #1a1a2e 100%);
    border: 1px solid #4a4a5a;
    border-radius: 8px;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    z-index: 500;
    opacity: 0;
    transition: all 0.3s ease;
    max-width: 80%;
    text-align: center;
}

.toast.show {
    transform: translateX(-50%) translateY(0);
    opacity: 1;
}

.toast.toast-error {
    background: linear-gradient(180deg, #4a2a2a 0%, #3a1a1a 100%);
    border-color: #6a3a3a;
    color: #faa;
}

.toast.toast-info {
    background: linear-gradient(180deg, #2a3a4a 0%, #1a2a3a 100%);
    border-color: #3a4a5a;
    color: #adf;
}

/* Floating action buttons */
.floating-btn {
    position: fixed;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    z-index: 100;
    transition: transform 0.2s, background 0.2s;
}

.floating-btn:hover {
    transform: scale(1.1);
}

#generator-btn {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(180deg, #e63946 0%, #a62633 100%);
    border: none;
    color: #fff;
    font-size: 20px;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    z-index: 100;
    transition: transform 0.2s, background 0.2s;
}

#generator-btn:hover {
    transform: scale(1.1);
    background: linear-gradient(180deg, #ff4d5a 0%, #c62d3b 100%);
}

#library-btn {
    position: fixed;
    top: 20px;
    right: 74px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(180deg, #2d4a2d 0%, #1a3a1a 100%);
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    z-index: 100;
    transition: transform 0.2s, background 0.2s;
}

#library-btn:hover {
    transform: scale(1.1);
    background: linear-gradient(180deg, #3d5a3d 0%, #2a4a2a 100%);
}

#community-btn {
    position: fixed;
    top: 20px;
    right: 128px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: linear-gradient(180deg, #2d2d5a 0%, #1a1a4a 100%);
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    z-index: 100;
    transition: transform 0.2s, background 0.2s;
}

#community-btn:hover {
    transform: scale(1.1);
    background: linear-gradient(180deg, #3d3d6a 0%, #2a2a5a 100%);
}

#help-btn {
    position: fixed;
    top: 20px;
    right: 182px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #1d3557;
    border: none;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 16px;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    z-index: 100;
    transition: transform 0.2s, background 0.2s;
}

#help-btn:hover {
    transform: scale(1.1);
}

#settings-btn {
    position: fixed;
    top: 20px;
    right: 236px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #3d3557;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    z-index: 100;
    transition: transform 0.2s, background 0.2s;
}

#settings-btn:hover {
    transform: scale(1.1);
    background: #4d4567;
}

#debug-btn {
    position: fixed;
    top: 20px;
    right: 290px;
    width: 44px;
    height: 44px;
    border-radius: 50%;
    background: #2d4a3e;
    border: none;
    color: #fff;
    font-size: 18px;
    cursor: pointer;
    box-shadow: 0 3px 10px rgba(0, 0, 0, 0.3);
    z-index: 100;
    transition: transform 0.2s, background 0.2s;
}

#debug-btn:hover {
    transform: scale(1.1);
    background: #3d5a4e;
}

/* Settings Panel Styles */
#settings-panel {
    position: fixed;
    top: 70px;
    right: 20px;
    width: 400px;
    max-height: calc(100vh - 100px);
    background: linear-gradient(180deg, #2a1a3a 0%, #1a0d2a 100%);
    border: 2px solid #5a3a6a;
    border-radius: 10px;
    box-shadow: 0 5px 30px rgba(0, 0, 0, 0.5);
    z-index: 160;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#settings-panel.hidden {
    display: none;
}

#settings-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: #4a2a5a;
    border-bottom: 1px solid #5a3a6a;
}

#settings-header span {
    font-size: 10px;
    color: #d8f;
    letter-spacing: 1px;
}

#close-settings {
    background: none;
    border: none;
    color: #f88;
    font-size: 14px;
    cursor: pointer;
    padding: 5px;
}

#close-settings:hover {
    color: #faa;
}

#settings-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.settings-section {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.settings-section label {
    font-size: 9px;
    color: #a8f;
    letter-spacing: 1px;
}

.settings-hint {
    font-size: 7px;
    color: #888;
    font-style: italic;
}

.settings-section textarea {
    width: 100%;
    padding: 10px;
    background: #111;
    border: 2px solid #444;
    border-radius: 5px;
    color: #fff;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 9px;
    line-height: 1.4;
    resize: vertical;
    min-height: 200px;
}

.settings-section textarea:focus {
    border-color: #a8f;
    outline: none;
}

.settings-section input[type="number"] {
    width: 100%;
    padding: 10px;
    background: #111;
    border: 2px solid #444;
    border-radius: 5px;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 10px;
}

.settings-section input[type="number"]:focus {
    border-color: #a8f;
    outline: none;
}

.settings-actions {
    display: flex;
    gap: 10px;
    margin-top: 10px;
}

.settings-btn {
    flex: 1;
    padding: 12px 15px;
    border: none;
    border-radius: 5px;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

.settings-btn.restore {
    background: linear-gradient(180deg, #5a4a4a 0%, #4a3a3a 100%);
    color: #faa;
    border: 1px solid #6a5a5a;
}

.settings-btn.restore:hover {
    background: linear-gradient(180deg, #6a5a5a 0%, #5a4a4a 100%);
}

.settings-btn.save {
    background: linear-gradient(180deg, #5a3a6a 0%, #4a2a5a 100%);
    color: #d8f;
    border: 1px solid #6a4a7a;
}

.settings-btn.save:hover {
    background: linear-gradient(180deg, #6a4a7a 0%, #5a3a6a 100%);
}

/* Debug Panel Styles */
#debug-panel {
    position: fixed;
    top: 70px;
    right: 20px;
    width: 350px;
    max-height: calc(100vh - 100px);
    background: linear-gradient(180deg, #1a2a1a 0%, #0d1a0d 100%);
    border: 2px solid #3d5a3d;
    border-radius: 10px;
    box-shadow: 0 5px 30px rgba(0, 0, 0, 0.5);
    z-index: 150;
    overflow: hidden;
    display: flex;
    flex-direction: column;
}

#debug-panel.hidden {
    display: none;
}

#debug-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 12px 15px;
    background: #2d4a2d;
    border-bottom: 1px solid #3d5a3d;
}

#debug-header span {
    font-size: 10px;
    color: #8f8;
    letter-spacing: 1px;
}

#close-debug {
    background: none;
    border: none;
    color: #f88;
    font-size: 14px;
    cursor: pointer;
    padding: 5px;
}

#close-debug:hover {
    color: #faa;
}

#debug-tabs {
    display: flex;
    background: #1a2a1a;
    border-bottom: 1px solid #3d5a3d;
}

.debug-tab {
    flex: 1;
    padding: 10px 8px;
    background: transparent;
    border: none;
    color: #6a8;
    font-family: 'Press Start 2P', monospace;
    font-size: 6px;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom: 2px solid transparent;
}

.debug-tab:hover {
    background: rgba(100, 200, 100, 0.1);
}

.debug-tab.active {
    color: #8f8;
    border-bottom-color: #8f8;
    background: rgba(100, 200, 100, 0.15);
}

#debug-content {
    flex: 1;
    overflow-y: auto;
    padding: 15px;
}

.debug-tab-content {
    display: flex;
    flex-direction: column;
    gap: 15px;
}

.debug-tab-content.hidden {
    display: none;
}

.debug-tab-content h3 {
    font-size: 8px;
    color: #6a8;
    margin-bottom: 8px;
    letter-spacing: 1px;
}

/* Source Tab Styles */
#source-toolbar {
    display: flex;
    gap: 8px;
    margin-bottom: 10px;
}

#copy-source-btn {
    padding: 8px 12px;
    background: linear-gradient(180deg, #3a4a5a 0%, #2a3a4a 100%);
    border: 1px solid #4a5a6a;
    border-radius: 5px;
    color: #adf;
    font-family: 'Press Start 2P', monospace;
    font-size: 7px;
    cursor: pointer;
    transition: all 0.2s;
}

#copy-source-btn:hover {
    background: linear-gradient(180deg, #4a5a6a 0%, #3a4a5a 100%);
    border-color: #5a6a7a;
}

#source-code-inline {
    background: #0a0a0a;
    border: 1px solid #333;
    border-radius: 5px;
    padding: 15px;
    margin: 0;
    color: #8f8;
    font-family: 'JetBrains Mono', 'Fira Code', monospace;
    font-size: 10px;
    line-height: 1.5;
    white-space: pre-wrap;
    word-wrap: break-word;
    tab-size: 2;
    max-height: 400px;
    overflow-y: auto;
}

/* Palette Display */
#palette-display {
    display: grid;
    grid-template-columns: repeat(16, 1fr);
    gap: 2px;
    background: #111;
    padding: 8px;
    border-radius: 5px;
}

.palette-color {
    aspect-ratio: 1;
    border-radius: 2px;
    cursor: pointer;
    transition: transform 0.1s;
}

.palette-color:hover {
    transform: scale(1.3);
    z-index: 10;
}

/* Tileset Sprites */
#tileset-sprites {
    display: flex;
    flex-wrap: wrap;
    gap: 10px;
    background: #111;
    padding: 10px;
    border-radius: 5px;
}

.sprite-preview {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 5px;
    padding: 8px;
    background: #1a1a1a;
    border-radius: 5px;
    border: 1px solid #333;
}

.sprite-preview canvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    background: repeating-conic-gradient(#222 0% 25%, #333 0% 50%) 50% / 8px 8px;
}

.sprite-label {
    font-size: 6px;
    color: #888;
}

/* Layers Debug */
#layers-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.layer-item {
    background: #111;
    padding: 12px;
    border-radius: 5px;
    border-left: 3px solid #4a4;
}

.layer-item.tile-layer {
    border-left-color: #48f;
}

.layer-item.sprites-layer {
    border-left-color: #f84;
}

.layer-item.text-layer {
    border-left-color: #ff0;
}

.layer-item.layer-legend {
    border-left-color: #4aa;
    background: #0a1a1a;
}

.layer-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
    gap: 10px;
}

.layer-name {
    font-size: 9px;
    color: #8f8;
    flex: 1;
}

.layer-status {
    font-size: 7px;
    padding: 3px 6px;
    border-radius: 3px;
    background: #2a2a2a;
}

.layer-status.active {
    color: #48f;
    background: #1a1a3a;
}

.layer-status.sprite {
    color: #f84;
    background: #3a1a1a;
}

.layer-status.text {
    color: #ff0;
    background: #3a3a1a;
}

.layer-status.inactive {
    color: #888;
}

.layer-details {
    display: flex;
    gap: 15px;
    font-size: 7px;
    color: #6a8;
    flex-wrap: wrap;
}

/* Layer Visibility Toggle */
.layer-visibility-toggle {
    display: flex;
    align-items: center;
    cursor: pointer;
}

.layer-visibility-toggle input {
    display: none;
}

.visibility-icon {
    font-size: 14px;
    opacity: 0.8;
    transition: opacity 0.2s;
}

.layer-visibility-toggle:hover .visibility-icon {
    opacity: 1;
}

/* Sprites Grid */
.sprites-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(70px, 1fr));
    gap: 8px;
    margin-top: 10px;
    max-height: 200px;
    overflow-y: auto;
    padding: 5px;
}

.sprite-grid-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 4px;
    padding: 6px;
    background: #1a1a1a;
    border-radius: 5px;
    border: 1px solid #333;
    cursor: pointer;
    transition: all 0.2s;
}

.sprite-grid-item:hover {
    border-color: #8f8;
    background: #1a2a1a;
}

.sprite-grid-item.prio-bg {
    border-left: 2px solid #4af;
}

.sprite-grid-item.prio-mid {
    border-left: 2px solid #4a4;
}

.sprite-grid-item.prio-fg {
    border-left: 2px solid #fa4;
}

.sprite-thumb {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    border-radius: 2px;
}

.sprite-grid-name {
    font-size: 5px;
    color: #888;
    text-align: center;
    max-width: 100%;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

/* Sprite Detail View */
.back-btn {
    padding: 5px 10px;
    background: #2a3a2a;
    border: 1px solid #4a5a4a;
    border-radius: 4px;
    color: #8f8;
    font-family: 'Press Start 2P', monospace;
    font-size: 6px;
    cursor: pointer;
    transition: all 0.2s;
}

.back-btn:hover {
    background: #3a4a3a;
}

.sprite-detail {
    display: flex;
    gap: 15px;
    margin-top: 10px;
    padding: 10px;
    background: #0a0a0a;
    border-radius: 5px;
}

.sprite-detail-canvas {
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    border: 1px solid #333;
    border-radius: 4px;
}

.sprite-props {
    display: flex;
    flex-direction: column;
    gap: 6px;
    flex: 1;
}

.prop-row {
    display: flex;
    gap: 8px;
    font-size: 7px;
}

.prop-label {
    color: #6a8;
    min-width: 50px;
}

.prop-value {
    color: #adf;
}

.sprites-list {
    margin-top: 8px;
    display: flex;
    flex-direction: column;
    gap: 5px;
    max-height: 150px;
    overflow-y: auto;
}

.sprite-info {
    font-size: 6px;
    color: #888;
    padding: 5px 8px;
    background: #1a1a1a;
    border-radius: 3px;
}

.sprite-info strong {
    color: #a8f;
}

.prio-group {
    font-size: 7px;
    color: #8af;
    padding: 5px 8px;
    background: #1a1a2a;
    border-radius: 3px;
}

.prio-group strong {
    color: #aaf;
}

/* Layer Legend */
.legend-content {
    display: flex;
    flex-direction: column;
    gap: 6px;
    margin-top: 8px;
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 7px;
    color: #8aa;
}

.legend-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
}

.legend-dot.tile {
    background: linear-gradient(135deg, #48f 0%, #28a 100%);
    box-shadow: 0 0 5px #48f;
}

.legend-dot.sprite {
    background: linear-gradient(135deg, #f84 0%, #a52 100%);
    box-shadow: 0 0 5px #f84;
}

.legend-dot.text {
    background: linear-gradient(135deg, #ff0 0%, #aa0 100%);
    box-shadow: 0 0 5px #ff0;
}

.legend-dot.bg {
    background: linear-gradient(135deg, #4af 0%, #28f 100%);
    box-shadow: 0 0 5px #4af;
}

.legend-dot.mid {
    background: linear-gradient(135deg, #4a4 0%, #282 100%);
    box-shadow: 0 0 5px #4a4;
}

.legend-dot.fg {
    background: linear-gradient(135deg, #fa4 0%, #f82 100%);
    box-shadow: 0 0 5px #fa4;
}

/* Sound Log */
#sound-log-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
}

#sound-log-header span {
    font-size: 8px;
    color: #6a8;
}

#clear-sound-log {
    padding: 5px 10px;
    background: #3a2a2a;
    border: none;
    border-radius: 3px;
    color: #f88;
    font-family: 'Press Start 2P', monospace;
    font-size: 6px;
    cursor: pointer;
}

#clear-sound-log:hover {
    background: #4a3a3a;
}

#sound-log-entries {
    background: #111;
    border-radius: 5px;
    max-height: 300px;
    overflow-y: auto;
}

.sound-entry {
    display: grid;
    grid-template-columns: 60px 80px 1fr;
    gap: 10px;
    padding: 8px 10px;
    border-bottom: 1px solid #222;
    font-size: 7px;
}

.sound-entry:last-child {
    border-bottom: none;
}

.sound-time {
    color: #666;
    font-family: monospace;
}

.sound-name {
    color: #fa0;
    font-weight: bold;
}

.sound-mml {
    color: #888;
    font-family: monospace;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.debug-empty {
    font-size: 8px;
    color: #666;
    text-align: center;
    padding: 20px;
}

/* Scrollbar styling for debug panel */
#debug-content::-webkit-scrollbar,
#sound-log-entries::-webkit-scrollbar,
.sprites-list::-webkit-scrollbar,
.sprites-grid::-webkit-scrollbar,
#source-code-inline::-webkit-scrollbar,
#settings-content::-webkit-scrollbar,
#generator-content::-webkit-scrollbar,
#library-content::-webkit-scrollbar,
#community-content::-webkit-scrollbar {
    width: 6px;
}

#debug-content::-webkit-scrollbar-track,
#sound-log-entries::-webkit-scrollbar-track,
.sprites-list::-webkit-scrollbar-track,
.sprites-grid::-webkit-scrollbar-track,
#source-code-inline::-webkit-scrollbar-track,
#settings-content::-webkit-scrollbar-track,
#generator-content::-webkit-scrollbar-track,
#library-content::-webkit-scrollbar-track,
#community-content::-webkit-scrollbar-track {
    background: #111;
}

#debug-content::-webkit-scrollbar-thumb,
#sound-log-entries::-webkit-scrollbar-thumb,
.sprites-list::-webkit-scrollbar-thumb,
.sprites-grid::-webkit-scrollbar-thumb,
#source-code-inline::-webkit-scrollbar-thumb,
#settings-content::-webkit-scrollbar-thumb,
#generator-content::-webkit-scrollbar-thumb,
#library-content::-webkit-scrollbar-thumb,
#community-content::-webkit-scrollbar-thumb {
    background: #3d5a3d;
    border-radius: 3px;
}

#help-modal {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

#help-modal.hidden {
    display: none;
}

.modal-content {
    background: #1a1a2e;
    padding: 30px;
    border-radius: 15px;
    max-width: 300px;
    text-align: center;
}

.modal-content h2 {
    font-size: 14px;
    margin-bottom: 20px;
    color: #e63946;
}

.control-section {
    margin-bottom: 20px;
    text-align: left;
}

.control-section h3 {
    font-size: 10px;
    color: #0ff;
    margin-bottom: 10px;
}

.control-section p {
    font-size: 8px;
    color: #ccc;
    margin: 5px 0;
}

#close-help {
    padding: 10px 20px;
    background: #e63946;
    border: none;
    border-radius: 5px;
    color: #fff;
    font-family: 'Press Start 2P', monospace;
    font-size: 8px;
    cursor: pointer;
}

footer {
    margin-top: 30px;
    padding: 20px;
    text-align: center;
}

footer .footer-divider {
    margin: 0 0.5rem;
    color: #666;
    font-size: 8px;
}

footer a {
    color: #666;
    text-decoration: none;
    font-size: 8px;
    transition: color 0.3s;
}

footer a:hover {
    color: #3CBCFC;
}

/* Modal backdrop for generator */
.modal-backdrop {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.7);
    z-index: 199;
}

.modal-backdrop.hidden {
    display: none;
}

/* Fullscreen screen wrapper - hidden by default */
.fullscreen-screen-wrapper {
    display: none;
}

/* Desktop - hide touch controls and show floating buttons */
@media (min-width: 769px) {
    #controls.touch-only,
    #start-select.touch-only {
        display: none;
    }
    
    #console-body {
        padding-bottom: 20px;
    }
    
    .desktop-only {
        display: block;
    }
    
    .fullscreen-touch-controls {
        display: none !important;
    }
    
    /* Screen bezel fills available space */
    #screen-bezel {
        flex: 1;
        min-height: 0;
    }
    
    /* Screen container fills bezel */
    #screen-container {
        width: 100%;
        height: 100%;
    }
}

@media (min-width: 1024px) {
    #game-title {
        max-width: 150px;
    }
}

/* Mobile: expanded fullscreen-like layout */
@media (max-width: 768px) {
    body {
        padding: 0;
        justify-content: flex-start;
        min-height: 100dvh;
    }
    
    #console-container {
        width: 100%;
        height: 100dvh;
        gap: 0;
    }
    
    #console-body {
        width: 100%;
        height: 100%;
        max-height: 100%;
        padding: 8px;
        border-radius: 0;
        display: flex;
        flex-direction: column;
        box-shadow: none;
    }
    
    #console-header {
        padding: 5px 8px;
        margin-bottom: 8px;
        flex-shrink: 0;
    }
    
    #logo .title {
        font-size: 14px;
    }
    
    #logo .star {
        font-size: 12px;
    }
    
    #game-title {
        max-width: 100px;
        font-size: 7px;
    }
    
    #auth-status {
        display: none;
    }
    
    #screen-bezel {
        padding: 8px;
        flex: 1;
        display: flex;
        align-items: center;
        justify-content: center;
        min-height: 0;
    }
    
    #screen-container {
        width: 100%;
        height: 100%;
    }
    
    #status-bar {
        padding: 8px 15px;
        margin-top: 5px;
        flex-shrink: 0;
    }
    
    .score-display .label {
        font-size: 7px;
    }
    
    .score-display .value {
        font-size: 14px;
    }
    
    #controls.touch-only,
    #start-select.touch-only {
        display: flex;
        flex-shrink: 0;
    }
    
    #controls {
        padding: 10px;
        margin-top: 5px;
    }
    
    #dpad {
        grid-template-columns: repeat(3, 38px);
        grid-template-rows: repeat(3, 38px);
    }
    
    .dpad-btn {
        font-size: 14px;
    }
    
    .action-btn {
        width: 48px;
        height: 48px;
        font-size: 11px;
    }
    
    #start-select {
        padding: 10px;
        gap: 20px;
    }
    
    .sys-btn {
        padding: 10px 25px;
        font-size: 9px;
    }
    
    /* Hide floating buttons on mobile - they're in the SELECT menu */
    .floating-btn.desktop-only,
    #generator-btn,
    #library-btn,
    #community-btn,
    #help-btn,
    #settings-btn,
    #debug-btn {
        display: none !important;
    }
    
    /* Full-screen modals on mobile */
    #debug-panel,
    #settings-panel,
    #library-panel,
    #community-panel {
        position: fixed;
        top: 0;
        left: 0;
        right: 0;
        bottom: 0;
        width: 100%;
        max-height: 100%;
        border-radius: 0;
        z-index: 200;
    }
    
    #generator-panel {
        width: 100%;
        max-width: 100%;
        max-height: 100%;
        height: 100%;
        border-radius: 0;
        top: 0;
        left: 0;
        transform: none;
    }
    
    #library-panel,
    #community-panel {
        top: 0;
        left: 0;
        transform: none;
        width: 100%;
        max-width: 100%;
        max-height: 100%;
        height: 100%;
    }
    
    footer {
        display: none;
    }
    
    /* Mobile fullscreen mode */
    body.fullscreen-mode .fullscreen-screen-wrapper {
        display: flex !important;
    }
    
    body.fullscreen-mode .fullscreen-screen-wrapper #screen-container {
        width: min(100vw, calc(100vh - 180px));
        height: min(100vw, calc(100vh - 180px));
    }
    
    body.fullscreen-mode .fullscreen-touch-controls {
        display: flex;
    }
}

/* Very small screens */
@media (max-width: 360px) {
    #dpad {
        grid-template-columns: repeat(3, 32px);
        grid-template-rows: repeat(3, 32px);
    }
    
    .dpad-btn {
        font-size: 12px;
    }
    
    .action-btn {
        width: 42px;
        height: 42px;
        font-size: 10px;
    }
    
    #action-buttons {
        gap: 10px;
    }
    
    #controls {
        padding: 8px;
    }
    
    .sys-btn {
        padding: 8px 18px;
        font-size: 8px;
    }
}

/* Landscape mobile */
@media (max-height: 500px) and (max-width: 768px) {
    #console-body {
        flex-direction: row;
        flex-wrap: wrap;
        align-items: center;
        justify-content: center;
        gap: 10px;
    }
    
    #console-header {
        width: 100%;
        margin-bottom: 5px;
    }
    
    #screen-bezel {
        flex: 0 0 auto;
        padding: 5px;
        height: calc(100vh - 100px);
    }
    
    #screen-container {
        height: 100%;
        width: auto;
        aspect-ratio: 1;
    }
    
    #status-bar {
        position: absolute;
        top: 40px;
        right: 10px;
        flex-direction: column;
        gap: 5px;
        padding: 5px;
    }
    
    #controls {
        flex: 1;
        margin-top: 0;
        padding: 5px;
    }
    
    #start-select {
        position: absolute;
        bottom: 10px;
        left: 50%;
        transform: translateX(-50%);
        padding: 5px;
        gap: 15px;
    }
}