:root {
    --bg-color: #0f172a;
    --card-bg: rgba(30, 41, 59, 0.7);
    --primary-text: #f8fafc;
    --secondary-text: #94a3b8;
    --accent-p1: #ef4444;
    --accent-p2: #3b82f6;
    --score-color: #fbbf24;
    --border-color: rgba(255, 255, 255, 0.1);
    --glass-border: 1px solid rgba(255, 255, 255, 0.05);
}

* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: 'Inter', sans-serif;
    background-color: var(--bg-color);
    color: var(--primary-text);
    height: 100vh;
    /* display: flex; -> Removed to prevent cut-off */
    /* justify-content: center; */
    /* align-items: center; */
    overflow-y: auto;
    /* Allow scrolling */
}

.app-container {
    width: 100%;
    max-width: 1200px;
    min-height: 95vh;
    height: auto;
    margin: 2rem auto;
    /* Center horizontally and add vertical spacing */
    padding: 0 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

/* Header */
header {
    text-align: center;
    margin-bottom: 1rem;
    text-transform: uppercase;
    letter-spacing: 2px;
}

header h1 {
    font-size: 1.5rem;
    font-weight: 800;
    background: linear-gradient(to right, #60a5fa, #a78bfa);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.match-info {
    font-size: 0.8rem;
    color: var(--secondary-text);
    margin-top: 0.5rem;
}

#match-length {
    background: rgba(255, 255, 255, 0.1);
    color: var(--secondary-text);
    border: 1px solid rgba(255, 255, 255, 0.2);
    padding: 0.3rem 0.5rem;
    border-radius: 6px;
    font-family: inherit;
    font-size: 0.8rem;
    outline: none;
    cursor: pointer;
    text-align: center;
}

#match-length:hover {
    background: rgba(255, 255, 255, 0.15);
    color: #fff;
}

#match-length option {
    background: var(--bg-color);
    color: #fff;
}

/* Main Scoreboard Layout */
.scoreboard {
    display: grid;
    grid-template-columns: 1fr auto 1fr;
    gap: 2rem;
    align-items: center;
    background: var(--card-bg);
    padding: 3rem;
    border-radius: 24px;
    backdrop-filter: blur(16px);
    border: var(--glass-border);
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.5);
    flex-grow: 1;
}

/* Player Cards */
.player-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1.5rem;
    position: relative;
    padding: 1rem;
    border-radius: 16px;
    transition: background 0.3s;
}

.player-card:hover {
    background: rgba(255, 255, 255, 0.03);
}

.player-header {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
}

.player-name {
    background: transparent;
    border: none;
    color: var(--primary-text);
    font-size: 2rem;
    font-weight: 700;
    text-align: center;
    width: 100%;
    outline: none;
    border-bottom: 2px solid transparent;
    transition: border-color 0.3s;
}

.player-name:focus {
    border-color: var(--accent-p2);
}

#player1 .player-name:focus {
    border-color: var(--accent-p1);
}

.player-club {
    background: transparent;
    border: none;
    color: var(--secondary-text);
    font-size: 1rem;
    text-align: center;
    width: 100%;
    outline: none;
    text-transform: uppercase;
    letter-spacing: 1px;
}

/* Score Display */
.score-display {
    position: relative;
    width: 100%;
    display: flex;
    justify-content: center;
    align-items: center;
}

.score {
    font-family: 'Share Tech Mono', monospace;
    font-size: 10rem;
    line-height: 1;
    font-weight: 700;
    color: var(--score-color);
    text-shadow: 0 0 20px rgba(251, 191, 36, 0.3);
}

/* Service Indicator */
.service-indicator {
    width: 20px;
    height: 20px;
    background-color: #fff;
    border-radius: 50%;
    position: absolute;
    top: 50%;
    transform: translateY(-50%);
    left: 20px;
    /* Adjust based on layout */
    box-shadow: 0 0 10px #fff;
    opacity: 1;
    transition: opacity 0.3s, left 0.3s;
}

.player-card#player2 .service-indicator {
    left: auto;
    right: 20px;
    /* Right side for player 2 */
}

.service-indicator.hidden {
    opacity: 0;
}

/* Controls */
.controls {
    display: flex;
    gap: 1rem;
}

.btn-score {
    width: 50px;
    height: 50px;
    border-radius: 50%;
    border: none;
    font-size: 1.5rem;
    cursor: pointer;
    transition: transform 0.1s, background 0.3s;
    display: flex;
    align-items: center;
    justify-content: center;
    font-weight: bold;
}

