:root {
    /* MODERN PALETTE */
    --bg-gradient: radial-gradient(circle at top left, #0f3d0f, #b21f1f, #fdbb2d);
    --bg-dark: #0f0f13;
    
    /* Glassmorphism Cards */
    --card-bg: rgba(255, 255, 255, 0.05);
    --card-border: 1px solid rgba(255, 255, 255, 0.1);
    --card-shadow: 0 8px 32px 0 rgba(0, 0, 0, 0.37);
    
    /* Active Player */
    --active-bg: linear-gradient(135deg, #ffffff 0%, #e0e0e0 100%);
    --active-text: #222;
    --active-shadow: 0 10px 40px -10px rgba(255, 255, 255, 0.5);

    /* Accents */
    --accent-gold: #ffd700;
    --accent-blue: #00ff41; 
    --accent-green: #00ccff; 
    
    --font-main: 'Montserrat', sans-serif;
    --font-num: 'Roboto', sans-serif;
}

body { 
    margin: 0; overflow: hidden; height: 100vh; width: 100vw;
    background: #0f0f13; 
    background-image: radial-gradient(circle at 50% 0%, #1a2a1f 0%, #050505 100%);
    color: #fff;
    font-family: var(--font-main);
    display: flex; flex-direction: column;
    align-items: center;
}

/* --- VIEW MANAGEMENT --- */
.view {
    width: 100%;
    height: 100%;
    display: flex;
    flex-direction: column;
    align-items: center;
}
.view.hidden { display: none !important; }

#auth-view, #profile-view {
    justify-content: center; /* Keskitä kirjautuminen pystysuunnassa */
}

/* --- AUTH & PROFILE CARDS --- */
.auth-card, .profile-card {
    background: var(--card-bg);
    border: var(--card-border);
    padding: 40px;
    border-radius: 20px;
    backdrop-filter: blur(15px);
    text-align: center;
    max-width: 400px;
    width: 90%;
    box-shadow: var(--card-shadow);
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 15px;
    margin: 30px 0;
}

.input-group input {
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 50px;
    color: white;
    font-family: var(--font-main);
    font-size: 1rem;
    text-align: center;
    outline: none;
    transition: all 0.3s ease;
}

.input-group input:focus {
    border-color: var(--accent-green);
    background: rgba(0, 0, 0, 0.5);
    box-shadow: 0 0 15px rgba(0, 204, 255, 0.2);
}

#btn-login:hover, #btn-logout:hover {
    transform: scale(1.05);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.3);
}

/* --- HEADER --- */
.header-bar {
    width: 100%;
    padding: 20px 0;
    text-align: center;
    background: linear-gradient(to bottom, rgba(0, 0, 0, 0.8), transparent);
    z-index: 10;
    flex-shrink: 0;
}

.venue-pill {
    display: inline-block;
    background: rgba(0, 255, 65, 0.15);
    border: 1px solid var(--accent-blue);
    padding: 8px 24px;
    border-radius: 50px;
    color: var(--accent-blue);
    font-weight: 700;
    letter-spacing: 2px;
    text-transform: uppercase;
    font-size: 0.9rem;
    backdrop-filter: blur(10px);
    box-shadow: 0 0 20px rgba(0, 255, 65, 0.2);
    transition: all 0.3s;
}

.match-mode {
    margin-top: 8px;
    font-size: 0.9rem;
    color: rgba(255,255,255,0.5);
    letter-spacing: 1px;
}

/* --- MAIN CONTENT --- */
#main-container {
    flex: 1;
    width: 100%;
    max-width: 1280px; /* Leveä näyttö */
    padding: 20px;
    box-sizing: border-box;
    overflow-y: auto;
    display: flex;
    flex-direction: column;
    gap: 15px;
    scrollbar-width: none; 
}
#main-container::-webkit-scrollbar { display: none; }

/* --- PLAYER CARD --- */
.player-card {
    position: relative;
    display: grid;
    grid-template-columns: auto 1fr auto;
    align-items: center;
    padding: 15px;
    border-radius: 20px;
    background: var(--card-bg);
    border: var(--card-border);
    box-shadow: var(--card-shadow);
    backdrop-filter: blur(8px);
    transition: all 0.4s cubic-bezier(0.25, 0.8, 0.25, 1);
    transform: perspective(1000px) rotateX(0deg);
}

.player-card.active {
    background: var(--active-bg);
    color: var(--active-text);
    box-shadow: var(--active-shadow);
    transform: perspective(1000px) scale(1.03) translateZ(10px);
    z-index: 5;
    border: none;
}

