:root {
    --bg-color: #0a0a0a;
    --panel-bg: #141414;
    --header-bg: #1f1f1f;
    --border-color: #2a2a2a;
    --text-primary: #ffffff;
    --text-secondary: #777;
    --accent-color: #3498db;
    --deploy-color: #2ecc71;
    --danger-color: #e74c3c;
    --ink-green: #2ecc71;
    --canvas-bg: #2c2c2c;
}

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

body {
    font-family: 'Segoe UI', system-ui, -apple-system, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-primary);
    overflow: hidden;
    height: 100vh;
    height: -webkit-fill-available; /* Fixes iOS Safari height bugs */
    width: 100vw;
    padding-bottom: max(env(safe-area-inset-bottom), 10px);
}

#app-container { display: flex; height: 100%; width: 100%; }
#app-container.hidden {
    display: none !important;
}

#sandbox-container {
    flex: 0 0 400px;
    max-width: 400px;
    display: flex;
    flex-direction: column;
    background: var(--panel-bg);
    border-right: 2px solid var(--border-color);
    z-index: 10;
}

#arena-container {
    flex: 1;
    display: flex;
    flex-direction: column;
    background: var(--canvas-bg);
    position: relative;
}

#arena-view {
    flex: 1;
    position: relative;
    overflow: hidden;
}

.ui-header {
    height: 60px;
    padding: 0 15px;
    background: var(--header-bg);
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border-color);
}

.header-left h1 { font-size: 0.9rem; text-transform: uppercase; letter-spacing: 2px; font-weight: 800; }
.subtitle { font-size: 0.65rem; color: var(--text-secondary); text-transform: uppercase; }

#ink-budget-container { width: 100px; }
.label { font-size: 0.6rem; text-transform: uppercase; color: var(--text-secondary); display: block; margin-bottom: 3px; font-weight: bold; }
.progress-bar { width: 100%; height: 6px; background: #222; border-radius: 3px; overflow: hidden; border: 1px solid #333; }
#ink-budget-fill { height: 100%; width: 100%; background-color: var(--ink-green); transition: width 0.3s; }

.canvas-wrapper {
    flex: 1;
    position: relative;
    background: var(--canvas-bg);
    cursor: crosshair;
    overflow: hidden;
    touch-action: none; /* Prevent mobile scroll while drawing */
}

canvas { display: block; width: 100%; height: 100%; }

#symmetry-line {
    position: absolute;
    top: 0;
    left: 50%;
    width: 1px;
    height: 100%;
    background: rgba(255, 255, 255, 0.1);
    border-left: 1px dashed rgba(255, 255, 255, 0.2);
    pointer-events: none;
}

#game-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0,0,0,0.8);
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    z-index: 100;
    transition: opacity 1s ease;
}

#game-overlay h2 { font-size: 3rem; color: var(--danger-color); letter-spacing: 5px; margin-bottom: 10px; text-align: center; }
#game-overlay p { color: #888; font-weight: bold; text-transform: uppercase; }

.hidden { display: none !important; opacity: 0; pointer-events: none; }

#toolbar {
    padding: 12px;
    background: var(--header-bg);
    display: flex;
    flex-direction: column;
    gap: 10px;
    border-top: 1px solid var(--border-color);
    overflow-y: auto;
}

.tool-section { display: flex; flex-direction: column; gap: 5px; }
.section-label { font-size: 0.6rem; text-transform: uppercase; color: var(--text-secondary); font-weight: 800; }

.colors-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 6px;
    background: rgba(0,0,0,0.2);
    padding: 6px;
    border-radius: 6px;
}

