/**
 * Møbee Multi - Game Styles
 *
 * Table of Contents:
 * 1. CSS Variables & Reset
 * 2. Base Layout (Body, Header)
 * 3. Game Board & Cards
 * 4. Symbol Positioning (7-symbol & 12-symbol)
 * 5. Card Animations
 * 6. Message Overlay & Countdown
 * 7. Button System
 * 8. Timer Display
 * 9. Footer & Version
 * 10. Modal System
 * 11. Avatar System
 * 12. Lobby Layout
 * 13. Friends Section (Multiplayer)
 * 14. Mobile Responsive (iPhone)
 */

/* =============================================================================
   1. CSS VARIABLES & RESET
   ============================================================================= */

html, body {
    margin: 0;
    padding: 0;
    width: 100%;
    overflow-x: hidden;
    overscroll-behavior-x: none;
}

* { box-sizing: border-box; }

:root {
    /* Colors */
    --bg-color: #f0f4f8;
    --accent: #4a90e2;
    --text: #333;
    --success: #BFCA86;
    --error: #E6A07F;

    /* Card styling */
    --card-border-color: #f7f9d2;
    --card-border-width: 7px;

    /* Card layout (3 hex cards in triangle) */
    --hex-height: 50%;
    --hex-width: 43.33%;
    --spread-radius: 25.5%;
    --symbol-scale: 0.66;

    /* Button system */
    --btn-radius: 18px;
    --btn-font: 1.05rem;
    --btn-pad-y: 14px;
    --btn-pad-x: 18px;
    --btn-maxw: 360px;
    --btn-green: #BEC887;
    --btn-blue: #4a90e2;
    --btn-text: #ffffff;
}

/* =============================================================================
   2. BASE LAYOUT
   ============================================================================= */

body {
    font-family: 'Poppins', sans-serif;
    background-color: var(--bg-color);
    color: var(--text);
    display: flex;
    flex-direction: column;
    align-items: center;
    height: 100vh;
    height: -webkit-fill-available;
    height: 100svh;
    height: 100dvh;
    margin: 0;
    position: relative;
    user-select: none;
    -webkit-user-select: none;
    overscroll-behavior: none;
    padding-top: env(safe-area-inset-top);
    padding-bottom: env(safe-area-inset-bottom);
    overflow: hidden;
}

/* Prevent zoom/pan on touch devices */
@media (pointer: coarse) {
    body { touch-action: none; }
}

header {
    text-align: center;
    z-index: 50;
    margin-top: 10px;
    flex-shrink: 0;
    position: relative;
}

.logo-container {
    display: flex;
    justify-content: center;
    margin-bottom: 5px;
    padding: 0 20px;
}

.logo-img {
    max-width: 80vw;
    height: auto;
    max-height: 12vh;
    width: 400px;
    object-fit: contain;
    cursor: pointer;
}

.stats {
    font-size: 1.4rem;
    margin-top: 0;
    margin-bottom: 5px;
    min-height: 36px;
    font-weight: 600;
    width: 100%;
    max-width: 100%;
    padding: 0 40px;
}

#score-el {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
}

.scores-container {
    display: flex;
    gap: 8px;
    align-items: center;
}

/* =============================================================================
   3. GAME BOARD & CARDS
   ============================================================================= */

#board-container {
    flex: 1;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
    overflow: visible;
    position: relative;
    min-height: 0;
    padding: 0;
    box-sizing: border-box;
    container-type: size;
}

#game-board {
    position: relative;
    /* Scale up to 115% of container to fill more space */
    width: min(115cqw, 115cqh);
    height: min(115cqw, 115cqh);
    max-width: 115%;
    max-height: 115%;
    z-index: 60;
    overflow: visible;
}

.card {
    position: absolute;
    width: var(--hex-width);
    height: var(--hex-height);
    background: transparent;
    transform: translate(-50%, -50%);
    transform-origin: center center;
    transition: transform 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    cursor: pointer;
    filter: drop-shadow(0 4px 6px rgba(0,0,0,0.1));
    -webkit-backface-visibility: hidden;
    overflow: visible;
    -webkit-mask-image: none;
    mask-image: none;
}

