* {
    box-sizing: border-box;
}

:root {
    --primary: #1d78cb;
    --primary-hover: #2db34a;
    --bg-dark: #000;
    --glass-bg: rgba(255, 255, 255, 0.03);
    --glass-border: rgba(255, 255, 255, 0.1);
    --glass-hover: rgba(255, 255, 255, 0.08);
    --text-primary: #ffffff;
    --text-secondary: rgba(255, 255, 255, 0.5);
    --success: #1d78cb;
    --error: #ff3b30;
    --font-main: 'Outfit', sans-serif;
}

@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;600;700&display=swap');

body {
    background-color: var(--bg-dark);
    background-image:
        radial-gradient(at 0% 0%, hsla(253, 16%, 7%, 1) 0, transparent 50%),
        radial-gradient(at 50% 0%, hsla(225, 39%, 30%, 0.2) 0, transparent 50%),
        radial-gradient(at 100% 0%, hsla(339, 49%, 30%, 0.2) 0, transparent 50%);
    color: var(--text-primary);
    font-family: var(--font-main);
    margin: 0;
    padding: 0;
    height: 100vh;
    overflow: hidden;
    /* Prevent global scroll */
    display: flex;
}

.container {
    width: 100%;
    height: 100%;
    padding: 0;
    margin: 0;
}

/* Layout and Sidebar */
.app-layout {
    display: flex;
    gap: 0;
    width: 100%;
    height: 100vh;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    position: relative;
    overflow: hidden;
}

.sidebar {
    width: 300px;
    height: 100%;
    background: var(--glass-bg);
    border-right: 1px solid var(--glass-border);
    padding: 1.5rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
    transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    flex-shrink: 0;
    position: relative;
    /* Default relative to push content */
    z-index: 100;
}

.sidebar.hidden {
    margin-left: -300px;
    opacity: 0;
    pointer-events: none;
}

.sidebar h2 {
    font-size: 1.2rem;
    margin: 0;
    color: var(--text-primary);
}

/* Sidebar Toggle (close ✕ inside sidebar) */
.sidebar-toggle {
    background: rgba(255, 255, 255, 0.06);
    color: var(--text-secondary);
    border: 1px solid var(--glass-border);
    width: 34px;
    height: 34px;
    border-radius: 50%;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    flex-shrink: 0;
    transition: all 0.2s ease;
}

.sidebar-toggle:hover {
    background: rgba(255, 255, 255, 0.12);
    color: var(--text-primary);
}

/* Floating open button (☰ visible when sidebar is hidden) */
.sidebar-open-btn {
    position: fixed;
    top: 1.5rem;
    left: 1.5rem;
    z-index: 1001;
    background: var(--primary);
    color: #000;
    border: none;
    width: 40px;
    height: 40px;
    border-radius: 50%;
    cursor: pointer;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 1.2rem;
    box-shadow: 0 4px 15px rgba(29, 120, 203, 0.3);
    transition: all 0.3s ease;
}

.sidebar-open-btn:hover {
    transform: scale(1.1);
    background: var(--primary-hover);
}

/* Backdrop overlay for mobile (click outside to close) */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    z-index: 99;
    backdrop-filter: blur(2px);
}

.sidebar-backdrop.visible {
    display: block;
}

.sheet-list {
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
    overflow-y: auto;
    flex: 1;
}