.color-item { display: flex; align-items: center; gap: 8px; }
.color-btn { width: 20px; height: 20px; border-radius: 3px; border: 2px solid transparent; cursor: pointer; flex-shrink: 0; }
.color-btn.active { border-color: #fff; }
.color-btn[data-color="#FFFFFF"], .color-btn[data-color="#FFFF00"] { border-color: #444; }
.color-btn[data-color="#FFFFFF"].active, .color-btn[data-color="#FFFF00"].active { border-color: #fff; }
.color-tag { font-size: 0.65rem; color: var(--text-secondary); font-weight: 600; }

.tool-row { display: flex; gap: 6px; }

.size-btn {
    flex: 1;
    padding: 6px 0;
    background: #252525;
    color: white;
    border: 1px solid #333;
    border-radius: 4px;
    font-size: 0.7rem;
    cursor: pointer;
}

.size-btn.active { background: var(--accent-color); border-color: transparent; }

.slots-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    gap: 4px;
}

.slot-btn {
    padding: 5px 0;
    background: #252525;
    color: #888;
    border: 1px solid #333;
    border-radius: 4px;
    font-size: 0.55rem;
    cursor: pointer;
    text-align: center;
}

.slot-btn.predefined { color: #fff; background: #333; font-weight: bold; }
.slot-btn.filled { color: var(--accent-color); border-color: var(--accent-color); }
.slot-btn:hover { background: #3a3a3a; }

.icon-btn { flex: 1; padding: 8px 0; background: #252525; border-radius: 6px; font-size: 1rem; border: 1px solid #333; cursor: pointer; color: white; }
.icon-btn.active { background: #333; border-color: var(--accent-color); }

.mini-btn { flex: 1; font-size: 0.6rem; padding: 6px 0; background: #252525; color: white; border: 1px solid #333; border-radius: 4px; cursor: pointer; }
.mini-btn.danger { border-color: var(--danger-color); color: var(--danger-color); }

/* ─── Editing Mode Toggle ─── */
.edit-mode-toggle { display: flex; gap: 0; border-radius: 6px; overflow: hidden; border: 1px solid #333; }
.mode-btn {
    flex: 1; padding: 8px 0; background: #252525; color: #888;
    border: none; font-size: 0.7rem; font-weight: 700; cursor: pointer;
    text-transform: uppercase; letter-spacing: 1px; transition: all 0.2s;
}
.mode-btn.active { background: var(--accent-color); color: #fff; }
.mode-btn.enemy.active { background: var(--danger-color); color: #fff; }

.mode-btn.map.active { background: #8e44ad; color: #fff; }

/* Canvas enemy-mode tint */
.canvas-wrapper.enemy-mode { box-shadow: inset 0 0 30px rgba(231, 76, 60, 0.25); }
.canvas-wrapper.map-mode { box-shadow: inset 0 0 30px rgba(142, 68, 173, 0.3); cursor: crosshair; }

/* Map editor tool buttons */
.map-tool-btn {
    flex: 1; padding: 6px 4px; background: #252525; color: #aaa;
    border: 1px solid #333; border-radius: 4px; font-size: 0.55rem;
    cursor: pointer; text-align: center; font-weight: 600;
}
.map-tool-btn.active { background: #8e44ad; color: #fff; border-color: #8e44ad; }
.map-tool-btn:hover { background: #3a3a3a; }
.map-data-btn { background: #1a3a2a; border-color: #2ecc71; color: #2ecc71; font-weight: 700; }

.arena-header-buttons { display: flex; gap: 6px; align-items: center; }
#mode-selector { background: #252525; color: #fff; border: 1px solid #444; border-radius: 4px; padding: 4px 8px; font-size: 0.65rem; cursor: pointer; }

.deploy-hint { font-size: 0.5rem; color: var(--text-secondary); font-style: italic; margin-top: 2px; }

.primary-btn { width: 100%; padding: 12px; background: var(--deploy-color); color: #000; font-weight: 900; letter-spacing: 1px; border: none; border-radius: 8px; cursor: pointer; text-transform: uppercase; }
.primary-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ─── Deploy Strip (always visible between canvas and toolbar) ─── */
#deploy-strip {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 12px;
    background: var(--header-bg);
    border-top: 1px solid var(--border-color);
    border-bottom: 1px solid var(--border-color);
    flex-shrink: 0; /* never squished by flex */
}

#deploy-strip #deploy-btn {
    flex: 0 0 auto;
    width: auto;
    padding: 8px 16px;
    font-size: 0.7rem;
    margin: 0;
}

#deploy-strip #deploy-checklist {
    display: flex;
    flex-direction: row;
    gap: 8px;
    flex: 1;
    background: none;
    padding: 0;
}

#deploy-strip .check-item {
    font-size: 0.55rem;
    white-space: nowrap;
    color: var(--danger-color);
    font-weight: 700;
    transition: color 0.2s;
}

#deploy-strip .check-item.met { color: var(--deploy-color); }

/* ─── Community Feed ─── */
.mode-btn.community.active { background: #27ae60; color: #fff; }
.canvas-wrapper.community-mode { box-shadow: inset 0 0 30px rgba(39, 174, 96, 0.2); }

.community-bot-list {
    max-height: 280px;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 4px;
    background: rgba(0,0,0,0.2);
    border-radius: 6px;
}

.community-bot-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: #1a1a1a;
    border: 1px solid #333;
    border-radius: 6px;
}

.community-bot-card canvas {
    width: 48px !important;
    height: 48px !important;
    border: 1px solid #444;
    border-radius: 3px;
    background: var(--canvas-bg);
    flex-shrink: 0;
}

.community-bot-info {
    flex: 1;
    min-width: 0;
}

.community-bot-info .bot-name {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.community-bot-info .bot-creator {
    font-size: 0.6rem;
    color: var(--text-secondary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.community-bot-info .bot-date {
    font-size: 0.5rem;
    color: #555;
}

.community-bot-card .load-enemy-btn {
    flex-shrink: 0;
    padding: 4px 8px;
    background: var(--danger-color);
    color: #fff;
    border: none;
    border-radius: 4px;
    font-size: 0.55rem;
    font-weight: 700;
    cursor: pointer;
    text-transform: uppercase;
}

.community-bot-card .load-enemy-btn:hover { background: #c0392b; }

.feed-loading, .feed-empty {
    text-align: center;
    padding: 20px 0;
    font-size: 0.6rem;
    color: var(--text-secondary);
}

/* ─── Auth & Cloud Publishing ─── */
#auth-section { display: flex; align-items: center; gap: 6px; }
#auth-section .mini-btn { flex: none; padding: 4px 10px; font-size: 0.55rem; }
#user-display { font-size: 0.6rem; color: var(--text-secondary); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 90px; }
#publish-bot-btn { font-size: 0.65rem; padding: 10px; letter-spacing: 0.5px; }
#publish-bot-btn:disabled { opacity: 0.35; cursor: not-allowed; }

/* ─── Mobile Panel Handle (hidden on desktop) ─── */
.panel-handle { display: none; }

@media (max-width: 768px) {
    /* Stack layout: arena on top, panel slides up from bottom */
    #app-container { flex-direction: column; }

    #arena-container {
        position: fixed;
        top: 0; left: 0;
        width: 100vw;
        height: 100vh;
        z-index: 1;
    }

    #sandbox-container {
        position: fixed;
        bottom: 0; left: 0;
        width: 100%;
        max-width: 100vw;
        height: 85vh;
        max-height: 85vh;
        transform: translateY(calc(100% - 96px)); /* show handle (52px) + deploy strip (~44px) */
        transition: transform 0.35s ease;
        z-index: 20;
        border-right: none;
        border-top: 2px solid var(--border-color);
        display: flex;
        flex-direction: column;
    }

    #sandbox-container.panel-open {
        transform: translateY(0);
    }

    /* Hide the header on mobile — handle replaces it */
    #sandbox-container .ui-header { display: none; }

    /* Reorder: handle first, then deploy strip, then rest of panel */
    .panel-handle { order: -2; }
    #deploy-strip { order: -1; }

    /* Show the handle bar on mobile */
    .panel-handle {
        display: flex;
        align-items: center;
        justify-content: space-between;
        padding: 0 16px;
        height: 52px;
        background: var(--header-bg);
        border-bottom: 1px solid var(--border-color);
        cursor: pointer;
        flex-shrink: 0;
    }

    .handle-bar {
        width: 36px; height: 4px;
        background: #444;
        border-radius: 2px;
        flex-shrink: 0;
    }

    #handle-label {
        font-size: 0.7rem;
        font-weight: 700;
        color: var(--text-secondary);
        text-transform: uppercase;
        letter-spacing: 1px;
    }

    .handle-toggle-btn {
        background: var(--deploy-color);
        color: #000;
        border: none;
        border-radius: 6px;
        padding: 6px 12px;
        font-size: 0.65rem;
        font-weight: 800;
        cursor: pointer;
        text-transform: uppercase;
    }

    /* Shrink the 4-tab mode toggle so it fits on narrow screens */
    .mode-btn {
        font-size: 0.55rem;
        letter-spacing: 0;
        padding: 8px 2px;
    }

    /* Community bot list gets more height on mobile */
    .community-bot-list { max-height: 45vh; }

    /* Arena header stays compact */
    #arena-container .ui-header {
        height: 50px;
        padding: 0 10px;
    }

    /* Safe area for notched phones */
    #sandbox-container {
        padding-bottom: max(env(safe-area-inset-bottom), 0px);
    }

    /* Deploy strip — compact, visible below handle when collapsed */
    #deploy-strip {
        padding: 6px 10px;
        gap: 6px;
        background: var(--header-bg);
        border-top: 1px solid var(--border-color);
        border-bottom: 1px solid var(--border-color);
        flex-shrink: 0;
    }
    #deploy-strip #deploy-checklist { display: none; } /* hide checklist on mobile — save space */
    #deploy-strip #deploy-btn { flex: 1; width: 100%; }

    /* Title screen must remain fullscreen on mobile — ensure no overrides */
    #title-screen {
        position: fixed !important;
        inset: 0 !important;
        z-index: 9999 !important;
        transform: none !important;
    }
}

/* ─── Landscape mobile: side-panel layout ─── */
/* Triggers on phones in landscape (short + wide screens) */
@media (max-width: 900px) and (max-height: 500px) {

    /* Switch from stacked to side-by-side */
    #app-container { flex-direction: row; }

    /* Panel becomes a left sidebar — no more bottom sheet */
    #sandbox-container {
        position: relative;
        transform: none !important;
        flex: 0 0 240px;
        max-width: 240px;
        width: 240px;
        height: 100vh;
        max-height: 100vh;
        border-right: 2px solid var(--border-color);
        border-top: none;
        z-index: 10;
        overflow: hidden;
    }

    /* Arena fills the rest of the screen */
    #arena-container {
        position: relative;
        flex: 1;
        height: 100vh;
        z-index: 1;
    }

    /* Restore the desktop header — no bottom sheet handle needed */
    #sandbox-container .ui-header {
        display: flex;
        height: 44px;
        padding: 0 10px;
    }

    /* Hide the drag handle — not needed in landscape */
    .panel-handle { display: none !important; }

    /* Deploy bar sits at very bottom of arena in landscape */
    #arena-deploy-bar {
        position: static;
        padding: 4px 10px;
    }

    /* Compact everything vertically to fit the short screen */
    #toolbar { gap: 5px; padding: 6px 8px; overflow-y: auto; }
    .colors-grid { gap: 3px; padding: 4px; grid-template-columns: repeat(4, 1fr); }
    .tool-section { gap: 3px; }
    .slot-btn { padding: 2px 0; font-size: 0.48rem; }
    .slots-grid { grid-template-columns: repeat(7, 1fr); }
    .mini-btn { padding: 4px 0; font-size: 0.52rem; }
    .primary-btn { padding: 7px; font-size: 0.65rem; }
    .mode-btn { font-size: 0.5rem; letter-spacing: 0; padding: 6px 1px; }
    .section-label { font-size: 0.5rem; }
    .color-tag { font-size: 0.55rem; }

    /* Canvas takes remaining space between header and toolbar */
    .canvas-wrapper { min-height: 60px; }

    /* Header left title compact */
    .header-left h1 { font-size: 0.7rem; letter-spacing: 1px; }
    .subtitle { font-size: 0.5rem; }

    /* Arena header compact */
    #arena-container .ui-header { height: 44px; padding: 0 8px; }
}

/* ═══ Title Screen ═══ */
#title-screen {
    position: fixed;
    inset: 0;
    z-index: 9999;
    background: radial-gradient(ellipse at 50% 30%, #1a1a2e 0%, #0a0a0a 70%);
    overflow-y: auto;
    display: flex !important;
    flex-direction: column;
    min-height: 100vh;
    min-height: -webkit-fill-available;
    width: 100vw;
    transition: opacity 0.4s ease;
}

#title-screen.fading { opacity: 0; pointer-events: none; }
#title-screen.hidden { display: none !important; opacity: 0; pointer-events: none; }

/* ─── Top auth bar ─── */
#title-topbar {
    width: 100%;
    padding: 10px 24px;
    padding-top: max(env(safe-area-inset-top), 10px);
    background: var(--header-bg);
    border-bottom: 1px solid var(--border-color);
    display: flex;
    justify-content: flex-end;
    align-items: center;
    flex-shrink: 0;
}

#title-auth-area {
    display: flex;
    align-items: center;
    gap: 10px;
}

.title-google-btn {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 7px 16px;
    background: #fff;
    color: #333;
    border: none;
    border-radius: 4px;
    font-size: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: box-shadow 0.15s;
}

.title-google-btn:hover { box-shadow: 0 2px 8px rgba(255,255,255,0.15); }
.title-google-btn svg { flex-shrink: 0; }

#title-signed-in {
    display: flex;
    align-items: center;
    gap: 10px;
}

