:root {
    color-scheme: light dark;
    --bg: #ffffff;
    --fg: #1a1d21;
    --muted: #667085;
    --border: #d8dce3;
    --accent: #1f6feb;
    --danger: #c62828;
    --chart: #1f6feb;
    --map-space: #ffffff;
    --map-ocean: #dce7f2;
    --map-land: #f7f5f0;
    --map-border: #c9c5bb;
    --map-route: #1f6feb;
    --map-airport: #0b3d91;
    /* Visited countries: three fills (checked as a categorical palette against the
       land colour) and an outline for the wishlist, so it never needs a fourth hue. */
    --country-visited: #2a78d6;
    --country-lived: #eb6834;
    --country-layover: #1baf7a;
    --country-wishlist: #4a3aa7;
}

@media (prefers-color-scheme: dark) {
    :root {
        --bg: #0f1216;
        --fg: #e6e8eb;
        --muted: #98a2b3;
        --border: #2a2f37;
        --accent: #6ea8fe;
        --danger: #ff8a80;
        --chart: #4f8ff0;
        --map-space: #05080c;
        --map-ocean: #101c2b;
        --map-land: #1c2530;
        --map-border: #33404f;
        --map-route: #6ea8fe;
        --map-airport: #cfe2ff;
        --country-visited: #3987e5;
        --country-lived: #d95926;
        --country-layover: #199e70;
        --country-wishlist: #9085e9;
    }
}

* {
    box-sizing: border-box;
}

body {
    display: flex;
    flex-direction: column;
    min-height: 100vh;
    margin: 0;
    background: var(--bg);
    color: var(--fg);
    font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

a {
    color: var(--accent);
}

.site-header {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
}

.site-name {
    color: var(--fg);
    font-weight: 600;
    text-decoration: none;
}

main {
    width: 100%;
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px;
}

.muted {
    color: var(--muted);
}

h1 {
    margin: 0 0 16px;
    font-size: 1.6rem;
}

h2 {
    margin: 32px 0 12px;
    padding-top: 24px;
    border-top: 1px solid var(--border);
    font-size: 1.15rem;
}

.site-header {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 8px 16px;
}

.site-nav {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 16px;
}

main.narrow {
    max-width: 480px;
}

main.wide {
    max-width: 1200px;
}

.field {
    margin: 0 0 16px;
    padding: 0;
    border: 0;
}

.field > label,
.field > legend {
    display: block;
    margin-bottom: 4px;
    padding: 0;
    font-weight: 600;
}

input[type="text"],
input[type="email"],
input[type="password"] {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--fg);
    font: inherit;
}

input[aria-invalid="true"] {
    border-color: var(--danger);
}

.check {
    display: block;
    margin: 4px 0;
    font-weight: 400;
}

.hint,
.error {
    margin: 4px 0 0;
    font-size: 0.9rem;
}

.hint {
    color: var(--muted);
}

.error {
    color: var(--danger);
}

.actions {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 12px 16px;
    margin: 20px 0 0;
}

button,
.button {
    padding: 8px 14px;
    border: 1px solid var(--accent);
    border-radius: 6px;
    background: var(--accent);
    color: var(--bg);
    font: inherit;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
}

button.danger {
    border-color: var(--danger);
    background: var(--danger);
}

button.link {
    padding: 0;
    border: 0;
    background: none;
    color: var(--accent);
    font-weight: 400;
    text-decoration: underline;
}

.notice {
    margin: 0 0 20px;
    padding: 10px 12px;
    border: 1px solid var(--border);
    border-left: 4px solid var(--accent);
    border-radius: 6px;
}

.page-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 16px;
}

.page-head h1 {
    margin: 0;
}

.flight-form {
    max-width: 640px;
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 0 16px;
}

.form-grid.thirds {
    grid-template-columns: repeat(3, minmax(0, 1fr));
}

@media (max-width: 520px) {
    .form-grid,
    .form-grid.thirds {
        grid-template-columns: minmax(0, 1fr);
    }
}

input[type="date"],
input[type="month"],
input[type="time"],
select,
textarea {
    width: 100%;
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    color: var(--fg);
    font: inherit;
}

