/* ===================================================
   WOJNA — Style globalne + Lobby + Modal
   Mobile-first approach
   =================================================== */

/* ---------- Reset & base ---------- */
*, *::before, *::after {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

:root {
    --app-h: 100vh;
    --app-w: 100vw;
}

@supports (height: 100svh) {
    :root {
        --app-h: 100svh;
        --app-w: 100svw;
    }
}

html {
    font-size: 14px;           /* mniejszy bazowy rozmiar na mobile */
    height: var(--app-h);
}

html[data-page="lobby"] {
    --lobby-box-w: min(400px, 72vw);
    height: auto !important;
    min-height: var(--lobby-lock-h, 100%);
    max-height: none !important;
    width: 100%;
    box-sizing: border-box;
    font-size: 16px;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: #0f1724;
    color: #e0e6f0;
    min-height: var(--app-h);
    max-height: var(--app-h);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    overflow-x: hidden;
    overflow-y: auto;
}

/* Ekran startowy — wyżej; wymiary z JS (--lobby-lock-*), nie svh (klawiatura) */
body.lobby-page {
    justify-content: flex-start;
    padding-top: max(10px, env(safe-area-inset-top, 0px));
    padding-bottom: max(12px, env(safe-area-inset-bottom, 0px));
    min-height: var(--lobby-lock-h, 100%);
    max-height: var(--lobby-lock-h, none);
    overflow-y: auto;
    box-sizing: border-box;
}

html.lobby-viewport-locked,
html.lobby-viewport-locked body.lobby-page {
    min-height: var(--lobby-lock-h) !important;
    max-height: var(--lobby-lock-h) !important;
}

/* ---------- Telefon w pionie: obrót tylko na stronie gry (nie lobby) ---------- */
@media (orientation: portrait) and (max-width: 900px) and (pointer: coarse) {
    html[data-page="game"] {
        transform: rotate(90deg);
        transform-origin: top left;
        width: var(--app-h);
        height: var(--app-w);
        position: absolute;
        top: 0;
        left: 100%;
        overflow: hidden;
    }

    html[data-page="game"] body {
        width: 100%;
        height: 100%;
        min-height: 0;
        max-height: none;
        overflow: hidden;
        position: relative;
        padding: 0;
    }
}

/* ---------- Buttons (shared) ---------- */
.btn {
    display: block;
    width: 100%;
    padding: 10px 0;
    border: none;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    transition: background 0.2s, opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.btn:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.btn:disabled:hover {
    opacity: 0.45;
}

.btn--primary {
    background: #3b82f6;
    color: #fff;
}

.btn--secondary {
    background: #1e2a42;
    color: #cbd5e1;
    border: 1px solid #2d3d5a;
}

.btn--outline {
    background: transparent;
    color: #cbd5e1;
    border: 1px solid #4b5e7e;
}

/* ===================================================
   LOBBY
   =================================================== */
.lobby {
    width: 100%;
    max-width: 380px;
    padding: 16px 14px;
    text-align: center;
}

.lobby__title {
    font-family: Georgia, 'Times New Roman', serif;
    font-style: italic;
    font-size: 2.4rem;
    color: #d4a84b;
    margin-bottom: 4px;
}

.lobby__subtitle {
    font-size: 0.85rem;
    color: #8896ab;
    margin-bottom: 20px;
}

.app-version {
    margin: 14px 0 0;
    font-size: 0.62rem;
    font-weight: 600;
    color: rgba(136, 150, 171, 0.9);
    text-align: center;
    letter-spacing: 0.06em;
    user-select: text;
}

.lobby__box {
    background: #19253a;
    border: 1px solid #2d3d5a;
    border-radius: 12px;
    padding: 18px 16px;
    text-align: left;
}

.lobby__label {
    display: block;
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: #8896ab;
    margin-bottom: 8px;
    text-transform: uppercase;
}

.lobby__input {
    display: block;
    width: 100%;
    padding: 10px 12px;
    margin-bottom: 12px;
    background: #0f1724;
    border: 1px solid #2d3d5a;
    border-radius: 8px;
    color: #e0e6f0;
    font-size: 16px; /* >=16px — bez zoomu iOS przy fokusie */
    outline: none;
    transition: border-color 0.2s;
}

.lobby__input::placeholder {
    color: #4b5e7e;
}

.lobby__input:focus {
    border-color: #3b82f6;
}

.lobby__input--code {
    text-transform: uppercase;
    font-family: 'Courier New', monospace;
    font-weight: 700;
    letter-spacing: 0.18em;
    text-align: center;
}

.lobby__box .btn {
    margin-top: 10px;
}

/* ===================================================
   OVERLAY & MODAL
   =================================================== */
.overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.55);
    backdrop-filter: blur(6px);
    -webkit-backdrop-filter: blur(6px);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 1000;
    padding: 12px;
}

