/* 全体のリセットと基本設定 */
body {
    font-family: "Helvetica Neue", Arial, "Hiragino Kaku Gothic ProN", "Hiragino Sans", Meiryo, sans-serif;
    background-color: #f4f5f7;
    margin: 0;
    padding: 0;
    color: #333;
}

/* ヘッダー */
header {
    background-color: #f4f5f7;
    padding: 15px 20px 10px;
}

.header-inner {
    display: flex;
    justify-content: space-between;
    align-items: center;
    max-width: 1000px;
    margin: 0 auto;
    border-bottom: 2px solid #ddd;
    padding-bottom: 10px;
}

h1 {
    font-size: 1.3rem;
    margin: 0;
    font-weight: bold;
}

.update-btn {
    background-color: #3b82f6;
    color: white;
    border: none;
    padding: 6px 12px;
    border-radius: 6px;
    font-size: 0.9rem;
    cursor: pointer;
    font-weight: bold;
}

.last-update {
    max-width: 1000px;
    margin: 6px auto 0;
    padding: 0 0 0 2px;
    font-size: 0.8rem;
    color: #888;
}

/* メインコンテンツ */
main {
    max-width: 1000px;
    margin: 0 auto;
    padding: 10px 20px 40px;
}

/* セクション見出し */
h2 {
    font-size: 1.1rem;
    margin-top: 30px;
    margin-bottom: 15px;
    font-weight: bold;
}

.map-section h2 {
    margin: 0;
}

.map-heading {
    display: flex;
    justify-content: space-between;
    align-items: end;
    gap: 12px;
    margin-bottom: 12px;
}

.map-subtitle,
.map-data-status,
.map-congestion-label,
.map-disclaimer {
    margin: 5px 0 0;
}

.map-subtitle,
.map-disclaimer {
    color: #64748b;
    font-size: 0.88rem;
}

.map-data-status {
    color: #166534;
    font-size: 0.9rem;
    font-weight: 700;
    text-align: right;
}

.map-card {
    padding: 14px;
}

.map-canvas {
    overflow: hidden;
    background: #e8f2e7;
}

.congestion-map {
    position: relative;
    display: block;
    width: 100%;
    aspect-ratio: 781 / 768;
    overflow: hidden;
    --queue-color: #16a34a;
    --queue-glow-blur: 3px;
    --queue-glow-opacity: 0.55;
}

