* {
    box-sizing: border-box;
}

:root {
    --theme-primary: #2f7d32;
    --theme-secondary: #8bc34a;
    --theme-accent: #ffca28;
    --theme-panel: rgba(255, 255, 255, 0.94);
    --theme-soft: #eef9e9;
    --theme-text: #203124;
}

body {
    position: relative;
    min-height: 100vh;
    margin: 0;
    padding: 14px;
    overflow-x: hidden;

    font-family: "Trebuchet MS", Arial, sans-serif;
    text-align: center;
    color: var(--theme-text);

    background:
        radial-gradient(circle at 15% 15%, rgba(255,255,255,.65), transparent 26%),
        linear-gradient(145deg, var(--theme-soft), #ffffff 55%, var(--theme-secondary));
    background-attachment: fixed;
}

body.theme-jungle {
    --theme-primary: #257a3e;
    --theme-secondary: #a7df75;
    --theme-accent: #ffd54f;
    --theme-soft: #e4f8df;
    --theme-text: #183c25;
}

body.theme-space {
    --theme-primary: #5146c7;
    --theme-secondary: #7f7cff;
    --theme-accent: #ffd54f;
    --theme-soft: #e9e8ff;
    --theme-text: #1d1c48;

    background:
        radial-gradient(circle at 12% 18%, #ffffff 0 2px, transparent 3px),
        radial-gradient(circle at 72% 14%, #ffffff 0 2px, transparent 3px),
        radial-gradient(circle at 88% 45%, #ffffff 0 1.5px, transparent 2.5px),
        radial-gradient(circle at 33% 75%, #ffffff 0 2px, transparent 3px),
        linear-gradient(145deg, #17163f, #373381 55%, #6a65d8);
    color: #f7f7ff;
}

body.theme-dinosaurs {
    --theme-primary: #8a4d18;
    --theme-secondary: #e2a85d;
    --theme-accent: #76c85a;
    --theme-soft: #fff0d8;
    --theme-text: #4b2b15;

    background:
        radial-gradient(circle at 15% 15%, rgba(255,255,255,.6), transparent 25%),
        linear-gradient(145deg, #fff0cf, #f3c37e 55%, #8bcf6a);
}

.background-decoration::before,
.background-decoration::after {
    position: fixed;
    z-index: -1;
    pointer-events: none;
    opacity: .24;
    font-size: clamp(90px, 14vw, 190px);
}

.theme-jungle .background-decoration::before {
    content: "🌿";
    left: 1vw;
    bottom: 2vh;
}

.theme-jungle .background-decoration::after {
    content: "🐒";
    right: 2vw;
    top: 8vh;
}

.theme-space .background-decoration::before {
    content: "🪐";
    left: 1vw;
    bottom: 3vh;
}

.theme-space .background-decoration::after {
    content: "🚀";
    right: 2vw;
    top: 9vh;
}

.theme-dinosaurs .background-decoration::before {
    content: "🌋";
    left: 1vw;
    bottom: 2vh;
}

.theme-dinosaurs .background-decoration::after {
    content: "🦕";
    right: 2vw;
    top: 8vh;
}

button,
input,
select {
    font: inherit;
}

h1 {
    margin: 5px 0;
    color: var(--theme-primary);
    font-size: clamp(30px, 5vw, 48px);
    text-shadow: 0 2px 0 rgba(255,255,255,.65);
}

.theme-space h1,
.theme-space header p {
    color: white;
    text-shadow: 0 2px 4px rgba(0,0,0,.55);
}

header p {
    margin: 5px 0 14px;
    font-size: 18px;
    font-weight: bold;
}

.hidden {
    display: none !important;
}

#setup-screen {
    width: 100%;
    max-width: 900px;
    margin: 24px auto;
    padding: 26px;

    background: var(--theme-panel);
    border: 4px solid var(--theme-primary);
    border-radius: 24px;
    box-shadow: 0 12px 30px rgba(0,0,0,.18);
}

#setup-screen h2 {
    margin-top: 0;
    color: var(--theme-primary);
    font-size: 30px;
}

.setup-group {
    margin: 24px 0;
    padding: 16px;

    border-radius: 18px;
    background: rgba(255,255,255,.68);
}

.setup-group h3 {
    margin-top: 0;
}

.choice-row {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 14px;
}


.choice-card {
    min-height: 120px;
    padding: 15px;

    border: 4px solid transparent;
    border-radius: 18px;

    background: white;
    color: #222;
    box-shadow: 0 5px 14px rgba(0,0,0,.12);

    cursor: pointer;

    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
}

.choice-card:hover {
    transform: translateY(-2px);
}

.choice-card.selected {
    border-color: var(--theme-primary);
    background: var(--theme-soft);
}

.choice-icon {
    font-size: 42px;
}

.choice-card strong {
    font-size: 20px;
}

.choice-card small {
    color: #555;
    line-height: 1.35;
}

#setup-screen label {
    display: block;
    margin: 14px 0 8px;
    font-size: 18px;
    font-weight: bold;
}

#player-count {
    width: 180px;
    padding: 10px;
    border: 2px solid var(--theme-primary);
    border-radius: 10px;
    font-size: 17px;
}

#player-name-fields {
    margin-top: 18px;
}

.player-name-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 10px 0;
}

.player-color-box {
    width: 26px;
    height: 26px;

    border: 2px solid #555;
    border-radius: 6px;
}

.player-name-input {
    width: 250px;
    padding: 10px;

    border: 2px solid var(--theme-primary);
    border-radius: 10px;

    font-size: 16px;
}

#start-button {
    padding: 15px 34px;

    border: none;
    border-radius: 16px;

    background: linear-gradient(90deg, var(--theme-primary), var(--theme-secondary));
    color: white;

    font-size: 22px;
    font-weight: bold;
    cursor: pointer;
}

#game-container {
    width: 100%;
    max-width: 1220px;
    margin: 0 auto;
    padding: 14px;

    background: var(--theme-panel);
    border: 4px solid var(--theme-primary);
    border-radius: 22px;
    box-shadow: 0 12px 30px rgba(0,0,0,.18);
}

.top-line {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 34px;
}

.top-line h2 {
    margin: 5px 0;
}

#game-mode-label {
    margin: 3px 0;
    color: var(--theme-primary);
    font-weight: bold;
}

#scoreboard {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: 8px 0 14px;
}

.score-item {
    padding: 8px 13px;

    border: 3px solid transparent;
    border-radius: 999px;

    font-weight: bold;
}

.score-item.active {
    border-color: #222;
    transform: scale(1.05);
}

#main-area {
    display: flex;
    align-items: flex-start;
    justify-content: center;
    gap: 18px;
}

#letter-grid {
    display: grid;
    width: max-content;

    border: 4px solid var(--theme-primary);
    border-radius: 10px;
    overflow: hidden;

    background: white;
}

.letter-cell {
    display: flex;
    align-items: center;
    justify-content: center;

    border: 1px solid #aab3bb;
    background: white;

    font-family: "Courier New", monospace;
    font-weight: bold;

    user-select: none;
    -webkit-user-select: none;
}

#side-panel {
    width: 260px;
    flex: 0 0 260px;
}

.panel-box {
    margin-bottom: 10px;
    padding: 11px;

    border: 2px solid var(--theme-primary);
    border-radius: 13px;

    background: rgba(255,255,255,.92);
    text-align: left;
}

.panel-box h3 {
    margin: 0 0 8px;
    color: var(--theme-primary);
    text-align: center;
}

