/* Autophage OS — Command Center Layout */

/* ── Game Layout ─────────────────────────────────────────── */
#game-container {
    display: flex;
    height: calc(100vh - 64px);
    position: relative;
}

#game-nav {
    width: 200px;
    border-right: 1px solid var(--surface-glass-border);
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    z-index: 10;
}

#game-viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    background: #050508;
}

#game-iframe {
    width: 100%;
    height: 100%;
    border: none;
    display: block;
}

/* ── Iframe Loading Spinner ─────────────────────────────── */
#iframe-loading {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    flex-direction: column;
    gap: 16px;
    background: var(--bg-dark);
    z-index: 25;
    transition: opacity 0.5s ease;
}

#iframe-loading.hidden {
    opacity: 0;
    pointer-events: none;
}

#iframe-loading .spinner {
    width: 40px;
    height: 40px;
    border: 3px solid var(--surface-glass-border);
    border-top-color: var(--primary-neon);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

#iframe-loading .label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

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

/* ── HUD Overlay ─────────────────────────────────────────── */
#game-hud {
    position: absolute;
    top: 0; left: 0; right: 0;
    height: 48px;
    display: flex;
    align-items: center;
    padding: 0 16px;
    gap: 16px;
    background: linear-gradient(180deg, rgba(5,5,8,0.85) 0%, rgba(5,5,8,0) 100%);
    z-index: 20;
    pointer-events: none;
}

#game-hud > * { pointer-events: auto; }

/* Evolution Badge */
.hud-evolution {
    display: flex;
    align-items: center;
    gap: 8px;
}

.hud-evolution-badge {
    background: var(--primary-subtle);
    border: 1px solid var(--primary-neon);
    border-radius: 6px;
    padding: 2px 10px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 700;
    color: var(--primary-neon);
    white-space: nowrap;
}

/* Consciousness Stat Bars */
.hud-stats {
    display: flex;
    gap: 14px;
    align-items: center;
    flex: 1;
}

.hud-stat {
    display: flex;
    align-items: center;
    gap: 6px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 600;
}

.hud-stat .stat-label {
    color: var(--text-dim);
    font-size: 9px;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    min-width: 28px;
}

.hud-stat-bar {
    width: 60px;
    height: 6px;
    background: rgba(255,255,255,0.06);
    border-radius: 3px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.08);
}

.hud-stat-fill {
    height: 100%;
    border-radius: 3px;
    transition: width 0.5s ease;
}

