/* 夜神AI コックピット — apple-design の適用。値はすべて意図があるもの。
   §12 Materials / §15 Typography / §16 Foundations / §14 Reduced motion */

:root {
  /* iOS ダークの面。数値が大きいほど手前 */
  --bg: #000000;
  --l1: #1C1C1E;
  --l2: #2C2C2E;
  --l3: #3A3A3C;
  --sep: rgba(84, 84, 88, 0.42);

  /* 文字は色ではなく不透明度で階層を作る（iOS の label 階層） */
  --label: #FFFFFF;
  --label-2: rgba(235, 235, 245, 0.60);
  --label-3: rgba(235, 235, 245, 0.32);

  /* 意味を持つ色だけ。装飾には使わない */
  --blue: #0A84FF;
  --green: #30D158;
  --red: #FF453A;
  --orange: #FF9F0A;
  --teal: #64D2FF;
  --indigo: #5E5CE6;
  --yellow: #FFD60A;

  /* 余白は 4 の倍数 */
  --s1: 4px; --s2: 8px; --s3: 12px; --s4: 16px; --s5: 20px; --s6: 24px; --s8: 32px;
  --r-card: 16px;
  --r-tile: 12px;
  --r-pill: 999px;

  --tabbar-h: 64px;
  --header-h: 52px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--label);
  /* §15: プラットフォーム標準フォントを最優先。和文はWindowsのUI標準へ落とす */
  font-family: -apple-system, "Segoe UI Variable Text", "Segoe UI", system-ui,
               "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 15px;
  line-height: 1.45;
  letter-spacing: 0;                 /* 本文は tracking 0 */
  overflow: hidden;
  -webkit-font-smoothing: antialiased;
  user-select: none;
  cursor: default;
}

/* §15: 大きい文字ほど tracking を詰め、leading も詰める */
.large-title { font-size: 32px; font-weight: 700; letter-spacing: -0.024em; line-height: 1.12; }
.title-1     { font-size: 24px; font-weight: 700; letter-spacing: -0.018em; line-height: 1.18; }
.title-3     { font-size: 17px; font-weight: 600; letter-spacing: -0.008em; line-height: 1.3; }
.headline    { font-size: 15px; font-weight: 600; letter-spacing: -0.004em; }
.body        { font-size: 15px; font-weight: 400; }
.subhead     { font-size: 13px; font-weight: 400; color: var(--label-2); }
.footnote    { font-size: 12px; font-weight: 400; color: var(--label-3); letter-spacing: 0.004em; }
.caption     { font-size: 11px; font-weight: 500; color: var(--label-3); letter-spacing: 0.012em; }
.metric      { font-size: 34px; font-weight: 700; letter-spacing: -0.028em; line-height: 1.05;
               font-variant-numeric: tabular-nums; }
.metric-sm   { font-size: 22px; font-weight: 700; letter-spacing: -0.02em;
               font-variant-numeric: tabular-nums; }
.num         { font-variant-numeric: tabular-nums; }

.pos { color: var(--green); }
.neg { color: var(--red); }
.dim { color: var(--label-2); }

/* ---------- レイアウト ---------- */
#app { height: 100%; display: flex; flex-direction: column; position: relative; }

/* §12: chrome は不透明な帯ではなく、内容が下を流れる半透明レイヤー */
.header {
  position: absolute; inset: 0 0 auto 0; height: var(--header-h); z-index: 30;
  display: flex; align-items: center; gap: var(--s3); padding: 0 var(--s5);
  background: rgba(0, 0, 0, 0);
  backdrop-filter: blur(0px);
  transition: background 180ms ease, backdrop-filter 180ms ease;
}
/* スクロールで内容が潜り込んだときだけ材質が立ち上がる（§12 scroll edge effect） */
.header.materialized {
  background: rgba(20, 20, 22, 0.72);
  backdrop-filter: blur(24px) saturate(180%);
}
.header .spacer { flex: 1; }

.status-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--orange);
              box-shadow: 0 0 0 4px rgba(255, 159, 10, 0.14); }
.status-dot.ok   { background: var(--green); box-shadow: 0 0 0 4px rgba(48, 209, 88, 0.14); }
.status-dot.down { background: var(--red);   box-shadow: 0 0 0 4px rgba(255, 69, 58, 0.14); }

