/* --- RESET & VARIABLES --- */
:root {
    --primary-purple: #5e35b1;
    --light-purple: #ede7f6;
    --bg-blue: #eef4fc;
    --text-dark: #2c3e50;
    --text-grey: #64748b;
    --card-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
    --radius: 16px;
    --max-w: 900px;
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
}

body {
    background-color: var(--bg-blue);
    color: var(--text-dark);
    min-height: 100vh;
    display: flex;
    justify-content: center;
    align-items: center;
    padding: 80px 20px 20px 20px;
    /* Top padding accounts for sticky banner height */
}

/* --- STICKY BANNER --- */
.sticky-banner {
    position: fixed;
    top: 0;
    left: 50%;
    /* Start at horizontal center */
    transform: translateX(-50%);
    /* Shift back by 50% to perfectly center */
    width: 100%;
    max-width: var(--max-w);
    /* Match the content width */
    height: 60px;
    background: white;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0 40px;
    /* Align padding with the card below */
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
    z-index: 3000;
    font-weight: 600;
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 12px;
}

.banner-link {
    color: var(--primary-purple);
    text-decoration: none;
    font-size: 1rem;
}

.banner-copyright {
    color: var(--primary-purple);
    font-size: 0.9rem;
}

/* --- MAIN CONTAINER --- */
.app-container {
    background: white;
    width: 100%;
    max-width: var(--max-w);
    border-radius: 24px;
    box-shadow: var(--card-shadow);
    padding: 40px;
    min-height: 600px;
    position: relative;
    overflow: hidden;
}

/* --- HEADER SECTION --- */
header {
    text-align: center;
    margin-bottom: 30px;
}

h1 {
    font-size: 2rem;
    margin-bottom: 10px;
}

.subtitle {
    color: var(--text-grey);
    font-size: 1.1rem;
}

/* --- USER STATUS BAR (Top) --- */
.my-status-bar {
    background-color: var(--bg-blue);
    border-radius: var(--radius);
    padding: 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
    margin-bottom: 30px;
}

.my-profile {
    display: flex;
    align-items: center;
    gap: 12px;
}

.avatar-circle {
    font-size: 2rem;
    background: white;
    width: 50px;
    height: 50px;
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 50%;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.05);
}

.status-selector {
    display: flex;
    align-items: center;
    gap: 10px;
}

select {
    padding: 10px 16px;
    border-radius: 8px;
    border: 1px solid #cbd5e1;
    font-size: 1rem;
    color: var(--text-dark);
    cursor: pointer;
    outline: none;
}

select:focus {
    border-color: var(--primary-purple);
}

/* --- PLAYER LIST (The Hub) --- */
.player-list-header {
    display: flex;
    justify-content: space-between;
    margin-bottom: 15px;
    padding: 0 10px;
    font-weight: 600;
    color: var(--text-grey);
}

.player-card {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 20px;
    border: 1px solid #e2e8f0;
    border-radius: 12px;
    margin-bottom: 12px;
    transition: all 0.3s ease;
    background: white;
}

.player-card:hover {
    border-color: var(--primary-purple);
    background-color: #fafafa;
}

/* --- DIMMED STATE --- */
.player-card.dimmed {
    opacity: 0.5;
    background-color: #f8fafc;
}

.player-card.dimmed:hover {
    opacity: 0.9;
    border-color: var(--text-grey);
}

.player-info {
    display: flex;
    align-items: center;
    gap: 15px;
}

/* Default Badge Style (Grey) */
.player-game-intent {
    display: inline-block;
    padding: 4px 12px;
    border-radius: 20px;
    font-size: 0.85rem;
    background: #f1f5f9;
    color: var(--text-grey);
    margin-left: 10px;
    transition: all 0.3s ease;
}

/* Match Badge Style (Purple) */
.player-game-intent.intent-match {
    background: var(--light-purple);
    color: var(--primary-purple);
    font-weight: 600;
}

