/* Fire Agents OS — Idle Game Layout */

html, body {
    background: #020203;
    height: 100%;
    min-height: 100vh;
    min-height: 100dvh;
    overflow: hidden;
    overscroll-behavior: none;
}

/* ── Game Layout ─────────────────────────────────────────── */
#game-container {
    display: flex;
    height: calc(100vh - var(--app-header-height, 64px));
    height: calc(100dvh - var(--app-header-height, 64px));
    position: relative;
    min-height: 0;
    overflow: hidden;
}

#game-nav {
    width: 200px;
    flex: 0 0 200px;
    border-right: 1px solid var(--surface-glass-border);
    background: var(--bg-panel);
    display: flex;
    flex-direction: column;
    z-index: 10;
    min-height: 0;
    overflow-x: hidden;
    overflow-y: hidden;
    overscroll-behavior: contain;
}

.game-nav-primary,
.game-nav-secondary,
.game-nav-health,
.game-nav-brand {
    min-height: 0;
}

.game-nav-primary {
    padding: 16px 8px 8px;
    flex: 1 1 auto;
    overflow-y: auto;
}

.game-nav-secondary {
    padding: 12px 8px;
    border-top: 1px solid var(--surface-glass-border);
    flex: 0 0 auto;
}

.game-nav-health {
    padding: 12px;
    border-top: 1px solid var(--surface-glass-border);
    flex: 0 0 auto;
    max-height: clamp(96px, 24vh, 200px);
    overflow-y: auto;
}

.game-nav-brand {
    padding: 10px;
    border-top: 1px solid var(--surface-glass-border);
    flex: 0 0 auto;
    margin-top: auto;
}

#game-viewport {
    flex: 1;
    position: relative;
    overflow: hidden;
    background:
        radial-gradient(circle at top, rgba(26, 31, 40, 0.45), rgba(5, 5, 8, 0.96) 52%),
        #050508;
    min-width: 0;
    min-height: 0;
    isolation: isolate;
    touch-action: none;
}

#office-canvas {
    width: 100%;
    height: 100%;
    image-rendering: pixelated;
    image-rendering: crisp-edges;
    display: block;
    z-index: 10;
    position: relative;
}

#game-viewport > canvas:not(#office-canvas) {
    display: block;
    max-width: none;
    max-height: none;
    touch-action: none;
}

#chat-overlay,
.view-panel,
#agent-popup {
    touch-action: auto;
}

/* ── 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; }

/* Level Bar */
.hud-level {
    display: flex;
    align-items: center;
    gap: 8px;
    flex: 1;
    max-width: 320px;
}

.hud-level-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;
}

.hud-xp-bar {
    flex: 1;
    height: 8px;
    background: rgba(255,255,255,0.06);
    border-radius: 4px;
    overflow: hidden;
    border: 1px solid rgba(255,255,255,0.08);
}

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

.hud-xp-text {
    font-family: 'JetBrains Mono', monospace;
    font-size: 9px;
    color: var(--text-dim);
    white-space: nowrap;
}

/* Resources */
.hud-resources {
    display: flex;
    gap: 14px;
    align-items: center;
}

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

.hud-resource .icon {
    width: 14px;
    height: 14px;
    border-radius: 3px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 9px;
}