.panel-box p {
    margin: 5px 0;
}

#seed-list {
    max-height: 250px;
    overflow-y: auto;

    margin-top: 10px;
    padding: 8px;

    border: 1px solid #aaa;
    border-radius: 8px;
    background: white;

    font-family: "Courier New", monospace;
}

.seed-word-found {
    font-weight: bold;
    text-decoration: line-through;
}

.player-key-row {
    display: flex;
    align-items: center;
    gap: 8px;
    margin: 5px 0;
}

.player-key-color {
    width: 22px;
    height: 22px;

    border: 1px solid #555;
    border-radius: 4px;
}

#word-controls {
    margin-top: 16px;
    padding: 15px;

    border-top: 2px solid var(--theme-primary);
}

#word-controls label {
    display: block;
    margin-bottom: 10px;
    font-size: 18px;
    font-weight: bold;
}

#input-row {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
}

#word-input {
    width: 220px;
    padding: 11px 13px;

    border: 3px solid var(--theme-primary);
    border-radius: 12px;

    font-size: 18px;
    text-transform: uppercase;
}

button {
    padding: 10px 14px;

    border: none;
    border-radius: 10px;

    background: var(--theme-primary);
    color: white;

    font-size: 15px;
    font-weight: bold;
    cursor: pointer;
}

button:hover {
    opacity: .86;
}

button:disabled {
    cursor: not-allowed;
    opacity: .45;
}

#skip-button {
    background: #e38b00;
}

#finish-button {
    background: #a9283d;
}

#new-game-button {
    background: #596579;
}

#change-players-button {
    background: #7647bd;
}

#status-message {
    min-height: 24px;
    margin: 13px 0 0;

    font-size: 18px;
    font-weight: bold;
}

@media (max-width: 1020px) {
    #main-area {
        flex-direction: column;
        align-items: center;
    }

    #side-panel {
        width: 100%;
        max-width: 720px;
        flex: none;

        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
        gap: 10px;
    }

    .panel-box {
        margin-bottom: 0;
    }
}

@media (max-width: 760px) {
    body {
        padding: 6px;
    }

    .choice-row {
        grid-template-columns: 1fr;
    }

    .choice-card {
        min-height: 95px;
    }

    #game-container {
        overflow-x: auto;
    }

    #side-panel {
        grid-template-columns: 1fr;
    }
}

@media (max-width: 600px) {
    #input-row {
        flex-direction: column;
    }

    #word-input,
    #input-row button {
        width: 100%;
        max-width: 320px;
    }
}


/* Space-theme readability fix */
#game-container,
#setup-screen,
.panel-box,
.letter-cell,
#seed-list,
#word-controls,
#current-player,
#timer,
.player-key-row {
    color: var(--theme-text);
}

.theme-space #game-container,
.theme-space #setup-screen,
.theme-space .panel-box,
.theme-space .letter-cell,
.theme-space #seed-list,
.theme-space #word-controls,
.theme-space #current-player,
.theme-space #timer,
.theme-space .player-key-row {
    color: #1d1c48;
}

.theme-space .letter-cell {
    color: #17163f;
    background: #ffffff;
}

.theme-space .panel-box,
.theme-space #game-container {
    background: rgba(255, 255, 255, 0.96);
}

.theme-space #status-message {
    color: #1d1c48;
}

.theme-space #word-input {
    color: #1d1c48;
    background: #ffffff;
}


/* Touch and mouse drag selection */
#letter-grid {
    touch-action: none;
    cursor: crosshair;
}

.letter-cell {
    touch-action: none;
}

.letter-cell.drag-selected {
    background: var(--theme-accent) !important;
    color: #111 !important;
    transform: scale(1.05);
    box-shadow:
        inset 0 0 0 2px var(--theme-primary);
    z-index: 2;
}


/* Main mode launcher */
.mode-launcher,
.online-card {
    width: min(900px, 100%);
    margin: 28px auto;
    padding: 28px;
    border: 4px solid var(--theme-primary);
    border-radius: 24px;
    background: var(--theme-panel);
    box-shadow: 0 12px 30px rgba(0,0,0,.18);
}

.mode-launcher h2,
.online-card h2 {
    color: var(--theme-primary);
}

.mode-cards,
.online-action-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 18px;
}

.mode-card {
    min-height: 220px;
    padding: 24px;
    border: 4px solid var(--theme-primary);
    border-radius: 20px;
    background: white;
    color: #222;
    text-decoration: none;
    box-shadow: 0 7px 18px rgba(0,0,0,.12);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 12px;
}

.mode-card:hover {
    transform: translateY(-3px);
}

.mode-icon {
    font-size: 58px;
}

.mode-card strong {
    font-size: 25px;
}

.mode-card span:last-child {
    max-width: 300px;
    line-height: 1.45;
}

.online-back-row {
    text-align: left;
}

.back-link {
    color: var(--theme-primary);
    font-weight: bold;
    text-decoration: none;
}

.online-card label {
    display: block;
    margin: 12px 0 7px;
    font-weight: bold;
}

.online-card input,
.online-card select {
    width: min(340px, 100%);
    padding: 11px 13px;
    border: 2px solid var(--theme-primary);
    border-radius: 10px;
    background: white;
    color: #222;
}

.online-action-grid {
    margin-top: 22px;
}

.online-action-box {
    padding: 20px;
    border: 2px solid var(--theme-primary);
    border-radius: 16px;
    background: rgba(255,255,255,.86);
}

.online-action-box button {
    margin-top: 14px;
}

.room-code-display {
    margin: 16px auto;
    font-family: "Courier New", monospace;
    font-size: clamp(42px, 10vw, 72px);
    font-weight: bold;
    letter-spacing: 9px;
    color: var(--theme-primary);
}

#online-game-container {
    width: 100%;
    max-width: 1220px;
    margin: 0 auto;
    padding: 14px;
    color: var(--theme-text);
    background: var(--theme-panel);
    border: 4px solid var(--theme-primary);
    border-radius: 22px;
    box-shadow: 0 12px 30px rgba(0,0,0,.18);
}

#online-scoreboard {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin: 8px 0 14px;
}

#online-letter-grid {
    display: grid;
    width: max-content;
    border: 4px solid var(--theme-primary);
    border-radius: 10px;
    overflow: hidden;
    background: white;
    touch-action: none;
    cursor: crosshair;
}

#online-letter-grid .letter-cell {
    color: #1d1c48;
    background: white;
    touch-action: none;
}

#online-room-label {
    margin: 3px 0;
    font-weight: bold;
}

.danger-button {
    background: #a9283d !important;
}

.theme-space #online-game-container,
.theme-space .online-card,
.theme-space .online-action-box {
    color: #1d1c48;
}

.theme-space #online-game-container .panel-box,
.theme-space #online-game-container #word-controls {
    color: #1d1c48;
}

@media (max-width: 760px) {
    .mode-cards,
    .online-action-grid {
        grid-template-columns: 1fr;
    }

    .mode-card {
        min-height: 165px;
    }
}

#online-build-marker {
    margin: 4px 0 12px;
    font-size: 13px;
    font-weight: bold;
    opacity: 0.72;
}

.competition-note {
    font-weight: bold;
    color: var(--theme-primary);
}





