/* Coreward shell. The game owns the whole viewport (fixed overlay) so the site nav/layout doesn't
   intrude on the canvas. Lobby and play states both live inside .cw-root. Mirrors cs2d.css. */
/* The game is a fullscreen experience — hide the site's fixed "Enable Combat" toggle while it's up
   (its own stacking context sits above the page, so z-index alone can't cover it). */
body:has(.cw-root) .game-toggle { display: none !important; }

.cw-root {
    position: fixed;
    inset: 0;
    z-index: 1000;
    background: #0a0e16;
    color: #e8eaf0;
    font-family: 'Segoe UI', system-ui, sans-serif;
    overflow: hidden;
    user-select: none;
}

.cw-canvas {
    display: block;
    width: 100%;
    height: 100%;
    background: #0a0e16;
    cursor: crosshair;
}

/* ---- lobby -------------------------------------------------------------- */
.cw-lobby {
    position: absolute;
    inset: 0;
    display: grid;
    place-items: center;
    background:
        radial-gradient(900px 600px at 50% 120%, rgba(255, 180, 60, 0.16), transparent 60%),
        radial-gradient(700px 500px at 50% -10%, rgba(74, 144, 217, 0.14), transparent 60%),
        #0a0e16;
}

.cw-card {
    width: min(460px, 92vw);
    padding: 34px 30px;
    background: rgba(18, 22, 32, 0.92);
    border: 1px solid #283044;
    border-radius: 14px;
    box-shadow: 0 24px 70px rgba(0, 0, 0, 0.55);
    text-align: center;
}