.score-orb {
    width: 140px; height: 140px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    font-family: var(--font-num);
    font-size: 3rem; font-weight: 900;
    letter-spacing: -2px;
    margin-right: 20px;
    position: relative;
    background: radial-gradient(circle at 30% 30%, #ffffff, #d1d1d1);
    box-shadow: 5px 5px 15px rgba(0,0,0,0.3), inset -5px -5px 10px rgba(0,0,0,0.1), inset 5px 5px 10px rgba(255,255,255,1);
    color: #333;
}

.player-card.active .score-orb {
    background: radial-gradient(circle at 30% 30%, #e0f7fa, #00ccff);
    color: #004d66; 
    box-shadow: 0 0 20px rgba(0, 204, 255, 0.6), inset 5px 5px 10px rgba(255,255,255,0.8);
}

.info-col { display: flex; flex-direction: column; justify-content: center; }

.p-name {
    font-size: 2rem; font-weight: 900;
    text-transform: uppercase;
    letter-spacing: -0.5px;
    margin-bottom: 5px;
    background: linear-gradient(to right, #fff, #aaa);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
}
.player-card.active .p-name { background: none; -webkit-text-fill-color: #222; }

.stats-row { display: flex; gap: 15px; font-size: 0.9rem; font-weight: 600; opacity: 0.7; font-family: var(--font-num); }
.player-card.active .stats-row { opacity: 1; color: #444; }

.wins-badge {
    background: linear-gradient(135deg, #333, #111);
    color: var(--accent-gold);
    padding: 10px 20px;
    border-radius: 12px;
    text-align: center;
    border: 1px solid rgba(255, 215, 0, 0.2);
    box-shadow: inset 0 2px 5px rgba(255,255,255,0.05);
    min-width: 80px;
}
.sets-val { font-size: 0.8rem; text-transform: uppercase; color: #888; margin-bottom: 2px; }
.legs-val { font-size: 2.2rem; font-weight: 900; line-height: 1; font-family: var(--font-num); }

/* --- LOWER THIRD --- */
.lower-third {
    width: 100%;
    background: #000;
    border-top: 4px solid var(--accent-blue);
    padding: 15px 30px;
    display: flex; align-items: center; justify-content: space-between;
    box-shadow: 0 -10px 50px rgba(0,0,0,0.8);
    z-index: 20;
    position: relative; overflow: hidden;
    flex-shrink: 0;
}
.lower-third::before {
    content: ''; position: absolute; top: 0; left: 0; width: 100%; height: 50%;
    background: linear-gradient(to bottom, rgba(255,255,255,0.05), transparent);
    pointer-events: none;
}

.status-left { display: flex; flex-direction: column; }
.status-label { font-size: 0.8rem; color: var(--accent-blue); letter-spacing: 2px; font-weight: 700; text-transform: uppercase; margin-bottom: 2px; }
.status-player { font-size: 1.5rem; font-weight: 800; text-transform: uppercase; color: #fff; }
.status-center { font-family: var(--font-num); font-size: 4rem; font-weight: 900; color: #fff; text-shadow: 0 0 20px rgba(255,255,255,0.4); line-height: 1; }
.status-right { font-family: var(--font-num); font-size: 1.5rem; font-weight: 700; color: #888; letter-spacing: 5px; }

/* --- OVERLAYS --- */
#idle-view, #victory-view {
    position: absolute; top: 0; left: 0; width: 100%; height: 100%;
    background: rgba(0,0,0,0.9); z-index: 100;
    display: flex; flex-direction: column; align-items: center; justify-content: center;
    backdrop-filter: blur(15px);
}
.hidden { display: none !important; }
.blink { animation: pulse 2s infinite; }
@keyframes pulse { 0% { opacity: 0.5; } 50% { opacity: 1; } 100% { opacity: 0.5; } }

h1.big-title { 
    font-size: 5rem; margin: 0; font-weight: 900; 
    background: linear-gradient(to bottom, #fff, #aaa);
    -webkit-background-clip: text; -webkit-text-fill-color: transparent;
    text-transform: uppercase; letter-spacing: -2px;
}
.code-display { 
    font-size: 6rem; 
    color: var(--accent-green); 
    font-family: var(--font-num); 
    font-weight: 900; 
    letter-spacing: 15px; 
    margin: 30px 0; 
    text-shadow: 0 0 30px rgba(0, 204, 255, 0.5); 
}

/* --- TIMEOUT WARNING STYLE --- */
#timeout-warning {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.95);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 5000;
    backdrop-filter: blur(5px);
}

.timeout-container { text-align: center; animation: pulse-red 1.5s infinite; }
.timeout-title { font-size: 3rem; font-weight: 900; color: #fff; text-transform: uppercase; margin-bottom: 20px; letter-spacing: 2px; }
.timeout-timer { font-size: 15rem; font-weight: 900; line-height: 1; font-family: var(--font-num); color: #ff3333; text-shadow: 0 0 50px rgba(255, 51, 51, 0.6); }
.timeout-desc { font-size: 1.2rem; color: #aaa; margin-top: 20px; text-transform: uppercase; letter-spacing: 2px; }
@keyframes pulse-red { 0% { transform: scale(1); } 50% { transform: scale(1.05); } 100% { transform: scale(1); } }

/* --- HEADS UP MODE (2 PLAYERS) --- */
#main-container.heads-up-mode {
    display: grid;
    grid-template-columns: 1fr 1fr;
    width: 100%;
    height: 100%;
    max-width: none;
    padding: 0;
    margin: 0;
    gap: 0;
    position: absolute;
    top: 0;
    left: 0;
    z-index: 5;
}

.split-pane {
    position: relative;
    display: flex !important;
    flex-direction: column;
    justify-content: flex-start;
    align-items: center;
    height: 100%;
    overflow: hidden;
    transition: all 0.3s ease;
    
    /* REUNUSTEN HALLINTA */
    box-sizing: border-box; /* TÄRKEÄ: Pitää leveyden kurissa reunuksesta huolimatta */
    border: 6px solid transparent; /* Varataan tila reunalle, oletuksena läpinäkyvä */
}
/* 1. Nimi-palkki (Musta) */
.player-header-name {
    width: 100%;
    background-color: #000;
    color: #fff;
    font-family: var(--font-main);
    font-weight: 900;
    font-size: 2.5rem;
    text-transform: uppercase;
    text-align: center;
    padding: 15px 0;
    z-index: 20;
    letter-spacing: 2px;
    box-shadow: 0 5px 15px rgba(0,0,0,0.5);
    /* Varmistetaan että teksti ei mene kuvien alle */
    position: relative; 
}

/* 2. Stat-palkki (Harmaa/Tumma, nimen alla) */
.player-header-stats {
    width: 100%;
    background-color: rgba(30, 30, 30, 0.9); /* Tummanharmaa, hieman läpinäkyvä */
    border-bottom: 1px solid rgba(255,255,255,0.1);
    display: flex;
    justify-content: center;
    gap: 60px; /* Reilu väli */
    padding: 10px 0;
    z-index: 19;
    position: relative;
    backdrop-filter: blur(5px);
}

.ph-stat-item {
    display: flex;
    flex-direction: column;
    align-items: center;
    line-height: 1;
}

.ph-label {
    font-size: 0.7rem;
    color: #aaa;
    margin-bottom: 3px;
    font-weight: 700;
    letter-spacing: 1px;
}

.ph-value {
    font-family: var(--font-num);
    font-size: 1.8rem;
    font-weight: 900;
    color: var(--accent-gold);
}

/* 3. Pääsisältö (Pisteet, Checkout, Heitot) - Keskitetään jäljelle jäävään tilaan */
.player-center-content {
    flex: 1; /* Ottaa kaiken jäljelle jäävän tilan */
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    width: 100%;
    position: relative;
    z-index: 10;
}

/* Säädetään vanhoja elementtejä uuteen layoutiin */
.hud-score {
    margin-top: -20px; /* Hienosäätö, nostetaan vähän */
}

/* Jos taustakuva on päällä, varmistetaan että se on "alla" */
.split-pane-bg {
    z-index: 0;
}
.split-pane.p1 { background: radial-gradient(circle at 30% 50%, #004d00, #001a00); }
.split-pane.p2 { background: radial-gradient(circle at 70% 50%, #b21f1f, #240b0b); }

.split-pane:not(.active-turn) {
    filter: grayscale(1) brightness(0.5);
    z-index: 1;
    border-color: rgba(255,255,255,0.05); /* Hyvin haalea reunus ei-aktiiviselle */
}
.split-pane.active-turn {
    filter: grayscale(0) brightness(1.0);
    z-index: 10;
    
    /* KELTAINEN REUNUS JA HEHKU */
    border-color: #FFD700; /* Kirkas kulta/keltainen */
    box-shadow: 
        0 0 30px rgba(255, 215, 0, 0.2),  /* Ulkoinen hehku */
        inset 0 0 20px rgba(255, 215, 0, 0.1); /* Sisäinen hehku */
    
    transform: scale(1); /* Palautetaan normaali koko */
}
.big-bg-char {
    position: absolute; top: 50%; left: 50%; transform: translate(-50%, -50%);
    font-family: var(--font-main); font-size: 80vh; font-weight: 900; color: rgba(255, 255, 255, 0.05);
    z-index: 0; pointer-events: none; line-height: 1;
}

.hud-content { position: relative; z-index: 2; text-align: center; display: flex; flex-direction: column; align-items: center; gap: 10px; }
.hud-name { font-size: 2.5rem; font-weight: 900; text-transform: uppercase; letter-spacing: 2px; margin-bottom: 20px; text-shadow: 0 4px 20px rgba(0,0,0,0.5); }
.hud-score { font-family: var(--font-num);
    /* Oletuskoko kun pelaaja EI ole vuorossa */
    font-size: 15rem !important; 
    font-weight: 900;
    line-height: 0.9;
    color: #fff;
    text-shadow: 0 10px 30px rgba(0,0,0,0.5);
    
    /* PEHMEÄ SIIRTYMÄ */
    transition: all 0.6s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    opacity: 0.4; /* Himmennetään ei-aktiivista scorea */
    transform: scale(0.7);}
.active-turn .hud-score {
    font-size: 30rem !important; /* Kasvaa suureksi */
    color: #ffffff;
    text-shadow: 0 0 50px rgba(0, 204, 255, 0.4);
    opacity: 1;
    transform: scale(1);
}
@keyframes flyInScore {
    0% { 
        opacity: 0; 
        transform: translate(-50%, -50%) scale(0.1); /* Alkaa pienenä kaukana */
    }
    20% { 
        opacity: 1; 
        transform: translate(-50%, -50%) scale(1.2); /* Hypähtää vähän yli */
    }
    40% { 
        transform: translate(-50%, -50%) scale(1); /* Asettuu hetkeksi */
    }
    80% { 
        opacity: 1; 
        transform: translate(-50%, -50%) scale(1.1); 
    }
    100% { 
        opacity: 0; 
        transform: translate(-50%, -50%) scale(10); /* LENTÄÄ PÄIN RUUTUA (kasvaa jättimäiseksi) */
    }
}

/* Otetaan uusi animaatio käyttöön turn-overlaylle */
#turn-overlay.pop-active { 
    animation: flyInScore 2.2s ease-in-out forwards; 
}
.hud-stats-grid {
    display: grid; grid-template-columns: repeat(2, 1fr); gap: 20px; margin-top: 30px;
    background: rgba(0,0,0,0.4); padding: 15px 30px; border-radius: 20px; backdrop-filter: blur(5px);
}
.stat-box { display: flex; flex-direction: column; }
.stat-label { font-size: 0.8rem; color: #aaa; font-weight: 700; letter-spacing: 1px; }
.stat-value { font-size: 1.8rem; font-family: var(--font-num); font-weight: 700; }

.last-throws-row {
    margin-top: 15px;
    font-family: var(--font-num);
    font-size: 5rem;
    color: var(--accent-blue);
    font-weight: 700;
    letter-spacing: 3px;
    background: rgba(0, 255, 65, 0.1);
    padding: 5px 15px;
    border-radius: 50px;
    border: 1px solid rgba(0, 255, 65, 0.2);
}
.heads-up-mode + .lower-third { display: none; }

/* --- CENTRAL SCORE POPUP --- */
#turn-overlay {
    position: fixed;
    top: 50%;
    left: 50%;
    width: 100%;
    height: 100%;
    transform: translate(-50%, -50%) scale(0);
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    background: #000000e3;
    border: none;
    box-shadow: none;
    padding: 0;
    z-index: 2000;
    pointer-events: none;
    opacity: 0;
}
.popup-name {
    font-family: var(--font-main); font-size: 5rem; font-weight: 900; text-transform: uppercase;
    letter-spacing: 5px; color: #fff; text-shadow: 0 0 10px rgba(0,0,0,0.8); margin-bottom: -20px; z-index: 2;
}
.popup-score {
    font-family: var(--font-num); font-size: 28rem; font-weight: 900; line-height: 1; color: #fff;
    text-shadow: 0 10px 0 #000, 0 0 20px rgba(0,0,0,0.5), 0 0 50px #000; z-index: 1;
}
#turn-overlay.pop-active { animation: centerPop 2.2s ease-in-out forwards; }
#turn-overlay.score-180 .popup-score {
    color: var(--accent-gold); text-shadow: 0 10px 0 #8b0000, 0 0 30px var(--accent-gold), 0 0 80px #ff0000;
}
#turn-overlay.score-180 .popup-name { color: #fff; text-shadow: 0 0 20px var(--accent-gold); }

@keyframes centerPop {
    0% { opacity: 0; transform: translate(-50%, -50%) scale(0.5); }
    10% { opacity: 1; transform: translate(-50%, -50%) scale(1.1); }
    20% { opacity: 1; transform: translate(-50%, -50%) scale(1.0); }
    80% { opacity: 1; transform: translate(-50%, -50%) scale(1.0); }
    100% { opacity: 0; transform: translate(-50%, -50%) scale(1.3) translateY(-30px); }
}

.popup-score.bust-mode {
    color: #ff0000; font-size: 15rem; text-shadow: 0 10px 0 #8b0000, 0 0 30px #ff0000, 0 0 80px rgba(255, 0, 0, 0.5);
    letter-spacing: 5px; transform: rotate(-5deg);
}


/* --- TOURNAMENT LIST (Profile) --- */
.tournament-list-container {
    display: flex;
    flex-direction: column;
    gap: 10px;
    max-height: 400px; /* Hieman korkeampi tila useammalle kohteelle */
    overflow-y: auto;
    overflow-x: hidden; /* Estää sivuttaisen scrollbarin */
    padding: 10px;      /* Tilaa transform-animaatiolle ja varjoille */
    margin: 0 -10px;    /* Kompensoidaan padding jotta lista pysyy linjassa */
}

.tour-item {
    background: rgba(255, 255, 255, 0.1);
    border: 1px solid rgba(255, 255, 255, 0.1);
    padding: 15px;
    border-radius: 10px;
    text-align: left;
    cursor: pointer;
    transition: all 0.2s ease-in-out; /* Lisätty ease-in-out pehmeyttä */
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;        /* Varmistetaan että vie tilan oikein */
    box-sizing: border-box; /* Sisällytetään padding ja border leveyteen */
}

/* Hover-efekti nyt turvallisempi */
.tour-item:hover {
    background: rgba(255, 255, 255, 0.2);
    transform: translateX(5px);
    border-color: var(--accent-green);
    box-shadow: 0 4px 15px rgba(0, 0, 0, 0.3);
}

.tour-name { font-weight: 700; font-size: 1.1rem; color: #fff; }
.tour-status { font-size: 0.8rem; padding: 2px 8px; border-radius: 4px; font-weight: bold; }
.status-ongoing { background: var(--accent-blue); color: #000; }
.status-finished { background: #555; color: #aaa; }
.status-pending { background: var(--accent-gold); color: #000; }
.status-cancelled { background: #330000; color: #ff3333; border: 1px solid #ff3333; }


/* --- TOURNAMENT BRACKET (Korjattu Pyramid View) --- */

.main-scroll-area {
    width: 100%;
    flex: 1;
    overflow: auto;
    display: flex; 
    flex-direction: column;
    align-items: center;
    
    /* Tämä takaa, että footerin jälkeen on vielä tyhjää tilaa scrollata */
    padding: 20px 40px 60px 40px; 
    
    box-sizing: border-box;
    -webkit-overflow-scrolling: touch;
}

/* Päivitetty bracket-layout: ei pakota kiinteää korkeutta, vaan venyy sisällön mukaan */
/* --- style.css --- */

.bracket-layout {
    display: flex;
    flex-direction: row;
    gap: 60px;
    min-width: min-content;
    
    /* TÄRKEIN KORJAUS: */
    flex-shrink: 0;   /* Estää säiliötä kutistumasta, jolloin footer ei pääse liukumaan sen päälle */
    
    height: max-content;
    min-height: 0;
    padding-bottom: 0; 
    margin-bottom: 0;
}

/* Varmistetaan että sarakkeet pysyvät linjassa */
.round-column {
    display: flex;
    flex-direction: column;
    justify-content: flex-start;
    min-width: 260px;
    position: relative;
    /* Gap ja padding-top tulevat nyt JS:stä */
}

/* Otsikko nostetaan "ulos" virtauksesta, jotta se ei työnnä pelejä alaspäin */
.round-header {
    text-align: center;
    font-size: 1rem;
    font-weight: 900;
    color: var(--accent-green);
    position: absolute; /* TÄRKEÄ: Ei vaikuta pelien sijaintiin */
    top: -40px;
    width: 100%;
    text-transform: uppercase;
    letter-spacing: 2px;
}

.match-card {
    /* Pakotetaan korkeus ja box-model */
    height: 90px;
    box-sizing: border-box; /* TÄRKEÄ: Border sisältyy 90px korkeuteen */
    
    background: rgba(0, 0, 0, 0.6);
    border: 1px solid rgba(255, 255, 255, 0.15);
    border-radius: 12px;
    padding: 0 12px; /* Poistetaan pystypadding, käytetään flexiä */
    position: relative;
    backdrop-filter: blur(5px);
    box-shadow: 0 4px 15px rgba(0,0,0,0.3);
    
    display: flex;
    flex-direction: column;
    justify-content: center;
    z-index: 2;
}

/* --- VIIVAT (CONNECTORS) --- */

/* Ylempi ottelu: Viiva lähtee kortin keskeltä ALAS */
.bracket-node-top::before {
    content: '';
    position: absolute;
    right: -30px; /* Puolet välistä */
    top: 50%;
    width: 2px;
    height: var(--connector-height, 50px); /* JS laskee tämän */
    background: rgba(255, 255, 255, 0.3);
    z-index: 1;
}

/* Alempi ottelu: Viiva lähtee kortin keskeltä YLÖS */
.bracket-node-bottom::before {
    content: '';
    position: absolute;
    right: -30px;
    bottom: 50%;
    width: 2px;
    height: var(--connector-height, 50px); /* JS laskee tämän */
    background: rgba(255, 255, 255, 0.3);
    z-index: 1;
}

/* Vaakaviivat korttien välissä */
.match-card::after {
    content: '';
    position: absolute;
    right: -30px;
    top: 50%;
    width: 30px;
    height: 2px;
    background: rgba(255, 255, 255, 0.3);
}

.match-players::before {
    content: '';
    position: absolute;
    left: -30px;
    top: 50%;
    width: 30px;
    height: 2px;
    background: rgba(255, 255, 255, 0.3);
}

/* Piilotetaan turhat viivat */
.round-column:first-child .match-players::before { display: none; }
.round-column:last-child .match-card::after { display: none; }
.round-column:last-child .bracket-node-top::before { display: none; }
.round-column:last-child .bracket-node-bottom::before { display: none; }

/* Ensimmäisellä kierroksella ei sisääntuloviivaa */
.round-column:first-child .match-players::before {
    display: none;
}

/* Finaalissa/viimeisellä kierroksella ei lähtöviivoja */
.round-column:last-child .match-card::after,
.round-column:last-child .bracket-node-top::before,
.round-column:last-child .bracket-node-bottom::before {
    display: none;
}

/* Pelaajien tyylit ja avatarit */
.m-player {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 4px 8px;
    margin: 2px 0;
    border-radius: 6px;
    background: rgba(255,255,255,0.03);
}

.m-player.winner { 
    background: linear-gradient(90deg, rgba(0, 255, 65, 0.15), transparent);
    border-left: 3px solid var(--accent-blue);
}

.m-player.loser { opacity: 0.4; }

.bracket-avatar {
    width: 26px;
    height: 26px;
    border-radius: 50%;
    object-fit: cover;
    background: #222;
    border: 1px solid rgba(255,255,255,0.2);
}

.mp-name {
    font-weight: 600;
    font-size: 0.9rem;
    margin-left: 8px;
}

.mp-score {
    font-family: var(--font-num);
    font-weight: 900;
    color: var(--accent-gold);
}

.live-badge {
    position: absolute;
    top: -10px;
    right: 10px;
    background: #ff0000;
    color: white;
    font-size: 0.6rem;
    padding: 2px 8px;
    border-radius: 4px;
    font-weight: bold;
    box-shadow: 0 0 10px rgba(255,0,0,0.5);
}

/* --- FEATURED LIVE MATCH (Bracketin yläpuolella) --- */

#featured-match-container {
    width: 100%;
    max-width: 100%; 
    animation: fadeIn 0.5s ease-out;
}

/* --- WIDE FEATURED MATCH DESIGN --- */

.featured-card {
    position: relative;
    width: 100%;
    /* Max-width 1200px (tai 100% jos näyttö on pienempi) */
    max-width: 1200px; 
    min-height: 350px; 
    /* Musta tausta pohjalle */
    background-color: #000; 
    border-radius: 20px;
    overflow: hidden;
    margin: 0 auto 20px auto;
    border: 1px solid #333;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
    display: flex;
    flex-direction: column;
    justify-content: center;
}

/* Taustakuvat (Pelaajat) */
.player-bg-layer {
    position: absolute;
    top: 0;
    bottom: 0;
    width: 50%; 
    /* MUUTOS: auto 100% pakottaa kuvan koko korkeuden näkyviin */
    background-size: auto 100%;
    background-repeat: no-repeat;
    z-index: 0;
    opacity: 0.8; 
}

/* Vasen pelaaja (P1) */
.player-bg-left {
    left: 0;
    /* MUUTOS: Kuva alkaa vasemmasta reunasta */
    background-position: left center;
    
    /* Fade: Kuva näkyy vasemmalla, mutta alkaa himmetä kohti keskustaa */
    mask-image: linear-gradient(to right, black 50%, transparent 100%);
    -webkit-mask-image: linear-gradient(to right, black 50%, transparent 100%);
}

/* Oikea pelaaja (P2) */
.player-bg-right {
    right: 0;
    /* MUUTOS: Kuva alkaa oikeasta reunasta */
    background-position: right center;
    
    /* Fade: Kuva näkyy oikealla, mutta alkaa himmetä kohti keskustaa */
    mask-image: linear-gradient(to left, black 50%, transparent 100%);
    -webkit-mask-image: linear-gradient(to left, black 50%, transparent 100%);
}


.featured-header {
    display: flex;
    justify-content: center;
    margin-bottom: 15px;
    position: relative;
    z-index: 10;
}
.live-indicator {
    background: #ff0000;
    color: #fff;
    font-size: 0.8rem;
    font-weight: 900;
    padding: 4px 12px;
    border-radius: 4px;
    letter-spacing: 2px;
    box-shadow: 0 0 15px rgba(255, 0, 0, 0.6);
    animation: pulse-red 1.5s infinite;
}

.featured-content {
    position: relative;
    z-index: 5;
    width: 30%;
    min-width: 320px;
    background-color: #000000e8;
    margin: 0 auto;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 20px;
    text-shadow: 0 2px 10px rgba(0, 0, 0, 0.9);
    height: 100%;
    box-shadow: 0 0 50px 20px #000;
}

.f-player {
    flex: 1;
    display: flex;
    flex-direction: column;
    align-items: center;
    text-align: center;
}

.f-player.active-turn {
    transform: scale(1.05);
}

.f-avatar {
    display: none; 
}


.f-name {
    font-size: 1.8em;
    font-weight: 800;
    text-transform: uppercase;
    margin-bottom: 5px;
    color: #fff;
    letter-spacing: 1px;
}

.active-turn .f-name {
    color: #4CAF50;
    text-shadow: 0 0 15px rgba(76, 175, 80, 0.6);
}

/* Iso 501-luku */
.f-score {
    font-family: var(--font-num);
    font-size: 3.5em; /* Hieman pienennetty jotta mahtuu 30% alueelle */
    font-weight: 900;
    line-height: 1;
    color: #fff;
}

.f-legs {
    font-size: 0.9rem;
    color: var(--accent-gold);
    margin-top: 5px;
    font-weight: bold;
}

.vs-divider {
    font-size: 1.5rem;
    font-weight: 900;
    color: rgba(255,255,255,0.3);
    margin: 0 10px;
}

.last-throw-info {
    position: relative;
    z-index: 10;
    text-align: center;
    margin-top: 0;
    padding: 10px;
    font-size: 0.9rem;
    color: #aaa;
    background: transparent; /* Tausta on jo musta contentin ansiosta */
    width: 30%; /* Sama leveys kuin contentilla */
    margin: 0 auto;
}

@keyframes fadeIn { from { opacity: 0; transform: translateY(-10px); } to { opacity: 1; transform: translateY(0); } }

/* --- GHOST BRACKET STYLES --- */

/* Haamuottelu (tuleva peli) */
.match-card.ghost {
    opacity: 0.3; /* Himmeä */
    border-style: dashed;
    background: rgba(255, 255, 255, 0.02);
    pointer-events: none; /* Ei voi klikata */
}

/* Haamupelaajan nimi */
.match-card.ghost .mp-name {
    color: #666;
    font-style: italic;
}

/* --- HEITTOTIEDOT (Featured Match) --- */

.throw-row {
    display: flex;
    justify-content: center;
    gap: 8px;
    margin-top: 8px;
    height: 24px; /* Kiinteä korkeus jotta ei hypi */
}

.dart-badge {
    background: rgba(255,255,255,0.1);
    border: 1px solid rgba(255,255,255,0.2);
    border-radius: 4px;
    padding: 2px 6px;
    font-size: 0.8rem;
    font-family: var(--font-num);
    color: #aaa;
    font-weight: bold;
    min-width: 25px;
    text-align: center;
}

/* Korostetaan viimeisin heitto kirkkaammaksi */
.f-player.active-turn .dart-badge {
    color: #fff;
    border-color: var(--accent-green);
    background: rgba(0, 204, 255, 0.1);
}
/* --- TABS --- */
.tabs-container {
    display: flex;
    gap: 20px;
    margin-bottom: 60px;
    background: rgba(0,0,0,0.3);
    padding: 5px;
    border-radius: 50px;
    border: 1px solid rgba(255,255,255,0.1);
}

.tab-btn {
    background: transparent;
    border: none;
    color: #aaa;
    padding: 10px 25px;
    font-family: var(--font-main);
    font-weight: 700;
    font-size: 0.9rem;
    cursor: pointer;
    border-radius: 40px;
    transition: all 0.3s;
}

.tab-btn.active {
    background: var(--accent-green); /* Sininen/Vihreä riippuen teemasta */
    color: #000;
    box-shadow: 0 0 15px rgba(0, 204, 255, 0.4);
}

.tab-btn:hover:not(.active) {
    color: #fff;
    background: rgba(255,255,255,0.05);
}

/* --- GROUP STAGE TABLES --- */
.group-layout {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    gap: 30px;
    width: 100%;
    max-width: 1000px;
    animation: fadeIn 0.5s;
}

.group-card {
    background: rgba(255, 255, 255, 0.05);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 12px;
    padding: 15px;
    min-width: 300px;
    flex: 1;
    backdrop-filter: blur(5px);
}

.group-header {
    text-align: center;
    font-weight: 900;
    color: var(--accent-gold);
    margin-bottom: 15px;
    font-size: 1.2rem;
    text-transform: uppercase;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 10px;
}

.standings-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.9rem;
}

.standings-table th {
    text-align: left;
    color: #888;
    padding: 5px;
    font-size: 0.75rem;
    text-transform: uppercase;
}

.standings-table td {
    padding: 8px 5px;
    border-bottom: 1px solid rgba(255,255,255,0.05);
}

.st-player {
    display: flex;
    align-items: center;
    gap: 8px;
    font-weight: 600;
}

.st-avatar {
    width: 20px;
    height: 20px;
    border-radius: 50%;
    background: #333;
}

.val-center { text-align: center; }
.val-points { text-align: right; font-weight: 900; color: var(--accent-green); }

/* Piilotetaan elementit animaatiolla tai ilman */
.hidden { display: none !important; }

/* Voittajan korostus */
.winner-badge-overlay {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%) rotate(-10deg);
    background: #FFD700;
    color: #000;
    font-weight: bold;
    padding: 5px 15px;
    border: 3px solid #fff;
    border-radius: 8px;
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);
    z-index: 10;
    font-size: 1.2em;
    animation: popIn 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

.match-loser-dim {
    opacity: 0.5;
    filter: grayscale(0.8);
}

.live-indicator.finished {
    background-color: #555; /* Harmaa tausta live-punaisen sijaan */
}

@keyframes popIn {
    0% { transform: translate(-50%, -50%) scale(0) rotate(0deg); }
    100% { transform: translate(-50%, -50%) scale(1) rotate(-10deg); }
}

/* Overlay joka peittää koko ottelukortin pelin päätyttyä */
.match-result-overlay {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.85); /* Tumma läpinäkyvä tausta */
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    z-index: 100; /* Varmasti kaiken päällä */
    animation: fadeIn 0.5s ease-out;
}

.winner-text {
    font-size: 2em;
    font-weight: bold;
    color: #FFD700; /* Kulta */
    text-transform: uppercase;
    text-align: center;
    margin-bottom: 10px;
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.5);
}

.score-text {
    font-size: 3em;
    font-weight: bold;
    color: white;
}

/* Animaatio overlaylle */
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* Otsikon tyylittely */
#tour-title {
    font-family: 'Arial Black', sans-serif; /* Tai mikä fontti sinulla onkaan */
}

.player-lightbox-overlay {
    position: fixed; /* TÄRKEÄ: Kiinnittää ruutuun, ei sivuun */
    top: 0;
    left: 0;
    width: 100vw; /* Koko näkymän leveys */
    height: 100vh; /* Koko näkymän korkeus */
    background: rgba(0, 0, 0, 0.9);
    display: flex;
    justify-content: center; /* Keskittää sivusuunnassa */
    align-items: center;     /* Keskittää pystysuunnassa */
    z-index: 10000;          /* Varmasti kaiken päällä */
    backdrop-filter: blur(8px);
    animation: fadeIn 0.3s ease-out;
}
.profile-location {
    font-size: 1rem;
    color: #888;
    margin-bottom: 10px; /* Väli ennen pisteitä */
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 1px;
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 6px;
        margin-bottom: 10px;
}
.player-profile-card {
    background: linear-gradient(145deg, #1a1a1a, #252525);
    width: 90%;
    max-width: 500px;
    max-height: 90vh; /* Estää korttia menemästä ruudun yli pystysuunnassa */
    overflow-y: auto; /* Lisää scrollbarin kortin sisälle jos sisältö ei mahdu */
    padding: 40px;
    border-radius: 30px;
    text-align: center;
    border: 1px solid #333;
    box-shadow: 0 20px 50px rgba(0,0,0,0.6);
    position: relative;
    color: white;
    
    /* Pidetään se "hieno vinous" alussa, mutta suoristetaan lopuksi tai jätetään vinoksi */
    /* Jos haluat sen jäävän hieman vinoon, muuta 100% rotate arvoa */
    animation: popInModal 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* TÄSSÄ ON MUUTOS: Paljon isompi kuva */
.big-profile-img {
    width: 250px;  /* Kasvatettu (oli 150px) */
    height: 250px; /* Kasvatettu (oli 150px) */
    border-radius: 50%;
    object-fit: cover;
    border: 6px solid #4CAF50; /* Paksumpi reunus sopii isompaan kuvaan */
    margin-bottom: 25px;
    box-shadow: 0 0 30px rgba(76, 175, 80, 0.4);
    background-color: #333; /* Taustaväri jos kuva latautuu hitaasti */
}

.profile-name {
    font-size: 2.2em; /* Isompi fontti */
    font-weight: 800;
    margin-bottom: 10px;
    letter-spacing: -0.5px;
}

.profile-rank {
    color: #FFD700;
    font-size: 1.3em;
    font-weight: bold;
    margin-bottom: 25px;
    display: inline-block;
    background: rgba(255, 215, 0, 0.15);
    padding: 8px 20px;
    border-radius: 20px;
}

.profile-desc {
    color: #ccc;
    font-size: 1.1em;
    line-height: 1.6;
    font-style: italic;
    max-width: 80%;
    margin: 0 auto;
}

.profile-close-btn {
    position: absolute;
    top: 20px;
    right: 25px;
    font-size: 32px;
    cursor: pointer;
    color: #666;
    line-height: 1;
}

/* Lisää tämä, jos ei jo ole */
#btn-share-match:hover {
    background: rgba(0, 204, 255, 0.4) !important;
    transform: scale(1.05);
    box-shadow: 0 0 15px rgba(0, 204, 255, 0.4);
}

/* Toast-ilmoituksen animaatio */
#toast-msg {
    transition: opacity 0.5s ease-in-out;
}
#toast-msg.hidden {
    opacity: 0;
    pointer-events: none;
    display: block !important; /* Ylikirjoitetaan display:none jotta opacity toimii */
}

/* Uusi animaatio joka toimii fixed-positionin kanssa */
@keyframes popInModal {
    0% { 
        opacity: 0; 
        transform: scale(0.7) rotate(-5deg); 
    }
    100% { 
        opacity: 1; 
        transform: scale(1) rotate(0deg); /* Voit vaihtaa 0deg -> -2deg jos haluat sen jäävän vinoon */
    }
}
/* --- style.css --- */

/* --- style.css --- */

.site-footer {
    flex-shrink: 0;
    
    /* Varmistetaan tila yläpuolelle */
    margin-top: 50px; 
    
    /* Varmistetaan että teksti on keskitetty ja näkyvä */
    position: relative; 
    z-index: 5; 
    
    color: rgba(255, 255, 255, 0.2);
    font-size: 0.8rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 2px;
    text-align: center;
    width: 100%;
    font-family: var(--font-main);
    pointer-events: none;
}

/* --- style.css --- */

/* 1. Jos kuvallinen tila on päällä, ylikirjoitetaan oletusgradientti mustalla */
.split-pane.has-photo {
    background: #000 !important; 
}

/* 2. Asetetaan kuva taustalle */
.split-pane-bg {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background-size: cover;
    background-position: center;
    background-repeat: no-repeat;
    z-index: 0;
    opacity: 0.6; /* Kuvan kirkkaus */
}

/* 3. Lisätään värikerros (Tint) kuvan PÄÄLLE pseudo-elementillä */
.split-pane.has-photo .split-pane-bg::after {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1;
}

/* Pelaaja 1 (Vihreä sävy kuvan päällä) */
.split-pane.has-photo.p1 .split-pane-bg::after {
    background: linear-gradient(to bottom, rgba(0, 50, 0, 0.6), rgba(0, 20, 0, 0.9));
    mix-blend-mode: hard-light; /* Sekoittaa värin tyylikkäästi kuvaan */
}

/* Pelaaja 2 (Punainen sävy kuvan päällä) */
.split-pane.has-photo.p2 .split-pane-bg::after {
    background: linear-gradient(to bottom, rgba(80, 0, 0, 0.6), rgba(30, 0, 0, 0.9));
    mix-blend-mode: hard-light;
}

/* Aktiivinen vuoro kirkastaa kuvaa */
.split-pane.active-turn .split-pane-bg {
    opacity: 1;
    transform: scale(1.02);
    transition: all 0.5s ease;
}

/* Piilotetaan kirjaintausta jos kuva on */
.split-pane.has-photo .big-bg-char {
    display: none !important;
}

/* Varmistetaan että teksti on kaiken päällä */
.hud-content {
    position: relative;
    z-index: 10;
}

/* style.css - Lisää nämä Heads-Up osion kohdalle */

.hud-top-stats {
    display: flex;
    justify-content: center;
    gap: 40px;          /* Väli tilastojen välillä */
    margin-bottom: 10px;
    background: rgba(0, 0, 0, 0.3);
    padding: 10px 40px;
    border-radius: 50px;
    backdrop-filter: blur(5px);
    border: 1px solid rgba(255, 255, 255, 0.1);
}

.top-stat {
    font-family: var(--font-num);
    font-size: 2.5rem;  /* Suuri fontti */
    font-weight: 900;
    color: var(--accent-gold);
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Säädetään nimen marginaalia pienemmäksi */
.hud-name {
    margin-bottom: 10px !important;
}

/* Pienennetään hieman scorea, jotta kaikki mahtuu pystysuunnassa paremmin */
.hud-score {
    font-size: 30rem !important; 
}

/* --- ANIMATED VERTICAL CHECKOUTS --- */

.checkout-stack {
    display: flex;
    flex-direction: row; /* Vierekkäin */
    justify-content: center;
    flex-wrap: wrap; /* Rivittyy jos ei mahdu */
    gap: 15px;
    margin-top: 10px;
    width: 100%;
    min-height: 60px; /* Varaa tilaa ettei hypi */
}

/* Yksittäinen checkout-rivi */
.checkout-row {
    font-family: var(--font-num);
    font-weight: 900;
    font-size: 2.7rem; /* Pienennetty hieman jotta mahtuu vierekkäin */
    color: #fff;
    background: rgba(0, 0, 0, 0.6);
    padding: 8px 20px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.2);
    box-shadow: 0 4px 10px rgba(0,0,0,0.3);
    
    /* Animaatio */
    opacity: 0;
    transform: translateY(20px); /* Tulee alhaalta ylös */
    animation: popUpCheckout 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275) forwards;
}

/* Paras vaihtoehto korostetaan hieman enemmän */
.checkout-row:first-child {
    color: var(--accent-gold);
    border-color: var(--accent-gold);
    background: rgba(255, 215, 0, 0.15);
    transform: scale(1.05); /* Hieman isompi */
}

/* Vaihtoehdot himmeämmällä */
.checkout-row:not(:first-child) {

    color: #ccc;
    border-color: rgba(255, 255, 255, 0.1);
}

/* Animaatio (liukuu sivulta esiin) */
@keyframes slideInCheckout {
    0% {
        opacity: 0;
        transform: translateX(-100px); /* Tulee vasemmalta */
    }
    100% {
        opacity: 1;
        transform: translateX(0);
    }
}
@keyframes popUpCheckout {
    to { opacity: 1; transform: translateY(0) scale(1); }
}

/* Viivästytetään animaatioita jotta ne tulevat yksi kerrallaan */
/* Viiveet animaatioon */
.checkout-row:nth-child(1) { animation-delay: 0.05s; }
.checkout-row:nth-child(2) { animation-delay: 0.15s; }
.checkout-row:nth-child(3) { animation-delay: 0.25s; }

/* Piilotetaan last-throws aktiiviselta pelaajalta */
.hidden-turn-info {
    visibility: hidden;
    opacity: 0;
    height: 0;
    margin: 0 !important;
    transition: all 0.3s;
}

/* --- EXTENDED GAME STATS (Alareuna) --- */

.extended-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr); /* 3 saraketta */
    gap: 10px;
    width: 90%;
    margin-top: 20px;
    padding-top: 20px;
    border-top: 1px solid rgba(255,255,255,0.1);
}

.ext-stat-box {
    display: flex;
    flex-direction: column;
    align-items: center;
    background: rgba(255, 255, 255, 0.03);
    padding: 8px;
    border-radius: 8px;
}

.ext-label {
    font-size: 1.7rem;
    color: #888;
    font-weight: 700;
    margin-bottom: 2px;
}

.ext-value {
    font-family: var(--font-num);
    font-size: 3.2rem;
    font-weight: 900;
    color: #ddd;
}

/* Korostetaan 180 luku */
.ext-value.val-180 { color: var(--accent-gold); }

/* --- TURN HISTORY (Previous Visits) --- */

.turn-history-container {
    display: flex;
    justify-content: center;
    align-items: center;
    gap: 8px;
    margin-top: 15px;
    width: 100%;
    height: 40px;
    overflow: hidden; /* Varmistetaan ettei vuoda yli */
}

.history-pill {
    font-family: var(--font-num);
    font-size: 1rem;
    font-weight: 700;
    color: #888;
    background: rgba(255, 255, 255, 0.05);
    padding: 5px 10px;
    border-radius: 6px;
    border: 1px solid rgba(255, 255, 255, 0.05);
    min-width: 30px;
    text-align: center;
    
    /* Animaatio kun uusi ilmestyy */
    animation: fadeInPill 0.5s ease;
}

/* Uusin heitto korostetaan hieman */
.history-pill:last-child {
    color: #fff;
    background: rgba(255, 255, 255, 0.15);
    border-color: rgba(255, 255, 255, 0.2);
    font-weight: 900;
}

/* Jos tulos on kova (100+), korostetaan värillä */
.history-pill.high-score {
    color: var(--accent-gold);
    border-color: rgba(255, 215, 0, 0.2);
}

@keyframes fadeInPill {
    from { opacity: 0; transform: translateX(10px); }
    to { opacity: 1; transform: translateX(0); }
}
/* --- TURN HISTORY: SUUREMPI JA LEVEÄMPI --- */

.turn-history-container {
    display: flex;
    justify-content: space-between; /* Levittää laatikot reunoille asti */
    align-items: flex-end;
    gap: 8px; /* Väli laatikoiden välillä */
    margin-top: 25px; /* Lisää tilaa yläpuolen statseihin */
    width: 90%; /* Sama leveys kuin extended-stats-gridillä */
    height: auto;
    overflow: hidden;
        padding: 9px;
}

.history-item-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1; /* TÄRKEÄ: Pakottaa jokaisen pilarin olemaan samanlevuinen */
    animation: fadeInPill 0.5s ease;
    min-width: 0; /* Estää flex-lapsia venymästä yli rajojen */
}

.history-turn-label {
    font-size: 0.8rem; /* Suurempi numero */
    color: #aaa;
    margin-bottom: 6px;
    font-weight: 900;
    font-family: var(--font-num);
}

.history-pill {
    width: 100%; /* Täyttää wrapperin leveyden */
    font-family: var(--font-num);
    font-size: 1.4rem; /* Huomattavasti suurempi teksti */
    font-weight: 900;
    color: #eee;
    background: rgba(255, 255, 255, 0.07);
    padding: 12px 0; /* Enemmän pystysuuntaista tilaa */
    border-radius: 10px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    text-align: center;
    box-shadow: 0 4px 15px rgba(0,0,0,0.2);
}

/* Aktiivisen/uusimman korostus */
.history-item-wrapper:last-child .history-pill {
    background: rgba(255, 255, 255, 0.4);
    border-color: rgba(255, 255, 255, 0.4);
    color: #fff;
}

.history-item-wrapper:last-child .history-turn-label {
    color: var(--accent-gold);
}

/* High score (100+) loistaa kirkkaammin */
.history-pill.high-score {
    background: rgba(255, 215, 0, 0.1);
    color: var(--accent-gold);
    border-color: rgba(255, 215, 0, 0.3);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.4);
}
/* --- VISIT COUNTER PÄIVITYS --- */
.visit-badge {
    margin-top: 15px;
    font-size: 0.9rem; /* Hieman isompi */
    color: #fff;
    font-weight: 900;
    text-transform: uppercase;
    letter-spacing: 2px;
    background: rgba(0, 255, 65, 0.2); /* Vihertävä pohja korostaa aktiivisuutta */
    padding: 8px 25px;
    border-radius: 20px;
    border: 1px solid var(--accent-blue);
    display: inline-block;
}

/* Lisätään syke aktiiviselle vuorolle */
.active-turn .visit-badge {
    animation: visitPulse 2s infinite;
    background: rgba(0, 255, 65, 0.3);
}

@keyframes visitPulse {
    0% { box-shadow: 0 0 0 0 rgba(0, 255, 65, 0.4); }
    70% { box-shadow: 0 0 0 10px rgba(0, 255, 65, 0); }
    100% { box-shadow: 0 0 0 0 rgba(0, 255, 65, 0); }
}

/* --- NEWS TICKER (Urheilulähetys-tyyli) --- */

.ticker-wrap {
    position: fixed;
    bottom: 0;
    width: 100%;
    overflow: hidden;
    height: 40px;
background: linear-gradient(90deg, #000 0%, #1a1a1a 50%, #000 100%);
    border-top: 2px solid var(--accent-gold);
    box-shadow: 0 -5px 20px rgba(0,0,0,0.5);
    z-index: 1000;
    display: flex;
    align-items: center;
}

.ticker-move {
    display: inline-block;
    white-space: nowrap;
    padding-right: 100%;
    animation: tickerLoop 30s linear infinite;
    font-family: var(--font-main);
    font-weight: 700;
    text-transform: uppercase;
    font-size: 0.9rem;
    color: #fff;
}

.ticker-item {
font-variant-numeric: tabular-nums; /* Pitää numerot tasavälisinä */
    border-right: 2px solid rgba(255,255,255,0.1);
    padding: 0 40px;
}

.ticker-highlight {
color: var(--accent-gold);
    text-shadow: 0 0 10px rgba(255, 215, 0, 0.3);
}

@keyframes tickerLoop {
    0% { transform: translateX(100%); }
    100% { transform: translateX(-100%); }
}

@media screen and (orientation: portrait) {
    
    /* --- 0. NÄKYVYYSLOGIIKKA (LISÄTTY) --- */
    /* Tämä varmistaa, että piilotettu vaihe katoaa kokonaan ja toinen saa tilan */
    #group-stage-container.hidden,
    #bracket-container.hidden {
        display: none !important;
    }

    /* Varmistetaan että Bracket-kontti täyttää tilan kun se on aktiivinen */
    #bracket-container:not(.hidden) {
        display: flex !important;
        flex-direction: column;
        flex: 1;
        height: auto;
        min-height: 0;
        width: 100%;
        justify-content: flex-start;
        overflow: hidden;
    }

    /* --- 1. YLEISET ASETUKSET --- */
    body { height: 100vh; overflow: hidden; }
    .main-scroll-area { padding: 5px; display: flex; flex-direction: column; height: 100%; overflow: hidden; margin: 0; }
    .site-footer, #btn-share-tournament, #btn-back-profile, #btn-share-match { display: none !important; }
    .header-bar { padding: 5px 0; flex-shrink: 0; }
    #tour-title { font-size: 1.1rem !important; margin: 0; line-height: 1.2; }
    #tour-title div:nth-child(2) { display: none; }
    .tabs-container { height: 35px; margin: 5px auto; }

    /* --- 2. LIVE MATCH (n. 32% korkeudesta) --- */
    #featured-match-container {
        flex: 0 0 auto; /* Ei veny turhaan */
        width: 100%;
    }
    .featured-card { height: 100%; border-radius: 12px; }
    .featured-content { padding: 5px; width: 55%; height: 50%; }
    .f-score { font-size: 3rem; }
    .f-name { font-size: 0.9rem; }
    .f-legs { font-size: 0.7rem; }
    .throw-row { height: 18px; margin-top: 2px; }
    .dart-badge { font-size: 0.7rem; padding: 1px 4px; min-width: 18px; }

    /* --- 3. RYHMÄT (Loput tilasta) --- */
    /* Muutettu valitsin: #group-stage-container -> #group-stage-container:not(.hidden) */
    #group-stage-container:not(.hidden) {
        display: flex !important;
        flex-direction: column !important; /* Tämä on avain: elementit allekkain */
        flex-wrap: nowrap !important;
        align-items: stretch; /* Venytetään kortit reunoihin asti */
        
        /* Varmistetaan että pystyscrollaus toimii, jos ryhmiä on paljon */
        overflow-y: auto !important; 
        overflow-x: hidden;
        
        /* Nollataan mahdolliset korkeusrajoitukset jotta scrollaus toimii */
        height: auto;
        flex: 1;
    }

    /* KORTIN ASETTELU: Koko leveys, ei sivuttaisscrollia */
    .group-card {
        /* Täysi leveys */
        max-width: none !important;  /* Poistetaan rajoitukset */
        margin: 0 0 15px 0 !important; /* Väliä alapuolelle */
        
        /* Estetään korttia jakamasta tilaa muiden kanssa */
        flex: 0 0 auto !important;
    }

    .group-header {
        font-size: 1rem !important; /* Maltillinen otsikko */
        margin-bottom: 5px;
        padding-bottom: 2px;
        text-align: center;
    }
    
    /* 4. TAULUKKO: Tiivis paketti */
    .standings-table {
        width: 100%;
        font-size: 0.75rem !important; /* Pieni fontti jotta mahtuu */
        table-layout: auto; /* Antaa selaimen sovitella sarakkeet */
    }

    .standings-table th, .standings-table td {
        padding: 2px 1px !important; /* Erittäin pienet välit */
        text-align: center; /* Keskitetään numerot */
        white-space: nowrap; /* Estää numeroiden rivittymisen */
    }

    /* Pelaajan nimi vasemmalle */
    .standings-table td:first-child, 
    .standings-table th:first-child {
        text-align: left;
        padding-left: 5px !important;
        max-width: 100px; /* Rajoitetaan nimen tilaa tarvittaessa */
        overflow: hidden;
        text-overflow: ellipsis; /* Katkaisee pitkän nimen "..." */
    }

    /* Avatar pieneksi */
    .st-avatar {
        width: 20px !important;
        height: 20px !important;
        border: none;
    }
    
    .st-player {
        gap: 6px;
        font-weight: 600;
        display: flex;
        align-items: center;
    }

    /* Sarakkeiden hienosäätö */
    .standings-table th {
        font-size: 0.65rem !important; /* Otsikot vielä pienemmällä */
        color: #aaa;
    }

    /* Varmistetaan että kaikki sarakkeet näkyvät */
    .standings-table th, .standings-table td { display: table-cell !important; }

    /* Pisteet korostettuna, mutta pienenä */
    .val-points {
        font-size: 0.8rem !important;
        color: var(--accent-green);
        font-weight: bold;
    }
    
    /* --- BRACKET OPTIMOINTI --- */

    /* 1. Pakotetaan vaakarivi (Row) eikä pystyrivi (Column) */
    .bracket-layout {
        display: flex !important;
        flex-direction: row !important; /* Vierekkäin */
        justify-content: space-between;
        align-items: stretch; /* Venytetään korkeussuunnassa */
        width: 100%;
        gap: 2px !important; /* Minimaalinen väli sarakkeiden väliin */
        overflow-x: hidden; /* Estetään sivuttaisscrollaus, pakotetaan mahtumaan */
        padding: 5px 0;
    }

    /* 2. Sarakkeet jakavat tilan tasan (esim. 3 kierrosta = 33% kukin) */
    .round-column {
        flex: 1;           /* Jokainen sarake ottaa yhtä paljon tilaa */
        min-width: 0;      /* Sallii kutistumisen alle sisällön leveyden */
        display: flex;
        flex-direction: column;
        justify-content: center; /* Keskitetään pelit pystysuunnassa */
        position: relative;
        /* Ylikirjoitetaan JS-laskut marginaaleista, jotta mahtuu */
        margin: 0 !important; 
        padding-top: 20px !important; /* Tilaa otsikolle */
    }
    
    /* Javascriptin laskemat gapit pitää nollata tai pienentää mobiilissa */
    .round-column {
        gap: 0 !important; /* Nollataan JS-gap, hoidetaan flexillä */
        justify-content: space-around; /* Jakaa pelit tasaisesti pystysuunnassa */
    }

    /* 3. Otsikko (ROUND 1, SEMI...) */
    .round-header {
        font-size: 0.6rem !important;
        top: 0;
        margin-bottom: 5px;
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis;
    }

    /* 4. Ottelukortti (Match Card) */
    .match-card {
        width: 100%;       /* Täyttää sarakkeen leveyden */
        height: auto !important; /* Joustava korkeus */
        min-height: 40px;  /* Minimikorkeus */
        padding: 2px !important;
        border-radius: 4px;
        background: rgba(0,0,0,0.6);
        border: 1px solid rgba(255,255,255,0.1);
        margin: 2px 0;    /* Pieni väli korttien väliin */
    }

    /* 5. Pelaajarivi */
    .m-player {
        padding: 1px 2px;
        margin: 1px 0;
        border-radius: 2px;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
    
    .player-info {
        display: flex;
        align-items: center;
        min-width: 0; /* Tärkeä tekstin lyhennykselle */
        flex: 1;
    }

    /* 6. Avatar "mikrokoko" */
    .bracket-avatar {
        width: 12px !important;
        height: 12px !important;
        margin-right: 3px;
        flex-shrink: 0;
    }

    /* 7. Nimi ja Pisteet */
    .mp-name {
        font-size: 0.55rem !important; /* Hyvin pieni fontti */
        white-space: nowrap;
        overflow: hidden;
        text-overflow: ellipsis; /* Lyhentää nimet "M. Sm..." */
        line-height: 1;
    }

    .mp-score {
        font-size: 0.6rem !important;
        margin-left: 2px;
    }

    /* 8. Yhdysviivat (Connectors) - Ohennetaan ja tuodaan takaisin */
    .bracket-node-top::before, 
    .bracket-node-bottom::before, 
    .match-card::after, 
    .match-players::before {
        display: block !important; /* Tuodaan takaisin */
        width: 1px !important;     /* Ohuet viivat */
        background: rgba(255,255,255,0.2);
    }
    
    /* Korjataan viivojen sijainnit ahtaassa tilassa */
    .match-card::after { 
        right: -2px; width: 4px; /* Lyhyt viiva kortista ulos */
    }
    .match-players::before {
        left: -2px; width: 4px;  /* Lyhyt viiva korttiin sisään */
    }
    .bracket-node-top::before { right: -2px; }
    .bracket-node-bottom::before { right: -2px; }
    
    /* Piilotetaan live-badge tilan säästämiseksi tai pienennetään */
    .live-badge { display: none; }
}