/* Persistent first-letter hint until the hinted word is found */
#online-letter-grid .letter-cell.hint-flash {
    position: relative;
    z-index: 10;
    color: #000 !important;
    background: #fff200 !important;
    border-color: #ff5a00 !important;
    box-shadow:
        inset 0 0 0 4px #ff5a00,
        0 0 22px 10px rgba(255, 242, 0, 1);
    animation: persistent-first-letter-hint 0.55s ease-in-out infinite alternate;
}

@keyframes persistent-first-letter-hint {
    from {
        transform: scale(1);
        background: #fff200 !important;
        filter: brightness(1);
    }

    to {
        transform: scale(1.22);
        background: #ff8c00 !important;
        filter: brightness(1.25);
    }
}


/* Large winner popup */
.winner-popup {
    position: fixed;
    inset: 0;
    z-index: 5000;

    display: flex;
    align-items: center;
    justify-content: center;

    padding: 20px;
    background: rgba(15, 20, 40, 0.82);
    backdrop-filter: blur(5px);
}

.winner-popup-card {
    width: min(620px, 96vw);
    padding: 34px 28px;

    border: 6px solid #ffd700;
    border-radius: 28px;

    background:
        radial-gradient(circle at top, #fffbe2, #ffffff 55%);
    color: #222;

    text-align: center;
    box-shadow:
        0 18px 60px rgba(0, 0, 0, 0.45),
        0 0 40px rgba(255, 215, 0, 0.8);

    animation: winner-popup-enter 0.45s ease-out;
}

.winner-popup-emoji {
    font-size: clamp(54px, 10vw, 92px);
    margin-bottom: 8px;

    animation: winner-trophy-bounce 0.8s ease-in-out infinite alternate;
}

.winner-popup-card h2 {
    margin: 8px 0 12px;
    color: #7a4df3;
    font-size: clamp(34px, 7vw, 58px);
}

#winner-popup-scores {
    margin: 12px 0 24px;
    font-size: clamp(20px, 4vw, 30px);
    font-weight: bold;
}

.winner-popup-actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 12px;
}

.winner-popup-actions button {
    min-width: 180px;
    padding: 14px 20px;
    font-size: 20px;
}

.winner-popup-note {
    margin-top: 16px;
    font-size: 14px;
    opacity: 0.75;
}

@keyframes winner-popup-enter {
    from {
        opacity: 0;
        transform: scale(0.72);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@keyframes winner-trophy-bounce {
    from {
        transform: translateY(0) rotate(-2deg);
    }

    to {
        transform: translateY(-10px) rotate(2deg);
    }
}


/* Build 22: actual local + online phone layout */
@media (max-width: 760px) {
    html,
    body {
        width: 100%;
        max-width: 100%;
        margin: 0;
        overflow-x: hidden !important;
    }

    #game-screen,
    #online-game-container {
        width: 100% !important;
        max-width: 100% !important;
        margin: 0 !important;
        padding: 6px !important;
        border-left-width: 3px !important;
        border-right-width: 3px !important;
        box-sizing: border-box !important;
    }

    #main-area {
        display: flex !important;
        flex-direction: column !important;
        align-items: center !important;
        gap: 10px !important;
        width: 100% !important;
        max-width: 100% !important;
    }

    #letter-grid,
    #online-letter-grid {
        width: max-content !important;
        max-width: calc(100vw - 18px) !important;
        margin: 0 auto !important;
        box-sizing: border-box !important;
        border-width: 3px !important;
    }

    #letter-grid .letter-cell,
    #online-letter-grid .letter-cell {
        min-width: 0 !important;
        min-height: 0 !important;
        padding: 0 !important;
        line-height: 1 !important;
        box-sizing: border-box !important;
    }

    #side-panel {
        width: 100% !important;
        max-width: 100% !important;
        flex: 0 0 auto !important;
    }

    .panel-box {
        width: 100% !important;
        box-sizing: border-box !important;
    }

    #game-info,
    #word-controls {
        width: 100% !important;
        max-width: 100% !important;
        box-sizing: border-box !important;
    }

    header {
        padding-left: 6px;
        padding-right: 6px;
    }
}


/* Phone-only level restrictions */
.large-screen-only-badge {
    display: inline-block;
    margin-top: 7px;
    padding: 4px 8px;
    border-radius: 999px;
    background: #5a4ad1;
    color: #fff;
    font-size: 12px;
    font-weight: 800;
}

.adventure-choice.phone-level-disabled {
    opacity: 0.48;
    cursor: not-allowed;
    filter: grayscale(0.65);
}

.adventure-choice.phone-level-disabled:hover {
    transform: none;
}


.phone-level-note {
    margin: 14px auto 18px;
    max-width: 760px;
    padding: 14px 18px;
    border: 3px solid #ff9800;
    border-radius: 16px;
    background: #fff3b0;
    color: #5a3a00;
    font-weight: 800;
    text-align: center;
    box-shadow:
        0 5px 16px rgba(255, 152, 0, 0.28),
        inset 0 0 0 2px rgba(255, 255, 255, 0.65);
}

.phone-level-note strong {
    color: #3d32b6;
}

@media (min-width: 700px) {
    .phone-level-note {
        display: none;
    }
}


.phone-level-popup {
    position: fixed;
    inset: 0;
    z-index: 6000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 18px;
    background: rgba(20, 20, 35, 0.82);
}

.phone-level-popup-card {
    width: min(92vw, 430px);
    padding: 28px 22px;
    border: 5px solid #ff9800;
    border-radius: 24px;
    background: #fff8c9;
    color: #4d3200;
    text-align: center;
    box-shadow:
        0 18px 50px rgba(0, 0, 0, 0.45),
        0 0 28px rgba(255, 193, 7, 0.85);
    animation: phone-level-popup-in 0.35s ease-out;
}

.phone-level-popup-icon {
    font-size: 58px;
    margin-bottom: 8px;
}

.phone-level-popup-card h2 {
    margin: 4px 0 10px;
    color: #d96b00;
    font-size: 30px;
}

.phone-level-popup-card p {
    margin: 0 0 20px;
    font-size: 18px;
    line-height: 1.4;
    font-weight: 700;
}

.phone-level-popup-card button {
    min-width: 150px;
    padding: 12px 18px;
    font-size: 18px;
    font-weight: 800;
}

@keyframes phone-level-popup-in {
    from {
        opacity: 0;
        transform: scale(0.8);
    }

    to {
        opacity: 1;
        transform: scale(1);
    }
}

@media (min-width: 700px) {
    .phone-level-popup {
        display: none !important;
    }
}


/* Build 24: open room browser and watch mode */
.open-rooms-box {
    margin-top: 18px;
}

.open-rooms-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}

.open-rooms-header h3 {
    margin: 0;
}

.open-rooms-help {
    margin: 8px 0 12px;
    font-size: 14px;
    opacity: 0.82;
}

.open-rooms-list {
    display: grid;
    gap: 10px;
}

.open-room-row {
    display: grid;
    grid-template-columns: 1fr auto;
    align-items: center;
    gap: 10px;

    padding: 10px 12px;
    border-radius: 14px;
    background: rgba(255, 255, 255, 0.76);
    border: 2px solid rgba(90, 74, 209, 0.18);
}

.open-room-details {
    font-weight: 800;
    line-height: 1.35;
}

.open-room-row button {
    min-width: 82px;
    padding: 9px 12px;
    font-size: 15px;
}

.open-room-row button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.open-rooms-empty {
    word-break: break-word;
    margin: 0;
    padding: 12px;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.7);
    text-align: center;
    font-weight: 700;
}

