/* ==========================================================================
   PUTTING TRACKER — STYLESHEET
   Mobile-first design with a single breakpoint at 520px for tablet/desktop.
   No frameworks — vanilla CSS3 with custom properties for theming.
   ========================================================================== */

/* ── Theme Variables ──
   All colors are defined here for easy theming.
   Used throughout via var(--name). */
:root {
    --bg-color: #f4f7f6;           /* Page background (light gray) */
    --card-bg: #ffffff;             /* Container / modal backgrounds */
    --text-main: #2d3436;           /* Primary text (dark charcoal) */
    --text-muted: #636e72;          /* Secondary / label text (medium gray) */
    --accent-blue: #74b9ff;         /* Primary accent: active buttons, stat bars */
    --accent-blue-hover: #0984e3;   /* Darker accent: hover states, slider thumb */
    --border-color: #dfe6e9;        /* Borders, dividers, slider track */
}

/* ── Global Reset ──
   box-sizing: border-box for predictable sizing.
   Removes tap highlight on mobile webkit browsers.  */
* {
    box-sizing: border-box;
    -webkit-tap-highlight-color: transparent;
}

/* ── Base Typography & Page Setup ──
   System font stack for native look on all platforms.
   overscroll-behavior: none prevents pull-to-refresh / bounce effects. */
html, body {
    margin: 0;
    padding: 0;
    background-color: var(--bg-color);
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    color: var(--text-main);
    overscroll-behavior: none;
}

/* Center the container horizontally, align to top.
   -webkit-fill-available handles iOS Safari's dynamic viewport height. */
body {
    display: flex;
    justify-content: center;
    align-items: flex-start;
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

/* ── Main Container ──
   Full-bleed on mobile (no border-radius), card style on desktop.
   56px top padding accommodates the absolutely-positioned top buttons. */
.container {
    background: var(--card-bg);
    padding: 56px 16px 40px;
    text-align: center;
    width: 100%;
    max-width: 480px;
    position: relative;           /* Anchor for absolute-positioned child buttons */
    border-radius: 0;            /* Full-bleed on mobile */
    min-height: 100vh;
    min-height: -webkit-fill-available;
}

/* ==========================================================================
   TOP BAR BUTTONS
   Absolutely positioned in top corners of the container.
   ========================================================================== */

/* Unit toggle button (top-right): switches between Meters and Feet */
.unit-toggle {
    position: absolute;
    top: 12px;
    right: 12px;
    padding: 9px 14px;
    font-size: 12px;
    border-radius: 8px;
    background: var(--bg-color);
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    cursor: pointer;
    font-weight: 700;
    touch-action: manipulation;   /* Prevents double-tap zoom on mobile */
    min-height: 40px;
}

.unit-toggle:active { opacity: 0.7; }

/* Game mode button (top-left): circular button with gamepad emoji */
.game-toggle-btn {
    position: absolute;
    top: 12px;
    left: 12px;
    width: 40px;
    height: 40px;
    border-radius: 50%;           /* Perfect circle */
    border: 1px solid var(--border-color);
    background: var(--bg-color);
    font-size: 20px;
    display: flex;
    justify-content: center;
    align-items: center;
    cursor: pointer;
    padding: 0;
    touch-action: manipulation;
}

.game-toggle-btn:active { opacity: 0.7; }

/* ==========================================================================
   STATS HEADER
   Displays success % (left) and reps count (right) for the current distance.
   Updated dynamically by updateUI() in script.js.
   ========================================================================== */
.stats-header {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    margin-bottom: 12px;
    font-weight: 700;
    font-size: 15px;
}

/* Success percentage text color */
.bolt-percent { color: var(--accent-blue-hover); }
/* Reps count text color */
.reps-count   { color: var(--text-muted); }

/* ==========================================================================
   VISUAL DISTANCE DISPLAY
   Basket and player images with an animated gap that grows with distance.
   Gap is set via JS: imageContainer.style.gap = (distance * 10) + "px"
   ========================================================================== */
.images-wrapper {
    display: flex;
    justify-content: center;
    align-items: center;
    margin-bottom: 4px;
    transition: gap 0.3s ease-out; /* Smooth gap animation on distance change */
}

/* Responsive image height: min 90px, scales with viewport, max 150px */
.images-wrapper img {
    width: auto;
    height: clamp(90px, 22vw, 150px);
    object-fit: contain;
}

/* ── Distance Number Display ──
   Large, bold distance value (e.g., "10m" or "33ft").
   Responsive font size via clamp(). */
.distance-display {
    font-size: clamp(26px, 8vw, 34px);
    font-weight: 700;
    margin-bottom: 10px;
}

/* ==========================================================================
   DISTANCE SLIDER
   Custom-styled range input for distances 1-20m.
   Distances 21-35m require the arrow buttons.
   Cross-browser styling for WebKit and Firefox.
   ========================================================================== */
.slider-container { margin-bottom: 14px; }

/* Base slider: strip default appearance, 36px height for touch target */
input[type=range] {
    width: 100%;
    cursor: pointer;
    height: 36px;
    -webkit-appearance: none;
    appearance: none;
    background: transparent;
}

/* WebKit (Chrome, Safari, Edge) track styling */
input[type=range]::-webkit-slider-runnable-track {
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
}

/* WebKit thumb: 28px circle with shadow, offset to center on track */
input[type=range]::-webkit-slider-thumb {
    -webkit-appearance: none;
    appearance: none;
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-blue-hover);
    margin-top: -11px;            /* Center thumb on 6px track: -(28-6)/2 */
    cursor: pointer;
    box-shadow: 0 2px 6px rgba(0,0,0,0.2);
}