.sheet-item {
    padding: 1rem;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 1rem;
    cursor: pointer;
    transition: all 0.3s ease;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.sheet-item:hover {
    background: var(--glass-hover);
}

.sheet-item.active {
    background: rgba(29, 120, 203, 0.1);
    border-color: var(--primary);
}

.sheet-item-info {
    display: flex;
    flex-direction: column;
    gap: 0.2rem;
}

.sheet-item-name {
    font-weight: 600;
    font-size: 0.95rem;
}

.sheet-item-date {
    font-size: 0.75rem;
    color: var(--text-secondary);
}

.delete-sheet-btn {
    background: rgba(255, 59, 48, 0.1);
    color: var(--error);
    border: none;
    padding: 0.4rem;
    border-radius: 0.5rem;
    cursor: pointer;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.sheet-item:hover .delete-sheet-btn {
    opacity: 1;
}

.new-sheet-btn {
    width: 100%;
    padding: 1rem;
    background: var(--primary);
    color: #000;
    border: none;
    border-radius: 1rem;
    font-weight: 700;
    cursor: pointer;
    transition: all 0.3s ease;
}

.new-sheet-btn:hover {
    background: var(--primary-hover);
    transform: translateY(-2px);
}

.main-content {
    flex: 1;
    min-width: 0;
    padding: 2.5rem;
    transition: all 0.3s ease;
    height: 100%;
    overflow-y: auto;
    /* Independent scroll for content */
}

/* Empty State */
.empty-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    height: 60vh;
    text-align: center;
    gap: 0.75rem;
    color: var(--text-secondary);
}

.empty-state-icon {
    font-size: 4rem;
    margin-bottom: 0.5rem;
    opacity: 0.6;
}

.empty-state h2 {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin: 0;
}

.empty-state p {
    font-size: 0.95rem;
    margin: 0;
    max-width: 320px;
}

/* Simplified Header */
.simplified-header {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1.5rem;
    padding: 1.5rem 2rem;
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 2rem;
    margin-bottom: 2rem;
}

.auto-save-status {
    position: fixed;
    bottom: 2rem;
    right: 2rem;
    padding: 0.6rem 1.2rem;
    background: rgba(0, 0, 0, 0.85);
    backdrop-filter: blur(15px);
    border: 1px solid rgba(255, 255, 255, 0.1);
    border-radius: 2rem;
    font-size: 0.85rem;
    color: var(--text-secondary);
    display: flex;
    align-items: center;
    gap: 0.8rem;
    z-index: 1000;
    box-shadow: 0 4px 20px rgba(0, 0, 0, 0.5);
    transition: all 0.4s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    transform: translateY(100px);
    opacity: 0;
}

.auto-save-status.visible {
    transform: translateY(0);
    opacity: 1;
    animation: pop-in 0.5s cubic-bezier(0.175, 0.885, 0.32, 1.275);
}

@keyframes pop-in {
    0% {
        transform: translateY(100px) scale(0.8);
        opacity: 0;
    }

    70% {
        transform: translateY(-5px) scale(1.02);
        opacity: 1;
    }

    100% {
        transform: translateY(0) scale(1);
        opacity: 1;
    }
}

.auto-save-status.success {
    border-color: rgba(29, 120, 203, 0.4);
    background: rgba(29, 120, 203, 0.1);
    box-shadow: 0 4px 25px rgba(29, 120, 203, 0.2);
}

/* Field level success highlight */
.auto-save.saved-field-success {
    border-color: #1d78cb !important;
    box-shadow: 0 0 10px rgba(29, 120, 203, 0.3) !important;
    transition: all 0.3s ease;
}

.save-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--primary);
    box-shadow: 0 0 10px var(--primary);
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.save-dot::after {
    display: none;
    font-size: 0.7rem;
    color: #fff;
}

.save-dot.saving {
    background: #ffcc00;
    box-shadow: 0 0 15px #ffcc00;
    animation: pulse-save 1.5s infinite;
}

.save-dot.success {
    background: var(--success);
    box-shadow: 0 0 15px var(--success);
    transform: scale(1.2);
}

.save-dot.success::after {
    content: "✓";
    display: block;
}

@keyframes blink {
    0% {
        opacity: 0.4;
    }

    50% {
        opacity: 1;
    }

    100% {
        opacity: 0.4;
    }
}

@keyframes pulse-save {
    0% {
        transform: scale(1);
        opacity: 1;
    }

    50% {
        transform: scale(1.3);
        opacity: 0.6;
    }

    100% {
        transform: scale(1);
        opacity: 1;
    }
}

header {
    margin-bottom: 2rem;
    text-align: left;
    display: flex;
    justify-content: space-between;
    align-items: flex-end;
}

