* {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
    font-family: -apple-system, BlinkMacSystemFont, Roboto, 'Helvetica Neue', Arial, 'Hiragino Kaku Gothic ProN', 'Hiragino Sans', Meiryo, sans-serif;
}

html {
    background-color: #f1f5f9; /* ページ外側のベース背景色 */
}

body {
    background-color: #f9f4f1;
    color: #334155;
    line-height: 1.6;
    padding: 140px 0 0 0; /* 左右の余白はコンテナ側で制御 */
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}

/* =========================================================
   wxidx.com 共通固定ヘッダー（画面横幅いっぱい）
   ========================================================= */

.site-header {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    height: 58px;
    z-index: 1000;
    background: #0f172a; /* ヘッダー：ダークネイビー */
    border-bottom: 1px solid #1e293b;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
}

.site-header-inner {
    height: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 20px;
    display: flex;
    align-items: center;
}

.menu-button {
    width: 42px;
    height: 42px;
    margin: 0 8px 0 0;
    padding: 9px 8px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    cursor: pointer;
    display: flex;
    flex-direction: column;
    justify-content: center;
    gap: 5px;
}

.menu-button:hover {
    background: rgba(255, 255, 255, 0.1);
}

.menu-button:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.menu-button span {
    display: block;
    width: 24px;
    height: 2px;
    margin: 0 auto;
    border-radius: 999px;
    background: #f8fafc;
    transition: transform 0.2s ease, opacity 0.2s ease;
}

.site-brand {
    color: #ffffff;
    text-decoration: none;
    font-size: 20px;
    font-weight: 800;
    letter-spacing: -0.01em;
}

.menu-overlay {
    position: fixed;
    inset: 0;
    z-index: 1090;
    background: rgba(15, 23, 42, 0.6);
    backdrop-filter: blur(2px);
    opacity: 0;
    visibility: hidden;
    transition: opacity 0.2s ease, visibility 0.2s ease;
}

.site-menu {
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    width: min(320px, 86vw);
    z-index: 1100;
    background: #1e293b;
    box-shadow: 8px 0 24px rgba(0, 0, 0, 0.25);
    transform: translateX(-100%);
    transition: transform 0.25s ease;
    overflow-y: auto;
}

.site-menu-header {
    height: 58px;
    padding: 0 16px 0 20px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    border-bottom: 1px solid #334155;
}

.site-menu-title {
    font-size: 17px;
    font-weight: 700;
    color: #f8fafc;
}

.menu-close {
    width: 40px;
    height: 40px;
    border: 0;
    border-radius: 7px;
    background: transparent;
    color: #94a3b8;
    font-size: 30px;
    line-height: 1;
    cursor: pointer;
}

.menu-close:hover {
    background: rgba(255, 255, 255, 0.1);
    color: #ffffff;
}

.site-menu-links {
    padding: 12px;
}

.site-menu-link {
    display: flex;
    align-items: center;
    min-height: 46px;
    padding: 10px 14px;
    margin-bottom: 4px;
    border-radius: 7px;
    color: #cbd5e1;
    text-decoration: none;
    font-size: 15px;
    font-weight: 500;
}

.site-menu-link:hover {
    background: rgba(255, 255, 255, 0.08);
    color: #ffffff;
}

.site-menu-link.active {
    background: #2563eb;
    color: #ffffff;
    font-weight: 700;
}

body.menu-open {
    overflow: hidden;
}

body.menu-open .menu-overlay {
    opacity: 1;
    visibility: visible;
}

body.menu-open .site-menu {
    transform: translateX(0);
}

/* =========================================================
   コントロールバー（画面横幅いっぱい）
   ========================================================= */

.controls-bar {
    position: fixed;
    top: 58px;
    left: 0;
    right: 0;
    z-index: 900;
    background: #e2e8f0;
    border-bottom: 1px solid #cbd5e1;
    box-shadow: 0 2px 4px rgba(0, 0, 0, 0.04);
}

.controls-bar-inner {
    position: relative; /* 期間指定パネルの基準位置 */
    max-width: 1200px;
    margin: 0 auto;
    padding: 10px 30px 12px;
    display: flex;
    flex-direction: column;
    gap: 4px;
}

.controls-label {
    font-size: 12px;
    line-height: 1.2;
    color: #475569;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.05em;
}

/* 任意期間の指定パネル */
.range-panel {
    position: absolute;
    top: 100%;
    right: 30px;
    margin-top: 8px;
    padding: 14px 16px;
    width: max-content;
    max-width: calc(100vw - 24px);
    background: #e2e8f0; /* 期間選択バー（.controls-bar）と同じ色 */
    border: 1px solid #a1a9b3;
    border-radius: 10px;
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.15);
}

.range-panel[hidden] {
    display: none;
}

.range-fields {
    display: flex;
    align-items: flex-end;
    flex-wrap: wrap;
    gap: 10px;
}