/* Firefox track styling */
input[type=range]::-moz-range-track {
    height: 6px;
    border-radius: 3px;
    background: var(--border-color);
}

/* Firefox thumb styling */
input[type=range]::-moz-range-thumb {
    width: 28px;
    height: 28px;
    border-radius: 50%;
    background: var(--accent-blue-hover);
    border: none;
    cursor: pointer;
}

/* ==========================================================================
   DISTANCE CONTROLS (Arrow buttons + Reset)
   Arranged in a horizontal row below the slider.
   ========================================================================== */
.controls {
    display: flex;
    justify-content: center;
    gap: 10px;
    margin-bottom: 14px;
}

/* Larger padding and min-height for easy tapping */
.controls button {
    padding: 12px 22px;
    font-size: 15px;
    min-height: 48px;
}

/* ── Horizontal Divider ── */
.divider { border: 0; border-top: 1px solid var(--border-color); margin: 14px 0; }

/* ==========================================================================
   INPUT GROUPS
   Vertically stacked label + control pairs used in both normal tracking
   and game setup modal.
   ========================================================================== */
.input-group-col {
    display: flex;
    flex-direction: column;
    align-items: center;
    margin-bottom: 14px;
}

/* Uppercase label styling for form fields */
.input-group-col label {
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 1px;
    color: var(--text-muted);
    margin-bottom: 10px;
}

/* ==========================================================================
   DISC COUNT BAR ("My Bag")
   Row of 10 equal-width buttons (1-10). Active button highlighted in blue.
   ========================================================================== */
.number-bar {
    display: flex;
    justify-content: center;
    gap: 4px;
    width: 100%;
}

/* Individual disc count button — flex:1 makes all equal width */
.num-btn {
    flex: 1;
    min-width: 0;                 /* Allow flex shrink below content size */
    padding: 13px 0;
    border: 1px solid var(--border-color);
    background: var(--card-bg);
    color: var(--text-main);
    border-radius: 8px;
    cursor: pointer;
    transition: background 0.15s;
    font-size: clamp(13px, 3.5vw, 15px); /* Responsive font for small screens */
    touch-action: manipulation;
    min-height: 46px;
}

/* Press feedback */
.num-btn:active { background: #e8f4ff; }
/* Selected/active state: blue background with white text */
.num-btn.active { background: var(--accent-blue); color: white; border-color: var(--accent-blue); }

/* ==========================================================================
   MISSED COUNTER
   Circular +/- buttons flanking a large number display.
   ========================================================================== */
.counter-group {
    display: flex;
    align-items: center;
    gap: 36px;                    /* Wide gap for easy tapping */
}

/* Circular +/- buttons */
.counter-btn {
    width: 56px;
    height: 56px;
    border-radius: 50%;
    font-size: 26px;
    padding: 0;
    display: flex;
    justify-content: center;
    align-items: center;
    touch-action: manipulation;
}

/* Large missed count display */
#missed-display {
    font-size: 30px;
    font-weight: 700;
    min-width: 36px;              /* Prevents layout shift between 0 and 10 */
}

/* ==========================================================================
   BASE BUTTON STYLES
   All <button> elements share these defaults. Specific button types
   (primary, secondary, game) override as needed.
   ========================================================================== */
button {
    background-color: var(--card-bg);
    border: 2px solid var(--border-color);
    color: var(--text-muted);
    padding: 10px 20px;
    font-size: 16px;
    font-weight: 600;
    border-radius: 10px;
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s, color 0.15s;
    touch-action: manipulation;
    min-height: 44px;             /* Minimum touch target (accessibility) */
}

/* Subtle press-down effect on all buttons */
button:active { transform: scale(0.95); }

/* ── Primary Call-to-Action Button ──
   Full-width blue button used for OK, modal confirm, etc. */
.btn-primary {
    width: 100%;
    padding: 16px;
    background-color: var(--accent-blue);
    color: white;
    border: none;
    font-size: 17px;
    margin-top: 8px;
    border-radius: 12px;
    min-height: 54px;
}