header h1 {
    font-size: 3rem;
    font-weight: 600;
    background: linear-gradient(135deg, #fff 0%, #aaa 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.subtitle {
    font-size: 1rem;
    color: var(--text-secondary);
    font-weight: 500;
    letter-spacing: 0.05em;
    text-transform: uppercase;
}

.glass-card {
    background: var(--glass-bg);
    backdrop-filter: blur(40px);
    -webkit-backdrop-filter: blur(40px);
    border: 1px solid var(--glass-border);
    border-radius: 2rem;
    padding: 2.5rem;
    box-shadow: 0 8px 32px rgba(0, 0, 0, 0.4);
    margin-bottom: 3rem;
    transition: all 0.3s ease;
}

.header-meta {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1.5rem;
}

.input-group {
    display: flex;
    flex-direction: column;
    gap: 0.6rem;
}

label {
    font-size: 0.75rem;
    font-weight: 700;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.1em;
}

input {
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    padding: 0.8rem 1.25rem;
    color: var(--text-primary);
    font-family: inherit;
    font-size: 1rem;
    outline: none;
    transition: all 0.3s ease;
}

input:focus {
    border-color: rgba(255, 255, 255, 0.3);
    background: rgba(255, 255, 255, 0.06);
    box-shadow: 0 0 15px rgba(255, 255, 255, 0.05);
}

.matches-container {
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.match-row {
    background: var(--glass-bg);
    border: 1px solid var(--glass-border);
    border-radius: 1.5rem;
    padding: 1.5rem 2rem;
    display: grid;
    grid-template-columns: 80px minmax(210px, 1.2fr) minmax(210px, 1.2fr) 300px 80px 80px;
    gap: 1.5rem;
    align-items: center;
    transition: all 0.3s ease;
    overflow-x: auto;
    /* Allow internal scroll if viewport is really small but before mobile breakpoint */
}

.match-row:hover {
    background: var(--glass-hover);
    border-color: rgba(255, 255, 255, 0.2);
    transform: translateY(-2px);
}

.discipline-label {
    font-weight: 700;
    color: var(--primary);
    font-size: 1.1rem;
    letter-spacing: -0.02em;
}

.player-inputs {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    min-width: 210px;
}

.player-inputs input {
    padding: 0.6rem 1rem;
    font-size: 0.9rem;
    width: 100%;
}

.score-inputs {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.8rem;
    width: 100%;
}

.score-set {
    display: flex;
    flex-direction: column;
    gap: 0.4rem;
    min-width: 0;
}

.score-set label {
    font-size: 0.6rem;
    text-align: center;
}

.score-set input {
    width: 100%;
    padding: 0.5rem;
    text-align: center;
    font-weight: 700;
    font-size: 1.1rem;
}

/* Chrome, Safari, Edge, Opera */
input::-webkit-outer-spin-button,
input::-webkit-inner-spin-button {
    -webkit-appearance: none;
    appearance: none;
    margin: 0;
}

/* Firefox */
input[type=number] {
    -moz-appearance: textfield;
    appearance: textfield;
}

.total-points,
.match-winner {
    text-align: center;
}

.points-display {
    font-size: 1.4rem;
    font-weight: 700;
    margin-top: 0.5rem;
}

.footer-totals {
    background: var(--glass-bg);
    backdrop-filter: blur(40px);
    border: 1px solid var(--glass-border);
    border-radius: 2rem;
    padding: 2.5rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-top: 2rem;
}

.total-score {
    font-size: 2.5rem;
    font-weight: 700;
    background: linear-gradient(135deg, #fff 0%, #aaa 100%);
    -webkit-background-clip: text;
    background-clip: text;
    -webkit-text-fill-color: transparent;
}

.submit-btn {
    background: var(--text-primary);
    color: #000;
    border: none;
    padding: 1.25rem 3rem;
    border-radius: 1.25rem;
    font-size: 1.1rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s cubic-bezier(0.16, 1, 0.3, 1);
    box-shadow: 0 10px 20px rgba(0, 0, 0, 0.2);
}

.submit-btn:hover:not(:disabled) {
    transform: translateY(-3px);
    box-shadow: 0 15px 30px rgba(255, 255, 255, 0.2);
    filter: brightness(1.1);
}

.submit-btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

@media (max-width: 1024px) {
    .sidebar {
        position: fixed;
        left: 0;
        top: 0;
        bottom: 0;
        z-index: 1100;
        border-radius: 0 1.5rem 1.5rem 0;
        box-shadow: 20px 0 50px rgba(0, 0, 0, 0.5);
        background: rgba(15, 15, 20, 0.95);
        backdrop-filter: blur(20px);
        margin-left: 0;
        /* Override desktop margin-left */
        transform: translateX(0);
        transition: transform 0.3s cubic-bezier(0.4, 0, 0.2, 1);
    }

    .sidebar.hidden {
        transform: translateX(-100%);
        margin-left: 0;
        opacity: 1;
        /* Keep opacity but slide out */
    }

    .app-layout {
        gap: 0;
    }

    .match-row {
        grid-template-columns: 1fr;
        padding: 1.5rem;
        gap: 1.5rem;
        min-width: 0;
    }

    .player-inputs {
        min-width: 0;
    }

    .discipline-label {
        text-align: center;
        background: rgba(255, 255, 255, 0.05);
        padding: 0.5rem;
        border-radius: 0.8rem;
    }

    .score-inputs {
        grid-template-columns: 1fr;
    }

    .score-set {
        flex-direction: row;
        justify-content: center;
        align-items: center;
        gap: 1rem;
    }

    .score-set label {
        width: 30px;
        text-align: left;
    }

    .score-set input {
        width: 70px;
    }

    .main-content {
        padding: 1rem;
        padding-top: 5rem;
    }

    header {
        flex-direction: column;
        align-items: flex-start;
        gap: 1rem;
    }

    .footer-totals {
        padding: 1.5rem;
        margin-top: 1.5rem;
    }
}

@media (max-width: 768px) {
    .footer-totals {
        flex-direction: column;
        gap: 1.5rem;
        text-align: center;
        padding: 1.5rem;
    }

    .total-score {
        font-size: 2rem;
    }

    .submit-btn {
        width: 100%;
        padding: 1rem;
        font-size: 1rem;
    }

    .modal-content {
        padding: 1.5rem;
        border-radius: 1.5rem;
    }
}

/* Custom Player Selection Popup */
.player-popup {
    position: absolute;
    background: rgba(15, 15, 20, 0.95);
    backdrop-filter: blur(15px);
    border: 1px solid var(--glass-border);
    border-radius: 1rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.5);
    max-height: 250px;
    overflow-y: auto;
    z-index: 2000;
    min-width: 250px;
    display: none;
    flex-direction: column;
    padding: 0.5rem;
    gap: 0.2rem;
}

.player-popup.visible {
    display: flex;
}

.player-popup-item {
    padding: 0.6rem 1rem;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 0.2s ease;
    display: flex;
    justify-content: space-between;
    gap: 1rem;
    align-items: center;
}

.player-popup-item:hover,
.player-popup-item.active-item {
    background: rgba(255, 255, 255, 0.1);
}

.player-popup-name {
    font-weight: 600;
    color: var(--text-primary);
    font-size: 0.95rem;
}

.player-popup-rank {
    font-size: 0.75rem;
    color: var(--primary);
    background: rgba(29, 120, 203, 0.15);
    padding: 0.2rem 0.5rem;
    border-radius: 1rem;
    white-space: nowrap;
}

/* Scrollbar styling for popup */
.player-popup::-webkit-scrollbar {
    width: 6px;
}

.player-popup::-webkit-scrollbar-track {
    background: transparent;
}

.player-popup::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 10px;
}

.player-popup::-webkit-scrollbar-thumb:hover {
    background: rgba(255, 255, 255, 0.3);
}

/* Signature Modal */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.7);
    backdrop-filter: blur(10px);
    z-index: 3000;
    display: none;
    align-items: center;
    justify-content: center;
    padding: 1rem;
    opacity: 0;
    transition: opacity 0.3s ease;
}

