/* 色・余白・文字サイズはすべて変数。ダークが基本で、ライトは同じ変数の差し替え */
:root {
  color-scheme: dark;
  --bg: #0E1116;
  --card: #171B22;
  --border: #262C36;
  --text: #E8EBF0;
  --sub: #A3ACB9;
  --profit: #7AA7FF;
  --profit-bar: #5B8DEF;
  --loss: #FF9466;
  --loss-bar: #F07A45;
  --draw-bar: #667080;
  --draw-text: #C3CAD4;
  --draw-ring: #A3ACB9;
  --day-profit: #1B2A4A;
  --day-loss: #3A2218;
  --day-draw: #252B34;
  --amt-profit: #9DBDFF;
  --amt-loss: #FFA27A;
  --btn: #E8EBF0;
  --btn-text: #0E1116;
  --seg-bg: #1A1F27;
  --seg-on: #2E3542;
  --seg-on-text: #FFFFFF;
  --seg-off-text: #A3ACB9;
  --seg-shadow: none;
  --chip-bg: transparent;
  --chip-border: #343B47;
  --cell: #1A1F27;
  --cell-border: #1A1F27;
  --weekend-num: #7D8796;
  --dash: #4A5260;
  --nav: #12161C;
  --inset: #0E1116;
  --col-hl: #20262F;
  --zero-line: #4A5260;
  --field: #0E1116;
  --field-border: #343B47;
  --backdrop: rgba(0, 0, 0, 0.6);
  /* 買い=赤・売り=青(FX会社のアプリの見慣れた色。入力画面のボタンだけに使う) */
  --buy: #D7263D;
  --buy-text: #FF6B78;
  --sell: #2563EB;
  --sell-text: #6FA0FF;

  --fs-big: 40px;
  --fs-title: 26px;
  --fs-h: 16px;
  --fs-body: 14px;
  --fs-sub: 12px;
  --fs-min: 11px;
  --gap: 16px;
  --pad: 16px;
  --radius-card: 16px;
  --radius-big: 20px;
  --tap: 44px;
  --font: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Noto Sans JP", "Yu Gothic UI", Meiryo, system-ui, sans-serif;
}

:root[data-theme="light"] {
  color-scheme: light;
  --bg: #F4F6F8;
  --card: #FFFFFF;
  --border: #E3E7EC;
  --text: #111827;
  --sub: #4B5563;
  --profit: #1D4ED8;
  --profit-bar: #1D4ED8;
  --loss: #B23A0A;
  --loss-bar: #D9622B;
  --draw-bar: #8A94A1; /* キャンバスの #CBD2DA では白との差が 3:1 に届かないため、少し濃くした */
  --draw-text: #374151;
  --draw-ring: #6B7280;
  --day-profit: #E8EEFC;
  --day-loss: #FCEDE4;
  --day-draw: #EEF1F4;
  --amt-profit: #1D4ED8;
  --amt-loss: #B23A0A;
  --btn: #111827;
  --btn-text: #FFFFFF;
  --seg-bg: #E5E8EC;
  --seg-on: #FFFFFF;
  --seg-on-text: #111827;
  --seg-off-text: #374151;
  --seg-shadow: 0 1px 2px rgba(17, 24, 39, 0.12);
  --chip-bg: #FFFFFF;
  --chip-border: #CBD2DA;
  --cell: #FFFFFF;
  --cell-border: #EEF1F4;
  --weekend-num: #6B7280;
  --dash: #9AA3AE;
  --nav: #FFFFFF;
  --inset: #F4F6F8;
  --col-hl: #EEF1F4;
  --zero-line: #9AA3AE;
  --field: #FFFFFF;
  --field-border: #CBD2DA;
  --backdrop: rgba(17, 24, 39, 0.45);
  --buy-text: #D7263D;
  --sell-text: #2563EB;
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: var(--fs-body);
  font-variant-numeric: tabular-nums;
  line-height: 1.5;
  -webkit-tap-highlight-color: transparent;
}
button, input, select, textarea { font: inherit; color: inherit; }
button { cursor: pointer; }
:focus-visible { outline: 2px solid var(--text); outline-offset: 2px; }
[hidden] { display: none !important; }
.num { font-variant-numeric: tabular-nums; }
.profit { color: var(--profit); }
.loss { color: var(--loss); }
.draw { color: var(--draw-text); }
.sub { color: var(--sub); }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }

/* ---------- 全体の枠 ---------- */
.app { max-width: 480px; margin: 0 auto; min-height: 100vh; }
main {
  display: flex; flex-direction: column; gap: var(--gap);
  padding: calc(24px + env(safe-area-inset-top)) var(--pad) calc(112px + env(safe-area-inset-bottom)) var(--pad);
}
h1 { margin: 0; font-size: var(--fs-title); font-weight: 700; letter-spacing: 0.02em; }
h2 { margin: 0; font-size: var(--fs-h); font-weight: 700; }
.head { display: flex; flex-direction: column; gap: 14px; }
.head-row { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; }

.card {
  display: flex; flex-direction: column; gap: 12px;
  padding: var(--pad); background: var(--card);
  border: 1px solid var(--border); border-radius: var(--radius-card);
}
.card-big { gap: 18px; padding: 20px; border-radius: var(--radius-big); }
.card-title { display: flex; align-items: baseline; justify-content: space-between; gap: 8px; flex-wrap: wrap; }
.card-title .hint { font-size: var(--fs-sub); color: var(--sub); }

/* ---------- 切り替えボタン ---------- */
.seg {
  display: grid; grid-auto-columns: minmax(0, 1fr); grid-auto-flow: column; gap: 4px;
  padding: 4px; background: var(--seg-bg); border-radius: 12px;
}
.seg button {
  min-height: var(--tap); border: 0; border-radius: 9px; background: transparent;
  color: var(--seg-off-text); font-size: var(--fs-body); font-weight: 500;
}
.seg button[aria-pressed="true"] { background: var(--seg-on); color: var(--seg-on-text); font-weight: 700; box-shadow: var(--seg-shadow); }
.seg.seg-theme { grid-auto-flow: row; grid-template-columns: 1fr 1fr 1.6fr; }
.seg button { white-space: nowrap; }
.seg.tall button { min-height: 56px; font-size: 17px; }

.chips { display: flex; gap: 8px; flex-wrap: wrap; }
.chips button {
  min-height: var(--tap); padding: 0 18px; border: 1px solid var(--chip-border);
  border-radius: 999px; background: var(--chip-bg); color: var(--text); font-size: var(--fs-body); font-weight: 500;
}
.chips button[aria-pressed="true"] { background: var(--btn); border-color: var(--btn); color: var(--btn-text); font-weight: 700; }

.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: var(--tap); padding: 0 16px; border: 0; border-radius: 12px;
  background: var(--btn); color: var(--btn-text); font-size: var(--fs-body); font-weight: 700;
  text-decoration: none; white-space: nowrap;
}
.btn.big { min-height: 60px; font-size: 18px; border-radius: 16px; width: 100%; }
.btn.ghost { background: transparent; color: var(--text); border: 1px solid var(--chip-border); }
.btn.danger { background: transparent; color: var(--text); border: 1px solid var(--chip-border); }
.btn:disabled { opacity: 0.4; cursor: not-allowed; }