#title-signed-in.hidden { display: none !important; }

#title-user-display {
    font-size: 0.75rem;
    color: var(--deploy-color);
    font-weight: 600;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

#title-logout-btn {
    padding: 5px 12px;
    background: transparent;
    color: var(--text-secondary);
    border: 1px solid #444;
    border-radius: 4px;
    font-size: 0.65rem;
    cursor: pointer;
}

#title-logout-btn:hover { border-color: var(--danger-color); color: var(--danger-color); }

/* ─── Hero section ─── */
#title-hero {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 40px 24px 20px;
}

#title-hero-inner {
    text-align: center;
    max-width: 560px;
    width: 100%;
}

#title-logo-wrap { margin-bottom: 16px; }

.title-logo {
    font-size: 3.8rem;
    font-weight: 900;
    letter-spacing: 10px;
    text-transform: uppercase;
    line-height: 1;
    background: linear-gradient(90deg, #3498db, #2ecc71, #f1c40f, #e74c3c);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.title-logo span {
    -webkit-text-fill-color: transparent; /* inherits gradient */
}

.title-tagline {
    font-size: 1rem;
    color: var(--text-secondary);
    margin-top: 6px;
    letter-spacing: 4px;
    text-transform: uppercase;
}

.title-description {
    font-size: 0.85rem;
    color: #999;
    line-height: 1.6;
    margin-bottom: 28px;
}

/* ─── Mode select + Play button ─── */
#title-play-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 12px;
    margin-bottom: 16px;
}

