/* Self-hosted fonts (latin subset from Google Fonts, SIL Open Font License): no requests to Google */
/* Cinzel is one variable file (400-700) so it groups with the Latin Extended face below; separate static
   weights next to a weight-range face make browsers pick the extended face alone and fall back to serif */
@font-face {
    font-family: 'Cinzel';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('fonts/cinzel-variable.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

/* Outfit is a variable font: one file covers weights 300 to 700 */
/* Latin Extended (Polish, Turkish, Czech, Romanian... letters in player names). Fonts: SIL OFL 1.1, see fonts/OFL.txt */
@font-face {
    font-family: 'Cinzel';
    font-style: normal;
    font-weight: 400 700;
    font-display: swap;
    src: url('fonts/cinzel-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Outfit';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('fonts/outfit-ext.woff2') format('woff2');
    unicode-range: U+0100-02BA, U+02BD-02C5, U+02C7-02CC, U+02CE-02D7, U+02DD-02FF, U+0304, U+0308, U+0329, U+1D00-1DBF, U+1E00-1E9F, U+1EF2-1EFF, U+2020, U+20A0-20AB, U+20AD-20C4, U+2113, U+2C60-2C7F, U+A720-A7FF;
}

@font-face {
    font-family: 'Outfit';
    font-style: normal;
    font-weight: 300 700;
    font-display: swap;
    src: url('fonts/outfit-variable.woff2') format('woff2');
    unicode-range: U+0000-00FF, U+0131, U+0152-0153, U+02BB-02BC, U+02C6, U+02DA, U+02DC, U+0304, U+0308, U+0329, U+2000-206F, U+20AC, U+2122, U+2191, U+2193, U+2212, U+2215, U+FEFF, U+FFFD;
}

:root {
    /* Color Palette */
    --bg-dark: #0a0c10;
    --bg-panel: rgba(22, 27, 34, 0.6);
    --text-primary: #f8fafc;
    --text-secondary: #a1b3c9;
    --gold-primary: #d4af37;
    --gold-secondary: #b08d28;
    --gold-dim: rgba(212, 175, 55, 0.2);
    --border-color: rgba(255, 255, 255, 0.08);
    --border-hover: rgba(212, 175, 55, 0.4);
    
    /* Effects */
    --glass-blur: blur(12px);
    --glass-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    --transition: all 0.3s cubic-bezier(0.25, 0.8, 0.25, 1);
    
    /* Typography */
    --font-heading: 'Cinzel', serif;
    --font-body: 'Outfit', sans-serif;
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
}

body {
    font-family: var(--font-body);
    background-color: var(--bg-dark);
    color: var(--text-primary);
    min-height: 100vh;
    overflow-x: hidden;
    position: relative;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* Background Animated Shapes */
.bg-shape {
    position: fixed;
    border-radius: 50%;
    filter: blur(120px);
    z-index: -1;
    opacity: 0.4;
    animation: float 20s infinite ease-in-out alternate;
}

.shape-1 {
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, rgba(212,175,55,0.15) 0%, rgba(10,12,16,0) 70%);
    top: -200px;
    left: -200px;
}

.shape-2 {
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, rgba(30,58,138,0.2) 0%, rgba(10,12,16,0) 70%);
    bottom: -100px;
    right: -100px;
    animation-delay: -5s;
}

.shape-3 {
    width: 400px;
    height: 400px;
    background: radial-gradient(circle, rgba(255,255,255,0.05) 0%, rgba(10,12,16,0) 70%);
    top: 40%;
    left: 40%;
    animation-duration: 25s;
}

@keyframes float {
    0% { transform: translate(0, 0) scale(1); }
    50% { transform: translate(30px, 50px) scale(1.05); }
    100% { transform: translate(-30px, 20px) scale(0.95); }
}

.app-container {
    max-width: 1800px;
    margin: 0 auto;
    padding: 0 2rem;
}

/* Navbar */
.navbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem 0;
    margin-bottom: 2rem;
    border-bottom: 1px solid var(--border-color);
}

.nav-logo {
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.nav-logo h1 {
    font-family: var(--font-heading);
    font-size: 1.8rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.nav-logo span.logo-icon {
    font-size: 2rem;
}

.nav-logo h1 span {
    color: var(--gold-primary);
}

.nav-actions {
    display: flex;
    gap: 1rem;
}

/* Buttons */
.btn {
    padding: 0.6rem 1.2rem;
    border-radius: 6px;
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 0.9rem;
    cursor: pointer;
    transition: var(--transition);
    border: none;
    outline: none;
}

.btn-primary {
    background: linear-gradient(135deg, var(--gold-primary), var(--gold-secondary));
    color: #000;
    box-shadow: 0 4px 15px rgba(212, 175, 55, 0.3);
}

.btn-primary:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(212, 175, 55, 0.5);
    background: linear-gradient(135deg, #e5c355, var(--gold-primary));
}

.btn-secondary {
    background: transparent;
    color: var(--text-primary);
    border: 1px solid var(--border-color);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--text-primary);
}

/* Glass Panel Utility */
.glass-panel {
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    box-shadow: var(--glass-shadow);
    border-radius: 12px;
}

/* Filters Section */
.filters-section {
    display: flex;
    flex-wrap: wrap;
    gap: 1.5rem;
    padding: 1.5rem;
    margin-bottom: 2rem;
    align-items: center;
}

.search-container {
    flex: 1 1 100%;
    min-width: 300px;
    position: relative;
    display: flex;
    align-items: center;
}

.search-icon {
    position: absolute;
    left: 1rem;
    color: var(--text-secondary);
}

.search-container input[type="text"] {
    width: 100%;
    padding: 0.8rem 1rem 0.8rem 3rem;
    border-radius: 8px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-size: 1rem;
    transition: var(--transition);
}

.search-container input[type="text"]:focus {
    outline: none;
    border-color: var(--gold-primary);
    box-shadow: 0 0 0 2px var(--gold-dim);
}

.filter-controls {
    display: flex;
    gap: 1rem;
    flex-wrap: wrap;
}

.filter-group {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.9rem;
    color: var(--text-secondary);
}

select {
    padding: 0.6rem 2rem 0.6rem 1rem;
    border-radius: 6px;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    color: var(--text-primary);
    font-family: var(--font-body);
    font-size: 0.9rem;
    appearance: none;
    cursor: pointer;
    background-image: url("data:image/svg+xml;charset=UTF-8,%3csvg xmlns='http://www.w3.org/2000/svg' viewBox='0 0 24 24' fill='none' stroke='%238b949e' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3e%3cpolyline points='6 9 12 15 18 9'%3e%3c/polyline%3e%3c/svg%3e");
    background-repeat: no-repeat;
    background-position: right 0.7rem center;
    background-size: 1em;
    transition: var(--transition);
}

select:focus, select:hover {
    border-color: var(--gold-primary);
    outline: none;
}

/* Lobbies Header */
.lobbies-header {
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
    margin-bottom: 1.5rem;
    padding: 0 0.5rem;
}

.lobbies-title {
    font-family: var(--font-heading);
    font-size: 1.5rem;
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.75rem;
}

.pulse-indicator {
    width: 10px;
    height: 10px;
    background-color: #2ea043;
    border-radius: 50%;
    position: relative;
}

.pulse-indicator::after {
    content: '';
    position: absolute;
    width: 100%;
    height: 100%;
    top: 0;
    left: 0;
    background-color: #2ea043;
    border-radius: 50%;
    animation: pulse 2s infinite;
    z-index: -1;
}

@keyframes pulse {
    0% { transform: scale(1); opacity: 0.8; }
    70% { transform: scale(2.5); opacity: 0; }
    100% { transform: scale(1); opacity: 0; }
}

.lobbies-stats {
    color: var(--text-secondary);
    font-size: 0.95rem;
}

/* Narrow screens: the title, view toggles, layout toggles and count wrap onto rows instead of overflowing the page
   (the header's inline styles set no flex-wrap, so these apply without !important) */
@media (max-width: 768px) {
    .lobbies-header,
    .lobbies-header > div {
        flex-wrap: wrap;
    }
    .lobbies-header {
        gap: 12px;
    }
}

.lobbies-stats span {
    color: var(--gold-primary);
    font-weight: 600;
}

/* Lobby Grid */
.lobby-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(480px, 1fr));
    gap: 1.5rem;
    padding-bottom: 3rem;
}

