@font-face {
  font-family: "Sahel FD";
  src: url("https://cdn.jsdelivr.net/npm/sahel-font@3.4.0/dist/Farsi-Digits/Sahel-FD.woff2") format("woff2");
  font-weight: 400;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Sahel FD";
  src: url("https://cdn.jsdelivr.net/npm/sahel-font@3.4.0/dist/Farsi-Digits/Sahel-Bold-FD.woff2") format("woff2");
  font-weight: 700;
  font-style: normal;
  font-display: swap;
}

@font-face {
  font-family: "Sahel Black FD";
  src: url("https://cdn.jsdelivr.net/npm/sahel-font@3.4.0/dist/Farsi-Digits/Sahel-Black-FD.woff2") format("woff2");
  font-weight: 900;
  font-style: normal;
  font-display: swap;
}

@layer reset, base, components, utilities;

@layer reset {
  *, *::before, *::after { box-sizing: border-box; }
  html { scroll-behavior: smooth; }
  body, h1, h2, h3, h4, p, figure, fieldset { margin: 0; }
  button, input, select { font: inherit; }
  button { cursor: pointer; }
  img, svg { display: block; max-width: 100%; }
  a { color: inherit; }
}

@layer base {
  :root {
    --forest-950: #082821;
    --forest-900: #0d332b;
    --forest-800: #123f35;
    --forest-700: #1b594a;
    --forest-600: #2e765f;
    --forest-500: #4d9279;
    --sage-300: #a8c8b8;
    --sage-200: #c9ddd2;
    --sage-100: #e7f0eb;
    --sage-50: #f3f8f5;
    --sand-100: #f5efe3;
    --sand-50: #fbf8f2;
    --gold-500: #d49a37;
    --gold-400: #e6b75c;
    --gold-200: #f2d79d;
    --ink: #17302a;
    --muted: #64746f;
    --warm-white: #fbf7ee;
    --surface: var(--warm-white);
    --surface-soft: #f6f8f6;
    --line: #dfe7e2;
    --danger: #9f4737;
    --trip-short-bg: #dbeafe;
    --trip-short-border: #60a5fa;
    --trip-short-text: #1e3a8a;
    --trip-long-bg: #f3e8ff;
    --trip-long-border: #c084fc;
    --trip-long-text: #6b21a8;
    --shadow-sm: 0 8px 25px rgba(15, 55, 45, .07);
    --shadow-md: 0 18px 55px rgba(15, 55, 45, .11);
    --shadow-lg: 0 26px 80px rgba(15, 55, 45, .16);
    --radius-sm: 12px;
    --radius-md: 20px;
    --radius-lg: 30px;
    --shell: 1180px;
  }

  html[data-theme="dark"] {
    --ink: #eef6f1;
    --muted: #a6b7b0;
    --surface: #112d27;
    --surface-soft: #0d2520;
    --line: #28483f;
    --sage-50: #0b211c;
    --sage-100: #15362e;
    --sand-50: #122b25;
    --sand-100: #1a342d;
    --trip-short-bg: #173a63;
    --trip-short-border: #60a5fa;
    --trip-short-text: #dbeafe;
    --trip-long-bg: #3b1f52;
    --trip-long-border: #c084fc;
    --trip-long-text: #f3e8ff;
    --shadow-sm: 0 8px 25px rgba(0, 0, 0, .17);
    --shadow-md: 0 18px 55px rgba(0, 0, 0, .23);
    --shadow-lg: 0 26px 80px rgba(0, 0, 0, .3);
  }

  body {
    min-width: 320px;
    background: var(--sage-50);
    color: var(--ink);
    font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
  }

  ::selection { background: var(--gold-200); color: var(--forest-950); }

  .shell {
    width: min(calc(100% - 40px), var(--shell));
    margin-inline: auto;
  }

  h1, h2, h3, h4 { line-height: 1.12; letter-spacing: -.035em; }
  h1 { font-size: clamp(3.15rem, 7vw, 6.35rem); font-weight: 720; }
  h2 { font-size: clamp(2.05rem, 4vw, 3.35rem); font-weight: 700; }
  h3 { font-size: 1.35rem; }
  p { color: var(--muted); }

  .skip-link {
    position: fixed;
    inset: 12px auto auto 12px;
    transform: translateY(-160%);
    z-index: 1000;
    background: var(--forest-950);
    color: var(--warm-white);
    padding: 10px 14px;
    border-radius: 10px;
    text-decoration: none;
  }
  .skip-link:focus { transform: translateY(0); }
}