/* --- BUTTONS --- */
.btn {
    background-color: var(--primary-purple);
    color: white;
    border: none;
    padding: 10px 24px;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.2s;
}

.btn:hover {
    opacity: 0.9;
}

.btn-secondary {
    background-color: #cbd5e1;
    color: #475569;
}

.btn-outline {
    background: transparent;
    border: 2px solid #e2e8f0;
    color: var(--text-grey);
}

.btn-outline:hover {
    border-color: var(--text-dark);
    color: var(--text-dark);
}

/* --- MODALS / OVERLAYS --- */
.modal-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(255, 255, 255, 0.95);
    display: flex;
    justify-content: center;
    align-items: center;
    opacity: 0;
    pointer-events: none;
    transition: opacity 0.3s;
    z-index: 10;
}

.modal-overlay.active {
    opacity: 1;
    pointer-events: all;
}

.modal-content {
    background: white;
    padding: 40px;
    border-radius: 24px;
    box-shadow: 0 10px 25px rgba(94, 53, 177, 0.15);
    text-align: center;
    border: 2px solid var(--bg-blue);
    max-width: 400px;
    width: 90%;
}

.avatar-group {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 15px;
    margin-bottom: 20px;
}

.avatar-large {
    font-size: 3rem;
    width: 80px;
    height: 80px;
    border-radius: 50%;
    background: var(--bg-blue);
    display: flex;
    align-items: center;
    justify-content: center;
}

.vs-badge {
    font-weight: 800;
    color: var(--primary-purple);
    font-size: 1.2rem;
}

.loader {
    border: 4px solid #f3f3f3;
    border-top: 4px solid var(--primary-purple);
    border-radius: 50%;
    width: 40px;
    height: 40px;
    animation: spin 1s linear infinite;
    margin: 0 auto 20px auto;
}

@keyframes spin {
    0% {
        transform: rotate(0deg);
    }

    100% {
        transform: rotate(360deg);
    }
}

/* --- GAME PICKER MODAL --- */
.game-options-grid {
    display: grid;
    grid-template-columns: 1fr;
    gap: 10px;
    margin-top: 20px;
}

.game-option-btn {
    padding: 15px;
    border: 2px solid #e2e8f0;
    border-radius: 12px;
    background: white;
    cursor: pointer;
    font-weight: 600;
    color: var(--text-dark);
}

.game-option-btn:hover {
    border-color: var(--primary-purple);
    background: var(--light-purple);
}

/* --- GAME SCREEN --- */
#game-view {
    display: none;
    text-align: center;
    height: 100%;
    /* padding-top: 20px; Removed large padding to fit game better */
}

.game-placeholder {
    width: 100%;
    /* height: 300px;  Removed fixed height to allow game to grow */
    min-height: 400px;
    background: #fdfdfd;
    border-radius: 12px;
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    /* color: white; */
    margin-top: 20px;
    border: 1px solid #eee;
    padding: 20px;
}

/* --- DANDELIONS CSS MERGE --- */
#dandelions-game-container {
    background-color: #fff;
    padding: 20px;
    border-radius: 8px;
    box-shadow: 0 4px 8px rgba(0, 0, 0, 0.1);
    text-align: center;
    width: 100%;
    /* Adapting to parent */
    max-width: none;
    /* Was 700px */
}

#dandelions-game-area {
    display: flex;
    justify-content: space-around;
    align-items: flex-start;
    flex-wrap: wrap;
    gap: 20px;
    margin-bottom: 20px;
}

#meadow-grid {
    display: grid;
    grid-template-columns: repeat(5, 1fr);
    grid-template-rows: repeat(5, 1fr);
    width: 250px;
    height: 250px;
    border: 2px solid #8FBC8F;
    gap: 1px;
    background-color: #ccc;
}

.grid-cell {
    background-color: #E6F5E6;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 2.4em;
    line-height: 1;
    cursor: pointer;
    border: 1px solid #ccc;
    transition: background-color 0.2s;
}