/* Lobby Card */
.lobby-card {
    background: var(--bg-panel);
    backdrop-filter: var(--glass-blur);
    -webkit-backdrop-filter: var(--glass-blur);
    border: 1px solid var(--border-color);
    border-radius: 12px;
    overflow: hidden;
    transition: var(--transition);
    display: flex;
    flex-direction: column;
    position: relative;
    cursor: pointer;
}

.lobby-card:hover {
    transform: translateY(-5px);
    border-color: var(--border-hover);
    box-shadow: 0 10px 40px rgba(0,0,0,0.5), 0 0 20px rgba(212, 175, 55, 0.1);
}

.lobby-card::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 3px;
    background: linear-gradient(90deg, transparent, var(--gold-primary), transparent);
    opacity: 0;
    transition: var(--transition);
}

.lobby-card:hover::before {
    opacity: 1;
}

.card-header {
    padding: 1.25rem 1.25rem 0.5rem;
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
}

.host-info {
    display: flex;
    flex-direction: column;
    gap: 0.25rem;
}

.host-name {
    font-family: var(--font-heading);
    font-size: 1.2rem;
    font-weight: 600;
    color: #fff;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.elo-badge {
    background: rgba(212, 175, 55, 0.15);
    color: var(--gold-primary);
    padding: 0.15rem 0.5rem;
    border-radius: 4px;
    font-size: 0.8rem;
    font-weight: 600;
    border: 1px solid var(--gold-dim);
}

.game-title {
    color: var(--text-secondary);
    font-size: 0.9rem;
    white-space: normal;
    word-break: break-word;
    max-width: 200px;
}

