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

:root {
    --primary: #22c55e;
    --primary-hover: #16a34a;
    --bg-light: #f8fafc;
    --card-light: #ffffff;
    --text-light: #0f172a;
    --text-muted-light: #64748b;
    --border-light: #e2e8f0;
    
    /* Improved Dark Mode variables with better depth */
    --bg-dark: #050505;
    --card-dark: #121212;
    --text-dark: #f8fafc;
    --text-muted-dark: #a1a1aa;
    --border-dark: #27272a;
    
    --success: #22c55e;
    --warning: #f59e0b;
    --error: #f43f5e;
    
    /* Default to Dark Mode variables */
    --bg: var(--bg-dark);
    --card-bg: var(--card-dark);
    --text: var(--text-dark);
    --text-muted: var(--text-muted-dark);
    --border: var(--border-dark);
    --glass-bg: rgba(18, 18, 18, 0.8);
}

[data-theme="light"] {
    --bg: var(--bg-light);
    --card-bg: var(--card-light);
    --text: var(--text-light);
    --text-muted: var(--text-muted-light);
    --border: var(--border-light);
    --glass-bg: rgba(255, 255, 255, 0.8);
}

* {
    margin: 0;
    padding: 0;
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

::placeholder {
    color: var(--text-muted);
    opacity: 0.8;
}

body {
    font-family: 'Inter', -apple-system, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    line-height: 1.6;
    transition: background-color 0.3s ease, color 0.3s ease;
    min-height: 100vh;
}

h1, h2, h3 {
    font-family: 'Outfit', sans-serif;
    font-weight: 600;
}

.container {
    max-width: 600px;
    margin: 0 auto;
    padding: 1.5rem;
}

/* Navbar */
.navbar {
    position: sticky;
    top: 0;
    z-index: 100;
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1rem 1.5rem;
    background: var(--glass-bg);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
}

.logo {
    font-family: 'Outfit', sans-serif;
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    letter-spacing: -0.5px;
}

.status-indicator {
    font-size: 0.75rem;
    font-weight: 600;
    padding: 0.25rem 0.75rem;
    border-radius: 9999px;
    background: var(--border);
}

.status-indicator.online {
    color: var(--success);
    background: rgba(34, 197, 94, 0.15);
}

.status-indicator.offline {
    color: var(--error);
    background: rgba(244, 63, 94, 0.15);
}

/* Cards & Sections */
.section {
    margin-bottom: 2rem;
}

.section-title {
    font-size: 1.25rem;
    margin-bottom: 1rem;
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 1.25rem;
    padding: 1.25rem;
    box-shadow: 0 4px 6px -1px rgba(0, 0, 0, 0.2), 0 2px 4px -1px rgba(0, 0, 0, 0.06);
    margin-bottom: 1rem;
    transition: transform 0.2s ease, box-shadow 0.2s ease, border-color 0.2s ease;
}

.card:hover {
    transform: translateY(-2px);
    border-color: rgba(34, 197, 94, 0.3);
    box-shadow: 0 10px 15px -3px rgba(0, 0, 0, 0.3);
}

/* Feed Items */
.feed-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    border-bottom: 1px solid var(--border);
    padding: 1rem 0;
}

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

.feed-user-info {
    display: flex;
    flex-direction: column;
}

.feed-username {
    font-weight: 600;
    font-size: 1rem;
}

.feed-last-action {
    font-size: 0.8rem;
    color: var(--text-muted);
}

.feed-score-badge {
    background: linear-gradient(135deg, var(--primary), var(--primary-hover));
    color: white;
    padding: 0.5rem 1rem;
    border-radius: 0.75rem;
    font-weight: 700;
    text-align: center;
    min-width: 80px;
}

/* Inputs & Buttons */
.input-group {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 1.5rem;
    margin: 1.5rem 0;
}

.btn-circle {
    width: 3rem;
    height: 3rem;
    border-radius: 50%;
    border: 1px solid var(--border);
    background: var(--card-bg);
    color: var(--text);
    font-size: 1.5rem;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.2s ease;
    font-family: inherit;
}

.btn-circle:active {
    transform: scale(0.9);
}

.btn-circle:hover {
    background: var(--border);
    border-color: var(--primary);
}

.btn-circle:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

.score-display {
    font-size: 3rem;
    font-weight: 800;
    font-family: 'Outfit', sans-serif;
    color: var(--primary);
}

.btn-primary {
    width: 100%;
    padding: 1rem;
    background: var(--primary);
    color: white;
    border: none;
    border-radius: 1rem;
    font-weight: 600;
    font-size: 1rem;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 10px 15px -3px rgba(34, 197, 94, 0.3);
}

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

.btn-primary:active {
    transform: translateY(0);
}

.btn-primary:disabled {
    background: var(--text-muted);
    box-shadow: none;
    cursor: not-allowed;
    opacity: 0.5;
}

