/* --- CSS Variables for Modern Theme --- */
:root {
    --bg-color: #f0f2f5; /* 非常に明るいグレー */
    --surface-color: #ffffff;
    --primary-color: #0056b3; /* 深い青 */
    --secondary-color: #6c757d; /* サブテキスト用 */
    --text-color: #212529;
    --subtle-text-color: #868e96; /* より控えめなテキスト */
    --border-color: #e0e0e0;
    --shadow-color: rgba(0, 0, 0, 0.08); /* より強い影 */
    --hover-shadow-color: rgba(0, 0, 0, 0.15); /* ホバー時の影 */

    --up-train-color: #28a745;   /* 緑系 */
    --down-train-color: #fd7e14; /* オレンジ系 */
    --stop-color: #dc3545;     /* 赤 */
    --delay-color: #ffc107;    /* 黄色 */
    --early-color: #17a2b8;    /* シアン */
    --wait-color: #007bff;     /* 青 */
    --substitute-color: #6f42c1; /* 紫 */

    --info-bg-color: #e9f7ff;
    --info-border-color: #a5d8ff;
    --info-icon-color: #007bff;

    --suspended-bg-color: rgba(255, 192, 203, 0.4); /* 薄いピンク */
    --suspended-border-color: #ff69b4; /* 濃いピンク */

    --warning-bg-color: rgba(255, 235, 59, 0.3); /* 薄い黄色 */
    --warning-border-color: #ffc107; /* 濃い黄色 */

    --branch-line-color: #a3cc95; /* ライトグリーン/グレー */

    --light-gray-bg: #f8f8f8; /* 薄い灰色を追加 */
}

/* --- General Settings --- */
body {
    font-family: 'Inter', sans-serif; /* Interフォントを使用 */
    background-color: var(--bg-color);
    color: var(--text-color);
    display: flex;
    justify-content: center;
    padding: 20px; /* 全体のパディングを増やす */
    margin: 0;
    line-height: 1.6;
    min-height: 100vh;
    align-items: flex-start; /* 上部に寄せる */
    box-sizing: border-box;
}

.container {
    width: 95%;
    max-width: 900px;
    background-color: var(--surface-color);
    border-radius: 16px; /* 角をさらに丸く */
    box-shadow: 0 8px 30px var(--shadow-color); /* 影を強調 */
    padding: 30px; /* パディングを増やす */
    border: 1px solid var(--border-color);
    display: flex;
    flex-direction: column;
    min-height: calc(100vh - 40px); /* body paddingを考慮 */
    box-sizing: border-box;
}

header {
    text-align: center;
    padding-bottom: 20px;
    margin-bottom: 20px;
    border-bottom: 1px solid var(--border-color);
}

h1 {
    font-size: 2.2em; /* 大きな見出し */
    font-weight: 700; /* 太字 */
    color: var(--primary-color);
    margin: 0;
    letter-spacing: -0.5px; /* 文字間隔を調整 */
}

h2 {
    font-size: 1.4em;
    font-weight: 500;
    color: var(--secondary-color);
    margin-top: 5px;
}

#current-time {
    font-size: 1.2em;
    color: var(--subtle-text-color);
    font-weight: 600;
    margin-top: 10px;
}

/* --- Card Style --- */
.card {
    background-color: var(--surface-color);
    border-radius: 12px;
    box-shadow: 0 4px 15px var(--shadow-color);
    border: 1px solid var(--border-color);
    padding: 15px 20px;
    margin-bottom: 20px;
    transition: box-shadow 0.3s ease;
}

.card:hover {
    box-shadow: 0 6px 20px var(--hover-shadow-color);
}

/* --- Announcements --- */
#announcements-board {
    margin-bottom: 24px;
}

.announcement-item {
    display: flex;
    align-items: flex-start;
    gap: 12px;
    padding: 12px 16px;
    background-color: var(--info-bg-color);
    border: 1px solid var(--info-border-color);
    color: var(--primary-color);
    font-size: 0.95em;
    border-radius: 8px;
    margin-bottom: 8px;
    box-shadow: none; /* 個々のお知らせアイテムには影をつけない */
}
.announcement-item:last-child {
    margin-bottom: 0;
}

