:root {
    color-scheme: light;
    font-family: var(--perfect-picker-font-family);
    --theme-canvas: #f2f2f1;
    --theme-surface: #fff;
    --theme-ink: #252525;
    --theme-muted: #747474;
    --theme-line: #303030;
    --theme-soft-line: #d8d8d8;
    --theme-accent: #f126dc;
}

* { box-sizing: border-box; }
html, body { min-width: 320px; min-height: 100%; margin: 0; }
body { color: var(--theme-ink); background: var(--theme-canvas); }
button, input, select { font: inherit; }
button { cursor: pointer; }

.themePage {
    width: min(1540px, calc(100% - 36px));
    margin: 0 auto;
    padding: 22px 0 48px;
}

.themePageHeading {
    display: flex;
    min-height: 78px;
    align-items: center;
    justify-content: space-between;
    gap: 24px;
}

.themeEyebrow { margin: 0 0 3px; color: var(--theme-accent); font-size: 10px; font-weight: 700; letter-spacing: .18em; }
.themePageHeading h1 { margin: 0; font-size: 27px; }
.themePageHeading p:last-child { margin: 4px 0 0; color: var(--theme-muted); font-size: 12px; }
.oldPageLink { padding: 7px 11px; color: #555; background: #fff; border: 1px solid #c8c8c8; font-size: 11px; font-weight: 700; text-decoration: none; }

.themeSelectorPanel,
.relativeSection {
    background: var(--theme-surface);
    border: 2px solid var(--theme-line);
    box-shadow: 5px 5px 0 rgba(36,36,36,.14);
}

.themeSelectorPanel { display: flex; height: calc(100vh - var(--perfect-picker-header-height) - 120px); min-height: 480px; flex-direction: column; }

.relativeSection { margin-top: 22px; scroll-margin-top: var(--perfect-picker-header-height); }
.sectionHeader { display: flex; min-height: 78px; align-items: center; justify-content: space-between; gap: 22px; padding: 16px 22px; border-bottom: 2px solid var(--theme-line); }
.sectionHeader > div:first-child { display: grid; grid-template-columns: auto auto auto; align-items: baseline; gap: 0 10px; }
.sectionNumber { color: var(--theme-accent); font-size: 16px; font-weight: 700; }
.sectionHeader h2 { margin: 0; font-size: 20px; }
.sectionHeader p { grid-column: 3; margin: 3px 0 0; color: var(--theme-muted); font-size: 11px; }
.selectionSummary { display: flex; align-items: baseline; gap: 4px; }
.selectionSummary strong { font-size: 24px; }
.selectionSummary span { color: var(--theme-muted); font-size: 11px; }
.collapsibleHeader { cursor: pointer; user-select: none; }
.collapsibleHeader:hover { background: #fafafa; }
.collapsibleHeader:focus-visible { outline: 3px solid rgba(241,38,220,.24); outline-offset: -3px; }
.collapseIndicator { display: inline-block; color: #555; font-size: 25px; line-height: .8; transform: rotate(90deg); transition: transform 140ms ease; }
.isCollapsed .collapseIndicator { transform: rotate(0); }
.selectorBody { display: flex; min-height: 0; flex: 1; flex-direction: column; }

.selectorToolbar { display: flex; align-items: flex-end; gap: 10px; padding: 14px 22px 10px; }
.themeSearch { display: grid; width: min(420px, 100%); gap: 5px; color: var(--theme-muted); font-size: 10px; font-weight: 700; }
.themeSearch input { width: 100%; height: 36px; padding: 0 11px; color: var(--theme-ink); background: #fafafa; border: 1px solid #cfcfcf; outline: none; }
.themeSearch input:focus { background: #fff; border-color: #777; box-shadow: 0 0 0 3px rgba(241,38,220,.1); }
.secondaryButton, .primaryButton { min-height: 36px; padding: 0 14px; border: 1px solid #aaa; font-size: 12px; font-weight: 700; }
.secondaryButton { color: #444; background: #fff; }
.primaryButton { color: #fff; background: #292929; border-color: #292929; }
.primaryButton:disabled { color: #999; background: #ddd; border-color: #ddd; cursor: not-allowed; }
.selectorToolbar .primaryButton { margin-left: auto; }

.selectedThemeChips { display: flex; min-height: 38px; align-items: center; gap: 6px; padding: 0 22px 10px; overflow-x: auto; }
.selectedThemeChips:empty::before { content: "テーマは未選択です"; color: #999; font-size: 11px; }
.themeChip { display: inline-flex; flex: 0 0 auto; align-items: center; gap: 7px; padding: 5px 8px; color: #333; background: #f3f3f3; border: 1px solid #ccc; font-size: 11px; font-weight: 700; }
.themeChip i { width: 8px; height: 8px; background: var(--chip-color); border-radius: 50%; }
.themeChip button { padding: 0; color: #777; background: transparent; border: 0; line-height: 1; }

.themeGridGroup { display: grid; min-height: 0; flex: 1; grid-template-columns: repeat(3, minmax(340px, 1fr)); gap: 12px; padding: 0 22px 18px; overflow-x: auto; }
.themeGrid { display: flex; min-width: 0; min-height: 0; flex-direction: column; border: 1px solid #bdbdbd; }
.themeGrid h3 { margin: 0; padding: 8px 11px; color: #333; background: #f7f7f7; border-bottom: 1px solid #bdbdbd; font-size: 12px; }
.themeTableWrap { min-height: 0; flex: 1; overflow: auto; scrollbar-gutter: stable; }
.themeTable { width: 100%; border-collapse: collapse; table-layout: fixed; }
.themeTable th { position: sticky; z-index: 2; top: 0; padding: 8px 12px; color: #666; background: #ededed; border-bottom: 1px solid #bbb; font-size: 10px; font-weight: 700; text-align: left; }
.themeTable td { height: 34px; padding: 6px 12px; background: #fff; border-bottom: 1px solid #e1e1e1; font-size: 12px; }
.themeTable tbody tr { cursor: pointer; }
.themeTable tbody tr:hover td { background: #f5f5f5; }
.themeTable tbody tr.isSelected td { background: #fff1fd; }
.themeTable tbody tr.isSelected td:first-child { box-shadow: inset 3px 0 var(--theme-accent); }
.themeTable .selectColumn { width: 52px; text-align: center; }
.themeTable .metricColumn { width: 104px; text-align: right; }
.themeTable .marketCapColumn { width: 116px; }
.themeTable td.selectColumn { text-align: center; }
.themeTable td.metricColumn { color: var(--theme-muted); font-variant-numeric: tabular-nums; white-space: nowrap; }
.themeTable td.metricColumn.isPositive { color: #c51c2d; }
.themeTable td.metricColumn.isNegative { color: #1967b3; }
.themeTable input { accent-color: #cc1bbb; }
.themeNameCell { overflow: hidden; font-weight: 700; text-overflow: ellipsis; white-space: nowrap; }
.loadingMessage, .emptyMessage { height: 76px !important; color: var(--theme-muted); font-size: 12px !important; text-align: center; }

.themeSelectorPanel.isCollapsed { height: auto; min-height: 0; }
.isCollapsed > .sectionHeader { border-bottom: 0; }
.isCollapsed > [data-collapsible-body] { display: none; }
.relativeSection.isCollapsed .chartControls { display: none; }

.chartControls { display: flex; align-items: flex-end; gap: 9px; }
.chartControls label { display: grid; gap: 4px; color: var(--theme-muted); font-size: 10px; font-weight: 700; }
.chartControls select { height: 36px; min-width: 104px; padding: 0 30px 0 10px; color: var(--theme-ink); background: #fff; border: 1px solid #aaa; }
.chartStatus { margin: 0; padding: 56px 24px; color: var(--theme-muted); font-size: 12px; text-align: center; }
.chartStatus.isError { color: #b42318; }
.chartStatus.isReady { padding: 7px 22px; border-bottom: 1px solid var(--theme-soft-line); font-size: 10px; text-align: right; }
.chartStatus[hidden] { display: none; }

.chartPair { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); }
.chartPair[hidden] { display: none; }
.chartPanel { min-width: 0; padding: 20px 20px 12px; }
.chartPanel + .chartPanel { border-left: 1px solid var(--theme-soft-line); }
.chartPanel > header { min-height: 72px; padding: 0 4px 12px; }
.chartType { color: var(--theme-accent); font-size: 9px; font-weight: 700; letter-spacing: .12em; }
.chartPanel h3 { margin: 3px 0 0; font-size: 22px; }
.chartPanel header p { margin: 4px 0 0; color: var(--theme-muted); font-size: 10px; }
.chartMount { width: 100%; height: 410px; }

@media (max-width: 900px) {
    .chartPair { grid-template-columns: 1fr; }
    .chartPanel + .chartPanel { border-top: 1px solid var(--theme-soft-line); border-left: 0; }
}

@media (max-width: 720px) {
    .themePage { width: calc(100% - 20px); padding-top: 14px; }
    .themePageHeading, .sectionHeader, .selectorToolbar { align-items: flex-start; flex-direction: column; }
    .themePageHeading { justify-content: center; gap: 9px; padding: 14px 2px; }
    .sectionHeader { gap: 12px; padding: 15px; }
    .selectorToolbar { padding: 13px 15px 9px; }
    .themeSearch, .secondaryButton, .selectorToolbar .primaryButton { width: 100%; }
    .selectorToolbar .primaryButton { margin-left: 0; }
    .selectedThemeChips { padding-right: 15px; padding-left: 15px; }
    .themeGridGroup { padding-right: 15px; padding-left: 15px; }
    .themeSelectorPanel { height: calc(100vh - var(--perfect-picker-header-height) - 90px); min-height: 430px; }
    .chartControls { width: 100%; }
    .chartControls label { flex: 1; }
    .chartControls select { width: 100%; }
    .chartPanel { padding: 16px 10px 10px; }
    .chartMount { height: 350px; }
}