.server-badge {
    background: rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-size: 0.75rem;
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.card-body {
    padding: 1rem 1.25rem;
    display: flex;
    gap: 1rem;
    flex: 1;
}

.map-icon {
    width: 60px;
    height: 60px;
    border-radius: 8px;
    background: #1e2430;
    display: flex;
    align-items: center;
    justify-content: center;
    border: 1px solid var(--border-color);
    font-size: 2rem;
}

.map-spinner {
    position: absolute;
    top: -6px;
    right: -6px;
    width: 20px;
    height: 20px;
    border: 2px solid rgba(212, 175, 55, 0.2);
    border-top: 2px solid var(--gold-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    background-color: var(--bg-dark);
    box-shadow: 0 0 5px rgba(0,0,0,0.5);
}

@keyframes spin {
    0% { transform: rotate(0deg); }
    100% { transform: rotate(360deg); }
}

.game-details {
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 0.4rem;
}

.detail-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.9rem;
    color: var(--text-primary);
}

.detail-icon {
    color: var(--text-secondary);
    width: 16px;
    display: inline-block;
    text-align: center;
}

.card-footer {
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    display: flex;
    justify-content: space-between;
    align-items: center;
    background: rgba(0, 0, 0, 0.2);
}

.players-count {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.95rem;
}

.players-count .fill-bar {
    width: 60px;
    height: 6px;
    background: rgba(255,255,255,0.1);
    border-radius: 3px;
    overflow: hidden;
}

.players-count .fill-progress {
    height: 100%;
    background: var(--gold-primary);
    border-radius: 3px;
}

.btn-join {
    padding: 0.5rem 1rem;
    border-radius: 4px;
    background: rgba(212, 175, 55, 0.1);
    color: var(--gold-primary);
    border: 1px solid var(--gold-primary);
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-join:hover {
    background: rgba(212, 175, 55, 0.2);
    box-shadow: 0 0 10px rgba(212, 175, 55, 0.3);
}

.btn-view {
    padding: 0.5rem 1rem;
    border-radius: 4px;
    background: rgba(88, 166, 255, 0.1);
    color: #60a5fa;
    border: 1px solid rgba(88, 166, 255, 0.5);
    font-family: var(--font-body);
    font-weight: 500;
    font-size: 0.85rem;
    cursor: pointer;
    transition: var(--transition);
    text-decoration: none;
    display: inline-block;
    text-align: center;
}

.btn-view:hover {
    background: rgba(88, 166, 255, 0.2);
    border-color: #60a5fa;
    box-shadow: 0 0 10px rgba(88, 166, 255, 0.3);
}

.player-list {
    display: none;
    padding: 1rem 1.25rem;
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.25);
    max-height: 150px;
    overflow-y: auto;
}

.lobby-card.expanded .player-list {
    display: block;
}

.player-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.6rem 1rem;
    font-size: 1rem;
    color: var(--text-secondary);
    border-bottom: 1px solid rgba(255,255,255,0.04);
    transition: background 0.2s ease;
}

.player-item:hover {
    background: rgba(255,255,255,0.02);
}

.player-item:last-child {
    border-bottom: none;
}

.player-item .player-name {
    color: var(--text-primary);
}

.player-name {
    font-weight: 500;
    font-size: 1.05rem;
    letter-spacing: 0.3px;
}

.player-stats {
    font-size: 0.8rem;
    color: #cbd5e1;
    background: rgba(255, 255, 255, 0.08);
    padding: 0.2rem 0.6rem;
    border-radius: 12px;
    margin-left: 0.5rem;
    font-weight: 500;
    letter-spacing: 0.3px;
    box-shadow: 0 1px 2px rgba(0,0,0,0.2);
    white-space: nowrap;
}

.player-elo {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--gold-primary);
    letter-spacing: 0.5px;
    text-shadow: 0 0 10px rgba(212, 175, 55, 0.2);
}

.player-item .player-elo {
    color: var(--gold-primary);
    font-weight: 600;
}

.lobby-card:hover .btn-join {
    background: var(--gold-primary);
    color: #000;
}

/* Empty State */
.empty-state {
    grid-column: 1 / -1;
    text-align: center;
    padding: 4rem 2rem;
    background: var(--bg-panel);
    border-radius: 12px;
    border: 1px dashed var(--border-color);
}

.empty-state h3 {
    font-family: var(--font-heading);
    color: var(--gold-primary);
    margin-bottom: 0.5rem;
    font-size: 1.5rem;
}

.empty-state p {
    color: var(--text-secondary);
}

/* Responsive */
@media (max-width: 768px) {
    .filters-section {
        flex-direction: column;
        align-items: stretch;
    }
    .filter-controls {
        flex-direction: column;
    }
    .filter-group {
        width: 100%;
    }
    select {
        width: 100%;
    }
    .lobby-grid {
        grid-template-columns: 1fr;
    }
}

/* Badges for Match Info */
.tags-row {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
    flex-wrap: wrap;
}

.badge {
    padding: 0.25rem 0.6rem;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    letter-spacing: 0.3px;
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    backdrop-filter: blur(4px);
    border: none;
}

.match-type-badge {
    background: rgba(46, 160, 67, 0.2);
    color: #4ade80;
}

.map-size-badge {
    background: rgba(88, 166, 255, 0.2);
    color: #60a5fa;
}

.mod-info-badge {
    background: rgba(139, 148, 158, 0.2);
    color: #94a3b8;
}

.pop-badge {
    background: rgba(212, 175, 55, 0.2);
    color: #fde047;
}

.speed-badge {
    background: rgba(163, 113, 247, 0.2);
    color: #c084fc;
}

.age-badge,
.resources-badge {
    background: rgba(139, 148, 158, 0.2);
    color: #94a3b8;
}

/* Non-standard start age / resources stand out so players can spot them at a glance */
.age-badge.custom-setting,
.resources-badge.custom-setting {
    background: rgba(46, 160, 67, 0.2);
    color: #4ade80;
}