.card-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 0;
    overflow: visible;
    pointer-events: none;
    -webkit-mask-image: none;
    mask-image: none;
}

.card-shape {
    fill: #ffffff;
    stroke: var(--card-border-color);
    stroke-width: var(--card-border-width);
    stroke-linejoin: round;
    transition: stroke 0.3s, fill 0.3s;
}

/* Card positions (triangle layout) */
.card:nth-child(1) { top: calc(50% - var(--spread-radius)); left: 50%; }
.card:nth-child(2) { top: calc(50% + (var(--spread-radius) * 0.5)); left: calc(50% + (var(--spread-radius) * 0.866)); }
.card:nth-child(3) { top: calc(50% + (var(--spread-radius) * 0.5)); left: calc(50% - (var(--spread-radius) * 0.866)); }

/* Card hover effect (desktop only) */
@media (hover: hover) {
    .card:hover {
        z-index: 10;
        transform: translate(-50%, -50%) scale(1.05);
        filter: drop-shadow(0 0 10px rgba(74, 144, 226, 0.5));
    }
}

/* Touch device: show shadow on active press */
@media (hover: none) {
    .card {
        transition: filter 0.3s ease-out;
    }
    .card:active {
        filter: drop-shadow(0 0 10px rgba(74, 144, 226, 0.5));
        transition: filter 0s;
    }
}