button.secondary {
    background: none;
    color: var(--accent);
}

.lookup {
    position: relative;
}

.lookup-list {
    position: absolute;
    z-index: 10;
    left: 0;
    right: 0;
    max-height: 280px;
    margin: 2px 0 0;
    padding: 4px;
    overflow-y: auto;
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    box-shadow: 0 6px 20px rgb(0 0 0 / 0.18);
    list-style: none;
}

.lookup-list li {
    display: flex;
    flex-direction: column;
    padding: 6px 8px;
    border-radius: 4px;
    cursor: pointer;
}

.lookup-list li:hover,
.lookup-list li[aria-selected="true"] {
    background: var(--accent);
    color: var(--bg);
}

.lookup-list .detail {
    font-size: 0.85rem;
    opacity: 0.75;
}

.table-scroll {
    overflow-x: auto;
}

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

th,
td {
    padding: 8px 10px;
    border-bottom: 1px solid var(--border);
    text-align: left;
    vertical-align: top;
}

th {
    color: var(--muted);
    font-size: 0.85rem;
    font-weight: 600;
}

.number {
    text-align: right;
    font-variant-numeric: tabular-nums;
}

.nowrap {
    white-space: nowrap;
}

.pagination {
    display: flex;
    justify-content: center;
    gap: 16px;
    margin-top: 20px;
}

input[type="file"] {
    width: 100%;
    font: inherit;
}

.summary {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 24px;
    margin: 0 0 16px;
    padding: 0;
    list-style: none;
}

.row-problem strong {
    color: var(--danger);
}

.row-duplicate {
    color: var(--muted);
}

