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

html, body {
    height: 100%;
    background: #080a12;   /* also paints the safe areas (notch, home indicator) */
    touch-action: none;
    -webkit-tap-highlight-color: transparent;
    -webkit-user-select: none;
    user-select: none;
}

body {
    background: #080a12;
    display: flex;
    justify-content: center;
    align-items: center;
    height: 100vh;
    height: 100dvh;   /* iOS: the visible height, not the one behind the toolbars */
    overflow: hidden;
}

#gameCanvas {
    display: block;
    cursor: crosshair;
}

#portrait-hint {
    display: none;
    position: fixed;
    inset: 0;
    background: #080a12;
    color: #9496c0;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 16px;
    font-family: Consolas, 'Courier New', monospace;
    font-size: 1.1rem;
    z-index: 100;
    text-align: center;
    padding: 2rem;
}

#portrait-hint svg {
    width: 56px;
    height: 56px;
    fill: #6870b0;
    animation: rotateIn 1.2s ease-in-out infinite alternate;
}

@keyframes rotateIn {
    from { transform: rotate(0deg); }
    to   { transform: rotate(90deg); }
}

/* Touch devices only — a tall desktop window is not a rotated phone */
@media (orientation: portrait) and (pointer: coarse) {
    #portrait-hint { display: flex; }
    #gameCanvas    { display: none; }
}

/* ── Multiplayer lobby (overlay) ───────────────────────────────────────────── */
#lobby {
    display: none;
    position: fixed; inset: 0; z-index: 50;
    align-items: center; justify-content: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
    background: rgba(4, 6, 14, 0.6);
    font: 15px Consolas, 'Courier New', monospace;
    color: #b9bdf0;
    touch-action: manipulation; -webkit-user-select: text; user-select: text;
}
#lobby .lb-card {
    width: min(780px, 94vw); max-height: 94dvh; overflow: auto;
    padding: 16px 20px; border-radius: 12px;
    background: rgba(12, 15, 30, 0.95);
    border: 1px solid rgba(0, 210, 255, 0.55);
    box-shadow: 0 0 24px rgba(0, 200, 255, 0.25);
    display: flex; flex-direction: column; gap: 10px;
}
#lobby .lb-head { display: flex; align-items: center; gap: 14px; }
#lobby h1 { font-size: 1.2rem; color: #c8ccff; letter-spacing: 2px; text-shadow: 0 0 10px #6070ff; margin-right: auto; }
#lobby .lb-codebox { display: none; align-items: baseline; gap: 8px; font-size: 0.8rem; color: #7c82bb; }
#lobby .lb-codebox b { font-size: 1.7rem; letter-spacing: 5px; color: #9ff0ff; text-shadow: 0 0 10px #00c8ff; }
#lobby .lb-share { font-size: 0.7rem; color: #5a609a; }
#lobby .lb-err { min-height: 1.1em; color: #ff7a80; text-align: center; font-size: 0.85rem; }

#lobby input, #lobby select {
    font: inherit; padding: 8px 10px; border-radius: 6px; min-height: 40px;
    background: #0a0d1c; color: #dfe2ff; border: 1px solid #3a4280; min-width: 0;
}
#lobby button {
    font: inherit; padding: 8px 14px; min-height: 40px; border-radius: 8px; cursor: pointer;
    background: rgba(50, 55, 120, 0.7); color: #d2d6ff; border: 1px solid rgba(160, 165, 255, 0.8);
}
#lobby button:disabled { opacity: 0.35; cursor: default; }
#lobby .lb-back { background: transparent; border-color: #3a4280; color: #8a90c8; }

/* Entry: name, back-to-room, create, join */
#lobby .lb-entry { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#lobby .lb-name  { grid-column: 1 / -1; }
#lobby .lb-rejoin { grid-column: 1 / -1; border-color: #9ff0ff; }
#lobby .lb-join { display: flex; gap: 8px; }
#lobby .lb-join .lb-code { flex: 1; text-transform: uppercase; letter-spacing: 4px; text-align: center; }

