:root {
    --bg:        #0d1117;
    --bg-soft:   #161b22;
    --bg-hover:  #1f2630;
    --line:      #263140;
    --text:      #e6edf3;
    --muted:     #8b98a5;
    --accent:    #3fb485;
    --warn:      #e3a008;
    --late:      #f0663f;
    --panel-w:   340px;
    --rail-w:     54px;
    --topbar-h:   48px;

    /* «Жидкое стекло»: панели лежат поверх карты и просвечивают.
       Тёмная полупрозрачная заливка + размытие того, что под ней. */
    --glass:     rgba(17, 23, 32, .26);
    --glass-str: rgba(17, 23, 32, .42);
    --glass-brd: rgba(255, 255, 255, .16);
    --glass-hi:  rgba(255, 255, 255, .10);
}

.glass {
    background: var(--glass);
    -webkit-backdrop-filter: blur(34px) saturate(190%);
    backdrop-filter: blur(34px) saturate(190%);
    box-shadow: inset 0 1px 0 var(--glass-hi), 0 8px 30px rgba(0, 0, 0, .35);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font: 14px/1.45 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
    -webkit-font-smoothing: antialiased;
}

/* Карта занимает всё окно, панели лежат поверх неё — как у Flightradar.
   Так при сворачивании панели карта не меняет размер и не дёргается. */
#app {
    position: relative;
    height: 100%;
    overflow: hidden;
}

#topbar {
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    height: var(--topbar-h);
    z-index: 900;
    display: flex;
    align-items: center;
    justify-content: center;
    border-bottom: 1px solid var(--glass-brd);
    background: var(--glass);
    -webkit-backdrop-filter: blur(34px) saturate(190%);
    backdrop-filter: blur(34px) saturate(190%);
    box-shadow: inset 0 -1px 0 var(--glass-hi), 0 4px 20px rgba(0, 0, 0, .30);
}

/* Логотип по центру полосы — тот же знак, что и на карте. */
.rr-logo {
    display: flex;
    align-items: center;
    gap: 6px;
    color: #e5b429;
    font-size: 15px;
    font-weight: 600;
    letter-spacing: .3px;
    user-select: none;
}

.rr-logo span { color: #dbe4ee; }
.rr-logo b    { color: #e5b429; font-weight: 700; }

/* ------------------------------------------------------------------ панель */

#panel {
    position: absolute;
    left: 0;
    top: var(--topbar-h);
    bottom: 0;
    width: var(--panel-w);
    z-index: 850;
    display: flex;
    flex-direction: column;
    min-height: 0;
    border-right: 1px solid var(--glass-brd);
    background: var(--glass);
    -webkit-backdrop-filter: blur(34px) saturate(190%);
    backdrop-filter: blur(34px) saturate(190%);
    box-shadow: inset -1px 0 0 var(--glass-hi), 6px 0 28px rgba(0, 0, 0, .32);
}

#brand {
    display: flex;
    gap: 12px;
    align-items: center;
    padding: 16px 16px 12px;
    position: relative;
}

/* ------------------------------------------------- сворачивание панели */

.panel-btn {
    display: grid;
    place-items: center;
    width: 28px;
    height: 28px;
    padding: 0;
    border: 1px solid var(--glass-brd);
    border-radius: 8px;
    background: rgba(255, 255, 255, .10);
    color: var(--text);
    font: 600 18px/1 -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    cursor: pointer;
    flex: 0 0 auto;
}

.panel-btn:hover {
    background: var(--accent);
    border-color: var(--accent);
    color: #06231a;
}

#panel-toggle {
    position: absolute;
    right: 12px;
    top: 16px;
    z-index: 5;
}

/* --------------------------------------------------- свёрнутое состояние
   Панель не исчезает совсем, а сжимается в узкую полосу: остаются только
   кнопка разворота и фильтр линий, поставленный вертикально. Так видно,
   какая линия выбрана, и переключаться можно не разворачивая панель. */