/* Card correct/wrong states */
.card.correct { z-index: 15; animation: pulse 0.5s; filter: drop-shadow(0 0 15px var(--success)); }
.card.correct .card-shape { stroke: var(--success); fill: #eafaf1; }
.card.wrong { z-index: 15; animation: shake 0.4s; filter: drop-shadow(0 0 15px var(--error)); }
.card.wrong .card-shape { stroke: var(--error); fill: #fcebe9; }

/* Small Møbee logo sticker on card */
.card-symbol-sticker {
    position: absolute;
    bottom: 7.5%;
    left: 50%;
    transform: translateX(-50%);
    pointer-events: none;
    z-index: 5;
}

/* =============================================================================
   4. SYMBOL POSITIONING
   ============================================================================= */

/* --- 7-Symbol Layout (Level 1) --- */

.symbol-container {
    position: absolute;
    width: calc(34% * var(--symbol-scale));
    aspect-ratio: 1 / 1;
    height: auto;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s;
    z-index: 10;
    overflow: visible;
    clip-path: none !important;
    -webkit-clip-path: none !important;
}

.symbol-container img {
    width: 100%;
    height: 100%;
    object-fit: contain;
    transition: transform 0.2s;
    mix-blend-mode: normal;
    filter: drop-shadow(0 0 0.5px rgba(0, 0, 0, 0.6));
}

.game-symbol {
    width: 100%;
    height: 100%;
    object-fit: contain;
    pointer-events: none;
    image-rendering: auto;
    filter: drop-shadow(0 0 0.5px rgba(0, 0, 0, 0.6));
}

.symbol-sprite {
    transform: scale(1);
    transform-origin: center center;
}

@media (hover: hover) {
    .symbol-container:hover { z-index: 20; }
    .symbol-container:hover > div,
    .symbol-container:hover > img {
        transform: scale(1.3);
    }
}

/* 7-symbol positions (center + 6 around) */
.pos-0 { top: 50%; left: 50%; }
.pos-1 { top: 24%; left: 50%; }
.pos-2 { top: 37%; left: 73%; }
.pos-3 { top: 63%; left: 73%; }
.pos-4 { top: 76%; left: 50%; }
.pos-5 { top: 63%; left: 27%; }
.pos-6 { top: 37%; left: 27%; }

/* --- 12-Symbol Layout (Level 2) --- */

.card-12-symbols {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
}

/* 12-symbol cards have beige border */
.card:has(.card-12-symbols) .card-shape {
    stroke: #fff5de;
}

.card-12-symbols .center-logo {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 5%;
    height: auto;
    filter: grayscale(100%) opacity(0.2);
}

.card-12-symbols .symbol-12 {
    position: absolute;
    width: 18%;
    height: auto;
    pointer-events: auto;
    cursor: pointer;
}

.card-12-symbols .symbol-12-img {
    width: 100%;
    height: auto;
    display: block;
    transition: transform 0.15s ease-out;
}

@media (hover: hover) {
    .card-12-symbols .symbol-12:hover { z-index: 20; }
    .card-12-symbols .symbol-12:hover .symbol-12-img { transform: scale(1.3); }
}

.card-12-symbols .symbol-12-img.symbol-clicked {
    transform: scale(1.5);
}

/* 12-symbol inner cardinal positions (close to center) */
.card-12-symbols .symbol-12.pos-0-inner {
    top: 35%; left: 50%;
    transform: translate(-50%, -50%) rotate(180deg);
}
.card-12-symbols .symbol-12.pos-90-inner {
    top: 50%; left: 68%;
    transform: translate(-50%, -50%) rotate(-90deg);
}
.card-12-symbols .symbol-12.pos-180-inner {
    top: 65%; left: 50%;
    transform: translate(-50%, -50%) rotate(0deg);
}
.card-12-symbols .symbol-12.pos-270-inner {
    top: 50%; left: 32%;
    transform: translate(-50%, -50%) rotate(90deg);
}

/* 12-symbol outer cardinal positions */
.card-12-symbols .symbol-12.pos-0-outer {
    top: 15%; left: 50%;
    transform: translate(-50%, -50%) rotate(180deg);
}
.card-12-symbols .symbol-12.pos-90-outer {
    top: 50%; left: 87.5%;
    transform: translate(-50%, -50%) rotate(-90deg);
}
.card-12-symbols .symbol-12.pos-180-outer {
    top: 85%; left: 50%;
    transform: translate(-50%, -50%) rotate(0deg);
}
.card-12-symbols .symbol-12.pos-270-outer {
    top: 50%; left: 12.5%;
    transform: translate(-50%, -50%) rotate(90deg);
}

/* 12-symbol diagonal positions */
.card-12-symbols .symbol-12.pos-45 {
    top: 25%; left: 71.5%;
    transform: translate(-50%, -50%) rotate(-135deg);
}
.card-12-symbols .symbol-12.pos-135 {
    top: 75%; left: 71.5%;
    transform: translate(-50%, -50%) rotate(-45deg);
}
.card-12-symbols .symbol-12.pos-225 {
    top: 75%; left: 28.5%;
    transform: translate(-50%, -50%) rotate(45deg);
}
.card-12-symbols .symbol-12.pos-315 {
    top: 25%; left: 28.5%;
    transform: translate(-50%, -50%) rotate(135deg);
}

/* =============================================================================
   5. CARD ANIMATIONS
   ============================================================================= */

@keyframes pulse {
    0% { transform: translate(-50%, -50%) scale(1); }
    50% { transform: translate(-50%, -50%) scale(1.08); }
    100% { transform: translate(-50%, -50%) scale(1); }
}

@keyframes shake {
    0% { transform: translate(-50%, -50%) translateX(0); }
    25% { transform: translate(-50%, -50%) translateX(-5px); }
    50% { transform: translate(-50%, -50%) translateX(5px); }
    75% { transform: translate(-50%, -50%) translateX(-5px); }
    100% { transform: translate(-50%, -50%) translateX(0); }
}

@keyframes symbolPush {
    0% { transform: scale(1); }
    40% { transform: scale(0.7); }
    70% { transform: scale(1.1); }
    100% { transform: scale(1); }
}

.symbol-match {
    animation: symbolPush 0.3s ease-out !important;
}

/* =============================================================================
   6. MESSAGE OVERLAY & COUNTDOWN
   ============================================================================= */

#message {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(255,255,255,0.98);
    padding: 40px;
    border-radius: 20px;
    text-align: center;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3);
    display: block;
    z-index: 100;
    border: 4px solid #BEC887;
    width: 80%;
    max-width: 400px;
    margin-top: 20px;
    min-height: 180px;
}

#message.lost {
    border-color: #E6A07F;
}

#message.countdown-overlay {
    background: rgba(255, 255, 255, 0.85);
    box-shadow: none;
    border: none;
}

#msg-body {
    min-height: 3rem;
}

@keyframes countdownPulse {
    0% { transform: scale(0.8); opacity: 0.5; }
    50% { transform: scale(1.3); opacity: 1; }
    100% { transform: scale(1); opacity: 0.9; }
}