.modal-overlay.visible {
    display: flex;
    opacity: 1;
}

.modal-content {
    background: #1a1a20;
    border: 1px solid var(--glass-border);
    border-radius: 2rem;
    padding: 2.5rem;
    width: 100%;
    max-width: 500px;
    box-shadow: 0 20px 50px rgba(0, 0, 0, 0.8);
    transform: translateY(20px);
    transition: transform 0.3s ease;
}

.modal-overlay.visible .modal-content {
    transform: translateY(0);
}

.modal-header {
    margin-bottom: 2rem;
}

.modal-header h2 {
    font-size: 1.5rem;
    margin: 0;
}

.signature-pad-container {
    background: #fff;
    border-radius: 1rem;
    margin-bottom: 1.5rem;
    overflow: hidden;
    touch-action: none;
    /* Critical for signing on touch devices */
}

#signatureCanvas {
    width: 100%;
    height: 200px;
    cursor: crosshair;
}

.modal-step {
    display: none;
    animation: fadeIn 0.3s ease;
}

.modal-step.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(10px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

.modal-actions {
    display: flex;
    gap: 1rem;
    margin-top: 2rem;
}

.modal-actions button {
    flex: 1;
    padding: 0.8rem;
    border-radius: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    border: none;
    font-family: inherit;
}

.btn-cancel {
    background: rgba(255, 59, 48, 0.1);
    color: #ff3b30;
    border: 1px solid rgba(255, 59, 48, 0.2) !important;
}

.btn-cancel:hover {
    background: rgba(255, 59, 48, 0.2);
}

.btn-clear {
    background: rgba(255, 204, 0, 0.1);
    color: #ffcc00;
    border: 1px solid rgba(255, 204, 0, 0.2) !important;
}

.btn-clear:hover {
    background: rgba(255, 204, 0, 0.2);
}

.btn-secondary {
    background: rgba(255, 255, 255, 0.05);
    color: var(--text-primary);
    border: 1px solid var(--glass-border);
}

.btn-secondary:hover {
    background: rgba(255, 255, 255, 0.1);
}

.signature-label {
    margin-bottom: 0.8rem;
    display: block;
    font-size: 0.85rem;
    color: var(--text-primary);
    font-weight: 600;
}

.opponent-email-input {
    width: 100%;
    margin-bottom: 1.5rem;
}

/* Print Specific overrides for the actual browser page if print=true is in URL */
@media print {
    body {
        background: white !important;
        color: black !important;
        height: auto !important;
        overflow: visible !important;
    }

    .sidebar,
    .new-sheet-btn,
    #openSidebarBtn,
    .sidebar-backdrop,
    .auto-save-status,
    .sidebar-open-btn {
        display: none !important;
    }

    .main-content {
        padding: 0 !important;
        width: 100% !important;
        height: auto !important;
        overflow: visible !important;
    }

    .app-layout {
        height: auto !important;
        overflow: visible !important;
    }

    .simplified-header,
    .match-row,
    .footer-totals {
        background: transparent !important;
        border-color: #eee !important;
        color: black !important;
        box-shadow: none !important;
        backdrop-filter: none !important;
    }

    input,
    select {
        color: black !important;
        background: transparent !important;
        border: none !important;
        border-bottom: 1px solid #ccc !important;
    }

    .player-select-btn,
    .submit-btn {
        display: none !important;
    }

    .total-score {
        -webkit-text-fill-color: black !important;
        background: none !important;
    }
}

.print-mode {
    background: white !important;
    color: black !important;
    height: auto !important;
    overflow: visible !important;
}

.print-mode .sidebar,
.print-mode .new-sheet-btn,
.print-mode #openSidebarBtn,
.print-mode .sidebar-backdrop,
.print-mode .auto-save-status,
.print-mode .sidebar-open-btn {
    display: none !important;
}

.print-mode .main-content {
    padding: 0 !important;
    width: 100% !important;
    height: auto !important;
    overflow: visible !important;
}

.print-mode .app-layout {
    height: auto !important;
    overflow: visible !important;
}

.print-mode .simplified-header,
.print-mode .match-row,
.print-mode .footer-totals {
    background: transparent !important;
    border-color: #eee !important;
    color: black !important;
    box-shadow: none !important;
    backdrop-filter: none !important;
}

.print-mode input,
.print-mode select {
    color: black !important;
    background: transparent !important;
    border: none !important;
    border-bottom: 1px solid #ccc !important;
}

.print-mode .player-select-btn,
.print-mode .submit-btn {
    display: none !important;
}

.print-mode .total-score {
    -webkit-text-fill-color: black !important;
    background: none !important;
}
/* Read Mode Overrides */
body.read-mode .new-sheet-btn,
body.read-mode .delete-sheet-btn,
body.read-mode #signSubmitBtn,
body.read-mode .player-select-btn,
body.read-mode #saveIndicator {
    display: none !important;
}
body.read-mode input, body.read-mode select, body.read-mode textarea {
    pointer-events: none;
    opacity: 0.6;
}