/* Modern Inputs */
.form-control {
    width: 100%;
    background: var(--card-bg);
    border: 1px solid var(--border);
    color: var(--text);
    padding: 0.875rem 1rem;
    border-radius: 0.75rem;
    font-size: 1rem;
    font-family: inherit;
    transition: all 0.2s ease;
}

.form-control:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(34, 197, 94, 0.2);
}

/* Player Selector (Tabs) */
.player-selector {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding: 0.5rem 0.25rem;
    margin-bottom: 1.5rem;
    scrollbar-width: none;
}

.player-selector::-webkit-scrollbar {
    display: none;
}

.player-tab {
    padding: 0.625rem 1.25rem;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 9999px;
    white-space: nowrap;
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    color: var(--text-muted);
    opacity: 0.6;
}

.player-tab:hover {
    opacity: 0.9;
    border-color: var(--primary);
}

.player-tab.active {
    background: var(--primary);
    border-color: var(--primary);
    color: white;
    box-shadow: 0 4px 15px rgba(34, 197, 94, 0.5);
    transform: scale(1.1);
    z-index: 2;
    opacity: 1;
    animation: tabPulse 2s infinite;
}

@keyframes tabPulse {
    0% { box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4); }
    50% { box-shadow: 0 4px 20px rgba(34, 197, 94, 0.8); }
    100% { box-shadow: 0 4px 12px rgba(34, 197, 94, 0.4); }
}

.player-tab.active::after {
    content: '';
    display: inline-block;
    width: 6px;
    height: 6px;
    background: white;
    border-radius: 50%;
    margin-left: 8px;
    vertical-align: middle;
    box-shadow: 0 0 5px white;
}

.scoring-player-info {
    text-align: center;
    margin-bottom: 0.5rem;
    padding: 0.5rem;
    border-radius: 0.75rem;
    background: rgba(34, 197, 94, 0.08);
    border: 1px solid rgba(34, 197, 94, 0.2);
    animation: fadeIn 0.3s ease;
}

.scoring-player-info .label {
    display: block;
    font-size: 0.7rem;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 0.1rem;
}

.scoring-player-info .player-name {
    font-weight: 700;
    font-size: 1.1rem;
    color: var(--primary);
}

.active-player-card {
    border-color: var(--primary) !important;
    background: rgba(34, 197, 94, 0.03) !important;
    box-shadow: 0 0 15px rgba(34, 197, 94, 0.15) !important;
    transform: scale(1.02);
}

/* Setup Player List */
.setup-player-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 1rem;
    padding: 0.75rem;
    background: rgba(255, 255, 255, 0.05);
    border-radius: 0.75rem;
    margin-bottom: 0.5rem;
    border: 1px solid var(--border);
}

.setup-player-info {
    flex: 1;
}

.setup-player-hcp {
    width: 70px;
    text-align: center;
}

/* Theme Toggle */
.theme-toggle {
    background: none;
    border: 1px solid var(--border);
    padding: 0.5rem;
    border-radius: 0.75rem;
    cursor: pointer;
    color: var(--text);
    transition: all 0.2s ease;
}

.theme-toggle:hover {
    background: var(--border);
    color: var(--primary);
}

/* Animations */
@keyframes fadeIn {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes modalIn {
    from { opacity: 0; transform: translate(-50%, -45%) scale(0.95); }
    to { opacity: 1; transform: translate(-50%, -50%) scale(1); }
}

@keyframes backdropIn {
    from { opacity: 0; background: rgba(0, 0, 0, 0); backdrop-filter: blur(0px); }
    to { opacity: 1; background: rgba(0, 0, 0, 0.6); backdrop-filter: blur(8px); }
}

.fade-in {
    animation: fadeIn 0.4s ease forwards;
}

/* Modals */
.modal-overlay {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    z-index: 1000;
    animation: backdropIn 0.3s ease forwards;
    backdrop-filter: blur(8px);
    -webkit-backdrop-filter: blur(8px);
}

.modal-content {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: 90%;
    max-width: 400px;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: 1.5rem;
    padding: 2rem;
    box-shadow: 0 25px 50px -12px rgba(0, 0, 0, 0.6);
    z-index: 1001;
    text-align: center;
    animation: modalIn 0.3s cubic-bezier(0.34, 1.56, 0.64, 1) forwards;
}

.modal-title {
    font-size: 1.5rem;
    margin-bottom: 0.75rem;
    color: var(--text);
}

.modal-message {
    color: var(--text-muted);
    margin-bottom: 2rem;
}

/* Picker Modal Items */
.picker-item {
    padding: 1.25rem 1rem;
    border-bottom: 1px solid var(--border);
    cursor: pointer;
    transition: background 0.2s ease;
}

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

.picker-item:hover {
    background: rgba(255, 255, 255, 0.05);
}

.picker-item:active {
    background: rgba(255, 255, 255, 0.1);
}

/* Touch-friendly HCP button */
.hcp-badge-editable {
    background: var(--border);
    color: var(--text);
    padding: 0.4rem 0.8rem;
    border-radius: 0.75rem;
    font-weight: 600;
    font-size: 0.9rem;
    cursor: pointer;
    transition: all 0.2s ease;
    border: 1px solid transparent;
}

.hcp-badge-editable:hover {
    border-color: var(--primary);
    color: var(--primary);
}

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

.btn-secondary {
    flex: 1;
    padding: 0.75rem;
    background: var(--border);
    color: var(--text);
    border: none;
    border-radius: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}

.btn-secondary:hover {
    background: var(--text-muted);
    color: white;
}

.btn-danger {
    flex: 1;
    padding: 0.75rem;
    background: var(--error);
    color: white;
    border: none;
    border-radius: 0.75rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
    box-shadow: 0 4px 6px -1px rgba(244, 63, 94, 0.2);
}

.btn-danger:hover {
    background: #e11d48;
    transform: translateY(-1px);
}

/* Scorecard Table */
.scorecard-container {
    overflow-x: auto;
    background: var(--card-bg);
    border-radius: 1rem;
    border: 1px solid var(--border);
    margin-top: 1rem;
    scrollbar-width: thin;
}

.scorecard-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
    min-width: 600px;
}