/* ---------- 入力画面 ---------- */
.sides { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.sides button {
  min-height: 72px; border: 2px solid var(--chip-border); border-radius: 16px;
  background: var(--card); color: var(--text); font-size: 22px; font-weight: 700;
}
.sides button.buy { border-color: var(--buy); color: var(--buy-text); }
.sides button.sell { border-color: var(--sell); color: var(--sell-text); }
.sides button.buy[aria-pressed="true"] { background: var(--buy); border-color: var(--buy); color: #FFFFFF; }
.sides button.sell[aria-pressed="true"] { background: var(--sell); border-color: var(--sell); color: #FFFFFF; }
.field { display: flex; flex-direction: column; gap: 6px; }
.field > span { font-size: var(--fs-sub); font-weight: 600; color: var(--sub); }
.field input, .field select, .field textarea {
  width: 100%; min-height: 52px; padding: 0 14px;
  background: var(--field); border: 1px solid var(--field-border); border-radius: 12px;
  font-size: 18px; font-variant-numeric: tabular-nums;
}
.field textarea { min-height: 72px; padding: 10px 14px; font-size: 15px; resize: vertical; }
.field input.price { min-height: 64px; font-size: 28px; font-weight: 700; letter-spacing: 0.02em; }
.field select { font-size: 16px; appearance: auto; }
.row2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.stepper { display: grid; grid-template-columns: 52px 1fr 52px; gap: 6px; }
.stepper button { min-height: 52px; border: 1px solid var(--field-border); border-radius: 12px; background: var(--card); font-size: 22px; font-weight: 700; }
.stepper input { text-align: center; }
.preview { font-size: var(--fs-body); font-weight: 700; min-height: 21px; }

/* 保有中の一覧 */
.holding {
  display: flex; align-items: center; gap: 12px;
  padding: 12px 12px 12px 16px; background: var(--card);
  border: 1px dashed var(--dash); border-radius: 16px;
}
.holding .info { display: flex; flex-direction: column; gap: 2px; flex: 1 1 auto; min-width: 0; }
.holding .info .k { font-size: var(--fs-sub); font-weight: 600; color: var(--sub); }
.holding .info .v { font-size: var(--fs-body); font-weight: 600; }
.holding-list { display: flex; flex-direction: column; gap: 8px; }

/* ---------- 一覧 ---------- */
.filters { display: flex; flex-direction: column; gap: 10px; }
.trade-list { display: flex; flex-direction: column; gap: 8px; }
.trade-row {
  display: grid; grid-template-columns: 68px minmax(0, 1fr) auto; align-items: center; gap: 10px;
  width: 100%; min-height: 64px; padding: 10px 12px; text-align: left;
  background: var(--card); border: 1px solid var(--border); border-radius: 14px;
}
.trade-row .mid { display: flex; flex-direction: column; min-width: 0; }
.trade-row .t1 { font-weight: 600; }
.trade-row .t2, .trade-row .t3 { font-size: var(--fs-sub); color: var(--sub); }
.trade-row .amt { display: flex; flex-direction: column; align-items: flex-end; font-weight: 700; }
.trade-row .amt small { font-size: var(--fs-sub); font-weight: 600; }
.tag {
  display: inline-flex; align-items: center; justify-content: center; min-width: 40px;
  padding: 2px 8px; border-radius: 999px; font-size: var(--fs-sub); font-weight: 700; white-space: nowrap;
}
.tag.win { background: var(--day-profit); color: var(--profit); }
.tag.lose { background: var(--day-loss); color: var(--loss); }
.tag.draw { background: var(--day-draw); color: var(--draw-text); }
.tag.open { border: 1px dashed var(--dash); color: var(--sub); }

/* ---------- 集計:成績カード ---------- */
.big-label { font-size: 13px; font-weight: 500; color: var(--sub); }
.big-num { display: flex; align-items: baseline; gap: 6px; }
.big-num .n { font-size: var(--fs-big); font-weight: 700; letter-spacing: -0.01em; line-height: 1.1; }
.big-num .u { font-size: 18px; font-weight: 600; }
.headline { font-size: var(--fs-body); font-weight: 700; }
.headline.warn { color: var(--loss); }
.note { font-size: var(--fs-sub); line-height: 1.6; color: var(--sub); }
.band { display: flex; flex-direction: column; gap: 6px; }
.band-labels { display: flex; justify-content: space-between; gap: 6px; font-size: var(--fs-sub); font-weight: 700; flex-wrap: wrap; }
.bar { display: flex; gap: 2px; height: 14px; border-radius: 7px; overflow: hidden; background: var(--seg-bg); }
.bar > div { min-width: 0; }
.bar .w { background: var(--profit-bar); }
.bar .l { background: var(--loss-bar); }
.bar .d { background: var(--draw-bar); }
.metrics {
  display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.4fr) minmax(0, 1fr); gap: 8px;
  padding-top: 14px; border-top: 1px solid var(--border);
}
.metrics > div { display: flex; flex-direction: column; gap: 2px; min-width: 0; }
.metrics .k { font-size: var(--fs-min); color: var(--sub); }
.metrics .v { font-size: 13px; font-weight: 700; white-space: nowrap; }
.metrics .v.lg { font-size: 18px; }
.ref { display: inline-block; margin-left: 4px; padding: 0 6px; border-radius: 6px; background: var(--day-draw); color: var(--draw-text); font-size: var(--fs-min); font-weight: 700; vertical-align: middle; }

/* ---------- カレンダー ---------- */
.cal-nav { display: flex; align-items: center; gap: 4px; }
.cal-nav button { width: var(--tap); height: var(--tap); border: 1px solid var(--chip-border); border-radius: 12px; background: transparent; }
.cal-week, .cal-grid { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); gap: 4px; }
.cal-week { font-size: var(--fs-min); text-align: center; color: var(--sub); }
.cell {
  display: flex; flex-direction: column; align-items: center; gap: 3px;
  height: 62px; padding: 5px 0 0; border-radius: 10px; min-width: 0;
  background: var(--cell); border: 1px solid var(--cell-border);
}
.cell.weekend { background: transparent; border-color: transparent; }
.cell.pos { background: var(--day-profit); border-color: var(--day-profit); }
.cell.neg { background: var(--day-loss); border-color: var(--day-loss); }
.cell.even { background: var(--day-draw); border-color: var(--day-draw); }
.cell.sel { border: 2px solid var(--profit); padding-top: 4px; }
.cell.blank { visibility: hidden; }
.cell .d { font-size: var(--fs-min); line-height: 16px; font-weight: 600; }
.cell.weekend .d { color: var(--weekend-num); }
.cell .d.today { min-width: 18px; padding: 0 3px; border-radius: 8px; background: var(--btn); color: var(--btn-text); font-weight: 700; }
.cell .dots { display: flex; flex-wrap: wrap; justify-content: center; align-items: center; gap: 2px; min-height: 7px; }
.dot { width: 7px; height: 7px; border-radius: 50%; }
.dot.w { background: var(--profit); }
.dot.l { background: var(--loss); }
.dot.d { border: 1.5px solid var(--draw-ring); }
.cell .more { font-size: 9px; font-weight: 700; color: var(--sub); line-height: 7px; }
.cell .a { font-size: var(--fs-min); font-weight: 700; letter-spacing: -0.03em; color: var(--sub); white-space: nowrap; }
.cell.pos .a { color: var(--amt-profit); }
.cell.neg .a { color: var(--amt-loss); }
.cell.even .a { color: var(--draw-text); }
.legend { display: flex; flex-wrap: wrap; gap: 14px; font-size: var(--fs-sub); color: var(--sub); }
.legend span { display: inline-flex; align-items: center; gap: 5px; }
.legend .dot { width: 8px; height: 8px; }
.day-panel { display: flex; flex-direction: column; gap: 10px; padding: 12px; background: var(--inset); border-radius: 12px; }
.day-panel .tags { display: flex; gap: 6px; flex-wrap: wrap; }
.day-panel .rows { display: flex; flex-direction: column; gap: 6px; font-size: 13px; }
.day-panel .r { display: flex; justify-content: space-between; align-items: center; gap: 8px; }
.day-panel .r b { font-weight: 600; white-space: nowrap; }

/* ---------- グラフ ---------- */
.chart { position: relative; }
.chart svg { display: block; width: 100%; height: auto; overflow: visible; }
.chart .hit { position: absolute; top: 0; bottom: 0; border: 0; background: transparent; padding: 0; border-radius: 8px; }
.chart text { font-family: var(--font); font-variant-numeric: tabular-nums; }

/* ---------- 通貨ペア別の表 ---------- */
.ptable { display: flex; flex-direction: column; }
.prow { display: grid; grid-template-columns: 1.6fr 0.8fr 0.9fr 1.2fr; gap: 8px; align-items: center; min-height: 52px; border-bottom: 1px solid var(--col-hl); }
.prow:last-child { border-bottom: 0; }
.prow.head { min-height: 0; padding-bottom: 8px; border-bottom: 1px solid var(--border); font-size: var(--fs-sub); color: var(--sub); }
.prow > :not(:first-child) { text-align: right; }
.prow .name { display: flex; flex-direction: column; }
.prow .name b { font-weight: 600; }
.prow .name small { font-size: var(--fs-min); color: var(--sub); }

/* ---------- データなし ---------- */
.empty { align-items: center; gap: 14px; padding: 40px 24px; text-align: center; }
.empty .ic { display: flex; align-items: center; justify-content: center; width: 64px; height: 64px; border-radius: 20px; background: var(--day-profit); color: var(--profit); }
.empty h2 { font-size: 18px; }
.empty p { margin: 0; line-height: 1.7; color: var(--sub); }

/* ---------- 案内 ---------- */
.notice { display: flex; flex-direction: column; gap: 10px; padding: 14px 16px; border-radius: 14px; background: var(--card); border: 1px solid var(--border); }
.notice p { margin: 0; line-height: 1.6; }
.update-bar {
  position: fixed; left: 50%; transform: translateX(-50%); top: calc(8px + env(safe-area-inset-top)); z-index: 30;
  display: flex; align-items: center; gap: 12px; width: calc(100% - 32px); max-width: 448px;
  padding: 10px 10px 10px 16px; border-radius: 14px; background: var(--card); border: 1px solid var(--border);
  box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25);
}
.update-bar span { flex: 1 1 auto; font-weight: 600; }

