:root {
  --bg: #F6F6F3;
  --surface: #FFFFFF;
  --surface-sub: #EFEFEA;
  --track: #F1F1EC;
  --border: #DEDED8;
  --border-input: #C7C8C2;
  --row-line: #ECECE7;
  --text: #1C1E21;
  --text-sub: #3F4247;
  --text-muted: #55585E;
  --text-faint: #6A6D72;
  --header-bg: #1C1E21;
  --header-text: #F6F6F3;
  --header-text-sub: #C9CBCF;
  --header-active: #3A3D42;
  --up: #1F4E8C;
  --up-hover: #163A69;
  --down: #B4600F;
  --neutral-bar: #B9BBB6;
  --rsi: #5B3E8C;
  --ma: #2F7A5C;

  --font-sans: "Noto Sans JP", "Hiragino Kaku Gothic ProN", "Yu Gothic", Meiryo, sans-serif;
  --font-mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { -webkit-text-size-adjust: 100%; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font-sans);
  font-size: 14px;
  font-weight: 400;
  line-height: 1.6;
  overflow-x: hidden;
}

a { color: var(--up); text-decoration: none; }
a:hover { color: var(--up-hover); text-decoration: underline; }

.mono { font-family: var(--font-mono); }

/* ---------- ヘッダー (C-01) ---------- */

.site-header {
  position: sticky;
  top: 0;
  z-index: 100;  /* チャートやツールチップより前に出す */
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px 24px;
  padding: 20px 32px;
  background: var(--header-bg);
  color: var(--header-text-sub);
  font-size: 12px;
}

.site-header__left {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px 16px;
}

.site-name {
  color: var(--header-text);
  font-size: 20px;
  font-weight: 700;
}
.site-name:hover { color: var(--header-text); text-decoration: none; }

.site-nav { display: flex; gap: 4px; margin-left: 8px; }
.site-nav a {
  color: var(--header-text-sub);
  font-size: 14px;
  padding: 6px 14px;
  border-radius: 8px;
}
.site-nav a:hover { color: var(--header-text); text-decoration: none; }
.site-nav a.is-active { color: var(--header-text); background: var(--header-active); }

.site-header__right { display: flex; flex-wrap: wrap; gap: 4px 16px; }

/* ---------- ページ ---------- */

.page {
  max-width: 1216px;
  margin: 0 auto;
  padding: 24px 32px 48px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px 20px;
}

h1 { margin: 0; font-size: 20px; font-weight: 700; line-height: 1.4; }
h2 { margin: 0; font-size: 16px; font-weight: 700; }

/* ---------- 部品 ---------- */

.field { display: flex; flex-direction: column; gap: 4px; }
.field__label { font-size: 12px; color: var(--text-muted); }
.field--check { justify-content: flex-end; }
.field--right { margin-left: auto; }

.controls {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  gap: 16px 20px;
}

