@layer reset, base, components;

@layer reset {
    *,
    *::before,
    *::after {
        box-sizing: border-box;
    }

    html {
        -webkit-text-size-adjust: 100%;
    }

    body,
    h1,
    h2,
    h3,
    p {
        margin: 0;
    }

    button,
    input,
    select {
        font: inherit;
    }

    button {
        border: 0;
    }
}

@layer base {
    :root {
        color-scheme: light dark;
        --page: #f5f5f7;
        --surface: rgba(255, 255, 255, 0.82);
        --surface-solid: #ffffff;
        --surface-subtle: rgba(118, 118, 128, 0.08);
        --line: rgba(60, 60, 67, 0.14);
        --line-strong: rgba(60, 60, 67, 0.23);
        --text: #1d1d1f;
        --secondary: #6e6e73;
        --accent: #0071e3;
        --accent-pressed: #0062c3;
        --include: #248a3d;
        --include-bg: rgba(52, 199, 89, 0.12);
        --exclude: #d70015;
        --exclude-bg: rgba(255, 59, 48, 0.11);
        --warning: #b25000;
        --shadow: 0 18px 50px rgba(0, 0, 0, 0.08);
        --radius-xl: 28px;
        --radius-lg: 20px;
        --radius-md: 14px;
        --focus: 0 0 0 4px rgba(0, 113, 227, 0.18);
    }

    @media (prefers-color-scheme: dark) {
        :root {
            --page: #000000;
            --surface: rgba(28, 28, 30, 0.82);
            --surface-solid: #1c1c1e;
            --surface-subtle: rgba(118, 118, 128, 0.18);
            --line: rgba(235, 235, 245, 0.14);
            --line-strong: rgba(235, 235, 245, 0.25);
            --text: #f5f5f7;
            --secondary: #a1a1a6;
            --accent: #0a84ff;
            --accent-pressed: #409cff;
            --include: #30d158;
            --include-bg: rgba(48, 209, 88, 0.14);
            --exclude: #ff453a;
            --exclude-bg: rgba(255, 69, 58, 0.14);
            --warning: #ff9f0a;
            --shadow: 0 18px 50px rgba(0, 0, 0, 0.32);
        }
    }

    body {
        min-height: 100vh;
        background: var(--page);
        color: var(--text);
        font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Segoe UI", sans-serif;
        font-size: 16px;
        line-height: 1.45;
        letter-spacing: -0.01em;
        -webkit-font-smoothing: antialiased;
    }

    button,
    input,
    select,
    summary {
        -webkit-tap-highlight-color: transparent;
    }

    button,
    summary {
        cursor: pointer;
    }

    input,
    select {
        width: 100%;
        color: var(--text);
        background: transparent;
        border: 0;
        outline: 0;
    }

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

    ::selection {
        background: rgba(0, 113, 227, 0.22);
    }
}