.announcement-icon {
    flex-shrink: 0;
    margin-top: 2px;
    width: 20px; /* アイコンサイズを少し大きく */
    height: 20px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.announcement-icon img {
    width: 100%;
    height: 100%;
    object-fit: contain;
}

/* --- Legend --- */
.legend {
    display: flex;
    justify-content: center;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px 24px;
    margin-bottom: 24px;
    font-size: 0.9em;
    color: var(--subtle-text-color);
    padding: 15px 20px; /* カードのパディング */
}

.legend-item {
    display: flex;
    align-items: center;
    gap: 8px;
}

.legend-icon {
    width: 28px; /* アイコンのコンテナサイズを調整 */
    height: 28px;
    display: flex;
    align-items: center;
    justify-content: center;
}

.legend-icon img {
    width: 25px; /* 画像の実際のサイズ */
    height: 25px;
    object-fit: contain;
}

/* --- Track Layout --- */
#train-guide-wrapper {
    position: relative;
    padding: 0 20px;
    flex-grow: 1;
    min-height: calc(100vh - 400px); /* ヘッダーやカードの高さに合わせて調整 */
    overflow-y: auto; /* スクロール可能にする */
    -webkit-overflow-scrolling: touch; /* iOSでのスムーズなスクロール */
    border-radius: 12px;
    background-color: var(--surface-color); /* 背景色を白に統一 */
    padding-top: 20px; /* 上部にパディング */
    padding-bottom: 20px; /* 下部にパディング */
}

#track {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 0;
    bottom: 0;
    width: 8px; /* 少し太く */
    background-color: var(--primary-color);
    z-index: 1;
    border-radius: 4px; /* 端を丸く */
}

#station-list {
    display: flex;
    flex-direction: column;
    height: 100%;
    position: relative; /* 駅の配置基準 */
}

.station {
    position: relative;
    display: flex;
    align-items: center;
    flex-grow: 1;
    font-size: 14px;
    min-height: 90px; /* 駅と駅の間の間隔を広げる */
    background-color: var(--light-gray-bg); /* 奇数駅（デフォルト）は薄い灰色 */
}

.station:nth-child(even) {
    background-color: var(--surface-color); /* 偶数駅は白 */
}

.station-marker {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    top: 50%;
    width: 18px; /* 少し大きく */
    height: 18px;
    background-color: var(--surface-color); /* マーカー内部は白 */
    border: 4px solid var(--primary-color); /* マーカーの枠線はプライマリカラー */
    border-radius: 50%;
    z-index: 4;
}

.station-name {
    position: absolute;
    left: 25px; /* 左端からの余白を増やす */
    top: calc(50% - 25px); /* アイコンとの重なりを避けるため調整 */
    white-space: nowrap;
    color: var(--text-color);
    font-size: 1.15em; /* フォントサイズを大きく */
    font-weight: 700; /* さらに太字 */
}

.station-icon-wrapper {
    position: absolute;
    left: 25px;
    top: calc(50% + 10px); /* 駅名の下に配置 */
    display: flex;
    align-items: center;
    justify-content: flex-start;
    width: auto;
    height: auto;
    z-index: 5;
    cursor: pointer;
}

.station-icon {
    width: 24px; /* アイコンのサイズを調整 */
    height: 24px;
    border-radius: 6px; /* 角を丸める */
    object-fit: cover;
    box-shadow: 0 1px 3px rgba(0,0,0,0.1);
}

/* 山陽線分岐のスタイル */
#sanyo-line-branch {
    position: absolute;
    left: calc(50% + 4px); /* Adjusted for new track width */
    width: 70px; /* Adjusted width */
    height: 35px; /* Adjusted height */
    border-left: 3px solid var(--branch-line-color);
    border-bottom: 3px solid var(--branch-line-color);
    border-bottom-left-radius: 35px;
    z-index: 1;
    pointer-events: none;
    box-sizing: border-box;
}

.sanyo-line-label {
    position: absolute;
    top: calc(100% + 5px);
    left: calc(100% - 20px); /* Adjusted horizontally */
    white-space: nowrap;
    font-size: 0.85em;
    color: var(--branch-line-color);
    text-align: right;
    font-weight: 600;
}

/* Style for Line Indicator (幡生駅) - 廃止。アイコンで表示 */
/* .line-indicator {} */

