:root {
    --bg-color: #121212;
    --card-bg: #ffffff;
    --header-bg: #1f1f1f;
    --text-light: #e0e0e0;
    --text-dark: #333;
    --winner-gold: #ffcc00;
    --past-blue: #a3d8f4;
    --accent-red: #d32f2f;
}

body { 
    font-family: -apple-system, system-ui, sans-serif;
    background: var(--bg-color); 
    margin: 0; padding: 10px;
    color: var(--text-light);
}

/* --- Header & Box Score Table --- */
.main-header {
    text-align: center;
    background: var(--header-bg);
    padding: 20px;
    border-radius: 12px;
    margin-bottom: 20px;
    border: 1px solid #333;
}

.box-score-table {
    width: 100%;
    max-width: 500px;
    margin: 15px auto 0;
    border-collapse: collapse;
    background: #fff;
    color: #000;
    border-radius: 8px;
    overflow: hidden;
    font-size: 0.85rem;
    border: 1px solid #fff;
}

.box-score-table th { background: #333; color: #fff; }
.box-score-table th, .box-score-table td {
    padding: 8px;
    text-align: center;
    border: 1px solid #ddd;
}

.team-cell { text-align: left !important; display: flex; align-items: center; gap: 8px; font-weight: bold; }
.tiny-logo { width: 24px; height: 24px; object-fit: contain; }
.final-col { background: #f0f0f0; font-weight: bold; }

/* --- Layout --- */
.content-wrapper { display: flex; flex-direction: column; gap: 20px; }

/* --- Grid Section --- */
.scroll-container {
    display: block;
    overflow-x: auto;
    background: #fff;
    padding: 10px;
    /* border-radius: 8px; */
    box-shadow: 0 4px 10px rgba(0,0,0,0.5);flex: 1; 
    /* Grows to fill available space */
    width: 100%; /* Ensures it respects the parent container's width */
    -webkit-overflow-scrolling: touch;
    max-width: 615px;
}

.grid-flex { display: flex; width: max-content; }

#squares-grid {
    display: grid;
    grid-template-columns: 40px repeat(10, 55px);
    gap: 1px;
    background: #bbb;
    width: max-content !important;
}

.square {
    width: 55px; height: 55px;
    background: white;
    color: var(--text-dark);
    display: flex; align-items: center; justify-content: center;
    font-size: 0.6rem; text-align: center;
    position: relative;
    word-break: break-word;
    /* padding: 4px; */
    line-height: 1.1;
    transition: none !important;
}

.label { background: #222; color: #fff; font-weight: bold; }

/* --- Winners & Badges --- */
/* Reverted to the Red Badge Look */
.q-badge {
    position: absolute;
    width: 15px;
    height: 11px;
    background: #d32f2f; /* That classic vibrant red */
    color: #ffffff;      /* White text for contrast */
    font-size: 10px;
    font-weight: 900;    /* Extra bold for readability */
    display: flex;
    align-items: center;
    justify-content: center;
    border-radius: 4px;  /* Slightly rounded corners for a "tag" look */
    border: 1px solid rgba(255, 255, 255, 0.3);
    z-index: 5;
    box-shadow: 0 2px 4px rgba(0,0,0,0.3);
    pointer-events: none; /* Ensures the badge doesn't interfere with clicks */
}

/* Corner Specific Positions */
.q-badge.q1 { top: 0px; left: 0px; }
.q-badge.q2 { top: 0px; right: 0px; }
.q-badge.q3 { bottom: 0px; left: 0px; }
.q-badge.q4 { bottom: 0px; right: 0px; background: #b71c1c;}

.active-winner {
    background-color: var(--winner-gold) !important;
    font-weight: bold;
    box-shadow: inset 0 0 10px rgba(0,0,0,0.2);
    animation: pulse 1.5s infinite;
}

.past-winner { background-color: var(--past-blue) !important; }

@keyframes pulse {
    0% { transform: scale(1); }
    50% { transform: scale(1.04); }
    100% { transform: scale(1); }
}

.grid-section{
    border-radius: 12px;
    margin-bottom: 20px;
    background: #1f1f1f;
    border: 1px solid #333;
}

/* --- Axis Labels --- */
.top-label { 
    background: #222; 
    padding: 10px; 
    display: flex; 
    justify-content: center; /* Centers the content horizontally */
    align-items: center; 
}

/* New inner wrapper to keep logo and text tight together */
.top-label-inner {
    display: flex;
    flex-direction: row; /* Horizontal alignment */
    align-items: center;
    gap: 12px; /* Space between logo and name */
}

.top-label .axis-logo { 
    width: 40px; /* Slightly smaller for a cleaner horizontal look */
    height: 40px; 
    object-fit: contain; 
}

.top-label .label-text { 
    font-size: 0.85rem; 
    font-weight: bold; 
    color: #fff; 
    letter-spacing: 1px;
    white-space: nowrap; /* Prevents name from wrapping to a second line */
}
.left-label { padding: 10px; display: flex; flex-direction: column; align-items: center; }
.axis-logo { width: 40px; height: 40px; object-fit: contain; }
.label-text { font-size: 0.75rem; font-weight: bold; color: #fff; letter-spacing: 1px; }

.left-label span { 
    writing-mode: vertical-rl; 
    transform: rotate(180deg); 
    margin-top: 10px; 
    font-size: 0.8rem;
    white-space: nowrap;
}

/* --- Sidebar Payouts --- */
.sidebar { background: #fff; padding: 15px; border-radius: 12px; }
.sidebar h3 { margin-top: 0; border-bottom: 2px solid #333; padding-bottom: 5px; }
.payout-item { 
    display: flex; justify-content: space-between; 
    padding: 10px 0; border-bottom: 1px solid #eee; 
}
.payout-amount { font-weight: bold; color: #2e7d32; }

/* --- Desktop Layout Reflow --- */
@media (min-width: 1024px) {
    .content-wrapper { flex-direction: row; align-items: flex-start; justify-content: center; }
    .sidebar { width: 300px; position: sticky; top: 20px; }
}

/* --- Participant & Payout List --- */
.sidebar h3 { 
    margin-top: 0; 
    font-size: 1.1rem;
    border-bottom: 2px solid var(--bg-color);
    padding-bottom: 10px;
    color: var(--text-dark);
}

.participant-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 0;
    border-bottom: 1px solid #eee;
    color: var(--text-dark);
}

.p-info {
    display: flex;
    flex-direction: column;
}

.p-name {
    font-weight: bold;
    font-size: 0.9rem;
}

.p-count {
    font-size: 0.75rem;
    color: #666;
}

.p-payout {
    font-weight: bold;
    font-family: monospace;
    font-size: 1rem;
    color: #999; /* Grey for no earnings */
}

.has-earnings .p-payout {
    color: #2e7d32; /* Green for winners */
    background: #e8f5e9;
    padding: 2px 8px;
    border-radius: 4px;
}

.has-earnings {
    background: rgba(46, 125, 50, 0.05);
    margin: 0 -10px;
    padding: 10px;
    border-radius: 8px;
}

/* Container for Left Label + Grid */
.main-grid-area {
    display: flex;
    align-items: flex-start;
    background: var(--header-bg);
    /* border-radius: 8px; */
    overflow: hidden; /* Clips the inner scroll shadow */
    max-width: fit-content;
}

/* Static Left Axis Label */
.left-label {
    flex: 0 0 60px; /* Fixed width, won't shrink or grow */
    display: flex;
    flex-direction: column;
    align-items: center;
    color: white;
    padding-top: 55px; /* Matches the height of the top digit-label row */
    z-index: 10;
}

/* The Scrollable Squares */
.scroll-container {
    flex: 1;
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    background: #fff;
    max-width: 671px;
}

#squares-grid {
    display: grid;
    /* Removed the first 40px column since the label is now outside */
    grid-template-columns: repeat(12, 55px); 
    gap: 1px;
    background: #bbb;
    width: max-content;
}

/* Ensure the top-left corner of the grid matches the top axis height */
.label {
    height: 55px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.payout-summary {
    display: flex;
    justify-content: center;
    gap: 15px;
    margin-top: 10px;
    font-size: 0.85rem;
    color: #eee;
    background: rgba(255, 255, 255, 0.1);
    padding: 5px 15px;
    border-radius: 20px;
    display: inline-flex; /* Keeps it centered if parent is centered */
}

.payout-summary strong {
    color: #ffca28; /* Gold color for the labels */
    margin-right: 3px;
}

@media (max-width: 600px) {
    .payout-summary {
        font-size: 0.75rem;
        gap: 8px;
        padding: 5px 10px;
    }
}

.mobile-hint {
    text-align: center;
    font-size: 0.85rem;
    color: #888;
    margin-top: 10px;
    font-style: italic;
    /* Optional: subtle animation */
    animation: fadeIn 0.5s ease-in;
}

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

/* The Pulse Effect */
.winning-now {
    outline: 4px solid #ffca28;
    outline-offset: -4px;
    box-shadow: 0 0 20px #ffca28;
    z-index: 10;
    transform: scale(1.1);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

/* Optional: Score Change Flash */
.score-changed {
    animation: scoreFlash 1s ease-out;
}

@keyframes scoreFlash {
    0% { background-color: rgba(255, 202, 40, 0.8); }
    100% { background-color: transparent; }
}

.leader-card {
    background: rgba(255, 255, 255, 0.05);
    padding: 12px;
    border-radius: 8px;
    margin-bottom: 10px;
    display: flex;
    flex-direction: column;
    border-left: 4px solid #444;
}

.current-winner {
    background: rgba(255, 202, 40, 0.1);
    border-left-color: #ffca28;
    box-shadow: 0 0 15px rgba(255, 202, 40, 0.1);
}

.winner-payout {
    border-left-color: #4caf50; /* Green for confirmed wins */
}

.leader-card .label { font-size: 0.7rem; color: #aaa; text-transform: uppercase; letter-spacing: 1px; }
.leader-card .name { font-size: 1.1rem; font-weight: bold; margin: 2px 0; }
.leader-card .amount { font-size: 0.9rem; color: #ffca28; font-family: monospace; }

.participant-row {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 8px 0;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
    font-size: 0.95rem;
    color: #eee;
}

.p-count {
    font-size: 0.75rem;
    background: rgba(255, 255, 255, 0.1);
    padding: 2px 8px;
    border-radius: 10px;
    color: #aaa;
}

.sidebar {
    background: var(--header-bg);
    padding: 20px;
    border-radius: 8px;
    min-width: 280px;
    max-width: 734px;
    /* align-self: flex-start; */
    position: sticky;
    top: 20px;
}

.sidebar h3 {
    margin-top: 0;
    margin-bottom: 15px;
    font-size: 1.1rem;
    border-bottom: 1px solid rgba(255,255,255,0.1);
    padding-bottom: 8px;
    color: #ffca28;
}

.sidebar-section {
    margin-bottom: 25px;
}

.sidebar hr {
    border: 0;
    border-top: 1px solid rgba(255,255,255,0.1);
    margin: 20px 0;
}

.user-highlight {
    outline: 3px solid #fff !important;
    outline-offset: -3px;
    z-index: 5;
    transform: scale(1.05);
    opacity: 1 !important;
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.8);
}

.participant-row:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffca28;
}

.participant-row.active-row {
    background: rgba(255, 202, 40, 0.2) !important;
    color: #ffca28 !important;
    border-left: 3px solid #ffca28;
    padding-left: 10px;
}

/* Ensure the user-highlight is very visible */
.user-highlight {
    outline: 3px solid #fff !important;
    outline-offset: -3px;
    z-index: 10;
    transform: scale(1.08);
    box-shadow: 0 0 20px rgba(255, 255, 255, 0.6);
}

/* --- Lobby Specific Styles --- */
.lobby-container {
    max-width: 650px;
    margin: 0 auto;
    padding: 40px 20px;
}

.lobby-header {
    text-align: center;
    margin-bottom: 40px;
}

.lobby-icon { font-size: 3rem; margin-bottom: 10px; }
.lobby-header h1 { margin: 0; font-size: 2rem; letter-spacing: -1px; }
.lobby-header p { color: #888; margin-top: 5px; }

.match-list {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.lobby-card {
    background: #1f1f1f;
    border: 1px solid #333;
    border-radius: 16px;
    text-decoration: none;
    color: inherit;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    overflow: hidden;
    display: block;
}

.lobby-card:hover {
    transform: translateY(-4px);
    border-color: #ffca28;
    background: #252525;
    box-shadow: 0 10px 30px rgba(0,0,0,0.5);
}

.card-body {
    padding: 24px;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.game-date {
    display: block;
    font-size: 0.8rem;
    color: #666;
    text-transform: uppercase;
    letter-spacing: 1px;
    margin-bottom: 6px;
}

.match-details h2 {
    margin: 0 0 12px 0;
    font-size: 1.4rem;
    color: #fff;
}

.match-meta-tags {
    display: flex;
    gap: 10px;
    align-items: center;
}

.meta-tag {
    font-size: 0.85rem;
    color: #aaa;
    background: rgba(255,255,255,0.05);
    padding: 4px 12px;
    border-radius: 20px;
}

.meta-tag.prize {
    background: rgba(255, 202, 40, 0.1);
    color: #ffca28;
    font-weight: bold;
    border: 1px solid rgba(255, 202, 40, 0.2);
}

.view-btn {
    color: #ffca28;
    border: 1px solid #ffca28;
    padding: 8px 16px;
    border-radius: 8px;
    font-size: 0.8rem;
    font-weight: bold;
    text-transform: uppercase;
    transition: all 0.2s;
}

.lobby-card:hover .view-btn {
    background: #ffca28;
    color: #000;
}

.empty-state {
    text-align: center;
    padding: 60px 20px;
    background: rgba(255,255,255,0.02);
    border: 2px dashed #333;
    border-radius: 16px;
    color: #555;
}

@media (max-width: 500px) {
    .card-body { flex-direction: column; align-items: flex-start; gap: 20px; }
    .card-arrow { width: 100%; }
    .view-btn { display: block; text-align: center; }
}