.congestion-map[data-level="low"] {
    --queue-color: #16a34a;
    --queue-glow-blur: 3px;
    --queue-glow-opacity: 0.55;
}
.congestion-map[data-level="mid"] {
    --queue-color: #eab308;
    --queue-glow-blur: 5px;
    --queue-glow-opacity: 0.7;
}
.congestion-map[data-level="busy"] {
    --queue-color: #f97316;
    --queue-glow-blur: 7px;
    --queue-glow-opacity: 0.85;
}
.congestion-map[data-level="high"] {
    --queue-color: #dc2626;
    --queue-glow-blur: 10px;
    --queue-glow-opacity: 1;
}
.congestion-map[data-status="stale"],
.congestion-map[data-status="error"],
.congestion-map[data-status="unavailable"] { --queue-color: #64748b; }

.map-reference {
    display: block;
    width: 100%;
    height: 100%;
}

.map-overlay {
    position: absolute;
    inset: 0;
    display: block;
    width: 100%;
    height: 100%;
    overflow: visible;
    pointer-events: none;
}

.queue-marker-glow {
    fill: none;
    stroke: var(--queue-color);
    stroke-width: 4;
    opacity: var(--queue-glow-opacity);
    filter: drop-shadow(0 0 var(--queue-glow-blur) var(--queue-color));
    transform-box: fill-box;
    transform-origin: center;
    animation: marker-glow 1.4s ease-in-out infinite alternate;
}

@keyframes marker-glow {
    from { opacity: calc(var(--queue-glow-opacity) * 0.55); }
    to { opacity: var(--queue-glow-opacity); }
}

@media (prefers-reduced-motion: reduce) {
    .queue-marker-glow {
        animation: none;
        opacity: var(--queue-glow-opacity);
    }
}

.map-ground {
    fill: #e5efd9;
}

.map-campus-green {
    fill: #9bd47f;
}

.map-field {
    fill: #f3e5b7;
}

.map-field-line {
    fill: none;
    stroke: #fff7dc;
    stroke-width: 7;
}

.map-courtyard {
    fill: #dfd1a0;
}

.map-crossroad-edge {
    fill: none;
    stroke: #aeb3b7;
    stroke-width: 58;
}

.map-crossroad {
    fill: none;
    stroke: #c9cdd0;
    stroke-width: 50;
}

.map-crossroad-marking {
    fill: none;
    stroke: #f7f8f8;
    stroke-width: 2;
}

.map-road-edge {
    fill: none;
    stroke: #cbd2d9;
    stroke-width: 46;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.map-road {
    fill: none;
    stroke: #e7ebef;
    stroke-width: 40;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.map-road-marking {
    fill: none;
    stroke: #ffffff;
    stroke-width: 3;
    stroke-dasharray: 18 15;
    stroke-linecap: round;
}

.map-building {
    fill: #9299ac;
    stroke: #f3f5f8;
    stroke-width: 5;
}

.building-roof {
    fill: none;
    stroke: #bcc3d0;
    stroke-width: 4;
}

.map-parking {
    fill: #b7b9bf;
    stroke: #e7ece1;
    stroke-width: 8;
}

.parking-row {
    fill: none;
    stroke: #f4f4f1;
    stroke-width: 7;
}

.map-label {
    fill: #334155;
    font-family: inherit;
    font-size: 18px;
    font-weight: 700;
    text-anchor: middle;
}

.building-label,
.parking-label {
    font-size: 22px;
}

.campus-trees circle,
.map-shrubs circle {
    fill: #55a653;
    stroke: #79ba65;
    stroke-width: 2;
}

.map-greenery {
    fill: none;
    stroke: #80c969;
    stroke-width: 8;
}

.map-shrub {
    fill: #79bd72;
    stroke: #4d9950;
    stroke-width: 2;
}

.map-walkway {
    fill: none;
    stroke: #e7e2ca;
    stroke-width: 25;
    stroke-linecap: round;
}

.map-route {
    fill: none;
    stroke: #2563eb;
    stroke-width: 7;
    stroke-dasharray: 13 10;
    stroke-linecap: round;
    stroke-linejoin: round;
    filter: drop-shadow(0 1px 1px rgba(255, 255, 255, 0.9));
}

.map-gate-icon rect {
    fill: #dbeafe;
    stroke: #2563eb;
    stroke-width: 3;
}

.map-gate-icon path {
    stroke: #2563eb;
    stroke-width: 2;
}

.map-bus-stop-icon rect {
    fill: #fff;
    stroke: #dc2626;
    stroke-width: 3;
}

.map-bus-stop-icon path {
    fill: #fecaca;
    stroke: #dc2626;
    stroke-width: 2;
}

.map-bus-stop-icon circle {
    fill: #dc2626;
}

.map-place-label rect {
    fill: #fff;
    stroke-width: 3;
}

.gate-place-label rect {
    stroke: #2563eb;
}

.stop-place-label rect {
    stroke: #dc2626;
}

.map-place-label text {
    fill: #172554;
    font-family: inherit;
    font-size: 18px;
    font-weight: 800;
    text-anchor: middle;
}

.map-navigation-label rect {
    fill: rgba(255, 255, 255, 0.94);
    stroke: #bfdbfe;
    stroke-width: 2;
}

.map-navigation-label text {
    fill: #1e3a8a;
    font-family: inherit;
    font-size: 17px;
    font-weight: 800;
    text-anchor: middle;
}

.map-navigation-label .navigation-subtext {
    fill: #475569;
    font-size: 13px;
    font-weight: 600;
}

.north-indicator circle {
    fill: rgba(255, 255, 255, 0.9);
    stroke: #cbd5e1;
    stroke-width: 2;
}

.north-indicator path {
    fill: none;
    stroke: #334155;
    stroke-width: 3;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.north-indicator text {
    fill: #334155;
    font-family: inherit;
    font-size: 13px;
    font-weight: 700;
    text-anchor: middle;
}

.queue-path {
    fill: none;
    stroke: var(--queue-color);
    stroke-width: 7;
    stroke-dasharray: 3 9;
    stroke-linecap: round;
    opacity: 0.65;
}

.queue-marker {
    fill: var(--queue-color);
    stroke: #fff;
    stroke-width: 3;
}

.queue-marker-number {
    fill: #fff;
    font-family: inherit;
    font-size: 13px;
    font-weight: 800;
    text-anchor: middle;
    dominant-baseline: central;
}

.queue-head-label {
    fill: #334155;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    paint-order: stroke;
    stroke: #fff;
    stroke-width: 5px;
    stroke-linejoin: round;
}

.queue-tail-label {
    fill: #334155;
    font-family: inherit;
    font-size: 14px;
    font-weight: 700;
    paint-order: stroke;
    stroke: #fff;
    stroke-width: 5px;
    stroke-linejoin: round;
}

.map-unavailable {
    display: none;
}

.congestion-map[data-status="stale"] .map-unavailable,
.congestion-map[data-status="error"] .map-unavailable,
.congestion-map[data-status="unavailable"] .map-unavailable,
.congestion-map[data-status="loading"] .map-unavailable {
    display: block;
}

.map-unavailable rect {
    fill: rgba(255, 255, 255, 0.94);
    stroke: #94a3b8;
    stroke-width: 2;
}

.map-unavailable text {
    fill: #334155;
    font-family: inherit;
    font-size: 20px;
    font-weight: 700;
}

.map-caption {
    padding: 12px 4px 2px;
}

.map-congestion-label {
    color: #166534;
    font-size: 1.05rem;
    font-weight: 800;
}

.map-legend {
    display: flex;
    flex-wrap: wrap;
    gap: 8px 18px;
    margin-top: 10px;
    color: #475569;
    font-size: 0.82rem;
}

.map-legend span {
    display: inline-flex;
    align-items: center;
    gap: 6px;
}

.legend-dot {
    display: inline-block;
    width: 11px;
    height: 11px;
    border-radius: 50%;
}

.legend-dot.level-low { background: #16a34a; }
.legend-dot.level-mid { background: #eab308; }
.legend-dot.level-busy { background: #f97316; }
.legend-dot.level-high { background: #dc2626; }

.estimated-time h2 {
    border-bottom: 1px solid #ccc;
    padding-bottom: 8px;
}

/* カードの共通スタイル */
.card {
    background-color: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    padding: 20px;
}

/* --- 予想所要時間 --- */
.status-container {
    display: flex;
    gap: 20px;
}

.queue-info {
    flex: 1 1 200px;
    text-align: center;
    padding: 25px 15px;
    max-width: 360px;
}

.next-bus-summary {
    flex: 1 1 260px;
    min-width: 0;
    margin-bottom: 0;
    align-self: stretch;
}

.next-bus-summary .next-bus-inner {
    flex-wrap: wrap;
    gap: 8px 16px;
}

.queue-info .card-title {
    margin: 0;
    font-weight: bold;
    font-size: 1rem;
}

.secondary-count {
    margin: 0.75rem 0 0;
    color: #64748b;
    font-size: 0.9rem;
}

.queue-count {
    font-size: 4rem;
    color: #3b82f6;
    margin: 10px 0 0 0;
    font-weight: bold;
    line-height: 1;
    transition: color 0.4s ease;
}

.congestion-up-arrow {
    display: inline-block;
    width: 0.34em;
    height: 0.48em;
    margin-left: 0.07em;
    vertical-align: 0.04em;
    overflow: visible;
}

.congestion-up-arrow path {
    fill: none;
    stroke: currentColor;
    stroke-width: 2.2;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.queue-count.level-low { color: #16a34a; }
.queue-count.level-mid { color: #ca8a04; }
.queue-count.level-busy { color: #ea580c; }
.queue-count.level-high { color: #ef4444; }

.next-bus-info {
    margin-bottom: 15px;
    text-align: center;
}

.schedule-label {
    margin: 0 0 12px;
    color: #475569;
    font-weight: bold;
}

.next-bus-inner {
    display: flex;
    justify-content: center;
    gap: 18px;
    align-items: center;
}

.time-left {
    color: #166534;
    font-size: 1.25rem;
    font-weight: bold;
    margin: 12px 0;
}

.route-info {
    font-size: 1.1rem;
    font-weight: bold;
}
.time-text {
    color: #666;
    font-size: 1.2rem;
    font-weight: bold;
}

.schedule-status {
    color: #475569;
    font-size: 0.9rem;
    margin: 8px 0 0;
}

.ride-estimate {
    border-left: 4px solid #64748b;
}

.ride-estimate p {
    margin-bottom: 0;
}

/* --- 直近4本のバス情報 --- */
.bus-cards {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
}

.bus-card {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    padding: 20px 15px;
    display: flex;
    flex-direction: column;
    justify-content: space-between;
    min-height: 100px;
}

.bus-card.is-next {
    box-shadow: 0 0 0 2px #3b82f6, 0 2px 8px rgba(0,0,0,0.06);
}

.bus-card-top {
    display: flex;
    justify-content: space-between;
    align-items: flex-start;
    margin-bottom: 15px;
}

.route-name {
    font-weight: bold;
    font-size: 1rem;
    line-height: 1.4;
}

.route-time {
    color: #666;
    font-size: 0.95rem;
}

.bus-card-bottom {
    margin-top: auto;
}

.wait-time {
    color: #3b82f6;
    font-weight: bold;
    font-size: 0.95rem;
}

/* --- バス時刻表 --- */
.timetables {
    display: grid;
    grid-template-columns: repeat(4, 1fr);
    gap: 15px;
    align-items: start;
}

.timetable-wrapper {
    background: #fff;
    border-radius: 12px;
    box-shadow: 0 2px 8px rgba(0,0,0,0.06);
    padding: 20px 15px;
}

.timetable-wrapper h3 {
    text-align: center;
    margin: 0 0 15px 0;
    font-size: 1.1rem;
    font-weight: bold;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th, td {
    padding: 12px 8px;
    border-bottom: 1px solid #f0f0f0;
    font-size: 0.95rem;
}

th {
    background-color: #f8f9fa;
    font-weight: normal;
    color: #333;
}

th:nth-child(1), td:nth-child(1) {
    width: 40px;
    text-align: center;
}

th:nth-child(2), td:nth-child(2) {
    text-align: left;
    padding-left: 15px;
}

tr.highlight td {
    background: rgba(59, 130, 246, 0.08);
    color: #3b82f6;
    font-weight: bold;
}

/* --- エラーバナー --- */
.error-banner {
    position: relative;
    max-width: 960px;
    margin: 0 auto 12px;
    background: #ef4444;
    color: #fff;
    padding: 0.6rem 1.5rem;
    border-radius: 10px;
    z-index: 200;
    box-shadow: 0 4px 12px rgba(239, 68, 68, 0.4);
    font-weight: bold;
    font-size: 0.9rem;
}

.error-banner.hidden { display: none; }

/* スマホ表示対応 */
@media (max-width: 768px) {
    .map-heading {
        align-items: flex-start;
        flex-direction: column;
    }
    .map-data-status {
        text-align: left;
    }
    .map-card {
        padding: 9px;
    }
    .map-label {
        font-size: 21px;
    }
    .building-label,
    .parking-label {
        font-size: 25px;
    }
    .map-legend {
        gap: 8px 12px;
    }
    .status-container {
        display: grid;
        grid-template-columns: repeat(2, minmax(0, 1fr));
    }
    .queue-info {
        max-width: none;
        padding: 18px 8px;
    }
    .queue-info, .next-bus-info {
        flex: auto;
    }
    .next-bus-inner {
        flex-wrap: wrap;
        gap: 8px 16px;
    }
    .status-container {
        gap: 12px;
    }
    .queue-count {
        font-size: 3rem;
    }
    .next-bus-info, .ride-estimate {
        padding: 18px;
    }
    .bus-cards, .timetables {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 480px) {
    .map-label {
        font-size: 25px;
    }
    .route-label,
    .gate-label {
        font-size: 20px;
    }
    .map-unavailable text {
        font-size: 24px;
    }
    .map-disclaimer,
    .map-legend {
        font-size: 0.78rem;
    }
    .bus-cards, .timetables {
        grid-template-columns: 1fr;
    }
}