@layer reset, base, components, utilities;

@layer reset {
    /* Box sizing and border defaults */
    :where(*, *::before, *::after) {
        box-sizing: border-box;
        border-width: 0;
        border-style: solid;
        min-width: 0;
    }

    /* Core root defaults */
    :where(html) {
        block-size: 100%;
        text-size-adjust: none;
        interpolate-size: allow-keywords;
    }

    :where(body) {
        min-block-size: 100vh;
        line-height: 1.5;
        margin: 0;
        -webkit-font-smoothing: antialiased;
    }

    /* Typography improvements */
    :where(h1, h2, h3, h4, h5, h6) {
        text-wrap: balance;
        font-weight: bold;
        margin-block: 0;
    }

    :where(p) {
        text-wrap: pretty;
        margin-block-end: 1em;
    }

    /* Media handling */
    :where(img, svg, video, canvas) {
        display: block;
        max-inline-size: 100%;
        block-size: auto;
    }

    /* Form control modernization */
    :where(input, textarea, select, button) {
        font: inherit;
        letter-spacing: inherit;
        word-spacing: inherit;
        color: currentColor;
        cursor: pointer;
    }

    :where(textarea, select, input) {
        field-sizing: content;
    }

    :where(select) {
        appearance: base-select;
    }

    /* Accessibility */
    :where(:focus-visible) {
        outline: 2px solid canvasText;
        outline-offset: 2px;
    }

    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            animation-duration: 0.01ms !important;
            transition-duration: 0.01ms !important;
        }
    }
}

@layer base {
    :root {
        --bg: #f7f6f2;
        --surface: #ffffff;
        --ink: #1c1f1a;
        --ink-soft: #4a504a;
        --muted: #8a8f87;
        --line: #e3e1d8;
        --line-strong: #cfccc1;
        --accent: #2f6b3a;
        --accent-ink: #ffffff;
        --accent-soft: #e6efe5;
        --radius: 8px;
        --pill: 999px;
        --shadow: 0 1px 2px rgba(0, 0, 0, 0.04), 0 4px 16px rgba(0, 0, 0, 0.04);
        --max: 1100px;
        --font: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
    }

    body {
        background: var(--bg);
        color: var(--ink);
        font-family: var(--font);
        line-height: 1.5;
    }
    a {
        color: var(--accent);
        text-decoration: none;
    }
    a:hover {
        text-decoration: underline;
    }
}

