/* ==================================================
   mtrUI.css — 所有港鐵路線共用

   支援：
   1. 中央主線
   2. 左右支線
   3. Junction 分叉
   4. Reverse 匯合
   5. Pass 路線佔位格
   6. Merge 橫向橢圓站點
   7. Pill2 / Pill3 長圓點
   8. 橫向步行轉乘
   9. 末站下方步行轉乘

   所有路線共用排版。
   各路線 class 只設定配色。
   ================================================== */


/* ==================================================
   1. 可調整數值

   一般修改尺寸，只需修改這一區。

   注意：
   --mtr-link-step 控制長圓點內的轉線間距。
   如果把它加大，也應檢查 pill2 / pill3 行高
   是否仍然足夠。
   ================================================== */

:root {
    /* ---------- 每行高度 ---------- */

    /* 普通站 */
    --mtr-row-height: 60px;

    /* 兩條轉線站 */
    --mtr-pill2-row-height: 88px;

    /* 三條轉線站 */
    --mtr-pill3-row-height: 116px;


    /* ---------- 主線及圓點 ---------- */

    /* 路線粗幼 */
    --mtr-track-width: 10px;

    /* 普通圓點外部尺寸 */
    --mtr-dot-size: 30px;

    /* 圓點邊框 */
    --mtr-dot-border-width: 3px;

    /* 橫向橢圓站點 */
    --mtr-merge-dot-width: 36px;
    --mtr-merge-dot-height: 24px;


    /* ---------- 支線 ---------- */

    /* 左右支線距離中央的水平距離 */
    --mtr-branch-offset: 42px;

    /* 窄螢幕使用的支線距離 */
    --mtr-mobile-branch-offset: 36px;


    /* ---------- 轉線標示 ---------- */

    /* 多條轉線之間的垂直距離 */
    --mtr-link-step: 28px;

    /* 轉線文字距離圓心的水平距離 */
    --mtr-link-text-offset: 44px;

    /* 窄螢幕使用的文字距離 */
    --mtr-mobile-link-text-offset: 36px;

    /* 色條與文字之間的空隙 */
    --mtr-link-text-gap: 6px;

    /* 轉線色條高度 */
    --mtr-link-bar-height: 12px;


    /* ---------- 一般步行轉乘 ---------- */

    /* 主站與另一站的水平圓心距離 */
    --mtr-interchange-offset: 52px;

    /* 窄螢幕使用的圓心距離 */
    --mtr-mobile-interchange-offset: 46px;

    /* 步行虛線粗幼 */
    --mtr-walk-dotted-width: 2px;


    /* ---------- 末站下方步行轉乘 ---------- */

    /* 主站底部至另一站頂部的距離 */
    --mtr-terminal-walk-gap: 44px;

    /* 黑色垂直連線粗幼 */
    --mtr-walk-line-width: 6px;

    /* 下方轉乘站之後的留白 */
    --mtr-terminal-bottom-space: 24px;


    /* ---------- 路線容器留白 ---------- */

    --mtr-route-padding-top: 24px;
    --mtr-route-padding-bottom: 16px;


    /* ---------- 站名 ---------- */

    /* 站名與圓心的水平距離 */
    --mtr-label-offset: 28px;

    --mtr-station-name-size: 23px;
    --mtr-station-en-size: 12px;

    --mtr-mobile-station-name-size: 20px;
    --mtr-mobile-station-en-size: 10px;


    /* ---------- 轉線文字 ---------- */

    --mtr-link-font-size: 11px;
    --mtr-link-line-height: 12px;

    --mtr-mobile-link-font-size: 10px;
    --mtr-mobile-link-line-height: 11px;


    /* ---------- 外觀 ---------- */

    --mtr-map-background: #f1f1f5;
    --mtr-dot-background: #ffffff;
    --mtr-dot-border-color: #111111;

    --mtr-station-text-color: #3a295a;
    --mtr-link-text-color: #111111;
    --mtr-walk-line-color: #111111;

    --mtr-dot-hover-background: #e0f0ce;
}


/* ==================================================
   2. 路線配色

   --line-color：
       主路線線條顏色。

   --background-color：
       標題、轉線色條及 Speed Dial 顏色。
   ================================================== */

.line-airport,
.line-airportexpress {
    --line-color: #1c7670;
    --background-color: #1c7670;
}

