:root {
    --primary: #3b4cca;
    --secondary: #ffde00;
    --danger: #cc0000;
    --dark: #1a1a1a;
    --panel-bg: #263238;
    --shiny-gold: #FFD700;
    --text-color: #eee;
}

body {
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    background-color: #121212;
    color: var(--text-color);
    margin: 0;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.hidden { display: none !important; }

/* --- HEADER --- */
.top-title-area { 
    text-align: center; 
    padding: 10px; 
    background: #b71c1c; 
}
.game-title { 
    margin: 0; 
    font-size: 2rem; 
    color: var(--secondary); 
    text-shadow: 2px 2px 0 var(--primary); 
}
.game-credits { 
    margin: 0; 
    font-size: 0.8rem; 
    opacity: 0.8; 
}

header { 
    background: #333; 
    padding: 10px; 
    border-bottom: 3px solid #444; 
}
.game-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    max-width: 1400px; 
    margin: 0 auto; 
    flex-wrap: wrap;
    gap: 10px;
}
.score-group { 
    display: flex; 
    gap: 20px; 
}
.header-controls { 
    display: flex; 
    gap: 10px; 
    align-items: center;
}

/* --- BUTTONS --- */
.action-btn, .map-theme-btn {
    background: var(--primary);
    color: white;
    border: none; 
    padding: 10px 20px; 
    border-radius: 5px;
    cursor: pointer; 
    font-weight: bold; 
    text-transform: uppercase; 
    transition: 0.2s;
}
.action-btn:hover:not(:disabled), .map-theme-btn:hover { 
    background: #5c6bc0; 
}
.action-btn:disabled { 
    background: #555; 
    cursor: not-allowed; 
}

.reset-btn {
    background: #555; 
    color: #ccc; 
    border: 1px solid #777;
    padding: 10px; 
    border-radius: 5px; 
    cursor: pointer; 
    font-size: 0.8rem;
}
.reset-btn:hover { 
    background: #b71c1c; 
    color: white; 
}

/* Gym Alert Button (Gold Pulse) */
.gym-alert-btn {
    background: linear-gradient(45deg, #FFD700, #FFA500);
    color: #000;
    border: 2px solid #fff;
    padding: 10px 20px;
    border-radius: 5px;
    cursor: pointer;
    font-weight: bold;
    text-transform: uppercase;
    box-shadow: 0 0 10px #FFD700;
    animation: pulseGold 1.5s infinite;
    margin-right: 5px;
    display: inline-block;
}
.gym-alert-btn:hover {
    transform: scale(1.05);
    background: linear-gradient(45deg, #FFA500, #FFD700);
}
@keyframes pulseGold {
    0% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0.7); }
    70% { box-shadow: 0 0 0 10px rgba(255, 215, 0, 0); }
    100% { box-shadow: 0 0 0 0 rgba(255, 215, 0, 0); }
}

/* --- MAIN LAYOUT --- */
main { 
    flex: 1; 
    padding: 15px; 
    width: 100%; 
    box-sizing: border-box; 
    max-width: 1600px; 
    margin: 0 auto; 
}
.main-message-panel {
    text-align: center;
    margin-bottom: 20px;
}
.note { 
    font-size: 0.9em; 
    color: #aaa; 
    font-style: italic; 
    margin-top: 5px; 
}

/* --- SHINY MECHANICS --- */
.shiny-controls {
    background: #3e2723; 
    border: 1px solid var(--shiny-gold);
    padding: 10px; 
    margin-bottom: 15px; 
    border-radius: 5px; 
    text-align: center; 
    color: var(--shiny-gold);
}
.is-shiny-card {
    border: 2px solid var(--shiny-gold) !important;
    box-shadow: 0 0 15px var(--shiny-gold);
    background: linear-gradient(135deg, #263238 0%, #5d4037 100%);
    animation: shinyPulse 3s infinite;
}
@keyframes shinyPulse {
    0% { box-shadow: 0 0 10px var(--shiny-gold); }
    50% { box-shadow: 0 0 25px var(--shiny-gold); }
    100% { box-shadow: 0 0 10px var(--shiny-gold); }
}

/* --- SELECTION GRID --- */
.selection-grid, .starter-grid {
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(140px, 1fr));
    gap: 15px; 
    margin-bottom: 20px;
}

