/* 引け値台帳 — 相場罫線用紙をたどった配色。色は「方向」の意味にだけ使う。 */

:root {
  --paper:      #E9ECE7;   /* 罫線用紙 */
  --paper-2:    #F3F5F1;   /* 面の上げ */
  --rule:       #CBD2C7;   /* 罫 */
  --rule-fine:  #DCE1D9;   /* 方眼 */
  --ink:        #1B1F1C;   /* 墨 */
  --ink-mute:   #6C7469;   /* 淡墨 */
  --shu:        #C0392B;   /* 朱 — 上昇・勝ち (日本式の陽線) */
  --shu-fill:   #C0392B22;
  --ai:         #254D82;   /* 藍 — 下落・負け */
  --ai-fill:    #254D8222;

  --ja-display: "Shippori Mincho", "Hiragino Mincho ProN", "Yu Mincho", serif;
  --ja-body:    "Zen Kaku Gothic New", "Hiragino Sans", "Noto Sans JP", sans-serif;
  --figure:     "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;

  --gutter: clamp(1rem, 3vw, 2.5rem);
  --stack:  clamp(1.75rem, 4vw, 3rem);
}

@media (prefers-color-scheme: dark) {
  :root {
    --paper:     #14181A;
    --paper-2:   #1B2023;
    --rule:      #2E373A;
    --rule-fine: #232A2D;
    --ink:       #DFE4DE;
    --ink-mute:  #858F87;
    --shu:       #E0574A;
    --shu-fill:  #E0574A2E;
    --ai:        #6597D8;
    --ai-fill:   #6597D82E;
  }
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: var(--ja-body);
  font-size: 15px;
  line-height: 1.7;
  -webkit-font-smoothing: antialiased;
}

/* 数字は台帳なので必ず等幅・桁揃え */
.fig, td.num, th.num, .stat-value, .band-value, tspan {
  font-family: var(--figure);
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum" 1;
}

a { color: inherit; }
:focus-visible { outline: 2px solid var(--shu); outline-offset: 3px; }

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

.masthead {
  border-bottom: 1px solid var(--ink);
  padding: 1.25rem var(--gutter) 0;
  display: flex;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 0.5rem 1.5rem;
}

.masthead h1 {
  font-family: var(--ja-display);
  font-weight: 700;
  font-size: clamp(1.35rem, 3vw, 1.7rem);
  letter-spacing: 0.14em;
  margin: 0 0 0.75rem;
}

.masthead .sub {
  color: var(--ink-mute);
  font-size: 0.8rem;
  letter-spacing: 0.05em;
  margin: 0 0 0.75rem;
}

.masthead .sub .fig { color: var(--ink); }

/* 口座タブ — 台帳の見出し紙 */
.ledger-tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 0;
  padding: 0 var(--gutter);
  margin-top: -1px;
  border-bottom: 1px solid var(--rule);
  background: var(--paper);
  position: sticky;
  top: 0;
  z-index: 5;
}

.tab {
  appearance: none;
  background: none;
  border: 0;
  border-bottom: 2px solid transparent;
  color: var(--ink-mute);
  font-family: inherit;
  font-size: 0.9rem;
  padding: 0.7rem 1rem;
  cursor: pointer;
  display: flex;
  align-items: baseline;
  gap: 0.5rem;
  white-space: nowrap;
}

.tab:hover { color: var(--ink); }

.tab[aria-selected="true"] {
  color: var(--ink);
  border-bottom-color: var(--ink);
}

.tab .pct { font-family: var(--figure); font-size: 0.8rem; }
.tab .pct.up { color: var(--shu); }
.tab .pct.down { color: var(--ai); }

/* ------------------------------------------------------------------ 版面 */

main {
  max-width: 1180px;
  margin: 0 auto;
  padding: var(--stack) var(--gutter) 5rem;
}

section + section { margin-top: var(--stack); }

.section-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 1rem;
  border-bottom: 1px solid var(--rule);
  padding-bottom: 0.4rem;
  margin-bottom: 1.1rem;
}

.section-head h2 {
  font-family: var(--ja-display);
  font-weight: 700;
  font-size: 1.05rem;
  letter-spacing: 0.1em;
  margin: 0;
}