/* --- Suspended Section --- */
.suspended-section {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 24px; /* 少し太く */
    background-color: var(--suspended-bg-color);
    border-left: 2px solid var(--suspended-border-color);
    border-right: 2px solid var(--suspended-border-color);
    z-index: 5;
    cursor: pointer;
    border-radius: 4px; /* 角を丸く */
}

/* NEW: お知らせ範囲セクションのスタイル */
.info-range-section {
    position: absolute;
    left: 50%;
    transform: translateX(-50%);
    width: 24px; /* 少し太く */
    background-color: var(--warning-bg-color);
    border-left: 2px solid var(--warning-border-color);
    border-right: 2px solid var(--warning-border-color);
    z-index: 5;
    cursor: pointer;
    border-radius: 4px; /* 角を丸く */
}


/* --- Train Icons (画像用) --- */
.train {
    position: absolute;
    width: 45px; /* クリック可能な領域を拡大 */
    height: 45px;
    cursor: pointer;
    transition: top 1s linear;
    z-index: 10;
    display: flex;
    justify-content: center;
    align-items: center;
    border-radius: 50%; /* 丸い背景 */
    background-color: rgba(255, 255, 255, 0.9); /* 白い半透明背景 */
    box-shadow: 0 2px 8px rgba(0, 0, 0, 0.2); /* 影 */
    top: -10px; /* ここで列車アイコンの垂直位置を調整します。 */
                  /* 以前はJavaScriptで設定されていましたが、CSSで基準値を設定します。 */
}

.train img {
    width: 30px; /* 画像のサイズを少し大きく */
    height: 30px;
    object-fit: contain;
}

/* 各方向・状態の列車アイコンの位置調整 */
/* 線路の中心 (50%) からのオフセットを増やす */
.train.up-image,
.train.delayed-up-image,
.train.substitute-up-image {
    left: calc(50% + 4px - (45px / 2) + 25px); /* 線路右側へさらに20pxオフセット */
}

.train.down-image,
.train.delayed-down-image,
.train.substitute-down-image {
    left: calc(50% - 4px - (45px / 2) - 25px); /* 線路左側へさらに20pxオフセット */
}

.train.stopped-image,
.train.waiting-image {
    left: calc(50% - (45px / 2)); /* 線路の中心 */
}

/* NEW: 列車アイコンの上に表示される遅延/早発のテキスト */
.train-status-overlay {
    position: absolute;
    top: -18px; /* 画像にさらに近づけるために調整 */
    left: 50%;
    transform: translateX(-50%);
    font-size: 1.1em; /* 文字を大きく */
    font-weight: 800; /* 文字をさらに太く (Extra Bold) */
    white-space: nowrap;
    z-index: 11;
    text-shadow: 0 0 4px rgba(255,255,255,0.9), 0 0 4px rgba(255,255,255,0.9); /* 白い影を強くして視認性を向上 */
}

.train-status-overlay.delay {
    color: var(--delay-color); /* Orange */
}

.train-status-overlay.early {
    color: var(--early-color); /* Deep Sky Blue for early departure */
}


/* --- Tooltip --- */
.tooltip {
    display: none;
    position: fixed;
    background-color: var(--surface-color);
    color: var(--text-color);
    padding: 20px 25px; /* パディングを増やす */
    border-radius: 16px; /* 角を丸くする */
    font-size: 15px; /* フォントサイズを調整 */
    white-space: nowrap;
    z-index: 20;
    pointer-events: none;
    line-height: 1.6;
    box-shadow: 0 8px 30px var(--shadow-color); /* 影を強調 */
    border: 1px solid var(--border-color);
    text-align: left;
    min-width: 280px; /* 最小幅を設定 */
    max-width: 350px; /* 最大幅を設定 */
    opacity: 0; /* 初期状態は透明 */
    transition: opacity 0.2s ease, transform 0.2s ease; /* アニメーション */
    transform: translateY(10px); /* 少し下にずらして表示 */
}

.tooltip.active {
    opacity: 1;
    transform: translateY(0);
    pointer-events: auto; /* 表示時にクリックを許可 */
}

