:root {
    --primary: #2d5016;
    --primary-light: #4a7c28;
    --primary-dark: #1a3009;
    --accent: #d4a017;
    --accent-light: #f0c040;
    --danger: #c0392b;
    --success: #27ae60;
    --warning: #f39c12;
    --bg: #1a1a2e;
    --bg-light: #16213e;
    --bg-card: #0f3460;
    --text: #eaeaea;
    --text-muted: #8899aa;
    --border: #2a4a6e;
    --shadow: rgba(0, 0, 0, 0.3);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    max-width: 900px;
    margin: 0 auto;
    padding: 1rem;
}

/* Navbar */
.navbar {
    background: var(--bg-light);
    border-bottom: 1px solid var(--border);
    padding: 0.75rem 1rem;
    position: sticky;
    top: 0;
    z-index: 100;
}

.nav-container {
    max-width: 1200px;
    margin: 0 auto;
    display: flex;
    align-items: center;
    justify-content: space-between;
}

.nav-brand {
    font-size: 1.5rem;
    font-weight: bold;
    color: var(--accent);
    text-decoration: none;
}

.nav-links {
    display: flex;
    list-style: none;
    gap: 1rem;
}

.nav-links a {
    color: var(--text);
    text-decoration: none;
    padding: 0.5rem 0.75rem;
    border-radius: 6px;
    transition: background 0.2s;
}

.nav-links a:hover {
    background: var(--bg-card);
}

.nav-toggle {
    display: none;
    background: none;
    border: none;
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
}

@media (max-width: 768px) {
    .nav-toggle {
        display: block;
    }

    .nav-links {
        display: none;
        flex-direction: column;
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        background: var(--bg-light);
        border-bottom: 1px solid var(--border);
        padding: 1rem;
        z-index: 150;
    }

    .nav-links.active {
        display: flex;
    }

    .profile-btn {
        width: 44px;
        height: 44px;
    }
}

/* Main Content */
.main-content {
    padding: 1rem 0;
}

/* Flash Messages */
.flash-messages {
    max-width: 900px;
    margin: 0 auto;
    padding: 0 1rem;
}

.flash {
    padding: 0.75rem 1rem;
    border-radius: 8px;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
}

.flash-success { background: rgba(39, 174, 96, 0.2); border: 1px solid var(--success); }
.flash-error { background: rgba(192, 57, 43, 0.2); border: 1px solid var(--danger); }
.flash-info { background: rgba(52, 152, 219, 0.2); border: 1px solid #3498db; }

/* Auth */
.auth-container {
    display: flex;
    justify-content: center;
    align-items: center;
    min-height: 70vh;
    padding: 1rem;
}

.auth-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 420px;
    box-shadow: 0 4px 20px var(--shadow);
}

.auth-card h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--accent);
}

.auth-link {
    text-align: center;
    margin-top: 1rem;
    color: var(--text-muted);
}

.auth-link a {
    color: var(--accent);
}

/* Forms */
.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    margin-bottom: 0.3rem;
    font-size: 0.9rem;
    color: var(--text-muted);
}

.form-input {
    width: 100%;
    padding: 0.7rem 1rem;
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 8px;
    color: var(--text);
    font-size: 1rem;
    transition: border-color 0.2s;
}

.form-input:focus {
    outline: none;
    border-color: var(--accent);
}

.form-error {
    color: var(--danger);
    font-size: 0.8rem;
    margin-top: 0.2rem;
    display: block;
}

.checkbox-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.checkbox-group label {
    margin-bottom: 0;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.7rem 1.5rem;
    border: none;
    border-radius: 8px;
    font-size: 1rem;
    cursor: pointer;
    text-decoration: none;
    text-align: center;
    transition: transform 0.1s, opacity 0.2s;
    min-height: 44px;
}

.btn:hover { opacity: 0.9; }
.btn:active { transform: scale(0.97); }

.btn-primary { background: var(--primary-light); color: white; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-success { background: var(--success); color: white; }
.btn-warning { background: var(--warning); color: white; }
.btn-danger { background: var(--danger); color: white; }
.btn-full { width: 100%; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.85rem; min-height: 44px; }
.btn-back { position: fixed; bottom: 1rem; left: 1rem; opacity: 0.7; background: var(--border); color: var(--text); }

/* Lobby */
.lobby-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(280px, 100%), 1fr));
    gap: 1rem;
    margin-top: 1rem;
}

.lobby-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 1.5rem;
    box-shadow: 0 2px 10px var(--shadow);
}

.lobby-card h3 {
    color: var(--accent);
    margin-bottom: 0.5rem;
}

.lobby-card p {
    color: var(--text-muted);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

.bot-levels {
    display: flex;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.match-status {
    margin-top: 0.75rem;
    color: var(--accent-light);
    font-style: italic;
}

.online-friends-list {
    max-height: 200px;
    overflow-y: auto;
}

.friend-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    border-bottom: 1px solid var(--border);
}

.friend-item:last-child {
    border-bottom: none;
}

.online-dot {
    display: inline-block;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--text-muted);
    margin-right: 0.5rem;
}