fieldset.times {
    margin: 0 0 16px;
    padding: 12px 16px 4px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

fieldset.times > legend {
    padding: 0 6px;
    font-weight: 600;
}

fieldset.times > .hint {
    margin: 0 0 12px;
}

input[readonly] {
    border-style: dashed;
    color: var(--muted);
}

.times-summary {
    margin: 0 0 12px;
    padding: 8px 10px;
    border-left: 4px solid var(--accent);
    border-radius: 4px;
    background: color-mix(in srgb, var(--accent) 10%, transparent);
    font-weight: 600;
}

.times-summary.warning {
    border-left-color: var(--danger);
    background: color-mix(in srgb, var(--danger) 10%, transparent);
}

main.full {
    display: flex;
    flex: 1;
    flex-direction: column;
    max-width: none;
    padding: 0;
}

/* The map takes whatever height the header and the filter bar leave. */
.map {
    flex: 1;
    width: 100%;
    min-height: 320px;
    /* Shows around the globe; the ocean is drawn on it. */
    background: var(--map-space);
}

.map-empty,
.map-failed {
    max-width: 960px;
    margin: 0 auto;
    padding: 24px 16px;
}

.map-popup {
    display: flex;
    flex-direction: column;
    gap: 2px;
    color: #1a1d21;
    font: 14px/1.4 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
}

.map-popup a {
    margin-top: 6px;
    color: #1f6feb;
}

h3 {
    margin: 20px 0 8px;
    font-size: 1rem;
}

.filter {
    display: flex;
    flex-wrap: wrap;
    align-items: end;
    gap: 8px 12px;
    margin: 0 0 20px;
}

.filter label span {
    display: block;
    color: var(--muted);
    font-size: 0.8rem;
}

.filter select {
    width: auto;
    max-width: 200px;
    padding: 5px 8px;
}

.chip {
    padding: 4px 10px;
    border: 1px solid var(--border);
    border-radius: 999px;
    white-space: nowrap;
}

.chip a {
    margin-left: 4px;
    text-decoration: none;
}

.map-filter {
    padding: 10px 16px 0;
    border-bottom: 1px solid var(--border);
}

.map-filter .filter {
    margin-bottom: 10px;
}

.tiles {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 12px;
    margin: 0;
}

.tile {
    padding: 12px 14px;
    border: 1px solid var(--border);
    border-radius: 8px;
}

.tile dt {
    color: var(--muted);
    font-size: 0.85rem;
}

.tile dd {
    margin: 2px 0 0;
    font-size: 1.5rem;
    font-weight: 600;
    font-variant-numeric: tabular-nums;
}

.tile dd.note {
    color: var(--muted);
    font-size: 0.8rem;
    font-weight: 400;
}

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

.chart {
    margin: 0;
}

.chart figcaption {
    margin-bottom: 8px;
    font-weight: 600;
}

/* Columns grow from one baseline; the bar is capped in width and rounded at the data end only. */
.columns {
    display: flex;
    align-items: stretch;
    gap: 2px;
    height: 160px;
    border-bottom: 1px solid var(--border);
}

.column {
    position: relative;
    display: flex;
    flex: 1;
    align-items: flex-end;
    justify-content: center;
    min-width: 0;
}

.column .bar {
    width: 100%;
    max-width: 24px;
    min-height: 0;
    border-radius: 4px 4px 0 0;
    background: var(--chart);
}

.column:hover,
.column:focus-visible {
    background: color-mix(in srgb, var(--chart) 12%, transparent);
    outline: none;
}

.tooltip {
    position: absolute;
    z-index: 5;
    bottom: 100%;
    left: 50%;
    display: none;
    padding: 4px 8px;
    transform: translateX(-50%);
    border: 1px solid var(--border);
    border-radius: 6px;
    background: var(--bg);
    box-shadow: 0 4px 12px rgb(0 0 0 / 0.15);
    color: var(--fg);
    font-size: 0.85rem;
    white-space: nowrap;
    pointer-events: none;
}

.column:hover .tooltip,
.column:focus-visible .tooltip {
    display: block;
}

.axis {
    display: flex;
    justify-content: space-between;
    margin-top: 4px;
    color: var(--muted);
    font-size: 0.8rem;
}

details {
    margin-top: 12px;
}

summary {
    color: var(--accent);
    cursor: pointer;
}

.toggle a {
    margin-left: 8px;
}

.toggle a[aria-current] {
    color: var(--fg);
    font-weight: 600;
    text-decoration: none;
}

.rankings {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 24px 32px;
}

.ranking {
    margin: 0;
    padding: 0;
    list-style: none;
}

.ranking li {
    display: grid;
    grid-template-columns: minmax(0, 1fr) auto;
    gap: 2px 12px;
    padding: 5px 0;
}

.ranking .name {
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ranking .value {
    font-variant-numeric: tabular-nums;
    white-space: nowrap;
}

.ranking .track {
    grid-column: 1 / -1;
    height: 6px;
}

.ranking .bar {
    display: block;
    height: 100%;
    min-width: 2px;
    border-radius: 0 4px 4px 0;
    background: var(--chart);
}

.ranking .bar.none {
    background: var(--border);
}

th[scope="row"] {
    color: var(--fg);
    font-size: 1rem;
    white-space: nowrap;
}

/* A map inside a page, not filling it. */
.map.map-inline {
    flex: none;
    height: 460px;
    margin: 16px 0;
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}

a.button.secondary {
    background: none;
    color: var(--accent);
}

.downloads dt {
    margin-top: 16px;
    font-weight: 600;
}

.downloads dd {
    margin: 2px 0 0;
    color: var(--muted);
}

code.token {
    display: block;
    padding: 8px 10px;
    overflow-wrap: anywhere;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: 0.95rem/1.4 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    user-select: all;
}

.site-footer {
    display: flex;
    gap: 16px;
    justify-content: center;
    margin-top: auto;
    padding: 16px;
    border-top: 1px solid var(--border);
    font-size: 0.9rem;
}

.features {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
    gap: 16px 24px;
    margin: 32px 0 0;
    padding: 0;
    list-style: none;
}

.features strong {
    display: block;
}

img {
    max-width: 100%;
    height: auto;
}

.found {
    margin: 0;
    padding: 0;
    list-style: none;
}

progress {
    width: 100%;
    height: 12px;
    accent-color: var(--chart);
}

.required {
    color: var(--danger);
    font-weight: 600;
}

.required-note {
    margin: 0 0 12px;
}

.notice.error {
    border-left-color: var(--danger);
}

.row-actions > summary {
    white-space: nowrap;
}

.row-actions form {
    margin: 8px 0;
}

.row-actions label {
    display: block;
    font-size: 0.9rem;
}

.row-actions input[type="text"] {
    max-width: 220px;
    margin: 4px 0;
}

.visually-hidden {
    position: absolute;
    width: 1px;
    height: 1px;
    overflow: hidden;
    clip-path: inset(50%);
    white-space: nowrap;
}

/* The button that unfolds the filter exists only on narrow screens. */
.filter-toggle-label {
    display: none;
}

@media (max-width: 700px) {
    .filter-toggle-label {
        display: inline-block;
        margin: 0 0 12px;
        padding: 6px 12px;
        border: 1px solid var(--border);
        border-radius: 6px;
        color: var(--accent);
        font-weight: 600;
        cursor: pointer;
    }

    .filter-toggle:focus-visible + .filter-toggle-label {
        outline: 2px solid var(--accent);
        outline-offset: 2px;
    }

    .filter {
        display: none;
    }

    .filter-toggle:checked ~ .filter {
        display: flex;
    }

    .filter label {
        flex: 1 1 140px;
    }

    .filter select {
        width: 100%;
        max-width: none;
    }

    .site-nav {
        gap: 6px 14px;
    }

    .tile dd {
        font-size: 1.25rem;
    }
}

.admin-nav {
    display: flex;
    flex-wrap: wrap;
    gap: 6px 16px;
    margin: 0 0 16px;
}

.chip.danger {
    border-color: var(--danger);
    color: var(--danger);
}

h1 .chip {
    font-size: 0.85rem;
    font-weight: 400;
    vertical-align: middle;
}

.report {
    margin-top: 32px;
    font-size: 0.9rem;
}

.qr {
    display: inline-block;
    padding: 12px;
    border-radius: 8px;
    background: #ffffff; /* a QR code needs a white ground in dark mode too */
}

pre.token {
    padding: 8px 10px;
    border: 1px solid var(--border);
    border-radius: 6px;
    font: 0.95rem/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    user-select: all;
}

.demo-banner {
    margin: 0;
    padding: 8px 16px;
    background: color-mix(in srgb, var(--accent) 14%, var(--bg));
    font-size: 0.9rem;
    text-align: center;
}

/* The flight date: a day, or only a year, switched by a checkbox. */
.date-choice {
    display: flex;
    flex-direction: column;
}

.date-choice .year-toggle {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.date-choice .date-year,
.year-toggle:checked ~ .date-day {
    display: none;
}

.year-toggle:checked ~ .date-year {
    display: block;
}

.date-choice > label.check {
    order: 3;
    margin-top: -10px;
    cursor: pointer;
    text-decoration: underline;
}

.year-toggle:focus-visible ~ label.check {
    outline: 2px solid var(--accent);
}

.year-toggle:checked ~ label.check::before {
    content: "✓ ";
}

.form-note {
    margin: -8px 0 16px;
}

.row-fix form {
    min-width: 240px;
    margin-top: 8px;
}

.choices li {
    margin: 0 0 16px;
}

.filter input[type="date"] {
    width: auto;
    padding: 4px 8px;
}

/* Your countries: the key, its swatches, and the lists under the map. */
.legend {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1.25rem;
    padding: 0;
    list-style: none;
}

.swatch {
    display: inline-block;
    width: 0.9rem;
    height: 0.9rem;
    border-radius: 3px;
    vertical-align: -0.1rem;
}

.swatch-visited { background: var(--country-visited); }
.swatch-lived { background: var(--country-lived); }
.swatch-layover { background: var(--country-layover); }
.swatch-wishlist { border: 2px dashed var(--country-wishlist); }

#countries-map {
    height: min(60vh, 520px);
    margin: 0.75rem 0 0.25rem;
    border-radius: 6px;
    overflow: hidden;
}

.inline-form {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.5rem;
}

.inline-form select {
    max-width: 16rem;
}

.country-list {
    padding-left: 1.1rem;
}

.country-list .hint {
    display: block;
}