@layer components {
    .container {
        max-width: var(--max);
        margin: 0 auto;
        padding: 0 24px;
    }

    header.nav {
        border-bottom: 1px solid var(--line);
        background: var(--surface);
    }
    .nav-inner {
        display: flex;
        align-items: center;
        gap: 18px;
        max-width: var(--max);
        margin: 0 auto;
        padding: 14px 24px;
    }
    .brand {
        font-weight: 700;
        font-size: 18px;
        color: var(--ink);
        display: flex;
        align-items: center;
        gap: 8px;
    }
    .brand-mark {
        width: 14px;
        height: 14px;
        border-radius: 3px;
        background: var(--accent);
        display: inline-block;
    }
    .nav-inner .spacer {
        flex: 1;
    }
    .lang-switch {
        font-size: 14px;
        color: var(--ink-soft);
    }
    .lang-switch a {
        color: var(--ink-soft);
    }
    .lang-switch .current {
        color: var(--ink);
        font-weight: 600;
    }

    .hero {
        background: var(--surface);
        border-bottom: 1px solid var(--line);
        padding: 56px 0 40px;
    }
    .hero h1 {
        font-size: clamp(32px, 5vw, 48px);
        line-height: 1.1;
        margin: 0 0 16px;
        letter-spacing: -0.01em;
    }
    .hero .lede {
        font-size: 19px;
        color: var(--ink-soft);
        max-width: 60ch;
        margin: 0 0 12px;
    }
    .hero .pitch {
        font-size: 16px;
        color: var(--ink-soft);
        max-width: 60ch;
        margin: 0 0 8px;
        font-style: italic;
    }

    main {
        padding: 32px 0 72px;
    }
    section.block {
        margin: 24px 0;
    }
    section.block h2 {
        font-size: 26px;
        margin: 0 0 12px;
        letter-spacing: -0.01em;
    }
    section.block p {
        color: var(--ink-soft);
        max-width: 70ch;
        margin: 0 0 12px;
    }

    .planner {
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: var(--radius);
        padding: 24px;
        box-shadow: var(--shadow);
        margin-top: 24px;
    }
    .planner h2 {
        margin-top: 0;
        font-size: 22px;
    }
    .preview-note {
        font-size: 13px;
        color: var(--muted);
        margin-bottom: 16px;
    }
    #result-count {
        margin: 0;
    }
    .form-grid {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
        gap: 14px;
    }
    .field label {
        display: block;
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--muted);
        margin-bottom: 4px;
    }
    .field input,
    .field select {
        width: 100%;
        padding: 8px 10px;
        border: 1px solid var(--line-strong);
        border-radius: var(--radius);
        background: var(--surface);
        color: var(--ink);
        font-size: 15px;
    }
    .field input:disabled {
        background: var(--bg);
        color: var(--ink-soft);
    }

    .chips {
        display: flex;
        flex-wrap: wrap;
        gap: 8px;
        margin-top: 14px;
    }
    .chip {
        display: inline-flex;
        align-items: center;
        gap: 6px;
        padding: 6px 12px;
        border: 1px solid var(--line-strong);
        border-radius: var(--pill);
        background: var(--surface);
        color: var(--ink-soft);
        font-size: 14px;
    }
    .chip input {
        display: none;
    }
    .chip.on {
        background: var(--accent-soft);
        border-color: var(--accent);
        color: var(--accent);
    }

    .actions {
        margin-top: 18px;
        display: flex;
        gap: 12px;
        align-items: center;
        flex-wrap: wrap;
    }
    .actions .spacer {
        flex: 1;
    }
    .sort-bar[hidden] {
        display: none;
    }
    .sort-bar {
        display: inline-flex;
        flex-wrap: wrap;
        gap: 10px;
        align-items: baseline;
        font-size: 13px;
        color: var(--muted);
    }
    .sort-link {
        color: var(--muted);
    }
    .sort-link.active {
        color: var(--ink);
        font-weight: 600;
    }
    .btn {
        display: inline-block;
        padding: 10px 18px;
        border-radius: var(--radius);
        background: var(--accent);
        color: var(--accent-ink);
        font-weight: 600;
        border: 0;
    }
    .btn:hover {
        text-decoration: none;
        filter: brightness(0.95);
    }
    .btn.secondary {
        background: var(--surface);
        color: var(--ink);
        border: 1px solid var(--line-strong);
    }

    .results {
        display: grid;
        gap: 16px;
        margin-top: 24px;
    }
    .result-card {
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: var(--radius);
        box-shadow: var(--shadow);
    }
    .result-card > summary {
        padding: 18px 20px;
        cursor: pointer;
        list-style: none;
        display: grid;
        grid-template-columns: 1fr auto;
        gap: 12px 24px;
        align-items: start;
    }
    .result-card > summary::-webkit-details-marker {
        display: none;
    }
    .result-card[open] > summary {
        border-bottom: 1px dashed var(--line);
    }
    .result-card .card-head {
        grid-column: 1;
    }
    .result-card h3 {
        margin: 0 0 4px;
        font-size: 18px;
    }
    .result-card .label {
        color: var(--muted);
        font-size: 14px;
        margin: 0 0 12px;
    }
    .result-card .meta {
        display: flex;
        flex-wrap: wrap;
        gap: 10px;
        font-size: 14px;
        color: var(--ink-soft);
    }
    .result-card .meta span {
        background: var(--bg);
        padding: 3px 10px;
        border-radius: var(--pill);
    }
    .result-card .stats {
        display: flex;
        gap: 18px;
    }
    .result-card .stat {
        text-align: right;
    }
    .result-card .stat .v {
        font-size: 22px;
        font-weight: 700;
    }
    .result-card .stat .v small {
        font-size: 13px;
        font-weight: 500;
        color: var(--muted);
        margin-left: 2px;
    }
    .result-card .stat .k {
        font-size: 12px;
        color: var(--muted);
        text-transform: uppercase;
        letter-spacing: 0.06em;
    }
    .result-card .links {
        grid-column: 1 / -1;
        display: flex;
        flex-wrap: wrap;
        gap: 14px;
        padding-top: 12px;
        border-top: 1px dashed var(--line);
        margin-top: 4px;
        font-size: 14px;
    }

    .result-detail {
        padding: 18px 20px 22px;
        display: grid;
        gap: 22px;
    }
    .result-detail h4 {
        margin: 0 0 8px;
        font-size: 13px;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--muted);
        font-weight: 600;
    }
    .result-detail .soft-note {
        color: var(--muted);
        font-size: 13px;
        margin: 4px 0 0;
    }
    .result-detail .run-time-block p {
        margin: 0;
        color: var(--ink-soft);
    }

    .connections {
        display: grid;
        gap: 6px;
    }
    .connection-row {
        display: flex;
        flex-wrap: wrap;
        align-items: baseline;
        gap: 12px;
        padding: 8px 10px;
        background: var(--bg);
        border-radius: var(--radius);
        font-size: 14px;
    }
    .connection-time {
        font-weight: 600;
        color: var(--ink);
        font-variant-numeric: tabular-nums;
    }
    .connection-meta {
        color: var(--ink-soft);
        font-size: 13px;
    }
    .connection-badge {
        background: var(--accent-soft);
        color: var(--accent);
        font-size: 12px;
        font-weight: 600;
        padding: 2px 8px;
        border-radius: var(--pill);
    }
    .connection-link {
        margin-left: auto;
        font-size: 13px;
    }

    .loc-grid {
        display: grid;
        gap: 16px;
        grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
    }
    .loc-block {
        display: flex;
        flex-direction: column;
        gap: 8px;
        background: var(--bg);
        border-radius: var(--radius);
        padding: 12px;
    }
    .loc-heading {
        font-size: 12px;
        text-transform: uppercase;
        letter-spacing: 0.06em;
        color: var(--muted);
        font-weight: 600;
    }
    .loc-block img {
        width: 100%;
        height: auto;
        border-radius: var(--radius);
        border: 1px solid var(--line);
        display: block;
    }
    .loc-name {
        font-weight: 600;
        color: var(--ink);
        font-size: 14px;
    }
    .loc-osm {
        font-size: 13px;
    }

    .empty {
        padding: 24px;
        text-align: center;
        color: var(--muted);
        border: 1px dashed var(--line-strong);
        border-radius: var(--radius);
    }

    .values {
        display: grid;
        grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
        gap: 18px;
        margin-top: 20px;
    }
    .value-card {
        background: var(--surface);
        border: 1px solid var(--line);
        border-radius: var(--radius);
        padding: 18px;
    }
    .value-card h3 {
        margin: 0 0 6px;
        font-size: 16px;
    }
    .value-card p {
        color: var(--ink-soft);
        font-size: 14px;
        margin: 0;
    }

    footer {
        border-top: 1px solid var(--line);
        background: var(--surface);
        padding: 28px 0;
        color: var(--muted);
        font-size: 14px;
    }
    footer .container {
        display: flex;
        flex-wrap: wrap;
        gap: 14px;
    }
    footer a {
        color: var(--ink-soft);
    }

    @media (max-width: 560px) {
        .result-card > summary {
            display: flex;
            flex-direction: column;
            gap: 8px;
        }
        .result-card .card-head {
            display: contents;
        }
        .result-card .label {
            margin: 0;
        }
        .result-card .stats {
            order: 1;
            justify-content: flex-start;
            gap: 22px;
            margin: 4px 0;
        }
        .result-card .meta {
            order: 2;
        }
        .result-card .links {
            order: 3;
        }
        .result-card .stat {
            text-align: left;
        }
        .result-card .stat .v {
            font-size: 18px;
        }
    }

    .preview-ribbon {
        position: fixed;
        top: 0;
        right: 0;
        width: 160px;
        height: 160px;
        overflow: hidden;
        pointer-events: none;
        z-index: 1000;
    }
    .preview-ribbon span {
        position: absolute;
        display: block;
        width: 240px;
        padding: 8px 0;
        background: #c0392b;
        color: #fff;
        font-size: 13px;
        font-weight: 700;
        letter-spacing: 0.12em;
        text-transform: uppercase;
        text-align: center;
        box-shadow: 0 2px 6px rgba(0, 0, 0, 0.25);
        transform: rotate(45deg);
        top: 38px;
        right: -64px;
    }
    @media (max-width: 600px) {
        .preview-ribbon {
            width: 90px;
            height: 90px;
        }
        .preview-ribbon span {
            width: 150px;
            font-size: 10px;
            padding: 3px 0;
            top: 18px;
            right: -45px;
        }
        .nav-inner {
            flex-wrap: wrap;
            padding-right: 90px;
        }
    }
}