.line-disneylandresort {
    --line-color: #f550a6;
    --background-color: #f550a6;
}

.line-eastrail {
    --line-color: #53b7e8;
    --background-color: #53b7e8;
}

.line-island {
    --line-color: #0860a8;
    --background-color: #0860a8;
}

.line-kwuntong {
    --line-color: #199439;
    --background-color: #199439;
}

.line-southisland {
    --line-color: #b5bd00;
    --background-color: #b5bd00;
}

.line-tseungkwano {
    --line-color: #80469a;
    --background-color: #80469a;
}

.line-tsuenwan {
    --line-color: #ff0000;
    --background-color: #ff0000;
}

.line-tuenma {
    --line-color: #9a3b26;
    --background-color: #9a3b26;
}

.line-tungchung {
    --line-color: #fe7f1d;
    --background-color: #fe7f1d;
}

.line-westrail {
    --line-color: #91107e;
    --background-color: #91107e;
}

.line-maonshan {
    --line-color: #9e4f18;
    --background-color: #9e4f18;
}

.line-lightrail {
    --line-color: #bfa23c;
    --background-color: #bfa23c;
}


/* ==================================================
   3. Header

   保留你提供的五組設定：
   #mtr-lines 內使用路線標題設定。
   其他位置仍可使用一般 header 置中設定。
   ================================================== */

.header {
    color: #fff;
    padding: 18px 0 12px 0;
    text-align: left;
    position: relative;
    background: var(--background-color);
}

#mtr-lines .header .title {
    display: inline-block;
    font-size: 28px;
    margin-left: 18px;
    padding-top: 20px;
    vertical-align: middle;
    font-weight: bold;
    letter-spacing: 2px;
    text-align: right;
    margin-top: -20px;
}

#mtr-lines .header .subtitle {
    display: block;
    font-size: 16px;
    margin-left: 18px;
    font-weight: normal;
    margin-top: -2px;
    margin-bottom: 10px;
    text-align: left;
}

.header .title {
    display: block;
    font-size: 28px;
    margin: 10px auto 0 auto;
    font-weight: bold;
    letter-spacing: 2px;
    text-align: center;
    vertical-align: middle;
}

.header .subtitle {
    display: block;
    font-size: 16px;
    margin: -2px auto 10px auto;
    font-weight: normal;
    text-align: center;
}


/* ==================================================
   4. 路線圖外層

   每條線佔滿容器寬度。
   若一次顯示多條線，會逐條向下排列。
   ================================================== */

#mtr-lines {
    display: flex;
    flex-wrap: wrap;
    justify-content: center;
    align-items: flex-start;

    width: 100%;
    max-width: none;

    margin: 0;
    padding: 0;

    gap: 0;
}

/* 只在路線圖內使用 border-box，不影響其他頁面 */
.mtr-map,
.mtr-map *,
.mtr-map::before,
.mtr-map::after,
.mtr-map *::before,
.mtr-map *::after {
    box-sizing: border-box;
}

.mtr-map {
    /*
       將集中設定的數值對應至元件變數。
       保留原本各個元件使用的變數名稱。
    */

    --normal-row-height: var(--mtr-row-height);
    --pill2-row-height: var(--mtr-pill2-row-height);
    --pill3-row-height: var(--mtr-pill3-row-height);

    --branch-offset: var(--mtr-branch-offset);

    --track-width: var(--mtr-track-width);
    --dot-size: var(--mtr-dot-size);
    --dot-border-width: var(--mtr-dot-border-width);

    --link-step: var(--mtr-link-step);
    --link-text-offset: var(--mtr-link-text-offset);

    --interchange-offset: var(--mtr-interchange-offset);

    --terminal-walk-gap: var(--mtr-terminal-walk-gap);
    --terminal-bottom-space: var(--mtr-terminal-bottom-space);
    --walk-line-width: var(--mtr-walk-line-width);

    --map-background: var(--mtr-map-background);
    --dot-background: var(--mtr-dot-background);
    --dot-border-color: var(--mtr-dot-border-color);

    --station-text-color: var(--mtr-station-text-color);
    --walk-line-color: var(--mtr-walk-line-color);

    flex: 0 0 100%;

    width: 100%;
    max-width: none;
    min-width: 0;

    margin: 0;

    background: var(--map-background);

    border-radius: 0;
    box-shadow: none;

    overflow: hidden;

    font-family:
        Arial,
        "PingFang TC",
        "Microsoft JhengHei",
        sans-serif;
}