.countdown-number {
    animation: countdownPulse 1s ease-out;
    font-size: 3rem;
    font-weight: 700;
    color: #888;
}

/* =============================================================================
   7. BUTTON SYSTEM
   ============================================================================= */

button,
a.buy-btn,
button.buy-btn,
button.stay-btn,
a.stay-btn {
    -webkit-appearance: none;
    appearance: none;
    border: none;
    border-radius: var(--btn-radius);
    padding: var(--btn-pad-y) var(--btn-pad-x);
    font-size: var(--btn-font);
    font-weight: 700;
    line-height: 1.1;
    text-align: center;
    text-decoration: none;
    color: var(--btn-text);
    cursor: pointer;
    display: block;
    width: 100%;
    max-width: var(--btn-maxw);
    margin: 14px auto 0 auto;
    transition: transform 0.08s ease, filter 0.15s ease;
    font-family: 'Poppins', sans-serif;
}

button:active,
a.buy-btn:active,
button.buy-btn:active,
button.stay-btn:active {
    transform: scale(0.98);
}

/* Default button = primary green */
button { background: var(--btn-green); }

/* Secondary CTA = blue */
a.buy-btn,
button.buy-btn { background: var(--btn-blue); }

/* Explicit primary green */
button.stay-btn,
a.stay-btn { background: var(--btn-green); }

.btn-primary { background: var(--btn-green) !important; }
.btn-secondary { background: var(--btn-blue) !important; }

/* Modal button stacks */
.modal-actions button,
.modal-actions a.buy-btn,
.modal-actions button.buy-btn,
.modal-actions button.stay-btn {
    max-width: none;
    margin: 0;
}

.modal-actions {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Amazon button */
.amazon-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2px 16px;
    background: #232f3e;
    border-radius: var(--btn-radius);
    text-decoration: none;
    transition: opacity 0.2s;
    width: 100%;
    max-width: none;
    margin: 0;
}

.amazon-btn:hover { opacity: 0.85; }

.modal-content .amazon-btn img {
    width: 50%;
    height: auto;
    max-width: 50%;
}

/* Game over buttons */
.game-over-btn {
    padding: 12px 20px;
    border-radius: 10px;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    border: none;
    transition: transform 0.08s ease, filter 0.15s ease;
    font-family: 'Poppins', sans-serif;
}