.res-essence .icon { background: rgba(0,229,255,0.2); color: #00e5ff; }
.res-essence .val { color: #00e5ff; }
.res-catalysts .icon { background: rgba(245,166,35,0.2); color: #f5a623; }
.res-catalysts .val { color: #f5a623; }
.res-prisms .icon { background: rgba(124,58,237,0.2); color: #7c3aed; }
.res-prisms .val { color: #7c3aed; }

/* Streak */
.hud-streak {
    display: flex;
    align-items: center;
    gap: 4px;
    font-family: 'JetBrains Mono', monospace;
    font-size: 11px;
    color: var(--warning-neon);
}

/* ── Chat Overlay ────────────────────────────────────────── */
#chat-overlay {
    position: absolute;
    bottom: max(16px, env(safe-area-inset-bottom));
    left: 16px;
    width: 380px;
    max-width: calc(100% - 32px);
    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;
    box-shadow: 0 18px 36px rgba(0, 0, 0, 0.35);
}

#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.xp { border-color: var(--primary-neon); }
.game-toast.levelup { border-color: var(--success-neon); color: var(--success-neon); font-size: 12px; font-weight: 700; }
.game-toast.achievement { border-color: #ffd700; }
.game-toast.unlock { border-color: var(--secondary-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); } }

/* ── Floating XP Text ────────────────────────────────────── */
.floating-xp {
    position: absolute;
    font-family: 'Outfit', sans-serif;
    font-weight: 800;
    font-size: 16px;
    color: var(--primary-neon);
    text-shadow: 0 0 8px rgba(0,229,255,0.5);
    animation: floatUp 1.5s ease forwards;
    pointer-events: none;
    z-index: 35;
}

@keyframes floatUp {
    0% { opacity: 1; transform: translateY(0) scale(1); }
    100% { opacity: 0; transform: translateY(-40px) scale(0.8); }
}

/* ── 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;
}

@media (min-width: 769px) and (max-height: 820px) {
    .game-nav-primary {
        padding: 10px 6px 6px;
    }

    .game-nav-item {
        margin: 1px 6px;
        padding: 8px 12px;
        font-size: 11px;
    }

    .game-nav-section {
        padding: 12px 12px 4px;
        font-size: 8px;
    }

    .game-nav-secondary {
        padding: 10px 6px;
    }

    .quick-cmd {
        padding: 6px 10px;
        font-size: 10px;
    }

    .game-nav-health {
        padding: 10px;
        max-height: clamp(84px, 18vh, 128px);
    }

    #agent-health-list {
        font-size: 9px !important;
        line-height: 1.45;
    }

    .game-nav-brand {
        padding: 8px;
    }
}

@media (max-width: 1360px) {
    #game-nav {
        width: 188px;
        flex-basis: 188px;
    }

    #chat-overlay {
        width: 360px;
    }
}

/* ── View Panels (Gallery, Quests, Mastery, Stats, Achievements) ── */
.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;
}

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

/* ── 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);
}

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

.gallery-filter {
    padding: 4px 12px;
    border-radius: 100px;
    font-size: 10px;
    font-family: 'JetBrains Mono', monospace;
    cursor: pointer;
    transition: var(--trans-fast);
    border: 1px solid var(--surface-glass-border);
    background: var(--surface-glass);
    color: var(--text-dim);
    outline: none;
}

.gallery-filter:hover {
    background: var(--surface-glass-hover);
    color: var(--text-secondary);
}

.gallery-filter.active {
    background: var(--primary-subtle);
    border-color: var(--primary-neon);
    color: var(--primary-neon);
}

/* ── Feeding Overlay ────────────────────────────────────────── */
#feeding-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    z-index: 9999;
    display: none;
    align-items: center;
    justify-content: center;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(12px);
    flex-direction: column;
}

/* ── Room Lock Overlay (canvas-rendered) ─────────────────── */
/* These are visual cues rendered on the canvas, not CSS */

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

/* ── Base Mobile Adjustments ─────────────────────────────── */
@media (max-width: 768px) {
    /* Compact viewport variables are defined in index.html so the header and shell stay in sync */

    /* Prevent zoom on input focus */
    input, textarea, select {
        font-size: 16px !important;
    }

    /* Larger touch targets */
    button, .action-btn, .quick-cmd, .game-nav-item, .gallery-filter {
        min-height: 44px;
        min-width: 44px;
    }

    /* ── Game Container Mobile ───────────────────────────── */
    #game-container {
        height: calc(100vh - var(--app-header-height, 56px));
        height: calc(100dvh - var(--app-header-height, 56px));
        flex-direction: column;
    }

    /* ── Game Nav as Slide-out Drawer ────────────────────── */
    #game-nav {
        position: fixed;
        top: var(--app-header-height, 56px);
        left: calc(-1 * var(--game-nav-drawer-width, min(280px, 84vw)));
        width: var(--game-nav-drawer-width, min(280px, 84vw));
        height: calc(100vh - var(--app-header-height, 56px));
        height: calc(100dvh - var(--app-header-height, 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: hidden;
    }

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

    /* Nav overlay when open */
    #nav-overlay {
        display: none;
        position: fixed;
        top: var(--app-header-height, 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-nav-item i {
        width: 18px !important;
    }

    .game-nav-section {
        padding: 20px 20px 8px;
        font-size: 10px;
    }

    .quick-cmd {
        padding: 10px 16px;
        font-size: 12px;
    }

    /* ── Viewport Mobile ─────────────────────────────────── */
    #game-viewport {
        width: 100%;
    }

    #office-canvas {
        width: 100vw;
        height: calc(100vh - var(--app-header-height, 56px));
        height: calc(100dvh - var(--app-header-height, 56px));
    }

    /* ── HUD Mobile ──────────────────────────────────────── */
    #game-hud {
        height: 40px;
        padding: 0 10px;
        gap: 8px;
        flex-wrap: wrap;
    }

    .hud-level {
        max-width: 100%;
        flex: 1;
    }

    .hud-level-badge {
        padding: 2px 8px;
        font-size: 10px;
    }

    .hud-xp-bar {
        height: 6px;
    }

    .hud-xp-text {
        font-size: 8px;
    }

    .hud-resources {
        gap: 8px;
    }

    .hud-resource {
        font-size: 10px;
    }

    .hud-resource .icon {
        width: 12px;
        height: 12px;
    }

    .hud-streak {
        font-size: 10px;
    }

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

    #chat-overlay-header {
        padding: 12px 14px;
    }

    #chat-overlay-header .label {
        font-size: 11px;
    }

    #chat-messages-overlay {
        padding: 10px 14px;
        gap: 8px;
    }

    #chat-messages-overlay .msg {
        font-size: 12px;
        padding: 8px 12px;
        max-width: 95%;
    }

    #chat-input-overlay {
        padding: 10px;
        gap: 8px;
    }

    #chat-input-overlay input {
        padding: 10px 14px;
        font-size: 16px;
    }

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

    /* ── Toasts Mobile ───────────────────────────────────── */
    #game-toasts {
        top: 48px;
        right: 8px;
        left: 8px;
    }

    .game-toast {
        padding: 12px 16px;
        font-size: 12px;
    }

    /* ── View Panels Mobile ──────────────────────────────── */
    .view-panel {
        padding: 16px 12px;
        padding-top: env(safe-area-inset-top, 16px);
        padding-bottom: env(safe-area-inset-bottom, 16px);
    }

    .view-panel h2 {
        font-size: 18px !important;
    }

    /* ── Gallery Mobile ──────────────────────────────────── */
    #gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(140px, 1fr)) !important;
        gap: 8px !important;
    }

    .gallery-item-card img,
    .gallery-item-card video {
        height: 100px !important;
    }

    /* ── Stats Mobile ────────────────────────────────────── */
    #stats-content > div:first-child {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    .stat-card {
        padding: 12px !important;
    }

    .stat-card > div:first-child {
        font-size: 20px !important;
    }

    /* ── Quests Mobile ───────────────────────────────────── */
    #quests-daily,
    #quests-weekly,
    #quests-epic {
        gap: 10px !important;
    }

    /* ── Approvals Mobile ────────────────────────────────── */
    #approvals-stats {
        grid-template-columns: repeat(2, 1fr) !important;
        gap: 8px !important;
    }

    /* ── Achievements Mobile ─────────────────────────────── */
    #achievements-grid {
        grid-template-columns: 1fr !important;
        gap: 10px !important;
    }

    /* ── Feeding Overlay Mobile ──────────────────────────── */
    #feeding-stage {
        width: 90vw !important;
        height: 300px !important;
    }

    #feeding-status {
        font-size: 18px !important;
        padding: 0 16px;
        text-align: center;
    }

    #feeding-progress {
        width: 80vw !important;
        height: 10px !important;
    }

    /* ── Agent Popup Mobile ──────────────────────────────── */
    #agent-popup {
        width: 240px !important;
        font-size: 11px !important;
    }

    /* ── Floating XP Mobile ──────────────────────────────── */
    .floating-xp {
        font-size: 14px !important;
    }
}