.seg {
  display: inline-flex;
  border: 1px solid var(--border-input);
  border-radius: 8px;
  overflow: hidden;
  background: var(--surface);
}
.seg button {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: transparent;
  border: 0;
  border-left: 1px solid var(--border-input);
  padding: 9px 14px;
  cursor: pointer;
  white-space: nowrap;
}
.seg button:first-child { border-left: 0; }
.seg button[aria-pressed="true"] { background: var(--up); color: #FFFFFF; }
.seg button:disabled { color: var(--text-faint); background: var(--surface-sub); cursor: default; }

select {
  font: inherit;
  font-size: 14px;
  color: var(--text);
  background: var(--surface);
  border: 1px solid var(--border-input);
  border-radius: 8px;
  padding: 8px 10px;
  min-width: 140px;
}

.check { display: inline-flex; align-items: center; gap: 8px; padding: 9px 0; cursor: pointer; }
.check input { width: 18px; height: 18px; margin: 0; accent-color: var(--up); }

.btn {
  font: inherit;
  font-size: 14px;
  border-radius: 8px;
  padding: 10px 16px;
  cursor: pointer;
}
.btn--main { background: var(--up); color: #FFFFFF; border: 1px solid var(--up); }
.btn--main:hover { background: var(--up-hover); }
.btn--sub { background: var(--surface); color: var(--text); border: 1px solid var(--border-input); }
.btn:disabled { opacity: 0.45; cursor: default; }

button:focus-visible, select:focus-visible, input:focus-visible, a:focus-visible {
  outline: 2px solid var(--up);
  outline-offset: 2px;
}

/* ---------- 01-26 軸の比率の調節(「自分で調節」のときだけ開く) ---------- */

.ratio-panel {
  flex-basis: 100%;
  display: flex;
  flex-direction: column;
  gap: 12px;
  padding-top: 16px;
  border-top: 1px solid var(--row-line);
}
.ratio-panel[hidden] { display: none; }
.ratio-panel__head { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; }
.ratio-panel__title { font-size: 14px; font-weight: 700; }
.ratio-panel__note { font-size: 12px; color: var(--text-muted); }
.ratio-panel__body {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 12px 24px;
}
.ratio-slider { display: flex; align-items: center; gap: 8px; }
.ratio-slider__label { font-size: 14px; min-width: 48px; }
.ratio-slider input[type="range"] { width: 160px; margin: 0; accent-color: var(--up); }
.ratio-slider__value { min-width: 32px; text-align: right; font-size: 14px; }

/* ---------- 見出し行 ---------- */

.heading-row {
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  justify-content: space-between;
  gap: 8px 24px;
  margin: 20px 0 12px;
}
.heading-row__title { display: flex; flex-wrap: wrap; align-items: baseline; gap: 4px 16px; }
.count { font-size: 14px; color: var(--text-sub); }
.legend { display: flex; flex-wrap: wrap; gap: 4px 16px; font-size: 12px; color: var(--text-muted); }

.chg-up { color: var(--up); }
.chg-down { color: var(--down); }
.chg-none { color: var(--text-faint); }

/* ---------- 一覧表 ---------- */

.table-card { padding: 0; overflow: hidden; }

.table-scroll { overflow-x: auto; }

table.ranking {
  width: 100%;
  min-width: 1080px;
  border-collapse: collapse;
  font-size: 14px;
}

table.ranking th {
  background: var(--surface-sub);
  text-align: left;
  font-weight: 500;
  font-size: 12px;
  color: var(--text-muted);
  padding: 0;
  white-space: nowrap;
}
table.ranking th.num { text-align: right; }

.th-btn {
  font: inherit;
  color: inherit;
  background: transparent;
  border: 0;
  width: 100%;
  padding: 10px 12px;
  text-align: inherit;
  cursor: pointer;
}
.th-btn:hover { color: var(--text); }
.th-btn:disabled { cursor: default; }
.th-btn:disabled:hover { color: inherit; }
.th-btn .unit { font-weight: 400; }
th[aria-sort] .th-btn { color: var(--text); font-weight: 700; }
th[aria-sort="descending"] .th-btn::after { content: " \25BC"; font-size: 10px; }
th[aria-sort="ascending"] .th-btn::after { content: " \25B2"; font-size: 10px; }

table.ranking td {
  padding: 9px 12px;
  border-top: 1px solid var(--row-line);
  vertical-align: middle;
}
table.ranking td.num { text-align: right; }
table.ranking tbody tr:hover { background: var(--bg); }

.col-rank { width: 64px; }
.col-chg { width: 96px; }
.col-sector { color: var(--text-sub); white-space: nowrap; }
.col-axis { width: 84px; }
.col-total { font-size: 16px; font-weight: 500; }
.col-cap { white-space: nowrap; }
.col-rel { width: 72px; }

.stock-link { font-weight: 500; margin-right: 6px; }
.code { color: var(--text-faint); font-size: 12px; margin-left: 4px; }

.chg { display: inline-block; }
.chg-sub { display: block; font-size: 11px; color: var(--text-muted); }

.score { display: block; line-height: 1.3; }
.minibar {
  display: block;
  height: 4px;
  margin-top: 4px;
  background: var(--row-line);
  border-radius: 2px;
  overflow: hidden;
}
.minibar__fill { display: block; height: 100%; background: var(--up); }

.rel-低 { color: var(--down); }

.status { padding: 24px 20px; color: var(--text-muted); }
.status--error { color: var(--down); }
.status[hidden], .table-scroll[hidden] { display: none; }

.unit { color: var(--text-muted); }

/* ---------- ページ操作 ---------- */

.pager {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: center;
  gap: 12px 16px;
  margin-top: 20px;
}
.pager__info { color: var(--text-muted); font-size: 12px; min-width: 64px; text-align: center; }

/* ---------- 銘柄詳細 (SCR-02) ---------- */

.back { margin: 0 0 12px; font-size: 14px; }

.summary {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 16px 32px;
}
.summary__meta { font-size: 12px; color: var(--text-muted); }
.summary__title { font-size: 28px; }
.summary__facts { display: flex; flex-wrap: wrap; gap: 12px 32px; margin: 0; }
.fact dt { font-size: 12px; color: var(--text-muted); }
.fact dd { margin: 0; font-size: 16px; font-family: var(--font-mono); font-weight: 500; }
.fact--total dd { font-size: 32px; line-height: 1.2; }
.fact dd.rel-低 { color: var(--down); }

/* 02-25 プリセット別の総合偏差値・順位。選んでいる行は --surface-sub で強調する */
.summary__preset-table { flex-basis: 100%; }
table.preset-table { border-collapse: collapse; font-size: 13px; min-width: 420px; }
table.preset-table caption { text-align: left; font-size: 12px; color: var(--text-muted); padding-bottom: 4px; }
table.preset-table th, table.preset-table td { padding: 8px 10px; white-space: nowrap; }
table.preset-table thead th {
  background: var(--surface-sub);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
}
table.preset-table tbody th { text-align: left; font-weight: 400; color: var(--text-sub); }
table.preset-table tbody th, table.preset-table tbody td { border-top: 1px solid var(--row-line); }
table.preset-table .num { text-align: right; }
table.preset-table tr.is-current { background: var(--surface-sub); }
table.preset-table tr.is-current th { color: var(--text); font-weight: 700; }

.section-title { margin: 24px 0 12px; }
.section-note { margin: -8px 0 12px; font-size: 12px; color: var(--text-muted); }
.section-note[hidden] { display: none; }

.cards-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 20px;
}
.axis-card__head { display: flex; align-items: baseline; gap: 8px; }
.axis-card__name { margin: 0; font-size: 16px; font-weight: 700; }
.axis-card__score { margin-left: auto; font-size: 20px; font-weight: 500; }
.axis-card .minibar { margin: 6px 0 10px; }

table.metrics, table.changes, table.financials {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
table.metrics th, table.changes th, table.financials th {
  background: var(--surface-sub);
  color: var(--text-muted);
  font-size: 12px;
  font-weight: 500;
  text-align: left;
  padding: 8px 10px;
  white-space: nowrap;
}
table.metrics td, table.changes td, table.financials td {
  padding: 8px 10px;
  border-top: 1px solid var(--row-line);
}
table.metrics th.num, table.changes th.num, table.financials th.num,
table.metrics td.num, table.changes td.num, table.financials td.num { text-align: right; }
table.financials { min-width: 560px; }
table.financials tbody th { background: transparent; color: var(--text-sub); border-top: 1px solid var(--row-line); font-size: 13px; }
table.changes { margin-top: 12px; }

.chart-card { margin-top: 20px; }
.chart-card__head { display: flex; flex-wrap: wrap; align-items: center; gap: 8px 16px; }
.chart-card__freq { font-size: 12px; color: var(--text-muted); }
.chart-card__checks { display: flex; flex-wrap: wrap; align-items: center; gap: 4px 20px; margin: 8px 0; }
.chart-box { position: relative; width: 100%; }
.chart-box[hidden], .chart-group[hidden], #chart-area[hidden], .status[hidden] { display: none; }
.chart-group + .chart-group { margin-top: 8px; }
.chart-box--price { height: 280px; }
.chart-box--rsi, .chart-box--volume { height: 100px; }
.chart-box--macd { height: 120px; }
.chart-box--small { height: 200px; margin-top: 8px; }
.chart-legend { margin-top: 4px; }

.sw { display: inline-block; vertical-align: middle; margin-right: 4px; }
.sw--line, .sw--mid, .sw--ma, .sw--rsi, .sw--macd, .sw--signal { width: 16px; height: 0; border-top: 2px solid var(--text); }
.sw--mid { border-top: 2px dashed var(--up); }
.sw--ma { border-top-color: var(--ma); }
.sw--rsi { border-top-color: var(--rsi); }
.sw--signal { border-top: 2px dashed var(--down); }
.sw--band, .sw--hist, .sw--vol, .sw--up, .sw--flat, .sw--down { width: 12px; height: 12px; }
.sw--band { background: var(--up); opacity: 0.2; }
.sw--hist { background: var(--up); opacity: 0.45; }
.sw--vol { background: var(--border-input); }
.sw--up { background: var(--up); }
.sw--flat { background: var(--neutral-bar); }
.sw--down { background: var(--down); }

.pair {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(420px, 1fr));
  gap: 20px;
  margin-top: 20px;
}
.streaks { margin: 4px 0 0; font-size: 13px; color: var(--text-sub); }

@media (max-width: 720px) {
  .pair { grid-template-columns: 1fr; }
  .summary__title { font-size: 22px; }
}

@media (max-width: 720px) {
  .site-header { padding: 16px; position: static; }  /* 狭い画面では折り返して高くなるため固定しない */
  .page { padding: 16px 16px 40px; }
  .field--right { margin-left: 0; }

  /* 切替ボタンは2列に折り返し、枠からはみ出さないようにする */
  .controls .field { min-width: 0; max-width: 100%; }
  .seg { display: grid; grid-template-columns: repeat(2, 1fr); max-width: 100%; }
  .seg button { border-left: 0; border-top: 1px solid var(--border-input); }
  .seg button:nth-child(even) { border-left: 1px solid var(--border-input); }
  .seg button:nth-child(-n + 2) { border-top: 0; }
}

/* ---------- セクター別 (SCR-04) ---------- */

.pattern-cards { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); margin-bottom: 8px; }
.pattern-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  text-align: left;
  font: inherit;
  color: var(--text);
  cursor: pointer;
}
.pattern-card:hover { border-color: var(--border-input); }
.pattern-card[aria-pressed="true"] { border: 2px solid var(--up); padding: 17px 19px; }
.pattern-card__arrows { font-size: 16px; font-weight: 700; letter-spacing: 2px; }
.pattern-card__name { font-size: 14px; font-weight: 700; }
.pattern-card__count { font-size: 20px; font-weight: 500; }
.pattern-card__count .unit { font-size: 12px; margin-left: 2px; }
.pattern-card__hint { font-size: 12px; color: var(--text-muted); }