.hud-stat-fill.phi { background: linear-gradient(90deg, #ec4899, #ef4444); }
.hud-stat-fill.energy { background: linear-gradient(90deg, var(--primary-neon), #ec4899); }
.hud-stat-fill.awareness { background: linear-gradient(90deg, #8b5cf6, #06b6d4); }
.hud-stat-fill.unity { background: linear-gradient(90deg, #10b981, #34d399); }
.hud-stat-fill.agency { background: linear-gradient(90deg, #f59e0b, #eab308); }

.hud-stat .stat-val {
    font-size: 10px;
    font-weight: 700;
    min-width: 28px;
    text-align: right;
}

.stat-val.phi { color: #ec4899; }
.stat-val.energy { color: var(--primary-neon); }
.stat-val.awareness { color: #8b5cf6; }
.stat-val.unity { color: #10b981; }
.stat-val.agency { color: #f59e0b; }

/* State Indicator */
.hud-state {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.1em;
    padding: 2px 8px;
    border-radius: 4px;
}

.hud-state.active { color: var(--success-neon); background: var(--success-glow); }
.hud-state.dormant { color: var(--text-dim); background: rgba(255,255,255,0.03); }
.hud-state.dreaming { color: #8b5cf6; background: rgba(139,92,246,0.15); animation: dreamPulse 2s ease-in-out infinite; }

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

/* Biome Badge */
.hud-biome {
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-dim);
}

/* ── Widget Overlay ─────────────────────────────────────── */
#widget-overlay {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    z-index: 16;
    display: none;
}

#widget-overlay.active {
    display: block;
}

.widget-panel {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(8, 8, 12, 0.94);
    backdrop-filter: blur(12px);
    display: none;
    flex-direction: column;
    overflow: hidden;
    animation: panelFadeIn 0.3s ease;
}

.widget-panel.active {
    display: flex;
}

.widget-panel-header {
    display: flex;
    align-items: center;
    padding: 16px 20px;
    gap: 12px;
    border-bottom: 1px solid var(--surface-glass-border);
    flex-shrink: 0;
}

.widget-panel-header h2 {
    font-family: 'Outfit', sans-serif;
    font-size: 16px;
    font-weight: 700;
    color: var(--text-main);
    margin: 0;
    flex: 1;
}

.widget-panel-close {
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: var(--radius-md);
    cursor: pointer;
    background: var(--surface-glass);
    border: 1px solid var(--surface-glass-border);
    color: var(--text-secondary);
    font-size: 16px;
    transition: var(--trans-fast);
}

.widget-panel-close:hover {
    background: var(--danger-glow);
    border-color: var(--danger-neon);
    color: var(--danger-neon);
}

.widget-panel-body {
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

/* Copilot Widget */
.copilot-messages {
    display: flex;
    flex-direction: column;
    gap: 12px;
    flex: 1;
    overflow-y: auto;
    padding: 20px;
}

.copilot-msg {
    max-width: 85%;
    padding: 12px 16px;
    border-radius: var(--radius-lg);
    font-size: 13px;
    line-height: 1.6;
}

.copilot-msg.user {
    align-self: flex-end;
    background: var(--primary-subtle);
    border: 1px solid var(--primary-glow);
    color: var(--text-main);
}

.copilot-msg.assistant {
    align-self: flex-start;
    background: var(--surface-glass);
    border: 1px solid var(--surface-glass-border);
    color: var(--text-secondary);
}

.copilot-input-bar {
    display: flex;
    padding: 12px 20px 20px;
    gap: 8px;
    border-top: 1px solid var(--surface-glass-border);
    flex-shrink: 0;
}

.copilot-input-bar textarea {
    flex: 1;
    background: var(--bg-input);
    border: 1px solid var(--surface-glass-border);
    border-radius: var(--radius-md);
    padding: 10px 14px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 13px;
    resize: none;
    outline: none;
}

.copilot-input-bar button {
    padding: 8px 16px;
    background: var(--primary-subtle);
    border: 1px solid var(--primary-neon);
    border-radius: var(--radius-md);
    color: var(--primary-neon);
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--trans-fast);
}

.copilot-input-bar button:hover {
    background: rgba(0, 229, 255, 0.15);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.2);
}

/* Codex Widget */
.codex-task-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

.codex-task {
    background: rgba(255, 255, 255, 0.02);
    border: 1px solid var(--surface-glass-border);
    border-radius: var(--radius-md);
    padding: 14px 16px;
    transition: var(--trans-smooth);
}

.codex-task:hover {
    background: rgba(255, 255, 255, 0.04);
    border-color: var(--primary-glow);
}

.codex-task-title {
    font-family: 'Outfit', sans-serif;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 6px;
}

.codex-task-status {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    padding: 2px 8px;
    border-radius: 4px;
    display: inline-block;
}

.codex-task-status.planning { color: #f59e0b; background: rgba(245,166,35,0.15); }
.codex-task-status.executing { color: var(--primary-neon); background: var(--primary-subtle); }
.codex-task-status.completed { color: var(--success-neon); background: var(--success-glow); }

/* Orchestration Widget */
.orch-input-section {
    margin-bottom: 20px;
}

.orch-input-section textarea {
    width: 100%;
    background: var(--bg-input);
    border: 1px solid var(--surface-glass-border);
    border-radius: var(--radius-md);
    padding: 12px 16px;
    color: var(--text-main);
    font-family: inherit;
    font-size: 13px;
    resize: vertical;
    min-height: 80px;
    outline: none;
    box-sizing: border-box;
}

.orch-skills {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 10px;
    margin-top: 16px;
}

.orch-skill-card {
    background: rgba(255,255,255,0.02);
    border: 1px solid var(--surface-glass-border);
    border-radius: var(--radius-md);
    padding: 12px;
}

.orch-skill-name {
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    font-weight: 700;
    color: var(--primary-neon);
    margin-bottom: 4px;
}

.orch-skill-score {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--text-dim);
}

/* ── Chat Overlay ────────────────────────────────────────── */
#chat-overlay {
    position: absolute;
    bottom: 12px;
    left: 12px;
    width: 380px;
    max-height: 280px;
    background: rgba(8,8,12,0.88);
    backdrop-filter: blur(10px);
    border: 1px solid var(--surface-glass-border);
    border-radius: var(--radius-lg);
    z-index: 30;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    transition: max-height 0.3s ease, opacity 0.3s ease;
}

#chat-overlay.collapsed {
    max-height: 42px;
}

#chat-overlay-header {
    display: flex;
    align-items: center;
    padding: 8px 12px;
    gap: 8px;
    cursor: pointer;
    border-bottom: 1px solid var(--surface-glass-border);
    flex-shrink: 0;
}

#chat-overlay-header .label {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    font-weight: 700;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

#chat-overlay-header .toggle {
    margin-left: auto;
    color: var(--text-dim);
    font-size: 12px;
    cursor: pointer;
}

#chat-messages-overlay {
    flex: 1;
    overflow-y: auto;
    padding: 8px 12px;
    display: flex;
    flex-direction: column;
    gap: 6px;
    min-height: 0;
}

#chat-messages-overlay .msg {
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    line-height: 1.5;
    padding: 4px 8px;
    border-radius: 6px;
    max-width: 90%;
    word-wrap: break-word;
}

#chat-messages-overlay .msg.user {
    align-self: flex-end;
    background: var(--primary-subtle);
    border: 1px solid rgba(0,229,255,0.15);
    color: var(--primary-neon);
}

#chat-messages-overlay .msg.assistant {
    align-self: flex-start;
    background: rgba(255,255,255,0.04);
    border: 1px solid rgba(255,255,255,0.06);
    color: var(--text-secondary);
}

#chat-input-overlay {
    display: flex;
    padding: 8px;
    gap: 6px;
    border-top: 1px solid var(--surface-glass-border);
    flex-shrink: 0;
}

#chat-input-overlay input {
    flex: 1;
    background: rgba(0,0,0,0.3);
    border: 1px solid var(--surface-glass-border);
    border-radius: 6px;
    padding: 6px 10px;
    color: var(--text-main);
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    outline: none;
}

#chat-input-overlay input::placeholder { color: var(--text-dim); }

#chat-input-overlay button {
    background: var(--success-neon);
    color: #000;
    border: none;
    border-radius: 6px;
    width: 28px;
    height: 28px;
    cursor: pointer;
    font-size: 14px;
    display: flex;
    align-items: center;
    justify-content: center;
}