.title-mode-select {
    background: var(--header-bg);
    color: var(--text-primary);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 12px 18px;
    font-size: 0.85rem;
    cursor: pointer;
    min-width: 180px;
}

.title-play-btn {
    background: var(--deploy-color);
    color: #000;
    border: none;
    border-radius: 8px;
    padding: 12px 52px;
    font-size: 1.2rem;
    font-weight: 900;
    letter-spacing: 4px;
    text-transform: uppercase;
    cursor: pointer;
    transition: transform 0.15s, box-shadow 0.15s;
}

.title-play-btn:hover {
    transform: scale(1.05);
    box-shadow: 0 0 24px rgba(46, 204, 113, 0.45);
}

.title-howto-link {
    background: none;
    border: none;
    color: var(--accent-color);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: underline;
    text-underline-offset: 3px;
}

.title-howto-link:hover { color: #5dade2; }

/* ─── Bottom panels (news + community) ─── */
#title-bottom {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 16px;
    max-width: 800px;
    width: 100%;
    padding: 0 24px 24px;
    margin: 0 auto;
    flex-shrink: 0;
}

.title-panel {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 14px;
}

.title-panel h3 {
    font-size: 0.75rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--accent-color);
    margin-bottom: 10px;
    font-weight: 700;
}

.title-news-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.title-news-item {
    font-size: 0.7rem;
    color: var(--text-secondary);
    padding: 7px 8px;
    background: rgba(0,0,0,0.25);
    border-radius: 4px;
    line-height: 1.4;
}