/* Type filter row above selection grid */
.type-filters {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    margin: 10px 0 16px 0;
    align-items: center;
}
.type-filter {
    background: #2b2f33;
    color: #eee;
    border: 1px solid #444;
    padding: 6px 10px;
    border-radius: 6px;
    cursor: pointer;
    font-weight: 600;
    font-size: 0.85rem;
}
.type-filter.active {
    background: var(--primary);
    border-color: var(--secondary);
    color: white;
}
.poke-card {
    background: var(--panel-bg); 
    border: 2px solid #37474f;
    padding: 10px; 
    text-align: center; 
    cursor: pointer;
    border-radius: 8px; 
    transition: transform 0.1s;
    display: flex; 
    flex-direction: column; 
    align-items: center;
}
.poke-card:hover { 
    border-color: var(--secondary); 
    transform: translateY(-2px); 
}
.poke-card.selected-player {
    /* Player picks: gold */
    background: rgba(255, 215, 0, 0.18);
    border-color: var(--shiny-gold);
    box-shadow: 0 0 10px rgba(255, 215, 0, 0.12);
}
.poke-card.selected-machine {
    /* Machine picks: reddish */
    background: rgba(244, 67, 54, 0.16);
    border-color: #f44336;
    box-shadow: 0 0 10px rgba(244, 67, 54, 0.12);
}
.poke-card.unavailable {
    opacity: 0.4;
    pointer-events: none;
    filter: grayscale(100%);
}

/* Keep highlight visible when a selected card is marked unavailable */
.poke-card.unavailable.selected-player,
.poke-card.unavailable.selected-machine {
    opacity: 1;
    filter: none;
}
.selection-sprite { 
    width: 80px; 
    height: 80px; 
    object-fit: contain; 
    margin-bottom: 5px; 
}

/* --- DRAFT PREVIEW --- */
.draft-preview { 
    display: flex; 
    justify-content: space-between; 
    margin-top: 20px; 
    background: #1e1e1e; 
    padding: 15px; 
    border-radius: 10px; 
    gap: 20px;
    flex-wrap: wrap;
}
.team-box {
    flex: 1;
    min-width: 250px;
}
.mini-team-row { 
    display: flex; 
    gap: 10px; 
    flex-wrap: wrap; 
    min-height: 50px; 
    align-items: center;
}
.preview-item {
    position: relative;
    cursor: pointer;
    border: 1px solid #555;
    border-radius: 5px;
    padding: 5px;
    background: #333;
    transition: 0.2s;
}
.preview-item:hover { 
    background: #444; 
}
.preview-item img { 
    width: 40px; 
    height: 40px; 
    object-fit: contain; 
}
.preview-item.shiny-active { 
    border-color: var(--shiny-gold); 
    box-shadow: 0 0 5px var(--shiny-gold); 
}
.player-preview-item { 
    background: linear-gradient(135deg, rgba(255,215,0,0.04), rgba(255,215,0,0.02));
    border-color: rgba(255,215,0,0.18);
}
.machine-preview-item {
    background: linear-gradient(135deg, rgba(244,67,54,0.03), rgba(244,67,54,0.01));
    border-color: rgba(244,67,54,0.12);
}

/* Deselect X button on preview items */
/* Deselection removed: no X button styles needed */
.preview-item .shiny-icon {
    position: absolute; 
    top: -5px; 
    right: -5px; 
    font-size: 10px; 
    background: #000; 
    border-radius: 50%; 
    padding: 2px;
}

