/* Shared design tokens — kept in sync with the React app's client/src/styles/variables.css so
   the pre-auth pages (landing, login, register, bookmarklet) match the dashboard. */
:root {
    --color-header-bg: #2c3e50;
    --color-primary: #3498db;
    --color-primary-hover: #2980b9;
    --color-success: #27ae60;
    --color-success-hover: #219a52;
    --color-danger: #e74c3c;
    --color-background: #f5f5f5;
    --color-card-bg: #ffffff;
    --color-text: #333333;
    --color-text-muted: #7f8c8d;
    --color-border: #dddddd;
    --color-stat-box-bg: #ecf0f1;
    --radius: 8px;
    --shadow-card: 0 2px 4px rgba(0, 0, 0, 0.08);
    --shadow-card-hover: 0 4px 16px rgba(0, 0, 0, 0.12);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Oxygen, Ubuntu, sans-serif;
    background: var(--color-background);
    color: var(--color-text);
    line-height: 1.6;
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

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

header {
    background: var(--color-header-bg);
    color: white;
    padding: 15px 20px;
    display: flex;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

header h1 {
    font-size: 1.5rem;
}

header h1 a {
    color: inherit;
    text-decoration: none;
}

header h1 a:hover {
    opacity: 0.9;
}

header nav a {
    color: white;
    text-decoration: none;
    margin-left: 20px;
}

header nav a:hover {
    text-decoration: underline;
}

.card {
    background: var(--color-card-bg);
    border-radius: var(--radius);
    padding: 24px;
    margin-bottom: 20px;
    box-shadow: var(--shadow-card);
}

.card h2 {
    margin-bottom: 15px;
    color: #2c3e50;
    border-bottom: 2px solid #3498db;
    padding-bottom: 10px;
}

.form-group {
    margin-bottom: 15px;
}

.form-group label {
    display: block;
    margin-bottom: 5px;
    font-weight: 500;
}

.form-group input {
    width: 100%;
    padding: 10px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 1rem;
}

.form-group input:focus {
    outline: none;
    border-color: #3498db;
}

.btn {
    padding: 11px 22px;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 1rem;
    font-weight: 500;
    transition: background 0.2s, transform 0.05s;
}

.btn:active {
    transform: translateY(1px);
}

.btn-primary {
    background: #3498db;
    color: white;
}

.btn-primary:hover {
    background: #2980b9;
}

.btn-danger {
    background: #e74c3c;
    color: white;
}

.btn-danger:hover {
    background: #c0392b;
}

.btn-small {
    padding: 5px 10px;
    font-size: 0.875rem;
    background: #3498db;
    color: white;
    text-decoration: none;
}

.btn-small:hover {
    background: #2980b9;
}

.error {
    color: #e74c3c;
    margin-top: 10px;
}

.success {
    color: #27ae60;
    margin-top: 10px;
}

.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 15px;
    margin-bottom: 20px;
}

.stat-box {
    background: #ecf0f1;
    padding: 15px;
    border-radius: 8px;
    text-align: center;
}

.stat-box .value {
    font-size: 2rem;
    font-weight: bold;
    color: #2c3e50;
}

.stat-box .label {
    color: #7f8c8d;
    font-size: 0.875rem;
}

.guess-list {
    max-height: 400px;
    overflow-y: auto;
}

.guess-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
}

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

.guess-item.correct {
    border-left: 4px solid #27ae60;
}

.guess-item.incorrect {
    border-left: 4px solid #e74c3c;
}

.guess-country {
    font-weight: 500;
}

.guess-details {
    color: #7f8c8d;
    font-size: 0.875rem;
}

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

.map-table th,
.map-table td {
    padding: 10px;
    text-align: left;
    border-bottom: 1px solid #eee;
}

.map-table th {
    background: #ecf0f1;
    font-weight: 600;
}

.map-table th.sortable {
    cursor: pointer;
    user-select: none;
    transition: background 0.15s;
}

.map-table th.sortable:hover {
    background: #d5dbdb;
}

.token-list {
    list-style: none;
}

.token-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px;
    border-bottom: 1px solid #eee;
}

.bookmarklet-link {
    display: inline-block;
    background: #27ae60;
    color: white;
    padding: 15px 30px;
    border-radius: 8px;
    text-decoration: none;
    font-weight: bold;
    margin: 20px 0;
}

.bookmarklet-link:hover {
    background: #219a52;
}