@media (max-width: 700px) {
    .open-room-row {
        grid-template-columns: 1fr;
        text-align: center;
    }

    .open-room-row button {
        width: 100%;
    }
}


/* Build 27: four-player online rooms */
#online-scoreboard {
    flex-wrap: wrap;
    max-width: 900px;
    margin-left: auto;
    margin-right: auto;
}

@media (max-width: 700px) {
    #online-scoreboard .score-item {
        font-size: 14px !important;
        padding: 7px 10px !important;
    }
}


/* Build 30: duplicate-name clarity */
#online-scoreboard .score-item {
    white-space: nowrap;
}


/* Build 31: Join + Watch button rules */
.open-room-actions {
    display: flex;
    align-items: center;
    justify-content: flex-end;
    gap: 8px;
    flex-wrap: wrap;
}

.open-room-actions button {
    min-width: 82px;
}

@media (max-width: 700px) {
    .open-room-actions {
        justify-content: center;
        width: 100%;
    }

    .open-room-actions button {
        flex: 1 1 110px;
    }
}


/* Build 32: active room heartbeat */
.open-rooms-help::after {
    content: " Rooms disappear automatically when players leave or disconnect.";
    opacity: 0.75;
}


/* Build 33: public rooms first, private code secondary */
.create-room-box {
    order: 1;
}

.open-rooms-box {
    order: 2;
}

.private-code-box {
    order: 3;
    max-width: 620px;
    margin-left: auto;
    margin-right: auto;
    background: rgba(245, 242, 255, 0.82);
}

.private-code-box h2::after {
    content: " 🔒";
}

.private-code-help {
    margin: 12px auto 0;
    max-width: 420px;
    font-size: 14px;
    opacity: 0.8;
    line-height: 1.35;
}

.open-rooms-box h3::before {
    content: "🌎 ";
}

.open-rooms-box {
    background:
        linear-gradient(
            180deg,
            rgba(255, 255, 255, 0.96),
            rgba(244, 255, 245, 0.9)
        );
}

@media (min-width: 701px) {
    .private-code-box {
        padding-top: 22px;
        padding-bottom: 22px;
    }

    .private-code-box input {
        max-width: 260px;
    }
}

@media (max-width: 700px) {
    .private-code-box {
        width: 100%;
    }
}


#cache-proof-marker {
    margin: 4px auto 12px;
    padding: 6px 12px;
    display: inline-block;
    border-radius: 999px;
    background: #fff3b0;
    color: #7a4b00;
    border: 2px solid #ff9800;
    font-weight: 900;
    font-size: 14px;
}


/* Build 37: separate public and private room creation */
.create-room-buttons {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 10px;
    margin-top: 12px;
}

.create-room-buttons button {
    min-width: 180px;
}

#create-private-room-button {
    background: #5b4ac9;
}

#create-public-room-button::before {
    content: "🌎 ";
}

#create-private-room-button::before {
    content: "🔒 ";
}

@media (max-width: 700px) {
    .create-room-buttons button {
        width: 100%;
    }
}


/* Build 38: private room list + quick chat */
.quick-chat-panel {
    display: flex;
    flex-direction: column;
    gap: 8px;
}

.online-chat-messages {
    height: 130px;
    overflow-y: auto;
    padding: 8px;
    border: 2px solid rgba(90, 74, 209, 0.18);
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.75);
    font-size: 14px;
    line-height: 1.3;
}

.online-chat-message {
    margin-bottom: 6px;
    word-break: break-word;
}

.online-chat-input-row {
    display: grid;
    grid-template-columns: 1fr auto;
    gap: 8px;
}

.online-chat-input-row input {
    min-width: 0;
    padding: 8px;
    font-size: 14px;
}

.online-chat-input-row button {
    padding: 8px 12px;
    font-size: 14px;
}

.open-room-details {
    text-align: left;
}

@media (max-width: 700px) {
    .online-chat-messages {
        height: 110px;
    }

    .open-room-details {
        text-align: center;
    }
}


/* Build 39: cleaner PC side-panel layout + distinct chat */
@media (min-width: 850px) {
    #main-area {
        align-items: flex-start;
        gap: 22px;
    }

    #side-panel {
        width: 290px;
        display: flex;
        flex-direction: column;
        gap: 12px;
    }

    #side-panel .panel-box {
        margin-bottom: 0;
    }

    .game-info-panel {
        background:
            linear-gradient(
                180deg,
                rgba(249, 255, 250, 0.98),
                rgba(235, 255, 240, 0.95)
            );
    }

    .rules-panel {
        background:
            linear-gradient(
                180deg,
                rgba(255, 255, 255, 0.96),
                rgba(250, 250, 250, 0.92)
            );
        opacity: 0.96;
    }

    .rules-panel h3 {
        color: #23743c;
    }
}

.quick-chat-panel {
    border-color: #5b8cff !important;
    background:
        linear-gradient(
            180deg,
            #eef5ff,
            #f8fbff
        ) !important;
    box-shadow:
        0 8px 22px rgba(47, 94, 190, 0.14),
        inset 0 0 0 1px rgba(255, 255, 255, 0.9);
}

.quick-chat-panel h3 {
    color: #2457b8 !important;
}

.online-chat-messages {
    background:
        linear-gradient(
            180deg,
            #ffffff,
            #f4f8ff
        ) !important;
    border-color: #a9c4ff !important;
}

.online-chat-message {
    margin-bottom: 8px;
    padding: 7px 9px;
    border-radius: 12px;
    background: #eaf2ff;
    border: 1px solid #c7d9ff;
}

.online-chat-message strong {
    color: #2457b8;
}

.online-chat-input-row input {
    border-color: #9bbcff !important;
}

.online-chat-input-row button {
    background: #3c6fe0 !important;
}

.online-chat-input-row button:hover {
    filter: brightness(1.05);
}

@media (max-width: 849px) {
    .quick-chat-panel {
        order: 3;
    }

    .rules-panel {
        opacity: 1;
    }
}


/* Build 40: move Live Chat under the grid on PC */
@media (min-width: 850px) {
    #grid-chat-column {
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 14px;
        width: auto;
        max-width: 100%;
    }

    #grid-chat-column .quick-chat-panel {
        width: 100%;
        max-width: 540px;
        min-height: 170px;
        box-sizing: border-box;
    }

    #grid-chat-column .online-chat-messages {
        height: 92px;
    }

    #grid-chat-column .online-chat-input-row {
        grid-template-columns: 1fr auto;
    }

    #side-panel {
        align-self: flex-start;
    }
}

@media (max-width: 849px) {
    #grid-chat-column {
        width: 100%;
        display: flex;
        flex-direction: column;
        align-items: center;
        gap: 12px;
    }

    #grid-chat-column .quick-chat-panel {
        width: 100%;
        box-sizing: border-box;
    }
}


/* Build 42: demo watch room */
.open-room-row:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 16px rgba(90, 74, 209, 0.12);
}


/* Build 43: always-visible demo room */
.demo-room-row {
    background:
        linear-gradient(
            90deg,
            #fff8d8,
            #f2fbff
        ) !important;
    border-color: #ffcf4d !important;
}

.demo-room-row .open-room-details {
    font-weight: 900;
}

.demo-room-row button {
    background: #f2a900 !important;
    color: #1d1600 !important;
}

.secondary-demo-button {
    margin: 10px 8px;
    padding: 12px 22px;
    border: none;
    border-radius: 10px;
    background: #2e7d32;
    color: white;
    font-weight: 800;
    font-size: 1rem;
    cursor: pointer;
}

