:root {
    --primary-color: #2563eb;
    --primary-hover: #1d4ed8;
    --bg-color: #f8fafc;
    --card-bg: #ffffff;
    --text-main: #1e293b;
    --text-secondary: #64748b;
    --border-color: #e2e8f0;
}

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

.centered-points {
    text-align: center;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    background-color: var(--bg-color);
    color: var(--text-main);
    padding: 2rem 1rem;
    line-height: 1.6;
}

header {
    text-align: center;
    margin-bottom: 2rem;
}

header.app-header {
    text-align: left;
}

/* Page Title inside container */
.page-title-container {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.page-icon {
    width: 28px;
    height: 28px;
    order: 1; /* Move icon to the right of title */
    border-radius: 6px;
    object-fit: cover;
}

.page-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-color);
    margin: 0;
}

/* Mode Toggle */
.mode-toggle {
    display: inline-flex;
    gap: 0;
    margin-bottom: 1.5rem;
    background: #e5e7eb;
    border-radius: 6px;
    padding: 3px;
}

.mode-btn {
    padding: 0.5rem 1rem;
    text-align: center;
    text-decoration: none;
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    background: transparent;
    border-radius: 4px;
    transition: all 0.2s ease;
}

.mode-btn.active {
    background: white;
    color: var(--primary-color);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.1);
}

.mode-btn:not(.active):hover {
    color: var(--text-main);
}

.calculate-title {
    font-size: 1.5rem;
    font-weight: 700;
    color: var(--text-main);
}

main {
    max-width: 800px;
    margin: 0 auto;
}

.container-fluid {
    position: relative;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    padding: 2rem;
}

/* Hamburger button inside container */
.container-fluid .hamburger-btn {
    position: absolute;
    top: 0.75rem;
    left: 0.75rem;
}

table {
    width: 100%;
    border-collapse: collapse;
}

.counter-header {
    font-weight: 600;
    padding: 0.75rem;
    text-align: left;
    border-bottom: 2px solid var(--border-color);
}

tr {
    border-bottom: 1px solid var(--border-color);
}

tr:last-child {
    border-bottom: none;
}

td {
    padding: 0.75rem;
}

.counter-input-results,
.counter-input-pts {
    width: 100%;
    padding: 0.5rem;
    border: 1px solid var(--border-color);
    border-radius: 6px;
    font-size: 1rem;
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
    font-variant-numeric: tabular-nums;
}

.counter-input-results:focus {
    outline: none;
    border-color: var(--primary-color);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.1);
}

.counter-input-pts {
    background-color: #f8fafc;
    font-weight: 600;
    color: var(--primary-color);
    text-align: center;
}

.counter-after {
    color: var(--text-secondary);
    font-size: 0.875rem;
    padding-left: 0.5rem;
    text-align: center;
    border: none !important;
    background: transparent !important;
    font-variant-numeric: tabular-nums;
}

/* Column width constraints */
/* Column 1: Event name */
td:nth-child(1) {
    width: 70px;
    max-width: 70px;
}

/* Column 2: Result */
td:nth-child(2) {
    width: 65px;
    max-width: 65px;
}

/* Column 3: Points (Pts) - only needs 4 digits */
td:nth-child(3) {
    width: 50px;
    max-width: 50px;
}

/* Column 4: 1 point reference */
td:nth-child(4) {
    width: 60px;
    max-width: 60px;
}

/* Reverse calculator: swap Pts and Result column widths */
/* In *res.html: Col 2 = Pts (narrow), Col 3 = Min Result (wider) */
.reverse-calc td:nth-child(2) {
    width: 50px;
    max-width: 50px;
}

.reverse-calc td:nth-child(3) {
    width: 65px;
    max-width: 65px;
}

/* Summary Container */
.summary-container {
    margin-top: 1rem;
}

.summary-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-color);
    margin: 0 0 1rem 0;
    text-align: center;
}

.summary-section {
    margin-bottom: 1rem;
}

