:root {
    --color-primary: #2563eb;
    --color-secondary: #64748b;
    --color-success: #10b981;
    --color-danger: #ef4444;
    --color-warning: #f59e0b;
    --color-info: #3b82f6;

    --camp-east-anglia: #3B82F6;
    --camp-mercia: #EF4444;
    --camp-northumbria: #10B981;
    --camp-wessex: #F59E0B;

    --bg-primary: #ffffff;
    --bg-secondary: #f8fafc;
    --bg-dark: #1e293b;

    --text-primary: #0f172a;
    --text-secondary: #64748b;
    --text-inverse: #ffffff;

    --border-color: #e2e8f0;
    --shadow-sm: 0 1px 2px 0 rgba(0, 0, 0, 0.05);
    --shadow-md: 0 4px 6px -1px rgba(0, 0, 0, 0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0, 0, 0, 0.1);

    --border-radius: 8px;
    --transition: all 0.3s ease;
}

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

html {
    /* Smooth scrolling */
    scroll-behavior: smooth;
    /* Prevent horizontal overflow */
    overflow-x: hidden;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, Cantarell, sans-serif;
    color: var(--text-primary);
    background-color: var(--bg-secondary);
    line-height: 1.6;
    /* Prevent horizontal overflow */
    overflow-x: hidden;
    /* Better font rendering on mobile */
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    /* Prevent text size adjustment on iOS */
    -webkit-text-size-adjust: 100%;
}

.container {
    max-width: 1400px;
    margin: 0 auto;
    padding: 0 20px;
}

.header {
    background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
    color: var(--text-inverse);
    padding: 2rem 0;
    box-shadow: var(--shadow-md);
}

.header__title {
    font-size: 2.5rem;
    font-weight: 700;
    margin-bottom: 0.5rem;
}

.header__subtitle {
    font-size: 1.1rem;
    opacity: 0.9;
}

.section-title {
    font-size: 1.8rem;
    font-weight: 600;
    margin-bottom: 1.5rem;
    color: var(--text-primary);
}

.global-stats {
    padding: 2rem 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

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

.filters {
    padding: 2rem 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.filters__grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 1rem;
    align-items: end;
}

.filter-group {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.filter-group label {
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.filter-input,
.filter-select {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    transition: var(--transition);
}

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

.btn {
    padding: 0.75rem 1.5rem;
    border: none;
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.btn-primary {
    background: var(--color-primary);
    color: var(--text-inverse);
}

.btn-primary:hover {
    background: #1d4ed8;
}

.btn-secondary {
    background: var(--color-secondary);
    color: var(--text-inverse);
}

.btn-secondary:hover {
    background: #475569;
}

.charts {
    padding: 3rem 0;
    background: var(--bg-secondary);
}

.charts-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(400px, 1fr));
    gap: 2rem;
}

.data-table {
    padding: 3rem 0;
    background: var(--bg-primary);
}

.loading {
    position: fixed;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(0, 0, 0, 0.5);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 9999;
}

.spinner {
    width: 50px;
    height: 50px;
    border: 4px solid rgba(255, 255, 255, 0.3);
    border-top-color: white;
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

.modal {
    display: none;
    position: fixed;
    z-index: 1000;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    overflow: auto;
    /* Smooth scrolling on mobile */
    -webkit-overflow-scrolling: touch;
}

.modal-content {
    background-color: var(--bg-primary);
    margin: 5% auto;
    padding: 2rem;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 800px;
    box-shadow: var(--shadow-lg);
}

.modal-close {
    color: var(--text-secondary);
    float: right;
    font-size: 28px;
    font-weight: bold;
    cursor: pointer;
    transition: var(--transition);
}

.modal-close:hover {
    color: var(--text-primary);
}

/* Floating Action Buttons */
.floating-actions {
    position: fixed;
    bottom: 2rem;
    left: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1rem;
    z-index: 100;
}

.floating-btn {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
    color: var(--text-inverse);
    border: none;
    border-radius: 50px;
    font-size: 1rem;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

.floating-btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(0, 0, 0, 0.4);
}

.floating-btn svg {
    width: 24px;
    height: 24px;
}

.floating-btn-search {
    background: #10b981;
}

.floating-btn-search:hover {
    background: #059669;
}

.floating-btn-filter {
    background: var(--color-primary);
}

.floating-btn-filter:hover {
    background: #1d4ed8;
}

.floating-btn-compare {
    background: #f97316;
}

.floating-btn-compare:hover {
    background: #ea580c;
}

/* Filter Modal */
.filter-modal {
    display: none;
    position: fixed;
    z-index: 1001;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    background-color: rgba(0, 0, 0, 0.6);
    overflow: auto;
    /* Smooth scrolling on mobile */
    -webkit-overflow-scrolling: touch;
}

.filter-modal-content {
    background-color: var(--bg-primary);
    margin: 5% auto;
    border-radius: var(--border-radius);
    width: 90%;
    max-width: 600px;
    box-shadow: var(--shadow-lg);
}

.filter-modal-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 1.5rem;
    border-bottom: 1px solid var(--border-color);
}

.filter-modal-header h2 {
    margin: 0;
    font-size: 1.5rem;
    color: var(--text-primary);
}

.filter-modal-close {
    background: none;
    border: none;
    font-size: 28px;
    font-weight: bold;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
}

.filter-modal-close:hover {
    color: var(--text-primary);
}

.filter-modal-body {
    padding: 2rem;
    display: flex;
    flex-direction: column;
    gap: 1.5rem;
}

.filter-modal-actions {
    display: flex;
    gap: 1rem;
    justify-content: flex-end;
    margin-top: 1rem;
}

/* Camp Button Filters */
.camp-filters-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 0.75rem;
}

.camp-btn {
    padding: 1rem;
    border: 2px solid transparent;
    border-radius: var(--border-radius);
    font-size: 0.95rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.3s ease;
    color: white;
    position: relative;
    overflow: hidden;
}

.camp-btn::before {
    content: '';
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    background: rgba(255, 255, 255, 0.2);
    opacity: 0;
    transition: opacity 0.3s ease;
}

.camp-btn:hover::before {
    opacity: 1;
}

.camp-btn::after {
    content: '';
    position: absolute;
    top: 0.5rem;
    right: 0.5rem;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    opacity: 0;
    transform: scale(0);
    transition: all 0.3s ease;
}

.camp-btn.active::after {
    content: '✓';
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 14px;
    font-weight: bold;
    color: var(--color-success);
    opacity: 1;
    transform: scale(1);
}

.camp-btn.east-anglia {
    background: var(--camp-east-anglia);
}

.camp-btn.mercia {
    background: var(--camp-mercia);
}

.camp-btn.northumbria {
    background: var(--camp-northumbria);
}

.camp-btn.wessex {
    background: var(--camp-wessex);
}

.camp-btn.active {
    border-color: white;
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.3);
}