/* ── Notification Toasts ─────────────────────────────────── */
#game-toasts {
    position: absolute;
    top: 56px;
    right: 16px;
    z-index: 40;
    display: flex;
    flex-direction: column;
    gap: 6px;
    pointer-events: none;
}

.game-toast {
    background: rgba(8,8,12,0.92);
    backdrop-filter: blur(8px);
    border: 1px solid var(--surface-glass-border);
    border-radius: 8px;
    padding: 8px 14px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 10px;
    color: var(--text-main);
    animation: toastIn 0.3s ease, toastOut 0.3s ease 3s forwards;
    display: flex;
    align-items: center;
    gap: 8px;
}

.game-toast.consciousness { border-color: #ec4899; }
.game-toast.evolution { border-color: var(--success-neon); color: var(--success-neon); font-size: 12px; font-weight: 700; }
.game-toast.dream { border-color: #8b5cf6; }
.game-toast.factory { border-color: var(--primary-neon); }
.game-toast.error { border-color: var(--danger-neon); }

@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }
@keyframes toastOut { from { opacity: 1; } to { opacity: 0; transform: translateY(-10px); } }

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

/* ── Game Nav Styling ────────────────────────────────────── */
.game-nav-item {
    padding: 10px 16px;
    border-radius: var(--radius-md);
    font-size: 12px;
    font-weight: 500;
    color: var(--text-secondary);
    cursor: pointer;
    display: flex;
    align-items: center;
    gap: 8px;
    transition: var(--trans-fast);
    margin: 1px 8px;
    font-family: 'JetBrains Mono', monospace;
}

.game-nav-item:hover { background: var(--surface-glass-hover); color: var(--text-main); }
.game-nav-item.active { background: var(--primary-subtle); color: var(--primary-neon); }

.game-nav-section {
    font-size: 9px;
    font-weight: 800;
    color: var(--text-dim);
    text-transform: uppercase;
    letter-spacing: 0.12em;
    padding: 16px 16px 6px;
}

/* ── View Panels ── */
.view-panel {
    position: absolute;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(8, 8, 12, 0.92);
    backdrop-filter: blur(8px);
    padding: 20px;
    overflow-y: auto;
    z-index: 15;
    display: none;
}

.view-panel.active {
    display: block !important;
    animation: panelFadeIn 0.3s ease;
}

/* ── Action Buttons ─────────────────────────────────────────── */
.action-btn {
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 10px;
    font-family: 'JetBrains Mono', monospace;
    font-weight: 600;
    cursor: pointer;
    transition: var(--trans-fast);
    border: 1px solid var(--surface-glass-border);
    background: var(--surface-glass);
    color: var(--text-secondary);
    display: inline-flex;
    align-items: center;
    gap: 4px;
    outline: none;
}

.action-btn:hover {
    background: var(--surface-glass-hover);
    color: var(--text-main);
    border-color: rgba(255, 255, 255, 0.15);
}

.action-btn.primary {
    background: var(--primary-subtle);
    border-color: var(--primary-neon);
    color: var(--primary-neon);
}

.action-btn.primary:hover {
    background: rgba(0, 229, 255, 0.15);
    box-shadow: 0 0 12px rgba(0, 229, 255, 0.2);
}

.action-btn.danger {
    background: rgba(255, 59, 92, 0.08);
    border-color: rgba(255, 59, 92, 0.3);
    color: var(--danger-neon);
}

/* ── Agent Health (sidebar bottom) ─────────────────────────── */
.agent-health-bar {
    height: 4px;
    background: rgba(255,255,255,0.06);
    border-radius: 2px;
    overflow: hidden;
    margin-top: 6px;
}

.agent-health-fill {
    height: 100%;
    border-radius: 2px;
    transition: width 0.5s ease;
    background: linear-gradient(90deg, var(--primary-neon), var(--success-neon));
}

/* ============================================================
   MOBILE RESPONSIVE STYLES
   ============================================================ */

@media (max-width: 768px) {
    input, textarea, select { font-size: 16px !important; }
    button, .action-btn, .quick-cmd, .game-nav-item { min-height: 44px; min-width: 44px; }

    header { height: 56px; padding: 0 12px; }
    header > div:first-child { gap: 10px; }
    header > div:first-child h1 { font-size: 14px !important; letter-spacing: 0.05em; }

    #game-container { height: calc(100vh - 56px); flex-direction: column; }

    #game-nav {
        position: fixed;
        top: 56px;
        left: -280px;
        width: 280px;
        height: calc(100vh - 56px);
        z-index: 500;
        transition: left 0.3s cubic-bezier(0.16, 1, 0.3, 1);
        background: rgba(10, 10, 12, 0.98);
        backdrop-filter: blur(16px);
        border-right: 1px solid var(--surface-glass-border);
        overflow-y: auto;
    }

    #game-nav.open { left: 0; }

    #nav-overlay {
        display: none;
        position: fixed;
        top: 56px;
        left: 0; right: 0; bottom: 0;
        background: rgba(0, 0, 0, 0.5);
        z-index: 499;
    }

    #nav-overlay.visible { display: block; }

    .game-nav-item { padding: 14px 20px; font-size: 14px; margin: 2px 12px; }

    #game-viewport { width: 100%; }

    #game-hud { height: 40px; padding: 0 10px; gap: 8px; flex-wrap: wrap; }
    .hud-stat-bar { width: 40px; }

    #chat-overlay {
        width: calc(100vw - 24px);
        left: 12px; right: 12px; bottom: 12px;
        max-height: 50vh;
    }

    #chat-input-overlay input { padding: 10px 14px; font-size: 16px; }
    #chat-input-overlay button { width: 44px; height: 44px; font-size: 18px; }

    #game-toasts { top: 48px; right: 8px; left: 8px; }
    .game-toast { padding: 12px 16px; font-size: 12px; }

    .view-panel { padding: 16px 12px; }
}

