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

:root {
    --bg-primary: #0a0f1a;
    --bg-secondary: #111827;
    --bg-card: #1a2235;
    --accent: #2dd4a8;
    --accent-dark: #1a9e7a;
    --accent-glow: rgba(45, 212, 168, 0.15);
    --text-primary: #e2e8f0;
    --text-secondary: #94a3b8;
    --text-muted: #64748b;
    --border: #1e293b;
    --input-bg: #0f172a;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', sans-serif;
    background: var(--bg-primary);
    color: var(--text-primary);
    height: 100vh;
    display: flex;
    flex-direction: row;
    overflow: hidden;
}

/* ── Sidebar ── */
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: #080d18;
    border-right: 1px solid var(--border);
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}
.sidebar-scroll {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    display: flex;
    flex-direction: column;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

.sidebar-logo {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 16px 16px 12px;
    border-bottom: 1px solid var(--border);
}

.sidebar-logo .logo-icon {
    width: 30px;
    height: 30px;
    font-size: 14px;
    border-radius: 8px;
}

.sidebar-logo h1 {
    font-size: 15px;
    font-weight: 700;
    color: var(--text-primary);
}

.new-chat-btn {
    margin: 10px 12px;
    padding: 9px 14px;
    border-radius: 10px;
    background: var(--accent-glow);
    border: 1px solid rgba(45,212,168,0.3);
    color: var(--accent);
    font-size: 13px;
    font-weight: 500;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 7px;
    transition: all 0.2s;
    text-align: left;
}

.new-chat-btn:hover {
    background: rgba(45,212,168,0.2);
}

.sidebar-section-label {
    font-size: 10px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    padding: 8px 16px 4px;
}

.chat-history {
    overflow-y: visible;
    padding: 4px 8px;
}

.history-item {
    padding: 8px 10px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 12px;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    transition: background 0.15s;
    display: flex;
    align-items: center;
    gap: 6px;
}

.history-item:hover { background: rgba(255,255,255,0.05); }
.history-item.active { background: var(--accent-glow); color: var(--text-primary); }

.history-item .hi-icon { font-size: 11px; flex-shrink: 0; }

.sidebar-bottom {
    padding: 12px;
    border-top: 1px solid var(--border);
}


/* ── Main wrapper ── */
.main-wrapper {
    flex: 1;
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
    min-width: 0;
}

header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 24px;
    border-bottom: 1px solid var(--border);
    background: var(--bg-secondary);
    z-index: 10;
}

.header-left {
    display: flex;
    align-items: center;
    gap: 12px;
}

.logo-icon {
    width: 36px;
    height: 36px;
    background: var(--accent);
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 18px;
}

.header-title h1 {
    font-size: 16px;
    font-weight: 600;
    color: var(--text-primary);
}

.header-title p {
    font-size: 11px;
    color: var(--text-secondary);
}

.model-selector {
    display: flex;
    align-items: center;
    gap: 8px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 8px 16px;
    color: var(--text-primary);
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    position: relative;
    user-select: none;
    transition: border-color 0.2s;
}

.model-selector:hover {
    border-color: var(--accent);
}

.model-selector .dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--accent);
}

.model-selector .chevron {
    font-size: 10px;
    color: var(--text-secondary);
    transition: transform 0.2s;
}

.model-selector.open .chevron {
    transform: rotate(180deg);
}

.model-dropdown {
    position: absolute;
    top: calc(100% + 6px);
    right: 0;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 6px;
    min-width: 240px;
    max-height: 480px;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
    display: none;
    z-index: 100;
    box-shadow: 0 12px 40px rgba(0,0,0,0.5);
}

.model-dropdown.show { display: block; }

.model-group-label {
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.8px;
    color: var(--text-muted);
    padding: 6px 10px 3px;
    margin-top: 4px;
}

.model-group-label:first-child { margin-top: 0; }

.model-group-divider {
    height: 1px;
    background: var(--border);
    margin: 4px 6px;
}

.model-free-badge {
    font-size: 9px;
    font-weight: 700;
    background: rgba(45,212,168,0.15);
    color: var(--accent);
    border: 1px solid rgba(45,212,168,0.3);
    border-radius: 4px;
    padding: 1px 5px;
    flex-shrink: 0;
}

.model-option {
    padding: 10px 12px;
    border-radius: 8px;
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 10px;
    transition: background 0.15s;
}

.model-option:hover { background: rgba(255,255,255,0.05); }
.model-option.active { background: var(--accent-glow); }