.badge {
    display: inline-block;
    padding: 2px 6px;
    border-radius: 3px;
    font-size: 0.5rem;
    font-weight: 800;
    text-transform: uppercase;
    margin-right: 4px;
    vertical-align: middle;
}

.badge-new { background: var(--deploy-color); color: #000; }
.badge-update { background: var(--accent-color); color: #fff; }

#title-community-list {
    display: flex;
    flex-direction: column;
    gap: 6px;
    max-height: 220px;
    overflow-y: auto;
}

.title-feed-msg {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-align: center;
    padding: 16px 0;
}

.title-bot-card {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 6px 8px;
    background: rgba(0,0,0,0.25);
    border: 1px solid #333;
    border-radius: 6px;
}

.title-bot-card canvas {
    width: 32px !important;
    height: 32px !important;
    border: 1px solid #444;
    border-radius: 3px;
    background: var(--canvas-bg);
    flex-shrink: 0;
}

.title-bot-card .title-bot-info { flex: 1; min-width: 0; }

.title-bot-card .title-bot-name {
    font-size: 0.65rem;
    font-weight: 600;
    color: var(--text-primary);
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.title-bot-card .title-bot-creator {
    font-size: 0.55rem;
    color: var(--text-secondary);
}

/* ─── How to Play modal ─── */
#howto-modal {
    position: fixed;
    inset: 0;
    z-index: 10000;
    background: rgba(0,0,0,0.85);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}

#howto-modal.hidden { display: none !important; }

#howto-modal-inner {
    background: var(--panel-bg);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    padding: 28px 32px;
    max-width: 680px;
    width: 100%;
    max-height: 85vh;
    overflow-y: auto;
    position: relative;
}