.scroll {
  flex: 1; overflow-y: auto; overflow-x: hidden;
  padding: calc(var(--header-h) + var(--s2)) var(--s5) calc(var(--tabbar-h) + var(--s6));
  scrollbar-width: thin; scrollbar-color: var(--l3) transparent;
  overscroll-behavior: contain;
}
.scroll::-webkit-scrollbar { width: 6px; }
.scroll::-webkit-scrollbar-thumb { background: var(--l3); border-radius: 3px; }
.scroll::-webkit-scrollbar-track { background: transparent; }

.page { display: none; height: 100%; flex-direction: column; }
.page.active { display: flex; }

/* ---------- タブバー（§12 半透明・§16 具体的な名前） ---------- */
.tabbar {
  position: absolute; inset: auto 0 0 0; height: var(--tabbar-h); z-index: 40;
  display: flex; align-items: stretch;
  background: rgba(18, 18, 20, 0.74);
  backdrop-filter: blur(28px) saturate(180%);
  border-top: 0.5px solid var(--sep);
}
.tab {
  flex: 1; display: flex; flex-direction: column; align-items: center; justify-content: center;
  gap: 3px; color: var(--label-3); cursor: pointer; position: relative;
  transition: color 140ms ease;
}
.tab .glyph { width: 22px; height: 22px; display: block; }
.tab .glyph path, .tab .glyph circle, .tab .glyph rect { stroke: currentColor; }
.tab span { font-size: 10px; font-weight: 600; letter-spacing: 0.01em; }
.tab.active { color: var(--blue); }
.tab:active .glyph { transform: scale(0.9); }        /* §1 押した瞬間に反応 */
.tab .glyph { transition: transform 100ms ease-out; }

/* ---------- カード（§12 材質で階層） ---------- */
.card {
  background: var(--l1); border-radius: var(--r-card);
  padding: var(--s5); margin-bottom: var(--s3);
}
.card.tight { padding: var(--s4); }
.card-head { display: flex; align-items: baseline; gap: var(--s2); margin-bottom: var(--s4); }
.card-head .sub { color: var(--label-3); font-size: 12px; }

.grid-2 { display: grid; grid-template-columns: repeat(2, 1fr); gap: var(--s3); }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: var(--s3); }
.grid-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: var(--s3); }
@media (max-width: 1040px) { .grid-4 { grid-template-columns: repeat(2, 1fr); } }

.stat { display: flex; flex-direction: column; gap: 2px; }
.stat .k { font-size: 12px; color: var(--label-3); }
.stat .v { font-size: 30px; font-weight: 700; letter-spacing: -0.026em;
           font-variant-numeric: tabular-nums; line-height: 1.1; }
.stat .n { font-size: 11px; color: var(--label-3); }