/* --- TM SELECTION --- */
#tm-selection-container { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr)); 
    gap: 20px; 
}
.tm-column { 
    background: var(--panel-bg); 
    padding: 15px; 
    border-radius: 8px; 
}
.tm-grid { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 5px; 
    margin-top: 10px; 
}
.tm-item { 
    background: #34495e; 
    padding: 8px; 
    font-size: 0.85rem; 
    cursor: pointer; 
    border: 1px solid #455a64; 
}
.tm-item.picked { 
    background: #27ae60; 
    border-color: #2ecc71; 
}
.tm-type-indicator { 
    font-size: 0.75em; 
    opacity: 0.8; 
    display: block; 
    margin-top: 2px; 
}

/* --- DUEL LAYOUT --- */
.duel-layout { 
    display: flex; 
    gap: 15px; 
    align-items: flex-start; 
    flex-wrap: wrap;
}
.battle-center { 
    flex: 2; 
    display: flex; 
    flex-direction: column; 
    min-width: 300px;
}
.party-sidebar { 
    flex: 0.5; 
    background: var(--panel-bg); 
    padding: 10px; 
    border-radius: 8px; 
    min-width: 160px; 
}
.sidebar-header { 
    display: flex; 
    justify-content: space-between; 
    align-items: center; 
    margin-bottom: 10px; 
}
.swap-badge { 
    background: #333; 
    border: 1px solid #555; 
    padding: 2px 6px; 
    border-radius: 4px; 
    font-size: 0.8rem; 
    color: var(--secondary); 
}

/* Party Lists */
.party-list { 
    display: flex; 
    flex-direction: column; 
    gap: 10px; 
}
.party-card {
    background: #37474f; 
    padding: 8px; 
    border-radius: 5px; 
    border: 1px solid #455a64;
    opacity: 0.7; 
    transition: 0.2s; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
    position: relative;
}
.party-thumb { 
    width: 50px; 
    height: 50px; 
    object-fit: contain; 
}
.party-card.active-mon { 
    opacity: 1; 
    border-color: var(--secondary); 
    background: #455a64; 
    box-shadow: 0 0 5px var(--secondary); 
}
.party-card.fainted { 
    opacity: 0.3; 
    filter: grayscale(100%); 
}
.party-card.tactical-swap:hover { 
    cursor: pointer; 
    opacity: 1; 
    border-color: #2ecc71; 
    background: #1b5e20; 
    transform: scale(1.02); 
}
.party-card.forced-swap { 
    cursor: pointer; 
    opacity: 1; 
    border-color: #f44336; 
    background: #b71c1c; 
    animation: pulse 1.5s infinite; 
}
@keyframes pulse { 
    0% { box-shadow: 0 0 0 0 rgba(244, 67, 54, 0.7); } 
    70% { box-shadow: 0 0 0 10px rgba(244, 67, 54, 0); } 
    100% { box-shadow: 0 0 0 0 rgba(244, 67, 54, 0); } 
}

/* Battle Arena */
.duel-container {
    display: flex; 
    flex-direction: row; 
    gap: 20px; 
    justify-content: space-between; 
    align-items: flex-end;
    background: #1c1c1c; 
    padding: 20px; 
    border-radius: 10px; 
    border: 2px solid #444; 
    min-height: 300px;
    margin-bottom: 15px;
}
.battle-side { 
    flex: 1; 
    text-align: center; 
    padding: 10px; 
    display: flex; 
    flex-direction: column; 
    align-items: center; 
}
.player-side { order: 1; } 
.log-wrapper { 
    order: 2; 
    flex: 1.2; 
    display: flex; 
    justify-content: center; 
    padding: 0 10px; 
}
.foe-side { order: 3; } 

.battle-sprite-img { 
    width: 160px; 
    height: 160px; 
    object-fit: contain; 
    filter: drop-shadow(0 5px 10px rgba(0,0,0,0.5)); 
    transition: opacity 0.5s; 
}
.player-side .battle-sprite-img { transform: scaleX(-1); }