#legend { margin-bottom: 12px; }
.pattern-legend { margin: 0 0 6px; font-size: 13px; font-weight: 700; color: var(--text); }
.pattern-arrows { display: inline-flex; gap: 4px; margin-right: 8px; font-weight: 700; }
.pattern-label { font-size: 12px; color: var(--text-muted); }

table.sectors { min-width: 920px; font-size: 13px; }
table.sectors td.col-n, table.sectors td.col-total { white-space: nowrap; }
table.sectors .col-total { font-size: 13px; font-weight: 400; }
table.sectors .col-pattern { white-space: nowrap; }
table.sectors .col-top { white-space: nowrap; }
table.sectors th.col-bar { width: 190px; }

.pctbar { display: flex; flex-direction: column; gap: 3px; }
.pctbar .pct { font-size: 13px; }
.hbar {
  position: relative;
  display: block;
  height: 8px;
  background: var(--track);
  border-radius: 2px;
}
.hbar::before {
  content: "";
  position: absolute;
  left: 50%;
  top: -1px;
  bottom: -1px;
  width: 1px;
  background: var(--border-input);
}
.hbar__fill { position: absolute; top: 0; bottom: 0; }
.hbar__fill--up { left: 50%; background: var(--up); }
.hbar__fill--down { right: 50%; background: var(--down); }