.treaty-badge {
    background: rgba(56, 139, 253, 0.2);
    color: #60a5fa;
}

/* Quick Play matchmaking (not the ranked ladder), and the ladder a match page's ratings come from */
.quickplay-badge {
    background: rgba(45, 212, 191, 0.18);
    color: #5eead4;
}

.ladder-badge {
    background: rgba(212, 175, 55, 0.15);
    color: var(--gold-primary);
}

/* Lobby needs a password (still joinable: the game asks for it) */
.password-badge {
    background: rgba(248, 113, 113, 0.18);
    color: #fca5a5;
}

/* Loader Animation */
.loader-container {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 4rem 2rem;
    grid-column: 1 / -1;
    color: var(--text-secondary);
    font-family: var(--font-body);
}

.loader-container .spinner {
    width: 50px;
    height: 50px;
    border: 3px solid rgba(212, 175, 55, 0.2);
    border-top: 3px solid var(--gold-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    margin-bottom: 1.5rem;
    box-shadow: 0 0 15px rgba(212, 175, 55, 0.2);
}

.spinner-inline {
    display: inline-block;
    width: 14px;
    height: 14px;
    border: 2px solid rgba(255, 255, 255, 0.1);
    border-top: 2px solid var(--gold-primary);
    border-radius: 50%;
    animation: spin 1s linear infinite;
    vertical-align: middle;
    margin-left: 6px;
}

/* List Layout Overrides */
.lobby-grid.list-layout {
    display: flex;
    flex-direction: column;
    gap: 1rem;
}

.lobby-grid.list-layout .lobby-card {
    display: grid;
    grid-template-columns: 3fr 5fr 2fr;
    grid-template-rows: auto auto;
    grid-template-areas: 
        "header body footer"
        "players players players";
    align-items: center;
}

.lobby-grid.list-layout .card-header {
    grid-area: header;
    border-bottom: none;
    border-right: 1px solid var(--border-color);
    padding: 1rem;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.lobby-grid.list-layout .card-body {
    grid-area: body;
    display: flex;
    align-items: center;
    gap: 1.5rem;
    padding: 1rem;
}

.lobby-grid.list-layout .card-footer {
    grid-area: footer;
    border-top: none;
    border-left: 1px solid var(--border-color);
    padding: 1rem;
    height: 100%;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 1rem;
}

.lobby-grid.list-layout .player-list {
    grid-area: players;
}

.lobby-grid.list-layout .map-icon-wrapper {
    margin-bottom: 0;
    width: 60px;
    height: 40px;
}
.lobby-grid.list-layout .game-details {
    flex: 1;
    display: flex;
    flex-direction: column;
}
.lobby-grid.list-layout .tags-row {
    margin-top: 0.5rem;
}

/* Tagline under the logo (part of the h1 so the heading says what the page is) */
.nav-logo h1 .nav-tagline {
    display: block;
    font-family: var(--font-body, inherit);
    font-size: 0.8rem;
    font-weight: 500;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
}

/* About + FAQ below the lobby list */
.about-section {
    margin-top: 3rem;
    padding: 1.5rem 1.75rem;
    color: var(--text-secondary);
    line-height: 1.6;
}

.about-section h2 {
    font-family: var(--font-heading);
    color: var(--text-primary, #fff);
    font-size: 1.2rem;
    margin: 0 0 0.75rem;
}

.about-section h2:not(:first-child) {
    margin-top: 1.5rem;
}

.about-section details {
    border-top: 1px solid var(--border-color);
    padding: 0.75rem 0;
}

.about-section summary {
    cursor: pointer;
    color: var(--text-primary, #fff);
    font-weight: 600;
}

.about-section details p {
    margin: 0.5rem 0 0;
}

.about-section a {
    color: var(--gold-primary);
}

/* "Clear filters": next to the lobby count, and inside the empty state */
.clear-filters-btn {
    margin-left: 0.75rem;
    padding: 4px 12px;
    border-radius: 6px;
    border: 1px solid var(--gold-primary);
    background: var(--gold-dim);
    color: var(--gold-primary);
    font-family: var(--font-body);
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
}

.clear-filters-btn:hover {
    background: rgba(212, 175, 55, 0.3);
}

.empty-state .clear-filters-btn {
    margin: 1rem 0 0;
}

/* A filter that is narrowing the list (remembered between visits) */
select.filter-active,
input.filter-active {
    border-color: var(--gold-primary) !important;
    box-shadow: 0 0 0 1px var(--gold-primary);
    color: var(--gold-primary);
}

/* Per-player profile links: AoE2Insights, official AoE stats (Xbox icon), Steam */
.player-links {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    margin-left: 4px;
}

.player-link {
    display: inline-flex;
    align-items: center;
    white-space: nowrap;
    padding: 1px 6px;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text-secondary);
    font-size: 0.7rem;
    line-height: 1.4;
    text-decoration: none;
}

.player-link:hover {
    border-color: var(--border-hover);
    color: var(--gold-primary);
}

.host-info .player-links {
    margin: 6px 0 0;
}

/* Let a player row wrap (name, stats, profile links) instead of running off narrow screens */
.player-item {
    gap: 0.5rem;
}

.player-item .player-name {
    flex-wrap: wrap;
    min-width: 0;
    row-gap: 4px;
}

.player-list {
    overflow-x: hidden;
}

@media (max-width: 768px) {
    .player-item .player-stats {
        margin-left: 0;
    }
}

/* Spectate view: teams side by side, Spectate button with the spectator-delay countdown */
.spectate-teams {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 0.75rem;
    padding: 0.75rem 1.25rem 1rem;
    border-top: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.25);
}

.spectate-team {
    min-width: 0;
}

.spectate-team-head {
    display: flex;
    justify-content: space-between;
    font-family: var(--font-heading);
    font-size: 0.8rem;
    letter-spacing: 1px;
    color: var(--text-secondary);
    padding: 0 1rem 0.25rem;
    border-bottom: 1px solid var(--border-color);
}

.spectate-teams .player-item {
    padding: 0.45rem 1rem;
    font-size: 0.95rem;
}

.spectate-started {
    margin-top: 0.6rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.spectate-btn.waiting {
    opacity: 0.85;
}

.spectate-countdown {
    font-variant-numeric: tabular-nums;
}

.spectate-more {
    grid-column: 1 / -1;
    display: flex;
    justify-content: center;
    padding: 1rem 0;
}

/* "Live game data unavailable since HH:MM" above the Spectate list */
.spectate-notice {
    grid-column: 1 / -1;
    padding: 0.75rem 1rem;
    border-radius: 8px;
    border: 1px solid var(--gold-dim);
    background: rgba(212, 175, 55, 0.08);
    color: var(--gold-primary);
    font-weight: 500;
    text-align: center;
}

.ai-count {
    color: var(--text-secondary);
    font-size: 0.85em;
}

/* A player's civilization (what they picked in the lobby, or what they play in Spectate) */
.civ-chip {
    font-size: 0.75rem;
    font-weight: 600;
    color: #e5c560;
    background: rgba(212, 175, 55, 0.12);
    border: 1px solid rgba(212, 175, 55, 0.25);
    padding: 0.1rem 0.5rem;
    border-radius: 10px;
    white-space: nowrap;
}

/* Lobby Full / Cannot Join / Cannot Spectate: not clickable, so don't look like the gold Join button */
.btn-join.disabled,
.lobby-card:hover .btn-join.disabled {
    opacity: 0.5;
    cursor: not-allowed;
    pointer-events: none;
    background: transparent;
    color: var(--text-secondary);
    border-color: var(--border-color);
}

/* Keyboard focus stays visible (.btn turns the browser outline off) */
.btn:focus-visible,
.btn-join:focus-visible,
.btn-view:focus-visible,
.player-link:focus-visible,
.clear-filters-btn:focus-visible,
.match-link:focus-visible,
.match-view a:focus-visible,
.match-view button:focus-visible,
.match-view input:focus-visible {
    outline: 2px solid var(--gold-primary);
    outline-offset: 2px;
}

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}

/* Player colours 1-8 (aoe2companion's colorHex). The light edge keeps blue and grey visible on the dark panels,
   and the dark ring keeps yellow and teal from glowing into them */
.player-color {
    flex: none;
    display: inline-block;
    width: 14px;
    height: 14px;
    border-radius: 3px;
    border: 1px solid rgba(255, 255, 255, 0.45);
    box-shadow: 0 0 0 1px rgba(0, 0, 0, 0.55);
}

.player-color-1 { background: #405BFF; }
.player-color-2 { background: #FF0000; }
.player-color-3 { background: #00FF00; }
.player-color-4 { background: #FFFF00; }
.player-color-5 { background: #00FFFF; }
.player-color-6 { background: #FF57B3; }
.player-color-7 { background: #797979; }
.player-color-8 { background: #FF9600; }

.player-color-none {
    border-style: dashed;
    border-color: var(--border-color);
    box-shadow: none;
}

.spectate-teams .player-color {
    width: 10px;
    height: 10px;
    border-radius: 2px;
}

.civs-hidden-badge {
    background: rgba(139, 148, 158, 0.2);
    color: #cbd5e1;
}

/* Spectate cards: the map name and Details lead to the game's own page */
.match-link {
    color: inherit;
    text-decoration: none;
    overflow-wrap: anywhere;
}

.match-link:hover {
    color: var(--gold-primary);
    text-decoration: underline;
}

/* On narrow cards the buttons drop below the player count as one row instead of squeezing it */
.spectate-card .card-footer {
    flex-wrap: wrap;
    gap: 0.75rem;
}

.spectate-card .players-count-text {
    white-space: nowrap;
}

.spectate-actions {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-end;
    align-items: center;
    gap: 0.5rem;
    margin-left: auto;
}

/* ---------------------------------------------------------------- Match page (/spectate/<id>) */
.match-view {
    padding-bottom: 3rem;
}

.match-view[hidden],
.match-view [hidden] {
    display: none !important;
}

.match-header {
    padding: 1.5rem;
    margin-bottom: 1.25rem;
}

.match-topline {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
    margin-bottom: 0.6rem;
}

/* LIVE / ENDED / Not found; z-index keeps the pulse ring above the pill's own background */
.match-status {
    position: relative;
    z-index: 0;
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.2rem 0.75rem;
    border-radius: 999px;
    border: 1px solid var(--border-color);
    font-size: 0.75rem;
    font-weight: 700;
    letter-spacing: 1px;
}

.match-status .pulse-indicator {
    width: 8px;
    height: 8px;
}

.match-status-live {
    color: #4ade80;
    border-color: rgba(46, 160, 67, 0.6);
    background: rgba(46, 160, 67, 0.15);
}

.match-status-ended {
    color: var(--gold-primary);
    border-color: var(--gold-dim);
    background: rgba(212, 175, 55, 0.1);
}

.match-status-unknown {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
}

.match-spectators {
    color: var(--text-secondary);
    font-size: 0.9rem;
}

.match-title {
    font-family: var(--font-heading);
    font-size: 2rem;
    font-weight: 700;
    line-height: 1.2;
    overflow-wrap: anywhere;
}

.match-subtitle {
    color: var(--text-secondary);
    overflow-wrap: anywhere;
}

.match-loading {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    margin-top: 0.5rem;
}

.match-loading .spinner-inline,
.match-result-pending .spinner-inline {
    margin-left: 0;
}

.match-timing {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem 1.25rem;
    margin-top: 1rem;
    color: var(--text-secondary);
    font-size: 0.95rem;
}

.match-countdown {
    color: var(--gold-primary);
    font-variant-numeric: tabular-nums;
}

.match-actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

.match-actions .btn-join,
.match-actions .btn-view {
    padding: 0.6rem 1.1rem;
    font-size: 0.95rem;
}

.match-watch {
    background: var(--gold-primary);
    color: #000;
    font-weight: 600;
}

.match-watch:hover {
    background: #e5c355;
}

.match-back {
    color: var(--text-secondary);
    text-decoration: none;
    font-size: 0.95rem;
    padding: 0.35rem 0.25rem;
}

.match-back:hover {
    color: var(--gold-primary);
    text-decoration: underline;
}

.match-copy-fallback {
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
    margin-top: 0.75rem;
    max-width: 640px;
}

.match-copy-fallback label {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.match-copy-fallback input {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border-radius: 6px;
    border: 1px solid var(--border-color);
    background: rgba(0, 0, 0, 0.3);
    color: var(--text-primary);
    font: inherit;
    font-size: 0.9rem;
}

.match-notes:not(:empty) {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.match-notes .spectate-notice {
    text-align: left;
}

.match-refresh-note,
.match-note,
.rating-kind {
    color: var(--text-secondary);
    font-size: 0.85rem;
}

/* Result (once the game has ended) and the not-found message */
.match-result {
    padding: 1.25rem 1.5rem;
    margin-bottom: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.match-result h2 {
    font-family: var(--font-heading);
    font-size: 1.2rem;
}

.match-result-pending {
    display: flex;
    align-items: center;
    gap: 0.6rem;
    color: var(--text-secondary);
}

.match-winner {
    font-size: 1.15rem;
    font-weight: 600;
    overflow-wrap: anywhere;
}

.match-winner-names {
    color: var(--gold-primary);
}

.match-length {
    color: var(--text-secondary);
}

.match-result-players {
    list-style: none;
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
}

.match-result-player {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem 0.6rem;
}

.match-result-name {
    font-weight: 500;
    overflow-wrap: anywhere;
    min-width: 0;
}

.result-tag {
    font-size: 0.75rem;
    font-weight: 700;
    padding: 0.05rem 0.55rem;
    border-radius: 10px;
}

.result-won {
    color: #4ade80;
    background: rgba(46, 160, 67, 0.18);
}

.result-lost {
    color: #fca5a5;
    background: rgba(248, 113, 113, 0.15);
}

.rating-change {
    font-weight: 700;
    font-variant-numeric: tabular-nums;
}

.rating-up {
    color: #4ade80;
}

.rating-down {
    color: #f87171;
}

.match-replay {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem 0.75rem;
}

/* Teams: one card per team, and one per player without a team */
.match-teams {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(min(100%, 320px), 1fr));
    gap: 1rem;
}

.match-team {
    min-width: 0;
    padding: 1rem 0 0.4rem;
}

.match-team-head {
    display: flex;
    justify-content: space-between;
    align-items: baseline;
    gap: 0.5rem;
    padding: 0 1.25rem 0.5rem;
    border-bottom: 1px solid var(--border-color);
    font-family: var(--font-heading);
    font-size: 1rem;
    letter-spacing: 1px;
}

.match-team-avg {
    font-family: var(--font-body);
    font-size: 0.8rem;
    letter-spacing: 0.3px;
    color: var(--text-secondary);
}

.match-team-avg .player-elo {
    font-size: 0.95rem;
}

.match-players {
    list-style: none;
}

.match-player {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.65rem 1.25rem;
    border-bottom: 1px solid rgba(255, 255, 255, 0.04);
}

.match-player:last-child {
    border-bottom: none;
}

.match-player-main {
    flex: 1;
    min-width: 0;
    display: flex;
    flex-direction: column;
    gap: 0.3rem;
}

.match-player-name {
    font-weight: 600;
    font-size: 1.05rem;
    overflow-wrap: anywhere;
}

.match-player-meta {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.35rem;
}

.match-player-meta:empty {
    display: none;
}

.match-player-meta .player-links {
    margin-left: 0;
    flex-wrap: wrap;
}

.match-player .player-elo {
    flex: none;
}

.civ-chip.civ-hidden {
    color: var(--text-secondary);
    background: rgba(255, 255, 255, 0.05);
    border-color: var(--border-color);
    font-style: italic;
}

/* Country: uppercase code, full name in the tooltip */
.country-badge {
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.5px;
    padding: 0 0.4rem;
    border-radius: 4px;
    border: 1px solid var(--border-color);
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    text-decoration: none;
    cursor: help;
}

@media (max-width: 480px) {
    .match-mode .app-container {
        padding: 0 1rem;
    }
    .match-header,
    .match-result {
        padding: 1rem;
    }
    .match-title {
        font-size: 1.5rem;
    }
    .match-team-head {
        padding: 0 1rem 0.5rem;
    }
    .match-player {
        gap: 0.6rem;
        padding: 0.6rem 1rem;
    }
}

/* ---------------------------------------------------------------- Civ details (a civ chip with details is a button) */
button.civ-chip {
    font-family: var(--font-body);
    line-height: inherit;
    cursor: pointer;
}
.civ-chip-info {
    text-decoration: underline dotted rgba(229, 197, 96, 0.6);
    text-underline-offset: 2px;
}
.civ-chip-info:hover,
.civ-chip-info[aria-expanded="true"] {
    background: rgba(212, 175, 55, 0.24);
    border-color: rgba(212, 175, 55, 0.55);
}
.civ-chip-info:focus-visible,
.follow-btn:focus-visible,
.follow-remove:focus-visible,
.toast a:focus-visible,
.toast button:focus-visible,
.follow-panel a:focus-visible,
.follow-panel button:focus-visible,
.civ-popover:focus-visible {
    outline: 2px solid var(--gold-primary);
    outline-offset: 2px;
}

.civ-popover {
    position: absolute;
    z-index: 1000;
    width: min(360px, calc(100vw - 16px));
    overflow-y: auto;
    padding: 0.9rem 1rem;
    background: #12161d;
    border: 1px solid rgba(212, 175, 55, 0.4);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.55);
    color: var(--text-primary);
    font-size: 0.85rem;
    line-height: 1.45;
}
.civ-popover[hidden] { display: none; }
.civ-pop-head { margin-bottom: 0.5rem; }
.civ-pop-name { font-family: var(--font-heading); font-size: 1.05rem; color: var(--gold-primary); margin: 0; }
.civ-pop-type { color: var(--text-secondary); font-size: 0.8rem; }
.civ-popover h4 {
    margin: 0.65rem 0 0.25rem;
    font-size: 0.72rem;
    letter-spacing: 0.06em;
    text-transform: uppercase;
    color: var(--text-secondary);
}
.civ-popover ul { list-style: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.25rem; }
.civ-popover > ul:first-of-type li { padding-left: 0.9rem; position: relative; }
.civ-popover > ul:first-of-type li::before { content: '•'; position: absolute; left: 0; color: var(--gold-secondary); }
.civ-pop-kind { color: var(--text-secondary); font-size: 0.78rem; }
.civ-pop-stats { display: block; color: #cbd5e1; font-size: 0.78rem; font-variant-numeric: tabular-nums; }
.civ-pop-source { margin-top: 0.65rem; color: var(--text-secondary); font-size: 0.72rem; }

/* ---------------------------------------------------------------- Followed players */
.follow-btn {
    background: none;
    border: none;
    padding: 0 0.15rem;
    cursor: pointer;
    color: var(--text-secondary);
    font-size: 1rem;
    line-height: 1;
    border-radius: 4px;
}
.follow-btn:hover { color: var(--gold-primary); }
.follow-btn.following { color: var(--gold-primary); }
.match-player-name .follow-btn { margin-left: 0.35rem; vertical-align: 0.05em; }

.follow-panel { padding: 0.9rem 1.25rem; margin-bottom: 20px; }
.follow-panel[hidden] { display: none; }
.follow-head { display: flex; flex-wrap: wrap; align-items: center; justify-content: space-between; gap: 0.5rem 1rem; margin-bottom: 0.6rem; }
.follow-title { font-size: 1rem; margin: 0; }
.follow-count { color: var(--text-secondary); font-family: var(--font-body); font-size: 0.85rem; font-weight: 500; margin-left: 0.35rem; }
.follow-note { color: var(--text-secondary); font-size: 0.85rem; margin: 0; }
.follow-desktop { padding: 0.3rem 0.75rem; font-size: 0.8rem; }
.follow-desktop[aria-pressed="true"] { background: rgba(88, 166, 255, 0.22); }
.follow-list { list-style: none; margin: 0; padding: 0; display: flex; flex-wrap: wrap; gap: 0.5rem; }
.follow-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.3rem 0.35rem 0.3rem 0.7rem;
    border: 1px solid var(--border-color);
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.03);
    font-size: 0.85rem;
    max-width: 100%;
}
.follow-item.follow-live { border-color: rgba(212, 175, 55, 0.4); }
.follow-name { font-weight: 600; overflow-wrap: anywhere; }
.follow-idle { color: var(--text-secondary); font-size: 0.8rem; white-space: nowrap; }
.follow-game { color: var(--gold-primary); text-decoration: none; display: inline-flex; align-items: center; gap: 0.35rem; font-size: 0.8rem; }
.follow-game:hover { text-decoration: underline; }
.follow-game .pulse-indicator { width: 8px; height: 8px; margin: 0; }
.follow-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.05rem;
    line-height: 1;
    width: 1.5rem;
    height: 1.5rem;
    border-radius: 50%;
}
.follow-remove:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.08); }

/* ---------------------------------------------------------------- Alerts */
.toasts {
    position: fixed;
    right: 16px;
    bottom: 16px;
    z-index: 1100;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    width: min(360px, calc(100vw - 32px));
}
.toasts:empty { display: none; }
.toast {
    position: relative;
    padding: 0.75rem 2.25rem 0.75rem 1rem;
    background: #12161d;
    border: 1px solid rgba(212, 175, 55, 0.45);
    border-radius: 8px;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    font-size: 0.9rem;
    animation: toast-in 0.25s ease-out;
}
@keyframes toast-in {
    from { opacity: 0; transform: translateY(8px); }
    to { opacity: 1; transform: none; }
}
@media (prefers-reduced-motion: reduce) {
    .toast { animation: none; }
}
.toast p { margin: 0; overflow-wrap: anywhere; }
.toast-actions { display: flex; flex-wrap: wrap; gap: 0.4rem 1rem; margin-top: 0.4rem !important; }
.toast-actions a,
.toast-link { color: var(--gold-primary); font-weight: 600; font-size: 0.85rem; }
.toast-link { background: none; border: none; padding: 0; font-family: var(--font-body); text-decoration: underline; cursor: pointer; }
.follow-note:focus-visible { outline: 2px solid var(--gold-primary); outline-offset: 2px; }
.toast-close {
    position: absolute;
    top: 0.35rem;
    right: 0.35rem;
    background: none;
    border: none;
    color: var(--text-secondary);
    cursor: pointer;
    font-size: 1.1rem;
    width: 1.75rem;
    height: 1.75rem;
    border-radius: 50%;
}
.toast-close:hover { color: var(--text-primary); background: rgba(255, 255, 255, 0.08); }

/* ---------------------------------------------------------------- Caster tools (match page) */
.caster-tools { margin-top: 1.25rem; padding: 0; }
.caster-tools > summary {
    cursor: pointer;
    padding: 1rem 1.5rem;
    font-weight: 600;
    color: var(--text-secondary);
    list-style-position: inside;
}
.caster-tools > summary:hover { color: var(--text-primary); }
.caster-tools > summary:focus-visible { outline: 2px solid var(--gold-primary); outline-offset: -2px; border-radius: 8px; }
.caster-tools[open] > summary { color: var(--text-primary); border-bottom: 1px solid var(--border-color); }
.caster-body { padding: 1rem 1.5rem 1.25rem; display: flex; flex-direction: column; gap: 0.9rem; }
.caster-mode { border: none; margin: 0; padding: 0; display: flex; flex-direction: column; gap: 0.45rem; }
.caster-mode legend { font-weight: 600; margin-bottom: 0.4rem; font-size: 0.9rem; }
.caster-check { display: inline-flex; align-items: center; gap: 0.45rem; flex-wrap: wrap; font-size: 0.9rem; }
.caster-follow { display: grid; grid-template-columns: auto minmax(0, 1fr); align-items: center; gap: 0.35rem 0.45rem; }
.caster-follow label { cursor: pointer; }
.caster-follow select { grid-column: 2; justify-self: start; }
.caster-row { display: flex; flex-wrap: wrap; align-items: flex-end; gap: 0.75rem 1.25rem; }
.caster-field { display: flex; flex-direction: column; gap: 0.3rem; font-size: 0.8rem; color: var(--text-secondary); min-width: 0; }
.caster-tools input[type="text"],
.caster-tools select {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    color: var(--text-primary);
    padding: 0.45rem 0.6rem;
    font-family: var(--font-body);
    font-size: 0.9rem;
    min-width: 0;
    max-width: 100%;
}
.caster-tools select option { background: #12161d; }
.caster-tools input:focus-visible,
.caster-tools select:focus-visible { outline: 2px solid var(--gold-primary); outline-offset: 1px; }
.caster-sides { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 1rem; }
.caster-side { display: flex; flex-direction: column; gap: 0.5rem; }
.caster-score { display: flex; align-items: center; gap: 0.5rem; }
.caster-score-label { font-size: 0.8rem; color: var(--text-secondary); margin-right: 0.25rem; }
.caster-step {
    width: 2rem;
    height: 2rem;
    border-radius: 6px;
    border: 1px solid rgba(212, 175, 55, 0.45);
    background: rgba(212, 175, 55, 0.1);
    color: var(--gold-primary);
    font-size: 1.1rem;
    cursor: pointer;
}
.caster-step:disabled { opacity: 0.35; cursor: not-allowed; }
.caster-score-value { min-width: 1.5rem; text-align: center; font-weight: 700; font-size: 1.1rem; font-variant-numeric: tabular-nums; }
.caster-url-label { font-size: 0.8rem; color: var(--text-secondary); margin-bottom: -0.5rem; }
.caster-url { display: flex; flex-wrap: wrap; gap: 0.5rem; }
.caster-url input { flex: 1 1 260px; font-size: 0.8rem !important; }
.caster-multi[hidden] { display: none; }

@media (max-width: 480px) {
    .caster-tools > summary { padding: 1rem; }
    .caster-body { padding: 1rem; }
    .caster-sides { grid-template-columns: minmax(0, 1fr); }
    .toasts { right: 16px; left: 16px; width: auto; }
}