.section-head .hint {
  color: var(--ink-mute);
  font-size: 0.78rem;
}

/* ------------------------------------------------------------------ 差の帯 (主役) */

.band {
  position: relative;
  background: var(--paper-2);
  border: 1px solid var(--rule);
}

/* 方眼 — 作画面にだけ敷く。台帳の罫線用紙のたとえはここで止める。 */
.band-plot {
  border-top: 1px solid var(--rule-fine);
  border-bottom: 1px solid var(--rule-fine);
  background-image:
    repeating-linear-gradient(to right, var(--rule-fine) 0 1px, transparent 1px 44px),
    repeating-linear-gradient(to bottom, var(--rule-fine) 0 1px, transparent 1px 44px);
}

.band-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-end;
  justify-content: space-between;
  gap: 1rem;
  padding: 1.1rem 1.25rem 0.5rem;
}

.band-label {
  font-size: 0.8rem;
  color: var(--ink-mute);
  letter-spacing: 0.06em;
  max-width: 30ch;
}

.band-readout { text-align: right; line-height: 1.15; }

.band-value {
  font-size: clamp(2.4rem, 7vw, 3.9rem);
  font-weight: 500;
  letter-spacing: -0.02em;
  display: block;
}

.band-value.up { color: var(--shu); }
.band-value.down { color: var(--ai); }

.band-caption {
  font-size: 0.78rem;
  color: var(--ink-mute);
}

.band svg {
  display: block;
  width: 100%;
  /* preserveAspectRatio="none" で伸ばすので、高さは直接与えて画面幅に潰されないようにする */
  height: clamp(220px, 24vw, 300px);
}

.band-axis {
  display: flex;
  justify-content: space-between;
  padding: 0.35rem 1.25rem 0;
  font-size: 0.72rem;
  color: var(--ink-mute);
}

/* 読み込み時に左から引く。一度だけ。 */
@keyframes draw-band { from { transform: scaleX(0); } to { transform: scaleX(1); } }

.band .plot {
  transform-origin: left center;
  animation: draw-band 900ms cubic-bezier(0.22, 0.65, 0.3, 1) both;
}

@media (prefers-reduced-motion: reduce) {
  .band .plot { animation: none; }
}

.band-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.5rem 1.25rem;
  padding: 0.7rem 1.25rem 0.85rem;
  font-size: 0.78rem;
  color: var(--ink-mute);
}

.band-legend .zero-note { margin-right: auto; }

.band-legend button {
  appearance: none;
  border: 1px solid var(--rule);
  background: transparent;
  color: var(--ink-mute);
  font-family: inherit;
  font-size: 0.78rem;
  padding: 0.15rem 0.6rem;
  cursor: pointer;
}

.band-legend button[aria-pressed="true"] {
  border-color: var(--ink);
  color: var(--ink);
}

.swatch {
  display: inline-block;
  width: 0.7em;
  height: 0.7em;
  margin-right: 0.35em;
  vertical-align: baseline;
}

.swatch.shu { background: var(--shu); }
.swatch.ai { background: var(--ai); }

/* ------------------------------------------------------------------ 勘定 */

.accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(190px, 1fr));
  border-top: 1px solid var(--rule);
  border-left: 1px solid var(--rule);
}

.stat {
  border-right: 1px solid var(--rule);
  border-bottom: 1px solid var(--rule);
  padding: 0.85rem 1rem 0.95rem;
}

.stat-label {
  font-size: 0.75rem;
  color: var(--ink-mute);
  letter-spacing: 0.06em;
  display: block;
  margin-bottom: 0.15rem;
}

.stat-value {
  display: block;
  font-size: 1.3rem;
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.35;
}

.stat-unit {
  font-family: var(--ja-body);
  font-size: 0.8rem;
  color: var(--ink-mute);
  margin-left: 0.25em;
  letter-spacing: 0;
}

.stat-sub {
  display: block;
  font-size: 0.78rem;
  color: var(--ink-mute);
  line-height: 1.55;
  margin-top: 0.1rem;
}
.up { color: var(--shu); }
.down { color: var(--ai); }

/* ------------------------------------------------------------------ 表 */

