/*
 * Styles for the Taiwan travel-time map tool.
 * Color variables are wired to the site theme tokens so the page follows the
 * site's light/dark mode (controlled by :root[data-theme="dark"]).
 */

.ttm-root {
    /* Surface tokens — fall back to warm-cream defaults if the site CSS hasn't loaded. */
    --ttm-bg: var(--bg-color, #fdfbf7);
    --ttm-surface: var(--bg-card, #fff);
    --ttm-border: var(--border-color, #e4dfd5);
    --ttm-text: var(--text-main, #1f1e1c);
    --ttm-muted: var(--text-secondary, #6b6864);

    /* Map-specific tokens that don't have a site equivalent. */
    --ttm-island-fill: #f4f1ec;
    --ttm-island-stroke: #d4cfc4;
    --ttm-dim: #b9b5ad;
    --ttm-toolbar-reset-bg: #f4f1ec;

    /* Mode colors stay constant across themes (they're the legend swatches). */
    --ttm-hsr: #c0392b;
    --ttm-rail: #27ae60;
    --ttm-highway: #2f6fb5;
    --ttm-metro: #8e44ad;
    --ttm-plane: #e67e22;
    --ttm-ferry: #16a085;
    --ttm-select: #d4a017;

    font-family: -apple-system, BlinkMacSystemFont, "PingFang TC", "Microsoft JhengHei", sans-serif;
    color: var(--ttm-text);
    line-height: 1.55;
    max-width: 1200px;
    margin: 0 auto;
    padding: 24px;
    background: var(--ttm-bg);
    box-sizing: border-box;
}

:root[data-theme="dark"] .ttm-root {
    --ttm-island-fill: #1a2638;
    --ttm-island-stroke: #334155;
    --ttm-dim: #475569;
    --ttm-toolbar-reset-bg: #1e293b;
}

.ttm-root * {
    box-sizing: border-box;
}

.ttm-root h1 {
    margin: 0 0 4px;
    font-size: 24px;
    font-weight: 700;
    letter-spacing: -0.5px;
}

.ttm-root header p {
    margin: 0;
    color: var(--ttm-muted);
    font-size: 14px;
}

.ttm-header {
    position: relative;
}

.ttm-lang-switch {
    position: absolute;
    top: 0;
    right: 0;
    display: flex;
    gap: 4px;
}

.ttm-lang-btn {
    border: 1px solid var(--ttm-border);
    background: var(--ttm-surface);
    color: var(--ttm-muted);
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 12px;
    cursor: pointer;
    font-family: inherit;
}

.ttm-lang-btn.active {
    background: var(--ttm-text);
    color: var(--ttm-bg);
    border-color: var(--ttm-text);
}

.ttm-lang-btn:hover {
    border-color: var(--ttm-text);
}

.ttm-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    margin: 18px 0 14px;
}

.ttm-toolbar button {
    border: 1px solid var(--ttm-border);
    background: var(--ttm-surface);
    color: var(--ttm-text);
    padding: 6px 12px;
    border-radius: 999px;
    font-size: 13px;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s;
}

.ttm-toolbar button:hover {
    border-color: var(--ttm-text);
}

.ttm-toolbar button.active {
    background: var(--ttm-text);
    color: var(--ttm-bg);
    border-color: var(--ttm-text);
}

.ttm-toolbar .ttm-reset {
    background: var(--ttm-toolbar-reset-bg);
}

.ttm-toolbar .ttm-sep {
    width: 1px;
    height: 18px;
    background: var(--ttm-border);
    margin: 0 4px;
}

.ttm-layout {
    display: grid;
    grid-template-columns: 1fr 320px;
    gap: 20px;
    align-items: start;
}

@media (width <= 860px) {
    .ttm-layout {
        grid-template-columns: 1fr;
    }
}

.ttm-mapwrap {
    background: var(--ttm-surface);
    border: 1px solid var(--ttm-border);
    border-radius: 14px;
    padding: 8px;
    overflow: hidden;
}

.ttm-root svg.ttm-map {
    display: block;
    width: 100%;
    height: auto;
}

.ttm-info {
    background: var(--ttm-surface);
    border: 1px solid var(--ttm-border);
    border-radius: 14px;
    padding: 18px 20px;
    font-size: 14px;
    position: sticky;
    top: 20px;
}

.ttm-info h2 {
    margin: 0 0 6px;
    font-size: 17px;
    font-weight: 700;
}

.ttm-info .ttm-sub {
    color: var(--ttm-muted);
    font-size: 13px;
    margin: 0 0 6px;
}

.ttm-info hr {
    border: 0;
    border-top: 1px solid var(--ttm-border);
    margin: 14px 0;
}

.ttm-info h3 {
    margin: 0 0 8px;
    font-size: 11px;
    font-weight: 700;
    color: var(--ttm-muted);
    text-transform: uppercase;
    letter-spacing: 1px;
}

.ttm-legend {
    list-style: none;
    padding: 0;
    margin: 0;
    display: grid;
    gap: 7px;
}

.ttm-legend li {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 13px;
}

.ttm-legend .ttm-swatch {
    width: 26px;
    height: 3px;
    border-radius: 2px;
    flex-shrink: 0;
}

.ttm-legend .ttm-swatch.dashed {
    background-image: repeating-linear-gradient(90deg, currentcolor 0 5px, transparent 5px 9px);
    height: 3px;
}

.ttm-step {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 0;
    border-bottom: 1px dashed var(--ttm-border);
    font-size: 13px;
}

.ttm-step:last-child {
    border-bottom: 0;
}

.ttm-step .ttm-badge {
    display: inline-block;
    min-width: 38px;
    text-align: center;
    padding: 2px 6px;
    border-radius: 4px;
    font-size: 11px;
    color: white;
    font-weight: 600;
    flex-shrink: 0;
}

.ttm-step .ttm-step-main {
    flex: 1;
}

.ttm-step .ttm-step-via {
    font-size: 11px;
    color: var(--ttm-muted);
    margin-top: 2px;
}

.ttm-step .ttm-step-time {
    color: var(--ttm-muted);
    font-size: 12px;
    white-space: nowrap;
}

.ttm-total {
    margin-top: 12px;
    padding: 10px 14px;
    background: var(--ttm-bg);
    border-radius: 8px;
    font-weight: 700;
    font-size: 14px;
}

.ttm-island {
    fill: var(--ttm-island-fill);
    stroke: var(--ttm-island-stroke);
    stroke-width: 1.5;
}

.ttm-edge {
    fill: none;
    stroke-width: 2.5;
    stroke-linecap: round;
    transition: opacity 0.2s, stroke-width 0.2s;
}

.ttm-edge.dimmed {
    opacity: 0.14;
}

.ttm-edge.highlight {
    stroke-width: 4.5;
    opacity: 1;
}

.ttm-edge.hidden {
    display: none;
}

.ttm-edge.hsr {
    stroke: var(--ttm-hsr);
}

.ttm-edge.rail {
    stroke: var(--ttm-rail);
}

.ttm-edge.highway {
    stroke: var(--ttm-highway);
}

.ttm-edge.metro {
    stroke: var(--ttm-metro);
}

.ttm-edge.plane {
    stroke: var(--ttm-plane);
    stroke-dasharray: 7 5;
}

.ttm-edge.ferry {
    stroke: var(--ttm-ferry);
    stroke-dasharray: 2 5;
}

.ttm-node {
    cursor: pointer;
    outline: none;
}

.ttm-node circle {
    fill: var(--ttm-text);
    stroke: var(--ttm-surface);
    stroke-width: 2;
    transition: fill 0.15s, r 0.15s;
}

.ttm-node text {
    font-size: 12px;
    font-weight: 600;
    pointer-events: none;
    fill: var(--ttm-text);
}

.ttm-node:hover circle,
.ttm-node:focus-visible circle {
    fill: var(--ttm-select);
}

.ttm-node:focus-visible circle {
    stroke: var(--ttm-text);
    stroke-width: 3;
}

.ttm-node.selected circle {
    fill: var(--ttm-select);
    stroke: var(--ttm-text);
    stroke-width: 3;

    /* `r` is the SVG circle radius attribute, supported as a CSS property in
       modern browsers for animating size on selection. */
    /* stylelint-disable-next-line declaration-property-value-no-unknown */
    r: 8;
}

.ttm-node.dimmed text,
.ttm-node.dimmed circle {
    fill: var(--ttm-dim);
}

.ttm-footer-note {
    margin-top: 18px;
    font-size: 12px;
    color: var(--ttm-muted);
    text-align: center;
}