.secondary-demo-button:hover {
    filter: brightness(1.05);
}


/* Public v2 fun pack */
.sound-toggle-button {
    margin-top: 8px;
    padding: 8px 14px;
    border: 2px solid rgba(255, 255, 255, 0.8);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.88);
    color: #1f4f2b;
    font-weight: 900;
    cursor: pointer;
}

.emoji-picker {
    width: 100%;
    max-width: 360px;
    margin-bottom: 14px;
}

.theme-ocean {
    --theme-main: #0277bd;
    --theme-dark: #014f86;
    --theme-light: #e0f7fa;
    --theme-accent: #00acc1;
}

.theme-ocean header {
    background: linear-gradient(135deg, #e0f7fa, #b3e5fc, #80deea);
}

.theme-ocean .online-card,
.theme-ocean .memory-card {
    border-color: #0288d1;
}

.theme-ocean .score-item {
    box-shadow: 0 3px 10px rgba(2, 119, 189, 0.16);
}

.confetti-canvas {
    position: fixed;
    inset: 0;
    z-index: 900;
    pointer-events: none;
}

.memory-page header h1 {
    color: #01579b;
}

.memory-card {
    width: min(760px, calc(100% - 24px));
    margin: 24px auto;
    padding: 22px;
    border: 3px solid #0288d1;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.94);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.10);
}

.memory-top-row {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    font-size: 1.1rem;
}

.memory-grid {
    display: grid;
    grid-template-columns: repeat(4, minmax(54px, 1fr));
    gap: 12px;
    max-width: 520px;
    margin: 0 auto 18px;
}

.memory-tile {
    aspect-ratio: 1;
    border: 3px solid #0288d1;
    border-radius: 18px;
    background: linear-gradient(135deg, #e1f5fe, #b3e5fc);
    font-size: clamp(2rem, 8vw, 3.4rem);
    cursor: pointer;
    transition: transform 0.16s ease, background 0.16s ease;
}

.memory-tile:hover {
    transform: translateY(-2px);
}

.memory-tile.flipped,
.memory-tile.matched {
    background: #ffffff;
}

.memory-tile.matched {
    border-color: #2e7d32;
    box-shadow: 0 0 0 4px rgba(46, 125, 50, 0.14);
}

#memory-message {
    text-align: center;
    font-size: 1.2rem;
    font-weight: 800;
    color: #014f86;
}

.memory-mode {
    background: linear-gradient(135deg, #fff8e1, #e1f5fe);
}

@media (max-width: 560px) {
    .memory-grid {
        gap: 8px;
    }

    .memory-card {
        padding: 14px;
    }
}


/* Emoji Pop mini-game */
.emoji-pop-mode {
    background: linear-gradient(135deg, #fff3e0, #fce4ec);
}

.emoji-pop-card {
    width: min(820px, calc(100% - 24px));
    margin: 24px auto;
    padding: 22px;
    border: 3px solid #f57c00;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.10);
}

.emoji-pop-top-row {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    font-size: 1.15rem;
}

#emoji-target {
    font-size: 2rem;
}

.emoji-play-area {
    position: relative;
    height: min(420px, 58vh);
    min-height: 280px;
    border: 4px dashed #f57c00;
    border-radius: 24px;
    background: linear-gradient(135deg, #fffde7, #ffe0b2);
    overflow: hidden;
}

.emoji-pop-button {
    position: absolute;
    width: 76px;
    height: 76px;
    border: 3px solid #ef6c00;
    border-radius: 50%;
    background: white;
    font-size: 2.4rem;
    cursor: pointer;
    box-shadow: 0 8px 16px rgba(0, 0, 0, 0.16);
    transition: transform 0.1s ease;
}

.emoji-pop-button:active {
    transform: scale(0.92);
}

#emoji-message {
    text-align: center;
    font-size: 1.2rem;
    font-weight: 900;
    color: #bf360c;
}

@media (max-width: 560px) {
    .emoji-pop-card {
        padding: 14px;
    }

    .emoji-play-area {
        min-height: 340px;
    }
}


/* Sectioned main menu */
.game-section {
    margin-top: 22px;
    padding: 18px;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.74);
    border: 2px solid rgba(255, 255, 255, 0.8);
    box-shadow: 0 8px 22px rgba(0, 0, 0, 0.08);
}

.game-section h3 {
    margin: 0 0 14px;
    font-size: 1.35rem;
    color: #1f4f2b;
    text-align: left;
}

.other-games-section {
    background: rgba(255, 248, 225, 0.82);
}

.section-card-grid {
    margin-top: 0;
}

@media (max-width: 560px) {
    .game-section {
        padding: 14px;
    }

    .game-section h3 {
        text-align: center;
    }
}

/* Public v2.3 polish */
.portal-hero {
    max-width: 980px;
    margin: 18px auto 0;
    border-radius: 28px;
    box-shadow: 0 14px 35px rgba(0, 0, 0, 0.12);
}

.game-portal {
    max-width: 980px;
}

.portal-intro {
    text-align: center;
    margin-bottom: 8px;
}

.portal-intro h2 {
    margin-bottom: 4px;
}

.portal-intro p {
    margin-top: 0;
    font-weight: 700;
    color: #36513b;
}

.section-heading-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 14px;
}

.section-heading-row h3 {
    margin: 0;
}

.section-heading-row span {
    display: inline-flex;
    border-radius: 999px;
    padding: 5px 11px;
    background: rgba(255, 255, 255, 0.78);
    color: #35553b;
    font-size: 0.88rem;
    font-weight: 900;
}

.featured-card {
    min-height: 178px;
}

.mode-card {
    transition: transform 0.16s ease, box-shadow 0.16s ease;
}

.mode-card:hover {
    transform: translateY(-4px);
    box-shadow: 0 16px 32px rgba(0, 0, 0, 0.14);
}

.coming-soon-section {
    background: rgba(232, 245, 233, 0.82);
}

.coming-soon-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
    gap: 12px;
}

.coming-soon-card {
    padding: 16px;
    border-radius: 18px;
    background: rgba(255, 255, 255, 0.88);
    border: 2px dashed rgba(46, 125, 50, 0.45);
    font-weight: 900;
    text-align: center;
}

.math-pop-mode {
    background: linear-gradient(135deg, #ede7f6, #e3f2fd);
}

.math-pop-card {
    width: min(820px, calc(100% - 24px));
    margin: 24px auto;
    padding: 22px;
    border: 3px solid #5e35b1;
    border-radius: 22px;
    background: rgba(255, 255, 255, 0.95);
    box-shadow: 0 12px 28px rgba(0, 0, 0, 0.10);
}

.math-pop-top-row {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    font-size: 1.15rem;
}

.math-question-box {
    text-align: center;
    padding: 24px;
    border-radius: 24px;
    background: linear-gradient(135deg, #f3e5f5, #e3f2fd);
    border: 3px solid #7e57c2;
}

#math-question {
    font-size: clamp(2.2rem, 8vw, 4.2rem);
    font-weight: 1000;
    color: #311b92;
    margin-bottom: 20px;
}

.math-answers {
    display: grid;
    grid-template-columns: repeat(2, minmax(90px, 1fr));
    gap: 14px;
    max-width: 440px;
    margin: 0 auto;
}

.math-answer-button {
    padding: 18px;
    border: 3px solid #5e35b1;
    border-radius: 18px;
    background: #ffffff;
    color: #311b92;
    font-size: 1.6rem;
    font-weight: 1000;
    cursor: pointer;
    box-shadow: 0 8px 16px rgba(49, 27, 146, 0.12);
}

.math-answer-button:active {
    transform: scale(0.96);
}

#math-message {
    text-align: center;
    font-size: 1.2rem;
    font-weight: 900;
    color: #311b92;
}