.overlay[hidden] {
    display: none;
}

.modal {
    background: #19253a;
    border: 1px solid #2d3d5a;
    border-radius: 14px;
    padding: 22px 20px;
    width: 100%;
    max-width: 620px;
    animation: fadeInUp 0.25s ease;
}

.modal--join {
    max-width: 420px;
}

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

.modal__title {
    font-size: 1.15rem;
    font-weight: 700;
    margin-bottom: 4px;
}

.modal__desc {
    font-size: 0.8rem;
    color: #8896ab;
    margin-bottom: 18px;
}

.modal__grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 16px;
    margin-bottom: 14px;
}

.modal__grid--triple {
    margin-bottom: 18px;
}

.modal__fieldset {
    border: 1px solid #2d3d5a;
    border-radius: 10px;
    padding: 16px 14px 12px;
    margin: 0 0 22px;
    min-width: 0;
}

.modal__fieldset-legend {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #8896ab;
    text-transform: uppercase;
    padding: 0 8px;
}

.modal__fieldset-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
    margin-top: 4px;
}

.modal__fieldset-hint {
    font-size: 0.8rem;
    color: #94a3b8;
    margin-top: 12px;
    text-align: center;
    font-weight: 600;
}

.modal__fieldset-hint--error {
    color: #fca5a5;
}

.modal__sublabel {
    display: block;
    font-size: 0.68rem;
    font-weight: 600;
    color: #94a3b8;
    margin-bottom: 6px;
    line-height: 1.25;
}

.modal__row--compact {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 10px;
    margin-bottom: 24px;
}

.modal__field--compact .modal__label {
    font-size: 0.62rem;
    margin-bottom: 4px;
    letter-spacing: 0.06em;
}

.modal__select--compact {
    padding: 7px 8px;
    font-size: 0.82rem;
}

.modal__label {
    display: block;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: #8896ab;
    margin-bottom: 6px;
    text-transform: uppercase;
}

.modal__select {
    display: block;
    width: 100%;
    padding: 10px 12px;
    background: #0f1724;
    border: 1px solid #2d3d5a;
    border-radius: 8px;
    color: #e0e6f0;
    font-size: 0.95rem;
    outline: none;
    cursor: pointer;
    appearance: auto;
    transition: border-color 0.2s;
}

.modal__select:focus {
    border-color: #3b82f6;
}

.modal__select option:disabled {
    color: #4b5e7e;
}

.modal__actions {
    display: flex;
    gap: 12px;
}

.modal__status {
    min-height: 1.1rem;
    margin: -4px 0 14px;
    color: #fbbf24;
    font-size: 0.82rem;
}

.modal__status--error {
    color: #fca5a5;
}

.modal__status--success {
    color: #86efac;
}

.modal__actions .btn--outline {
    flex: 0 0 auto;
    width: auto;
    padding: 10px 28px;
    border-radius: 8px;
}

.modal__actions .btn--primary {
    flex: 1;
    padding: 10px 0;
}

/* Telefon — przewijanie przy klawiaturze (pole nazwy / kod pokoju) */
@media (max-width: 1023px) and (pointer: coarse) {
    html.lobby-keyboard-focus body.lobby-page {
        overflow-y: auto !important;
        height: auto !important;
        max-height: none !important;
        min-height: var(--lobby-lock-h, 100%);
        padding-bottom: 42vh;
        -webkit-overflow-scrolling: touch;
    }

    html.lobby-keyboard-focus .lobby {
        position: relative !important;
        top: auto !important;
        left: auto !important;
        transform: none !important;
        margin: 12px auto 24px !important;
    }

    html.lobby-keyboard-focus .overlay:not([hidden]) {
        align-items: flex-start;
        overflow-y: auto;
        padding-top: max(8px, env(safe-area-inset-top, 0px));
        padding-bottom: 42vh;
        -webkit-overflow-scrolling: touch;
    }

    html.lobby-keyboard-focus .overlay:not([hidden]) .modal {
        margin: 8px auto 24px;
    }
}