@layer components {
  .site-header {
    position: sticky;
    top: 0;
    z-index: 50;
    background: color-mix(in srgb, var(--surface) 88%, transparent);
    backdrop-filter: blur(18px);
    border-bottom: 1px solid color-mix(in srgb, var(--line) 70%, transparent);
  }

  .header-inner {
    min-height: 78px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 28px;
  }

  .brand-lockup,
  .brand, .footer-brand {
    display: inline-flex;
    align-items: center;
  }

  .brand, .footer-brand {
    gap: 11px;
    text-decoration: none;
  }

  .brand-logo-pair {
    display: inline-flex;
    flex: 0 0 auto;
    align-items: center;
    gap: 7px;
  }

  .brand-mark {
    width: 50px;
    height: 50px;
    padding: 4px;
    border-radius: 15px;
    overflow: hidden;
    background: #fcb303;
    box-shadow: inset 0 0 0 1px rgba(8,40,33,.1), 0 5px 14px rgba(8,40,33,.1);
  }
  .brand-mark img,
  .municipality-mark img { width: 100%; height: 100%; object-fit: contain; }
  .municipality-mark {
    width: 50px;
    height: 50px;
    padding: 3px;
    border: 1px solid var(--line);
    border-radius: 14px;
    overflow: hidden;
    background: var(--warm-white);
  }
  .brand strong { display: block; color: var(--ink); font-size: 1.08rem; line-height: 1.05; letter-spacing: -.02em; }
  .brand small { display: block; color: var(--muted); font-size: .72rem; margin-top: 4px; }

  .desktop-nav { display: flex; align-items: center; gap: 30px; }
  .desktop-nav a {
    position: relative;
    text-decoration: none;
    color: var(--muted);
    font-weight: 600;
    font-size: .92rem;
  }
  .desktop-nav a::after {
    content: "";
    position: absolute;
    height: 2px;
    inset: auto 50% -8px;
    background: var(--gold-500);
    border-radius: 2px;
    transition: inset .2s ease;
  }
  .desktop-nav a:hover { color: var(--ink); }
  .desktop-nav a:hover::after { inset-inline: 0; }

  .header-actions { display: flex; align-items: center; gap: 10px; }
  .source-link {
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 9px 13px;
    text-decoration: none;
    color: var(--muted);
    font-size: .82rem;
    font-weight: 650;
    background: var(--surface);
  }
  .source-link:hover { color: var(--forest-600); border-color: var(--sage-300); }

  .icon-button {
    width: 42px;
    height: 42px;
    display: grid;
    place-items: center;
    border: 1px solid var(--line);
    border-radius: 13px;
    color: var(--ink);
    background: var(--surface);
  }
  .icon-button svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .moon-icon { display: none; }
  html[data-theme="dark"] .sun-icon { display: none; }
  html[data-theme="dark"] .moon-icon { display: block; }

  .hero {
    position: relative;
    overflow: hidden;
    padding: 88px 0 118px;
    background:
      radial-gradient(circle at 0 0, color-mix(in srgb, var(--gold-200) 60%, transparent), transparent 30%),
      linear-gradient(145deg, var(--sand-50), var(--sage-50) 68%);
  }
  .hero::after {
    content: "";
    position: absolute;
    inset: auto 0 0;
    height: 90px;
    background: linear-gradient(to bottom, transparent, var(--sage-50));
    pointer-events: none;
  }
  .hero-orb { position: absolute; border-radius: 999px; filter: blur(2px); opacity: .7; pointer-events: none; }
  .hero-orb-one { width: 460px; height: 460px; right: -220px; top: -160px; background: color-mix(in srgb, var(--sage-200) 60%, transparent); }
  .hero-orb-two { width: 240px; height: 240px; left: 45%; bottom: -150px; background: color-mix(in srgb, var(--gold-200) 55%, transparent); }
  .hero-grid { position: relative; z-index: 1; display: grid; grid-template-columns: 1.1fr .9fr; align-items: center; gap: 70px; }

  .eyebrow {
    display: inline-flex;
    align-items: center;
    gap: 10px;
    color: var(--forest-600);
    text-transform: uppercase;
    font-size: .76rem;
    letter-spacing: .18em;
    font-weight: 800;
  }
  .eyebrow span { width: 28px; height: 1px; background: var(--gold-500); }
  .hero h1 { margin-top: 18px; max-width: 760px; color: var(--forest-950); }
  html[data-language="en"] .hero h1 { font-size: clamp(3rem, 6.1vw, 5.55rem); line-height: .86; }
  html[data-language="en"] .hero-title-move,
  html[data-language="en"] .hero-title-main {
    color: var(--forest-950);
    font-family: inherit;
    font-size: .92em;
    font-style: normal;
    font-weight: 720;
    letter-spacing: -.035em;
    text-transform: none;
  }
  html[data-theme="dark"][data-language="en"] .hero-title-move,
  html[data-theme="dark"][data-language="en"] .hero-title-main { color: var(--ink); }
  html[data-theme="dark"] .hero h1 { color: var(--ink); }
  .hero h1 em { color: var(--forest-600); font-family: Georgia, "Times New Roman", serif; font-weight: 500; }
  .hero-lead { margin-top: 26px; max-width: 610px; font-size: clamp(1.05rem, 2vw, 1.25rem); }

  .hero-facts { display: flex; gap: 38px; margin-top: 38px; }
  .hero-facts div { display: grid; gap: 1px; }
  .hero-facts strong { font-size: 1.15rem; color: var(--ink); }
  .hero-facts span { color: var(--muted); font-size: .78rem; }

  .line-preview {
    position: relative;
    background: color-mix(in srgb, var(--surface) 90%, transparent);
    border: 1px solid color-mix(in srgb, var(--line) 78%, transparent);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 24px;
    transform: rotate(1.3deg);
  }
  .line-preview::before {
    content: "";
    position: absolute;
    width: 90px;
    height: 90px;
    right: -22px;
    bottom: -26px;
    border: 1px solid var(--gold-200);
    border-radius: 50% 50% 12% 50%;
    transform: rotate(28deg);
    z-index: -1;
  }
  .line-preview-head { display: flex; justify-content: space-between; align-items: center; padding-bottom: 18px; border-bottom: 1px solid var(--line); font-size: .82rem; font-weight: 800; color: var(--forest-600); }
  .status-pill { display: inline-flex; align-items: center; gap: 7px; padding: 7px 10px; border-radius: 999px; background: var(--sage-100); color: var(--forest-700); font-weight: 700; font-size: .7rem; }
  .status-pill i { width: 7px; height: 7px; border-radius: 50%; background: #3b9b73; box-shadow: 0 0 0 4px rgba(59,155,115,.12); }

  .mini-map { position: relative; padding: 25px 0 15px 20px; }
  .mini-map::before { content: ""; position: absolute; left: 27px; top: 36px; bottom: 26px; width: 3px; background: linear-gradient(var(--gold-400), var(--forest-600)); border-radius: 3px; }
  .mini-station { position: relative; display: flex; align-items: center; gap: 18px; min-height: 69px; }
  .mini-station.faint { opacity: .67; }
  .mini-station .dot { position: relative; z-index: 1; flex: 0 0 auto; width: 16px; height: 16px; border: 4px solid var(--surface); border-radius: 50%; background: var(--forest-600); box-shadow: 0 0 0 2px var(--forest-600); }
  .mini-station .terminal { width: 18px; height: 18px; background: var(--gold-500); box-shadow: 0 0 0 2px var(--gold-500); }
  .mini-station strong { display: block; font-size: .92rem; color: var(--ink); }
  .mini-station small { display: block; margin-top: 2px; color: var(--muted); font-size: .72rem; }
  .train-chip { position: absolute; left: 12px; top: 154px; z-index: 2; width: 33px; height: 33px; border-radius: 10px; display: grid; place-items: center; color: var(--warm-white); background: var(--forest-800); box-shadow: 0 6px 18px rgba(18,63,53,.22); }
  .train-chip svg { width: 18px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
  .line-note { margin: 2px 0 0; padding-top: 16px; border-top: 1px solid var(--line); font-size: .74rem; }

  .planner-section, .matrix-section, .stations-section { padding: 104px 0; scroll-margin-top: 76px; }
  .planner-section { padding-top: 40px; }
  .section-heading { display: flex; align-items: end; justify-content: space-between; gap: 30px; margin-bottom: 38px; }
  .section-heading h2 { margin-top: 12px; }
  .section-heading p:not(.eyebrow) { max-width: 620px; margin-top: 12px; }
  .compact-heading { margin-bottom: 26px; }

  .text-button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    border: 1px solid var(--line);
    border-radius: 12px;
    background: var(--surface);
    color: var(--forest-600);
    padding: 10px 14px;
    font-weight: 750;
    font-size: .85rem;
  }
  .text-button svg { width: 17px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .text-button:hover { border-color: var(--sage-300); box-shadow: var(--shadow-sm); }

  .planner-layout { display: grid; grid-template-columns: minmax(0, .92fr) minmax(0, 1.08fr); gap: 24px; align-items: stretch; }
  .planner-card, .result-card {
    background: var(--surface);
    border: 1px solid var(--line);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
  }
  .planner-card { padding: clamp(22px, 4vw, 38px); }

  .station-fields { position: relative; display: grid; grid-template-columns: minmax(0,1fr) 46px minmax(0,1fr); align-items: end; gap: 14px; }
  .route-rail { display: none; }
  .field-group { display: grid; gap: 8px; }
  .field-group > span:first-child, .field-group > legend { color: var(--muted); font-size: .75rem; font-weight: 750; letter-spacing: .02em; }
  .select-wrap { position: relative; display: block; }
  .select-wrap::after {
    content: "";
    position: absolute;
    top: 50%;
    right: 17px;
    width: 7px;
    height: 7px;
    border-right: 1.5px solid var(--muted);
    border-bottom: 1.5px solid var(--muted);
    transform: translateY(-65%) rotate(45deg);
    pointer-events: none;
  }
  .select-wrap svg { position: absolute; left: 15px; top: 50%; transform: translateY(-50%); width: 19px; fill: none; stroke: var(--forest-600); stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; pointer-events: none; }
  select, .clock-input {
    width: 100%;
    min-height: 54px;
    color: var(--ink);
    background: var(--surface-soft);
    border: 1px solid var(--line);
    border-radius: 14px;
    outline: none;
    transition: border-color .18s ease, box-shadow .18s ease, background .18s ease;
  }
  .select-wrap select { padding: 0 44px 0 46px; appearance: none; }
  .clock-input {
    padding: 0 14px;
    direction: ltr;
    text-align: center;
    font-variant-numeric: tabular-nums;
  }
  select:focus, input:focus { border-color: var(--forest-500); box-shadow: 0 0 0 4px color-mix(in srgb, var(--forest-500) 16%, transparent); background: var(--surface); }

  .swap-button {
    width: 46px;
    height: 46px;
    display: grid;
    place-items: center;
    margin-bottom: 4px;
    border-radius: 14px;
    border: 1px solid var(--line);
    color: var(--forest-600);
    background: var(--surface-soft);
    transition: transform .2s ease, border-color .2s ease;
  }
  .swap-button:hover { transform: rotate(180deg); border-color: var(--sage-300); }
  .swap-button svg { width: 19px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }

  .planner-options { display: grid; grid-template-columns: minmax(125px, .72fr) minmax(0, 2.28fr); gap: 14px; margin-top: 22px; }
  .service-day-summary {
    min-width: 0;
    min-height: 76px;
    display: grid;
    align-content: center;
    gap: 1px;
    padding: 10px 14px;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: var(--surface-soft);
  }
  .service-day-summary > span, .station-service-summary > span { color: var(--muted); font-size: .66rem; font-weight: 750; }
  .service-day-summary strong, .station-service-summary strong { color: var(--forest-700); font-size: .82rem; }
  .service-day-summary small { color: var(--muted); font-size: .64rem; line-height: 1.45; }
  .service-day-summary[data-service="weekend"], .station-service-summary[data-service="weekend"] {
    border-color: color-mix(in srgb, var(--gold-500) 52%, var(--line));
    background: color-mix(in srgb, var(--gold-100) 62%, var(--surface));
  }

  .form-note { margin-top: 15px; font-size: .72rem; line-height: 1.6; }

  .result-card { position: relative; min-height: 472px; overflow: hidden; }
  .result-card::before { content: ""; position: absolute; width: 230px; height: 230px; right: -110px; top: -120px; border-radius: 50%; background: var(--sage-100); }
  .result-empty { position: relative; z-index: 1; min-height: 472px; padding: 40px; display: grid; place-items: center; align-content: center; text-align: center; }
  .result-empty-icon { width: 84px; height: 84px; margin-bottom: 22px; display: grid; place-items: center; border-radius: 28px 28px 28px 8px; color: var(--forest-600); background: var(--sage-100); }
  .result-empty-icon svg { width: 48px; fill: color-mix(in srgb, var(--forest-500) 20%, transparent); stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; }
  .result-empty p { max-width: 400px; margin-top: 10px; font-size: .9rem; }

  .result-content { position: relative; z-index: 1; padding: clamp(22px, 4vw, 36px); }
  .result-topline { display: flex; align-items: start; justify-content: space-between; gap: 18px; }
  .result-topline p { text-transform: uppercase; letter-spacing: .12em; color: var(--forest-600); font-size: .69rem; font-weight: 850; }
  .result-topline h3 { display: flex; align-items: center; gap: 9px; margin-top: 8px; font-size: clamp(1.15rem, 2.5vw, 1.55rem); }
  .result-topline h3 svg { width: 18px; flex: 0 0 auto; fill: none; stroke: var(--gold-500); stroke-width: 2; stroke-linecap: round; stroke-linejoin: round; }
  .result-badge {
    position: relative;
    z-index: 2;
    padding: 8px 11px;
    border: 1px solid var(--gold-500);
    border-radius: 999px;
    background: var(--gold-200);
    color: var(--forest-950);
    box-shadow: 0 5px 14px rgba(8,40,33,.14);
    white-space: nowrap;
    font-size: .68rem;
    font-weight: 850;
  }

  .journey-metrics { display: grid; grid-template-columns: .9fr 1.1fr; gap: 16px; margin-top: 26px; }
  .metric-primary, .metric-times { border: 1px solid var(--line); background: var(--surface-soft); border-radius: 18px; }
  .metric-primary { padding: 20px; }
  .metric-primary span, .metric-times span { display: block; color: var(--muted); font-size: .7rem; font-weight: 700; }
  .metric-primary strong { display: block; margin-top: 5px; font-size: 2.25rem; letter-spacing: -.06em; color: var(--forest-600); }
  .metric-primary small { color: var(--muted); font-size: .74rem; }
  .metric-times { display: grid; grid-template-columns: 1fr; }
  .metric-times > div { padding: 15px 17px; }
  .metric-times > div + div { border-top: 1px solid var(--line); }
  .metric-schedule-row { display: grid; grid-template-columns: 1fr 1fr; padding: 0 !important; }
  .metric-schedule-row > div { min-width: 0; padding: 15px 17px; }
  .metric-schedule-row > div + div { border-left: 1px solid var(--line); }
  .metric-times strong { display: block; margin-top: 7px; font-size: 1.45rem; }
  #departureCountdown { font-variant-numeric: tabular-nums; }

  .service-message { margin-top: 14px; padding: 12px 14px; border-radius: 12px; background: color-mix(in srgb, var(--gold-200) 45%, var(--surface)); color: var(--ink); font-size: .78rem; }

  .route-progress {
    position: relative;
    margin: 24px 0 20px;
    padding-bottom: 6px;
    overflow-x: auto;
    overflow-y: hidden;
    direction: ltr;
    scrollbar-width: thin;
    scrollbar-color: var(--sage-300) transparent;
  }
  .route-wave-track {
    --route-line: #d49a37;
    position: relative;
    width: max(100%, calc(var(--stop-count) * 76px));
    min-width: 100%;
    height: 250px;
    direction: ltr;
  }
  .route-wave-canvas { position: absolute; inset: 0; z-index: 0; pointer-events: none; }
  .progress-stop {
    position: absolute;
    left: var(--wave-x);
    top: calc(50% + var(--wave-y));
    z-index: 1;
    width: 102px;
    height: 86px;
    transform: translate(-50%, -50%);
    outline: none;
  }
  .progress-stop i {
    position: absolute;
    left: 50%;
    top: 50%;
    width: 15px;
    height: 15px;
    transform: translate(-50%, -50%);
    border: 4px solid var(--surface);
    border-radius: 50%;
    background: var(--route-line);
    box-shadow: 0 0 0 2px var(--route-line);
    transition: transform .2s ease, box-shadow .2s ease;
  }
  .progress-stop.terminal i { width: 19px; height: 19px; box-shadow: 0 0 0 2px var(--route-line), 0 0 0 7px color-mix(in srgb, var(--route-line) 20%, transparent); }
  .progress-stop span {
    position: absolute;
    top: calc(50% + 17px);
    left: 50%;
    width: 98px;
    padding: 4px 5px;
    transform: translateX(-50%);
    border: 1px solid transparent;
    border-radius: 9px;
    color: var(--muted);
    text-align: center;
    font-size: clamp(.61rem, 1vw, .72rem);
    font-weight: 650;
    line-height: 1.25;
    overflow-wrap: anywhere;
    transition: transform .2s ease, color .2s ease, background .2s ease, border-color .2s ease, box-shadow .2s ease;
  }
  .progress-stop.label-above span { top: auto; bottom: calc(50% + 17px); }
  .progress-stop.terminal span { color: var(--ink); font-size: clamp(.68rem, 1.08vw, .78rem); font-weight: 900; }
  .progress-stop:hover,
  .progress-stop:focus-visible { z-index: 4; }
  .progress-stop:hover span,
  .progress-stop:focus-visible span { transform: translate(-50%, -4px) scale(1.045); border-color: var(--route-line); color: var(--ink); background: color-mix(in srgb, var(--surface) 96%, transparent); box-shadow: 0 9px 22px rgba(8,40,33,.14); }
  .progress-stop:hover i,
  .progress-stop:focus-visible i { transform: translate(-50%, -50%) scale(1.25); box-shadow: 0 0 0 3px var(--surface), 0 0 0 7px color-mix(in srgb, var(--route-line) 38%, transparent); }

  .subhead-row { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  .subhead-row h4 { font-size: .92rem; }
  .subhead-row span { color: var(--muted); font-size: .68rem; }
  .departure-list { display: grid; grid-template-columns: repeat(5, 1fr); gap: 8px; margin-top: 12px; }
  .departure-time { padding: 10px 7px; border: 1px solid var(--line); border-radius: 11px; color: var(--ink); background: var(--surface-soft); text-align: center; font: inherit; font-weight: 750; font-size: .82rem; }
  .departure-time.next { border-color: var(--forest-500); background: var(--sage-100); color: var(--forest-700); }
  button.departure-time { cursor: pointer; transition: transform .18s ease, border-color .18s ease, background .18s ease, box-shadow .18s ease; }
  button.departure-time:hover { transform: translateY(-2px); border-color: var(--forest-500); background: var(--sage-100); box-shadow: var(--shadow-sm); }
  button.departure-time:focus-visible { outline: 2px solid var(--gold-500); outline-offset: 3px; }

  .matrix-section { background: var(--surface); }
  .matrix-heading { align-items: end; }
  .matrix-controls { display: flex; gap: 12px; }
  .matrix-controls label { display: grid; gap: 7px; color: var(--muted); font-size: .72rem; font-weight: 700; }
  .matrix-controls select, .matrix-controls input { min-width: 152px; min-height: 46px; padding: 0 12px; background: var(--surface-soft); }
  .matrix-controls select { appearance: auto; }
  .matrix-legend { display: flex; flex-wrap: wrap; align-items: center; gap: 18px; margin-bottom: 16px; color: var(--muted); font-size: .72rem; }
  .matrix-legend > span { display: inline-flex; align-items: center; gap: 7px; }
  .legend-dot { width: 10px; height: 10px; border-radius: 3px; }
  .legend-dot.short { background: var(--trip-short-bg); border: 1px solid var(--trip-short-border); }
  .legend-dot.medium { background: color-mix(in srgb, var(--gold-200) 65%, var(--surface)); border: 1px solid var(--gold-400); }
  .legend-dot.long { background: var(--trip-long-bg); border: 1px solid var(--trip-long-border); }
  .matrix-hint { margin-left: auto; }

  .matrix-shell { border: 1px solid var(--line); border-radius: 20px; overflow: hidden; box-shadow: var(--shadow-sm); background: var(--surface); }
  .matrix-scroll { overflow: auto; max-height: 690px; }
  .matrix-table { border-collapse: separate; border-spacing: 0; min-width: 1460px; width: 100%; font-size: .68rem; }
  .matrix-table th, .matrix-table td { min-width: 66px; height: 54px; padding: 6px; border-right: 1px solid var(--line); border-bottom: 1px solid var(--line); text-align: center; }
  .matrix-table thead th { position: sticky; top: 0; z-index: 4; background: var(--surface-soft); color: var(--muted); font-weight: 750; writing-mode: vertical-rl; transform: rotate(180deg); height: 140px; min-width: 66px; }
  .matrix-table thead th:first-child { left: 0; z-index: 6; writing-mode: horizontal-tb; transform: none; min-width: 175px; }
  .matrix-table tbody th { position: sticky; left: 0; z-index: 3; min-width: 175px; max-width: 175px; padding-left: 14px; background: var(--surface-soft); color: var(--ink); text-align: left; font-size: .74rem; }
  .matrix-cell { border: 0; width: 100%; height: 100%; border-radius: 9px; background: transparent; color: var(--ink); font-weight: 750; transition: transform .15s ease, box-shadow .15s ease; }
  .matrix-cell:hover, .matrix-cell:focus-visible { transform: translateY(-1px); box-shadow: inset 0 0 0 2px var(--forest-500); outline: none; }
  .matrix-cell.short { background: var(--trip-short-bg); color: var(--trip-short-text); box-shadow: inset 0 0 0 1px var(--trip-short-border); }
  .matrix-cell.medium { background: color-mix(in srgb, var(--gold-200) 55%, var(--surface)); }
  .matrix-cell.long { background: var(--trip-long-bg); color: var(--trip-long-text); box-shadow: inset 0 0 0 1px var(--trip-long-border); }
  .matrix-cell.same { color: var(--muted); background: var(--surface-soft); cursor: default; }
  .matrix-cell.selected { box-shadow: inset 0 0 0 2px var(--gold-500); }

  .station-service-summary { min-width: 170px; display: grid; gap: 1px; padding: 9px 13px; border: 1px solid var(--line); border-radius: 13px; background: var(--surface); }

  .station-list { position: relative; display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 12px 18px; }
  .station-list::before { content: ""; position: absolute; left: 50%; top: 30px; bottom: 30px; width: 1px; background: var(--line); }
  .station-item { position: relative; display: grid; grid-template-columns: 43px minmax(0,1fr) auto; align-items: center; gap: 14px; min-height: 82px; padding: 13px 16px; border: 1px solid var(--line); border-radius: 17px; background: var(--surface); transition: transform .15s ease, box-shadow .15s ease, border-color .15s ease; }
  .station-item:hover { transform: translateY(-2px); box-shadow: var(--shadow-sm); border-color: var(--sage-300); }
  .station-number { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 14px; color: var(--forest-700); background: var(--sage-100); font-weight: 850; font-size: .8rem; }
  .station-item.terminal .station-number { color: var(--forest-950); background: var(--gold-200); }
  .station-meta strong { display: block; font-size: .91rem; }
  .station-meta span { display: block; margin-top: 3px; color: var(--muted); font-size: .7rem; }
  .station-times { display: flex; gap: 16px; text-align: right; }
  .station-times span { display: block; color: var(--muted); font-size: .63rem; }
  .station-times strong { display: block; margin-top: 2px; font-size: .76rem; white-space: nowrap; }

  .service-note-section { padding: 12px 0 90px; scroll-margin-top: 76px; }
  .service-note-card { display: grid; grid-template-columns: auto 1fr auto; align-items: center; gap: 22px; padding: 28px 32px; border-radius: 24px; color: var(--warm-white); background: linear-gradient(135deg, var(--forest-900), var(--forest-700)); box-shadow: var(--shadow-md); }
  .service-note-card p { color: rgba(251,247,238,.72); margin-top: 5px; max-width: 700px; font-size: .85rem; }
  .service-note-card h2 { font-size: 1.35rem; letter-spacing: -.02em; }
  .service-note-icon { width: 48px; height: 48px; display: grid; place-items: center; border-radius: 15px; color: var(--gold-400); background: rgba(251,247,238,.08); }
  .service-note-icon svg { width: 23px; fill: none; stroke: currentColor; stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round; }
  .service-note-card > a { padding: 10px 13px; border: 1px solid rgba(251,247,238,.2); border-radius: 12px; text-decoration: none; white-space: nowrap; font-size: .78rem; font-weight: 750; }
  .service-note-card > a:hover { background: rgba(251,247,238,.08); }

  .site-footer { padding: 36px 0; border-top: 1px solid var(--line); background: var(--surface); }
  .footer-inner { display: flex; align-items: center; justify-content: space-between; gap: 25px; }
  .footer-brand .brand-mark,
  .footer-brand .municipality-mark { width: 42px; height: 42px; border-radius: 12px; }
  .footer-brand .brand-mark { padding: 3px; }
  .footer-brand strong { display: block; font-size: .92rem; }
  .footer-brand span { display: block; color: var(--muted); font-size: .68rem; }
  .footer-inner > p, .footer-inner > a { color: var(--muted); font-size: .72rem; }
  .footer-inner > a { text-decoration: none; font-weight: 700; cursor: pointer; }
  .footer-inner > a:hover { color: var(--forest-600); }
  .footer-inner > a:focus-visible { outline: 2px solid var(--gold-500); outline-offset: 5px; border-radius: 4px; }

  @media (min-width: 781px) {
    html[data-language="en"] .footer-inner { display: grid; grid-template-columns: 1fr minmax(280px, auto) 1fr; }
    html[data-language="en"] .footer-inner > p { text-align: center; }
    html[data-language="en"] .footer-inner > a { justify-self: end; }
  }

  @media (max-width: 980px) {
    .desktop-nav { display: none; }
    .hero { padding-top: 70px; }
    .hero-grid { grid-template-columns: 1fr 420px; gap: 35px; }
    .planner-layout { grid-template-columns: 1fr; }
    .result-card, .result-empty { min-height: 420px; }
    .station-list::before { display: none; }
    .station-list { grid-template-columns: 1fr; }
  }

  @media (max-width: 780px) {
    .shell { width: min(calc(100% - 28px), var(--shell)); }
    .header-inner { min-height: 68px; gap: 10px; }
    .source-link { display: none; }
    .hero { padding: 62px 0 92px; }
    .hero-grid { grid-template-columns: 1fr; }
    .hero-copy { text-align: center; }
    .hero .eyebrow { justify-content: center; }
    .hero-lead { margin-inline: auto; }
    .hero-facts { justify-content: center; }
    .line-preview { width: min(100%, 500px); margin-inline: auto; transform: none; }
    .planner-section, .matrix-section, .stations-section { padding: 78px 0; }
    .planner-section { padding-top: 24px; }
    .section-heading { align-items: flex-start; }
    .matrix-heading { align-items: flex-start; flex-direction: column; }
    .matrix-controls { width: 100%; }
    .matrix-controls label { flex: 1; }
    .matrix-controls select, .matrix-controls input { min-width: 0; }
    .matrix-hint { width: 100%; margin-left: 0; }
    .service-note-card { grid-template-columns: auto 1fr; }
    .service-note-card > a { grid-column: 1 / -1; text-align: center; }
    .footer-inner { flex-direction: column; text-align: center; }
  }

  @media (max-width: 620px) {
    h1 { font-size: clamp(2.7rem, 14vw, 4.4rem); }
    h2 { font-size: 2.2rem; }
    .brand small { display: none; }
    .hero-facts { gap: 18px; }
    .hero-facts div { min-width: 80px; }
    .line-preview { padding: 20px; }
    .section-heading { flex-direction: column; margin-bottom: 28px; }
    .text-button { align-self: flex-start; }
    .station-fields { grid-template-columns: 1fr; gap: 14px; padding-left: 22px; }
    .route-rail { position: absolute; left: 4px; top: 35px; bottom: 35px; display: flex; flex-direction: column; align-items: center; }
    .route-rail span { width: 10px; height: 10px; border-radius: 50%; background: var(--surface); box-shadow: 0 0 0 2px var(--forest-600); }
    .route-rail i { width: 2px; flex: 1; margin: 4px 0; background: var(--forest-600); }
    .swap-button { position: absolute; right: 4px; top: 72px; z-index: 2; width: 40px; height: 40px; background: var(--surface); }
    .planner-options { grid-template-columns: 1fr 1fr; }
    .journey-metrics { grid-template-columns: 1fr; }
    .result-topline { flex-direction: column; }
    .result-badge { order: -1; }
    .route-progress { margin-inline: 0; }
    .route-wave-track { width: max(100%, calc(var(--stop-count) * 70px)); height: 230px; }
    .progress-stop { width: 90px; }
    .progress-stop span { width: 88px; font-size: .58rem; }
    .departure-list { grid-template-columns: repeat(5, minmax(48px,1fr)); overflow-x: auto; }
    .matrix-controls { flex-direction: column; }
    .station-service-summary { width: 100%; }
    .station-item { grid-template-columns: 40px minmax(0,1fr); }
    .station-times { grid-column: 2; justify-content: flex-start; text-align: left; margin-top: -5px; }
    .service-note-card { padding: 24px; }
  }

  @media (max-width: 430px) {
    .shell { width: min(calc(100% - 20px), var(--shell)); }
    .header-actions { gap: 4px; }
    .hero-facts { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
    .hero-facts div { padding: 9px 5px; border: 1px solid var(--line); border-radius: 12px; background: color-mix(in srgb, var(--surface) 65%, transparent); }
    .hero-facts strong { font-size: .92rem; }
    .hero-facts span { font-size: .61rem; }
    .planner-card, .result-content { padding: 20px; }
    .planner-options { grid-template-columns: 1fr; }
    .metric-times { grid-template-columns: 1fr; }
    .metric-primary strong { font-size: 2rem; }
  }

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

@layer utilities {
  [hidden] { display: none !important; }
}

@layer components {
  .network-switch {
    display: inline-flex;
    gap: 6px;
    margin-top: 24px;
    padding: 5px;
    border: 1px solid var(--line);
    border-radius: 16px;
    background: color-mix(in srgb, var(--surface) 82%, transparent);
    box-shadow: var(--shadow-sm);
  }

  .network-switch button {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    min-height: 42px;
    padding: 0 15px;
    border: 0;
    border-radius: 11px;
    background: transparent;
    color: var(--muted);
    font-size: .78rem;
    font-weight: 800;
    transition: background .18s ease, color .18s ease, transform .18s ease;
  }

  .network-switch button:hover { transform: translateY(-1px); }
  .network-switch button.active { color: var(--warm-white); background: var(--forest-800); }
  html[data-line="line2"] .network-switch button.active { background: #286f8d; }

  .line-swatch { width: 9px; height: 9px; border-radius: 999px; }
  .line-swatch.line-one { background: var(--gold-500); }
  .line-swatch.line-two { background: #4b9bb8; }

  html[data-line="line2"] .line-preview::before {
    background: linear-gradient(135deg, rgba(75,155,184,.2), transparent 42%);
  }

  html[data-line="line2"] .line-preview-head { color: #397f9b; }
  html[data-line="line2"] .mini-map::before { background: linear-gradient(#83c3d8, #286f8d); }
  html[data-line="line2"] .mini-station .dot { border-color: #286f8d; }
  html[data-line="line2"] .mini-station .dot.terminal { background: #4b9bb8; border-color: #286f8d; }
  html[data-line="line2"] .train-chip { color: #286f8d; background: #e4f2f7; }
  html[data-line="line2"] .route-wave-track { --route-line: #4b9bb8; }

  .status-pill.limited { color: #286f8d; background: #e4f2f7; }
  .status-pill.limited i { background: #4b9bb8; box-shadow: 0 0 0 4px rgba(75,155,184,.14); }
  .mini-station.planned { opacity: .58; }
  .mini-station.planned .dot { background: var(--surface); border-style: dashed; }

  .line-field { margin-bottom: 16px; }
  .line-field .select-wrap { max-width: 100%; }

  .line-service-banner {
    display: grid;
    gap: 3px;
    margin-bottom: 24px;
    padding: 13px 15px;
    border: 1px solid var(--sage-200);
    border-radius: 14px;
    background: var(--sage-50);
  }

  .line-service-banner.banner-line1 {
    min-height: 68px;
    align-content: center;
  }

  .line-service-banner.banner-line2 {
    min-height: 44px;
    display: flex;
    align-items: center;
    padding-block: 9px;
  }

  .line-service-banner strong { color: var(--forest-700); font-size: .78rem; }
  .line-service-banner span { color: var(--muted); font-size: .7rem; }
  .line-service-banner.limited { border-color: color-mix(in srgb, #4b9bb8 35%, var(--line)); background: color-mix(in srgb, #e4f2f7 72%, var(--surface)); }
  .line-service-banner.limited strong { color: #286f8d; }

  .legend-dot.planned {
    background: repeating-linear-gradient(135deg, var(--surface-soft), var(--surface-soft) 4px, var(--line) 4px, var(--line) 7px);
    border: 1px solid var(--muted);
  }

  .matrix-cell.planned {
    color: var(--muted);
    background: repeating-linear-gradient(135deg, var(--surface-soft), var(--surface-soft) 6px, color-mix(in srgb, var(--line) 68%, transparent) 6px, color-mix(in srgb, var(--line) 68%, transparent) 9px);
  }

  .row-status {
    display: block;
    margin-top: 2px;
    color: var(--muted);
    font-size: .58rem;
    font-weight: 650;
  }

  .progress-stop.planned i {
    background: var(--surface);
    box-shadow: 0 0 0 2px var(--route-line);
    border-style: dashed;
  }

  .departure-time.unavailable {
    color: var(--muted);
    background: var(--surface-soft);
  }

  .station-item.planned-station {
    border-style: dashed;
    background: color-mix(in srgb, var(--surface-soft) 72%, var(--surface));
  }

  .station-item.planned-station .station-number {
    color: var(--muted);
    background: var(--surface-soft);
  }

  .station-item.planned-station .station-meta strong { color: var(--muted); }

  @media (max-width: 780px) {
    .network-switch { margin-inline: auto; }
  }

  @media (max-width: 620px) {
    .network-switch { width: 100%; }
    .network-switch button { flex: 1; justify-content: center; }
    .line-service-banner { margin-bottom: 20px; }
  }
}


@layer components {
  .language-button {
    min-height: 42px;
    display: inline-flex;
    align-items: center;
    gap: 7px;
    padding: 0 12px;
    border: 1px solid var(--line);
    border-radius: 12px;
    color: var(--ink);
    background: var(--surface);
    font-size: .76rem;
    font-weight: 800;
    transition: transform .18s ease, border-color .18s ease, background .18s ease;
  }

  .language-button:hover {
    transform: translateY(-1px);
    border-color: var(--sage-300);
    background: var(--surface-soft);
  }

  .language-button svg {
    width: 18px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.7;
    stroke-linecap: round;
    stroke-linejoin: round;
  }

  .language-button #languageToggleLabel[lang="fa"] {
    font-family: Vazirmatn, "Sahel FD", Tahoma, Arial, sans-serif;
    font-size: .86rem;
    font-weight: 700;
    line-height: 1;
  }

  .hero-title-line { display: inline-block; }
  .hero-copy > h1:first-child { margin-top: 0; }

  html[data-language="fa"] body {
    font-family: Vazirmatn, "Sahel FD", Tahoma, Arial, sans-serif;
    font-feature-settings: "ss01" 1, "tnum" 1;
    line-height: 1.75;
  }

  html[data-language="fa"] h1,
  html[data-language="fa"] h2,
  html[data-language="fa"] h3,
  html[data-language="fa"] h4,
  html[data-language="fa"] .brand strong,
  html[data-language="fa"] .footer-brand strong,
  html[data-language="fa"] .metric-primary strong {
    font-family: "Sahel Black FD", Vazirmatn, Tahoma, sans-serif;
    letter-spacing: 0;
  }

  html[data-language="fa"] .hero h1 {
    max-width: none;
    font-size: clamp(2.45rem, 4.2vw, 4rem);
    line-height: 1.22;
  }

  html[data-language="fa"] .hero-title-main {
    white-space: nowrap;
  }

  html[data-language="fa"] .hero h1 .hero-title-confidence {
    display: inline-block;
    margin-top: .08em;
    color: var(--forest-600);
    font-family: Vazirmatn, "Sahel FD", Tahoma, Arial, sans-serif;
    font-size: .92em;
    font-style: normal;
    font-weight: 700;
  }

  html[data-language="fa"] button,
  html[data-language="fa"] input,
  html[data-language="fa"] select,
  html[data-language="fa"] .eyebrow,
  html[data-language="fa"] .status-pill,
  html[data-language="fa"] .station-number,
  html[data-language="fa"] .departure-time,
  html[data-language="fa"] .matrix-table {
    font-family: "Sahel FD", Vazirmatn, Tahoma, sans-serif;
  }

  html[dir="rtl"] .skip-link { inset: 12px 12px auto auto; }
  html[dir="rtl"] .line-preview { transform: rotate(-1.35deg); }
  html[dir="rtl"] .line-preview::before { right: auto; left: -22px; }
  html[dir="rtl"] .mini-map { padding: 25px 20px 15px 0; }
  html[dir="rtl"] .mini-map::before { left: auto; right: 27px; }
  html[dir="rtl"] .train-chip { left: auto; right: 12px; }
  html[dir="rtl"] .progress-stop span { direction: rtl; }
  html[dir="rtl"] .select-wrap svg { left: auto; right: 15px; }
  html[dir="rtl"] .select-wrap::after { right: auto; left: 17px; }
  html[dir="rtl"] .select-wrap select {
    padding: 0 46px 0 44px;
  }
  html[dir="rtl"] .metric-times > div + div { border-left: 0; border-right: 0; border-top: 1px solid var(--line); }
  html[dir="rtl"] .metric-schedule-row > div + div { border-left: 0; border-right: 1px solid var(--line); border-top: 0; }
  html[dir="rtl"] .matrix-hint { margin-left: 0; margin-right: auto; }
  html[dir="rtl"] .matrix-scroll,
  html[dir="rtl"] .matrix-table { direction: rtl; }
  html[dir="rtl"] .matrix-table thead th:first-child { left: auto; right: 0; }
  html[dir="rtl"] .matrix-table tbody th {
    left: auto;
    right: 0;
    padding-left: 6px;
    padding-right: 14px;
    text-align: right;
  }
  html[dir="rtl"] .station-times { text-align: left; }
  html[dir="rtl"] .result-card::before { right: auto; left: -110px; }
  html[dir="rtl"] .result-topline h3 svg { transform: scaleX(-1); }
  html[dir="rtl"] .hero-orb-one { right: auto; left: -220px; }
  html[dir="rtl"] .hero-orb-two { left: auto; right: 45%; }

  @media (max-width: 780px) {
    html[dir="rtl"] .line-preview { transform: none; }
  }

  @media (max-width: 620px) {
    html[data-language="fa"] .hero h1 {
      font-size: clamp(1.72rem, 8.1vw, 2.75rem);
      line-height: 1.28;
    }
    html[dir="rtl"] .station-fields { padding-left: 0; padding-right: 22px; }
    html[dir="rtl"] .route-rail { left: auto; right: 4px; }
    html[dir="rtl"] .swap-button { right: auto; left: 4px; }
    html[dir="rtl"] .station-times { justify-content: flex-end; text-align: right; }
    html[dir="rtl"] .matrix-hint { margin-right: 0; }
  }

  @media (max-width: 430px) {
    .brand { gap: 8px; }
    .brand-logo-pair { gap: 4px; }
    .brand-mark,
    .municipality-mark { width: 40px; height: 40px; border-radius: 12px; }
    .brand-mark { padding: 3px; }
    .brand strong { font-size: .94rem; }
    .language-button { width: 42px; padding: 0; justify-content: center; }
    .language-button span {
      position: absolute;
      width: 1px;
      height: 1px;
      padding: 0;
      margin: -1px;
      overflow: hidden;
      clip: rect(0, 0, 0, 0);
      white-space: nowrap;
      border: 0;
    }
  }
}