.game-over-btn:active { transform: scale(0.98); }
.game-over-btn:not(.level-up-btn) { background: var(--btn-green); color: #fff; }
.game-over-btn.level-up-btn { background: #F9CE79; color: #333; }

/* =============================================================================
   8. TIMER DISPLAY
   ============================================================================= */

.timer-display {
    display: inline-block;
    transition: transform 0.3s ease;
}

.timer-number {
    display: inline-block;
    font-variant-numeric: tabular-nums;
    font-feature-settings: "tnum";
    min-width: 2ch;
    text-align: right;
}

@keyframes timerPause {
    0% { transform: scale(1); }
    50% { transform: scale(1.15); }
    100% { transform: scale(1.1); }
}

@keyframes timerResume {
    0% { transform: scale(1.1); }
    50% { transform: scale(1.15); color: #2ecc71; }
    100% { transform: scale(1); color: inherit; }
}

@keyframes timerUrgent {
    0%, 100% { transform: scale(1); color: #e74c3c; }
    50% { transform: scale(1.15); color: #ff6b6b; }
}

.timer-display.paused { animation: timerPause 0.3s ease forwards; }
.timer-display.resumed { animation: timerResume 0.3s ease forwards; }
.timer-display.urgent { animation: timerUrgent 0.5s ease-in-out infinite; }

/* =============================================================================
   9. FOOTER & VERSION
   ============================================================================= */

.footer-link {
    position: fixed;
    bottom: 8px;
    left: 50%;
    transform: translateX(-50%);
    text-align: center;
    z-index: 40;
    pointer-events: none;
}

#version-display {
    font-size: 0.7rem;
    color: #bbb;
}

.footer-link a {
    color: #999;
    text-decoration: none;
    font-size: 1rem;
    font-weight: 400;
    transition: color 0.2s, transform 0.2s;
    display: inline-block;
}

.footer-link a:hover {
    color: #4a90e2;
    transform: translateY(-2px);
}

.footer-tagline {
    font-size: 1rem;
    color: #666;
    margin: 0 0 4px 0;
}

/* =============================================================================
   10. MODAL SYSTEM
   ============================================================================= */

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    max-width: 100%;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(3px);
    z-index: 200;
    display: none;
    justify-content: center;
    align-items: center;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.show {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: white;
    padding: 30px;
    border-radius: 20px;
    text-align: center;
    max-width: 90%;
    width: min(350px, 90vw);
    position: relative;
    box-shadow: 0 10px 40px rgba(0,0,0,0.3);
    transform: scale(0.9);
    transition: transform 0.3s ease;
}

.modal-overlay.show .modal-content {
    transform: scale(1);
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    background: none;
    border: none;
    font-size: 2rem;
    cursor: pointer;
    color: #666;
    padding: 0;
    width: 40px;
    height: 40px;
    margin: 0;
}

.close-btn:hover { color: #333; }

.modal-content h2 {
    color: #333;
    margin-bottom: 10px;
    margin-top: 0;
}

.modal-content p {
    color: #666;
    margin-bottom: 10px;
    font-size: 0.9rem;
}

.modal-content img {
    width: 100%;
    height: auto;
    display: block;
    border-radius: 10px;
    margin: 15px 0;
}

#carousel-image {
    cursor: pointer;
    user-select: none;
    -webkit-user-select: none;
    -webkit-touch-callout: none;
    height: auto;
    object-fit: contain;
}

#shop-modal .modal-content {
    width: 480px;
    max-width: 90%;
    padding: 40px;
}

.invite-modal-content {
    border: 4px solid #F9CE79;
    width: 80%;
    max-width: 400px;
}

/* =============================================================================
   11. AVATAR SYSTEM
   ============================================================================= */

.avatar-sprite {
    width: 32px;
    height: 32px;
    background-image: url('assets/mobee_sprite.svg');
    background-size: 617.67px 436.65px;
    background-repeat: no-repeat;
    display: inline-block;
    transition: transform 0.2s ease;
    border: 1px solid #BEC887;
    border-radius: 50%;
}

@media (hover: hover) {
    .avatar-sprite[onclick]:hover {
        transform: scale(1.3);
        z-index: 100;
    }
}

/* My avatar has yellow border */
.avatar-sprite.avatar-me {
    border-color: #F9CE79;
}

/* Avatar selection grid */
.avatar-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(48px, 1fr));
    gap: 4px;
    justify-content: center;
    margin: 20px auto;
    max-height: 400px;
    overflow-y: auto;
    padding: 8px;
    max-width: 100%;
}

.avatar-option {
    width: 48px;
    height: 48px;
    background-image: url('assets/mobee_sprite.svg');
    background-size: 925.57px 654.56px;
    background-repeat: no-repeat;
    cursor: pointer;
    border: 2px solid transparent;
    transition: all 0.2s;
}

.avatar-option:hover { border-color: #4a90e2; }
.avatar-option.selected {
    border-color: #BEC887;
    box-shadow: 0 0 10px rgba(190, 200, 135, 0.5);
}

#avatar-modal .modal-content {
    width: min(700px, 92vw);
    max-width: 92vw;
}

@keyframes avatarPopIn {
    0% { transform: scale(0); opacity: 0; }
    50% { transform: scale(1.3); }
    100% { transform: scale(1); opacity: 1; }
}

.avatar-sprite.new-player {
    animation: avatarPopIn 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* =============================================================================
   12. LOBBY LAYOUT
   ============================================================================= */

.lobby {
    flex: 1;
    width: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 0;
    min-height: 0;
    overflow: visible;
    position: relative;
    container-type: size;
}

/* Friends section - full container for card sizing */
#friends-section {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    background: var(--bg);
    z-index: 10;
    container-type: size;
}

/* Main lobby cards - use viewport units since no sized container wrapper */
#lobby-cards {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(90vw, 75vh);
    height: min(90vw, 75vh);
    z-index: 10;
    opacity: 0;
    transition: opacity 0.15s ease-out;
}