.instructions {
    background: #ffeaa7;
    padding: 15px;
    border-radius: 8px;
    margin-top: 15px;
}

.instructions h3 {
    margin-bottom: 10px;
}

.instructions ol {
    margin-left: 20px;
}

.hero {
    text-align: center;
    padding: clamp(48px, 10vw, 80px) 20px;
    background: linear-gradient(135deg, #3498db, #2c3e50);
    color: white;
    margin-bottom: 30px;
}

.hero h1 {
    font-size: clamp(2rem, 6vw, 2.75rem);
    margin-bottom: 15px;
}

.hero p {
    font-size: clamp(1rem, 3vw, 1.2rem);
    opacity: 0.92;
    max-width: 600px;
    margin: 0 auto 30px;
}

.hidden {
    display: none;
}

.loading {
    text-align: center;
    padding: 40px;
    color: #7f8c8d;
}

/* Histogram styles */
.histogram-container {
    margin-top: 15px;
}

.histogram-subtitle {
    color: #7f8c8d;
    font-size: 0.9rem;
    margin-bottom: 15px;
}

.histogram-row {
    display: flex;
    align-items: center;
    margin-bottom: 8px;
}

.histogram-label {
    width: 140px;
    min-width: 140px;
    font-size: 0.9rem;
    text-overflow: ellipsis;
    overflow: hidden;
    white-space: nowrap;
    padding-right: 10px;
}

.histogram-link {
    color: #3498db;
    text-decoration: none;
}

.histogram-link:hover {
    text-decoration: underline;
}

.histogram-bar-container {
    flex: 1;
    background: #ecf0f1;
    border-radius: 4px;
    height: 28px;
    overflow: hidden;
    position: relative;
}

.histogram-bar {
    height: 100%;
    border-radius: 4px;
    min-width: 30px;
    transition: width 0.3s ease;
}

.histogram-bar.correct {
    background: #27ae60;
}

.histogram-bar.incorrect {
    background: #e74c3c;
}

.histogram-count {
    position: absolute;
    right: 8px;
    top: 50%;
    transform: translateY(-50%);
    font-size: 0.8rem;
    font-weight: 600;
    color: #2c3e50;
    text-shadow: 
        0 0 3px rgba(255, 255, 255, 1),
        0 0 6px rgba(255, 255, 255, 0.9),
        0 0 9px rgba(255, 255, 255, 0.7),
        0 1px 2px rgba(255, 255, 255, 1);
    pointer-events: none;
    z-index: 1;
}

/* Country link in dashboard */
.country-link {
    color: #3498db;
    text-decoration: none;
    cursor: pointer;
}

.country-link:hover {
    text-decoration: underline;
}

/* Sort controls */
.sort-controls {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 15px;
    flex-wrap: wrap;
}

.sort-controls label {
    font-weight: 500;
    color: #2c3e50;
}

.sort-select {
    padding: 6px 12px;
    border: 1px solid #ddd;
    border-radius: 4px;
    font-size: 0.875rem;
    background: white;
    cursor: pointer;
    transition: border-color 0.2s;
}

.sort-select:focus {
    outline: none;
    border-color: #3498db;
}

.sort-direction-btn {
    margin-left: auto;
}

/* Filter badges */
.filter-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-bottom: 15px;
}

.filter-badge {
    display: inline-block;
    padding: 6px 12px;
    background: #ecf0f1;
    border-radius: 20px;
    font-size: 0.875rem;
    cursor: pointer;
    transition: all 0.2s;
    border: 2px solid transparent;
}

.filter-badge:hover {
    background: #d5dbdb;
}

.filter-badge.active {
    background: #3498db;
    color: white;
    border-color: #2980b9;
}

/* Clickable histogram rows */
.histogram-row.clickable {
    cursor: pointer;
    padding: 4px;
    margin: 4px -4px;
    border-radius: 4px;
    transition: background 0.15s;
}

.histogram-row.clickable:hover {
    background: #f0f3f4;
}

.histogram-row.selected {
    background: #eaf2f8;
    border-left: 3px solid #3498db;
    padding-left: 8px;
}

/* Mode toggle */
.mode-toggle {
    display: flex;
    gap: 0;
    margin-bottom: 20px;
    border-radius: 8px;
    overflow: hidden;
    border: 2px solid #3498db;
    width: fit-content;
}

.mode-btn {
    padding: 10px 20px;
    border: none;
    background: white;
    color: #3498db;
    cursor: pointer;
    font-weight: 500;
    font-size: 0.95rem;
    transition: all 0.2s;
}