.grid-cell:hover {
    background-color: #D0E0D0;
}

.dandelion-glyph {
    color: #FFD700;
    font-weight: bold;
    line-height: 1;
    position: relative;
    top: 0.12em;
}

.seed-glyph {
    color: #556B2F;
    font-weight: bold;
    line-height: 1;
}

.grid-cell.no-click {
    cursor: not-allowed;
}

#compass-rose-area {
    display: flex;
    flex-direction: column;
    align-items: center;
}

#compass-rose {
    display: grid;
    grid-template-columns: repeat(3, 60px);
    grid-template-rows: repeat(3, 60px);
    gap: 5px;
}

.direction-button {
    background-color: #ADD8E6;
    border: 1px solid #87CEEB;
    border-radius: 4px;
    font-size: 1em;
    font-weight: bold;
    cursor: pointer;
    transition: all 0.2s;
    width: 100%;
    height: 100%;
}

.direction-button:hover:not(:disabled) {
    background-color: #87CEEB;
}

.direction-button:disabled {
    background-color: #E0E0E0;
    border-color: #C0C0C0;
    color: #909090;
    cursor: not-allowed;
    opacity: 0.75;
}

.direction-button.used {
    background-color: #B0C4DE;
    border-color: #9AB0C8;
    color: #778899;
    text-decoration: line-through;
    opacity: 0.65;
}

.compass-placeholder {
    background-color: transparent;
    border: none;
}

#wind-status {
    margin-top: 10px;
    font-size: 0.9em;
    color: #4682B4;
}

#dandelions-status-message {
    margin: 15px 0;
    font-size: 1.1em;
    font-weight: bold;
    min-height: 2em;
}

/* --- ULTIMATE TIC TAC TOE CSS MERGE --- */
#ultimate-tic-tac-toe-container {
    font-family: Arial, sans-serif;
    max-width: none;
    /* Was 600px */
    margin: 0 auto;
    padding: 15px;
    border: 1px solid #ccc;
    border-radius: 8px;
    box-shadow: 0 0 10px rgba(0, 0, 0, 0.1);
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 100%;
}

.uttt-status-area {
    margin-bottom: 15px;
    font-size: 1.2em;
    font-weight: bold;
    text-align: center;
    min-height: 1.5em;
}

.uttt-main-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    width: 100%;
    aspect-ratio: 1 / 1;
    border: 3px solid #333;
    box-sizing: border-box;
}

.uttt-mini-board {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    grid-template-rows: repeat(3, 1fr);
    border: 1px solid #999;
    position: relative;
    box-sizing: border-box;
    transition: box-shadow 0.2s ease-in-out, background-color 0.2s ease-in-out;
}

.uttt-mini-board.active-board {
    background-color: #e0f7fa;
    box-shadow: 0 0 10px 2px #00bcd4;
}

.uttt-mini-board.any-active-board {
    background-color: #fff9c4;
}

.uttt-cell {
    border: 1px solid #ddd;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(0.8em, 4vw, 2.2em);
    line-height: 1;
    cursor: pointer;
    box-sizing: border-box;
    user-select: none;
    aspect-ratio: 1 / 1;
    overflow: hidden;
}

.uttt-cell:hover:not(.occupied):not(.board-won) {
    background-color: #f0f0f0;
}

.uttt-cell.player-X {
    color: #ff5252;
}

.uttt-cell.player-O {
    color: #448aff;
}

.uttt-cell.occupied {
    cursor: not-allowed;
}

.mini-board-winner-overlay {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    font-size: clamp(3em, 15vw, 8em);
    pointer-events: none;
    opacity: 0.8;
}

.mini-board-winner-overlay.player-X {
    color: #ff5252;
}

.mini-board-winner-overlay.player-O {
    color: #448aff;
}

.mini-board-winner-overlay.tie {
    color: #757575;
}

.uttt-mini-board.won .uttt-cell,
.uttt-mini-board.tie .uttt-cell {
    opacity: 0.3;
    cursor: not-allowed;
}