#panel {
    transition: width .24s cubic-bezier(.4, 0, .2, 1),
                height .24s cubic-bezier(.4, 0, .2, 1),
                left .24s cubic-bezier(.4, 0, .2, 1),
                border-radius .24s ease;
}

/* Свёрнутая панель не тянется во весь экран: это короткая плавающая
   полоса ровно под свои фильтры, прижатая к центру по высоте. */
body.panel-off #panel {
    width: var(--rail-w);
    left: 12px;
    top: 50%;
    bottom: auto;
    height: auto;
    max-height: calc(100% - var(--topbar-h) - 24px);
    transform: translateY(-50%);
    border: 1px solid var(--glass-brd);
    border-radius: 15px;
    overflow: hidden;
}

body.panel-off #brand,
body.panel-off #stats,
body.panel-off #list,
body.panel-off #foot { display: none; }

body.panel-off #panel-toggle {
    position: static;
    margin: 12px auto 6px;
}

body.panel-off #filter {
    flex-direction: column;
    flex-wrap: nowrap;
    align-items: center;
    justify-content: center;
    gap: 7px;
    padding: 8px 4px;
    overflow-y: auto;
}

body.panel-off #filter .chip {
    width: 38px;
    padding: 5px 0;
    text-align: center;
    font-size: 11px;
    font-weight: 600;
}

#brand h1 {
    margin: 0;
    text-shadow: 0 1px 3px rgba(0, 0, 0, .6);
    font-size: 17px;
    letter-spacing: .2px;
}

#brand p {
    margin: 2px 0 0;
    font-size: 12px;
    color: var(--muted);
}

.badge {
    display: grid;
    place-items: center;
    width: 38px;
    height: 38px;
    border-radius: 10px;
    background: var(--c, var(--accent));
    color: #06231a;
    font-weight: 700;
    font-size: 15px;
    flex: 0 0 auto;
}

#stats {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    border-block: 1px solid var(--glass-brd);
}

.stat {
    padding: 10px 8px;
    text-align: center;
    border-right: 1px solid var(--glass-brd);
}

.stat:last-child { border-right: 0; }

.stat b {
    display: block;
    font-size: 19px;
    font-variant-numeric: tabular-nums;
}

.stat span {
    font-size: 11px;
    color: var(--muted);
}

#filter {
    display: flex;
    gap: 6px;
    padding: 10px 12px;
    flex-wrap: wrap;
}

.chip {
    border: 1px solid var(--line);
    background: transparent;
    color: var(--muted);
    border-radius: 999px;
    padding: 4px 11px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
}

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

.chip.is-on {
    background: var(--chip, var(--accent));
    border-color: var(--chip, var(--accent));
    color: #06231a;
    font-weight: 600;
}

/* Метка линии рядом с номером поезда — когда линий на карте несколько. */
.line-tag {
    display: block;
    font-size: 9px;
    font-weight: 700;
    letter-spacing: .3px;
    opacity: .75;
    font-style: normal;
}

.badge-sm {
    display: inline-block;
    border-radius: 4px;
    padding: 0 5px;
    font-size: 11px;
    font-weight: 700;
    font-style: normal;
    color: #06231a;
    vertical-align: 2px;
}

#list {
    list-style: none;
    margin: 0;
    padding: 0 0 8px;
    overflow-y: auto;
    flex: 1 1 auto;
    min-height: 0;
}

#list li {
    display: grid;
    grid-template-columns: 46px 1fr auto;
    gap: 10px;
    align-items: center;
    padding: 9px 14px;
    border-bottom: 1px solid rgba(255, 255, 255, .06);
    cursor: pointer;
}

#list li:hover,
#list li.is-active { background: rgba(255, 255, 255, .07); }

#list .num {
    font-variant-numeric: tabular-nums;
    font-weight: 600;
    font-size: 13px;
    color: var(--accent);
}

#list .route {
    overflow: hidden;
}

#list .route b {
    display: block;
    font-weight: 500;
    font-size: 13px;
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
}

#list .route span {
    font-size: 11px;
    color: var(--muted);
    white-space: nowrap;
    text-overflow: ellipsis;
    overflow: hidden;
    display: block;
}