.mode-btn:hover:not(.active) {
    background: #ecf5fd;
}

.mode-btn.active {
    background: #3498db;
    color: white;
}

/* Distance mode score coloring (matching histogram buckets) */
.guess-item.score-low {
    border-left: 4px solid #e74c3c;
}

.guess-item.score-mid-low {
    border-left: 4px solid #e67e22;
}

.guess-item.score-mid {
    border-left: 4px solid #f39c12;
}

.guess-item.score-mid-high {
    border-left: 4px solid #9acd32;
}

.guess-item.score-high {
    border-left: 4px solid #27ae60;
}

/* Score bucket histogram coloring */
.histogram-bar.score-low {
    background: #e74c3c;
}

.histogram-bar.score-mid-low {
    background: #e67e22;
}

.histogram-bar.score-mid {
    background: #f39c12;
}

.histogram-bar.score-mid-high {
    background: #9acd32;
}

.histogram-bar.score-high {
    background: #27ae60;
}

/* Accuracy color cutoffs for Stats by Country section */
.accuracy-excellent {
    background: linear-gradient(90deg, #27ae60 var(--fill-percentage), transparent var(--fill-percentage));
}

.accuracy-good {
    background: linear-gradient(90deg, #9acd32 var(--fill-percentage), transparent var(--fill-percentage));
}

.accuracy-average {
    background: linear-gradient(90deg, #f39c12 var(--fill-percentage), transparent var(--fill-percentage));
}

.accuracy-below-average {
    background: linear-gradient(90deg, #e67e22 var(--fill-percentage), transparent var(--fill-percentage));
}

.accuracy-poor {
    background: linear-gradient(90deg, #e74c3c var(--fill-percentage), transparent var(--fill-percentage));
}

/* Score bar for Distance mode in Stats by Country section */
.score-bar-low {
    background: linear-gradient(90deg, #e74c3c var(--fill-percentage), transparent var(--fill-percentage));
}

.score-bar-mid-low {
    background: linear-gradient(90deg, #e67e22 var(--fill-percentage), transparent var(--fill-percentage));
}

.score-bar-mid {
    background: linear-gradient(90deg, #f39c12 var(--fill-percentage), transparent var(--fill-percentage));
}

.score-bar-mid-high {
    background: linear-gradient(90deg, #9acd32 var(--fill-percentage), transparent var(--fill-percentage));
}

.score-bar-high {
    background: linear-gradient(90deg, #27ae60 var(--fill-percentage), transparent var(--fill-percentage));
}

/* Text styling for stat bars */
.stat-bar-value {
    position: relative;
    font-weight: 600;
    color: #2c3e50;
    text-shadow:
        0 0 3px rgba(255, 255, 255, 1),
        0 0 6px rgba(255, 255, 255, 0.9),
        0 0 9px rgba(255, 255, 255, 0.7),
        0 1px 2px rgba(255, 255, 255, 1);
    z-index: 1;
}

/* The green "drag me" bookmarklet button: full-width and tappable on small screens. */
.bookmarklet-link {
    box-shadow: var(--shadow-card);
    transition: background 0.2s, box-shadow 0.2s;
}

.bookmarklet-link:hover {
    box-shadow: var(--shadow-card-hover);
}

/* --- Responsive: pre-auth pages (landing, login, register, bookmarklet) --- */
@media (max-width: 640px) {
    .container {
        padding: 16px;
    }

    header {
        padding: 12px 16px;
    }

    header nav {
        display: flex;
        flex-wrap: wrap;
        gap: 6px 4px;
    }

    header nav a {
        margin-left: 0;
        padding: 4px 8px;
    }

    .card {
        padding: 18px;
    }

    /* Auth cards use inline `max-width:400px; margin:40px auto` — tighten the vertical margin
       on phones so the form isn't pushed down the page. */
    .card[style] {
        margin-top: 20px !important;
        margin-bottom: 20px !important;
    }

    .stats-grid {
        grid-template-columns: repeat(auto-fit, minmax(120px, 1fr));
        gap: 12px;
    }

    .bookmarklet-link {
        display: block;
        text-align: center;
        padding: 16px 20px;
    }

    .btn {
        width: 100%;
    }
}

/* Buttons that shouldn't stretch full-width on mobile (inline actions, small buttons). */
@media (max-width: 640px) {
    .btn-small,
    .filter-badge {
        width: auto;
    }
}