.cw-title {
    margin: 0 0 6px;
    font-size: 50px;
    font-weight: 800;
    letter-spacing: 3px;
    color: #fff;
}
.cw-title span { color: #e0a23a; }

.cw-sub {
    margin: 0 0 22px;
    font-size: 14px;
    line-height: 1.5;
    color: #9aa0ad;
}

.cw-form {
    display: flex;
    gap: 10px;
    margin-bottom: 16px;
}
.cw-name {
    flex: 1;
    padding: 12px 14px;
    font-size: 16px;
    color: #e8eaf0;
    background: #0e1119;
    border: 1px solid #283044;
    border-radius: 8px;
    outline: none;
}
.cw-name:focus { border-color: #e0a23a; }
.cw-deploy {
    padding: 12px 22px;
    font-size: 15px;
    font-weight: 700;
    color: #1a1206;
    background: #e0a23a;
    border: 0;
    border-radius: 8px;
    cursor: pointer;
}
.cw-deploy:hover { background: #efb24a; }
.cw-deploy:disabled { background: #39414f; color: #6b7280; cursor: not-allowed; }

.cw-modes {
    display: grid;
    grid-template-columns: 1fr 1fr 1fr;
    gap: 8px;
    margin-bottom: 14px;
}
.cw-mode {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 2px;
    padding: 9px 6px;
    color: #cdd2dd;
    background: #161b27;
    border: 1px solid #283044;
    border-radius: 9px;
    cursor: pointer;
    font-family: inherit;
}
.cw-mode:hover { background: #1d2433; }
.cw-mode.sel { border-color: #e0a23a; background: #2a2316; color: #fff; }
.cw-mode-name { font-size: 13px; font-weight: 700; }
.cw-mode-desc { font-size: 10px; color: #8a90a0; text-align: center; }

.cw-hint {
    margin: 4px 0 0;
    font-size: 12px;
    color: #6b7280;
}

/* ---- lobby persistent stats (per-mode leaderboard + welcome-back) ---- */
.cw-welcome {
    margin: 14px 0 6px;
    font-size: 13px;
    color: #cdd2dd;
}
.cw-welcome b { color: #e0c24a; }
.cw-board {
    margin-top: 8px;
    padding: 8px 10px;
    background: rgba(12, 16, 24, 0.6);
    border: 1px solid #232b3a;
    border-radius: 10px;
    text-align: left;
}
.cw-board-head {
    margin-bottom: 6px;
    font-size: 11px;
    font-weight: 700;
    letter-spacing: 0.5px;
    color: #8a90a0;
    text-transform: uppercase;
}
.cw-board-row {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 3px 4px;
    font-size: 12.5px;
    color: #cdd2dd;
    border-radius: 5px;
}
.cw-board-row.me { background: rgba(40, 60, 90, 0.6); color: #fff; }
.cw-board-rank { width: 16px; color: #6b7280; text-align: right; }
.cw-board-name { flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.cw-board-stat { color: #e0c24a; font-variant-numeric: tabular-nums; }

/* ---- in-game chrome ----------------------------------------------------- */
.cw-leave {
    position: absolute;
    top: 12px;
    left: 14px;
    width: 34px;
    height: 34px;
    font-size: 16px;
    color: #e8eaf0;
    background: rgba(20, 24, 34, 0.8);
    border: 1px solid #283044;
    border-radius: 8px;
    cursor: pointer;
    z-index: 60;
}
.cw-leave:hover { background: rgba(224, 162, 58, 0.85); color: #1a1206; }

.cw-tool-btn {
    position: absolute;
    top: 12px;
    height: 34px;
    padding: 0 12px;
    font-size: 14px;
    font-weight: 600;
    color: #e8eaf0;
    background: rgba(20, 24, 34, 0.8);
    border: 1px solid #283044;
    border-radius: 8px;
    cursor: pointer;
    z-index: 60;
}
.cw-tool-btn:hover { background: rgba(224, 162, 58, 0.85); color: #1a1206; }
.cw-craft-toggle { left: 56px; }
.cw-help-toggle { left: 150px; width: 38px; padding: 0; }
.cw-settings-toggle { left: 196px; width: 38px; padding: 0; }

.cw-settings { width: 200px; }
.cw-set-row {
    display: flex; align-items: center; justify-content: space-between; gap: 10px;
    margin: 8px 0; font-size: 13px; color: #cdd2dd;
}
.cw-set-row input[type="range"] { flex: 1; accent-color: #e0a23a; }

.cw-panel {
    position: absolute;
    top: 56px;
    left: 14px;
    width: 240px;
    padding: 12px 14px;
    background: rgba(16, 19, 27, 0.96);
    border: 1px solid #283044;
    border-radius: 12px;
    z-index: 61;
}
.cw-panel-head {
    display: flex; justify-content: space-between; align-items: center;
    margin-bottom: 10px; font-weight: 700; font-size: 14px; color: #e8eaf0;
}
.cw-panel-x {
    width: 22px; height: 22px; color: #e8eaf0; background: #20242e;
    border: 1px solid #343a47; border-radius: 6px; cursor: pointer;
}
.cw-craft-item {
    display: flex; justify-content: space-between; align-items: center; width: 100%;
    margin: 4px 0; padding: 8px 10px; font-size: 13px; color: #cdd2dd;
    background: #1a1f2b; border: 1px solid #2a3242; border-radius: 8px; cursor: pointer; font-family: inherit;
}
.cw-craft-item:hover { background: #243247; border-color: #e0a23a; color: #fff; }
.cw-craft-cost { color: #e0c24a; font-size: 12px; }
/* chat input — sits bottom-left, dim until focused (Enter to focus, Escape/Enter to leave) */
.cw-chat {
    position: absolute;
    left: 14px;
    bottom: 96px;
    width: 280px;
    max-width: 42vw;
    padding: 7px 10px;
    font-size: 13px;
    font-family: inherit;
    color: #e8eaf0;
    background: rgba(12, 16, 24, 0.6);
    border: 1px solid #283044;
    border-radius: 8px;
    outline: none;
    opacity: 0.5;
    z-index: 62;
    transition: opacity 0.12s;
}
.cw-chat:focus { opacity: 1; border-color: #e0a23a; background: rgba(12, 16, 24, 0.96); }

/* On touch devices the bottom-left is the movement thumb zone — the chat box was catching taps meant
   for the ◀/▶ buttons. Move it clear, up to the top-centre (out of every thumb zone). Desktop keeps
   the bottom-left placement (fine pointer → this query never applies). */
@media (pointer: coarse) {
    .cw-chat {
        bottom: auto;
        top: 48px;
        left: 50%;
        transform: translateX(-50%);
        width: 300px;
        max-width: 56vw;
    }
}

.cw-help { width: 300px; }
.cw-help-list { margin: 0; padding-left: 16px; font-size: 12px; line-height: 1.7; color: #cdd2dd; }
.cw-help-list b { color: #e0a23a; }