#list .meta {
    text-align: right;
    font-size: 11px;
    color: var(--muted);
    font-variant-numeric: tabular-nums;
}

#list .meta i {
    font-style: normal;
    display: block;
}

.late  { color: var(--late); }
.early { color: var(--accent); }
.dot-live {
    display: inline-block;
    width: 6px; height: 6px;
    border-radius: 50%;
    background: var(--accent);
    margin-right: 4px;
    vertical-align: 1px;
}

#foot {
    padding: 9px 14px 12px;
    border-top: 1px solid var(--glass-brd);
    font-size: 11px;
    color: var(--muted);
    display: grid;
    gap: 3px;
}


/* ------------------------------------------------------------------ карта */

#map {
    position: absolute;
    inset: 0;
    background: #0b0f14;
}

/* Кнопки масштаба убираем там, где управляют пальцем: щипок удобнее, а
   кнопки только лезут под руку. Признак — тип указателя, а не ширина:
   у раскладных телефонов экран шире 780 точек, и по ширине они попадали
   бы в «десктоп». Мышь и трекпад дают pointer: fine, палец — coarse. */
@media (pointer: coarse) {
    .leaflet-control-zoom { display: none; }
}

/* Кнопки карты не должны нырять под верхнюю полосу. */
.leaflet-top { top: var(--topbar-h); }

.leaflet-container {
    background: #0b0f14;
    font: inherit;
}

/* Тёмная подложка без сторонних сервисов: обычные тайлы OSM + фильтр. */
.tiles-dark {
    filter: grayscale(.72) invert(1) hue-rotate(180deg) brightness(.8) contrast(.92) saturate(.85);
}

.leaflet-control-attribution {
    background: rgba(13, 17, 23, .8) !important;
    color: var(--muted) !important;
}

.leaflet-control-attribution a { color: #7fb3ff !important; }


.train-icon { will-change: transform; }

.train-icon .body {
    transform-origin: 50% 50%;
    transition: transform .25s linear;
}

.train-icon svg { display: block; overflow: visible; }

.train-icon.is-late .hull  { fill: var(--late); }
.train-icon.is-sel  .hull  { stroke: #fff; stroke-width: 2.5; }

.train-label {
    position: absolute;
    left: 30px;
    top: 6px;
    font-size: 10.5px;
    font-weight: 700;
    color: var(--text);
    background: rgba(13, 17, 23, .85);
    border: 1px solid rgba(63, 180, 133, .35);
    border-radius: 4px;
    padding: 0 4px;
    white-space: nowrap;
    pointer-events: none;
    letter-spacing: .2px;
}

.train-icon.is-late .train-label { border-color: rgba(240, 102, 63, .45); }

/* Подпись станции — просто текст поверх карты, без «пузыря» Leaflet. */
.leaflet-tooltip.st-label {
    background: none;
    border: 0;
    box-shadow: none;
    padding: 0;
    margin: 0;
    font-size: 11px;
    font-weight: 500;
    color: #dfe7f0;
    text-shadow: 0 0 3px #000, 0 0 7px #000, 0 1px 2px #000;
    white-space: nowrap;
    pointer-events: none;
}

.leaflet-tooltip.st-label::before { display: none; }

/* На мелких масштабах подписи только мешают. */
.hide-stations .st-label  { display: none; }
.hide-numbers  .train-label { display: none; }

/* ------------------------------------------------------------- карточка */

#card {
    position: absolute;
    right: 14px;
    top: calc(var(--topbar-h) + 14px);
    width: 310px;
    max-height: calc(100% - 28px);
    overflow-y: auto;
    border: 1px solid var(--glass-brd);
    border-radius: 14px;
    background: var(--glass);
    -webkit-backdrop-filter: blur(34px) saturate(190%);
    backdrop-filter: blur(34px) saturate(190%);
    box-shadow: inset 0 1px 0 var(--glass-hi), 0 14px 44px rgba(0, 0, 0, .5);
    z-index: 1000;
    padding: 14px 16px 16px;
}

#card[hidden] { display: none; }

#card-close {
    position: absolute;
    right: 8px;
    top: 6px;
    background: none;
    border: 0;
    color: var(--muted);
    font-size: 22px;
    line-height: 1;
    cursor: pointer;
}