.model-option .model-dot {
    width: 8px;
    height: 8px;
    border-radius: 50%;
}

.model-option .model-info { flex: 1; }
.model-option .model-name { font-size: 13px; font-weight: 500; }
.model-option .model-desc { font-size: 11px; color: var(--text-muted); }

.main-content {
    flex: 1;
    display: flex;
    flex-direction: column;
    overflow-y: auto;
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.welcome-screen {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 16px;
    padding: 40px 20px;
}

.welcome-screen.hidden { display: none; }

.welcome-icon {
    width: 80px;
    height: 80px;
    background: var(--accent);
    border-radius: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 36px;
    box-shadow: 0 8px 32px rgba(45, 212, 168, 0.25);
}

.welcome-screen h2 {
    font-size: 26px;
    font-weight: 600;
    margin-top: 8px;
}

.welcome-screen .subtitle {
    color: var(--text-secondary);
    font-size: 15px;
    text-align: center;
    max-width: 420px;
    line-height: 1.5;
}

.quick-actions {
    display: flex;
    gap: 10px;
    margin-top: 12px;
    flex-wrap: wrap;
    justify-content: center;
}

.quick-action {
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: 1px solid var(--border);
    border-radius: 20px;
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.2s;
}

.quick-action:hover {
    border-color: var(--accent);
    color: var(--accent);
    background: var(--accent-glow);
}

.quick-action .icon { font-size: 14px; }

.chat-messages {
    flex: 1;
    padding: 24px;
    display: none;
    flex-direction: column;
    gap: 24px;
    max-width: 800px;
    margin: 0 auto;
    width: 100%;
}

.chat-messages.active { display: flex; }

.message {
    display: flex;
    gap: 12px;
    animation: fadeIn 0.3s ease;
}

/* user messages on the right */
.message.user {
    flex-direction: row-reverse;
}

.message.user .message-content {
    background: #1a3a5c;
    border-radius: 18px 18px 4px 18px;
    padding: 10px 14px;
    max-width: 78%;
    border: 1px solid rgba(59,130,246,0.2);
    color: #e2e8f0;
}

@keyframes fadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: translateY(0); }
}

.message-avatar {
    width: 32px;
    height: 32px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    flex-shrink: 0;
}

.message.user .message-avatar {
    background: #3b82f6;
}

.message.assistant .message-avatar {
    background: var(--accent);
}

.message-content {
    flex: 1;
    line-height: 1.7;
    font-size: 14px;
}

.message.user .message-content {
    color: var(--text-primary);
}

.message.assistant .message-content {
    color: var(--text-secondary);
}

.message-content pre {
    background: var(--input-bg);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 14px;
    margin: 10px 0;
    overflow-x: auto;
    font-size: 13px;
    line-height: 1.5;
}

.message-content code {
    font-family: 'SF Mono', 'Fira Code', 'Cascadia Code', monospace;
    background: var(--input-bg);
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 13px;
}

.message-content pre code {
    background: none;
    padding: 0;
}

.typing-indicator {
    display: flex;
    gap: 4px;
    padding: 4px 0;
}

.typing-indicator span {
    width: 6px;
    height: 6px;
    border-radius: 50%;
    background: var(--accent);
    animation: typing 1.4s infinite;
}

.typing-indicator span:nth-child(2) { animation-delay: 0.2s; }
.typing-indicator span:nth-child(3) { animation-delay: 0.4s; }

@keyframes typing {
    0%, 60%, 100% { opacity: 0.3; transform: translateY(0); }
    30% { opacity: 1; transform: translateY(-4px); }
}

.input-area {
    padding: 16px 24px 24px;
    background: var(--bg-primary);
}

.input-container {
    max-width: 800px;
    margin: 0 auto;
    display: flex;
    align-items: flex-end;
    gap: 10px;
    background: var(--bg-secondary);
    border: 1px solid var(--border);
    border-radius: 14px;
    padding: 4px 4px 4px 16px;
    transition: border-color 0.2s;
}

.input-container:focus-within {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
}

.chat-input {
    flex: 1;
    background: transparent;
    border: none;
    color: var(--text-primary);
    font-size: 14px;
    padding: 10px 0;
    resize: none;
    outline: none;
    font-family: inherit;
    line-height: 1.5;
    max-height: 150px;
}

.chat-input::placeholder {
    color: var(--text-muted);
}

