/* Reset & Base */
:root {
    --bg-color: #f9f9f9;
    --card-bg: #ffffff;
    --text-color: #333;
    --border-color: #e0e0e0;
    --accent-color: #3a86ff;
    --hover-color: #f0f4f8;
    --font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    --shadow: 0 4px 6px rgba(0, 0, 0, 0.05);
}

* {
    box-sizing: border-box;
}

body {
    margin: 0;
    background-color: var(--bg-color);
    font-family: var(--font-family);
    color: var(--text-color);
    line-height: 1.5;
    -webkit-tap-highlight-color: transparent;
    /* Remove tap highlight on mobile */
}

body.no-scroll {
    overflow: hidden;
}

#promo-banner {
    background: linear-gradient(90deg, #ffc107, #ff9800);
    color: #000;
    text-align: center;
    padding: 10px;
    font-weight: bold;
    font-size: 1rem;
    box-shadow: 0 2px 5px rgba(0, 0, 0, 0.1);
    position: sticky;
    top: 0;
    z-index: 101;
}

/* Header */
header {
    background: var(--card-bg);
    border-bottom: 1px solid var(--border-color);
    padding: 1rem;
    /* Reduced padding for mobile */
    display: flex;
    justify-content: space-between;
    align-items: center;
    position: relative;
    /* Changed from sticky to support banner scrolling or relative */
    z-index: 100;
}

header h1 {
    margin: 0;
    font-size: 1.1rem;
    /* Smaller font on mobile */
    font-weight: 600;
}

.controls button {
    background: white;
    color: var(--text-color);
    border: 1px solid var(--border-color);
    padding: 0.5rem 0.8rem;
    cursor: pointer;
    border-radius: 4px;
    font-size: 0.85rem;
    transition: all 0.2s;
}

/* Main Layout */
main {
    padding: 1rem;
    /* Reduced main padding */
    max-width: 1600px;
    margin: 0 auto;
}

h2 {
    font-weight: 300;
    border-bottom: 1px solid #eee;
    padding-bottom: 10px;
    margin-bottom: 1.5rem;
    font-size: 1.3rem;
    /* Adjusted for mobile */
}

/* Groups Grid */
.groups-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 1rem;
    margin-bottom: 2rem;
}

@media (min-width: 1024px) {
    .groups-grid {
        grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
        gap: 1.5rem;
    }
}

.group-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    box-shadow: var(--shadow);
    padding: 1rem;
    display: flex;
    flex-direction: column;
}

.group-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 1rem;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 0.5rem;
}

.placeholder-select {
    background: white;
    color: #333;
    max-width: 130px;
    padding: 4px;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    font-size: 0.8rem;
}

/* Team List */
.team-list {
    list-style: none;
    padding: 0;
    margin: 0;
    flex: 1;
}

.team-item {
    display: flex;
    align-items: center;
    padding: 0.75rem 0.5rem;
    /* Larger touch target */
    background: var(--card-bg);
    border: 1px solid transparent;
    border-bottom: 1px solid #f0f0f0;
    cursor: grab;
    transition: background 0.2s;
    touch-action: pan-y;
    /* Allow vertical scroll */
}

/* ... (lines 159-197 unchanged) */

.grip {
    color: #ccc;
    cursor: grab;
    padding: 10px;
    /* Bigger touch target */
    font-size: 1.5rem;
    touch-action: none;
    /* Prevent scroll on handle */
}

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

.team-item:active {
    background: var(--hover-color);
}

.team-item.dragging {
    opacity: 0.5;
    background: #eef;
    border: 1px dashed var(--accent-color);
}

.team-item.over {
    border-top: 2px solid var(--accent-color);
}

.rank {
    width: 25px;
    color: #888;
    font-size: 0.9rem;
    font-weight: bold;
}

.flag {
    width: 28px;
    height: auto;
    margin: 0 10px;
    border-radius: 2px;
    box-shadow: 0 0 2px rgba(0, 0, 0, 0.1);
}

.name {
    flex: 1;
    font-weight: 500;
    font-size: 0.95rem;
}

.grip {
    color: #ccc;
    cursor: grab;
    padding: 0 5px;
    font-size: 1.2rem;
}

/* Action Area */
.action-area {
    text-align: center;
    margin: 2rem 0;
}

.primary-btn {
    background: var(--text-color);
    color: white;
    border: none;
    padding: 1rem 1.5rem;
    /* Better mobile fit */
    font-size: 1rem;
    border-radius: 6px;
    cursor: pointer;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.2);
    transition: all 0.3s;
    width: 100%;
    /* Full width on mobile default */
    max-width: 400px;
}

@media (min-width: 600px) {
    .primary-btn {
        width: auto;
    }
}

.primary-btn:hover {
    background: black;
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.3);
}

/* Third Place Section */
#third-place-section {
    margin-bottom: 4rem;
    border-top: 1px solid var(--border-color);
    padding-top: 2rem;
    display: none;
}

#third-place-container {
    max-width: 600px;
    margin: 0 auto;
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 8px;
    padding: 1rem;
    box-shadow: var(--shadow);
}

.third-place-header {
    display: flex;
    justify-content: space-between;
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
    background: #fcfcfc;
    border-radius: 8px 8px 0 0;
    font-weight: 600;
}

.qualified-line {
    border-bottom: 2px dashed #aaa;
    margin: 10px 0;
    text-align: center;
    color: #888;
    font-size: 0.8rem;
    padding: 5px;
}

