*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --green: #1a5e2a;
    --green-light: #2d8a42;
    --green-dark: #0f3d1a;
    --gold: #f0c040;
    --red: #d32f2f;
    --blue: #1976d2;
    --bg: #f5f5f0;
    --card: #ffffff;
    --text: #1a1a1a;
    --text-muted: #666;
    --border: #ddd;
    --radius: 10px;
    --shadow: 0 2px 8px rgba(0,0,0,0.1);
}

html { font-size: 16px; }
body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    -webkit-tap-highlight-color: transparent;
}

/* Nav */
.nav-bar {
    background: var(--green);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 1rem;
    padding-top: max(0.6rem, env(safe-area-inset-top));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    position: sticky;
    top: 0;
    z-index: 100;
}
.nav-brand {
    font-weight: 700;
    font-size: 1.2rem;
    color: white;
    text-decoration: none;
}
.nav-links { display: flex; gap: 1rem; }
.nav-links a {
    color: rgba(255,255,255,0.85);
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 500;
}
.nav-links a:hover { color: white; }
.nav-logout { opacity: 0.6; }

/* Layout */
.container {
    padding: 1rem;
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: max(1rem, env(safe-area-inset-bottom));
    max-width: 600px;
    margin: 0 auto;
}
.full-width { max-width: 100%; padding: 0; }

/* Cards */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 1rem;
    margin-bottom: 1rem;
}
.card-title {
    font-size: 0.8rem;
    text-transform: uppercase;
    color: var(--text-muted);
    margin-bottom: 0.5rem;
    letter-spacing: 0.05em;
}

/* Stat cards */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(70px, 1fr));
    gap: 0.75rem;
    margin-bottom: 1rem;
}
.stat-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.75rem;
    text-align: center;
}
.stat-value { font-size: 1.5rem; font-weight: 700; color: var(--green); }
.stat-label { font-size: 0.7rem; color: var(--text-muted); text-transform: uppercase; }

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.65rem 1.2rem;
    border-radius: var(--radius);
    border: none;
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    transition: opacity 0.15s;
    -webkit-appearance: none;
}
.btn:active { opacity: 0.7; }
.btn-primary { background: var(--green); color: white; }
.btn-danger { background: var(--red); color: white; }
.btn-secondary { background: var(--border); color: var(--text); }
.btn-lg { padding: 0.9rem 2rem; font-size: 1.1rem; width: 100%; }
.btn-sm { padding: 0.4rem 0.8rem; font-size: 0.8rem; }

/* Forms */
.form-group { margin-bottom: 1rem; }
.form-group label {
    display: block;
    font-size: 0.85rem;
    font-weight: 600;
    margin-bottom: 0.3rem;
    color: var(--text-muted);
}
.form-control {
    width: 100%;
    padding: 0.6rem 0.8rem;
    border: 2px solid var(--border);
    border-radius: var(--radius);
    font-size: 1rem;
    background: white;
    -webkit-appearance: none;
}
.form-control:focus { outline: none; border-color: var(--green); }
select.form-control { padding-right: 2rem; }

/* Error */
.alert-error {
    background: #fce4e4;
    border: 1px solid var(--red);
    color: var(--red);
    padding: 0.6rem 1rem;
    border-radius: var(--radius);
    margin-bottom: 1rem;
    font-size: 0.9rem;
}

/* Login page */
.login-container {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
    padding: max(1rem, env(safe-area-inset-top)) max(1rem, env(safe-area-inset-right)) max(1rem, env(safe-area-inset-bottom)) max(1rem, env(safe-area-inset-left));
    background: var(--green-dark);
}
.login-card {
    background: white;
    border-radius: 16px;
    padding: 2rem;
    width: 100%;
    max-width: 360px;
    box-shadow: 0 8px 32px rgba(0,0,0,0.2);
}
.login-title {
    text-align: center;
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--green);
    margin-bottom: 1.5rem;
}
.login-toggle {
    text-align: center;
    margin-top: 1rem;
    font-size: 0.85rem;
}
.login-toggle a { color: var(--green); }

