:root {
  --bg: #f7f5f0;
  --card: #ffffff;
  --text: #1c1408;
  --sub: #6b6455;
  --line: #e7e1d4;
  --accent: #b45309;
  --brand: #a16207;
  --up: #059669;
  --down: #dc2626;
  --band: #d97706;
  --warn-bg: #fff7ed;
  --warn: #9a3412;
  --info-bg: #eef6ff;
  --info: #1e3a8a;
  --chip: #f1ede4;
  --shadow: 0 1px 2px rgb(28 20 8 / 6%), 0 1px 8px rgb(28 20 8 / 4%);
  color-scheme: light;
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #14100a;
    --card: #1f1a12;
    --text: #efe9dd;
    --sub: #a8a08f;
    --line: #342c1f;
    --accent: #f59e0b;
    --brand: #fbbf24;
    --up: #34d399;
    --down: #f87171;
    --band: #fbbf24;
    --warn-bg: #2a1b0f;
    --warn: #fdba74;
    --info-bg: #13203a;
    --info: #bfdbfe;
    --chip: #2a2318;
    --shadow: none;
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "Hiragino Sans", "Hiragino Kaku Gothic ProN", "Yu Gothic UI", "Meiryo", sans-serif;
  font-size: 16px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
  padding-bottom: calc(64px + env(safe-area-inset-bottom));
}
a { color: var(--accent); text-decoration: none; }
button, input, select { font: inherit; color: inherit; }
.num { font-variant-numeric: tabular-nums; }

.topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: baseline; justify-content: space-between; gap: 12px;
  padding: calc(10px + env(safe-area-inset-top)) 16px 10px;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(10px);
  -webkit-backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--line);
}
.brand { font-weight: 700; font-size: 18px; color: var(--brand); }
.updated { font-size: 12px; color: var(--sub); text-align: right; }
.updated.stale { color: var(--down); font-weight: 600; }

main { max-width: 860px; margin: 0 auto; padding: 12px 16px 24px; }
.loading, .empty { color: var(--sub); text-align: center; padding: 40px 0; }

h2 { font-size: 15px; color: var(--sub); font-weight: 600; margin: 22px 0 8px; }
h2:first-child { margin-top: 4px; }
h3 { font-size: 15px; margin: 4px 0 6px; }

.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  background: var(--card);
  border-top: 1px solid var(--line);
  padding-bottom: env(safe-area-inset-bottom);
}
.tabbar a {
  flex: 1; max-width: 200px;
  display: flex; flex-direction: column; align-items: center;
  padding: 8px 0 6px; font-size: 12px; color: var(--sub);
}
.tabbar a .ti { font-size: 18px; line-height: 1.2; }
.tabbar a.active { color: var(--accent); font-weight: 600; }

.panel { background: var(--card); border-radius: 14px; box-shadow: var(--shadow); border: 1px solid var(--line); padding: 12px 14px; margin-top: 12px; }

/* 値段 */
.price-head .title { font-weight: 700; font-size: 17px; }
.price-head .contract { color: var(--sub); font-size: 13px; }
.price-head .big { font-size: 32px; font-weight: 800; line-height: 1.15; margin-top: 6px; }
.price-head .big small { font-size: 14px; font-weight: 600; color: var(--sub); margin-left: 4px; }
.price-head .alt { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 15px; margin-top: 2px; }
.price-head .alt b { font-weight: 700; }
.price-head .asof { font-size: 12px; color: var(--sub); margin-top: 4px; }
.chgs { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; margin-top: 10px; }
.chgs div { background: var(--chip); border-radius: 10px; padding: 5px 8px; text-align: center; }
.chgs .n { font-size: 11px; color: var(--sub); }
.chgs .v { font-size: 15px; font-weight: 700; }

.up { color: var(--up); }
.down { color: var(--down); }
.flat { color: var(--sub); }

.note { font-size: 13px; color: var(--sub); margin: 6px 0 0; }
.warnbox { background: var(--warn-bg); color: var(--warn); border-radius: 10px; padding: 8px 10px; font-size: 13px; margin-top: 10px; }
.infobox { background: var(--info-bg); color: var(--info); border-radius: 10px; padding: 8px 10px; font-size: 13px; margin-top: 10px; }

/* 予測の表 */
.ftable { width: 100%; border-collapse: collapse; font-size: 14px; }
.ftable th { font-size: 12px; color: var(--sub); font-weight: 600; text-align: left; padding: 4px 4px; border-bottom: 1px solid var(--line); }
.ftable td { padding: 8px 4px; border-bottom: 1px solid var(--line); vertical-align: top; }
.ftable tr:last-child td { border-bottom: 0; }
.ftable tr.sel td { background: color-mix(in srgb, var(--accent) 10%, transparent); }
.ftable tr { cursor: pointer; }
.ftable .h { font-weight: 700; white-space: nowrap; }
.ftable .d { font-size: 12px; color: var(--sub); }
.ftable .rg b { font-weight: 700; }
.ftable .rg .c { font-size: 12px; color: var(--sub); }
.ftable .hide { color: var(--sub); font-size: 12px; }
.bar { position: relative; height: 6px; border-radius: 3px; background: var(--chip); margin-top: 4px; }
.bar i { position: absolute; top: 0; bottom: 0; left: 0; border-radius: 3px; background: var(--band); }
.bar s { position: absolute; top: -3px; bottom: -3px; width: 2px; background: var(--sub); }