/* Bracket */
#bracket-section {
    margin-top: 3rem;
    border-top: 1px solid var(--border-color);
    padding-top: 1.5rem;
    position: relative;
    /* Ensure container handles scroll cleanly */
    overflow-x: auto;
    width: 100%;
    -webkit-overflow-scrolling: touch;
    padding-bottom: 20px;

    /* Scrollbar Styling */
    scrollbar-width: thin;
    scrollbar-color: var(--accent-color) #f0f0f0;
}

#bracket-section::-webkit-scrollbar {
    height: 8px;
}

#bracket-section::-webkit-scrollbar-track {
    background: #f0f0f0;
    border-radius: 4px;
}

#bracket-section::-webkit-scrollbar-thumb {
    background-color: #ccc;
    border-radius: 4px;
}

#bracket-section::-webkit-scrollbar-thumb:hover {
    background-color: var(--accent-color);
}

#bracket-section h2 {
    text-align: center;
    margin-bottom: 2rem;
}

.bracket-flex {
    display: flex;
    justify-content: flex-start;
    padding-bottom: 3rem;
    padding-left: 20px;
    padding-right: 20px;
    margin-top: 40px;
    width: max-content;
}

.bracket-round {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    min-width: 200px;
    margin-right: 13%;
    position: relative;
    padding-top: 0;
}

.bracket-round:last-child {
    margin-right: 0;
}

.bracket-round h4 {
    text-align: center;
    margin-bottom: 1rem;
    color: #666;
    font-size: 0.9rem;
    text-transform: uppercase;
    letter-spacing: 1px;
    font-weight: bold;
    position: absolute;
    top: -40px;
    width: 100%;
}

.round-matches {
    display: flex;
    flex-direction: column;
    justify-content: space-around;
    width: 100%;
}

.match-card {
    background: var(--card-bg);
    border: 1px solid var(--border-color);
    border-radius: 6px;
    padding: 0.4rem;
    margin-bottom: 0.8rem;
    /* Gap between cards */
    position: relative;
    margin-top: 25px;
    z-index: 2;
    width: 200px;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* Remove margin-bottom from last card to align perfectly? */
.match-card:last-child {
    margin-bottom: 0;
}

/* Connectors */
/* Line from RIGHT of card */
.match-card::after {
    content: '';
    position: absolute;
    right: -20px;
    top: 50%;
    width: 20px;
    height: 1px;
    background: #ccc;
    display: none;
}

.bracket-round:not(:last-child) .match-card::after {
    display: block;
}

/* Line from LEFT of card (for Rounds > 1) */
.bracket-round:not(:first-child) .match-card::before {
    content: '';
    position: absolute;
    left: -20px;
    top: 50%;
    width: 20px;
    height: 1px;
    background: #ccc;
}

.match-card:hover {
    border-color: var(--accent-color);
}

.match-card .team {
    display: flex;
    align-items: center;
    padding: 6px;
    cursor: pointer;
    border-radius: 3px;
    transition: background 0.1s;
    font-size: 0.9rem;
}

.match-card .team:hover {
    background: var(--hover-color);
}

.match-card .team.winner {
    background: #e6ffea;
    color: #006400;
    font-weight: bold;
}

.match-card .team img {
    margin-right: 8px;
    width: 18px;
    border: 1px solid #eee;
}

/* Champion Overlay */
.overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.8);
    display: flex;
    justify-content: center;
    align-items: center;
    z-index: 1000;
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.3s;
}

.overlay.visible {
    opacity: 1;
    visibility: visible;
}

.overlay-content {
    background: white;
    color: #333;
    border: none;
    padding: 2rem;
    border-radius: 12px;
    text-align: center;
    position: relative;
    max-width: 500px;
    width: 90%;
    /* Responsive width */
    margin: 0 5%;
    transform: scale(0.8);
    transition: transform 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
}

.overlay.visible .overlay-content {
    transform: scale(1);
}

.close-btn {
    position: absolute;
    top: 10px;
    right: 15px;
    font-size: 2rem;
    background: none;
    border: none;
    cursor: pointer;
    color: #888;
}

.champion-display-large img {
    width: 100px;
    /* Slightly smaller for mobile safety */
    height: auto;
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
    margin-bottom: 1rem;
    border-radius: 4px;
}

.champion-display-large h1 {
    font-size: 1.8rem;
    color: var(--accent-color);
    margin: 0.5rem 0;
}

/* Form Styles */
.form-group {
    margin-bottom: 1rem;
    text-align: left;
}

.form-group label {
    display: block;
    margin-bottom: 0.5rem;
    font-size: 0.9rem;
    color: #666;
}

.form-group input {
    width: 100%;
    padding: 12px;
    background: #fff;
    border: 1px solid #ccc;
    color: #333;
    border-radius: 4px;
    font-size: 1rem;
    /* Better for mobile typing */
}

/* Footer */
footer {
    text-align: center;
    padding: 2rem 1rem;
    color: #999;
    font-size: 0.85rem;
    border-top: 1px solid var(--border-color);
    margin-top: 3rem;
}

footer p {
    margin: 0.5rem 0;
}

footer a {
    color: var(--accent-color);
    text-decoration: none;
    margin: 0 5px;
    border-bottom: 1px solid transparent;
}

/* Media Queries specific for small phones */
@media (max-width: 480px) {
    header {
        flex-direction: column;
        gap: 1rem;
        text-align: center;
    }

    .groups-grid {
        grid-template-columns: 1fr;
    }

    .match-card {
        width: 160px;
    }

    .bracket-round {
        min-width: 160px;
        margin-right: 15px;
    }

    .match-card::after {
        width: 15px;
        right: -15px;
    }

    .bracket-round:not(:first-child) .match-card::before {
        width: 15px;
        left: -15px;
    }
}