/* Filtered Stats Cards */
.filtered-stats {
    padding: 1.5rem 0;
    background: var(--bg-primary);
    border-bottom: 1px solid var(--border-color);
}

.filtered-stats-grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 1rem;
}

.filtered-stat-card {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    padding: 1rem;
    box-shadow: var(--shadow-md);
    border-left: 4px solid var(--color-primary);
    transition: var(--transition);
    display: flex;
    align-items: center;
    gap: 1rem;
}

.filtered-stat-card:hover {
    transform: translateY(-2px);
    box-shadow: var(--shadow-lg);
}

.filtered-stat-card__icon {
    font-size: 2rem;
    line-height: 1;
}

.filtered-stat-card__content {
    flex: 1;
}

.filtered-stat-card__label {
    font-size: 0.75rem;
    color: var(--text-secondary);
    margin-bottom: 0.25rem;
    text-transform: uppercase;
    font-weight: 600;
}

.filtered-stat-card__value {
    font-size: 1.5rem;
    font-weight: 700;
}

/* Search Modal */
.search-modal-content {
    max-width: 500px;
}

.search-input-field {
    font-size: 1.1rem;
    padding: 1rem;
}

.search-hint {
    font-size: 0.85rem;
    color: var(--text-secondary);
    margin-top: 0.5rem;
    font-style: italic;
}