.send-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: var(--accent);
    border: none;
    color: white;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.send-btn:hover { background: var(--accent-dark); transform: scale(1.05); }
.send-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.send-btn svg {
    width: 18px;
    height: 18px;
}

.model-badge {
    text-align: center;
    padding: 6px 0 0;
    font-size: 12px;
    color: var(--text-muted);
}

.model-badge span {
    color: var(--accent);
    font-weight: 500;
}

/* ── Copy button on code blocks ── */
.code-block-wrap {
    position: relative;
    margin: 10px 0;
}

.code-block-wrap pre {
    margin: 0;
    padding-top: 36px !important;
}

.code-lang-label {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    padding: 5px 12px;
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(255,255,255,0.04);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-radius: 8px 8px 0 0;
}

.copy-btn {
    font-size: 11px;
    padding: 2px 8px;
    border-radius: 5px;
    background: rgba(255,255,255,0.06);
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    transition: all 0.15s;
}

.copy-btn:hover { background: rgba(255,255,255,0.12); color: var(--text-primary); }
.copy-btn.copied { color: var(--accent); border-color: var(--accent); }

/* ── Syntax highlighting ── */
.sh-keyword  { color: #60a5fa; }
.sh-string   { color: #a3e635; }
.sh-comment  { color: #4b5563; font-style: italic; }
.sh-number   { color: #f97316; }
.sh-function { color: #c084fc; }
.sh-builtin  { color: #2dd4a8; }
.sh-operator { color: #fb923c; }

/* ── Voice input button ── */
.voice-btn {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    background: transparent;
    border: 1px solid var(--border);
    color: var(--text-muted);
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    flex-shrink: 0;
}

.voice-btn:hover { border-color: var(--accent); color: var(--accent); }

.voice-btn.recording {
    border-color: #ef4444;
    color: #ef4444;
    animation: pulse-mic 1s infinite;
    background: rgba(239,68,68,0.08);
}

@keyframes pulse-mic {
    0%, 100% { box-shadow: 0 0 0 0 rgba(239,68,68,0.3); }
    50% { box-shadow: 0 0 0 6px rgba(239,68,68,0); }
}


/* ── Header controls ── */
.header-controls {
    display: flex;
    align-items: center;
    gap: 8px;
}

.clear-chat-btn {
    padding: 6px 12px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-muted);
    font-size: 12px;
    cursor: pointer;
    transition: all 0.15s;
}

.clear-chat-btn:hover {
    border-color: #ef4444;
    color: #ef4444;
}


.quick-action.image-gen-action {
    border-color: #facc15;
    color: #facc15;
}
.quick-action.image-gen-action:hover {
    background: rgba(250, 204, 21, 0.1);
    border-color: #facc15;
    color: #facc15;
}

.dalle-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(250, 204, 21, 0.12);
    color: #facc15;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 6px;
}

.gen-image-container {
    margin: 14px 0;
    border-radius: 12px;
    overflow: hidden;
    border: 1px solid rgba(250, 204, 21, 0.3);
    background: #000;
    position: relative;
}

.gen-image-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: rgba(250, 204, 21, 0.08);
    border-bottom: 1px solid rgba(250, 204, 21, 0.2);
}

.gen-image-header .img-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #facc15;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.gen-image-header .img-controls {
    display: flex;
    gap: 6px;
}

.img-btn {
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid rgba(250, 204, 21, 0.4);
    background: transparent;
    color: #facc15;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    text-decoration: none;
}

.img-btn:hover {
    background: rgba(250, 204, 21, 0.12);
}

.img-btn.primary {
    background: #facc15;
    color: #0a0f1a;
    border-color: #facc15;
}

.img-btn.primary:hover {
    background: #eab308;
}

.gen-image-canvas {
    display: block;
    width: 100%;
    height: auto;
    max-height: 420px;
    object-fit: contain;
    background: #0a0a1a;
}

.gen-image-prompt {
    padding: 8px 14px;
    font-size: 11px;
    color: var(--text-muted);
    background: rgba(250, 204, 21, 0.04);
    border-top: 1px solid rgba(250, 204, 21, 0.1);
    font-style: italic;
}

.gen-image-progress {
    height: 3px;
    background: var(--bg-card);
    overflow: hidden;
    position: relative;
}

.gen-image-progress-bar {
    height: 100%;
    background: linear-gradient(90deg, #facc15, #f97316, #facc15);
    animation: imgProgress 2s ease-in-out;
    width: 100%;
}

@keyframes imgProgress {
    0% { width: 0%; }
    60% { width: 85%; }
    100% { width: 100%; }
}

.quick-action.game-builder-action {
    border-color: #f472b6;
    color: #f472b6;
}
.quick-action.game-builder-action:hover {
    background: rgba(244, 114, 182, 0.12);
    border-color: #f472b6;
    color: #f472b6;
}

.game-preview-container {
    margin: 14px 0;
    border: 1px solid #f472b6;
    border-radius: 12px;
    overflow: hidden;
    background: #000;
}

.game-preview-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 8px 14px;
    background: rgba(244, 114, 182, 0.1);
    border-bottom: 1px solid rgba(244, 114, 182, 0.25);
}

.game-preview-header .game-label {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 12px;
    font-weight: 600;
    color: #f472b6;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.game-preview-header .game-controls {
    display: flex;
    gap: 6px;
}

.game-btn {
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid rgba(244, 114, 182, 0.4);
    background: transparent;
    color: #f472b6;
    font-size: 11px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.game-btn:hover {
    background: rgba(244, 114, 182, 0.15);
}

.game-btn.primary {
    background: #f472b6;
    color: #0a0f1a;
    border-color: #f472b6;
}

.game-btn.primary:hover {
    background: #ec4899;
}

.game-preview-iframe {
    width: 100%;
    height: 420px;
    border: none;
    display: block;
}

.game-fullscreen-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.9);
    z-index: 1000;
    display: none;
    flex-direction: column;
}

.game-fullscreen-overlay.active { display: flex; }

.game-fullscreen-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 12px 20px;
    background: var(--bg-secondary);
    border-bottom: 1px solid var(--border);
}

.game-fullscreen-bar .game-title {
    font-size: 14px;
    font-weight: 600;
    color: #f472b6;
    display: flex;
    align-items: center;
    gap: 8px;
}

.game-fullscreen-close {
    padding: 6px 14px;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--bg-card);
    color: var(--text-primary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
}

.game-fullscreen-close:hover {
    border-color: #f472b6;
    color: #f472b6;
}

.game-fullscreen-frame {
    flex: 1;
    border: none;
    width: 100%;
    height: 100%;
}

.gemini-badge {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    background: rgba(244, 114, 182, 0.12);
    color: #f472b6;
    font-size: 11px;
    font-weight: 500;
    padding: 2px 8px;
    border-radius: 4px;
    margin-left: 6px;
}

/* ── Games Gallery ── */
.games-gallery {
    flex: 1;
    overflow-y: auto;
    padding: 28px 32px;
    background: var(--bg-primary);
    scrollbar-width: thin;
    scrollbar-color: var(--border) transparent;
}

.gallery-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
}