.sheet {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.88rem;
}

.sheet th {
  text-align: left;
  font-weight: 500;
  font-size: 0.75rem;
  color: var(--ink-mute);
  letter-spacing: 0.06em;
  border-bottom: 1px solid var(--ink);
  padding: 0.35rem 0.6rem;
  white-space: nowrap;
}

.sheet td {
  border-bottom: 1px solid var(--rule-fine);
  padding: 0.5rem 0.6rem;
  vertical-align: baseline;
}

.sheet .num { text-align: right; }
.sheet tbody tr:hover { background: var(--paper-2); }
.sheet .code { color: var(--ink-mute); font-family: var(--figure); font-size: 0.82rem; }

.scroll-x { overflow-x: auto; }
.scroll-x table { min-width: 640px; }

/* ------------------------------------------------------------------ 立会日誌 */

.journal { border-top: 1px solid var(--rule); }

.entry {
  display: grid;
  grid-template-columns: 8.5rem 1fr;
  gap: 0 1.25rem;
  padding: 0.9rem 0;
  border-bottom: 1px solid var(--rule-fine);
}

.entry-date {
  font-family: var(--figure);
  font-size: 0.85rem;
  color: var(--ink-mute);
  line-height: 1.5;
}

.entry-date .nth {
  display: block;
  font-size: 0.72rem;
  color: var(--ink-mute);
  opacity: 0.75;
}

.entry-note {
  font-size: 0.92rem;
  line-height: 1.75;
  max-width: 68ch;
}

.entry-note.quiet { color: var(--ink-mute); }

.entry-settled {
  margin-top: 0.6rem;
  font-size: 0.72rem;
  color: var(--ink-mute);
  letter-spacing: 0.05em;
}

.entry-fills {
  margin: 0.2rem 0 0;
  padding: 0;
  list-style: none;
  font-size: 0.82rem;
  font-family: var(--figure);
}

.entry-fills li {
  padding: 0.15rem 0 0.15rem 0.75rem;
  border-left: 2px solid var(--rule);
}

.entry-fills .from {
  font-family: var(--ja-body);
  font-size: 0.72rem;
  color: var(--ink-mute);
}

.entry-fills .side-buy { color: var(--shu); }
.entry-fills .side-sell { color: var(--ai); }

.entry-equity {
  font-family: var(--figure);
  font-size: 0.78rem;
  color: var(--ink-mute);
  margin-top: 0.3rem;
}

/* ------------------------------------------------------------------ 比較 */

.compare-row {
  display: grid;
  grid-template-columns: minmax(9rem, 1fr) 2fr minmax(7rem, auto);
  gap: 1rem;
  align-items: center;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--rule-fine);
}

.compare-name { font-size: 0.92rem; }
.compare-name .desc { display: block; font-size: 0.75rem; color: var(--ink-mute); }
.compare-row svg { display: block; width: 100%; height: 42px; }

.compare-value { text-align: right; font-family: var(--figure); }
.compare-value .big { font-size: 1.15rem; }
.compare-value .small { display: block; font-size: 0.75rem; color: var(--ink-mute); }

.empty {
  border: 1px dashed var(--rule);
  padding: 2rem 1.25rem;
  text-align: center;
  color: var(--ink-mute);
  font-size: 0.9rem;
}

.empty code {
  font-family: var(--figure);
  background: var(--paper-2);
  border: 1px solid var(--rule);
  padding: 0.1rem 0.4rem;
  font-size: 0.85rem;
  color: var(--ink);
}

.footnote {
  margin-top: var(--stack);
  padding-top: 1rem;
  border-top: 1px solid var(--rule);
  font-size: 0.78rem;
  color: var(--ink-mute);
  line-height: 1.9;
}

.footnote code { font-family: var(--figure); color: var(--ink); }

@media (max-width: 640px) {
  .section-head { flex-direction: column; align-items: flex-start; gap: 0.15rem; }
  .band-head { flex-direction: column; align-items: flex-start; }
  .band-readout { text-align: left; }
  .entry { grid-template-columns: 1fr; gap: 0.35rem; }
  .compare-row { grid-template-columns: 1fr auto; }
  .compare-row svg { grid-column: 1 / -1; }
}