#howto-close-btn {
    position: absolute;
    top: 12px;
    right: 16px;
    background: none;
    border: 1px solid #444;
    color: var(--text-secondary);
    padding: 4px 12px;
    border-radius: 4px;
    font-size: 0.7rem;
    cursor: pointer;
}

#howto-close-btn:hover { border-color: var(--danger-color); color: var(--danger-color); }

#howto-modal-inner h2 {
    font-size: 1.3rem;
    letter-spacing: 2px;
    text-transform: uppercase;
    margin-bottom: 20px;
    color: var(--text-primary);
}

.howto-section {
    margin-bottom: 20px;
}

.howto-section h3 {
    font-size: 0.85rem;
    color: var(--accent-color);
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 8px;
}

.howto-section p {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.5;
    margin-bottom: 10px;
}

.howto-color-grid {
    display: flex;
    flex-direction: column;
    gap: 6px;
}

.howto-color-row {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.72rem;
    color: var(--text-secondary);
    line-height: 1.4;
}

.hc-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
    margin-top: 2px;
}

.howto-color-row strong { color: var(--text-primary); }

.howto-steps, .howto-modes {
    padding-left: 20px;
}

.howto-steps li, .howto-modes li {
    font-size: 0.75rem;
    color: var(--text-secondary);
    line-height: 1.6;
    margin-bottom: 4px;
}