/* ---------- 下のタブ ---------- */
nav.tabs {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 20;
  background: var(--nav); border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
}
nav.tabs .inner { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); max-width: 480px; margin: 0 auto; }
nav.tabs a {
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
  min-height: 48px; color: var(--sub); font-size: var(--fs-min); text-decoration: none;
}
nav.tabs a[aria-current="page"] { color: var(--text); font-weight: 700; }

/* ---------- 設定 ---------- */
.set-item { display: flex; flex-direction: column; gap: 8px; }
.set-item > .k { font-size: var(--fs-body); font-weight: 700; }
.set-item > .hint { font-size: var(--fs-sub); color: var(--sub); line-height: 1.6; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }
.btn-row .btn { flex: 1 1 140px; }

/* ---------- 確認の小窓 ---------- */
dialog {
  width: min(440px, calc(100% - 24px)); max-height: calc(100% - 24px); padding: 0;
  border: 1px solid var(--border); border-radius: 20px; background: var(--card); color: var(--text);
}
dialog::backdrop { background: var(--backdrop); }
.dlg { display: flex; flex-direction: column; gap: 14px; padding: 20px; }
.dlg h2 { font-size: 18px; }
.dlg p { margin: 0; line-height: 1.7; }
.dlg .actions { display: flex; flex-direction: column; gap: 8px; margin-top: 4px; }
.dlg .actions .btn { width: 100%; min-height: 52px; font-size: 16px; }

.toast {
  position: fixed; left: 50%; bottom: calc(92px + env(safe-area-inset-bottom)); transform: translateX(-50%);
  z-index: 40; padding: 12px 18px; border-radius: 12px; background: var(--btn); color: var(--btn-text);
  font-weight: 700; box-shadow: 0 6px 24px rgba(0, 0, 0, 0.25); transition: opacity 0.2s; width: max-content; max-width: calc(100% - 32px); text-align: center;
}
.toast.hide { opacity: 0; pointer-events: none; }

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation: none !important; transition: none !important; scroll-behavior: auto !important; }
}