#card h2 {
    margin: 0 0 2px;
    font-size: 15px;
}

#card .sub {
    color: var(--muted);
    font-size: 12px;
    margin-bottom: 10px;
}

#card .facts {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 8px;
    margin-bottom: 12px;
}

#card .facts div {
    background: rgba(255, 255, 255, .07);
    border-radius: 8px;
    padding: 7px 8px;
}

#card .facts b {
    display: block;
    font-size: 14px;
    font-variant-numeric: tabular-nums;
}

#card .facts span {
    font-size: 10px;
    color: var(--muted);
}

#card ol {
    list-style: none;
    margin: 0;
    padding: 0;
    border-left: 2px solid var(--line);
}

#card ol li {
    position: relative;
    padding: 3px 0 3px 14px;
    font-size: 12.5px;
    display: flex;
    justify-content: space-between;
    gap: 8px;
}

#card ol li::before {
    content: "";
    position: absolute;
    left: -5px;
    top: 10px;
    width: 8px;
    height: 8px;
    border-radius: 50%;
    background: var(--line);
}

#card ol li.on::before { background: var(--accent); }
#card ol li.passed    { opacity: .5; }
#card ol li time      { color: var(--muted); font-variant-numeric: tabular-nums; }
#card ol li time.fact { color: var(--accent); }

#card ol li .times {
    display: flex;
    gap: 6px;
    flex: 0 0 auto;
    white-space: nowrap;
}

#card ol li .times time:first-child:not(:only-child) {
    text-decoration: line-through;
    opacity: .6;
}

/* ------------------------------------------------------------ адаптивность */

@media (max-width: 780px) {
    /* Панель превращается в нижнюю шторку поверх карты — как у
       Flightradar на телефоне. Свернутая остаётся низкой полосой
       с фильтром линий. */
    #panel {
        left: 0;
        right: 0;
        top: auto;
        bottom: 0;
        width: auto;
        height: 52%;
        border-right: 0;
        border-top: 1px solid var(--glass-brd);
        border-radius: 18px 18px 0 0;
        transition: height .24s cubic-bezier(.4, 0, .2, 1);
        box-shadow: inset 0 1px 0 var(--glass-hi), 0 -6px 28px rgba(0, 0, 0, .38);
    }

    /* Полоска-ручка сверху: подсказывает, что шторку можно тянуть. */
    #panel::before {
        content: "";
        position: absolute;
        top: 7px;
        left: 50%;
        width: 38px;
        height: 4px;
        margin-left: -19px;
        border-radius: 2px;
        background: rgba(255, 255, 255, .22);
    }

    #brand { padding-top: 18px; }

    body.panel-off #panel {
        left: 50%;
        right: auto;
        top: auto;
        bottom: 14px;
        width: auto;
        max-width: calc(100% - 24px);
        height: 52px;
        transform: translateX(-50%);
        display: flex;
        flex-direction: row-reverse;
        align-items: center;
        gap: 6px;
        padding: 0 10px;
        border: 1px solid var(--glass-brd);
        border-radius: 15px;
    }

    /* Ручка шторки нужна только развёрнутой панели. */
    body.panel-off #panel::before { display: none; }

    body.panel-off #panel-toggle { margin: 0; }

    body.panel-off #filter {
        flex-direction: row;
        flex-wrap: nowrap;          /* иначе кнопки уезжают на вторую строку */
        flex: 0 1 auto;
        align-items: center;
        justify-content: center;
        padding: 0;
        gap: 6px;
        overflow: visible;
    }

    body.panel-off #filter .chip {
        width: auto;
        flex: 0 0 auto;
        padding: 5px 10px;
        font-size: 12px;
        line-height: 1.2;
    }

    #card {
        right: 8px;
        left: 8px;
        width: auto;
        max-height: 44%;
    }
}
