/* ============================================
   The lobby: the invitation that can come up on any page, and the portal's
   "Play Together" panel.

   The first half (.lobby-*) is loaded by js/lobby.js on every page, game
   pages included, so it carries its own colours and assumes nothing about
   the page it lands on. The second half (.together-*) is the portal's and
   uses the portal's variables (css/style.css).
   ============================================ */

/* ---------- the invitation ---------- */
.lobby-toast {
    --l-bg: #10152c;
    --l-line: #2a3360;
    --l-ink: #eef1ff;
    --l-muted: #a7aed3;
    --l-cyan: #2be4ff;
    --l-gold: #ffc93c;
    position: fixed;
    top: 14px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 9000;
    width: min(440px, calc(100vw - 20px));
    padding: 14px 16px 16px;
    border-radius: 16px;
    border: 1px solid var(--l-cyan);
    background: linear-gradient(180deg, #171d3c, var(--l-bg));
    box-shadow: 0 0 26px rgba(43, 228, 255, 0.28), 0 18px 44px rgba(0, 0, 0, 0.6);
    color: var(--l-ink);
    font-family: 'Chakra Petch', 'Rajdhani', 'Malgun Gothic', 'Apple SD Gothic Neo', 'Noto Sans KR', system-ui, sans-serif;
    font-weight: 600;
    text-align: left;
    word-break: keep-all;
    overflow: hidden;
    touch-action: manipulation;
    -webkit-user-select: none;
    user-select: none;
    animation: lobbyDrop 0.32s cubic-bezier(0.34, 1.4, 0.64, 1);
}

.lobby-toast *, .lobby-toast *::before, .lobby-toast *::after { box-sizing: border-box; margin: 0; padding: 0; }

@keyframes lobbyDrop {
    from { opacity: 0; transform: translate(-50%, -18px); }
    to { opacity: 1; transform: translate(-50%, 0); }
}

.lobby-toast-row { display: flex; align-items: center; gap: 12px; }

.lobby-face {
    flex: none;
    width: 52px;
    height: 52px;
    border-radius: 50%;
    border: 2px solid var(--l-gold, #ffc93c);
    box-shadow: 0 0 12px rgba(255, 201, 60, 0.35);
    display: inline-flex;
    align-items: center;
    justify-content: center;
    overflow: hidden;
    font-family: 'Orbitron', 'Malgun Gothic', 'Apple SD Gothic Neo', sans-serif;
    font-size: 1.3rem;
    font-weight: 900;
    color: #06101c;
    background: linear-gradient(135deg, #2be4ff, #0a7fd0);
}

.lobby-face img { width: 100%; height: 100%; object-fit: cover; display: block; }

.lobby-toast-words { min-width: 0; }
.lobby-toast-line { font-size: 1.05rem; line-height: 1.4; color: var(--l-ink); }
.lobby-toast-line b { color: var(--l-gold); font-weight: 700; }
.lobby-toast-sub { font-size: 0.86rem; color: var(--l-muted); margin-top: 2px; }

.lobby-toast-buttons { display: flex; gap: 8px; margin-top: 12px; }

.lobby-toast-buttons button {
    flex: 1 1 0;
    min-height: 46px;
    border-radius: 12px;
    font: inherit;
    font-weight: 700;
    font-size: 1rem;
    cursor: pointer;
    transition: transform 0.1s ease, box-shadow 0.15s ease, background 0.15s ease;
}

.lobby-yes {
    border: none;
    color: #06101c;
    background: linear-gradient(135deg, #2be4ff, #17a6ff);
    box-shadow: 0 0 16px rgba(43, 228, 255, 0.45);
}

.lobby-yes:not(:disabled):hover { transform: translateY(-1px); box-shadow: 0 0 24px rgba(43, 228, 255, 0.7); }

.lobby-no {
    border: 1px solid var(--l-line);
    color: var(--l-muted);
    background: transparent;
}

.lobby-no:not(:disabled):hover { color: var(--l-ink); border-color: var(--l-muted); }
.lobby-toast-buttons button:disabled { cursor: default; opacity: 0.7; transform: none; box-shadow: none; }
.lobby-toast-buttons button:focus-visible { outline: 3px solid var(--l-gold); outline-offset: 2px; }

/* The time left to answer, running down. */
.lobby-toast-time {
    position: absolute;
    left: 0;
    right: 0;
    bottom: 0;
    height: 4px;
    background: rgba(43, 228, 255, 0.12);
}

.lobby-toast-time span {
    display: block;
    height: 100%;
    width: 100%;
    transform-origin: left center;
    background: linear-gradient(90deg, #2be4ff, #ff4fd8);
    animation: lobbyDrain 30s linear forwards;
}

@keyframes lobbyDrain { from { transform: scaleX(1); } to { transform: scaleX(0); } }

.lobby-toast-over { border-color: var(--l-line); box-shadow: 0 14px 34px rgba(0, 0, 0, 0.55); text-align: center; }
.lobby-toast-over .lobby-toast-line { color: var(--l-muted); }

/* ---------- Play Together (the portal) ---------- */
.together {
    padding: 1.4rem 1.5rem 1.5rem;
    background:
        radial-gradient(ellipse at 0% 0%, rgba(43, 228, 255, 0.10), rgba(43, 228, 255, 0) 55%),
        var(--panel);
    word-break: keep-all;
}

.together-head {
    display: flex;
    flex-wrap: wrap;
    align-items: flex-start;
    justify-content: space-between;
    gap: 0.6rem 1rem;
    margin-bottom: 1.1rem;
}

.together-sub { font-size: 0.98rem; color: var(--muted); margin-top: 0.3rem; }
.together-sub b { color: var(--ink); font-weight: 700; }

.together-live {
    display: inline-block;
    width: 0.62em;
    height: 0.62em;
    margin-right: 0.15em;
    border-radius: 50%;
    background: var(--lime);
    box-shadow: 0 0 10px rgba(166, 255, 77, 0.8);
    vertical-align: 0.08em;
    animation: togetherPulse 1.8s ease-in-out infinite;
}

.together-live.off { background: var(--muted); box-shadow: none; animation: none; }

@keyframes togetherPulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.35; } }

/* The family: one tile a member, like the character select of an arcade. */
.together-members {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
    gap: 0.9rem;
}

.together-member {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.35rem;
    min-height: 44px;
    padding: 1rem 0.6rem 0.9rem;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    color: var(--ink);
    font: inherit;
    text-align: center;
    transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease;
}

button.together-member { cursor: pointer; }

button.together-member:hover, button.together-member:focus-visible {
    transform: translateY(-3px);
    border-color: var(--cyan);
    box-shadow: 0 0 20px rgba(43, 228, 255, 0.3);
}

.together-member.is-off { opacity: 0.5; }
.together-member.is-me { border-style: dashed; }

.together-face {
    position: relative;
    width: 68px;
    height: 68px;
    flex: none;
}

.together-face .lobby-face {
    width: 68px;
    height: 68px;
    font-size: 1.6rem;
    border-color: var(--line);
    box-shadow: none;
}

.together-member.is-on .lobby-face { border-color: var(--lime); box-shadow: 0 0 16px rgba(166, 255, 77, 0.4); }
.together-member.is-busy .lobby-face { border-color: var(--orange); box-shadow: 0 0 14px rgba(255, 138, 61, 0.35); }

/* The dot that says "here now". */
.together-dot {
    position: absolute;
    right: 1px;
    bottom: 1px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    border: 3px solid var(--panel-2);
    background: #5b6390;
}

.together-member.is-on .together-dot { background: var(--lime); box-shadow: 0 0 10px rgba(166, 255, 77, 0.9); }
.together-member.is-busy .together-dot { background: var(--orange); box-shadow: 0 0 10px rgba(255, 138, 61, 0.8); }

.together-name {
    max-width: 100%;
    font-weight: 700;
    font-size: 1.05rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.together-badges { display: flex; flex-wrap: wrap; justify-content: center; gap: 0.3rem; min-height: 1.35rem; }

.together-badge {
    font-size: 0.72rem;
    font-weight: 700;
    letter-spacing: 0.04em;
    padding: 0.08rem 0.5rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    color: var(--muted);
}

.together-badge.me { border-color: var(--gold); color: var(--gold); }
.together-badge.owner { border-color: var(--magenta); color: var(--magenta); }

.together-where { font-size: 0.9rem; color: var(--muted); min-height: 1.3rem; }
.together-member.is-on .together-where { color: var(--lime); }
.together-member.is-busy .together-where { color: var(--orange); }

/* How it stands between two members, from the games they have finished
   against each other: a small scoreboard under the name. On every tile, so
   the tiles keep one height - empty while the answer is on its way. */
.together-record {
    display: inline-flex;
    align-items: baseline;
    justify-content: center;
    gap: 0.4rem;
    min-height: 1.55rem;
    padding: 0.08rem 0.7rem;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: rgba(255, 255, 255, 0.04);
    font-family: var(--font-body);
    font-size: 0.86rem;
    font-weight: 700;
    line-height: 1.5;
    white-space: nowrap;
}

.together-record i { font-style: normal; font-weight: 600; color: var(--muted); }
.together-record .win { color: var(--lime); }
.together-record .loss { color: #ff9a9a; }
.together-record .draw { color: var(--soft); }
/* No games between these two yet: said quietly, without the frame. */
.together-record.none { border-color: transparent; background: none; font-weight: 600; color: var(--muted); }

.together-ask {
    margin-top: 0.2rem;
    /* Korean, which the display face does not have: set in the body face. */
    font-family: var(--font-body);
    font-size: 0.9rem;
    font-weight: 700;
    padding: 0.3rem 0.85rem;
    border-radius: 999px;
    color: #06101c;
    background: var(--cyan);
    box-shadow: 0 0 12px rgba(43, 228, 255, 0.4);
}

.together-note {
    margin-top: 1rem;
    padding: 0.8rem 1rem;
    border-radius: 12px;
    border: 1px dashed var(--line);
    font-size: 0.98rem;
    line-height: 1.6;
    color: var(--soft);
}

.together-note.warn { border-color: rgba(255, 201, 60, 0.5); color: #f0e2ad; border-style: solid; background: rgba(255, 201, 60, 0.06); }

/* ---------- no group yet: make one, or join one ---------- */
.together-setup {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    gap: 1rem;
}

.together-card {
    padding: 1.1rem 1.1rem 1.2rem;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: var(--panel-2);
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

.together-card h3 {
    font-family: var(--font-display);
    font-size: 0.92rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    color: var(--cyan);
}

.together-card p { font-size: 0.95rem; line-height: 1.55; color: var(--soft); }

.together-row { display: flex; flex-wrap: wrap; gap: 0.5rem; margin-top: auto; }

.together-input {
    flex: 1 1 150px;
    min-width: 0;
    min-height: 48px;
    padding: 0 0.9rem;
    border-radius: 12px;
    border: 2px solid var(--line);
    background: #0c1024;
    color: var(--ink);
    font: inherit;
    font-weight: 600;
    font-size: 1rem;
}

.together-input::placeholder { color: #5f678f; }
.together-input:focus { outline: none; border-color: var(--cyan); box-shadow: 0 0 14px rgba(43, 228, 255, 0.3); }

.together-input.code {
    font-family: var(--font-display);
    font-size: 1.05rem;
    letter-spacing: 0.22em;
    text-transform: uppercase;
    text-align: center;
    color: var(--gold);
}

.together-msg { min-height: 1.4rem; font-size: 0.92rem; color: var(--muted); }
.together-msg.bad { color: #ff9a9a; }

/* ---------- managing the group ---------- */
.together-manage {
    margin-top: 1.1rem;
    padding: 1.1rem;
    border-radius: 14px;
    border: 1px solid var(--line);
    background: #10152c;
    display: flex;
    flex-direction: column;
    gap: 0.9rem;
}

.together-manage h3 {
    font-family: var(--font-display);
    font-size: 0.85rem;
    font-weight: 700;
    letter-spacing: 0.08em;
    color: var(--muted);
}

.together-code-row { display: flex; flex-wrap: wrap; align-items: center; gap: 0.6rem; }

.together-code {
    font-family: var(--font-display);
    font-size: 1.5rem;
    font-weight: 900;
    letter-spacing: 0.16em;
    color: var(--gold);
    text-shadow: 0 0 12px rgba(255, 201, 60, 0.4);
    padding: 0.35rem 0.9rem;
    border-radius: 10px;
    border: 1px solid rgba(255, 201, 60, 0.5);
    background: rgba(255, 201, 60, 0.07);
    -webkit-user-select: all;
    user-select: all;
}

.together-people { display: flex; flex-direction: column; gap: 0.4rem; }

.together-person {
    display: flex;
    align-items: center;
    gap: 0.7rem;
    padding: 0.4rem 0.5rem;
    border-radius: 10px;
}

.together-person:nth-child(odd) { background: rgba(255, 255, 255, 0.03); }
.together-person .lobby-face { width: 34px; height: 34px; font-size: 0.9rem; border-width: 1px; box-shadow: none; }
.together-person-name { flex: 1 1 auto; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-weight: 700; }
.together-person .btn { min-height: 36px; padding: 0 0.8rem; font-size: 0.88rem; }

.together-manage-foot { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.6rem; }
.btn-danger { background: transparent; color: #ff9a9a; border-color: rgba(255, 110, 110, 0.6); }
.btn-danger:hover { background: rgba(255, 110, 110, 0.12); }

/* ---------- asking for a game ---------- */
.together-dialog {
    position: relative;
    z-index: 1;
    /* Wide enough for three games side by side: with three to choose from,
       a third one alone on a second row read as an afterthought. */
    width: min(92vw, 560px);
    max-height: 88vh;
    overflow-y: auto;
    padding: 1.7rem 1.4rem 1.5rem;
    border-radius: 18px;
    border: 1px solid var(--line);
    background: var(--panel);
    box-shadow: 0 0 34px rgba(43, 228, 255, 0.18), 0 22px 54px rgba(0, 0, 0, 0.65);
    text-align: center;
    word-break: keep-all;
    animation: lightboxZoomIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1);
}

.together-dialog .lobby-face { width: 84px; height: 84px; font-size: 2rem; margin: 0 auto 0.8rem; display: flex; }

.together-dialog-face { position: relative; width: 84px; height: 84px; margin: 0 auto 0.9rem; }
.together-dialog-face .lobby-face { margin: 0; }

/* Waiting for an answer: a ring that turns round the face. */
.together-dialog-face.waiting::after {
    content: '';
    position: absolute;
    inset: -8px;
    border-radius: 50%;
    border: 3px solid transparent;
    border-top-color: var(--cyan);
    border-right-color: var(--magenta);
    animation: togetherSpin 1.1s linear infinite;
}

@keyframes togetherSpin { to { transform: rotate(360deg); } }

.together-dialog-title {
    font-size: 1.25rem;
    font-weight: 700;
    line-height: 1.45;
}

.together-dialog-title b { color: var(--gold); }
.together-dialog-sub { font-size: 0.95rem; color: var(--muted); margin-top: 0.3rem; min-height: 1.4rem; }

/* Three across, every tile the same size however many there are; a row
   that is not full sits in the middle rather than against the left edge. */
.together-games {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.8rem;
    margin: 1.2rem 0 0.4rem;
}

.together-game {
    flex: 0 0 calc((100% - 1.6rem) / 3);
    min-width: 0;
    display: flex;
    flex-direction: column;
    overflow: hidden;
    border-radius: 14px;
    border: 2px solid var(--line);
    background: var(--panel-2);
    color: var(--ink);
    font: inherit;
    cursor: pointer;
    transition: transform 0.12s ease, border-color 0.15s ease, box-shadow 0.15s ease;
}

/* Four games: four to the row, each a little smaller. */
.together-games.per-4 .together-game { flex-basis: calc((100% - 2.4rem) / 4); }
.together-games.per-4 .together-game-name { font-size: 0.82rem; letter-spacing: 0.04em; }
.together-games.per-2 .together-game { flex-basis: calc((100% - 0.8rem) / 2); }

.together-game:hover, .together-game:focus-visible {
    transform: translateY(-3px);
    border-color: var(--cyan);
    box-shadow: 0 0 22px rgba(43, 228, 255, 0.35);
}

.together-game img { width: 100%; aspect-ratio: 16 / 10; object-fit: cover; display: block; }
.together-game-name { padding: 0.6rem 0.5rem 0.15rem; font-family: var(--font-display); font-weight: 700; font-size: 0.95rem; letter-spacing: 0.06em; }
.together-game-ko { padding: 0 0.5rem 0.25rem; font-size: 0.9rem; color: var(--muted); }

/* Under each game: how that game stands between the two of them. */
.together-game-record {
    display: flex;
    justify-content: center;
    gap: 0.4rem;
    min-height: 2rem;
    padding: 0 0.5rem 0.65rem;
    font-size: 0.86rem;
    font-weight: 700;
}

.together-game-record .win { color: var(--lime); }
.together-game-record .loss { color: #ff9a9a; }
.together-game-record .draw { color: var(--soft); }
.together-game-record.none { font-weight: 600; color: var(--muted); opacity: 0.8; }

.together-dialog-record { margin-top: 0.7rem; }

.together-wait-bar {
    height: 6px;
    margin: 1.2rem 0 1.1rem;
    border-radius: 999px;
    background: rgba(43, 228, 255, 0.12);
    overflow: hidden;
}

.together-wait-bar span {
    display: block;
    height: 100%;
    transform-origin: left center;
    background: linear-gradient(90deg, var(--cyan), var(--magenta));
    animation: lobbyDrain 30s linear forwards;
}

.together-dialog-buttons { display: flex; justify-content: center; gap: 0.6rem; margin-top: 1.1rem; }

@media (max-width: 720px) {
    .together { padding: 1.1rem 1rem 1.2rem; }
    .together-members { grid-template-columns: repeat(auto-fill, minmax(128px, 1fr)); gap: 0.7rem; }
    .together-face, .together-face .lobby-face { width: 58px; height: 58px; }
    .together-face .lobby-face { font-size: 1.35rem; }
    .together-code { font-size: 1.2rem; }
}

/* On a phone three across would be three postage stamps, and two rows of
   tiles made the card taller than the screen. So there the games are a
   list: a small picture, the name beside it, and how it stands at the end
   of the line. */
@media (max-width: 560px) {
    .together-dialog { padding: 1.3rem 1rem 1.2rem; }
    .together-dialog-face, .together-dialog .lobby-face { width: 64px; height: 64px; }
    .together-dialog .lobby-face { font-size: 1.5rem; }
    .together-dialog-face { margin-bottom: 0.7rem; }
    .together-dialog-title { font-size: 1.12rem; }

    .together-games { flex-direction: column; flex-wrap: nowrap; gap: 0.55rem; margin-top: 1rem; }
    .together-game {
        flex: none;
        display: grid;
        grid-template-columns: 96px 1fr auto;
        grid-template-rows: 1fr 1fr;
        column-gap: 0.8rem;
        align-items: center;
        text-align: left;
    }
    .together-game img { grid-column: 1; grid-row: 1 / 3; width: 96px; height: 60px; aspect-ratio: auto; }
    .together-game-name { grid-column: 2; grid-row: 1; align-self: end; padding: 0; }
    .together-game-ko { grid-column: 2; grid-row: 2; align-self: start; padding: 0; }
    .together-game-record { grid-column: 3; grid-row: 1 / 3; align-items: center; min-height: 0; padding: 0 0.9rem 0 0; }
}

@media (prefers-reduced-motion: reduce) {
    .lobby-toast, .together-live, .together-dialog, .together-dialog-face.waiting::after { animation: none !important; }
    .together-member, .together-game { transition: none !important; }
}