.btn-primary:active { background-color: var(--accent-blue-hover); }

/* ==========================================================================
   DATA SECTION (Download / Upload)
   Two side-by-side buttons for JSON export and import.
   ========================================================================== */
.data-section { display: flex; gap: 8px; }

/* Secondary button style — light background, used for download/upload */
.btn-secondary {
    flex: 1;
    padding: 14px 8px;
    font-size: 13px;
    color: var(--text-muted);
    border: 1px solid var(--border-color);
    border-radius: 10px;
    background: var(--bg-color);
    text-align: center;
    cursor: pointer;
    transition: background 0.15s;
    display: inline-flex;
    justify-content: center;
    align-items: center;
    touch-action: manipulation;
    min-height: 50px;
}

.btn-secondary:active { background: var(--border-color); }

/* ==========================================================================
   ABOUT SECTION
   Project info, feedback links, and donation QR code.
   ========================================================================== */
.about-section {
    margin-top: 20px;
    font-size: 13px;
    color: var(--text-muted);
    line-height: 1.5;
    text-align: left;
    background: var(--bg-color);
    padding: 14px;
    border-radius: 10px;
}

.about-section p { margin: 0 0 8px; }
.about-section p:last-child { margin: 0; }

/* ==========================================================================
   STATS SUMMARY BARS
   Per-distance bar chart rendered by renderStatsSummary() in script.js.
   Each row: [distance label] [colored bar] [percentage + count]
   ========================================================================== */
.stats-summary {
    margin: 10px 0;
    text-align: left;
    display: flex;
    flex-direction: column;
    gap: 10px;
}

/* Shown when no stats are logged yet */
.empty-stats {
    text-align: center;
    color: var(--text-muted);
    font-size: 14px;
    font-style: italic;
    margin: 10px 0;
}

/* Single stat row: horizontal layout with label, bar, and metadata */
.stat-row { display: flex; align-items: center; gap: 8px; }

/* Distance label (e.g., "6m") — fixed width for alignment */
.stat-label {
    width: 40px;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-main);
    text-align: right;
    flex-shrink: 0;
}

/* Bar background (gray track) */
.stat-bar-bg {
    flex: 1;
    height: 10px;
    background-color: var(--border-color);
    border-radius: 5px;
    overflow: hidden;
    min-width: 0;                 /* Allows flex shrink */
}

/* Bar fill (blue) — width set as inline style by JS (e.g., width: 80%) */
.stat-bar-fill {
    height: 100%;
    background-color: var(--accent-blue);
    border-radius: 5px;
    transition: width 0.4s ease-out; /* Smooth animation on stats update */
}

/* Right-side metadata container */
.stat-meta {
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    min-width: 45px;
    flex-shrink: 0;
}

/* Success percentage text (e.g., "80%") */
.stat-percent {
    width: auto;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-muted);
    line-height: 1.1;
}

/* Hit count text (e.g., "8/10") */
.stat-count {
    font-size: 10px;
    color: var(--text-muted);
    margin-top: -2px;
}

/* ==========================================================================
   MODALS
   Bottom-sheet style on mobile, centered card on desktop.
   Three modals: welcome, game setup, game over.
   ========================================================================== */

/* Overlay: covers viewport with semi-transparent backdrop + blur */
.modal-overlay {
    position: fixed;
    inset: 0;                     /* Shorthand for top/right/bottom/left: 0 */
    background-color: rgba(0, 0, 0, 0.45);
    display: flex;
    justify-content: center;
    align-items: flex-end;        /* Bottom-sheet positioning on mobile */
    z-index: 1000;
    backdrop-filter: blur(3px);
    opacity: 1;
    transition: opacity 0.25s ease;
    padding: 0;
}

/* Hidden state: fade out and disable pointer events */
.modal-overlay.hidden {
    opacity: 0;
    pointer-events: none;
}

/* Modal card: white panel with top-rounded corners (bottom-sheet) */
.modal-content {
    background: var(--card-bg);
    padding: 28px 20px 32px;
    padding-bottom: calc(32px + env(safe-area-inset-bottom, 0px)); /* Safe area for notched devices */
    border-radius: 20px 20px 0 0; /* Rounded top corners only (mobile) */
    width: 100%;
    max-width: 480px;
    text-align: center;
    box-shadow: 0 -6px 30px rgba(0, 0, 0, 0.15);
    max-height: 88vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch; /* Smooth scroll on iOS */
}

/* Drag-handle hint: small gray bar at top of modal (mobile only) */
.modal-content::before {
    content: '';
    display: block;
    width: 40px;
    height: 4px;
    background: var(--border-color);
    border-radius: 2px;
    margin: -12px auto 20px;
}