/* Round list */
.round-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.round-item:last-child { border-bottom: none; }
.round-course { font-weight: 600; }
.round-date { font-size: 0.8rem; color: var(--text-muted); }
.round-score { font-size: 1.3rem; font-weight: 700; }
.round-item-link { text-decoration: none; color: inherit; }

/* Score colors */
.score-eagle { color: #e6a800; font-weight: 700; }
.score-birdie { color: var(--red); font-weight: 700; }
.score-par { color: var(--green); }
.score-bogey { color: var(--blue); }
.score-double { color: #333; font-weight: 700; }

/* vs-par coloring: under=good (red), even (green), over (default text) */
.vs-par-under { color: var(--red); }
.vs-par-even { color: var(--green); }
.vs-par-over { color: var(--text); }

/* Strokes gained coloring: positive=good (green), negative=bad (red) */
.sg-positive { color: var(--green); }
.sg-negative { color: var(--red); }

/* Scoring distribution row */
.dist-row {
    display: flex;
    justify-content: space-around;
    text-align: center;
    font-size: 0.85rem;
}
.dist-item-val {
    font-size: 1.3rem;
    font-weight: 700;
}

/* Data table */
.data-table { width: 100%; font-size: 0.85rem; border-collapse: collapse; }
.data-table th, .data-table td { padding: 0.3rem; border-bottom: 1px solid var(--border); }
.data-table th { text-align: left; }
.data-table td { text-align: center; }
.data-table td:first-child { text-align: left; font-weight: 600; }

/* Club list */
.club-item {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.6rem 0;
    border-bottom: 1px solid var(--border);
}
.club-item:last-child { border-bottom: none; }
.club-name { font-weight: 600; }
.club-cat { font-size: 0.75rem; color: var(--text-muted); text-transform: capitalize; }
.club-inactive { opacity: 0.4; }
.club-actions { display: flex; gap: 0.5rem; }

/* Play screen */
.play-container {
    display: flex;
    flex-direction: column;
    height: 100vh;
    height: 100dvh;
    overflow: hidden;
}
.play-header {
    background: var(--green);
    color: white;
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.5rem 1rem;
    padding-top: max(0.5rem, env(safe-area-inset-top));
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    flex-shrink: 0;
}
.play-hole-num { font-size: 1.5rem; font-weight: 700; }
.play-par { font-size: 1rem; opacity: 0.8; }
.play-score-vs-par { font-size: 1.3rem; font-weight: 700; }
.play-map {
    flex: 1 1 0;
    min-height: 0;
    position: relative;
    overflow: hidden;
}
.play-map #map {
    width: 100%;
    height: 100%;
}
#map-compass {
    position: absolute;
    top: 8px;
    left: 32px;
    z-index: 500;
    width: 36px;
    height: 36px;
    background: rgba(0,0,0,0.65);
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
}
#recenter-btn {
    position: absolute;
    bottom: 55px;
    right: 10px;
    z-index: 500;
    background: rgba(0,0,0,0.7);
    color: white;
    border: none;
    border-radius: 8px;
    padding: 0.5rem 0.8rem;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    display: none;
}
.play-distance {
    position: absolute;
    bottom: 10px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0,0,0,0.8);
    color: white;
    padding: 0.5rem 1.4rem;
    border-radius: 24px;
    font-size: 2rem;
    font-weight: 700;
    z-index: 500;
    text-align: center;
    pointer-events: none;
}
.play-distance small { font-size: 0.75rem; font-weight: 400; opacity: 0.7; }
.play-weather {
    position: absolute;
    top: 10px;
    right: 10px;
    background: rgba(0,0,0,0.7);
    color: white;
    padding: 0.3rem 0.7rem;
    border-radius: 8px;
    font-size: 0.75rem;
    z-index: 500;
}
.play-sync {
    position: absolute;
    top: 10px;
    left: 10px;
    z-index: 500;
    width: 12px; height: 12px;
    border-radius: 50%;
    background: #4caf50;
}
.play-sync.pending { background: #ff9800; }
.play-sync.offline { background: var(--red); }
.play-wind-arrow {
    position: absolute;
    top: 38px;
    right: 10px;
    z-index: 500;
    background: rgba(0,0,0,0.65);
    border-radius: 50%;
    width: 32px;
    height: 32px;
    display: flex;
    align-items: center;
    justify-content: center;
    pointer-events: none;
}

.hole-nav-btn {
    width: 28px; height: 28px;
    border-radius: 50%;
    border: 1.5px solid rgba(255,255,255,0.5);
    background: rgba(255,255,255,0.15);
    color: rgba(255,255,255,0.8);
    font-size: 1.2rem; font-weight: 700;
    cursor: pointer;
    display: flex; align-items: center; justify-content: center;
    padding: 0; min-height: 0;
}
.hole-nav-btn:disabled { opacity: 0.3; cursor: default; }
.rescore-banner {
    background: #fff3e0; color: #e65100;
    padding: 0.3rem 0.6rem; font-size: 0.8rem; font-weight: 600;
    text-align: center; border-bottom: 1px solid #ffcc80;
}

.play-controls {
    background: var(--card);
    border-top: 1px solid var(--border);
    padding: 0.75rem;
    padding-bottom: max(0.75rem, env(safe-area-inset-bottom));
    padding-left: max(0.75rem, env(safe-area-inset-left));
    padding-right: max(0.75rem, env(safe-area-inset-right));
    flex-shrink: 0;
}
.club-rec {
    font-size: 0.9rem;
    padding: 0.2rem 0.4rem;
    color: var(--green);
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.4rem;
}
.club-rec .rec-club { color: var(--green-dark); }
.club-rec .rec-dist { color: var(--text-muted); font-weight: 400; }

.club-row {
    display: flex;
    gap: 0.5rem;
    overflow-x: auto;
    padding-bottom: 0.5rem;
    -webkit-overflow-scrolling: touch;
    scrollbar-width: none;
}
.club-row::-webkit-scrollbar { display: none; }
.club-btn {
    flex-shrink: 0;
    padding: 0.75rem 1.1rem;
    border-radius: 12px;
    border: 2px solid var(--border);
    background: white;
    font-size: 1.05rem;
    font-weight: 600;
    cursor: pointer;
    white-space: nowrap;
    min-height: 52px;
}
.club-btn.selected { border-color: var(--green); background: #e8f5e9; color: var(--green); }

.play-actions {
    display: grid;
    grid-template-columns: 2fr 1fr;
    gap: 0.6rem;
    margin-top: 0.6rem;
}
.play-actions .btn {
    font-size: 1.25rem;
    padding: 1rem;
    min-height: 58px;
    border-radius: 14px;
}

.hole-stats-row {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    margin-top: 0.6rem;
    padding: 0 0.25rem;
    flex-wrap: wrap;
}
.putts-control {
    display: flex;
    align-items: center;
    gap: 0.2rem;
}
.putts-control button {
    width: 38px; height: 38px;
    border-radius: 50%;
    border: 2px solid var(--border);
    background: white;
    font-size: 1.2rem;
    font-weight: 700;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
}
.putts-control .putts-val { font-size: 1.2rem; font-weight: 700; min-width: 1.1em; text-align: center; }

.fairway-toggle {
    display: flex;
    gap: 0.3rem;
}
.fairway-btn {
    padding: 0.4rem 0.6rem;
    border: 2px solid var(--border);
    border-radius: 10px;
    background: white;
    font-size: 0.85rem;
    font-weight: 600;
    cursor: pointer;
    min-height: 38px;
    display: flex;
    align-items: center;
}
.fairway-btn.active { border-color: var(--green); background: #e8f5e9; color: var(--green); }

.strokes-display {
    display: flex;
    align-items: center;
    gap: 0.3rem;
    font-size: 1.2rem;
    font-weight: 700;
    color: var(--text);
    padding: 0 0.2rem;
}
.strokes-display small {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-muted);
}

.club-btn.recommended {
    background: #c8e6c9;
    border-color: #66bb6a;
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.3);
}
.club-btn.recommended.selected {
    background: #a5d6a7;
    border-color: var(--green);
    color: var(--green-dark);
    box-shadow: 0 0 0 2px rgba(76, 175, 80, 0.4);
}

/* Scorecard table */
.scorecard { width: 100%; border-collapse: collapse; font-size: 0.8rem; }
.scorecard th, .scorecard td {
    padding: 0.4rem 0.3rem;
    text-align: center;
    border: 1px solid var(--border);
}
.scorecard th { background: var(--green); color: white; font-weight: 600; }
.scorecard .hole-num { font-weight: 600; }

/* Play scorecard overlay table */
.scorecard-table { width: 100%; border-collapse: collapse; font-size: 0.85rem; }
.scorecard-table th, .scorecard-table td { padding: 0.4rem 0.3rem; text-align: center; border-bottom: 1px solid var(--border); }
.scorecard-table th { font-size: 0.7rem; color: var(--text-muted); font-weight: 600; text-transform: uppercase; }
.scorecard-table .score-birdie { color: #d32f2f; font-weight: 700; }
.scorecard-table .score-par { color: var(--green); font-weight: 600; }
.scorecard-table .score-bogey { color: var(--blue); font-weight: 600; }
.scorecard-table .score-dbl { color: #333; font-weight: 700; }
.scorecard-table .score-eagle { color: #ff8f00; font-weight: 700; }
.scorecard-table .current-hole { background: #e8f5e9; }
.scorecard-table tfoot td { font-weight: 700; border-top: 2px solid var(--border); }
.edit-input { width: 3rem; padding: 0.3rem; text-align: center; border: 1px solid var(--border); border-radius: 4px; font-size: 0.85rem; }
.edit-select { padding: 0.3rem; border: 1px solid var(--border); border-radius: 4px; font-size: 0.85rem; }
.scorecard .front-nine { background: #f0f7f0; }

/* Nine tabs for scorecard (mobile) */
.nine-tabs {
    display: flex;
    gap: 0;
    margin-bottom: 0.5rem;
}
.nine-tab {
    flex: 1;
    padding: 0.5rem;
    text-align: center;
    font-size: 0.85rem;
    font-weight: 600;
    border: none;
    cursor: pointer;
    background: var(--border);
    color: var(--text-muted);
}
.nine-tab:first-child { border-radius: var(--radius) 0 0 var(--radius); }
.nine-tab:last-child { border-radius: 0 var(--radius) var(--radius) 0; }
.nine-tab.active { background: var(--green); color: white; }
.scorecard .back-nine { background: #f0f0f7; }

/* Leaderboard */
.leader-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0.75rem 0;
    border-bottom: 1px solid var(--border);
}
.leader-rank { font-size: 1.2rem; font-weight: 700; color: var(--green); width: 2rem; }
.leader-name { font-weight: 600; flex: 1; }
.leader-stats { text-align: right; font-size: 0.85rem; color: var(--text-muted); }

/* Course editor */
.editor-controls {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    z-index: 1000;
    background: white;
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 0.6rem;
    display: flex;
    gap: 0.5rem;
    align-items: center;
}
.editor-controls select, .editor-controls button {
    padding: 0.4rem 0.6rem;
    border-radius: 6px;
    border: 1px solid var(--border);
    font-size: 0.85rem;
}

/* Charts */
.chart-container { position: relative; height: 250px; margin-bottom: 1rem; }

/* Utilities */
.text-center { text-align: center; }
.text-sm { font-size: 0.85rem; }
.text-xs { font-size: 0.8rem; }
.text-xxs { font-size: 0.75rem; }
.text-bold { font-weight: 600; }
.text-muted { color: var(--text-muted); }
.text-green { color: var(--green); }
.link-back { font-size: 0.8rem; color: var(--green); text-decoration: none; }
.subtitle { color: var(--text-muted); font-size: 0.9rem; margin-bottom: 1rem; }
.mt-sm { margin-top: 0.5rem; }
.mt-1 { margin-top: 1rem; }
.mb-0 { margin-bottom: 0; }
.mb-sm { margin-bottom: 0.5rem; }
.mb-1 { margin-bottom: 1rem; }
.flex { display: flex; }
.flex-between { display: flex; justify-content: space-between; align-items: center; }
.flex-row { display: flex; gap: 0.5rem; }
.flex-col { display: flex; flex-direction: column; gap: 0.5rem; }
.flex-1 { flex: 1; }
.gap-1 { gap: 1rem; }
.inline { display: inline; }
.w-full { width: 100%; }
.overflow-x { overflow-x: auto; }

/* Stat mini (inline stat display) */
.stat-mini { text-align: center; }
.stat-mini-val { font-size: 1.1rem; font-weight: 700; }
.stat-mini-label { font-size: 0.7rem; color: var(--text-muted); }

/* Score badge circles (hole history) */
.score-badge {
    display: inline-flex; align-items: center; justify-content: center;
    width: 28px; height: 28px; border-radius: 50%;
    font-size: 0.8rem; font-weight: 600;
}
.score-badge-eagle { background: #fff3cd; color: #856404; }
.score-badge-birdie { background: #f8d7da; color: var(--red); }
.score-badge-par { background: #d4edda; color: var(--green); }
.score-badge-bogey { background: #d1ecf1; color: var(--blue); }
.score-badge-dbl { background: #e2e3e5; color: #333; }
/* Tee picker */
.tee-picker { display: flex; gap: 0.5rem; flex-wrap: wrap; }
.tee-dot {
    padding: 0.4rem 0.8rem;
    border-radius: 20px;
    border: 2px solid transparent;
    color: white;
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
    text-shadow: 0 1px 2px rgba(0,0,0,0.3);
}
.tee-dot.active { outline: 3px solid var(--green); outline-offset: 2px; }

/* Overlay safe areas */
.overlay-backdrop {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}
.overlay-backdrop-top {
    position: fixed;
    inset: 0;
    z-index: 2000;
    display: flex;
    align-items: flex-start;
    justify-content: center;
    padding-top: max(2rem, env(safe-area-inset-top));
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
    overflow-y: auto;
}

/* Bottom tab nav (non-play pages) */
.bottom-nav {
    display: none;
}
@media (max-width: 600px) {
    .bottom-nav {
        display: flex;
        position: fixed;
        bottom: 0;
        left: 0;
        right: 0;
        background: var(--card);
        border-top: 1px solid var(--border);
        z-index: 99;
        justify-content: space-around;
        padding: 0.4rem 0;
        padding-bottom: max(0.4rem, env(safe-area-inset-bottom));
        box-shadow: 0 -2px 8px rgba(0,0,0,0.06);
    }
    .bottom-nav a {
        display: flex;
        flex-direction: column;
        align-items: center;
        text-decoration: none;
        color: var(--text-muted);
        font-size: 0.65rem;
        font-weight: 600;
        padding: 0.25rem 0.5rem;
        gap: 0.15rem;
    }
    .bottom-nav a.active { color: var(--green); }
    .bottom-nav svg { width: 22px; height: 22px; }
    /* Add padding at bottom of main content so it doesn't hide behind nav */
    .container { padding-bottom: max(4.5rem, calc(4rem + env(safe-area-inset-bottom))); }
    /* Hide top nav links on mobile — bottom nav replaces them */
    .nav-links a:not(.nav-logout) { display: none; }
}

.hidden { display: none !important; }