.range-field {
    display: flex;
    flex-direction: column;
    gap: 3px;
    font-size: 12px;
    font-weight: 600;
    color: #64748b;
}

.range-field input[type="date"] {
    height: 36px;
    padding: 0 10px;
    border: 1px solid #cbd5e1;
    border-radius: 8px;
    background: #ffffff;
    color: #334155;
    font-size: 15px;
}

.range-field input[type="date"]:focus-visible,
.range-apply:focus-visible,
.btn:focus-visible {
    outline: 2px solid #3b82f6;
    outline-offset: 2px;
}

.range-sep {
    height: 36px;
    line-height: 36px;
    color: #64748b;
}

.range-apply {
    height: 36px;
    padding: 0 16px;
    border: 1px solid #2563eb;
    border-radius: 8px;
    background: #2563eb;
    color: #ffffff;
    font-size: 15px;
    cursor: pointer;
}

.range-apply:hover {
    background: #1d4ed8;
}

.range-note {
    margin-top: 8px;
    max-width: 440px;
    font-size: 13px;
    line-height: 1.5;
    color: #475569;
}

.range-note:empty {
    display: none;
}

.range-note.error {
    color: #dc2626;
}

/* =========================================================
   メインコンテンツエリア（中央寄せ）
   ========================================================= */

.container {
    max-width: 1200px;
    width: calc(100% - 40px);
    margin: 0 auto;
    background: #ffffff;
    border: 1px solid #cbd5e1;
    padding: 32px 32px 0px;
    flex: 1;
}

.page-header {
    margin-bottom: 25px;
    min-height: 92px;
    display: flex;
    flex-direction: column;
    justify-content: center;
}

.page-header h1 {
    font-size: 26px;
    font-weight: 800;
    color: #0f172a;
    letter-spacing: -0.02em;
}

.subtitle {
    font-size: 15px;
    color: #64748b;
    margin-top: 6px;
}

.subtitle-updated {
    display: block;
    margin-top: 4px;
    margin-left: 0px;
    color: #2563eb;
    font-weight: 600;
}

.controls {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 15px;
}

.btn-group {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
}

.btn {
    background: #ffffff;
    border: 1px solid #cbd5e1;
    padding: 6px 16px;
    border-radius: 8px;
    cursor: pointer;
    font-size: 15px;
    color: #334155;
    transition: all 0.2s ease;
}

.btn:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.btn.active {
    background: #2563eb;
    color: #ffffff;
    border-color: #2563eb;
    box-shadow: 0 2px 8px rgba(37, 99, 235, 0.25);
}

/* メインチャート表示エリア */
.chart-wrapper {
    width: 100%;
    margin-bottom: 35px;
    background: #f8fafc;
    padding: 20px;
    border-radius: 12px;
    border: 1px solid #c7ced7;
}

.chart-container {
    position: relative;
    height: 400px;
    width: 100%;
}

.series-toggles-label {
    margin-top: 16px;
    margin-bottom: 6px;
    font-size: 12px;
    line-height: 1.2;
    color: #64748b;
    font-weight: 600;
    text-transform: uppercase;
}

.series-toggles {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
}

.series-toggle {
    flex: 1 1 0;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    border: 1px solid #cbd5e1;
    background: #ffffff;
    border-radius: 8px;
    padding: 8px 12px;
    font-size: 14px;
    font-weight: 600;
    color: #475569;
    cursor: pointer;
    white-space: nowrap;
    transition: all 0.2s ease;
}

.series-toggle:hover {
    background: #f1f5f9;
    color: #0f172a;
}