/* ── Small Mobile (phones < 480px) ───────────────────────── */
@media (max-width: 480px) {
    #game-container {
        height: calc(100vh - var(--app-header-height, 50px));
        height: calc(100dvh - var(--app-header-height, 50px));
    }

    #game-nav {
        top: var(--app-header-height, 50px);
        left: calc(-1 * var(--game-nav-drawer-width, min(260px, 86vw)));
        width: var(--game-nav-drawer-width, min(260px, 86vw));
        height: calc(100vh - var(--app-header-height, 50px));
        height: calc(100dvh - var(--app-header-height, 50px));
    }

    #nav-overlay {
        top: var(--app-header-height, 50px);
    }

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

    .hud-level-badge {
        font-size: 9px;
        padding: 1px 6px;
    }

    .hud-xp-bar {
        height: 5px;
    }

    .hud-resources {
        gap: 6px;
    }

    .hud-resource {
        font-size: 9px;
    }

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

    #gallery-grid {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    #stats-content > div:first-child {
        grid-template-columns: repeat(2, 1fr) !important;
    }

    #feeding-stage {
        height: 250px !important;
    }

    #feeding-status {
        font-size: 16px !important;
    }
}

/* ── Landscape Mobile ────────────────────────────────────── */
@media (max-height: 500px) and (orientation: landscape) {
    #game-container {
        height: calc(100vh - var(--app-header-height, 40px));
        height: calc(100dvh - var(--app-header-height, 40px));
    }

    #game-nav {
        top: var(--app-header-height, 40px);
        height: calc(100vh - var(--app-header-height, 40px));
        height: calc(100dvh - var(--app-header-height, 40px));
        width: var(--game-nav-drawer-width, min(220px, 76vw));
    }

    #game-hud {
        height: 32px;
    }

    .hud-level {
        max-width: 200px;
    }

    #chat-overlay {
        max-height: 60vh;
        width: 300px;
    }

    #feeding-stage {
        height: 200px !important;
    }
}