/* Login/Identity Box (From Maths Melee Refined) */
#login-ov {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: #eef2f6;
    /* Lighter background matching screenshot */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: flex-start;
    z-index: 2000;
    padding-top: 40px;
    overflow-y: auto;
}

#login-box {
    background: white;
    padding: 40px;
    border-radius: 24px;
    text-align: center;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.1), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    max-width: 900px;
    width: 95%;
    margin-bottom: 40px;
}

#login-box h1 {
    font-size: 2.2rem;
    color: #000;
    margin-bottom: 15px;
}

.login-grid {
    display: flex;
    flex-direction: row;
    gap: 40px;
    text-align: left;
    margin-top: 30px;
}

@media (max-width: 768px) {
    .login-grid {
        flex-direction: column;
        gap: 20px;
    }
}

.login-inputs {
    flex: 1;
    display: flex;
    flex-direction: column;
}

.login-inputs label,
.login-avatars label {
    font-weight: 700;
    font-size: 0.95rem;
    color: #374151;
    margin-bottom: 8px;
    display: block;
}

.login-inputs select {
    width: 100%;
    padding: 12px;
    border: 1px solid #d1d5db;
    border-radius: 8px;
    font-size: 1rem;
    margin-bottom: 20px;
    background-color: white;
}

.btn-random {
    background-color: #e9d5ff;
    /* Light purple */
    color: #6b21a8;
    border: none;
    padding: 12px;
    border-radius: 50px;
    font-weight: 600;
    cursor: pointer;
    font-size: 0.95rem;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    transition: background-color 0.2s;
}

.btn-random:hover {
    background-color: #d8b4fe;
}

.login-avatars {
    flex: 1.5;
}

.emoji-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(40px, 1fr));
    gap: 8px;
    max-height: 300px;
    overflow-y: auto;
    border: 1px solid #e5e7eb;
    border-radius: 12px;
    padding: 12px;
    background: #fff;
}

.emoji-item {
    font-size: 24px;
    background: #f3f4f6;
    border-radius: 8px;
    aspect-ratio: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    transition: transform 0.1s, background-color 0.1s;
}

.emoji-item:hover {
    background: #e5e7eb;
    transform: scale(1.05);
}

.emoji-item.selected {
    background: #5e35b1;
    color: white;
}

.identity-preview-box {
    margin-top: 30px;
    padding: 20px;
    border: 1px dashed #cbd5e1;
    border-radius: 16px;
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 15px;
    background: white;
}

.btn-primary-lg {
    background-color: #4c1d95;
    /* Deep purple */
    color: white;
    font-size: 1.1rem;
    padding: 12px 40px;
    border-radius: 50px;
    border: none;
    font-weight: 600;
    margin-top: 30px;
    cursor: pointer;
    box-shadow: 0 4px 6px rgba(76, 29, 149, 0.2);
    transition: transform 0.1s;
}

.btn-primary-lg:hover {
    transform: translateY(-2px);
}

.app-info-box {
    margin-top: 40px;
    background-color: #eff6ff;
    border: 1px solid #bfdbfe;
    border-radius: 12px;
    padding: 20px;
    text-align: left;
    font-size: 0.9rem;
    color: #1e3a8a;
}

.app-info-box ul {
    margin-top: 10px;
    padding-left: 20px;
    line-height: 1.6;
}

/* --- GAME HUD & MODALS (Added) --- */
.game-hud {
    display: flex;
    align-items: center;
    justify-content: space-between;
    width: 100%;
    margin-bottom: 20px;
    background: white;
    padding: 15px;
    border-radius: var(--radius);
    box-shadow: var(--card-shadow);
}

.player-hud-side {
    display: flex;
    flex-direction: column;
    align-items: center;
    width: 140px;
    text-align: center;
}

.player-hud-side.is-active-turn {
    background: var(--light-purple);
    border-radius: 12px;
    padding: 5px;
    border: 2px solid var(--primary-purple);
}

