:root {
    --line-color: #ccc;
    --node-width: 140px;
    --gap-x: 40px;
    --gap-y: 100px;
}

.transit-map-wrapper {
    background: var(--glass-bg);
    border: 1px solid var(--border-color);
    padding: 60px 20px;
    border-radius: 30px;
    box-shadow: var(--shadow);
    overflow: hidden;
    position: relative;
    backdrop-filter: blur(10px);
    -webkit-backdrop-filter: blur(10px);
    margin: 40px 0;
    /* Mobile: allow horizontal scroll of entire map */
    overflow-x: auto;
    -webkit-overflow-scrolling: touch;
    touch-action: pan-x pan-y;
}

.transit-line {
    display: flex;
    flex-wrap: wrap;
    justify-content: flex-start;
    align-content: flex-start;
    position: relative;
    padding: 20px 0;
    width: 100%;
    margin: 0;
    gap: 100px 0;
}

.station-node-container {
    position: relative;
    display: flex;
    flex-direction: column;
    align-items: center;
    width: var(--node-width);
    height: 50px;
    z-index: 2;
}

.station-node-container::before {
    content: '';
    position: absolute;
    top: 13px;
    left: 50%;
    width: calc(var(--node-width) + var(--gap-x)); /* Spans to next node center */
    height: 10px;
    background: var(--line-color);
    transform: translateY(-50%);
    z-index: 1;
}

.station-node-container:last-child::before {
    display: none;
}

/* Hide line on last station of the line (manual class required or just let it overshoot if not wrapping) */
/* For wrapping, we'll use a slightly safer overflow:hidden on the wrapper */
.transit-line {
    display: flex;
    flex-wrap: wrap;
    justify-content: center; /* Center for better balance */
    position: relative;
    padding: 20px 0;
    width: 100%;
    margin: 0;
    gap: var(--gap-y) var(--gap-x);
}

.station-dot {
    width: 26px;
    height: 26px;
    background: white;
    border: 6px solid var(--line-color);
    border-radius: 50%;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    position: relative;
    z-index: 3;
}

.station-node-container:hover .station-dot {
    transform: scale(1.4);
    box-shadow: 0 0 15px rgba(0,0,0,0.2);
}

.station-name {
    position: absolute;
    top: 38px;
    left: 50%;
    transform: translateX(-50%);
    white-space: nowrap;
    font-weight: 800;
    font-size: 0.95rem;
    color: var(--text-primary);
    transition: all 0.3s ease;
    z-index: 10; /* Ensure labels are on top */
    text-align: center;
    width: 250px; /* Wider safety margin */
    pointer-events: none;
}

.station-name a {
    color: inherit;
    text-decoration: none;
    pointer-events: auto;
}

.direct-kanji {
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--text-secondary);
    margin-top: 1px;
    opacity: 0.85;
}

.direct-badges {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 5px;
    flex-wrap: wrap;
    max-width: 100%;
}

.mini-badge {
    width: 9px;
    height: 9px;
    border-radius: 50%; /* Dots look more 'transit-map' style */
    display: inline-block;
    box-shadow: 0 1px 3px rgba(0,0,0,0.4);
    border: 1.5px solid white; /* High contrast circle */
}

.station-node-container:hover .station-name {
    color: var(--line-color);
}

.station-tooltip {
    position: absolute;
    bottom: 50px;
    left: 50%;
    transform: translateX(-50%) translateY(10px);
    background: var(--card-bg);
    backdrop-filter: blur(10px);
    border-radius: 12px;
    padding: 15px;
    box-shadow: var(--shadow);
    border: 1px solid var(--border-color);
    opacity: 0;
    visibility: hidden;
    transition: all 0.3s cubic-bezier(0.175, 0.885, 0.32, 1.275);
    width: max-content;
    max-width: 220px;
    pointer-events: none;
    z-index: 10;
}

.station-node-container:hover .station-tooltip {
    opacity: 1;
    visibility: visible;
    transform: translateX(-50%) translateY(0);
}

.station-tooltip::after {
    content: '';
    position: absolute;
    bottom: -8px;
    left: 50%;
    transform: translateX(-50%);
    border-width: 8px 8px 0;
    border-style: solid;
    border-color: rgba(255, 255, 255, 0.95) transparent transparent transparent;
}

.tooltip-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 10px;
    border-bottom: 2px solid rgba(0,0,0,0.05);
    padding-bottom: 8px;
    gap: 15px;
}

.tooltip-kanji {
    font-weight: 800;
    font-size: 1.1rem;
    color: var(--text-primary);
}