/* Room: teams | side controls */
#lobby .lb-room { display: none; grid-template-columns: 1fr 230px; gap: 14px; }
#lobby.in-room .lb-room { display: grid; }
#lobby.in-room .lb-entry { display: none; }
#lobby.in-room .lb-codebox { display: flex; }
#lobby .lb-teams { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
#lobby .lb-team { padding: 8px 10px; border-radius: 8px; display: flex; flex-direction: column; gap: 6px; }
#lobby .lb-team.t1 { border: 1px solid rgba(70, 130, 255, 0.6); } #lobby .lb-team.t1 h2 { color: #6aa0ff; }
#lobby .lb-team.t2 { border: 1px solid rgba(255, 70, 80, 0.6); }  #lobby .lb-team.t2 h2 { color: #ff6a74; }
#lobby h2 { font-size: 0.9rem; }
#lobby ul { list-style: none; display: flex; flex-direction: column; gap: 4px; }
#lobby li { display: flex; justify-content: space-between; gap: 6px; min-height: 1.5em; overflow: hidden; white-space: nowrap; }
#lobby li > span:first-child { overflow: hidden; text-overflow: ellipsis; }
#lobby li.me { color: #ffffff; } #lobby li.bot { color: #4a4f78; font-style: italic; }
#lobby .lb-st { font-size: 0.75rem; flex-shrink: 0; }
#lobby .lb-st.ok { color: #6dff9a; } #lobby .lb-st.wait { color: #c9a850; } #lobby .lb-st.host { color: #7c82bb; }
#lobby .lb-side { display: flex; flex-direction: column; gap: 8px; }
#lobby .lb-settings { display: flex; flex-direction: column; gap: 6px; }
#lobby .lb-settings label { display: grid; grid-template-columns: 3.2em 1fr; align-items: center; gap: 8px; font-size: 0.85rem; }
#lobby .lb-hint { font-size: 0.78rem; color: #7c82bb; min-height: 2.4em; }
#lobby .lb-start, #lobby .lb-ready { font-weight: bold; font-size: 1.05rem; min-height: 48px; }
#lobby .lb-start:not(:disabled) { border-color: #9ff0ff; box-shadow: 0 0 12px rgba(0, 200, 255, 0.35); }
#lobby .lb-ready { background: rgba(70, 60, 20, 0.6); border-color: #c9a850; color: #ffe08a; }
#lobby .lb-ready.on { background: rgba(20, 70, 40, 0.7); border-color: #6dff9a; color: #b9ffd0; box-shadow: 0 0 12px rgba(80, 255, 140, 0.3); }

/* Narrow (portrait-ish) windows: one column */
@media (max-width: 600px) {
    #lobby .lb-room { grid-template-columns: 1fr; }
    #lobby .lb-entry { grid-template-columns: 1fr; }
}
/* Phones in landscape: compact everything so it fits without scrolling */
@media (max-height: 500px) {
    #lobby { font-size: 13px; }
    #lobby .lb-card { padding: 10px 14px; gap: 6px; width: min(820px, 96vw); max-height: 96dvh; }
    #lobby h1 { font-size: 1rem; }
    #lobby .lb-codebox b { font-size: 1.35rem; }
    #lobby .lb-err { min-height: 0; }
    #lobby .lb-room { grid-template-columns: 1fr 200px; gap: 10px; }
    #lobby .lb-team { padding: 6px 8px; gap: 4px; }
    #lobby ul { gap: 2px; }
    #lobby .lb-hint { min-height: 0; font-size: 0.72rem; }
    #lobby input, #lobby select, #lobby button { min-height: 38px; padding: 6px 10px; }
    #lobby .lb-start, #lobby .lb-ready { min-height: 42px; font-size: 0.95rem; }
}