@layer components {
    .topbar {
        position: sticky;
        top: 0;
        z-index: 50;
        border-bottom: 1px solid var(--line);
        background: color-mix(in srgb, var(--page) 76%, transparent);
        backdrop-filter: saturate(160%) blur(22px);
        -webkit-backdrop-filter: saturate(160%) blur(22px);
    }

    .topbar-inner {
        width: min(1120px, calc(100% - 32px));
        height: 58px;
        margin: 0 auto;
        display: flex;
        align-items: center;
        justify-content: space-between;
    }

    .brand {
        display: inline-flex;
        align-items: center;
        gap: 9px;
        font-weight: 650;
        letter-spacing: -0.02em;
    }

    .app-mark {
        width: 46px;
        height: 46px;
        display: grid;
        place-items: center;
        border-radius: 13px;
        background: var(--text);
        color: var(--page);
        font-size: 20px;
        font-weight: 760;
        letter-spacing: -0.04em;
        box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.08);
    }

    .app-mark.small {
        width: 29px;
        height: 29px;
        border-radius: 8px;
        font-size: 13px;
    }

    .quiet-button {
        min-height: 36px;
        padding: 0 13px;
        border-radius: 10px;
        background: var(--surface-subtle);
        color: var(--text);
        font-size: 14px;
        font-weight: 580;
        transition: transform 100ms ease-out, background-color 140ms ease-out;
    }

    .quiet-button:active,
    .primary-button:active,
    .swap-button:active,
    .chip button:active,
    .suggestion:active {
        transform: scale(0.97);
    }

    .page-shell {
        width: min(980px, calc(100% - 32px));
        margin: 0 auto;
        padding: 72px 0 96px;
    }

    .hero {
        max-width: 760px;
        margin-bottom: 36px;
    }

    .hero h1 {
        margin-top: 8px;
        font-size: clamp(38px, 7vw, 68px);
        line-height: 0.98;
        letter-spacing: -0.055em;
        font-weight: 730;
        text-wrap: balance;
    }

    .hero > p:last-child {
        max-width: 680px;
        margin-top: 22px;
        color: var(--secondary);
        font-size: clamp(17px, 2.4vw, 21px);
        line-height: 1.42;
        letter-spacing: -0.022em;
    }

    .eyebrow {
        color: var(--secondary);
        font-size: 12px;
        line-height: 1.2;
        font-weight: 720;
        letter-spacing: 0.075em;
        text-transform: uppercase;
    }

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

    .search-card,
    .result-card,
    .login-card {
        border: 1px solid var(--line);
        background: var(--surface);
        box-shadow: var(--shadow);
        backdrop-filter: blur(20px) saturate(140%);
        -webkit-backdrop-filter: blur(20px) saturate(140%);
    }

    .search-card {
        padding: clamp(22px, 4vw, 34px);
        border-radius: var(--radius-xl);
    }

    .section-heading,
    .results-heading,
    .filter-title,
    .result-card-header,
    .timeline-top {
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 16px;
    }

    .section-heading {
        margin-bottom: 26px;
    }

    .section-heading h2,
    .results-heading h2 {
        margin-top: 5px;
        font-size: 25px;
        line-height: 1.15;
        letter-spacing: -0.035em;
    }

    .status-pill,
    .mini-badge {
        display: inline-flex;
        align-items: center;
        justify-content: center;
        min-height: 26px;
        padding: 3px 9px;
        border: 1px solid var(--line);
        border-radius: 999px;
        background: var(--surface-subtle);
        color: var(--secondary);
        font-size: 11px;
        font-weight: 670;
        letter-spacing: 0.01em;
        white-space: nowrap;
    }

    .route-grid {
        display: grid;
        grid-template-columns: minmax(0, 1fr) 44px minmax(0, 1fr);
        gap: 10px;
        align-items: end;
    }

    .station-field {
        position: relative;
    }

    .station-field > label,
    .field > span {
        display: block;
        margin: 0 0 8px 2px;
        color: var(--secondary);
        font-size: 13px;
        font-weight: 590;
    }

    .input-shell,
    .field input,
    .field select {
        min-height: 52px;
        border: 1px solid var(--line);
        border-radius: var(--radius-md);
        background: var(--surface-subtle);
        transition: border-color 140ms ease-out, box-shadow 140ms ease-out, background-color 140ms ease-out;
    }

    .input-shell {
        display: flex;
        align-items: center;
    }

    .input-shell:focus-within,
    .field input:focus,
    .field select:focus {
        border-color: color-mix(in srgb, var(--accent) 56%, var(--line));
        box-shadow: var(--focus);
        background: var(--surface-solid);
    }

    .input-shell input {
        min-width: 0;
        padding: 0 13px 0 15px;
    }

    .field input,
    .field select {
        padding: 0 14px;
    }

    .clear-input {
        flex: 0 0 32px;
        width: 32px;
        height: 32px;
        margin-right: 7px;
        border-radius: 50%;
        background: transparent;
        color: var(--secondary);
        font-size: 22px;
        line-height: 1;
    }

    .swap-button {
        width: 44px;
        height: 44px;
        margin-bottom: 4px;
        border: 1px solid var(--line);
        border-radius: 50%;
        background: var(--surface-subtle);
        color: var(--text);
        font-size: 20px;
        transition: transform 100ms ease-out, border-color 140ms ease-out;
    }

    .suggestions {
        position: absolute;
        z-index: 30;
        top: calc(100% + 7px);
        left: 0;
        right: 0;
        max-height: 300px;
        overflow: auto;
        padding: 6px;
        border: 1px solid var(--line-strong);
        border-radius: 16px;
        background: color-mix(in srgb, var(--surface-solid) 92%, transparent);
        box-shadow: 0 20px 50px rgba(0, 0, 0, 0.16);
        backdrop-filter: blur(24px) saturate(150%);
        -webkit-backdrop-filter: blur(24px) saturate(150%);
    }

    .suggestion {
        width: 100%;
        min-height: 48px;
        padding: 8px 10px;
        display: flex;
        align-items: center;
        justify-content: space-between;
        gap: 12px;
        border-radius: 11px;
        background: transparent;
        color: var(--text);
        text-align: left;
        transition: transform 100ms ease-out, background-color 100ms ease-out;
    }

    .suggestion:hover,
    .suggestion.active {
        background: var(--surface-subtle);
    }

    .suggestion-name {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
        font-size: 14px;
        font-weight: 590;
    }

    .suggestion-id {
        color: var(--secondary);
        font-size: 11px;
        font-variant-numeric: tabular-nums;
    }

    .suggestion-empty {
        padding: 13px 12px;
        color: var(--secondary);
        font-size: 13px;
        text-align: center;
    }

    .time-grid {
        display: grid;
        grid-template-columns: 1fr 0.8fr 1fr;
        gap: 12px;
        margin-top: 18px;
    }

    .filter-grid {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 14px;
        margin-top: 22px;
    }

    .filter-panel {
        min-width: 0;
        padding: 17px;
        border: 1px solid var(--line);
        border-radius: var(--radius-lg);
        background: color-mix(in srgb, var(--surface-subtle) 75%, transparent);
    }

    .filter-title {
        margin-bottom: 13px;
    }

    .filter-title > div {
        display: flex;
        align-items: center;
        gap: 9px;
    }

    .filter-title h3 {
        font-size: 15px;
        line-height: 1.2;
        letter-spacing: -0.015em;
    }

    .filter-hint {
        color: var(--secondary);
        font-size: 12px;
    }

    .filter-dot {
        width: 9px;
        height: 9px;
        border-radius: 50%;
    }

    .filter-dot.include {
        background: var(--include);
        box-shadow: 0 0 0 4px var(--include-bg);
    }

    .filter-dot.exclude {
        background: var(--exclude);
        box-shadow: 0 0 0 4px var(--exclude-bg);
    }

    .compact .input-shell {
        min-height: 46px;
    }

    .chips {
        min-height: 10px;
        margin-top: 11px;
        display: flex;
        flex-wrap: wrap;
        gap: 7px;
    }

    .chip {
        max-width: 100%;
        min-height: 30px;
        padding: 4px 5px 4px 10px;
        display: inline-flex;
        align-items: center;
        gap: 5px;
        border-radius: 999px;
        font-size: 12px;
        font-weight: 620;
    }

    .chip > span {
        overflow: hidden;
        text-overflow: ellipsis;
        white-space: nowrap;
    }

    .include-chip {
        background: var(--include-bg);
        color: var(--include);
    }

    .exclude-chip {
        background: var(--exclude-bg);
        color: var(--exclude);
    }

    .chip button {
        width: 23px;
        height: 23px;
        border-radius: 50%;
        background: transparent;
        color: currentColor;
        font-size: 17px;
        line-height: 1;
        transition: transform 100ms ease-out, background-color 100ms ease-out;
    }

    .chip button:hover {
        background: color-mix(in srgb, currentColor 9%, transparent);
    }

    .form-message {
        min-height: 22px;
        margin-top: 13px;
        color: var(--exclude);
        font-size: 13px;
    }

    .primary-button {
        min-height: 50px;
        padding: 0 18px;
        display: inline-flex;
        align-items: center;
        justify-content: center;
        gap: 18px;
        border-radius: 14px;
        background: var(--accent);
        color: #ffffff;
        font-weight: 650;
        letter-spacing: -0.015em;
        transition: transform 100ms ease-out, background-color 140ms ease-out, opacity 140ms ease-out;
    }

    .primary-button:hover {
        background: color-mix(in srgb, var(--accent) 88%, black);
    }

    .primary-button:disabled {
        cursor: wait;
        opacity: 0.72;
    }

    .search-button {
        width: 100%;
    }

    .button-icon {
        font-size: 19px;
    }

    .results-section {
        margin-top: 52px;
    }

    .results-heading {
        align-items: end;
        margin-bottom: 16px;
    }

    .results-heading > .muted {
        max-width: 55%;
        font-size: 12px;
        text-align: right;
    }

    .results-list {
        display: grid;
        gap: 12px;
    }

    .result-card {
        padding: 20px;
        border-radius: var(--radius-lg);
        box-shadow: 0 10px 32px rgba(0, 0, 0, 0.06);
    }

    .train-identity h3 {
        font-size: 22px;
        letter-spacing: -0.035em;
    }

    .train-identity p {
        margin-top: 2px;
        font-size: 13px;
    }

    .result-badges {
        display: flex;
        flex-wrap: wrap;
        justify-content: flex-end;
        gap: 6px;
    }

    .mini-badge.danger {
        border-color: color-mix(in srgb, var(--exclude) 25%, transparent);
        background: var(--exclude-bg);
        color: var(--exclude);
    }

    .timing-row {
        display: grid;
        grid-template-columns: minmax(0, 1fr) minmax(70px, 1fr) minmax(0, 1fr);
        align-items: center;
        gap: 14px;
        margin-top: 21px;
        padding: 18px;
        border-radius: 16px;
        background: var(--surface-subtle);
    }

    .time-block {
        min-width: 0;
        display: grid;
        gap: 2px;
    }

    .time-block:last-child {
        text-align: right;
    }

    .time-label,
    .time-detail {
        color: var(--secondary);
        font-size: 11px;
    }

    .time-value {
        font-size: 25px;
        line-height: 1.1;
        letter-spacing: -0.035em;
        font-variant-numeric: tabular-nums;
    }

    .planned-time {
        margin-left: 4px;
        color: var(--secondary);
        font-size: 12px;
        font-weight: 500;
        text-decoration: line-through;
    }

    .time-detail.late {
        color: var(--exclude);
        font-weight: 620;
    }

    .time-connector {
        display: flex;
        align-items: center;
    }

    .time-connector span:first-child {
        flex: 1;
        height: 1px;
        background: var(--line-strong);
    }

    .time-connector span:last-child {
        width: 7px;
        height: 7px;
        margin-left: -1px;
        border-top: 1px solid var(--line-strong);
        border-right: 1px solid var(--line-strong);
        transform: rotate(45deg);
    }

    .route-details {
        margin-top: 10px;
        border-top: 1px solid var(--line);
    }

    .route-details summary {
        padding: 15px 2px 4px;
        color: var(--accent);
        font-size: 13px;
        font-weight: 620;
        list-style: none;
    }

    .route-details summary::-webkit-details-marker {
        display: none;
    }

    .timeline {
        margin: 13px 0 3px;
        padding: 0;
        list-style: none;
    }

    .timeline-stop {
        position: relative;
        min-height: 54px;
        display: grid;
        grid-template-columns: 18px 1fr;
        gap: 11px;
    }

    .timeline-stop::before {
        content: "";
        position: absolute;
        top: 14px;
        bottom: -4px;
        left: 6px;
        width: 2px;
        background: var(--line-strong);
    }

    .timeline-stop:last-child::before {
        display: none;
    }

    .timeline-marker {
        position: relative;
        z-index: 1;
        width: 14px;
        height: 14px;
        margin-top: 6px;
        border: 3px solid var(--surface-solid);
        border-radius: 50%;
        background: var(--secondary);
        box-shadow: 0 0 0 1px var(--line-strong);
    }

    .timeline-stop.boundary-stop .timeline-marker {
        background: var(--accent);
    }

    .timeline-stop.required-stop .timeline-marker {
        background: var(--include);
    }

    .timeline-stop.outside-segment {
        opacity: 0.44;
    }

    .timeline-stop.cancelled-stop {
        color: var(--exclude);
    }

    .timeline-body {
        padding-bottom: 15px;
    }

    .timeline-top {
        justify-content: flex-start;
        flex-wrap: wrap;
        gap: 7px;
    }

    .timeline-top strong {
        font-size: 13px;
    }

    .timeline-badges {
        display: inline-flex;
        flex-wrap: wrap;
        gap: 4px;
    }

    .timeline-badges .mini-badge {
        min-height: 20px;
        padding: 2px 6px;
        font-size: 9px;
    }

    .timeline-meta {
        display: block;
        margin-top: 3px;
        color: var(--secondary);
        font-size: 11px;
        font-variant-numeric: tabular-nums;
    }

    .empty-state,
    .notice {
        padding: 24px;
        border: 1px solid var(--line);
        border-radius: var(--radius-lg);
        background: var(--surface);
    }

    .empty-state h3 {
        font-size: 17px;
    }

    .empty-state p {
        margin-top: 5px;
        color: var(--secondary);
        font-size: 13px;
    }

    .notice.error {
        border-color: color-mix(in srgb, var(--exclude) 24%, var(--line));
        background: var(--exclude-bg);
        color: var(--exclude);
    }

    .skeleton-card {
        pointer-events: none;
    }

    .skeleton {
        border-radius: 7px;
        background: var(--surface-subtle);
        animation: pulse 1.15s ease-in-out infinite alternate;
    }

    .skeleton.wide {
        width: 42%;
        height: 24px;
    }

    .skeleton.medium {
        width: 25%;
        height: 12px;
        margin-top: 8px;
    }

    .skeleton-row {
        margin-top: 24px;
        display: flex;
        gap: 16px;
    }

    .skeleton.block {
        width: 50%;
        height: 64px;
    }

    @keyframes pulse {
        from { opacity: 0.45; }
        to { opacity: 0.9; }
    }

    .toast {
        position: fixed;
        z-index: 100;
        left: 50%;
        bottom: 24px;
        max-width: min(92vw, 520px);
        transform: translateX(-50%);
        padding: 10px 14px;
        border: 1px solid var(--line-strong);
        border-radius: 999px;
        background: color-mix(in srgb, var(--surface-solid) 90%, transparent);
        color: var(--text);
        box-shadow: 0 16px 40px rgba(0, 0, 0, 0.18);
        backdrop-filter: blur(20px);
        -webkit-backdrop-filter: blur(20px);
        font-size: 13px;
        font-weight: 570;
    }

    .login-page {
        display: grid;
        place-items: center;
        padding: 28px;
    }

    .login-shell {
        width: min(100%, 420px);
    }

    .login-card {
        padding: 32px;
        border-radius: var(--radius-xl);
    }

    .login-card .app-mark {
        margin-bottom: 25px;
    }

    .login-card h1 {
        margin-top: 6px;
        font-size: 36px;
        line-height: 1;
        letter-spacing: -0.045em;
    }

    .login-card > .muted {
        margin-top: 10px;
        font-size: 14px;
    }

    .login-form {
        margin-top: 25px;
        display: grid;
        gap: 15px;
    }

    .login-form .primary-button {
        width: 100%;
        margin-top: 3px;
    }

    .login-card .notice {
        margin-top: 18px;
        padding: 12px 13px;
        border-radius: 12px;
        font-size: 12px;
    }

    @media (max-width: 720px) {
        .page-shell {
            width: min(100% - 22px, 980px);
            padding-top: 42px;
        }

        .hero {
            margin-bottom: 26px;
            padding: 0 5px;
        }

        .route-grid {
            grid-template-columns: 1fr;
        }

        .swap-button {
            width: 38px;
            height: 38px;
            margin: -3px 0 -3px auto;
            transform: rotate(90deg);
        }

        .swap-button:active {
            transform: rotate(90deg) scale(0.97);
        }

        .time-grid,
        .filter-grid {
            grid-template-columns: 1fr;
        }

        .results-heading {
            align-items: start;
            flex-direction: column;
        }

        .results-heading > .muted {
            max-width: none;
            text-align: left;
        }

        .result-card-header {
            align-items: start;
        }

        .timing-row {
            grid-template-columns: 1fr 34px 1fr;
            gap: 8px;
            padding: 14px;
        }

        .time-value {
            font-size: 22px;
        }

        .result-badges {
            max-width: 45%;
        }
    }

    @media (max-width: 440px) {
        .topbar-inner {
            width: calc(100% - 22px);
        }

        .search-card,
        .login-card {
            border-radius: 22px;
        }

        .search-card {
            padding: 18px;
        }

        .section-heading {
            align-items: start;
        }

        .status-pill {
            display: none;
        }

        .result-card {
            padding: 17px;
        }

        .timing-row {
            grid-template-columns: 1fr;
        }

        .time-block:last-child {
            text-align: left;
        }

        .time-connector {
            display: none;
        }
    }

    @media (prefers-reduced-motion: reduce) {
        *,
        *::before,
        *::after {
            scroll-behavior: auto !important;
            animation-duration: 0.001ms !important;
            animation-iteration-count: 1 !important;
            transition-duration: 0.001ms !important;
        }
    }
}