.stat-code {
    display: inline-block;
    padding: 4px 10px;
    background: #334155;
    color: white;
    border-radius: 4px;
    font-weight: 800;
    font-family: 'Inter', monospace;
    font-size: 0.85rem;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.tooltip-transfers {
    display: flex;
    flex-wrap: wrap;
    gap: 5px;
}

.transfer-badge {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 3px 8px;
    border-radius: 4px; /* Default to JR-style square */
    font-size: 0.75rem;
    font-weight: 800;
    color: white;
    margin-bottom: 2px;
    box-shadow: 0 2px 5px rgba(0,0,0,0.1);
    white-space: nowrap;
    line-height: 1;
    min-width: 28px;
    text-align: center;
}

/* Official Operator Styles */
.badge-jr {
    border-radius: 4px;
}

.badge-subway {
    border-radius: 50%;
    border: 2px solid rgba(255, 255, 255, 0.8);
    width: 28px;
    height: 28px;
    padding: 0;
}

.badge-private {
    border-radius: 8px;
}

.badge-toei {
    border-radius: 6px;
    background: white !important;
    border: 4px solid var(--badge-color);
    color: #000 !important;
    width: 28px;
    height: 28px;
    padding: 0;
    box-sizing: border-box;
}

/* Mobile Layout */
@media (max-width: 768px) {
    .transit-map-wrapper {
        padding: 40px 15px;
        margin: 20px auto;
        overflow: hidden;
    }
    .transit-line {
        transform: none;
        width: 100%;
        margin: 0;
        flex-direction: column;
        align-items: stretch;
        justify-content: flex-start;
        gap: 0;
        padding-left: 0;
    }
    .station-node-container {
        transform: none;
        display: flex;
        flex-direction: column;
        align-items: flex-start;
        position: relative;
        width: 100%;
        height: auto;
        padding: 0 15px 15px 70px;
        box-sizing: border-box;
    }
    .station-node-container::before {
        content: '';
        position: absolute;
        top: -2px;
        left: 37px;
        width: 6px;
        height: calc(100% + 5px);
        background: var(--line-color);
        transform: none;
        z-index: 1;
    }
    .station-dot {
        position: absolute;
        left: 30px;
        top: 5px;
        width: 20px;
        height: 20px;
        border-width: 5px;
        margin: 0;
        z-index: 5;
    }
    .station-name {
        order: 1;
        position: relative;
        left: 0;
        top: 0;
        width: auto;
        transform: none;
        white-space: normal;
        font-size: 1.1rem;
        font-weight: 800;
        margin: 0;
        text-align: left;
        pointer-events: auto;
    }
    .direct-kanji {
        text-align: left;
        margin: 2px 0;
    }
    .direct-badges {
        justify-content: flex-start;
        gap: 6px;
        margin-top: 8px;
    }
    .mini-badge {
        width: 10px;
        height: 10px;
    }
    .station-tooltip {
        order: 2;
        position: static !important;
        transform: none !important;
        opacity: 0;
        max-height: 0;
        overflow: hidden;
        visibility: visible;
        background: transparent;
        border-radius: 0;
        padding: 0;
        box-shadow: none;
        border: none;
        width: auto;
        max-width: none;
        left: auto;
        bottom: auto;
        pointer-events: auto;
        transition: max-height 0.4s cubic-bezier(0.19, 1, 0.22, 1), opacity 0.3s ease, padding 0.3s ease;
    }
    /* Disable ALL desktop hover effects on mobile */
    .station-node-container:hover .station-tooltip {
        transform: none !important;
        position: static !important;
    }
    .station-node-container:hover .station-dot {
        transform: none;
        box-shadow: none;
    }
    .station-node-container:hover .station-name {
        transform: none;
        top: auto;
        color: inherit;
    }
    .is-active .station-tooltip {
        opacity: 1;
        max-height: 500px;
        padding: 5px 0 15px 0;
    }
    .station-tooltip::after {
        display: none;
    }
    .has-transfers .station-name::after {
        content: '\203A';
        display: inline-block;
        margin-left: 10px;
        font-size: 1.2rem;
        color: var(--text-secondary);
        transition: transform 0.3s ease;
    }
    .is-active .station-name::after {
        transform: rotate(90deg);
    }
    .tooltip-header {
        display: none;
    }
    .tooltip-transfers {
        padding-top: 5px;
    }
}

/* History & Heritage Timeline */
.history-section {
    margin-top: 50px;
    padding: 30px;
}

.history-timeline {
    position: relative;
    max-width: 800px;
    margin: 40px auto 0;
    padding-left: 30px;
}

.history-timeline::before {
    content: '';
    position: absolute;
    left: 0;
    top: 0;
    bottom: 0;
    width: 2px;
    background: var(--line-color);
}

.timeline-item {
    position: relative;
    margin-bottom: 30px;
    padding-left: 20px;
}

.timeline-item::before {
    content: '';
    position: absolute;
    left: -36px;
    top: 5px;
    width: 12px;
    height: 12px;
    background: var(--bg-color);
    border: 3px solid var(--line-color);
    border-radius: 50%;
    z-index: 2;
    box-shadow: 0 0 10px var(--line-color);
}

.timeline-date {
    display: block;
    font-weight: 900;
    font-size: 1.1rem;
    color: var(--line-color);
    margin-bottom: 5px;
    letter-spacing: 0.05em;
}

.timeline-content {
    background: rgba(255, 255, 255, 0.05);
    backdrop-filter: blur(10px);
    padding: 15px 20px;
    border-radius: 12px;
    border: 1px solid rgba(255, 255, 255, 0.1);
    color: var(--text-secondary);
    line-height: 1.5;
}

.timeline-content h4 {
    margin: 0 0 5px 0;
    color: var(--text-primary);
    font-size: 1rem;
}

/* Technical Specifications Table */
.spec-table-container {
    margin-top: 30px;
    background: rgba(255, 255, 255, 0.03);
    backdrop-filter: blur(10px);
    border: 1px solid rgba(255, 255, 255, 0.05);
    border-radius: 16px;
    padding: 2px;
    overflow-x: auto;
    margin-bottom: 40px;
}

.spec-table {
    width: 100%;
    border-collapse: collapse;
    color: var(--text-primary);
    font-size: 0.95rem;
    min-width: 600px;
}

.spec-table th {
    text-align: left;
    padding: 15px 20px;
    color: var(--line-color);
    border-bottom: 2px solid rgba(255, 255, 255, 0.1);
    font-weight: 800;
    text-transform: uppercase;
    letter-spacing: 0.05em;
    background: rgba(255, 255, 255, 0.02);
}

.spec-table td {
    padding: 12px 20px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.05);
}

.spec-table tr:last-child td {
    border-bottom: none;
}

.spec-table tr:hover {
    background: var(--glass-bg);
}

.spec-label {
    font-weight: 700;
    color: var(--text-secondary);
    width: 35%;
}