.summary-section:last-child {
    margin-bottom: 0;
}

.summary-section-title {
    font-size: 0.85rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin: 0 0 0.5rem 0;
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

/* Bar Chart */
.chart-container {
    display: flex;
    justify-content: center;
    gap: 1rem;
    height: 150px;
    align-items: flex-end;
    padding: 0 1rem;
}

.bar-wrapper {
    display: flex;
    flex-direction: column;
    align-items: center;
    flex: 1;
    max-width: 80px;
    height: 100%;
}

.bar {
    width: 100%;
    height: 0%;
    background: linear-gradient(180deg, var(--primary-color) 0%, #60a5fa 100%);
    border-radius: 6px 6px 0 0;
    transition: height 0.4s ease-out;
    margin-top: auto;
    min-height: 4px;
}

.bar-sprint { background: linear-gradient(180deg, #3b82f6 0%, #60a5fa 100%); }
.bar-jump { background: linear-gradient(180deg, #10b981 0%, #34d399 100%); }
.bar-throw { background: linear-gradient(180deg, #f59e0b 0%, #fbbf24 100%); }
.bar-distance { background: linear-gradient(180deg, #8b5cf6 0%, #a78bfa 100%); }

/* Sort toggle for event chart */
.sort-toggle {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.sort-toggle button {
    padding: 0.35rem 0.75rem;
    font-size: 0.7rem;
    font-weight: 600;
    border: 1px solid var(--border-color);
    border-radius: 4px;
    background: #f8fafc;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.sort-toggle button.active {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.sort-toggle button:hover:not(.active) {
    background: #e2e8f0;
}

/* Horizontal bar chart for events */
.hbar-container {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.hbar-row {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    height: 28px;
}

.hbar-label {
    width: 55px;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--text-main);
    text-align: right;
    flex-shrink: 0;
}

.hbar-track {
    flex: 1;
    height: 20px;
    background: #e5e7eb;
    border-radius: 4px;
    overflow: hidden;
    position: relative;
}

.hbar-fill {
    height: 100%;
    width: 0%;
    background: linear-gradient(90deg, var(--primary-color) 0%, #60a5fa 100%);
    border-radius: 4px;
    transition: width 0.4s ease-out;
}

.hbar-fill.bar-sprint { background: linear-gradient(90deg, #3b82f6 0%, #60a5fa 100%); }
.hbar-fill.bar-jump { background: linear-gradient(90deg, #10b981 0%, #34d399 100%); }
.hbar-fill.bar-throw { background: linear-gradient(90deg, #f59e0b 0%, #fbbf24 100%); }
.hbar-fill.bar-distance { background: linear-gradient(90deg, #8b5cf6 0%, #a78bfa 100%); }

.hbar-value {
    width: 45px;
    font-size: 0.8rem;
    font-weight: 700;
    color: var(--text-main);
    text-align: left;
    flex-shrink: 0;
}

.bar-value {
    font-size: 0.9rem;
    font-weight: 700;
    color: var(--text-color);
    margin-top: 0.5rem;
}

.bar-label {
    font-size: 0.7rem;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

@media (max-width: 480px) {
    body {
        padding: 0.5rem;
    }

    .container-fluid {
        padding: 0.5rem;
    }

    .page-title {
        font-size: 1rem;
    }

    /* Column 1: Event name - extra compact */
    td:first-child {
        width: 45px;
        max-width: 45px;
        font-size: 0.75rem;
    }

    /* Column 2: Result */
    td:nth-child(2) {
        width: 55px;
        max-width: 55px;
    }

    /* Column 3: Points (Pts) */
    td:nth-child(3) {
        width: 40px;
        max-width: 40px;
    }

    /* Column 4: 1pt reference */
    td:nth-child(4) {
        width: 50px;
        max-width: 50px;
    }

    /* Reverse calculator: swap Pts and Result widths */
    .reverse-calc td:nth-child(2) {
        width: 40px;
        max-width: 40px;
    }

    .reverse-calc td:nth-child(3) {
        width: 55px;
        max-width: 55px;
    }

    .counter-input-results,
    .counter-input-pts {
        padding: 0.3rem;
        font-size: 0.8rem;
    }

    .counter-after {
        font-size: 0.7rem;
        padding-left: 0.25rem;
    }

    .chart-container {
        gap: 0.35rem;
        height: 80px;
    }

    .bar-wrapper {
        max-width: 45px;
    }

    .bar-value {
        font-size: 0.65rem;
    }

    .bar-label {
        font-size: 0.55rem;
    }

    .hbar-label {
        width: 45px;
        font-size: 0.65rem;
    }

    .hbar-track {
        height: 14px;
    }

    .hbar-value {
        width: 35px;
        font-size: 0.7rem;
    }
}

.button-container {
    display: flex;
    gap: 1rem;
    margin-top: 1.5rem;
    justify-content: center;
}

.counter-input-button {
    padding: 0.75rem 2rem;
    font-size: 1rem;
    font-weight: 600;
    border: none;
    border-radius: 8px;
    cursor: pointer;
    transition: all 0.2s;
}

#calculate_btn {
    background-color: var(--primary-color);
    color: white;
}

#calculate_btn:hover {
    background-color: var(--primary-hover);
}

#reset_btn {
    background-color: #e5e7eb;
    color: var(--text-main);
}

#reset_btn:hover {
    background-color: #d1d5db;
}

/* App Header with Hamburger */
.app-header {
    display: flex;
    align-items: center;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.hamburger-btn {
    background: none;
    border: none;
    cursor: pointer;
    padding: 0.5rem;
    display: flex;
    flex-direction: column;
    gap: 5px;
    border-radius: 8px;
    transition: background 0.2s;
}

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

.hamburger-btn span {
    display: block;
    width: 24px;
    height: 3px;
    background: var(--text-main);
    border-radius: 2px;
    transition: all 0.3s;
}

.app-header .calculate-title {
    margin: 0;
    flex: 1;
}

/* Slide-out Menu */
.nav-overlay {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s;
    z-index: 999;
}

.nav-overlay.open {
    opacity: 1;
    visibility: visible;
}

.nav-menu {
    position: fixed;
    top: 0;
    left: -280px;
    width: 280px;
    height: 100%;
    background: var(--card-bg);
    box-shadow: 2px 0 10px rgba(0,0,0,0.1);
    transition: left 0.3s ease;
    z-index: 1000;
    overflow-y: auto;
}

.nav-menu.open {
    left: 0;
}

.nav-menu-header {
    position: relative;
    padding: 1.5rem;
    background: var(--primary-color);
    color: white;
}

.nav-menu-header h2 {
    font-size: 1.25rem;
    margin: 0;
}

.nav-menu-header p {
    font-size: 0.85rem;
    opacity: 0.8;
    margin: 0.25rem 0 0;
}

.nav-menu-items {
    padding: 1rem 0;
}

.nav-menu-item {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1rem 1.5rem;
    text-decoration: none;
    color: var(--text-main);
    transition: background 0.2s;
}

.nav-menu-item:hover {
    background: var(--bg-color);
}

.nav-menu-item.active {
    background: rgba(37, 99, 235, 0.1);
    color: var(--primary-color);
    border-left: 3px solid var(--primary-color);
}

.nav-menu-item .nav-icon {
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.85rem;
    font-weight: 700;
    background: var(--bg-color);
    color: var(--text-secondary);
    border: 2px solid var(--border-color);
}

.nav-menu-item.active .nav-icon {
    background: var(--primary-color);
    color: white;
    border-color: var(--primary-color);
}

.nav-menu-item .nav-icon.home-icon {
    font-size: 1.25rem;
    background: none;
    border: none;
}

.nav-menu-item .nav-text {
    flex: 1;
}

.nav-menu-item .nav-text strong {
    display: block;
    font-weight: 600;
}

.nav-menu-item .nav-text span {
    font-size: 0.8rem;
    color: var(--text-secondary);
}

.nav-divider {
    height: 1px;
    background: var(--border-color);
    margin: 0.5rem 1.5rem;
}

.close-btn {
    position: absolute;
    top: 1rem;
    right: 1rem;
    background: rgba(255,255,255,0.2);
    border: none;
    color: white;
    width: 32px;
    height: 32px;
    border-radius: 50%;
    cursor: pointer;
    font-size: 1.25rem;
    display: flex;
    align-items: center;
    justify-content: center;
}

.close-btn:hover {
    background: rgba(255,255,255,0.3);
}

@media (max-width: 768px) {
    body {
        padding: 1rem 0.5rem;
    }

    .calculate-title {
        font-size: 1.1rem;
    }

    .container-fluid {
        padding: 0.75rem;
        border-radius: 8px;
    }

    .page-title-container {
        margin-bottom: 0.5rem;
        gap: 0.5rem;
    }

    .page-icon {
        width: 24px;
        height: 24px;
    }

    .page-title {
        font-size: 1.1rem;
    }

    /* Compact mode toggle */
    .mode-toggle {
        padding: 2px;
        border-radius: 5px;
        margin-bottom: 0.75rem;
    }

    .mode-btn {
        padding: 0.4rem 0.75rem;
        font-size: 0.8rem;
    }

    /* Compact table */
    td {
        padding: 0.35rem 0.25rem;
    }

    /* Column 1: Event name */
    td:first-child {
        width: 50px;
        max-width: 50px;
        font-size: 0.85rem;
        padding-left: 0.5rem;
    }

    /* Column 2: Result */
    td:nth-child(2) {
        width: 60px;
        max-width: 60px;
    }

    /* Column 3: Points (Pts) - compact for 4 digits */
    td:nth-child(3) {
        width: 45px;
        max-width: 45px;
    }

    /* Column 4: 1pt reference - now visible on mobile */
    td:nth-child(4) {
        width: 55px;
        max-width: 55px;
    }

    /* Reverse calculator: swap Pts and Result widths */
    .reverse-calc td:nth-child(2) {
        width: 45px;
        max-width: 45px;
    }

    .reverse-calc td:nth-child(3) {
        width: 60px;
        max-width: 60px;
    }

    .counter-header {
        padding: 0.5rem 0.25rem;
        font-size: 0.75rem;
    }

    .counter-input-results,
    .counter-input-pts {
        padding: 0.35rem;
        font-size: 0.85rem;
    }

    .counter-after {
        font-size: 0.75rem;
        padding-left: 0.5rem;
    }

    /* Compact total row */
    .total-row td {
        padding: 0.5rem 0.25rem;
    }

    /* Compact button */
    .button-container {
        margin-top: 1rem;
    }

    .counter-input-button {
        padding: 0.6rem 1.5rem;
        font-size: 0.9rem;
    }

    /* Compact summary sections */
    .summary-container {
        padding: 0.75rem;
        margin-top: 0.75rem;
    }

    .summary-title {
        font-size: 1rem;
        margin-bottom: 0.75rem;
    }

    .summary-section {
        margin-bottom: 1rem;
    }

    .summary-section-title {
        font-size: 0.75rem;
        margin-bottom: 0.5rem;
    }

    /* Compact horizontal bars */
    .hbar-row {
        height: 24px;
    }

    .hbar-label {
        width: 50px;
        font-size: 0.7rem;
    }

    .hbar-track {
        height: 16px;
    }

    .hbar-value {
        width: 40px;
        font-size: 0.75rem;
    }

    .sort-toggle {
        margin-bottom: 0.5rem;
    }

    .sort-toggle button {
        padding: 0.25rem 0.5rem;
        font-size: 0.65rem;
    }

    /* Compact vertical bars */
    .chart-container {
        height: 100px;
        gap: 0.5rem;
    }

    .bar-wrapper {
        max-width: 50px;
    }

    .bar-value {
        font-size: 0.7rem;
        margin-top: 0.25rem;
    }

    .bar-label {
        font-size: 0.6rem;
    }
}

/* ========================================
   Reference Table Styles
   ======================================== */

.reference-container {
    margin-top: 1rem;
    background: var(--card-bg);
    border-radius: 12px;
    box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1);
    padding: 1rem;
}

.reference-title {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-main);
    margin-bottom: 0.25rem;
    text-align: center;
}

.reference-subtitle {
    font-size: 0.8rem;
    color: var(--text-secondary);
    text-align: center;
    margin: 0 0 0.75rem 0;
}

.reference-controls {
    display: flex;
    justify-content: center;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.step-toggle {
    display: flex;
    background: #e5e7eb;
    border-radius: 6px;
    padding: 3px;
}

.step-toggle button {
    padding: 0.4rem 0.75rem;
    font-size: 0.8rem;
    font-weight: 600;
    border: none;
    border-radius: 4px;
    background: transparent;
    color: var(--text-secondary);
    cursor: pointer;
    transition: all 0.2s;
}

.step-toggle button.active {
    background: var(--primary-color);
    color: white;
}

.reference-table-wrapper {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.reference-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.75rem;
    min-width: 500px;
}

.reference-table th,
.reference-table td {
    padding: 0.35rem 0.25rem;
    text-align: center;
    border-bottom: 1px solid var(--border-color);
    white-space: nowrap;
}

.reference-table th {
    background: #f8fafc;
    font-weight: 600;
    font-size: 0.7rem;
    color: var(--text-secondary);
    position: sticky;
    top: 0;
    z-index: 1;
}

.reference-table th:first-child {
    text-align: right;
    font-weight: 600;
    color: var(--primary-color);
    background: #f8fafc;
    position: sticky;
    left: 0;
    z-index: 2;
}

.reference-table td:first-child {
    text-align: right;
    font-weight: 600;
    color: var(--primary-color);
    position: sticky;
    left: 0;
    z-index: 2;
}

.reference-table tbody tr:nth-child(even) td:first-child {
    background: #f8fafc;
}

.reference-table tbody tr:nth-child(odd) td:first-child {
    background: #ffffff;
}

.reference-table tbody tr:hover td:first-child {
    background: rgba(37, 99, 235, 0.1);
}

.reference-table th:first-child {
    z-index: 3;
}

.reference-table tbody tr:nth-child(even) {
    background: #f8fafc;
}

.reference-table tbody tr:nth-child(odd) {
    background: #ffffff;
}

.reference-table tbody tr:hover {
    background: rgba(37, 99, 235, 0.1);
}

.reference-table td {
    font-family: "Segoe UI", Roboto, Arial, sans-serif;
    font-variant-numeric: tabular-nums;
    color: var(--text-main);
}

.reference-loading {
    text-align: center;
    padding: 2rem;
    color: var(--text-secondary);
}

.reference-loading::after {
    content: '';
    display: inline-block;
    width: 16px;
    height: 16px;
    margin-left: 0.5rem;
    border: 2px solid var(--border-color);
    border-top-color: var(--primary-color);
    border-radius: 50%;
    animation: spin 1s linear infinite;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* Mobile adjustments for reference table */
@media (max-width: 768px) {
    .reference-container {
        padding: 0.75rem;
    }

    .reference-title {
        font-size: 1rem;
    }

    .step-toggle button {
        padding: 0.35rem 0.6rem;
        font-size: 0.75rem;
    }

    .reference-table {
        font-size: 0.7rem;
    }

    .reference-table th,
    .reference-table td {
        padding: 0.3rem 0.2rem;
    }

    .reference-table th {
        font-size: 0.65rem;
    }
}

@media (max-width: 480px) {
    .reference-container {
        padding: 0.5rem;
    }

    .reference-table {
        font-size: 0.65rem;
    }

    .reference-table th,
    .reference-table td {
        padding: 0.25rem 0.15rem;
    }
}