.gallery-title {
    font-size: 22px;
    font-weight: 700;
    color: var(--text-primary);
    margin-bottom: 4px;
}

.gallery-sub {
    font-size: 13px;
    color: var(--text-muted);
}

.gallery-back-btn {
    padding: 8px 16px;
    border-radius: 9px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 13px;
    cursor: pointer;
    transition: all 0.15s;
    white-space: nowrap;
}

.gallery-back-btn:hover {
    border-color: var(--accent);
    color: var(--accent);
}

.gallery-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 16px;
}

.game-card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 14px;
    overflow: hidden;
    transition: transform 0.15s, border-color 0.15s;
}

.game-card:hover {
    transform: translateY(-2px);
    border-color: #f472b6;
}

.game-card-thumb {
    height: 110px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 42px;
    position: relative;
}

.game-card-body {
    padding: 12px 14px 8px;
}

.game-card-name {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 3px;
}

.game-card-date {
    font-size: 11px;
    color: var(--text-muted);
}

.game-card-actions {
    display: flex;
    gap: 6px;
    padding: 8px 14px 12px;
}

.game-card-btn {
    flex: 1;
    padding: 7px 0;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: transparent;
    color: var(--text-secondary);
    font-size: 12px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
}

.game-card-btn:hover { background: rgba(255,255,255,0.06); color: var(--text-primary); }

.game-card-btn.play {
    background: rgba(244,114,182,0.12);
    border-color: rgba(244,114,182,0.3);
    color: #f472b6;
}

.game-card-btn.play:hover {
    background: rgba(244,114,182,0.22);
}

.game-card-btn.delete:hover {
    border-color: #ef4444;
    color: #ef4444;
}

.gallery-empty {
    text-align: center;
    padding: 80px 0;
    color: var(--text-secondary);
}