/* Compare Modal */
.compare-modal-content {
    max-width: 900px;
    max-height: 90vh;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.compare-selected-container {
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-bottom: 1.5rem;
}

.compare-selected-label {
    font-size: 0.875rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-bottom: 0.75rem;
}

.compare-selected-list {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem;
    min-height: 40px;
}

.compare-chip {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    background: white;
    border: 2px solid var(--border-color);
    border-radius: 20px;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    font-weight: 500;
    transition: var(--transition);
}

.compare-chip.camp-chip {
    border-color: var(--color-primary);
    background: rgba(37, 99, 235, 0.1);
}

.compare-chip.kingdom-chip {
    border-color: var(--color-success);
    background: rgba(16, 185, 129, 0.1);
}

.compare-chip-remove {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 1.2rem;
    line-height: 1;
    cursor: pointer;
    padding: 0;
    margin-left: 0.25rem;
    transition: var(--transition);
}

.compare-chip-remove:hover {
    color: var(--color-danger);
}

.compare-header-actions {
    display: flex;
    align-items: center;
    gap: 1rem;
}

/* Compare Results Container */
#compare-results-container {
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

/* Compare Results Table */
.compare-results-table {
    width: 100%;
    border-collapse: collapse;
    margin-bottom: 1.5rem;
    min-width: 600px;
}

.compare-results-table thead {
    background: var(--bg-secondary);
}

.compare-results-table th {
    padding: 1rem;
    text-align: left;
    font-weight: 600;
    color: var(--text-primary);
    border-bottom: 2px solid var(--border-color);
}

.compare-results-table td {
    padding: 1rem;
    border-bottom: 1px solid var(--border-color);
}

.compare-results-table tbody tr:hover {
    background: var(--bg-secondary);
}

.compare-item-name {
    font-weight: 600;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.compare-item-type {
    display: inline-block;
    font-size: 0.75rem;
    padding: 0.25rem 0.5rem;
    border-radius: 4px;
    font-weight: 500;
}

.compare-item-type.camp {
    background: rgba(37, 99, 235, 0.1);
    color: var(--color-primary);
}

.compare-item-type.kingdom {
    background: rgba(16, 185, 129, 0.1);
    color: var(--color-success);
}

.compare-value {
    font-weight: 600;
    font-size: 1rem;
}

.compare-winner {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
    font-weight: 700;
    position: relative;
}

.compare-winner .compare-value::before {
    content: '👑 ';
    margin-right: 0.25rem;
}

/* Compare Results Cards (Mobile) */
.compare-results-cards {
    display: none;
}

.compare-metric-card {
    background: var(--bg-primary);
    border-radius: var(--border-radius);
    padding: 1rem;
    margin-bottom: 1rem;
    box-shadow: var(--shadow-md);
}

.compare-metric-card__header {
    font-size: 1.1rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    padding-bottom: 0.5rem;
    border-bottom: 2px solid var(--border-color);
}

.compare-metric-card__item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 0.75rem;
    margin-bottom: 0.5rem;
    border-radius: var(--border-radius);
    background: var(--bg-secondary);
}

.compare-metric-card__item.winner {
    background: linear-gradient(135deg, #fef3c7 0%, #fde68a 100%);
}

.compare-metric-card__item-name {
    font-weight: 500;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.compare-metric-card__item-value {
    font-weight: 700;
    font-size: 1.1rem;
}

.compare-metric-card__item.winner .compare-metric-card__item-value::before {
    content: '👑 ';
    margin-right: 0.25rem;
}

/* Category Breakdown Section */
.category-breakdown-section {
    margin-top: 2rem;
    padding-top: 2rem;
    border-top: 2px solid var(--border-color);
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
}

.category-breakdown-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
}

.category-breakdown-table {
    min-width: 800px;
}

.category-breakdown-table th {
    font-size: 0.875rem;
    white-space: nowrap;
    padding: 0.875rem 0.75rem;
}

.category-breakdown-table td {
    text-align: center;
    padding: 0.875rem 0.75rem;
}

.category-breakdown-table td:first-child {
    text-align: left;
}

.category-breakdown-vertical .category-label {
    font-weight: 600;
    text-align: left;
}

.category-breakdown-vertical .category-icon {
    margin-right: 0.5rem;
}

.category-breakdown-vertical .total-row {
    border-top: 2px solid var(--border-color);
    font-weight: 700;
}

.category-breakdown-vertical .total-row td {
    padding-top: 1rem;
}

.category-cards {
    margin-top: 2rem;
}

.category-cards-title {
    font-size: 1.3rem;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 1rem;
    text-align: center;
}

/* Threshold Configuration */
.threshold-config-label {
    display: flex;
    justify-content: space-between;
    align-items: center;
    width: 100%;
    font-size: 0.875rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.threshold-toggle-btn {
    background: var(--color-primary);
    color: white;
    border: none;
    padding: 0.5rem 1rem;
    border-radius: var(--border-radius);
    font-size: 0.85rem;
    font-weight: 500;
    cursor: pointer;
    transition: var(--transition);
}

.threshold-toggle-btn:hover {
    background: #1d4ed8;
}

.threshold-config {
    margin-top: 1rem;
    padding: 1rem;
    background: var(--bg-secondary);
    border-radius: var(--border-radius);
    border: 1px solid var(--border-color);
}

.threshold-grid {
    display: grid;
    grid-template-columns: repeat(2, 1fr);
    gap: 1rem;
}

.threshold-grid .threshold-input-group:last-child {
    grid-column: span 2;
}

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

.threshold-input-group label {
    font-size: 0.8rem;
    font-weight: 500;
    color: var(--text-secondary);
}

.threshold-input-group input {
    padding: 0.75rem;
    border: 1px solid var(--border-color);
    border-radius: var(--border-radius);
    font-size: 0.95rem;
}

.threshold-hint {
    font-size: 0.75rem;
    color: var(--text-secondary);
    font-style: italic;
    margin-top: 0.75rem;
    text-align: center;
}

.threshold-note {
    font-size: 0.8rem;
    color: var(--color-info);
    background: rgba(59, 130, 246, 0.1);
    padding: 0.75rem;
    border-radius: var(--border-radius);
    border-left: 3px solid var(--color-info);
    margin-top: 0.75rem;
    line-height: 1.5;
}

.threshold-note strong {
    font-weight: 600;
}