.battle-log { 
    width: 100%; 
    height: 150px; 
    background: #000; 
    border: 1px solid #444; 
    overflow-y: auto; 
    padding: 10px; 
    font-family: monospace; 
    font-size: 0.85rem; 
    color: #00e676; 
    display: flex; 
    flex-direction: column-reverse; 
    border-radius: 4px; 
}

/* HP Bars & Badges */
.hp-bar-container { 
    width: 100%; 
    height: 20px; 
    background: #555; 
    border-radius: 10px; 
    overflow: hidden; 
    margin: 5px 0; 
    border: 2px solid #222; 
}
.hp-bar { 
    height: 100%; 
    background: #4caf50; 
    width: 100%; 
    transition: width 0.5s; 
}
.hp-low { background: #f44336; } 
.hp-mid { background: #ffeb3b; }

.small-hp-bar { 
    width: 100%; 
    height: 6px; 
    background: #555; 
    margin-top: 4px; 
    border-radius: 3px; 
}
.small-hp-fill { 
    height: 100%; 
    background: #4caf50; 
    width: 100%; 
    transition: width 0.3s; 
}

.type-badges-container { 
    display: flex; 
    justify-content: center; 
    gap: 5px; 
    margin-top: 5px; 
}
.type-badge { 
    font-size: 0.7em; 
    padding: 2px 6px; 
    border-radius: 4px; 
    color: white; 
    text-shadow: 0 1px 2px rgba(0,0,0,0.5); 
    font-weight: bold; 
    background: #555; 
}

/* Battle Controls */
.battle-controls-wrapper { 
    text-align: center; 
    background: var(--panel-bg); 
    padding: 15px; 
    border-radius: 8px; 
    min-height: 120px; 
    display: flex; 
    flex-direction: column; 
    justify-content: center; 
}
.move-grid { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 10px; 
    max-width: 600px; 
    margin: 0 auto; 
    width: 100%; 
}
.move-btn { 
    padding: 10px; 
    font-size: 0.95rem; 
    cursor: pointer; 
    background: #eee; 
    color: #222; 
    border: 2px solid #ccc; 
    border-radius: 8px; 
    text-align: left; 
}
.move-btn:hover:not(:disabled) { 
    background: #fff; 
    border-color: var(--secondary); 
}
.move-btn:disabled { 
    opacity: 0.5; 
    cursor: not-allowed; 
}
.move-meta { 
    font-size: 0.8em; 
    color: #666; 
    display: flex; 
    justify-content: space-between; 
    margin-top: 2px; 
}
.move-type-text { 
    font-weight: bold; 
    text-transform: uppercase; 
    font-size: 0.8em; 
}

/* Weather panel styling (light background for readability) */
#weather-panel, .weather-panel {
    background: rgba(255,255,255,0.92);
    color: #111;
    border: 1px solid rgba(0,0,0,0.06);
    box-shadow: 0 2px 6px rgba(0,0,0,0.08);
    padding: 4px 6px;
    border-radius: 6px;
    font-size: 0.85rem;
    display: inline-flex;
    align-items: center;
    gap: 6px;
    margin-left: 8px;
}

.weather-panel .type-badge {
    font-size: 0.75rem;
    padding: 2px 6px;
    border-radius: 12px;
    color: #fff;
    display: inline-block;
}

.weather-badge {
    background: #2b7a00;
    color: #fff;
    padding: 2px 6px;
    border-radius: 8px;
    font-weight: 600;
    font-size: 0.8rem;
    margin-left: 6px;
}

/* End Game Panel */
.end-game-panel { 
    text-align: center; 
    animation: fadeIn 0.5s; 
}
.end-game-panel h2 { 
    font-size: 2rem; 
    margin-bottom: 10px; 
    text-shadow: 2px 2px 4px rgba(0,0,0,0.5); 
}
.end-game-panel button { 
    font-size: 1.2rem; 
    padding: 10px 30px; 
    background: var(--secondary); 
    color: #333; 
    border: none; 
    border-radius: 5px; 
    cursor: pointer; 
    font-weight: bold; 
}
.end-game-panel button:hover { 
    background: #fff; 
}

/* --- PROFILE & STATS (New) --- */
.profile-content { 
    max-width: 850px; 
}
.profile-stats { 
    display: flex; 
    justify-content: space-around; 
    margin-bottom: 20px; 
    background: #1a1a1a; 
    padding: 15px; 
    border-radius: 8px; 
    flex-wrap: wrap;
}
.stat-box { 
    text-align: center; 
    min-width: 100px;
}
.stat-box h3 { 
    margin: 0 0 5px 0; 
    color: #aaa; 
    font-size: 0.9rem; 
}
.stat-box span { 
    font-size: 1.5rem; 
    font-weight: bold; 
    color: var(--secondary); 
}

/* Stats Grid */
.stats-grid-container { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 15px; 
    margin-top: 15px; 
    margin-bottom: 20px; 
}
.stats-column { 
    flex: 1; 
    min-width: 200px; 
    background: #222; 
    padding: 10px; 
    border-radius: 5px; 
    border: 1px solid #444; 
}
.stats-column h3 { 
    margin-top: 0; 
    color: var(--secondary); 
    border-bottom: 1px solid #555; 
    padding-bottom: 5px; 
    font-size: 1rem; 
}
.stats-list { 
    list-style: none; 
    padding: 0; 
    margin: 0; 
    font-size: 0.9rem; 
}
.stats-list li { 
    display: flex; 
    justify-content: space-between; 
    padding: 4px 0; 
    border-bottom: 1px solid #333; 
}
.stats-list li:last-child { 
    border-bottom: none; 
}
.stat-val { 
    font-weight: bold; 
    color: #4caf50; 
}

/* Badges Grid */
#badge-collection-container { 
    display: flex; 
    flex-direction: column; 
    gap: 15px; 
    max-height: 300px; 
    overflow-y: auto; 
}
.region-badge-row { 
    text-align: left; 
    border-bottom: 1px solid #444; 
    padding-bottom: 10px; 
}
.region-title { 
    color: var(--primary); 
    font-size: 0.9rem; 
    text-transform: uppercase; 
    letter-spacing: 1px; 
    margin-bottom: 5px; 
}
.badges-list { 
    display: flex; 
    flex-wrap: wrap; 
    gap: 10px; 
}
.badge-item { 
    width: 40px; 
    height: 40px; 
    border-radius: 50%; 
    background: #333; 
    border: 2px solid #555; 
    display: flex; 
    justify-content: center; 
    align-items: center; 
    font-size: 1.2rem; 
    cursor: help; 
    transition: 0.3s; 
    opacity: 0.3; 
    filter: grayscale(100%); 
}
.badge-item.unlocked { 
    opacity: 1; 
    filter: grayscale(0%); 
    border-color: var(--secondary); 
    box-shadow: 0 0 8px var(--primary); 
    background: linear-gradient(45deg, #444, #222); 
}
.badge-item:hover { 
    transform: scale(1.1); 
}

/* --- GYM MODALS --- */
.modal { 
    position: fixed; 
    z-index: 1000; 
    left: 0; 
    top: 0; 
    width: 100%; 
    height: 100%; 
    background-color: rgba(0,0,0,0.85); 
    display: flex; 
    justify-content: center; 
    align-items: center; 
}
.modal-content { 
    background-color: var(--panel-bg); 
    border: 2px solid var(--secondary); 
    border-radius: 10px; 
    padding: 25px; 
    width: 90%; 
    max-width: 700px; 
    color: #eee; 
    position: relative; 
}
.close-modal { 
    position: absolute; 
    top: 10px; 
    right: 20px; 
    color: #aaa; 
    font-size: 28px; 
    font-weight: bold; 
    cursor: pointer; 
}

.region-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fit, minmax(120px, 1fr)); 
    gap: 10px; 
    margin-top: 15px; 
}
.region-btn { 
    padding: 15px; 
    background: #2c3e50; 
    color: white; 
    border: 2px solid var(--primary); 
    border-radius: 8px; 
    cursor: pointer; 
    font-weight: bold; 
    text-transform: uppercase; 
}
.region-btn:hover { 
    background: var(--primary); 
}