/* Telefon — lobby: stała szerokość, position fixed (nie reaguje na kurczenie viewportu) */
@media (max-width: 1023px) and (pointer: coarse) {
    body.lobby-page {
        padding-top: 0;
    }

    html[data-page="lobby"]:not(.lobby-keyboard-focus) .lobby {
        position: fixed;
        left: 50%;
        top: max(6px, env(safe-area-inset-top, 0px));
        transform: translateX(-50%);
        width: var(--lobby-box-w, min(400px, 72vw)) !important;
        min-width: var(--lobby-box-w, 300px) !important;
        max-width: var(--lobby-box-w, 400px) !important;
        flex-shrink: 0;
        padding: 16px 14px;
        z-index: 2;
        box-sizing: border-box;
    }

    .lobby__input {
        scroll-margin-top: 24px;
        scroll-margin-bottom: 40vh;
    }

    .lobby__title {
        font-size: 2.1rem;
    }

    .lobby__subtitle {
        font-size: 0.85rem;
        margin-bottom: 16px;
    }

    .lobby__box {
        padding: 16px 14px;
    }
}

/* ===================================================
   RESPONSIVE — tablet / desktop
   =================================================== */
/* Na landscape mobile / tablet — górny rząd w 3 kolumny */
@media (min-width: 560px) {
    .modal__grid--triple {
        grid-template-columns: repeat(3, 1fr);
        gap: 12px;
    }
}

@media (max-width: 559px) {
    .modal__fieldset-grid {
        grid-template-columns: 1fr 1fr;
        gap: 8px;
    }
}

/* Telefon (np. Galaxy S8) — zwarty modal „Załóż pokój” + przewijanie overlay */
@media (max-width: 1023px) and (pointer: coarse) {
    .overlay:not([hidden]) {
        align-items: flex-start;
        overflow-y: auto;
        -webkit-overflow-scrolling: touch;
        padding: max(6px, env(safe-area-inset-top, 0px)) 8px 12px;
    }

    .overlay:not([hidden]) .modal {
        margin: 4px auto 12px;
        max-height: none;
    }

    .modal {
        padding: 14px 12px;
    }

    .modal__title {
        font-size: 1.05rem;
        margin-bottom: 2px;
    }

    .modal__desc {
        font-size: 0.72rem;
        margin-bottom: 10px;
        line-height: 1.3;
    }

    .modal__grid,
    .modal__grid--triple {
        gap: 8px;
        margin-bottom: 10px;
    }

    .modal__label {
        font-size: 0.62rem;
        margin-bottom: 4px;
    }

    .modal__select {
        padding: 7px 10px;
        font-size: 0.86rem;
    }

    .modal__fieldset {
        padding: 10px 10px 8px;
        margin-bottom: 12px;
    }

    .modal__fieldset-legend {
        font-size: 0.62rem;
    }

    .modal__fieldset-grid {
        gap: 8px;
        margin-top: 2px;
    }

    .modal__sublabel {
        font-size: 0.62rem;
        margin-bottom: 4px;
    }

    .modal__select--compact {
        padding: 6px 8px;
        font-size: 0.8rem;
    }

    .modal__fieldset-hint {
        font-size: 0.72rem;
        margin-top: 8px;
    }

    .modal__actions {
        gap: 8px;
    }

    .modal__actions .btn--outline {
        padding: 8px 18px;
    }

    .modal__actions .btn--primary {
        padding: 8px 0;
    }
}

/* Desktop */
@media (min-width: 768px) {
    html {
        font-size: 16px;
    }

    body.lobby-page {
        padding-top: max(24px, env(safe-area-inset-top, 0px));
    }

    .lobby {
        max-width: 440px;
        padding: 24px 20px;
    }

    .lobby__title {
        font-size: 3.2rem;
    }

    .lobby__subtitle {
        margin-bottom: 28px;
    }

    .lobby__box {
        padding: 28px 24px;
    }

    .modal {
        max-width: 660px;
        padding: 28px 32px;
    }
}