.btn-score:active {
    transform: scale(0.95);
}

.btn-plus {
    background-color: rgba(255, 255, 255, 0.1);
    color: #fff;
}

.btn-plus:hover {
    background-color: rgba(255, 255, 255, 0.2);
}

.btn-minus {
    background-color: rgba(255, 0, 0, 0.1);
    color: #fca5a5;
}

.btn-minus:hover {
    background-color: rgba(255, 0, 0, 0.2);
}

.sets-won {
    font-size: 1.2rem;
    font-weight: 600;
    color: var(--secondary-text);
    background: rgba(0, 0, 0, 0.2);
    padding: 0.5rem 1rem;
    border-radius: 8px;
}

.sets-won span {
    color: #fff;
    margin-left: 0.5rem;
}

/* Divider & Middle Controls */
.divider {
    display: flex;
    flex-direction: column;
    align-items: center;
    gap: 1rem;
}

.vs {
    font-size: 2rem;
    font-weight: 800;
    color: rgba(255, 255, 255, 0.1);
}

.btn-reset-set {
    background: transparent;
    border: 1px solid rgba(255, 255, 255, 0.2);
    color: var(--secondary-text);
    padding: 0.5rem 1rem;
    border-radius: 8px;
    cursor: pointer;
    font-size: 0.8rem;
    transition: all 0.3s;
}

.btn-reset-set:hover {
    border-color: #fff;
    color: #fff;
}

#btn-close-set {
    padding: 0.8rem 1.5rem;
    font-weight: 800;
    letter-spacing: 1px;
    background: #ef4444;
    /* Red for attention */
    border: none;
    box-shadow: 0 0 15px rgba(239, 68, 68, 0.5);
}

#btn-close-set:hover {
    background: #dc2626;
}

.pulse {
    animation: pulse-animation 2s infinite;
}

@keyframes pulse-animation {
    0% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0.7);
    }

    70% {
        box-shadow: 0 0 0 10px rgba(239, 68, 68, 0);
    }

    100% {
        box-shadow: 0 0 0 0 rgba(239, 68, 68, 0);
    }
}

/* History Section */
.history-section {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 1.5rem;
    backdrop-filter: blur(16px);
    border: var(--glass-border);
}

.history-section h2 {
    font-size: 0.9rem;
    color: var(--secondary-text);
    margin-bottom: 1rem;
    text-transform: uppercase;
}

.history-grid {
    display: grid;
    grid-template-columns: 150px repeat(7, 1fr);
    gap: 2px;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    overflow: hidden;
}

.history-header,
.history-row-label,
.history-cell {
    padding: 0.8rem;
    text-align: center;
    font-size: 0.9rem;
}

.history-header {
    background: rgba(0, 0, 0, 0.3);
    color: var(--secondary-text);
    font-weight: 600;
}

.history-row-label {
    background: rgba(0, 0, 0, 0.2);
    color: var(--primary-text);
    font-weight: 600;
    text-align: left;
    padding-left: 1.5rem;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.history-cell {
    background: rgba(255, 255, 255, 0.02);
    color: #fff;
    font-family: 'Share Tech Mono', monospace;
}

/* Main Controls */
.main-controls {
    display: flex;
    justify-content: center;
    gap: 1rem;
}

.main-controls button {
    padding: 0.8rem 2rem;
    border-radius: 8px;
    border: none;
    font-weight: 600;
    cursor: pointer;
    text-transform: uppercase;
    transition: filter 0.2s;
}

.btn-danger {
    background-color: #dc2626;
    color: #fff;
}

.btn-danger:hover {
    background-color: #ef4444;
}

.btn-secondary {
    background-color: #475569;
    color: #fff;
}

.btn-secondary:hover {
    background-color: #64748b;
}

.btn-link {
    color: var(--secondary-text);
    text-decoration: none;
    font-size: 0.9rem;
    padding: 0.5rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.2);
    border-radius: 6px;
    transition: all 0.2s;
}

.btn-link:hover {
    color: #fff;
    border-color: #fff;
    background: rgba(255, 255, 255, 0.05);
}

.btn-primary {
    background-color: #3b82f6;
    color: #fff;
}

.btn-primary:hover {
    background-color: #2563eb;
}

/* Archive Section */
.archive-section {
    background: var(--card-bg);
    border-radius: 16px;
    padding: 1.5rem;
    backdrop-filter: blur(16px);
    border: var(--glass-border);
    margin-top: 1rem;
}