@media (max-width: 560px) {
    .section-heading-row {
        align-items: center;
        flex-direction: column;
    }

    .math-pop-card {
        padding: 14px;
    }

    .math-question-box {
        padding: 16px;
    }

    .math-answers {
        gap: 10px;
    }
}

/* Public v2.4 trophies */
.trophy-mode {
    background: linear-gradient(135deg, #fff8e1, #f3e5f5);
}

.trophy-card {
    width: min(900px, calc(100% - 24px));
    margin: 24px auto;
    padding: 22px;
    border: 3px solid #f9a825;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.12);
}

.score-summary-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
    margin: 18px 0 22px;
}

.score-summary-box {
    padding: 18px;
    border-radius: 20px;
    background: linear-gradient(135deg, #fffde7, #fff8e1);
    border: 2px solid #fbc02d;
    text-align: center;
    font-weight: 900;
}

.score-summary-icon {
    display: block;
    font-size: 2.2rem;
    margin-bottom: 8px;
}

.score-summary-box p {
    margin-bottom: 0;
    color: #5d4037;
}

.badge-section h2 {
    text-align: center;
    margin: 10px 0 16px;
}

.badge-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
    gap: 14px;
}

.badge-card {
    padding: 16px;
    border-radius: 18px;
    border: 2px solid;
    text-align: center;
    min-height: 160px;
}

.badge-icon {
    font-size: 2.3rem;
    margin-bottom: 8px;
}

.badge-card p {
    min-height: 44px;
    margin-bottom: 8px;
}

.badge-card span {
    display: inline-block;
    border-radius: 999px;
    padding: 4px 10px;
    font-weight: 900;
    font-size: 0.88rem;
}

.badge-earned {
    background: linear-gradient(135deg, #fff8e1, #e8f5e9);
    border-color: #43a047;
}

.badge-earned span {
    background: #c8e6c9;
    color: #1b5e20;
}

.badge-locked {
    background: #f5f5f5;
    border-color: #bdbdbd;
    color: #757575;
}

.badge-locked span {
    background: #e0e0e0;
    color: #616161;
}

.trophy-actions {
    display: flex;
    justify-content: center;
    gap: 12px;
    flex-wrap: wrap;
    margin: 22px 0 10px;
}

#trophy-message {
    text-align: center;
    font-weight: 800;
    color: #5d4037;
}

@media (max-width: 560px) {
    .trophy-card {
        padding: 14px;
    }

    .badge-card {
        min-height: 140px;
    }
}

/* Public v2.5 difficulty levels */
.mini-game-difficulty-label {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    font-weight: 900;
}

.mini-game-difficulty-label select {
    border: 2px solid rgba(0, 0, 0, 0.18);
    border-radius: 999px;
    padding: 7px 10px;
    font-weight: 900;
    background: white;
}

.score-summary-box br {
    line-height: 1.7;
}

/* Public v2.6 Vietnamese Match + Spelling Race */
.vietnamese-mode {
    background: linear-gradient(135deg, #e0f7fa, #fff8e1);
}

.spelling-mode {
    background: linear-gradient(135deg, #e8eaf6, #fce4ec);
}

.learning-game-card {
    width: min(840px, calc(100% - 24px));
    margin: 24px auto;
    padding: 22px;
    border: 3px solid #0288d1;
    border-radius: 24px;
    background: rgba(255, 255, 255, 0.96);
    box-shadow: 0 14px 32px rgba(0, 0, 0, 0.12);
}

.spelling-card {
    border-color: #5e35b1;
}

.learning-game-top-row {
    display: flex;
    gap: 14px;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 18px;
    font-size: 1.15rem;
}

.learning-question-box {
    text-align: center;
    padding: 24px;
    border-radius: 24px;
    background: linear-gradient(135deg, #e1f5fe, #fffde7);
    border: 3px solid #4fc3f7;
}

.spelling-card .learning-question-box {
    background: linear-gradient(135deg, #f3e5f5, #e8eaf6);
    border-color: #7e57c2;
}

.learning-small-label {
    margin: 0 0 8px;
    font-weight: 900;
    color: #455a64;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.learning-big-question {
    font-size: clamp(2.1rem, 8vw, 4rem);
    font-weight: 1000;
    color: #01579b;
    margin-bottom: 20px;
    text-transform: capitalize;
}

.spelling-card .learning-big-question {
    color: #311b92;
}

.learning-answer-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(120px, 1fr));
    gap: 14px;
    max-width: 580px;
    margin: 0 auto;
}

.learning-answer-button {
    min-height: 62px;
    padding: 14px;
    border: 3px solid #0288d1;
    border-radius: 18px;
    background: white;
    color: #014f86;
    font-size: 1.2rem;
    font-weight: 1000;
    cursor: pointer;
    box-shadow: 0 8px 16px rgba(1, 87, 155, 0.12);
}

.spelling-answer-button {
    border-color: #5e35b1;
    color: #311b92;
    text-transform: lowercase;
}

.learning-answer-button:active {
    transform: scale(0.96);
}

#vn-message,
#spelling-message {
    text-align: center;
    font-size: 1.2rem;
    font-weight: 900;
    color: #014f86;
}

#spelling-message {
    color: #311b92;
}

@media (max-width: 560px) {
    .learning-game-card {
        padding: 14px;
    }

    .learning-question-box {
        padding: 16px;
    }

    .learning-answer-grid {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .learning-answer-button {
        min-height: 56px;
    }
}


/* Public v2.7 mobile polish + homepage spacing */
:root {
    --mobile-safe-gap: 12px;
}

body {
    -webkit-tap-highlight-color: transparent;
}

button,
.mode-card,
.back-link,
select,
input {
    touch-action: manipulation;
}

.portal-hero,
header {
    width: min(980px, calc(100% - 24px));
}

.launcher-page header.portal-hero {
    padding: clamp(18px, 5vw, 34px);
}

.launcher-page header.portal-hero h1 {
    font-size: clamp(2rem, 7vw, 3.3rem);
    line-height: 1.05;
}

.launcher-page header.portal-hero p {
    font-size: clamp(1rem, 3.5vw, 1.25rem);
    max-width: 640px;
    margin-left: auto;
    margin-right: auto;
}

.mode-launcher.game-portal {
    width: min(980px, calc(100% - 24px));
    margin: 18px auto 34px;
    padding: clamp(14px, 3vw, 24px);
}

.portal-intro {
    padding: 4px 8px 10px;
}

.portal-intro h2 {
    font-size: clamp(1.55rem, 5vw, 2.1rem);
}

.game-section {
    margin-top: clamp(16px, 4vw, 24px);
    padding: clamp(14px, 3.5vw, 22px);
}

.section-heading-row {
    margin-bottom: clamp(12px, 3vw, 18px);
}

.section-heading-row h3 {
    font-size: clamp(1.2rem, 4.5vw, 1.55rem);
}

.section-heading-row span {
    white-space: nowrap;
}

.section-card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 230px), 1fr));
    gap: clamp(12px, 3vw, 18px);
}

.mode-card {
    min-height: 156px;
    padding: clamp(16px, 4vw, 22px);
    border-radius: 22px;
}