/* ==================================================
   5. 路線排版容器
   ================================================== */

.mtr-map > .line-container {
    position: relative;

    display: flex;
    flex-wrap: wrap;
    align-items: stretch;

    width: 100%;
    margin: 0;

    padding:
        var(--mtr-route-padding-top)
        0
        var(--mtr-route-padding-bottom);

    isolation: isolate;
}


/* ==================================================
   6. 車站格子

   station：
       中央全寬。

   stations：
       左右半寬。
   ================================================== */

.mtr-map > .line-container > .station,
.mtr-map > .line-container > .stations {
    --point-x: 50%;
    --row-height: var(--normal-row-height);

    position: relative;

    height: var(--row-height);
    min-width: 0;
    min-height: 0;

    margin: 0;
    padding: 0;

    /*
       不在每個格子建立獨立堆疊層，
       讓圓點可以蓋住相鄰格子的連接線。
    */
    z-index: auto;
}

.mtr-map > .line-container > .station {
    flex: 0 0 100%;
    width: 100%;
}

.mtr-map > .line-container > .stations {
    flex: 0 0 50%;
    width: 50%;
}

.mtr-map > .line-container > .stations.left {
    --point-x: calc(100% - var(--branch-offset));
}

.mtr-map > .line-container > .stations.right {
    --point-x: var(--branch-offset);
}


/* ==================================================
   7. 站點尺寸

   node-height：
       用於連線及站名對齊。

   dot-width / dot-height：
       白色圓點實際外觀尺寸。
   ================================================== */

.mtr-map > .line-container > .station,
.mtr-map > .line-container > .stations,
.mtr-map .interchange {
    --node-height: var(--dot-size);

    --dot-width: var(--dot-size);
    --dot-height: var(--dot-size);
}

/*
   station-pill1 沿用普通圓點，
   不需要額外的尺寸設定。
*/

/* 兩條轉線：拉長圓點 */
.mtr-map :is(.station, .stations, .interchange).station-pill2 {
    --node-height: calc(
        var(--dot-size) + var(--link-step)
    );

    --dot-height: var(--node-height);
}

/* 三條轉線：拉長圓點 */
.mtr-map :is(.station, .stations, .interchange).station-pill3 {
    --node-height: calc(
        var(--dot-size)
        + var(--link-step)
        + var(--link-step)
    );

    --dot-height: var(--node-height);
}

/* 主線兩條轉線站的行高 */
.mtr-map > .line-container > .station.station-pill2 {
    --row-height: var(--pill2-row-height);
}

/* 主線三條轉線站的行高 */
.mtr-map > .line-container > .station.station-pill3 {
    --row-height: var(--pill3-row-height);
}

/* Merge：橫向橢圓，不改變連線中心 */
.mtr-map :is(.station, .stations).merge {
    --dot-width: var(--mtr-merge-dot-width);
    --dot-height: var(--mtr-merge-dot-height);
}


/* ==================================================
   8. 圓點／長圓點
   ================================================== */

.mtr-map .station-dot {
    position: absolute;

    top: calc(
        (var(--node-height) - var(--dot-height)) / 2
    );

    left: var(--point-x);

    width: var(--dot-width);
    height: var(--dot-height);

    margin: 0;
    padding: 0;

    background: var(--dot-background);

    border: var(--dot-border-width) solid
        var(--dot-border-color);

    border-radius: 999px;

    transform: translateX(-50%);

    cursor: pointer;

    z-index: 3;
}

.mtr-map .station-dot:hover {
    background: var(--mtr-dot-hover-background);
}


/* ==================================================
   9. 預設向下直線

   從本站中心連到下一行標準站點中心。
   路線端點由圓點蓋住。
   ================================================== */

.mtr-map > .line-container > .station::after,
.mtr-map > .line-container > .stations::after {
    content: "";

    position: absolute;

    top: calc(var(--node-height) / 2);

    left: calc(
        var(--point-x) - var(--track-width) / 2
    );

    width: var(--track-width);

    height: calc(
        var(--row-height)
        + var(--dot-size) / 2
        - var(--node-height) / 2
    );

    background: var(--line-color);

    pointer-events: none;

    z-index: 0;
}