#lobby-cards.scaled { opacity: 1; }

/* Friends lobby cards - use container query units */
.lobby-cards {
    position: relative;
    width: min(115cqw, 115cqh);
    height: min(115cqw, 115cqh);
    max-width: 115%;
    max-height: 115%;
    margin: 0 auto;
    opacity: 0;
    transition: opacity 0.15s ease-out;
    z-index: 60;
}

.lobby-cards.scaled { opacity: 1; }

.lobby-card-content {
    position: absolute;
    top: 15%;
    left: 15%;
    width: 70%;
    height: 70%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 4px;
    pointer-events: none;
}

img.lobby-card-icon {
    width: 45%;
    height: auto;
    object-fit: contain;
}

/* Play Solo card icon - smaller and transparent */
.lobby-card:nth-child(1) img.lobby-card-icon {
    width: 25%;
    filter: grayscale(100%) opacity(0.2);
}

/* Lobby card border colors */
.lobby-card:nth-child(1) .card-shape { stroke: #E6A07F; } /* Play Solo - red */
.lobby-card:nth-child(2) .card-shape { stroke: #F9CE79; } /* Get the Cards - yellow */
.lobby-card:nth-child(3) .card-shape { stroke: #BEC887; } /* Play with Friends - green */

.lobby-card-label {
    font-size: clamp(0.7rem, 2vw, 0.95rem);
    font-weight: 700;
    color: #333;
    text-align: center;
}

.lobby-card-hint {
    font-size: clamp(0.55rem, 1.5vw, 0.75rem);
    color: #888;
    text-align: center;
    margin-top: 4px;
}

/* Visibility helpers */
.mobile-only { display: none; }
.desktop-only { display: block; }

.lobby-top-hint {
    text-align: center;
    font-size: 0.9rem;
    color: #666;
    padding: 8px 20px;
}

/* =============================================================================
   13. FRIENDS SECTION (MULTIPLAYER)
   ============================================================================= */

.friends-card-content {
    position: absolute;
    top: 15%;
    left: 15%;
    width: 70%;
    height: 70%;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    gap: 8px;
    pointer-events: none;
    overflow: visible;
}

/* Re-enable pointer events for interactive elements */
.friends-card-content .avatar-sprite,
.friends-card-content button,
.friends-card-content input {
    pointer-events: auto;
}

/* Friends card border colors */
.friends-card:nth-child(1) .card-shape { stroke: #E6A07F; } /* Room Code - red */
.friends-card:nth-child(2) .card-shape { stroke: #F9CE79; } /* Room Link - yellow */
.friends-card:nth-child(3) .card-shape { stroke: #BEC887; } /* Start Game - green */

.friends-card-label {
    font-size: clamp(0.7rem, 2vw, 0.95rem);
    font-weight: 700;
    color: #333;
    text-align: center;
}

.friends-input-wrap {
    position: relative;
    width: 90%;
    pointer-events: auto;
}

.friends-code-input,
.friends-link-input {
    width: 100%;
    padding: 8px 28px 8px 6px;
    border: 2px solid #F9CE79;
    border-radius: 8px;
    font-size: clamp(0.7rem, 1.8vw, 0.9rem);
    font-weight: 700;
    text-align: center;
    background: #fff;
}

.friends-code-input {
    letter-spacing: 0.08em;
    text-transform: uppercase;
    border-color: #E6A07F;
    font-size: clamp(0.85rem, 2.2vw, 1.1rem);
}

.friends-link-input {
    cursor: pointer;
    font-weight: 500;
    font-family: 'SF Mono', Consolas, Monaco, 'Lucida Console', monospace;
    font-size: clamp(0.6rem, 1.5vw, 0.8rem);
}

.friends-code-input:hover,
.friends-link-input:hover {
    border-color: #e5b85a;
    background: #fffef8;
}

.friends-code-input:focus,
.friends-link-input:focus {
    outline: none;
    border-color: #4a90e2;
    background: #f8fbff;
}

.friends-copy-icon {
    position: absolute;
    right: 6px;
    top: 50%;
    transform: translateY(-50%);
    width: 16px;
    height: 16px;
    background: no-repeat center/contain;
    opacity: 0.5;
    cursor: pointer;
    background-image: url("data:image/svg+xml;utf8,<svg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%23666' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'><rect x='9' y='9' width='13' height='13' rx='2' ry='2'/><path d='M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1'/></svg>");
}

.friends-copy-icon:hover { opacity: 1; }

.friends-players {
    display: flex;
    gap: 4px;
    justify-content: center;
    flex-wrap: wrap;
    min-height: 40px;
}

.friends-start-btn {
    background: var(--btn-green);
    color: var(--btn-text);
    border: none;
    border-radius: 12px;
    padding: 10px 16px;
    font-size: clamp(0.75rem, 2vw, 0.95rem);
    font-weight: 700;
    cursor: pointer;
    pointer-events: auto;
    width: 90%;
}

.friends-start-btn:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.friends-waiting {
    font-size: clamp(0.7rem, 2vw, 0.95rem);
    color: #666;
    font-weight: 700;
    text-align: center;
}

.friends-card-hint {
    font-size: clamp(0.5rem, 1.3vw, 0.65rem);
    color: #888;
    text-align: center;
    margin-top: 2px;
}

.friends-invite-btn {
    background: #F9CE79;
    color: #333;
    border: none;
    border-radius: 12px;
    padding: 10px 16px;
    font-size: clamp(0.75rem, 2vw, 0.95rem);
    font-weight: 700;
    cursor: pointer;
    pointer-events: auto;
    margin-top: 4px;
    width: 90%;
}

.friends-invite-btn:hover { background: #e5b85a; }

/* =============================================================================
   14. MOBILE RESPONSIVE (iPhone)
   ============================================================================= */

@media (max-width: 430px) {
    .mobile-only { display: block; }
    .desktop-only { display: none !important; }

    html, body { overflow-x: hidden !important; }

    :root {
        --ui-top: 120px;
        --ui-bottom: 24px;
        --symbol-scale: 0.66;
    }

    #board-container {
        width: 100vw !important;
        margin: 0 !important;
        padding: 0 !important;
        align-items: center;
    }

    #game-board {
        /* On iPhone, use container query sizing with slight zoom */
        width: min(100cqw, 100cqh) !important;
        height: min(100cqw, 100cqh) !important;
        margin: 0 auto !important;
        padding: 0 !important;
        transform: scale(1.12);
        transform-origin: center center;
    }

    .stats { font-size: 1.05rem; gap: 16px; }
    .logo-img { max-height: 10svh; }
    .logo-container { padding-left: 12px; padding-right: 12px; }
    .footer-link { display: none; }

    .lobby-cards {
        /* On iPhone, use container query sizing with slight zoom */
        width: min(100cqw, 100cqh) !important;
        height: min(100cqw, 100cqh) !important;
        margin: 0 auto !important;
        transform: scale(1.12);
        transform-origin: center center;
    }

    .lobby {
        flex-direction: row !important;
        justify-content: center;
        align-items: center;
        padding: 0 !important;
        position: relative;
    }

    /* Smaller avatars in lobby to fit 5 players (32px = 48px * 0.67) */
    .friends-players {
        gap: 0;
    }

    .friends-players .avatar-sprite {
        transform: scale(0.67);
        margin: -8px;
    }
}

/* Responsive avatar grid for mobile */
@media (max-width: 700px) {
    #avatar-modal .modal-content {
        width: 95vw;
        max-width: 95vw;
        max-height: 80vh;
        max-height: 80svh;
        padding: 15px 10px;
        overflow: hidden;
        display: flex;
        flex-direction: column;
    }

    #avatar-modal .modal-content h2 {
        font-size: 1.1rem;
        margin-bottom: 4px;
    }

    #avatar-modal .modal-content p {
        font-size: 0.75rem;
        margin-bottom: 6px;
    }

    .avatar-grid {
        display: grid;
        grid-template-columns: repeat(auto-fill, 48px);
        gap: 2px;
        padding: 2px;
        max-height: 60vh;
        max-height: 60svh;
        overflow-y: auto;
        overflow-x: hidden;
        flex: 1;
        justify-content: center;
    }
}

/* Landscape on short screens */
@media (orientation: landscape) and (max-height: 500px) {
    .logo-img { max-height: 8vh; }
}