.scorecard-table th, .scorecard-table td {
    padding: 0.75rem 0.5rem;
    text-align: center;
    border-bottom: 1px solid var(--border);
}

.scorecard-table th {
    background: rgba(255, 255, 255, 0.05);
    font-weight: 700;
    color: var(--text-muted);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
}

.scorecard-table tr:last-child td {
    border-bottom: none;
}

.scorecard-table .hole-col {
    font-weight: 700;
    width: 40px;
    background: var(--card-bg);
    position: sticky;
    left: 0;
    z-index: 10;
}

.scorecard-table .par-col {
    color: var(--text-muted);
}

.scorecard-table .hcp-col {
    color: var(--text-muted);
    font-size: 0.75rem;
}

.player-score-cell {
    border-left: 1px solid var(--border);
}

.score-val {
    font-weight: 700;
    font-size: 1rem;
    display: block;
}

.points-val {
    font-size: 0.7rem;
    color: var(--primary);
    font-weight: 600;
}

.scorecard-summary {
    margin-top: 1.5rem;
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
    gap: 1rem;
}

.summary-card {
    background: var(--card-bg);
    border: 1px solid var(--border);
    padding: 1rem;
    border-radius: 1rem;
    text-align: center;
}

.summary-card .label {
    display: block;
    font-size: 0.75rem;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.summary-card .value {
    font-size: 1.5rem;
    font-weight: 800;
    color: var(--primary);
    font-family: 'Outfit', sans-serif;
}

.utility-link {
    background: none;
    border: none;
    font-size: 0.85rem;
    color: var(--text-muted);
    cursor: pointer;
    padding: 0.4rem 0.6rem;
    border-radius: 0.5rem;
    transition: all 0.2s ease;
    font-weight: 500;
}

/* Round Setup Styles */
.btn-setup-type {
    background: var(--glass-bg);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    padding: 1rem;
    color: var(--text);
    cursor: pointer;
    transition: all 0.2s;
    text-align: center;
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 0.25rem;
}

.btn-setup-type:hover {
    border-color: var(--primary);
    background: rgba(34, 197, 94, 0.05);
}

.btn-setup-type.active {
    border-color: var(--primary);
    background: rgba(34, 197, 94, 0.15);
    box-shadow: 0 0 20px rgba(34, 197, 94, 0.3);
    color: var(--primary);
    transform: scale(1.05); /* Pieni suurennus antaa hyvän palautteen */
}

.btn-setup-type.active div {
    color: var(--primary);
}

/* Statistics View Styles */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.stat-card {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 1rem 0.5rem;
    text-align: center;
    background: var(--card-bg);
}

.stat-card .label {
    font-size: 0.65rem;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    color: var(--text-muted);
    margin-bottom: 0.25rem;
}

.stat-card .value {
    font-size: 1.25rem;
    font-weight: 800;
    color: var(--primary);
    font-family: 'Outfit', sans-serif;
}

.chart-container {
    padding: 1.5rem;
    margin-bottom: 1rem;
    position: relative; /* Kriittinen Chart.js:lle */
}

.chart-wrapper {
    position: relative;
    width: 100%;
    margin-top: 1rem;
}

.chart-wrapper.distribution {
    height: 250px;
}

.chart-wrapper.progress {
    height: 200px;
}

@media (max-width: 480px) {
    .stats-grid {
        grid-template-columns: 1fr;
    }
    
    .stat-card {
        flex-direction: row;
        justify-content: space-between;
        padding: 1rem 1.25rem;
    }
    
    .stat-card .label {
        margin-bottom: 0;
    }
}
