:root{
    --bg0:#f6f8ff;
    --bg1:#ffffff;
    --bg2:#f1f4ff;

    --text:#182033;
    --muted: rgba(24,32,51,0.65);

    --border: rgba(20,30,60,0.14);
    --borderSoft: rgba(20,30,60,0.10);

    --accent:#3b82f6;
    --accent2:#ff4d8d;
    --good:#22c55e;
    --warn:#f59e0b;

    --radius:14px;
    --shadow: 0 16px 40px rgba(18,32,80,0.12);
    --shadowStrong: 0 24px 70px rgba(18,32,80,0.18);
}

*{ box-sizing:border-box; }

html, body{
    height: 100vh;
    margin: 0;
    font-family: system-ui, Arial, sans-serif;
    background:
            radial-gradient(900px 600px at 18% 12%, rgba(59,130,246,0.16), transparent 55%),
            radial-gradient(900px 600px at 82% 78%, rgba(255,77,141,0.12), transparent 55%),
            var(--bg0);
    color: var(--text);
}

.smallText{ font-size:12px; }
.muted{ color: var(--muted); }

/* ===== App shell ===== */

.appShell{
    height: 100vh;
    display: grid;
    grid-template-rows: 64px 1fr;
    min-height: 0;
}

/* ===== Top bar ===== */

.topBar{
    height: 64px;
    display: grid;
    grid-template-columns: 220px 1fr 220px;
    align-items: center;
    padding: 10px 14px;
    gap: 10px;
    background: rgba(255,255,255,0.72);
    border-bottom: 1px solid var(--borderSoft);
    backdrop-filter: blur(10px);
}

.topLeft{ display:flex; align-items:center; }

.brandLogo{
    height: 42px;
    width: auto;
    filter: drop-shadow(0 8px 14px rgba(18,32,80,0.12));
    user-select: none;
}

.topCenter{
    display:flex;
    justify-content:center;
    gap: 10px;
    flex-wrap: wrap;
}

.pillInfo{
    display:flex;
    align-items:center;
    gap: 8px;
    padding: 8px 10px;
    border-radius: 999px;
    background: rgba(255,255,255,0.92);
    border: 1px solid var(--border);
    box-shadow: 0 10px 22px rgba(18,32,80,0.08);
    font-size: 12px;
}

.dot{
    width: 10px;
    height: 10px;
    border-radius: 999px;
    display: inline-block;
    box-shadow: 0 0 0 3px rgba(0,0,0,0.03);
}
.dotOk{ background: var(--good); }
.dotWarn{ background: var(--warn); }
.dotInfo{ background: var(--accent); }

.topRight{
    display:flex;
    justify-content:flex-end;
    gap: 8px;
}

.iconBtn{
    cursor: pointer;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.92);
    border-radius: 12px;
    padding: 10px 12px;
    box-shadow: 0 10px 22px rgba(18,32,80,0.08);
    transition: transform 120ms ease, box-shadow 120ms ease;
}
.iconBtn:hover{
    transform: translateY(-1px);
    box-shadow: 0 14px 30px rgba(18,32,80,0.10);
}

/* ===== Main ===== */

.mainArea{
    min-height: 0;
    display: grid;
    grid-template-columns: 1fr 380px;
    gap: 12px;
    padding: 12px;
}

/* ===== World / canvas ===== */

.worldArea{
    min-height: 0;
    position: relative;
    display: flex;
    align-items: stretch;
    justify-content: stretch;
    padding: 10px;
    border-radius: 18px;
    background: rgba(255,255,255,0.45);
    border: 1px solid var(--borderSoft);
    box-shadow: var(--shadow);
    overflow: hidden;
}