/* ---------- リスト行 ---------- */
.rows { display: flex; flex-direction: column; }
.row {
  display: flex; align-items: center; gap: var(--s3);
  padding: var(--s3) var(--s2); border-radius: 10px;
  cursor: pointer; transition: background 120ms ease, transform 100ms ease-out;
}
.row + .row { box-shadow: inset 0 0.5px 0 var(--sep); }
.row:hover { background: rgba(255, 255, 255, 0.04); }
.row:active { transform: scale(0.988); background: rgba(255, 255, 255, 0.07); }
.row .grow { flex: 1; min-width: 0; }
.row .ell { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

.badge {
  display: inline-flex; align-items: center; justify-content: center;
  min-width: 24px; height: 22px; padding: 0 7px; border-radius: 7px;
  font-size: 11px; font-weight: 700; letter-spacing: 0.01em;
  background: var(--l2); color: var(--label-2);
}
.badge.s { background: rgba(94, 92, 230, 0.22); color: #A9A7FF; }
.badge.a { background: rgba(10, 132, 255, 0.20); color: #6FB6FF; }
.badge.b { background: rgba(100, 210, 255, 0.16); color: #8FDCFF; }
.badge.c { background: var(--l2); color: var(--label-3); }
.badge.hit { background: rgba(48, 209, 88, 0.20); color: var(--green); }
.badge.miss { background: var(--l2); color: var(--label-3); }
.badge.jack { background: var(--green); color: #05240F; }

.pill {
  display: inline-flex; align-items: center; gap: 6px; height: 30px; padding: 0 var(--s3);
  border-radius: var(--r-pill); background: var(--l2); color: var(--label);
  font-size: 13px; font-weight: 600; cursor: pointer;
  transition: transform 100ms ease-out, background 140ms ease;
}
.pill:active { transform: scale(0.95); background: var(--l3); }
.pill.primary { background: var(--blue); color: #fff; }
.pill.danger  { background: rgba(255, 69, 58, 0.16); color: var(--red); }

/* ---------- 棒グラフ ---------- */
.bar-row { display: grid; grid-template-columns: 190px 1fr 92px; align-items: center;
           gap: var(--s3); padding: 5px 0; }
.bar { height: 8px; border-radius: 4px; background: var(--l2); overflow: hidden; }
.bar > i { display: block; height: 100%; border-radius: 4px; background: var(--blue);
           transform-origin: left center; }

/* 収支の推移 */
.spark { width: 100%; height: 68px; display: block; }

/* ---------- 表 ---------- */
table.t { width: 100%; border-collapse: collapse; font-variant-numeric: tabular-nums; }
table.t th {
  font-size: 11px; font-weight: 600; color: var(--label-3); text-align: right;
  padding: 0 var(--s2) var(--s2); letter-spacing: 0.012em;
}
table.t th:first-child, table.t td:first-child { text-align: left; }
table.t td { font-size: 14px; padding: var(--s2); text-align: right;
             box-shadow: inset 0 0.5px 0 var(--sep); }
table.t tr:first-child td { box-shadow: none; }

/* ---------- 設定行 ---------- */
.set-row { display: flex; align-items: center; gap: var(--s3); padding: var(--s3) 0; }
.set-row + .set-row { box-shadow: inset 0 0.5px 0 var(--sep); }
.set-row .grow { flex: 1; }

.switch {
  width: 50px; height: 30px; border-radius: var(--r-pill); background: var(--l3);
  position: relative; cursor: pointer; flex: none;
  transition: background 220ms cubic-bezier(0.2, 0.8, 0.2, 1);
}
.switch.on { background: var(--green); }
.switch i {
  position: absolute; top: 2px; left: 2px; width: 26px; height: 26px; border-radius: 50%;
  background: #fff; box-shadow: 0 2px 6px rgba(0, 0, 0, 0.35);
  transition: transform 260ms cubic-bezier(0.2, 0.9, 0.2, 1), width 160ms ease;
}
.switch.on i { transform: translateX(20px); }
.switch:active i { width: 30px; }        /* §1 押している間だけ伸びる */
.switch.on:active i { transform: translateX(16px); }

.seg {
  display: inline-flex; background: var(--l2); border-radius: 10px; padding: 2px;
  position: relative;
}
.seg button {
  border: 0; background: transparent; color: var(--label-2); font: inherit;
  font-size: 13px; font-weight: 600; padding: 6px 14px; border-radius: 8px;
  cursor: pointer; position: relative; z-index: 1; transition: color 160ms ease;
}
.seg button.on { color: var(--label); }
.seg .thumb {
  position: absolute; top: 2px; bottom: 2px; border-radius: 8px; z-index: 0;
  background: #48484A;                       /* 下地(--l2)との差を確保して選択位置が読めるように */
  box-shadow: 0 1px 3px rgba(0, 0, 0, 0.35), inset 0 0.5px 0 rgba(255, 255, 255, 0.10);
}

/* ---------- シート（§7 出入りは同じ経路・§2/3/5/6/9 はJS側） ---------- */
.scrim {
  position: absolute; inset: 0; z-index: 50; background: rgba(0, 0, 0, 0.5);
  opacity: 0; pointer-events: none;
}
.scrim.on { pointer-events: auto; }
.sheet {
  position: absolute; left: 50%; bottom: 0; z-index: 60;
  width: min(720px, calc(100% - 32px));
  max-height: 82%; display: flex; flex-direction: column;
  border-radius: 20px 20px 0 0;
  background: rgba(28, 28, 30, 0.86);
  backdrop-filter: blur(30px) saturate(180%);
  border: 0.5px solid rgba(255, 255, 255, 0.10);
  border-bottom: none;
  box-shadow: 0 -20px 60px rgba(0, 0, 0, 0.6);
  transform: translate(-50%, 100%);
  will-change: transform;
  pointer-events: none;
}
.sheet.on { pointer-events: auto; }
.grabber {
  width: 100%; padding: var(--s2) 0 var(--s1); display: flex; justify-content: center;
  cursor: grab; touch-action: none; flex: none;
}
.grabber:active { cursor: grabbing; }
.grabber i { width: 36px; height: 5px; border-radius: 3px; background: rgba(235,235,245,0.3); }
.sheet-body { padding: var(--s2) var(--s6) var(--s8); overflow-y: auto; }

/* ---------- pull to refresh ---------- */
.ptr {
  position: absolute; top: calc(var(--header-h) + 4px); left: 50%; z-index: 20;
  transform: translate(-50%, -18px); opacity: 0;
  width: 26px; height: 26px; pointer-events: none;
}
.ptr svg { width: 100%; height: 100%; }

.toast {
  position: absolute; left: 50%; bottom: calc(var(--tabbar-h) + 16px); z-index: 70;
  transform: translate(-50%, 20px); opacity: 0;
  background: rgba(44, 44, 46, 0.92); backdrop-filter: blur(20px);
  padding: 10px 18px; border-radius: var(--r-pill); font-size: 13px; font-weight: 600;
  pointer-events: none; white-space: nowrap;
}

.empty { color: var(--label-3); font-size: 13px; padding: var(--s5) 0; text-align: center; }

/* ---------- レースカード ---------- */
.rc-sec {
  font-size: 12px; font-weight: 700; color: var(--label-3); letter-spacing: 0.04em;
  margin: var(--s6) 0 var(--s3);
}
.rc-sec:first-child { margin-top: 0; }
.rc-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch;
           margin: 0 calc(var(--s5) * -1); padding: 0 var(--s5); }
.rc { min-width: 720px; }
.rc-row {
  display: grid; align-items: center; gap: var(--s2);
  grid-template-columns: 32px 20px minmax(120px, 1.4fr) repeat(7, minmax(48px, 0.6fr)) 60px;
  padding: var(--s2) 0;
}
.rc-row + .rc-row { box-shadow: inset 0 0.5px 0 var(--sep); }
.rc-mark { font-size: 17px; font-weight: 800; color: var(--yellow); text-align: center; }
.rc-name { min-width: 0; }
.rc-num { text-align: right; font-variant-numeric: tabular-nums; }
.rc-num .num { font-size: 14px; font-weight: 600; }
.rc-num .footnote { font-size: 10px; }

.rc-cond {
  display: flex; gap: var(--s6); flex-wrap: wrap;
  background: var(--l2); border-radius: var(--r-tile);
  padding: var(--s3) var(--s4); margin-bottom: var(--s4);
}

.picks { display: flex; flex-wrap: wrap; gap: var(--s2); }
.pick {
  background: var(--l2); border-radius: 10px; padding: 8px 12px; min-width: 86px;
  border: 1px solid transparent;
}
.pick.hit { background: rgba(48, 209, 88, 0.18); border-color: var(--green); }
.pick-combo { font-size: 15px; font-weight: 700; font-variant-numeric: tabular-nums; }
.pick-sub { font-size: 10px; color: var(--label-3); font-variant-numeric: tabular-nums; }

/* 会場ごとのレース一覧 */
.venue { margin-bottom: var(--s3); }
.venue-head { display: flex; align-items: baseline; gap: var(--s2); margin-bottom: var(--s2); }
.race-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(74px, 1fr));
             gap: var(--s2); }
.race-cell {
  background: var(--l2); border-radius: 10px; padding: 8px 6px; text-align: center;
  cursor: pointer; transition: transform 100ms ease-out, background 140ms ease;
}
.race-cell:hover { background: var(--l3); }
.race-cell:active { transform: scale(0.95); }
.race-cell .r { font-size: 15px; font-weight: 700; }
.race-cell .t { font-size: 10px; color: var(--label-3); font-variant-numeric: tabular-nums; }
.race-cell.hit { background: rgba(48, 209, 88, 0.20); }
.race-cell.miss { opacity: 0.55; }
.race-cell.pending { box-shadow: inset 0 0 0 1px var(--blue); }

@media (max-width: 700px) {
  .rc-wrap { margin: 0 calc(var(--s4) * -1); padding: 0 var(--s4); }
  .rc-cond { gap: var(--s4); }
}

/* ---------- スマートフォン（§16 Flexibility: 端末に合わせる） ---------- */
/* iOSのホーム画面から起動したときはノッチ/ホームバーを避ける */
:root {
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
.header { top: var(--safe-top); }
.tabbar { height: calc(var(--tabbar-h) + var(--safe-bottom)); padding-bottom: var(--safe-bottom); }
.scroll {
  padding-bottom: calc(var(--tabbar-h) + var(--safe-bottom) + var(--s6));
  padding-top: calc(var(--header-h) + var(--safe-top) + var(--s2));
  -webkit-overflow-scrolling: touch;
}
.sheet { max-height: calc(82% - var(--safe-top)); }
.sheet-body { padding-bottom: calc(var(--s8) + var(--safe-bottom)); }

@media (max-width: 700px) {
  :root { --s5: 16px; --s6: 20px; }
  body { font-size: 16px; }              /* 入力時の自動ズームを防ぐ下限 */
  .large-title { font-size: 28px; }
  .card { padding: var(--s4); border-radius: 14px; }
  .grid-4, .grid-3 { grid-template-columns: repeat(2, 1fr); }
  .stat .v { font-size: 24px; }
  .metric { font-size: 28px; }
  /* 横に長い表は表ごと横スクロールさせ、本文は絶対に横に溢れさせない */
  .card table.t { min-width: 520px; }
  .t-wrap { overflow-x: auto; -webkit-overflow-scrolling: touch; margin: 0 calc(var(--s4) * -1);
            padding: 0 var(--s4); }
  .bar-row { grid-template-columns: 128px 1fr 76px; gap: var(--s2); font-size: 13px; }
  .row { padding: var(--s3) var(--s1); gap: var(--s2); }
  .row .num.body { width: 74px; font-size: 13px; }
  .sheet { width: 100%; border-radius: 18px 18px 0 0; max-height: 88%; }
  .header { padding: 0 var(--s4); }
  .tab span { font-size: 10px; }
}
@media (max-width: 400px) {
  .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr 1fr; }
  .bar-row { grid-template-columns: 108px 1fr 64px; }
}

/* ---------- ログイン ---------- */
.login {
  position: absolute; inset: 0; display: flex; flex-direction: column;
  align-items: center; justify-content: center; gap: var(--s4); padding: var(--s6);
  padding-top: calc(var(--safe-top) + var(--s6));
}
.login .box { width: min(360px, 100%); display: flex; flex-direction: column; gap: var(--s3); }
.login input {
  width: 100%; height: 50px; border-radius: 12px; border: 0; outline: none;
  background: var(--l2); color: var(--label); font: inherit; font-size: 16px;
  padding: 0 var(--s4); -webkit-appearance: none;
}
.login input:focus { box-shadow: 0 0 0 3px rgba(10, 132, 255, 0.35); }
.login button {
  width: 100%; height: 50px; border: 0; border-radius: 12px; background: var(--blue);
  color: #fff; font: inherit; font-size: 16px; font-weight: 700; cursor: pointer;
  transition: transform 100ms ease-out, opacity 140ms ease;
}
.login button:active { transform: scale(0.97); }
.login button:disabled { opacity: 0.5; }
.login .err { color: var(--red); font-size: 13px; min-height: 18px; text-align: center; }

/* §14 アクセシビリティ: 動きを減らす */
@media (prefers-reduced-motion: reduce) {
  * { transition-duration: 1ms !important; }
}
body.reduce-motion * { transition-duration: 1ms !important; }
@media (prefers-reduced-transparency: reduce) {
  .header.materialized, .tabbar, .sheet { backdrop-filter: none; background: #141416; }
}
@media (prefers-contrast: more) {
  :root { --label-2: rgba(235,235,245,0.8); --label-3: rgba(235,235,245,0.6);
          --sep: rgba(120,120,128,0.7); }
}