/* ==================================================
   10. Reverse：左右向中央匯合
   ================================================== */

.mtr-map > .line-container > .stations.reverse::after {
    width: calc(
        var(--branch-offset) + var(--track-width)
    );
}

/* 左側向右下 */
.mtr-map > .line-container > .stations.left.reverse::after {
    clip-path: polygon(
        0 0,
        var(--track-width) 0,
        100% 100%,
        calc(100% - var(--track-width)) 100%
    );
}

/* 右側向左下 */
.mtr-map > .line-container > .stations.right.reverse::after {
    left: calc(0px - var(--track-width) / 2);

    clip-path: polygon(
        calc(100% - var(--track-width)) 0,
        100% 0,
        var(--track-width) 100%,
        0 100%
    );
}


/* ==================================================
   11. Junction：中央向左右分叉
   ================================================== */

.mtr-map > .line-container > .station.junction::before,
.mtr-map > .line-container > .station.junction::after {
    content: "";

    position: absolute;

    top: calc(var(--node-height) / 2);

    width: calc(
        var(--branch-offset) + var(--track-width)
    );

    height: calc(
        var(--row-height)
        + var(--dot-size) / 2
        - var(--node-height) / 2
    );

    background: var(--line-color);

    pointer-events: none;

    z-index: 0;
}

/* 中央向左下 */
.mtr-map > .line-container > .station.junction::before {
    left: calc(
        50%
        - var(--branch-offset)
        - var(--track-width) / 2
    );

    clip-path: polygon(
        calc(100% - var(--track-width)) 0,
        100% 0,
        var(--track-width) 100%,
        0 100%
    );
}

/* 中央向右下 */
.mtr-map > .line-container > .station.junction::after {
    left: calc(
        50% - var(--track-width) / 2
    );

    clip-path: polygon(
        0 0,
        var(--track-width) 0,
        100% 100%,
        calc(100% - var(--track-width)) 100%
    );
}


/* ==================================================
   12. Pass：沒有車站的路線佔位格
   ================================================== */

.mtr-map > .line-container > .pass > * {
    display: none;
}


/* ==================================================
   13. End：停止主路線

   不影響內部 interchange 的步行連線。
   ================================================== */

.mtr-map > .line-container > .end::before,
.mtr-map > .line-container > .end::after {
    content: none;
    display: none;
}


/* ==================================================
   14. 站名共用外觀
   ================================================== */

.mtr-map .station-name,
.mtr-map .station-en {
    position: absolute;

    margin: 0;
    padding: 0;

    color: var(--station-text-color);

    white-space: nowrap;

    z-index: 2;
}

.mtr-map .station-name {
    font-size: var(--mtr-station-name-size);
    font-weight: 700;

    line-height: 25px;
    letter-spacing: 1px;
}

.mtr-map .station-en {
    font-size: var(--mtr-station-en-size);
    line-height: 15px;
}


/* ==================================================
   15. 主線及支線站名位置

   使用直接子元素選擇器，
   不影響 interchange 裏面的站名。
   ================================================== */

.mtr-map > .line-container > :is(.station, .stations)
    > :is(.station-name, .station-en) {
    left: 0;

    width: calc(
        var(--point-x) - var(--mtr-label-offset)
    );

    text-align: right;
}

.mtr-map > .line-container > :is(.station, .stations)
    > .station-name {
    top: calc(
        var(--node-height) / 2 - 20px
    );
}

.mtr-map > .line-container > :is(.station, .stations)
    > .station-en {
    top: calc(
        var(--node-height) / 2 + 5px
    );
}

/* 右側支線：站名在圓點右側 */
.mtr-map > .line-container > .stations.right
    > :is(.station-name, .station-en) {
    left: calc(
        var(--point-x) + var(--mtr-label-offset)
    );

    width: calc(
        100%
        - var(--point-x)
        - var(--mtr-label-offset)
    );

    text-align: left;
}


/* ==================================================
   16. 轉線標示

   HTML：
   <div class="station-link line-xxx"
        data-line-name="XXX">
       中文<br>English
   </div>
   ================================================== */

.mtr-map .station-link {
    position: absolute;

    top: calc(var(--dot-size) / 2);

    left: calc(
        var(--point-x) + var(--link-text-offset)
    );

    width: max-content;

    margin: 0;
    padding: 0;

    color: var(--mtr-link-text-color);

    font-size: var(--mtr-link-font-size);
    line-height: var(--mtr-link-line-height);

    white-space: nowrap;

    transform: translateY(-50%);

    cursor: pointer;

    z-index: 1;
}

