:root {
    color-scheme: dark;
    --bg: #121417;
    --bg-2: #171b20;
    --panel: #1f242b;
    --line: rgba(148, 163, 184, 0.16);
    --text: #e8edf2;
    --muted: #93a0ae;
    --primary: #0e7490;
    --primary-hover: #155e75;
    --primary-soft: rgba(14, 116, 144, 0.18);
    --ok: #34d399;
    --warn: #fbbf24;
    --error: #f87171;
    --a: #22d3ee;
    --b: #fb7185;
    --sidebar-width: 232px;
    --sidebar-compact: 76px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
    margin: 0;
    min-height: 100%;

}

body {
    font-family: "Hiragino Sans", "Noto Sans JP", "Segoe UI", sans-serif;
    color: var(--text);
    background:
        radial-gradient(1200px 500px at 10% -10%, rgba(14, 116, 144, 0.18), transparent 50%),
        linear-gradient(180deg, #161a1f 0%, var(--bg) 40%);
    display: flex;
}

:focus-visible {
    outline: 2px solid rgba(14, 116, 144, 0.85);
    outline-offset: 2px;
}

.app-sidebar {
    position: fixed;
    inset: 0 auto 0 0;
    width: var(--sidebar-width);
    background: #1a1f25;
    border-right: 1px solid var(--line);
    z-index: 20;
}

.sidebar-rail {
    display: flex;
    flex-direction: column;
    height: 100%;
    padding: 20px 14px;
    gap: 8px;
}

.brand-lockup {
    display: flex;
    align-items: center;
    gap: 10px;
    text-decoration: none;
    color: inherit;
    padding: 8px 6px 18px;
    border-bottom: 1px solid var(--line);
}

.brand-mark {
    width: 14px;
    height: 28px;
    border-radius: 99px;
    background: linear-gradient(180deg, #22d3ee, var(--primary));
    flex-shrink: 0;
}

.brand-copy strong,
.brand-copy span { display: block; }
.brand-copy strong { font-size: 1rem; letter-spacing: 0.01em; }
.brand-copy span { color: var(--muted); font-size: 0.75rem; }

.sidebar-nav {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding-top: 10px;
    flex: 1;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 11px 12px;
    border-radius: 14px;
    color: var(--muted);
    text-decoration: none;
    font-weight: 650;
    border: 1px solid transparent;
}

.sidebar-link:hover {
    background: rgba(14, 116, 144, 0.12);
    color: var(--text);
}

.sidebar-link.is-active {
    background: var(--primary-soft);
    border-color: rgba(14, 116, 144, 0.45);
    color: #67e8f9;
}

.sidebar-link-icon {
    width: 28px;
    height: 28px;
    display: grid;
    place-items: center;
}

.sidebar-link-icon svg {
    width: 20px;
    height: 20px;
}

.sidebar-meta {
    margin-top: auto;
    padding-top: 14px;
    border-top: 1px solid var(--line);
    color: var(--muted);
    font-size: 0.82rem;
}

.sidebar-meta strong {
    display: block;
    color: var(--text);
    margin-bottom: 4px;
}

main {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-width: 0;
    padding: 32px 32px 72px;
}

.page-shell {
    width: 100%;
    max-width: 1280px;
    margin: 0 auto;
    min-width: 0;
}

.page-header { margin-bottom: 24px; max-width: none; }
.eyebrow {
    color: #67e8f9;
    letter-spacing: 0.12em;
    text-transform: uppercase;
    font-size: 0.72rem;
    margin: 0 0 8px;
}
h1 { font-size: 1.8rem; margin: 0 0 10px; letter-spacing: -0.02em; }
h2 { font-size: 1.08rem; margin: 0; }
.lede, .hint, .caption, .muted { color: var(--muted); }
.lede { margin: 0; line-height: 1.7; }

.panel {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 20px 22px;
    margin-bottom: 16px;
}

.panel-head { margin-bottom: 14px; }
.panel-head p { margin: 6px 0 0; color: var(--muted); font-size: 0.9rem; }
.panel-head-row {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    gap: 12px;
}
.panel-head-actions {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    flex-shrink: 0;
}

.analyze-grid { max-width: none; width: 100%; }

.series-pair {
    display: grid;
    grid-template-columns: minmax(280px, 1fr) auto minmax(280px, 1fr);
    gap: 16px;
    align-items: stretch;
}

.series-card {
    background: rgba(15, 20, 24, 0.45);
    border: 1px solid var(--line);
    border-radius: 16px;
    padding: 16px;
}

.series-card-a { box-shadow: inset 3px 0 0 var(--a); }
.series-card-b { box-shadow: inset 3px 0 0 var(--b); }
.series-kicker {
    margin: 0 0 4px;
    font-size: 0.75rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
}
.series-card h2 { font-size: 1rem; margin-bottom: 12px; font-weight: 650; }
.series-mid {
    display: flex;
    flex-direction: column;
    justify-content: center;
    align-items: center;
    gap: 10px;
}
.direction-arrow { font-size: 1.6rem; color: #67e8f9; }

select, input[type="search"], input[type="date"] {
    width: 100%;
    background: #12161b;
    color: var(--text);
    border: 1px solid var(--line);
    border-radius: 12px;
    padding: 10px 12px;
    font: inherit;
}

.series-search { margin-bottom: 8px; }
.field-label { display: block; margin: 8px 0 6px; font-size: 0.82rem; color: var(--muted); }
.field-error { color: var(--error); font-size: 0.86rem; margin: 8px 0 0; }
.series-meta { min-height: 2.4em; font-size: 0.82rem; margin: 8px 0 0; }

.period-options { display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    padding: 8px 12px;
    border-radius: 999px;
    border: 1px solid var(--line);
    background: #161b21;
    cursor: pointer;
}
.chip:has(input:checked) {
    border-color: rgba(14, 116, 144, 0.7);
    background: var(--primary-soft);
}
.chip:has(input:disabled) { opacity: 0.45; cursor: not-allowed; }
.chip input { accent-color: var(--primary); }
.custom-period { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-top: 14px; }

.variant-options {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px;
}
.variant-card {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 12px;
    align-items: start;
    padding: 14px 16px;
    border-radius: 16px;
    border: 1px solid var(--line);
    background: #161b21;
    cursor: pointer;
}
.variant-card:has(input:checked) {
    border-color: rgba(14, 116, 144, 0.7);
    background: var(--primary-soft);
}
.variant-card input { margin-top: 4px; accent-color: var(--primary); }
.variant-kicker {
    display: block;
    font-size: 0.72rem;
    letter-spacing: 0.08em;
    text-transform: uppercase;
    color: var(--muted);
    margin-bottom: 4px;
}
.variant-card strong { display: block; margin-bottom: 4px; }
.variant-card small {
    display: block;
    color: var(--muted);
    font-size: 0.82rem;
    line-height: 1.5;
}

.transform-preview {
    display: grid;
    gap: 8px;
}
.transform-row {
    display: flex;
    justify-content: space-between;
    gap: 12px;
    padding: 10px 0;
    border-bottom: 1px solid var(--line);
}
.transform-row:last-child { border-bottom: 0; }

.btn-primary, .btn-secondary {
    border: 0;
    border-radius: 12px;
    padding: 11px 16px;
    font: inherit;
    font-weight: 700;
    cursor: pointer;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn-primary { background: var(--primary); color: #f8fafc; }
.btn-primary:hover, .btn-primary:focus-visible { background: var(--primary-hover); }
.btn-primary:disabled { background: #334155; color: #94a3b8; cursor: not-allowed; }
.btn-secondary {
    background: #25303a;
    color: var(--text);
    border: 1px solid var(--line);
}
.btn-secondary:hover { border-color: rgba(14, 116, 144, 0.5); }

.analyze-actions {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-top: 8px;
}
.inline-form { display: inline; }

.banner {
    border-radius: 16px;
    padding: 14px 16px;
    margin-bottom: 16px;
}
.banner-error { background: rgba(248, 113, 113, 0.12); border: 1px solid rgba(248, 113, 113, 0.35); }
.banner-warn { background: rgba(251, 191, 36, 0.1); border: 1px solid rgba(251, 191, 36, 0.28); }
.dev-detail { color: var(--muted); font-size: 0.82rem; }

.kv-grid {
    display: grid;
    grid-template-columns: repeat(2, minmax(0, 1fr));
    gap: 12px 24px;
}
.kv-grid.compact { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.kv-grid dt { color: var(--muted); font-size: 0.8rem; }
.kv-grid dd { margin: 4px 0 0; }
.kv, .settings-list .kv {
    display: flex;
    justify-content: space-between;
    gap: 16px;
    padding: 12px 0;
    border-bottom: 1px solid var(--line);
}

.fact-grid {
    display: grid;
    grid-template-columns: repeat(3, minmax(0, 1fr));
    gap: 12px;
}
.fact-grid article {
    background: #161b21;
    border-radius: 14px;
    padding: 12px 14px;
}
.fact-grid p { margin: 0; color: var(--muted); font-size: 0.8rem; }
.fact-grid strong { display: block; margin-top: 6px; font-size: 1.15rem; }

.chart-card, .evidence-section img {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 16px;
    margin: 0 0 16px;
    width: 100%;
    max-width: 100%;
    min-width: 0;
}
.chart-card img, .evidence-section img { width: 100%; height: auto; display: block; border-radius: 10px; }
.chart-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    margin-bottom: 8px;
}
.chart-card-head figcaption { margin: 0; font-weight: 700; }
.chart-summary {
    margin: 0 0 10px;
    color: var(--text);
    font-size: 0.92rem;
    font-weight: 650;
}
.plotly-chart,
.plotly-chart .js-plotly-plot,
.plotly-chart .plot-container,
.plotly-chart .svg-container {
    width: 100% !important;
    max-width: 100%;
    min-width: 0;
}
.plotly-chart { min-height: 360px; }
.caption { font-size: 0.84rem; margin: 8px 0 0; }
.copy-list { margin: 12px 0 0; padding-left: 1.1em; color: var(--muted); line-height: 1.65; }
.empty-card {
    background: #161b21;
    border-radius: 12px;
    padding: 16px;
    color: var(--muted);
}
.badge {
    display: inline-flex;
    align-items: center;
    border-radius: 999px;
    padding: 4px 10px;
    font-size: 0.78rem;
    font-weight: 700;
}
.tone-ok { background: rgba(52, 211, 153, 0.14); color: #6ee7b7; }
.tone-warn { background: rgba(251, 191, 36, 0.14); color: #fbbf24; }
.tone-error { background: rgba(248, 113, 113, 0.14); color: #f87171; }
.tone-muted { background: rgba(148, 163, 184, 0.12); color: #cbd5e1; }
.status-row { display: flex; gap: 8px; margin-top: 14px; flex-wrap: wrap; }
.section-title { margin: 28px 0 12px; font-size: 1.2rem; }
code { font-size: 0.82rem; color: #cbd5e1; overflow-wrap: anywhere; }

#loading-overlay {
    position: fixed;
    inset: 0;
    background: rgba(8, 10, 12, 0.62);
    display: grid;
    place-items: center;
    z-index: 50;
}
.loading-card {
    background: var(--panel);
    border: 1px solid var(--line);
    border-radius: 18px;
    padding: 24px 28px;
    text-align: center;
}
.loading-spinner {
    width: 28px;
    height: 28px;
    border-radius: 99px;
    border: 3px solid #334155;
    border-top-color: #22d3ee;
    margin: 0 auto 12px;
    animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    border: 0;
}

.help-trigger,
.help-popover-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    border: 0;
    color: #cbd5e1;
    cursor: pointer;
}
.help-trigger {
    width: 36px;
    min-width: 36px;
    height: 36px;
    padding: 8px;
    border-radius: 50%;
    background: rgba(51, 65, 85, 0.64);
}
.help-trigger:hover {
    color: #f8fafc;
    background: rgba(14, 116, 144, 0.35);
}
.help-trigger svg,
.help-popover-close svg {
    width: 18px;
    height: 18px;
    fill: none;
    stroke: currentColor;
    stroke-linecap: round;
    stroke-linejoin: round;
    stroke-width: 2;
}
.help-popover {
    position: fixed;
    z-index: 120;
    width: min(400px, calc(100vw - 24px));
    max-height: min(76vh, calc(100vh - 24px));
    overflow: auto;
    overscroll-behavior: contain;
    border: 1px solid var(--line);
    border-radius: 14px;
    background: #151a20;
    box-shadow: 0 18px 42px rgba(0, 0, 0, 0.42);
    color: var(--text);
}
.help-popover[hidden] { display: none; }
.help-popover-header {
    position: sticky;
    top: 0;
    z-index: 1;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    padding: 14px 14px 10px 16px;
    border-bottom: 1px solid var(--line);
    background: #1a222b;
}
.help-popover h4,
.help-popover h5,
.help-popover p { margin: 0; }
.help-popover h4 { font-size: 0.94rem; }
.help-popover-close {
    width: 36px;
    min-width: 36px;
    height: 36px;
    padding: 8px;
    border-radius: 8px;
    background: transparent;
}
.help-popover-close:hover {
    color: #f8fafc;
    background: rgba(71, 85, 105, 0.72);
}
.help-popover-body {
    display: grid;
    gap: 14px;
    padding: 16px;
}
.help-copy-section { display: grid; gap: 6px; }
.help-copy-section h5 {
    color: #67e8f9;
    font-size: 0.78rem;
    letter-spacing: 0.02em;
}
.help-copy-section p {
    color: #cbd5e1;
    font-size: 0.82rem;
    line-height: 1.55;
}

@media (max-width: 960px) {
    .series-pair, .fact-grid, .kv-grid, .custom-period, .variant-options { grid-template-columns: minmax(0, 1fr); }
    .series-mid { flex-direction: row; }
    main { padding: 24px 16px 56px; }
}

@media (max-width: 820px) {
    .app-sidebar { width: var(--sidebar-compact); }
    .sidebar-link-label, .brand-copy span, .sidebar-meta { display: none; }
    .brand-copy strong { font-size: 0.72rem; }
    main { margin-left: var(--sidebar-compact); }
}

/* Child B: readable facts and keyboard-accessible progressive disclosure. */
.page-toolbar { display: flex; justify-content: flex-end; align-items: center; gap: 12px; margin-bottom: 20px; }
.page-toolbar .btn-secondary { font-size: .82rem; padding: 8px 12px; }
.page-result h1 { font-size: clamp(1.25rem, 2vw, 1.65rem); line-height: 1.55; max-width: 1100px; }
.context-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); margin: 0; gap: 10px 18px; }
.context-grid dd { font-size: .86rem; line-height: 1.45; }
.fact-grid { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.kv-grid > div, .series-card, .variant-card > span { min-width: 0; overflow-wrap: anywhere; }
.finding-list { list-style: none; padding: 0; margin: 8px 0 0; display: grid; gap: 12px; }
.finding-list li { border-left: 2px solid var(--primary); padding-left: 14px; }
.finding-list p { line-height: 1.65; margin: 0 0 4px; }
.evidence-link { color: #67e8f9; text-underline-offset: 3px; font-size: .84rem; }
.question-panel { border-color: rgba(34, 211, 238, .35); }
.question-panel p { line-height: 1.7; margin-bottom: 0; }
.primary-limitation { color: #fbbf24; font-size: .88rem; line-height: 1.65; }
.primary-lead-lag > p { line-height: 1.65; }
.lag-summary { width: 100%; border-collapse: collapse; table-layout: fixed; font-size: .85rem; }
.lag-summary th, .lag-summary td { padding: 10px 6px; text-align: right; border-bottom: 1px solid var(--line); overflow-wrap: anywhere; font-variant-numeric: tabular-nums; }
.lag-summary th:first-child { width: 64%; text-align: left; font-weight: 500; }
.lag-summary thead { color: var(--muted); }
summary { cursor: pointer; padding: 6px 0; line-height: 1.6; font-weight: 650; }
summary .badge { margin-left: 8px; }
details[open] > summary { margin-bottom: 18px; }
.evidence-section, .secondary-evidence, #primary-lead-lag { scroll-margin-top: 20px; }
.component-status-list { list-style: none; padding: 0; }
.component-status-list li { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 12px 0; border-bottom: 1px solid var(--line); }
.component-status-list p { width: 100%; margin: 0; }
.integrity-statement { color: var(--muted); font-size: .85rem; line-height: 1.7; margin: 24px 0; }
.panel-head-actions { flex-wrap: wrap; flex-shrink: 1; justify-content: flex-end; }
.panel-head-row { flex-wrap: wrap; }
.badge { max-width: 100%; overflow-wrap: anywhere; }
.loading-card { max-width: min(500px, calc(100vw - 32px)); line-height: 1.7; }
:focus-visible { outline: 2px solid #67e8f9; outline-offset: 4px; }
@media (max-width: 1280px) { .context-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 960px) { .fact-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); } }
@media (max-width: 820px) {
    .brand-copy { display: none; }
    .sidebar-link { position: relative; }
    .sidebar-link-label { display: block; position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0,0,0,0); }
}
@media (max-width: 600px) {
    .app-sidebar { inset: 0 0 auto; width: 100%; height: 60px; border-right: 0; border-bottom: 1px solid var(--line); }
    .sidebar-rail { padding: 4px 10px; flex-direction: row; align-items: center; }
    .sidebar-brand, .sidebar-meta { display: none; }
    .sidebar-nav { flex-direction: row; padding: 0; justify-content: space-around; }
    .sidebar-link { padding: 8px 12px; }
    main { margin-left: 0; padding: 80px 16px 40px; width: 100%; }
    .panel { padding: 16px; border-radius: 14px; }
    .kv-grid.compact, .context-grid { grid-template-columns: minmax(0, 1fr); }
    .context-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
    .context-grid dd { font-size: .8rem; }
    .fact-grid { gap: 8px; }
    .fact-grid article { padding: 10px; }
    .fact-grid strong { font-size: 1rem; }
    .analyze-actions, .transform-row { flex-wrap: wrap; }
    .lag-summary th:first-child { width: 54%; }
    .primary-lead-lag { padding: 12px; }
    .help-popover { max-height: calc(100dvh - 32px); }
    .evidence-section, .secondary-evidence { scroll-margin-top: 76px; }
}
@media (prefers-reduced-motion: reduce) { .loading-spinner { animation: none; } }

/* Child G: server-rendered auth and consent surfaces. */
.auth-page { min-height: 100vh; background: radial-gradient(circle at top, #172554, #020617 58%); }
.auth-shell { margin: 0; min-height: 100vh; display: grid; place-items: center; padding: 32px 16px; }
.auth-card { width: min(540px, 100%); padding: 36px; border: 1px solid var(--line); border-radius: 20px; background: rgba(15, 23, 42, .96); box-shadow: 0 24px 80px rgba(0, 0, 0, .35); }
.auth-card h1 { margin: 10px 0 14px; font-size: clamp(1.7rem, 5vw, 2.3rem); line-height: 1.25; }
.auth-card > p { color: var(--muted); line-height: 1.7; }
.auth-brand { color: #f8fafc; font-weight: 750; letter-spacing: -.02em; text-decoration: none; }
.auth-form { display: grid; gap: 18px; margin: 26px 0 18px; }
.consent-choice { display: flex; align-items: flex-start; gap: 11px; color: #cbd5e1; font-size: .9rem; line-height: 1.55; }
.consent-choice input { width: 18px; height: 18px; margin-top: 2px; accent-color: var(--primary); }
.auth-submit { width: 100%; border: 0; border-radius: 10px; padding: 13px 18px; cursor: pointer; }
.auth-legal { font-size: .78rem; }
.auth-legal a, .auth-help, .sidebar-meta a { color: #67e8f9; text-underline-offset: 3px; }
.auth-error { padding: 10px 12px; border: 1px solid rgba(248, 113, 113, .45); border-radius: 10px; color: #fecaca !important; background: rgba(127, 29, 29, .24); }
.sidebar-meta form { margin-top: 8px; }
.sidebar-logout { padding: 0; border: 0; background: transparent; color: #cbd5e1; cursor: pointer; text-decoration: underline; text-underline-offset: 3px; }