.gameCanvas{
    flex: 1;
    width: 100%;
    height: 100%;
    display: block;
    border-radius: 18px;
    border: 1px solid var(--borderSoft);
    background: linear-gradient(180deg, #ffffff, #f7f9ff);
    box-shadow: 0 16px 44px rgba(18,32,80,0.10);
}

/* Floating card */
.floatingCard{
    position: absolute;
    z-index: 20;
    background: rgba(255,255,255,0.78);
    border: 1px solid rgba(20,30,60,0.14);
    border-radius: 16px;
    padding: 10px 12px;
    backdrop-filter: blur(10px);
    box-shadow: 0 14px 34px rgba(18,32,80,0.12);
}
.floatingLeft{
    left: 16px;
    bottom: 18px;
    width: 260px;
}
.cardTitleSmall{
    font-weight: 900;
    font-size: 12px;
    margin-bottom: 4px;
}

.tinyRow{
    display:flex;
    gap: 8px;
    margin-top: 8px;
    flex-wrap: wrap;
}

.tinyBadge{
    font-size: 11px;
    padding: 6px 10px;
    border-radius: 999px;
    background: rgba(59,130,246,0.10);
    border: 1px solid rgba(59,130,246,0.18);
}

/* Bottom bar */
.bottomBar{
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    bottom: 14px;
    display:flex;
    align-items:center;
    gap: 14px;
    padding: 10px 12px;
    border-radius: 999px;
    background: rgba(255,255,255,0.80);
    border: 1px solid rgba(20,30,60,0.14);
    backdrop-filter: blur(10px);
    box-shadow: 0 18px 42px rgba(18,32,80,0.14);
    z-index: 22;
}

.bottomGroup{ display:flex; align-items:center; gap:8px; }

.bottomDivider{
    width: 1px;
    height: 18px;
    background: rgba(20,30,60,0.16);
    margin: 0 4px;
}

.kbd{
    font-size: 11px;
    font-weight: 800;
    padding: 5px 8px;
    border-radius: 10px;
    border: 1px solid rgba(20,30,60,0.16);
    background: rgba(255,255,255,0.92);
    box-shadow: 0 8px 16px rgba(18,32,80,0.08);
}

/* ===== Right rail ===== */

.rightRail{
    min-height: 0;
    overflow: hidden;
    border-radius: 18px;
    background: rgba(255,255,255,0.62);
    border: 1px solid var(--borderSoft);
    box-shadow: var(--shadow);
    display: flex;
    flex-direction: column;
    backdrop-filter: blur(10px);
}

.railHeader{
    flex: 0 0 auto;
    padding: 12px;
    border-bottom: 1px solid var(--borderSoft);
    background: rgba(255,255,255,0.70);
}

.railTitle{
    font-weight: 900;
    margin-bottom: 10px;
}

.railTabs{
    display: flex;
    gap: 8px;
}

.tabBtn{
    cursor: pointer;
    flex: 1;
    padding: 10px 10px;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: rgba(255,255,255,0.92);
    box-shadow: 0 10px 22px rgba(18,32,80,0.08);
    font-weight: 800;
    transition: transform 120ms ease;
}
.tabBtn:hover{ transform: translateY(-1px); }

.tabBtn.active{
    background: linear-gradient(180deg, rgba(59,130,246,0.20), rgba(59,130,246,0.10));
    border-color: rgba(59,130,246,0.30);
}

.railBody{
    flex: 1;
    min-height: 0;
}

/* Tab panels: devono essere colonne che riempiono */
.tabPanel{ display:none; }
.tabPanel.active{
    display:flex;
    flex-direction: column;
    flex: 1;
    min-height: 0;
}

/* ===== Utility rows ===== */

.row{ display:flex; gap:8px; align-items:center; }

/* IMPORTANT: evita impacchettamenti brutti */
.rowBetween{
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
}

.rowTight{
    gap: 6px;
    flex-wrap: wrap;
}

/* Inputs */
.textInput, select{
    font: inherit;
    color: var(--text);
    background: rgba(255,255,255,0.92);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 10px 10px;
    outline: none;
    box-shadow: 0 10px 22px rgba(18,32,80,0.08);
}

.textInput:focus{
    border-color: rgba(59,130,246,0.45);
    box-shadow: 0 14px 30px rgba(59,130,246,0.16);
}

.textInput.mono{
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

/* ===== Players tab ===== */

.playersBox{ padding: 12px; }

.playersList{
    display:flex;
    flex-direction:column;
    gap: 10px;
    margin-top: 10px;
}

.playerRow{
    height: 42px;
    border-radius: 14px;
    border: 1px solid var(--borderSoft);
    background: rgba(255,255,255,0.78);
    box-shadow: 0 10px 18px rgba(18,32,80,0.06);
}

.playerRow.skeleton{
    background: linear-gradient(
            90deg,
            rgba(255,255,255,0.70),
            rgba(255,255,255,0.95),
            rgba(255,255,255,0.70)
    );
    background-size: 180% 100%;
    animation: shimmer 1.2s infinite linear;
}

@keyframes shimmer{
    0%{ background-position: 0% 0%; }
    100%{ background-position: 180% 0%; }
}

.miniCard{
    margin: 12px;
    padding: 12px;
    border-radius: 16px;
    background: rgba(255,255,255,0.78);
    border: 1px solid var(--borderSoft);
    box-shadow: 0 14px 28px rgba(18,32,80,0.10);
}

/* ===== Status ===== */

.status{
    font-size: 12px;
    margin-top: 8px;
    color: rgba(24,32,51,0.70);
}

/* ===== LOGIN overlay ===== */

.loginOverlay{
    position: fixed;
    inset: 0;
    display:flex;
    align-items:center;
    justify-content:center;
    padding: 18px;
    background:
            radial-gradient(1200px 700px at 22% 16%, rgba(59,130,246,0.22), transparent 60%),
            radial-gradient(900px 600px at 82% 78%, rgba(255,77,141,0.16), transparent 58%),
            rgba(246,248,255,0.82);
    backdrop-filter: blur(10px);
    z-index: 999;
}

.loginCard{
    width: min(520px, 92vw);
    background: rgba(255,255,255,0.88);
    border: 1px solid rgba(20,30,60,0.16);
    border-radius: 20px;
    box-shadow: var(--shadowStrong);
    padding: 18px 18px 16px 18px;
}

.loginLogo{
    width: 280px;
    max-width: 78%;
    display: block;
    margin: 6px auto 10px auto;
    filter: drop-shadow(0 10px 18px rgba(18,32,80,0.16));
    user-select: none;
}

.loginSubtitle{
    text-align: center;
    color: rgba(24,32,51,0.72);
    font-size: 13px;
    margin-bottom: 14px;
}

.loginForm{ display:grid; gap:10px; }

.fieldLabel{
    font-size: 12px;
    color: rgba(24,32,51,0.70);
}

.colorRow{
    display:grid;
    grid-template-columns: 54px 1fr;
    gap: 10px;
    align-items: center;
}

.colorPicker{
    width: 54px;
    height: 44px;
    padding: 0;
    border-radius: 12px;
    border: 1px solid rgba(20,30,60,0.18);
    background: rgba(255,255,255,0.92);
    cursor: pointer;
    box-shadow: 0 10px 22px rgba(18,32,80,0.10);
}

.btnPrimary{
    cursor: pointer;
    border: 1px solid rgba(59,130,246,0.35);
    background: linear-gradient(180deg, rgba(59,130,246,0.22), rgba(59,130,246,0.12));
    color: rgba(24,32,51,0.95);
    border-radius: 14px;
    padding: 12px 12px;
    font-weight: 900;
    letter-spacing: 0.2px;
    box-shadow: 0 14px 30px rgba(59,130,246,0.16);
    transition: transform 120ms ease, box-shadow 120ms ease;
}

.btnPrimary:hover{
    transform: translateY(-1px);
    box-shadow: 0 18px 38px rgba(59,130,246,0.22);
}

.statusCenter{ text-align:center; }

.loginHint{
    text-align: center;
    font-size: 12px;
    color: rgba(24,32,51,0.62);
    margin-top: 2px;
}

/* Mostra UI gioco solo dopo login */
body.is-logged-out .inGameOnly{
    opacity: 0;
    pointer-events: none;
    filter: blur(3px);
}
body:not(.is-logged-out) .loginOverlay{
    display: none;
}