.player-hud-side .avatar {
    font-size: 2rem;
}

.player-hud-side .name {
    font-weight: bold;
    font-size: 0.9rem;
    margin-top: 4px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
    max-width: 100%;
}

.player-hud-side .role {
    font-size: 0.8rem;
    color: var(--text-grey);
    font-weight: bold;
}

.game-hud-center {
    flex: 1;
    text-align: center;
    padding: 0 10px;
}

.game-hud-center h2 {
    font-size: 1.4rem;
    margin-bottom: 5px;
    color: var(--primary-purple);
}

.game-status-text {
    font-size: 1rem;
    font-weight: bold;
}

.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0, 0, 0, 0.5);
    display: none;
    justify-content: center;
    align-items: center;
    z-index: 5000;
}

.modal-overlay.open,
.modal-overlay.active {
    display: flex;
}

.modal-box {
    background: white;
    padding: 30px;
    border-radius: var(--radius);
    max-width: 400px;
    width: 90%;
    text-align: center;
    box-shadow: 0 10px 40px rgba(0, 0, 0, 0.2);
    animation: popIn 0.3s ease-out;
}

@keyframes popIn {
    from {
        transform: scale(0.8);
        opacity: 0;
    }

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

.modal-box h1 {
    color: var(--primary-purple);
    margin-bottom: 10px;
}

.modal-actions {
    margin-top: 20px;
}

.rules-box {
    text-align: left;
    background: #f8fafc;
    padding: 20px;
    border-radius: 12px;
    margin-top: 20px;
    border: 1px solid #e2e8f0;
}

.rules-box h3,
.rules-box h4 {
    margin-top: 15px;
    margin-bottom: 8px;
    color: var(--primary-purple);
}

.rules-box ul {
    margin-left: 20px;
}

/* --- QUICK CHAT --- */
.chat-bar {
    display: flex;
    justify-content: center;
    gap: 10px;
    flex-wrap: wrap;
    margin-top: 10px;
    margin-bottom: 20px;
}

.btn-chat {
    background: white;
    border: 2px solid #e2e8f0;
    color: var(--text-dark);
    padding: 8px 16px;
    border-radius: 20px;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s;
    border-bottom-left-radius: 4px;
    /* Speech bubble ish */
}

.btn-chat:hover:not(:disabled) {
    background: var(--light-purple);
    border-color: var(--primary-purple);
    transform: translateY(-2px);
}

.btn-chat:disabled {
    opacity: 0.5;
    cursor: wait;
    background: #f1f5f9;
}

/* Speech Bubble on Avatar */
.player-hud-side {
    position: relative;
    /* For absolute bubble positioning */
}

.speech-bubble {
    position: absolute;
    top: -10px;
    left: 100%;
    transform: translateX(10px);
    background: white;
    border: 2px solid var(--text-dark);
    padding: 10px 15px;
    border-radius: 12px;
    border-bottom-left-radius: 0;
    width: max-content;
    max-width: 150px;
    z-index: 100;
    box-shadow: 0 4px 10px rgba(0, 0, 0, 0.1);
    font-weight: bold;
    font-size: 0.9rem;
    animation: popInBubble 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Right side player needs bubble to left? Or just keep uniform?
   Commonly P2 is on right. Mirroring would be nice.
   Let's check IDs in client.js. hud-p1 is left, hud-p2 is right.
*/
#hud-p2 .speech-bubble,
#uttt-hud-p2 .speech-bubble {
    left: auto;
    right: 100%;
    transform: translateX(-10px);
    border-bottom-left-radius: 12px;
    border-bottom-right-radius: 0;
}

@keyframes popInBubble {
    from {
        opacity: 0;
        transform: scale(0.5);
    }

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

/* --- UTTT Grid Resize --- */
/* Overriding previous generic style or adding specific override */
.uttt-main-board {
    /* Was implicitly 100% or auto */
    width: 80% !important;
    margin: 20px auto;
}