.leader-grid { 
    display: grid; 
    grid-template-columns: repeat(auto-fill, minmax(180px, 1fr)); 
    gap: 10px; 
}
.leader-card { 
    background: #1a1a1a; 
    border: 1px solid #555; 
    padding: 10px; 
    border-radius: 5px; 
    cursor: pointer; 
    text-align: center; 
}
.leader-card:hover { 
    border-color: var(--secondary); 
    background: #333; 
}
.leader-card.defeated { 
    opacity: 0.5; 
    border-color: #2ecc71; 
    pointer-events: none; 
}
.leader-card.defeated::after { 
    content: "✅"; 
    display: block; 
}

/* Rules */
.rules-grid { 
    display: grid; 
    grid-template-columns: 1fr 1fr; 
    gap: 20px; 
    margin: 20px 0; 
    text-align: left; 
}
.rule-item { 
    background: #37474f; 
    padding: 15px; 
    border-radius: 8px; 
    border-left: 4px solid var(--primary); 
}

footer { 
    text-align: center; 
    padding: 20px; 
    color: #777; 
    font-size: 0.8rem; 
}

/* Recent Duels Panel */
.recent-duels {
    background: #121212;
    border: 1px solid #2c2c2c;
    padding: 12px;
    border-radius: 8px;
    margin: 12px 0;
}
.recent-duels h3 {
    margin: 0 0 8px 0;
    color: var(--secondary);
}
.recent-duels-list {
    display: flex;
    gap: 8px;
    flex-wrap: nowrap;
    overflow-x: auto;
}
.recent-duel-card {
    min-width: 200px;
    background: #1b1b1b;
    border: 1px solid #333;
    padding: 8px;
    border-radius: 6px;
    font-size: 0.9rem;
}
.recent-duel-card.win { border-color: #4caf50; }
.recent-duel-card.loss { border-color: #f44336; }
.recent-duel-card .small-line { font-size: 0.8rem; color: #bbb; margin-top: 6px; }
.recent-duel-team { display:flex; gap:6px; margin-top:6px; align-items:center; }
.recent-duel-team .recent-duel-poke { width:28px; height:28px; position:relative; }
.recent-duel-team .recent-duel-poke img { width:28px; height:28px; object-fit:contain; border-radius:4px; display:block; }

/* New styles for clarity */
.recent-duel-header { display:flex; justify-content:space-between; align-items:center; gap:8px; }
.recent-duel-counts { margin-top:6px; color:#ccc; font-size:0.82rem; }
.recent-duel-card .team-label { margin-top:8px; font-weight:700; color:#ddd; font-size:0.82rem; }
.recent-duel-team.player-team .recent-duel-poke img { box-shadow: 0 0 3px rgba(255,215,0,0.5); border: 1px solid rgba(255,215,0,0.12); }
.recent-duel-team.machine-team .recent-duel-poke img { box-shadow: 0 0 3px rgba(244,67,54,0.3); border: 1px solid rgba(244,67,54,0.08); }
.recent-duel-poke.defeated img { opacity: 0.35; filter: grayscale(100%); }
.recent-duel-poke.defeated::after { content: "✖"; position: absolute; right: -6px; top: -8px; color: #f44336; font-size: 12px; font-weight: bold; }

.recent-duel-card hr { border: none; border-top: 1px solid #2a2a2a; margin: 8px 0; }