.featured-card {
    min-height: 166px;
}

.mode-icon {
    font-size: clamp(2.2rem, 8vw, 3.3rem);
}

.mode-card strong {
    font-size: clamp(1.08rem, 4vw, 1.28rem);
}

.mode-card span:last-child {
    font-size: clamp(0.94rem, 3.2vw, 1.02rem);
    line-height: 1.35;
}

.coming-soon-grid {
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 150px), 1fr));
    gap: clamp(10px, 2.5vw, 14px);
}

.coming-soon-card {
    min-height: 58px;
    display: grid;
    place-items: center;
}

/* General game-page mobile spacing */
.online-card,
.memory-card,
.emoji-pop-card,
.math-pop-card,
.trophy-card,
.learning-game-card {
    width: min(920px, calc(100% - 24px));
    margin-top: clamp(14px, 4vw, 24px);
    padding: clamp(14px, 3.5vw, 22px);
}

.online-back-row {
    margin-bottom: 12px;
}

.back-link {
    display: inline-flex;
    align-items: center;
    min-height: 42px;
    padding: 8px 12px;
}

button {
    min-height: 44px;
}

input,
select {
    min-height: 44px;
    font-size: 16px;
}

.memory-top-row,
.emoji-pop-top-row,
.math-pop-top-row,
.learning-game-top-row {
    gap: 10px;
}

.memory-top-row > *,
.emoji-pop-top-row > *,
.math-pop-top-row > *,
.learning-game-top-row > * {
    min-height: 38px;
}

/* Better game grids on small screens */
.memory-grid {
    width: min(100%, 540px);
}

.emoji-play-area {
    height: min(420px, 56vh);
}

.learning-answer-grid,
.math-answers {
    width: min(100%, 580px);
}

/* Online lobby and game polish */
.online-action-grid {
    gap: clamp(12px, 3vw, 18px);
}

.open-rooms-list {
    gap: 10px;
}

.open-room-row,
.room-row {
    border-radius: 16px;
}

#online-game-container {
    width: min(1120px, calc(100% - 16px));
}

#online-grid {
    max-width: 100%;
    overflow: auto;
    -webkit-overflow-scrolling: touch;
}

#word-controls {
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

#input-row {
    gap: 10px;
}

/* Phone-first refinements */
@media (max-width: 720px) {
    body {
        overflow-x: hidden;
    }

    .launcher-page {
        padding-left: 0;
        padding-right: 0;
    }

    .mode-launcher.game-portal {
        width: min(100% - 16px, 720px);
        margin-top: 12px;
        padding: 12px;
        border-radius: 22px;
    }

    .portal-hero,
    header {
        width: min(100% - 16px, 720px);
        margin-top: 10px;
        border-radius: 22px;
    }

    .game-section {
        padding: 12px;
        border-radius: 20px;
    }

    .section-heading-row {
        align-items: center;
        flex-direction: row;
    }

    .section-heading-row span {
        font-size: 0.78rem;
        padding: 4px 9px;
    }

    .section-card-grid {
        grid-template-columns: 1fr;
        gap: 12px;
    }

    .mode-card {
        min-height: 120px;
        display: grid;
        grid-template-columns: auto 1fr;
        grid-template-areas:
            "icon title"
            "icon desc";
        column-gap: 14px;
        align-items: center;
        text-align: left;
    }

    .mode-card .mode-icon {
        grid-area: icon;
        margin: 0;
        font-size: 2.6rem;
    }

    .mode-card strong {
        grid-area: title;
        align-self: end;
    }

    .mode-card span:last-child {
        grid-area: desc;
        align-self: start;
    }

    .coming-soon-grid {
        grid-template-columns: 1fr 1fr;
    }

    .coming-soon-card {
        padding: 12px 8px;
        font-size: 0.95rem;
    }

    .online-card,
    .memory-card,
    .emoji-pop-card,
    .math-pop-card,
    .trophy-card,
    .learning-game-card {
        width: min(100% - 16px, 720px);
        border-radius: 20px;
    }

    .memory-top-row,
    .emoji-pop-top-row,
    .math-pop-top-row,
    .learning-game-top-row {
        display: grid;
        grid-template-columns: 1fr 1fr;
        align-items: stretch;
    }

    .memory-top-row button,
    .emoji-pop-top-row button,
    .math-pop-top-row button,
    .learning-game-top-row button,
    .mini-game-difficulty-label {
        grid-column: 1 / -1;
        justify-content: center;
    }

    .mini-game-difficulty-label select {
        min-width: 130px;
    }

    .math-question-box,
    .learning-question-box {
        padding: 14px;
        border-radius: 20px;
    }

    .learning-answer-grid,
    .math-answers {
        grid-template-columns: 1fr;
        gap: 10px;
    }

    .learning-answer-button,
    .math-answer-button {
        min-height: 58px;
        font-size: 1.08rem;
    }

    .emoji-play-area {
        min-height: 360px;
        height: 52vh;
    }

    .trophy-actions {
        flex-direction: column;
    }

    .trophy-actions button {
        width: 100%;
    }
}

@media (max-width: 420px) {
    .launcher-page header.portal-hero h1 {
        font-size: 1.85rem;
    }

    .section-heading-row {
        align-items: flex-start;
        flex-direction: column;
        gap: 6px;
    }

    .section-heading-row span {
        align-self: flex-start;
    }

    .mode-card {
        min-height: 112px;
        padding: 14px;
        column-gap: 12px;
    }

    .mode-card .mode-icon {
        font-size: 2.35rem;
    }

    .mode-card strong {
        font-size: 1.03rem;
    }

    .mode-card span:last-child {
        font-size: 0.92rem;
    }

    .coming-soon-grid {
        grid-template-columns: 1fr;
    }

    .memory-grid {
        gap: 7px;
    }

    .memory-tile {
        border-radius: 14px;
    }

    #math-question,
    .learning-big-question {
        font-size: clamp(2rem, 11vw, 3rem);
    }

    .score-summary-grid,
    .badge-grid {
        grid-template-columns: 1fr;
    }
}

/* Landscape phone fix */
@media (max-height: 520px) and (orientation: landscape) {
    .portal-hero,
    header {
        padding-top: 12px;
        padding-bottom: 12px;
    }

    .launcher-page header.portal-hero h1 {
        font-size: 1.8rem;
    }

    .emoji-play-area {
        height: 260px;
        min-height: 240px;
    }
}
/* Center game-page titles on desktop */
@media (min-width: 769px) {
    body:not(.launcher-page) > header {
        margin-left: auto;
        margin-right: auto;
        text-align: center;
    }

    body:not(.launcher-page) > header h1,
    body:not(.launcher-page) > header p {
        margin-left: auto;
        margin-right: auto;
    }
}
/* Version 1.4 shared local player system */
.lm-current-player-button {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    margin: 10px auto 0;
    padding: 9px 14px;
    min-height: 42px;
    border: 2px solid rgba(47, 125, 50, 0.26);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.94);
    color: #184f2b;
    box-shadow: 0 5px 14px rgba(0, 0, 0, 0.12);
    font-weight: 900;
    cursor: pointer;
}

.lm-current-player-button:hover {
    transform: translateY(-1px);
}

.lm-player-modal {
    position: fixed;
    inset: 0;
    z-index: 5000;
    display: grid;
    place-items: center;
    padding: 18px;
    background: rgba(12, 27, 42, 0.72);
    backdrop-filter: blur(4px);
}