/* Modal heading: accent blue color with responsive size */
.modal-content h2 {
    margin-top: 0;
    color: var(--accent-blue-hover);
    font-size: clamp(18px, 5vw, 22px);
}

.modal-content p { color: var(--text-muted); line-height: 1.5; }

/* Instruction list in welcome modal */
.modal-instructions {
    text-align: left;
    color: var(--text-muted);
    font-size: 14px;
    line-height: 1.7;
    margin-bottom: 20px;
    padding-left: 18px;
}

/* ==========================================================================
   GAME MODE INPUT FIELDS & UTILITIES
   ========================================================================== */

/* Utility: hides elements (used to toggle sections between modes) */
.d-none { display: none !important; }

/* Styled number inputs for game setup modal */
.input-style {
    width: 100%;
    padding: 14px;
    border-radius: 10px;
    border: 1.5px solid var(--border-color);
    font-size: max(16px, 1em);   /* 16px minimum prevents iOS auto-zoom on focus */
    text-align: center;
    font-family: inherit;
    color: var(--text-main);
    background: var(--card-bg);
}

/* ==========================================================================
   GAME ACTIVE BANNER
   Blue banner displayed during an active game session.
   Contains throw progress, quit button, and miss/sink action buttons.
   ========================================================================== */
.game-banner {
    background-color: #0984e3;    /* Matches --accent-blue-hover */
    color: white;
    padding: 14px 16px;
    border-radius: 12px;
    margin-bottom: 14px;
    display: flex;
    flex-direction: column;
    gap: 10px;
    box-shadow: 0 4px 14px rgba(0, 0, 0, 0.15);
}

/* Top row: throw counter (left) and quit button (right) */
.game-banner-top {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
}

/* Throw counter text styling */
.game-banner span {
    font-weight: 700;
    font-size: 15px;
    opacity: 0.9;
}

/* Quit game button — slightly lighter blue with dark border */
.btn-quit {
    background: #2993e4;
    color: white;
    border: 1px solid #075a99;
    padding: 7px 14px;
    font-size: 13px;
    border-radius: 8px;
    cursor: pointer;
    font-weight: 700;
    min-height: 36px;
}

.btn-quit:active { opacity: 0.7; transform: scale(0.95); }

/* Bottom row: miss and sink buttons side by side */
.game-actions-inline {
    display: flex;
    gap: 10px;
    width: 100%;
}

/* Base game action button (Miss / Sink) */
.btn-game {
    flex: 1;
    padding: 15px 0;
    font-size: 16px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: #2d3436;
    border: none;
    border-radius: 10px;
    box-shadow: 0 3px 8px rgba(0,0,0,0.12);
    cursor: pointer;
    touch-action: manipulation;
    min-height: 54px;
    transition: filter 0.1s;
}

.btn-game:active { transform: scale(0.96); filter: brightness(0.9); }

/* Miss button: red */
.game-miss { background-color: #ff7675; }
.game-miss:active { background-color: #d63031; color: white; }
/* Sink button: green */
.game-sink { background-color: #55efc4; }
.game-sink:active { background-color: #00b894; }

/* ==========================================================================
   RESPONSIVE: TABLET / DESKTOP (min-width: 520px)
   Restores card-style container, centers modals, adds hover states.
   ========================================================================== */
@media (min-width: 520px) {
    /* Add page padding and keep background visible around card */
    body {
        padding: 24px 16px;
        background-color: var(--bg-color);
    }

    /* Card-style container with rounded corners and shadow */
    .container {
        border-radius: 20px;
        min-height: unset;         /* No longer full-viewport height */
        box-shadow: 0 10px 30px rgba(0, 0, 0, 0.07);
        padding: 52px 24px 28px;
    }

    /* Center modals instead of bottom-sheet */
    .modal-overlay {
        align-items: center;
        padding: 16px;
    }

    /* Fully rounded modal card */
    .modal-content {
        border-radius: 20px;
        padding: 28px 24px;
        max-height: 90vh;
    }

    /* Hide the drag-handle on desktop (not needed) */
    .modal-content::before { display: none; }

    /* Desktop hover states for buttons */
    button:hover {
        border-color: var(--accent-blue);
        color: var(--accent-blue-hover);
        background-color: #f0f8ff;
    }

    .btn-primary:hover { background-color: var(--accent-blue-hover); color: white; }
    .btn-secondary:hover { background: var(--border-color); color: var(--text-main); }
    .game-miss:hover { background-color: #d63031; color: white; border-color: transparent; }
    .game-sink:hover { background-color: #00b894; border-color: transparent; }
}

/* ── Support QR Code ──
   Centered image with max-width to prevent oversizing on large screens */
.support-qr {
    display: block;
    margin: 0 auto;
    margin-top: 12px;
    max-width: 150px;
}