.archive-section h2 {
    font-size: 0.9rem;
    color: var(--secondary-text);
    margin-bottom: 1rem;
    text-transform: uppercase;
}

.archive-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.empty-archive {
    color: var(--secondary-text);
    font-style: italic;
    text-align: center;
    padding: 1rem;
}

.archive-item {
    background: rgba(255, 255, 255, 0.05);
    border-radius: 8px;
    padding: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    border: 1px solid transparent;
    transition: all 0.2s;
}

.archive-item:hover {
    background: rgba(255, 255, 255, 0.1);
    border-color: rgba(255, 255, 255, 0.1);
}

.archive-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.archive-date {
    font-size: 0.75rem;
    color: var(--secondary-text);
}

.archive-result-row {
    display: flex;
    align-items: baseline;
    gap: 0.5rem;
    flex-wrap: wrap;
}

.archive-result {
    font-weight: 700;
    font-size: 1.1rem;
    color: #fff;
}

.archive-details {
    font-size: 0.85rem;
    color: var(--secondary-text);
    font-family: 'Share Tech Mono', monospace;
}

.archive-names {
    color: #cbd5e1;
    font-size: 0.9rem;
}

.btn-delete-archive {
    background: transparent;
    border: none;
    color: #ef4444;
    cursor: pointer;
    font-size: 0.9rem;
    padding: 0.5rem;
    opacity: 0.7;
    transition: opacity 0.2s;
}

.btn-delete-archive:hover {
    opacity: 1;
}

/* Responsive adjustments */
@media (max-width: 900px) {
    .scoreboard {
        padding: 1rem;
        gap: 1rem;
    }

    .score {
        font-size: 6rem;
    }

    .player-name {
        font-size: 1.5rem;
    }

    .history-grid {
        grid-template-columns: 100px repeat(7, 1fr);
    }
}

@media print {
    body {
        background: #fff;
        color: #000;
        height: auto;
        overflow: visible;
    }

    .app-container {
        height: auto;
        padding: 0;
        max-width: none;
    }

    .scoreboard,
    .team-box,
    .config-section,
    .match-table th,
    .match-table td,
    .input-text,
    .input-score {
        background: transparent;
        color: #000;
        border-color: #000;
        box-shadow: none;
        backdrop-filter: none;
    }

    .main-controls,
    .config-section select,
    label {
        display: none;
        /* Hide controls when printing */
    }

    /* We want to show the config setup results though? No, just the filled sheet */
    /* Let's keep input values visible */

    .total-score {
        color: #000;
        border: 2px solid #000;
        background: transparent;
    }

    header h1 {
        -webkit-text-fill-color: #000;
        background: none;
        color: #000;
    }

    /* Print specific for substitutions */
    .player-label-span.subbed {
        text-decoration: none;
        /* Maybe underline in print? */
        font-style: italic;
    }
}

/* New styles for Phase 2 */
.input-score-sm {
    width: 40px;
    text-align: center;
    background: rgba(0, 0, 0, 0.3);
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: #fff;
    padding: 0.2rem;
    border-radius: 4px;
    font-size: 0.8rem;
}

.input-score-sm:focus {
    border-color: var(--accent-p2);
    outline: none;
}

/* Substituted player styling */
.player-label-span.subbed {
    color: var(--score-color);
    /* Highlight subbed player */
    /* font-style: italic; */
}

/* Checkbox styling adjustment */
input[type="checkbox"] {
    cursor: pointer;
    width: 16px;
    height: 16px;
    accent-color: var(--accent-p2);
}

@media print {
    .input-score-sm {
        background: transparent;
        color: #000;
        border-color: #ccc;
    }

    input[type="checkbox"] {
        display: none;
        /* Hide checkboxes in print */
    }
}

.stats-table {
    border-collapse: collapse;
    background: rgba(0, 0, 0, 0.2);
    border-radius: 8px;
    font-size: 0.9rem;
    margin: 0 auto;
}

.stats-table th,
.stats-table td {
    padding: 0.5rem 1rem;
    border: 1px solid rgba(255, 255, 255, 0.05);
    text-align: center;
}

.btn-success {
    background: #10b981;
    color: white;
}

.btn-success:hover {
    background: #059669;
}

.stats-table th {
    background: rgba(255, 255, 255, 0.05);
    color: var(--secondary-text);
    font-weight: normal;
}