/* ツールチップ内のタイトル */
.tooltip h3 {
    font-size: 1.3em; /* タイトルを少し大きく */
    font-weight: 700; /* 太字 */
    margin-top: 0;
    margin-bottom: 8px;
    color: var(--primary-color);
}

.tooltip .sub-text {
    font-size: 0.9em; /* サブテキストを小さく */
    color: var(--subtle-text-color);
    margin-bottom: 15px;
    border-bottom: 1px solid var(--border-color);
    padding-bottom: 8px;
}

.tooltip .train-info-section {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    flex-wrap: wrap; /* 折り返しを許可 */
}

.tooltip .train-type-label {
    background-color: var(--primary-color); /* 青色の背景 */
    color: white;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: 0.9em;
    font-weight: bold;
    margin-right: 10px;
    flex-shrink: 0; /* 縮小しない */
}

.tooltip .train-main-info {
    font-size: 1.15em;
    font-weight: bold;
    color: var(--text-color);
    flex-grow: 1; /* 拡大を許可 */
    white-space: normal; /* 折り返しを許可 */
}

.tooltip .train-main-info span {
    font-weight: normal;
    color: var(--secondary-color); /* 行き先はサブカラー */
}

.tooltip .delay-status {
    font-weight: bold;
    color: var(--delay-color);
    margin-top: 5px; /* 上の要素との間隔 */
    margin-left: 0; /* 左寄せ */
    font-size: 1em;
    width: 100%; /* 全幅を使用 */
}

/* NEW: 乗りやすさ指標のスタイル */
.comfort-index-section {
    font-size: 0.95em;
    color: var(--text-color);
    margin-top: 10px;
    font-weight: normal;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
}

.comfort-index-section b {
    font-weight: bold;
    color: var(--secondary-color);
}

/* NEW: 各混雑度に応じた色定義 */
.comfort-value-very-empty {
    color: #28a745; /* とても空いています - 緑色 */
    font-weight: bold;
}

.comfort-value-empty {
    color: #17a2b8; /* 空いています - シアン系 */
    font-weight: bold;
}

.comfort-value-slightly-crowded {
    color: #ffc107; /* やや混雑 - 黄色 */
    font-weight: bold;
}

.comfort-value-crowded {
    color: #fd7e14; /* 混雑 - オレンジ色 */
    font-weight: bold;
}

.comfort-value-very-crowded {
    color: #dc3545; /* 非常に混雑 - 赤色 */
    font-weight: bold;
}

.comfort-value-unknown {
    color: #757575; /* 不明 - グレー */
    font-weight: bold;
}


.tooltip .next-station-arrival {
    font-size: 0.9em;
    color: var(--text-color);
    margin-top: 10px;
    margin-left: 0;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
}

.tooltip .next-station-arrival span {
    font-weight: bold;
    color: var(--primary-color); /* 駅名と時刻をプライマリカラーに */
}

.tooltip .disclaimer {
    font-size: 0.75em;
    color: var(--subtle-text-color);
    margin-top: 15px;
    padding-top: 10px;
    border-top: 1px dashed var(--border-color);
}

.tooltip .disclaimer::before {
    content: '● ';
    color: var(--subtle-text-color);
}

/* Responsive adjustments */
@media (max-width: 768px) {
    body {
        padding: 10px;
    }
    .container {
        padding: 20px;
        min-height: calc(100vh - 20px);
    }
    h1 {
        font-size: 1.8em;
    }
    h2 {
        font-size: 1.2em;
    }
    .legend {
        flex-direction: column;
        align-items: flex-start;
        gap: 10px;
    }
    .station-name {
        font-size: 1em;
        left: 15px;
        top: calc(50% - 20px);
    }
    .station-icon-wrapper {
        left: 15px;
        top: calc(50% + 5px);
    }
    .train {
        width: 40px;
        height: 40px;
    }
    .train img {
        width: 28px;
        height: 28px;
    }
    .train-status-overlay {
        font-size: 1em;
        top: -15px;
    }
    .tooltip {
        min-width: unset;
        width: 90%;
        left: 5% !important; /* 強制的に中央寄せ */
        transform: none !important;
        top: auto !important;
        bottom: 10px; /* 画面下部に固定 */
        right: 5%;
        white-space: normal;
    }
    .tooltip.active {
        transform: none; /* 下からスライドアップ */
    }
}