.reasons { margin: 6px 0 0; padding: 0; list-style: none; font-size: 14px; }
.reasons li { padding: 3px 0; display: flex; gap: 6px; }
.reasons .tag { flex: 0 0 auto; font-size: 11px; border-radius: 999px; padding: 1px 7px; background: var(--chip); color: var(--sub); align-self: center; }
.reasons .tag.move { color: var(--accent); }
.risks { margin: 6px 0 0; padding-left: 18px; font-size: 13px; color: var(--sub); }
.risks li { margin: 3px 0; }

/* グラフ */
.ranges { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.ranges button, .toggle {
  border: 1px solid var(--line); background: var(--chip); border-radius: 999px;
  padding: 4px 11px; font-size: 13px; cursor: pointer;
}
.ranges button.on, .toggle.on { background: var(--accent); border-color: var(--accent); color: #fff; }
.ranges .sep { width: 8px; }
.chart { width: 100%; height: 300px; }
@media (min-width: 700px) { .chart { height: 380px; } }
.legend { display: flex; flex-wrap: wrap; gap: 4px 14px; font-size: 12px; color: var(--sub); margin-top: 6px; }
.legend .sw { display: inline-block; width: 18px; height: 0; border-top: 2px dashed var(--band); vertical-align: middle; margin-right: 4px; }
.legend .sw.solid { border-top-style: solid; }
.ohlc { font-size: 12px; color: var(--sub); min-height: 18px; }

/* 限月の表・市場の一覧 */
.ttable { width: 100%; border-collapse: collapse; font-size: 14px; }
.ttable th { font-size: 12px; color: var(--sub); font-weight: 600; text-align: right; padding: 4px; border-bottom: 1px solid var(--line); }
.ttable th:first-child, .ttable td:first-child { text-align: left; }
.ttable td { padding: 6px 4px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.ttable tr:last-child td { border-bottom: 0; }
.ttable .sub { display: block; font-size: 11px; color: var(--sub); }
.scrollx { overflow-x: auto; }

.cards { display: grid; gap: 8px; }
@media (min-width: 700px) { .cards { grid-template-columns: 1fr 1fr; } }
.card {
  display: block; background: var(--card); color: var(--text);
  border-radius: 14px; padding: 10px 14px; box-shadow: var(--shadow); border: 1px solid var(--line);
}
.card.on { border-color: var(--accent); }
.card .row1 { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.card .name { font-weight: 700; }
.card .unit { font-size: 12px; color: var(--sub); }
.card .price { font-weight: 700; font-size: 17px; text-align: right; }
.card .row2 { display: flex; gap: 12px; margin-top: 4px; font-size: 13px; color: var(--sub); flex-wrap: wrap; }
.card .row2 b { font-weight: 600; }

/* AI の成績 */
.evh { display: flex; justify-content: space-between; align-items: baseline; }
.evh .h { font-weight: 800; font-size: 17px; }
.pill { font-size: 12px; border-radius: 999px; padding: 1px 9px; font-weight: 600; }
.pill.ok { background: color-mix(in srgb, var(--up) 15%, transparent); color: var(--up); }
.pill.ng { background: var(--chip); color: var(--sub); }
.evpart { margin-top: 10px; padding-top: 8px; border-top: 1px solid var(--line); }
.evpart .t { display: flex; justify-content: space-between; gap: 8px; font-weight: 600; font-size: 14px; }
.evpart .s { font-size: 13px; color: var(--sub); margin-top: 2px; }
.evpart .s b { color: var(--text); font-weight: 600; }
details { margin-top: 6px; font-size: 13px; }
details summary { cursor: pointer; color: var(--accent); }
.mini { width: 100%; border-collapse: collapse; font-size: 12px; margin-top: 4px; }
.mini th, .mini td { padding: 3px 4px; border-bottom: 1px solid var(--line); text-align: right; font-variant-numeric: tabular-nums; }
.mini th:first-child, .mini td:first-child { text-align: left; }

.about p, .about li { font-size: 15px; }
.about ul { padding-left: 20px; }

/* ログイン */
.login { max-width: 360px; margin: 40px auto; }
.login input { width: 100%; padding: 10px 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--card); margin-top: 8px; }
.login button { width: 100%; margin-top: 10px; padding: 10px; border-radius: 10px; border: 0; background: var(--accent); color: #fff; font-weight: 700; cursor: pointer; }
.login .err { color: var(--down); font-size: 14px; min-height: 20px; margin-top: 8px; }
.logout { margin-top: 24px; background: none; border: 1px solid var(--line); border-radius: 8px; padding: 6px 12px; color: var(--sub); cursor: pointer; }