.series-toggle:not(.inactive) {
    background: var(--series-color, #2563eb);
    border-color: var(--series-color, #2563eb);
    color: #ffffff;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.1);
}

.series-toggle.inactive {
    background: #f8fafc;
    border-color: #e2e8f0;
    color: #94a3b8;
}

.category-section {
    margin-bottom: 30px;
}

.grid {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 20px;
}

/* 株価カード */
.card {
    background: #ffffff;
    border: 1px solid #c7ced7;
    border-radius: 12px;
    padding: 20px;
    box-shadow: 0 2px 6px rgba(0, 0, 0, 0.02);
    transition: transform 0.2s ease, border-color 0.2s ease, box-shadow 0.2s ease;
}

.card-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 12px;
}

.card-title {
    font-size: 18px;
    font-weight: 700;
    color: #0f172a;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    min-width: 0;
}

.card-desc {
    font-size: 15px;
    color: #475569;
    margin-bottom: 16px;
    line-height: 1.6;
    background: #f8fafc;
    padding: 10px 12px;
    border-radius: 8px;
}

.tag {
    font-size: 12px;
    font-weight: 700;
    padding: 3px 10px;
    border-radius: 20px;
    letter-spacing: 0.02em;
    white-space: nowrap;
    flex-shrink: 0;
}

.tag.jp { background: #fee2e2; color: #991b1b; }
.tag.us { background: #dbeafe; color: #1e40af; }
.tag.global { background: #dcfce7; color: #166534; }

/* メイン数値 */
.stat-block {
    margin-bottom: 14px;
}

.stat-label {
    font-size: 15px;
    color: #64748b;
    margin-bottom: 2px;
    font-weight: 500;
}

.stat-note {
    font-weight: normal;
    margin-left: 4px;
    color: #94a3b8;
}

.stat-main {
    font-size: 32px;
    font-weight: 800;
    line-height: 1.2;
    letter-spacing: -0.02em;
}

.stat-main.positive, .stat-value.positive {
    color: #059669;
}

.stat-main.negative, .stat-value.negative {
    color: #dc2626;
}

/* サブ項目 */
.stat-details {
    display: flex;
    flex-direction: column;
    gap: 8px;
    border-top: 1px solid #f1f5f9;
    padding-top: 12px;
    font-size: 15px;
}

.stat-item {
    display: flex;
    justify-content: space-between;
    align-items: center;
    color: #64748b;
}

.stat-value {
    font-weight: 700;
    color: #1e293b;
    font-size: 17px;
}

/* カード内ミニグラフ */
.card-chart-wrapper {
    margin-top: 14px;
    background: #fafafa;
    padding: 8px;
    border-radius: 8px;
    border: 1px solid #f1f5f9;
}

.card-chart-container {
    position: relative;
    height: 140px;
    width: 100%;
}

.guide-section {
    margin-top: 35px;
    padding: 24px;
    background: #f8fafc;
    border-radius: 12px;
    border: 1px solid #e2e8f0;
}

.guide-title {
    font-size: 17px;
    font-weight: 700;
    color: #0f172a;
    margin-bottom: 10px;
}

.guide-intro {
    font-size: 14px;
    color: #475569;
    line-height: 1.8;
}

/* =========================================================
   フッター領域
   ========================================================= */

footer {
    width: 100%;
    padding: 30px 20px 40px 20px;
    margin-bottom: 50px;
    border-top: 1px solid #e2e8f0;
    font-size: 14px;
    color: #64748b;
    text-align: center;
}

footer a {
    color: #475569;
    text-decoration: underline;
}

footer a:hover {
    color: #2563eb;
}

.db-error {
    margin-bottom: 20px;
    padding: 14px 18px;
    background: #fef2f2;
    border: 1px solid #fecaca;
    color: #991b1b;
    border-radius: 8px;
    font-size: 14px;
}

/* スマホ・タブレット用調整 */
@media (max-width: 992px) {
    .grid {
        grid-template-columns: repeat(2, 1fr);
    }
}

@media (max-width: 768px) {
    body { padding: 60px 0 0 0; }
    .container {
        width: 100%;
        padding: 16px;
        border-radius: 0;
        box-shadow: none;
        border: none;
    }
    .page-header h1 { font-size: 22px; text-align: center; }
    .page-header { min-height: auto; }
    .subtitle-updated {
        display: block;
        margin-top: 4px;
        margin-left: 0;
    }

    .controls-bar {
        top: auto;
        bottom: 0;
        border-bottom: none;
        border-top: 1px solid #cbd5e1;
        box-shadow: 0 -2px 10px rgba(0,0,0,0.08);
    }
    .controls-bar-inner {
        padding: 8px 12px 10px;
    }

    .controls { flex-direction: column; align-items: stretch; gap: 10px; }
    .btn-group { width: 100%; }
    .btn { flex: 1 1 calc(25% - 8px); text-align: center; padding: 8px 0; font-size: 15px; } /* 8個を4個×2段に */
    /* 表示切替ボタン：4つを1行に横並びにする（折り返さない） */
    .series-toggles { flex-wrap: nowrap; gap: 6px; }
    .series-toggle { flex: 1 1 0; min-width: 0; padding: 8px 2px; font-size: 12px; }

    /* 下部固定バーの上に展開する */
    .range-panel {
        top: auto;
        bottom: 100%;
        left: 12px;
        right: 12px;
        margin: 0 0 8px;
        width: auto;
        max-width: none;
    }
    .range-fields { gap: 8px; }
    .range-field { flex: 1 1 40%; }
    .range-field input[type="date"] { font-size: 16px; } /* iOSの自動ズーム防止 */
    .range-sep { display: none; }
    .range-apply { flex: 1 1 100%; }

    .chart-container {
        height: 300px;
    }

    .grid { grid-template-columns: 1fr; gap: 14px; }
    .stat-main { font-size: 28px; }

    footer {
        padding-bottom: 120px; /* スマホ時の下部固定バー被り防止 */
    }
}

@media (max-width: 380px) {
    .series-toggles { gap: 4px; }
    .series-toggle { font-size: 11px; }
}