.online-dot.active {
    background: var(--success);
}

.friend-name {
    display: flex;
    align-items: center;
}

.friend-stats {
    color: var(--text-muted);
    font-size: 0.8rem;
    margin-left: 0.5rem;
}

.friend-actions {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

/* Room / multi-player lobby */
.room-select {
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 0.4rem 0.6rem;
    font-size: 1rem;
}

.room-code-input {
    background: var(--bg-light);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    padding: 0.4rem 0.6rem;
    font-size: 1rem;
    width: 130px;
    letter-spacing: 0.12em;
    text-transform: uppercase;
}

.room-code-display {
    font-size: 1.1rem;
    font-weight: bold;
    color: var(--accent);
    margin-bottom: 0.6rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn-copy {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1rem;
    padding: 0;
    opacity: 0.7;
}

.btn-copy:hover { opacity: 1; }

.room-player-list {
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
    max-height: 160px;
    overflow-y: auto;
}

.room-player-item {
    display: flex;
    align-items: center;
    gap: 0.4rem;
    font-size: 0.9rem;
    padding: 0.2rem 0;
}

.room-error {
    margin-top: 0.5rem;
    color: var(--danger);
    font-size: 0.85rem;
}

/* Shared overlay (used in lobby and game) */
.game-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
}

.overlay-content {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 1.5rem 2rem;
    text-align: center;
    max-width: 420px;
    width: 90%;
}

.overlay-content h2 { color: var(--accent); margin-bottom: 1rem; font-size: 1.5rem; }
.overlay-content p  { margin-bottom: 0.5rem; }
.overlay-content .btn { margin-top: 1rem; margin-right: 0.5rem; }

/* Profile */
.profile-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 2rem;
    text-align: center;
    max-width: 500px;
    margin: 2rem auto;
}

.profile-card h2 {
    color: var(--accent);
    margin-bottom: 1.5rem;
    font-size: 1.8rem;
}

.profile-stats {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.stat-item {
    background: var(--bg-light);
    border-radius: 8px;
    padding: 1rem;
}

.stat-value {
    display: block;
    font-size: 1.8rem;
    font-weight: bold;
    color: var(--accent);
}

.stat-label {
    display: block;
    font-size: 0.8rem;
    color: var(--text-muted);
    margin-top: 0.2rem;
}

.profile-info {
    color: var(--text-muted);
    font-size: 0.9rem;
}

/* History */
.history-list {
    margin-top: 1rem;
}

.history-item {
    background: var(--bg-card);
    border-radius: 8px;
    padding: 1rem;
    margin-bottom: 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-left: 4px solid var(--border);
}

.history-item.won { border-left-color: var(--success); }
.history-item.lost { border-left-color: var(--danger); }
.history-item.draw { border-left-color: var(--warning); }

.history-details { display: flex; flex-direction: column; }
.history-opponent { font-weight: bold; }
.history-score { color: var(--text-muted); font-size: 0.9rem; }
.history-meta { text-align: right; }
.history-result { display: block; font-weight: bold; }
.history-date { color: var(--text-muted); font-size: 0.8rem; }

/* Rules */
.rules-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 2rem;
    max-width: 700px;
    margin: 1rem auto;
}

.rules-card h1 {
    color: var(--accent);
    margin-bottom: 1.5rem;
    text-align: center;
}

.rules-card h2 {
    color: var(--accent-light);
    margin: 1.5rem 0 0.5rem;
    font-size: 1.2rem;
}

.rules-card section {
    margin-bottom: 1rem;
}

.rules-card ul, .rules-card ol {
    padding-left: 1.5rem;
    margin: 0.5rem 0;
}

.rules-card li {
    margin-bottom: 0.3rem;
}

.rules-table {
    width: 100%;
    border-collapse: collapse;
    margin-top: 0.5rem;
}

.rules-table th, .rules-table td {
    padding: 0.5rem;
    border: 1px solid var(--border);
    text-align: center;
}

.rules-table th {
    background: var(--bg-light);
    color: var(--accent);
}

/* Search */
.search-form {
    margin-bottom: 1.5rem;
}

.search-bar {
    display: flex;
    gap: 0.5rem;
}

.search-bar .form-input {
    flex: 1;
}

/* Social */
.social-actions {
    margin-bottom: 1.5rem;
}

.section {
    margin-bottom: 2rem;
}

.section h2 {
    color: var(--accent-light);
    margin-bottom: 0.75rem;
    font-size: 1.1rem;
}

/* Landing page */
.landing-wrap {
    max-width: 580px;
    margin: 0 auto;
    padding: 2rem 1rem 3rem;
    text-align: center;
}

.landing-hero {
    margin-bottom: 2rem;
}

.landing-title {
    font-size: 2.5rem;
    color: var(--accent);
    margin-bottom: 0.4rem;
    font-weight: 700;
}