/* 轉線色條 */
.mtr-map .station-link::before {
    content: "";

    position: absolute;

    top: 50%;

    left: calc(
        0px - var(--link-text-offset)
    );

    width: calc(
        var(--link-text-offset) - var(--mtr-link-text-gap)
    );

    height: var(--mtr-link-bar-height);

    background: var(--background-color);

    border-radius: 0 7px 7px 0;

    transform: translateY(-50%);
}

/* 第二條轉線 */
.mtr-map .station-link ~ .station-link {
    top: calc(
        var(--dot-size) / 2
        + var(--link-step)
    );
}

/* 第三條轉線 */
.mtr-map .station-link ~ .station-link ~ .station-link {
    top: calc(
        var(--dot-size) / 2
        + var(--link-step)
        + var(--link-step)
    );
}


/* ==================================================
   17. 一般步行轉乘：右側排列

   非末站使用橫向虛線。
   ================================================== */

.mtr-map .station > .interchange {
    --point-x: 0px;

    position: absolute;

    top: 0;

    left: calc(
        50% + var(--interchange-offset)
    );

    width: 0;
    height: var(--node-height);

    margin: 0;
    padding: 0;
}

/* 橫向步行虛線 */
.mtr-map .interchange::before {
    content: "";

    position: absolute;

    top: calc(
        var(--dot-size) / 2
        - var(--mtr-walk-dotted-width) / 2
    );

    left: calc(
        0px - var(--interchange-offset)
    );

    width: var(--interchange-offset);
    height: 0;

    border-top:
        var(--mtr-walk-dotted-width)
        dotted
        var(--walk-line-color);

    pointer-events: none;

    z-index: 1;
}

/* 預設：另一個車站的站名在圓點下方 */
.mtr-map .interchange > .station-name,
.mtr-map .interchange > .station-en {
    left: -12px;

    width: max-content;

    text-align: left;
}

.mtr-map .interchange > .station-name {
    top: calc(
        var(--node-height) + 5px
    );
}

.mtr-map .interchange > .station-en {
    top: calc(
        var(--node-height) + 30px
    );
}

/* Top：另一個車站的站名放在圓點上方 */
.mtr-map .interchange.top > .station-name {
    top: -42px;
}

.mtr-map .interchange.top > .station-en {
    top: -17px;
}


/* ==================================================
   18. 末站步行轉乘：下方排列

   最後一個中央 station 包含 interchange：
   1. 停止主路線。
   2. 另一個車站移到下方中央。
   3. 改用黑色垂直實線。
   4. 預留另一個車站的高度。
   ================================================== */

/* 計算末站容器高度 */
.mtr-map > .line-container
    > .station:last-child:has(> .interchange) {
    --terminal-interchange-height: var(--dot-size);

    /*
       此變數在主站計算後再由 interchange 繼承，
       避免被子站自己的 node-height 改變。
    */
    --terminal-interchange-top: calc(
        var(--node-height) + var(--terminal-walk-gap)
    );

    height: calc(
        var(--terminal-interchange-top)
        + var(--terminal-interchange-height)
        + var(--terminal-bottom-space)
    );
}

/* 下方車站有兩條轉線 */
.mtr-map > .line-container
    > .station:last-child:has(
        > .interchange.station-pill2
    ) {
    --terminal-interchange-height: calc(
        var(--dot-size) + var(--link-step)
    );
}

/* 下方車站有三條轉線 */
.mtr-map > .line-container
    > .station:last-child:has(
        > .interchange.station-pill3
    ) {
    --terminal-interchange-height: calc(
        var(--dot-size)
        + var(--link-step)
        + var(--link-step)
    );
}

/* 停止主路線向下延伸 */
.mtr-map > .line-container
    > .station:last-child:has(> .interchange)::before,
.mtr-map > .line-container
    > .station:last-child:has(> .interchange)::after {
    content: none;
    display: none;
}

/* 另一個車站移到下方中央 */
.mtr-map > .line-container
    > .station:last-child > .interchange {
    top: var(--terminal-interchange-top);
    left: 50%;

    width: 0;
    height: var(--node-height);
}