.lm-player-modal-card {
    width: min(520px, 100%);
    max-height: min(760px, calc(100vh - 32px));
    overflow-y: auto;
    padding: clamp(20px, 5vw, 30px);
    border: 4px solid #4b73d1;
    border-radius: 28px;
    background: linear-gradient(155deg, #ffffff, #edf7ff);
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.34);
    color: #17325d;
    text-align: center;
}

.lm-player-modal-card h2 {
    margin: 0 0 8px;
    color: #4e42b8;
    font-size: clamp(1.7rem, 6vw, 2.35rem);
}

.lm-player-modal-message {
    margin: 0 0 18px;
    line-height: 1.45;
    font-weight: 700;
}

.lm-saved-player-list {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(135px, 1fr));
    gap: 10px;
}

.lm-saved-player-button {
    min-height: 52px;
    padding: 10px 12px;
    border: 2px solid #b9c9ed;
    border-radius: 15px;
    background: white;
    color: #263e72;
    font-weight: 900;
    cursor: pointer;
}

.lm-saved-player-button.selected {
    border-color: #6d4bd4;
    background: #eee8ff;
    box-shadow: 0 0 0 3px rgba(109, 75, 212, 0.18);
}

.lm-player-divider {
    margin: 17px 0 10px;
    color: #52637e;
    font-size: 0.92rem;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.lm-player-fields {
    display: grid;
    grid-template-columns: 86px 1fr;
    gap: 10px;
}

.lm-player-emoji-select,
.lm-player-name-input {
    width: 100%;
    min-height: 50px;
    border: 2px solid #b8c7e7;
    border-radius: 14px;
    background: white;
}

.lm-player-emoji-select {
    text-align: center;
    font-size: 1.45rem;
}

.lm-player-name-input {
    padding: 10px 13px;
}

.lm-player-modal-actions {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 17px;
}

.lm-player-continue-button {
    min-width: 150px;
    padding: 10px 20px;
    border: 0;
    border-radius: 14px;
    background: linear-gradient(135deg, #5d4cd5, #347fd5);
    color: white;
    font-weight: 900;
    cursor: pointer;
}

.lm-player-continue-button:disabled {
    opacity: 0.45;
    cursor: not-allowed;
}

.profile-mode {
    background: linear-gradient(145deg, #fff4fb, #eadfff);
}

.profile-card {
    width: min(920px, calc(100% - 24px));
    margin: 18px auto 34px;
    padding: clamp(14px, 3.5vw, 24px);
    border: 4px solid var(--theme-primary);
    border-radius: 24px;
    background: var(--theme-panel);
    box-shadow: 0 12px 30px rgba(0, 0, 0, 0.16);
}

.profile-section {
    margin-top: 18px;
    padding: clamp(15px, 3.5vw, 22px);
    border-radius: 20px;
    background: rgba(255, 255, 255, 0.78);
}

.profile-field-label {
    display: grid;
    gap: 7px;
    max-width: 520px;
    margin: 14px auto;
    text-align: left;
    font-weight: 900;
}

.profile-toggle-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 9px;
    margin: 14px 0;
    font-weight: 900;
}

.profile-toggle-row input {
    min-height: auto;
}

.profile-preview-box {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    margin: 16px auto;
    padding: 14px;
    max-width: 360px;
    border-radius: 18px;
    background: #edf6ff;
    font-size: 1.2rem;
}

#profile-preview-emoji {
    font-size: 2rem;
}

.profile-button-row {
    display: flex;
    justify-content: center;
    flex-wrap: wrap;
    gap: 10px;
    margin-top: 14px;
}

.profile-score-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 12px;
}

.profile-score-box {
    padding: 15px;
    border-radius: 17px;
    background: #f3f8ff;
}

.profile-score-box > span {
    display: block;
    margin-bottom: 5px;
    font-size: 2rem;
}

@media (max-width: 520px) {
    .lm-player-fields {
        grid-template-columns: 74px 1fr;
    }

    .lm-saved-player-list {
        grid-template-columns: 1fr;
    }

    .lm-player-modal-card {
        border-width: 3px;
        border-radius: 22px;
    }
}

/* Player popup: optional no-profile and cancel actions */
.lm-player-temporary-button,
.lm-player-cancel-button {
    min-width: 150px;
    padding: 10px 18px;
    border-radius: 14px;
    font-weight: 900;
    cursor: pointer;
}

.lm-player-temporary-button {
    border: 2px solid #2c8f72;
    background: #e9fff7;
    color: #17634e;
}

.lm-player-cancel-button {
    border: 2px solid #aebbd1;
    background: #f6f8fc;
    color: #34445e;
}

.lm-player-temporary-button:hover,
.lm-player-cancel-button:hover {
    transform: translateY(-1px);
}

/* Local v1.5 language match expansion */
.chinese-mode {
    background: linear-gradient(135deg, #fff3e0, #fce4ec);
}

.chinese-card {
    border-color: #d84315;
}

.chinese-card .learning-question-box {
    background: linear-gradient(135deg, #fff8e1, #fce4ec);
    border-color: #ff8a65;
}

.language-controls {
    display: grid;
    grid-template-columns: repeat(2, minmax(180px, 1fr));
    gap: 14px;
    margin: 4px 0 18px;
    padding: 14px;
    border-radius: 18px;
    background: rgba(225, 245, 254, 0.78);
    border: 2px solid rgba(2, 136, 209, 0.24);
}

.chinese-card .language-controls {
    background: rgba(255, 243, 224, 0.84);
    border-color: rgba(216, 67, 21, 0.25);
}

.language-control {
    display: grid;
    gap: 7px;
    font-weight: 900;
    color: #37474f;
}

.language-control select {
    width: 100%;
    min-height: 46px;
    padding: 9px 12px;
    border: 2px solid rgba(2, 136, 209, 0.42);
    border-radius: 14px;
    background: white;
    color: #263238;
    font-weight: 800;
}

.chinese-card .language-control select {
    border-color: rgba(216, 67, 21, 0.42);
}

.language-target-question {
    text-transform: none;
    font-size: clamp(2.4rem, 9vw, 4.6rem);
}

.language-question-pronunciation {
    margin: -12px 0 18px;
    color: #6a1b9a;
    font-size: clamp(1.15rem, 4vw, 1.55rem);
    font-weight: 900;
}

.language-answer-button {
    display: grid;
    place-items: center;
    gap: 3px;
    line-height: 1.2;
}

.language-choice-main {
    font-size: 1.15em;
}

.language-choice-pronunciation {
    color: #7b1fa2;
    font-size: 0.78em;
    font-weight: 800;
}

.language-answer-correct,
.language-answer-correct:disabled {
    border-color: #2e7d32;
    background: #e8f5e9;
    color: #1b5e20;
    opacity: 1;
}

.language-answer-wrong,
.language-answer-wrong:disabled {
    border-color: #c62828;
    background: #ffebee;
    color: #b71c1c;
    opacity: 1;
}

.language-answer-button:disabled {
    cursor: default;
}

#language-message {
    text-align: center;
    font-size: 1.15rem;
    font-weight: 900;
    color: #014f86;
}

.chinese-card #language-message {
    color: #9a3412;
}

@media (max-width: 900px) {
    .language-controls {
        grid-template-columns: repeat(2, minmax(160px, 1fr));
    }
}

@media (max-width: 620px) {
    .language-controls {
        grid-template-columns: 1fr;
        gap: 10px;
        padding: 12px;
    }
}