.landing-tagline {
    color: var(--text-muted);
    font-size: 1.05rem;
    margin-bottom: 1.25rem;
    line-height: 1.5;
}

.landing-features {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 0.5rem;
}

.landing-feat {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 20px;
    padding: 0.3rem 0.85rem;
    font-size: 0.82rem;
    color: var(--text-muted);
}

.landing-cta-card {
    background: var(--bg-card);
    border-radius: 16px;
    padding: 2rem;
    box-shadow: 0 4px 20px var(--shadow);
}

.landing-guest-form {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.6rem;
}

.landing-name-input {
    flex: 1;
    min-width: 0;
}

.landing-play-btn {
    flex-shrink: 0;
    white-space: nowrap;
}

.landing-hint {
    color: var(--text-muted);
    font-size: 0.82rem;
    margin-bottom: 0;
}

.landing-auth-links {
    display: flex;
    gap: 0.75rem;
    justify-content: center;
}

/* "or" divider — used in landing + login */
.or-divider {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    color: var(--text-muted);
    font-size: 0.82rem;
    margin: 1.25rem 0;
}

.or-divider::before,
.or-divider::after {
    content: '';
    flex: 1;
    border-top: 1px solid var(--border);
}

/* Login page guest section */
.auth-guest-section {
    text-align: center;
}

.auth-guest-tagline {
    color: var(--text-muted);
    font-size: 0.9rem;
    margin-bottom: 0.75rem;
}

@media (max-width: 480px) {
    .landing-title { font-size: 2rem; }
    .landing-guest-form { flex-direction: column; }
    .landing-auth-links { flex-direction: column; }
    .landing-cta-card { padding: 1.25rem; }
}

/* Room controls layout */
.room-controls {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
    margin-bottom: 0.75rem;
}

.room-controls-join {
    display: flex;
    gap: 0.5rem;
    align-items: center;
    flex-wrap: wrap;
}

.room-controls-buttons {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

@media (max-width: 360px) {
    .room-controls,
    .room-controls-join {
        flex-direction: column;
        align-items: stretch;
    }
    .room-code-input {
        width: 100%;
    }
}

/* Utilities */
.hidden { display: none !important; }
.text-muted { color: var(--text-muted); }

h1 {
    color: var(--accent);
    margin-bottom: 0.5rem;
}

@media (max-width: 480px) {
    .profile-stats {
        grid-template-columns: 1fr 1fr;
    }

    .history-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .history-meta {
        text-align: left;
    }

    .friend-item {
        flex-direction: column;
        align-items: flex-start;
        gap: 0.5rem;
    }

    .search-bar {
        flex-direction: column;
    }
}

/* Nav icons group */
.nav-icons {
    display: flex;
    align-items: center;
    gap: 0.25rem;
    margin-left: 0.5rem;
    flex-shrink: 0;
}

/* Profile icon & dropdown */
.profile-icon-wrapper {
    position: relative;
}

.profile-btn {
    background: none;
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px;
    height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text);
    transition: background 0.2s;
    padding: 0;
}

.profile-btn:hover {
    background: var(--bg-card);
}

.profile-dropdown {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 0.4rem 0;
    min-width: 170px;
    max-width: calc(100vw - 1rem);
    box-shadow: 0 4px 16px var(--shadow);
    z-index: 200;
}

.dropdown-header {
    padding: 0.5rem 1rem 0.4rem;
    color: var(--text-muted);
    font-size: 0.82rem;
    border-bottom: 1px solid var(--border);
    margin-bottom: 0.25rem;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.dropdown-item {
    display: block;
    padding: 0.45rem 1rem;
    color: var(--text);
    text-decoration: none;
    font-size: 0.9rem;
    transition: background 0.15s;
    cursor: pointer;
}

.dropdown-item:hover {
    background: var(--bg-light);
}

.dropdown-item-active {
    color: var(--accent);
    font-weight: 600;
}

.lang-flag-btn {
    font-size: 1.35rem;
    line-height: 1;
}

.dropdown-flag {
    margin-right: 0.5rem;
    font-size: 1.1rem;
}

/* Login modal */
.modal-overlay {
    position: fixed;
    top: 0; left: 0; right: 0; bottom: 0;
    background: rgba(0, 0, 0, 0.75);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 300;
}

.modal-card {
    background: var(--bg-card);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
    max-width: 400px;
    max-height: calc(100dvh - 2rem);
    overflow-y: auto;
    position: relative;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.5);
    margin: 1rem;
}

.modal-card h2 {
    text-align: center;
    margin-bottom: 1.5rem;
    color: var(--accent);
}

.modal-close {
    position: absolute;
    top: 0.6rem;
    right: 0.75rem;
    background: none;
    border: none;
    color: var(--text-muted);
    font-size: 1.6rem;
    cursor: pointer;
    line-height: 1;
    padding: 0.2rem 0.4rem;
    border-radius: 4px;
    transition: color 0.15s, background 0.15s;
}

.modal-close:hover {
    color: var(--text);
    background: var(--bg-light);
}