.howto-steps li strong, .howto-modes li strong { color: var(--text-primary); }

/* ─── Title screen responsive: mobile portrait ─── */
@media (max-width: 768px) {
    /* Ensure title screen is fully isolated from game editor CSS */
    #title-screen {
        position: fixed !important;
        inset: 0 !important;
        z-index: 9999 !important;
        display: flex !important;
        flex-direction: column !important;
        min-height: 100vh;
        min-height: -webkit-fill-available;
        width: 100vw;
        transform: none !important;
    }

    #title-topbar { padding: 8px 12px; padding-top: max(env(safe-area-inset-top), 8px); }
    .title-google-btn { font-size: 0.7rem; padding: 8px 14px; touch-action: manipulation; }
    .title-logo { font-size: 2rem; letter-spacing: 4px; }
    .title-tagline { font-size: 0.75rem; letter-spacing: 2px; }
    #title-hero { padding: 20px 16px 12px; flex: 1; }
    #title-hero-inner { max-width: 100%; }
    .title-description { font-size: 0.75rem; margin-bottom: 20px; }
    #title-play-row { flex-direction: column; gap: 10px; }
    .title-play-btn { width: 100%; padding: 14px 20px; font-size: 1rem; touch-action: manipulation; }
    .title-mode-select { width: 100%; min-width: unset; padding: 10px 14px; font-size: 0.8rem; }
    .title-howto-link { padding: 8px; font-size: 0.75rem; touch-action: manipulation; }
    #title-bottom { grid-template-columns: 1fr; padding: 0 16px 16px; }
    #howto-modal-inner { padding: 20px 16px; }
    .title-panel h3 { font-size: 0.7rem; }
    .title-news-item { font-size: 0.65rem; }
}

/* ─── Title screen responsive: landscape mobile ─── */
@media (max-width: 900px) and (max-height: 500px) {
    /* Ensure title screen isolation in landscape too */
    #title-screen {
        position: fixed !important;
        inset: 0 !important;
        z-index: 9999 !important;
        transform: none !important;
        flex-direction: row !important;
        flex-wrap: wrap;
    }

    #title-topbar {
        width: 100%;
        padding: 4px 12px;
        padding-top: max(env(safe-area-inset-top), 4px);
    }

    /* Hero on the left half */
    #title-hero {
        flex: 1 1 50%;
        padding: 8px 12px;
        min-width: 0;
        align-items: center;
    }
    #title-hero-inner { max-width: 100%; }
    .title-logo { font-size: 1.5rem; letter-spacing: 3px; }
    .title-tagline { font-size: 0.6rem; letter-spacing: 1px; }
    .title-description { font-size: 0.6rem; margin-bottom: 10px; }
    #title-play-row { flex-direction: row; gap: 8px; }
    .title-play-btn { padding: 8px 28px; font-size: 0.85rem; width: auto; }
    .title-mode-select { min-width: 140px; padding: 8px 10px; font-size: 0.75rem; }
    .title-howto-link { font-size: 0.65rem; }

    /* Panels on the right half */
    #title-bottom {
        flex: 1 1 45%;
        display: flex;
        flex-direction: column;
        gap: 6px;
        padding: 8px 12px;
        max-width: 50%;
        max-height: calc(100vh - 40px);
        overflow-y: auto;
    }
    .title-panel { padding: 8px; }
    .title-panel h3 { font-size: 0.6rem; margin-bottom: 6px; }
    .title-news-item { font-size: 0.55rem; padding: 4px 6px; }
    #title-community-list { max-height: 120px; }

    #howto-modal-inner { padding: 16px 14px; max-height: 90vh; }
}

/* ─── Extra-narrow phones (iPhone SE, etc.) ─── */
@media (max-width: 400px) {
    .community-bot-card {
        flex-direction: column;
        align-items: flex-start;
    }
    .community-bot-card .load-enemy-btn {
        width: 100%;
        margin-top: 5px;
    }
}