/* 橫向虛線改為垂直黑色實線 */
.mtr-map > .line-container
    > .station:last-child > .interchange::before {
    content: "";
    display: block;

    top: calc(
        0px - var(--terminal-walk-gap)
    );

    left: calc(
        0px - var(--walk-line-width) / 2
    );

    width: var(--walk-line-width);
    height: var(--terminal-walk-gap);

    border: 0;
    background: var(--walk-line-color);

    transform: none;

    pointer-events: none;

    z-index: 1;
}

/* 下方車站：站名放左側 */
.mtr-map > .line-container
    > .station:last-child > .interchange
    > :is(.station-name, .station-en) {
    left: auto;
    right: var(--mtr-label-offset);

    width: max-content;

    text-align: right;
}

/* 對齊下方圓點／長圓點中央 */
.mtr-map > .line-container
    > .station:last-child > .interchange
    > .station-name {
    top: calc(
        var(--node-height) / 2 - 20px
    );
}

.mtr-map > .line-container
    > .station:last-child > .interchange
    > .station-en {
    top: calc(
        var(--node-height) / 2 + 5px
    );
}


/* ==================================================
   19. OnsenUI 路線選擇按鈕

   只套用有路線 class 的 speed-dial-item。
   ================================================== */

ons-speed-dial-item[class*="line-"] {
    background: var(--background-color) !important;
    color: #ffffff !important;
}


/* ==================================================
   20. 窄螢幕設定

   不更改 body，避免影響其他 OnsenUI page。
   ================================================== */

@media (max-width: 380px) {
    .mtr-map {
        --branch-offset: var(--mtr-mobile-branch-offset);

        --interchange-offset:
            var(--mtr-mobile-interchange-offset);

        --link-text-offset:
            var(--mtr-mobile-link-text-offset);
    }

    .mtr-map .station-name {
        font-size: var(--mtr-mobile-station-name-size);
    }

    .mtr-map .station-en {
        font-size: var(--mtr-mobile-station-en-size);
    }

    .mtr-map .station-link {
        font-size: var(--mtr-mobile-link-font-size);
        line-height: var(--mtr-mobile-link-line-height);
    }
}


/* ==================================================
   側邊繞行支線 — 測試元件

   結構：
   .side-bypass
       .station             第一行：大學
       .station             第二行：火炭
       .station             第三行：沙田
       .side-bypass-stop    第二行右側：馬場

   不修改原有 junction / reverse。
   ================================================== */


/* ---------- 元件容器 ---------- */

.mtr-map > .line-container > .side-bypass {
    /*
       右側支線距離中央的水平距離。

       clamp：
       隨畫面稍作調整，限制在 34px 至 42px。
    */
    --bypass-offset: clamp(34px, 10vw, 42px);

    /* 站點與文字之間的距離 */
    --bypass-label-gap: 10px;

    /* 容器右側安全留白 */
    --bypass-right-padding: 10px;

    /* 側邊站點使用一般圓點 */
    --node-height: var(--dot-size);
    --dot-width: var(--dot-size);
    --dot-height: var(--dot-size);

    position: relative;

    display: grid;
    grid-template-columns: minmax(0, 1fr);
    grid-template-rows: repeat(
        3,
        var(--normal-row-height)
    );

    flex: 0 0 100%;

    width: 100%;
    height: calc(
        var(--normal-row-height)
        + var(--normal-row-height)
        + var(--normal-row-height)
    );

    min-width: 0;
    margin: 0;
    padding: 0;

    z-index: auto;
}


/* ---------- 中央直線 ---------- */

.mtr-map .side-bypass::before {
    content: "";

    position: absolute;

    top: calc(var(--dot-size) / 2);

    left: calc(
        50% - var(--track-width) / 2
    );

    width: var(--track-width);

    /*
       從第一行站點中心，
       經第二、第三行，
       接到元件後下一站的中心。
    */
    height: calc(
        var(--normal-row-height)
        + var(--normal-row-height)
        + var(--normal-row-height)
    );

    background: var(--line-color);

    pointer-events: none;

    z-index: 0;
}


/* ---------- 右側半橢圓：上下各兩截 ---------- */