/* ── Compact Tablet + Mobile Shell (≤ 1100px) ───────────── */
@media (max-width: 1100px) {
    #game-container {
        flex-direction: column;
    }

    #game-nav {
        position: fixed;
        top: var(--app-header-height, 60px);
        left: calc(-1 * var(--game-nav-drawer-width, min(320px, 82vw)));
        width: var(--game-nav-drawer-width, min(320px, 82vw));
        height: calc(100vh - var(--app-header-height, 60px));
        height: calc(100dvh - var(--app-header-height, 60px));
        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: hidden;
    }

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

    #nav-overlay {
        display: none;
        position: fixed;
        top: var(--app-header-height, 60px);
        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: 12px 18px;
        font-size: 13px;
        margin: 2px 10px;
    }

    .game-nav-section {
        padding: 18px 18px 8px;
        font-size: 10px;
    }

    .quick-cmd {
        padding: 8px 12px;
        font-size: 11px;
    }

    #game-hud {
        height: auto;
        min-height: 48px;
        padding: 8px 14px 10px;
        gap: 8px 12px;
        display: grid;
        grid-template-columns: minmax(0, 1fr) auto;
        align-content: start;
    }

    .hud-level {
        grid-column: 1 / -1;
        max-width: none;
    }

    .hud-resources {
        grid-column: 1 / 2;
        min-width: 0;
        overflow-x: auto;
        padding-bottom: 2px;
        scrollbar-width: thin;
    }

    .hud-streak {
        grid-column: 2 / 3;
        justify-self: end;
        white-space: nowrap;
    }

    #chat-overlay {
        width: min(420px, calc(100vw - 32px));
        left: 16px;
        right: auto;
        bottom: max(16px, env(safe-area-inset-bottom));
        max-height: min(360px, 42vh);
    }

    #game-toasts {
        top: 72px;
        right: 12px;
        max-width: min(380px, calc(100vw - 24px));
    }

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

    #agent-popup {
        max-width: min(320px, calc(100vw - 32px));
    }

    #gallery-grid {
        grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
    }
}

/* ── Safe Area Support (notch devices) ───────────────────── */
@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));
        }

        .view-panel {
            padding-left: max(12px, env(safe-area-inset-left));
            padding-right: max(12px, env(safe-area-inset-right));
            padding-bottom: max(16px, env(safe-area-inset-bottom));
        }
    }
}

/* ── Touch Optimization ──────────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
    /* Remove hover effects on touch devices */
    .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);
    }

    /* Active state feedback */
    .gallery-item-card:active {
        transform: scale(0.97);
        transition: transform 0.1s ease;
    }
}