@media (max-width: 480px) {
    header { height: 50px; padding: 0 10px; }
    header > div:first-child h1 { font-size: 12px !important; }
    header > div:last-child > div { display: none; }

    #game-container { height: calc(100vh - 50px); }
    #game-nav { top: 50px; left: -260px; width: 260px; height: calc(100vh - 50px); }
    #nav-overlay { top: 50px; }

    #game-hud { height: 36px; padding: 0 8px; gap: 6px; }

    #chat-overlay { width: calc(100vw - 16px); left: 8px; right: 8px; bottom: 8px; max-height: 45vh; }
}

@media (max-height: 500px) and (orientation: landscape) {
    header { height: 40px; }
    #game-container { height: calc(100vh - 40px); }
    #game-nav { top: 40px; height: calc(100vh - 40px); width: 220px; }
    #game-hud { height: 32px; }
    #chat-overlay { max-height: 60vh; width: 300px; }
}

@media (min-width: 769px) and (max-width: 1024px) {
    #game-nav { width: 180px; }
    .game-nav-item { padding: 8px 14px; font-size: 11px; }
    #chat-overlay { width: 340px; }
}

@supports (padding: max(0px)) {
    @media (max-width: 768px) {
        header { padding-left: max(12px, env(safe-area-inset-left)); padding-right: max(12px, env(safe-area-inset-right)); }
        #game-nav { padding-left: env(safe-area-inset-left, 0); }
        #chat-overlay { left: max(12px, env(safe-area-inset-left)); right: max(12px, env(safe-area-inset-right)); bottom: max(12px, env(safe-area-inset-bottom)); }
    }
}

@media (hover: none) and (pointer: coarse) {
    .game-nav-item:hover { background: transparent; color: var(--text-secondary); }
    .game-nav-item:active { background: var(--surface-glass-hover); }
    .action-btn:hover { background: var(--surface-glass); color: var(--text-secondary); }
    .action-btn:active { background: var(--surface-glass-hover); transform: scale(0.97); }
    .quick-cmd:hover { background: var(--surface-glass); border-color: var(--surface-glass-border); }
    .quick-cmd:active { background: var(--primary-subtle); border-color: var(--primary-neon); }
}