.mtr-map .side-bypass::after {
    content: "";

    position: absolute;

    top: calc(
        var(--dot-size) / 2
        - var(--track-width) / 2
    );

    left: calc(
        50%
        - var(--bypass-offset)
        - var(--track-width) / 2
    );

    width: calc(
        var(--bypass-offset)
        + var(--bypass-offset)
        + var(--track-width)
    );

    height: calc(
        var(--normal-row-height)
        + var(--normal-row-height)
        + var(--track-width)
    );

    /*
       先畫完整的實線橢圓，
       再用遮罩切出四截弧線。
    */
    border: var(--track-width) solid var(--line-color);
    border-radius: 50%;

    background: transparent;

    /* 只保留右半邊 */
    clip-path: inset(0 0 0 50%);

    /*
       角度由正上方開始，順時針計算：

       0–35°     第一截：靠近大學
       35–55°    空隙
       55–85°    第二截：靠近馬場上方

       85–95°    馬場圓點所在位置的空隙

       95–125°   第三截：靠近馬場下方
       125–145°  空隙
       145–180°  第四截：靠近沙田

       左半邊保持透明。
    */
    -webkit-mask-image: conic-gradient(
        from 0deg at 50% 50%,

        #000 0deg 35deg,
        transparent 35deg 55deg,

        #000 55deg 85deg,
        transparent 85deg 95deg,

        #000 95deg 125deg,
        transparent 125deg 145deg,

        #000 145deg 180deg,
        transparent 180deg 360deg
    );

    mask-image: conic-gradient(
        from 0deg at 50% 50%,

        #000 0deg 35deg,
        transparent 35deg 55deg,

        #000 55deg 85deg,
        transparent 85deg 95deg,

        #000 95deg 125deg,
        transparent 125deg 145deg,

        #000 145deg 180deg,
        transparent 180deg 360deg
    );

    pointer-events: none;

    z-index: 0;
}



/* ---------- 三個中央車站格子 ---------- */

.mtr-map .side-bypass > .station {
    --point-x: 50%;

    --node-height: var(--dot-size);
    --dot-width: var(--dot-size);
    --dot-height: var(--dot-size);

    position: relative;

    width: 100%;
    height: var(--normal-row-height);

    min-width: 0;
    margin: 0;
    padding: 0;

    z-index: auto;
}


/* ---------- 中央車站文字 ---------- */

.mtr-map .side-bypass > .station
    > :is(.station-name, .station-en) {
    left: 0;

    width: calc(
        50% - var(--mtr-label-offset)
    );

    text-align: right;
}

.mtr-map .side-bypass > .station
    > .station-name {
    top: calc(
        var(--node-height) / 2 - 20px
    );
}

.mtr-map .side-bypass > .station
    > .station-en {
    top: calc(
        var(--node-height) / 2 + 5px
    );
}


/* ---------- 右側車站：馬場 ---------- */

.mtr-map .side-bypass > .side-bypass-stop {
    --point-x: calc(
        50% + var(--bypass-offset)
    );

    --node-height: var(--dot-size);
    --dot-width: var(--dot-size);
    --dot-height: var(--dot-size);

    position: absolute;

    /* 與第二行火炭處於相同高度 */
    top: var(--normal-row-height);
    left: 0;

    width: 100%;
    height: var(--normal-row-height);

    margin: 0;
    padding: 0;

    z-index: auto;
}


/* ---------- 右側站名容器 ---------- */

.mtr-map .side-bypass-stop > .side-bypass-label {
    position: absolute;

    top: calc(var(--dot-size) / 2 - 20px);

    left: calc(
        50%
        + var(--bypass-offset)
        + var(--dot-size) / 2
        + var(--bypass-label-gap)
    );

    right: var(--bypass-right-padding);

    min-width: 0;

    text-align: left;

    z-index: 2;
}


/* ---------- 馬場中英文文字 ---------- */

.mtr-map .side-bypass-label > .station-name,
.mtr-map .side-bypass-label > .station-en {
    position: static;

    width: auto;
    max-width: 100%;

    margin: 0;
    padding: 0;

    text-align: left;
}

.mtr-map .side-bypass-label > .station-name {
    line-height: 25px;

    white-space: normal;
}

.mtr-map .side-bypass-label > .station-en {
    margin-top: 0;

    line-height: 15px;

    /*
       一般手機寬度可完整顯示 Racecourse。
       空間極少或文字放大時，允許換行，
       不用 nowrap / ellipsis 裁切。
    */
    white-space: normal;
    overflow-wrap: anywhere;
}