:root {
  --bg: #0d1117;
  --card: #161b22;
  --card2: #1c232c;
  --line: #2a313b;
  --text: #e6edf3;
  --muted: #8b949e;
  --pos: #3fb950;
  --neg: #f85149;
  --warn: #d29922;
  --accent: #58a6ff;
  --radius: 14px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
}
* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }
html, body { margin: 0; background: var(--bg); color: var(--text); }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Hiragino Sans", "Segoe UI", sans-serif;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
}
.num { font-variant-numeric: tabular-nums; }
.pos { color: var(--pos); }
.neg { color: var(--neg); }
.muted { color: var(--muted); }

#topbar {
  position: sticky; top: 0; z-index: 10;
  display: flex; align-items: center; gap: 8px;
  padding: calc(var(--safe-top) + 10px) 16px 10px;
  background: rgba(13,17,23,.92);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--line);
}
#topbar h1 { flex: 1; margin: 0; font-size: 17px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.icon-btn { background: none; border: 0; color: var(--accent); font-size: 30px; line-height: 1; padding: 0 8px 0 0; cursor: pointer; }
.icon-btn.bell { font-size: 18px; padding: 0 4px; filter: grayscale(1); opacity: .8; }
.icon-btn.bell.on { filter: none; opacity: 1; }
.conn { width: 10px; height: 10px; border-radius: 50%; background: var(--muted); flex: none; }
.conn.live { background: var(--pos); box-shadow: 0 0 8px var(--pos); }
.conn.down { background: var(--neg); }

main { padding: 12px 12px calc(var(--safe-bottom) + 24px); max-width: 760px; margin: 0 auto; }

/* 合計 */
.totals { display: grid; gap: 8px; margin-bottom: 12px; }
.total-card { background: linear-gradient(135deg, #1a2330, #141a22); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; }
.total-card .cur { font-size: 12px; color: var(--muted); margin-bottom: 6px; }
.total-grid { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; }
.total-grid .k { font-size: 11px; color: var(--muted); }
.total-grid .v { font-size: 15px; font-weight: 600; }

/* 口座カード */
.cards { display: grid; gap: 10px; }
@media (min-width: 640px) { .cards { grid-template-columns: 1fr 1fr; } }
.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; cursor: pointer; transition: transform .08s; }
.card:active { transform: scale(.985); }
.card-head { display: flex; align-items: center; gap: 8px; margin-bottom: 8px; }
.card-head .name { font-weight: 600; flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.dot { width: 8px; height: 8px; border-radius: 50%; flex: none; background: var(--pos); }
.dot.stale { background: var(--muted); }
.dot.off { background: var(--neg); }
.badge { font-size: 10px; padding: 2px 6px; border-radius: 6px; background: var(--card2); color: var(--muted); border: 1px solid var(--line); }
.badge.demo { color: var(--warn); border-color: #5a4613; }
.age { font-size: 11px; color: var(--muted); }
.card-main { display: flex; justify-content: space-between; align-items: baseline; margin-bottom: 8px; }
.card-main .eq { font-size: 22px; font-weight: 700; }
.card-main .fl { font-size: 15px; font-weight: 600; text-align: right; }
.kv { display: grid; grid-template-columns: repeat(3, 1fr); gap: 6px 10px; }
.kv .k { font-size: 11px; color: var(--muted); }
.kv .v { font-size: 14px; }
.ml-warn { color: var(--warn); }
.ml-danger { color: var(--neg); font-weight: 700; }

/* 詳細 */
.metrics { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 12px 14px; margin-bottom: 10px; }
.tabs { display: flex; background: var(--card); border: 1px solid var(--line); border-radius: 10px; padding: 3px; margin-bottom: 10px; position: sticky; top: calc(var(--safe-top) + 52px); z-index: 5; }
.tabs button { flex: 1; background: none; border: 0; color: var(--muted); padding: 8px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer; }
.tabs button.on { background: var(--card2); color: var(--text); }
.chips { display: flex; gap: 6px; margin-bottom: 10px; }
.chips button { background: var(--card); border: 1px solid var(--line); color: var(--muted); border-radius: 999px; padding: 5px 12px; font-size: 13px; cursor: pointer; }
.chips button.on { color: var(--text); border-color: var(--accent); }
.summary-row { display: grid; grid-template-columns: repeat(4, 1fr); gap: 6px; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 10px; }
.summary-row .k { font-size: 11px; color: var(--muted); }
.summary-row .v { font-size: 15px; font-weight: 600; }

.list { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); overflow: hidden; }
.row { padding: 10px 14px; border-top: 1px solid var(--line); }
.row:first-child { border-top: 0; }
.row-1 { display: flex; align-items: center; gap: 8px; }
.row-1 .sym { font-weight: 600; }
.row-1 .pl { margin-left: auto; font-weight: 700; font-size: 16px; }
.side { font-size: 11px; font-weight: 700; padding: 1px 6px; border-radius: 5px; }
.side.buy { background: rgba(88,166,255,.15); color: var(--accent); }
.side.sell { background: rgba(248,81,73,.15); color: var(--neg); }
.row-2 { display: flex; justify-content: space-between; gap: 8px; margin-top: 4px; font-size: 12px; color: var(--muted); }
.empty { padding: 28px 14px; text-align: center; color: var(--muted); }
.group-h { padding: 6px 14px; font-size: 12px; color: var(--muted); background: var(--card2); border-top: 1px solid var(--line); display: flex; justify-content: space-between; }

/* ログイン */
.login { max-width: 380px; margin: 40px auto; background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 20px; }
.login h2 { margin: 0 0 6px; font-size: 18px; }
.login p { color: var(--muted); font-size: 13px; margin: 0 0 14px; }
.login input { width: 100%; padding: 12px; border-radius: 10px; border: 1px solid var(--line); background: var(--bg); color: var(--text); font-size: 16px; }
.btn { width: 100%; margin-top: 12px; padding: 12px; border: 0; border-radius: 10px; background: var(--accent); color: #fff; font-size: 16px; font-weight: 600; cursor: pointer; }
.btn.ghost { background: none; color: var(--muted); border: 1px solid var(--line); }
.err { color: var(--neg); font-size: 13px; margin-top: 8px; min-height: 1em; }
.footer { text-align: center; margin-top: 20px; font-size: 12px; color: var(--muted); }
.footer button { background: none; border: 0; color: var(--muted); text-decoration: underline; font-size: 12px; cursor: pointer; }

/* 通知設定 */
.section { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px; margin-bottom: 12px; }
.section h2 { margin: 0 0 4px; font-size: 15px; }
.section .desc { color: var(--muted); font-size: 12px; margin: 0 0 10px; line-height: 1.5; }
.section .btn { margin-top: 8px; }
.status-line { font-size: 14px; margin-bottom: 4px; }
.notice { background: rgba(210,153,34,.12); border: 1px solid #5a4613; color: var(--warn); border-radius: 10px; padding: 10px 12px; font-size: 13px; line-height: 1.5; }
.ntable { width: 100%; border-collapse: collapse; }
.ntable th { font-size: 11px; color: var(--muted); font-weight: 600; text-align: center; padding: 4px 2px 8px; }
.ntable th:first-child { text-align: left; }
.ntable td { border-top: 1px solid var(--line); padding: 10px 2px; text-align: center; }
.ntable td:first-child { text-align: left; font-size: 14px; max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.sw { position: relative; display: inline-block; width: 44px; height: 26px; }
.sw input { opacity: 0; width: 0; height: 0; }
.sw span { position: absolute; inset: 0; background: #30363d; border-radius: 999px; transition: .15s; cursor: pointer; }
.sw span::before { content: ""; position: absolute; width: 20px; height: 20px; left: 3px; top: 3px; background: #fff; border-radius: 50%; transition: .15s; }
.sw input:checked + span { background: var(--pos); }
.sw input:checked + span::before { transform: translateX(18px); }
.log-row { padding: 8px 0; border-top: 1px solid var(--line); font-size: 13px; }
.log-row:first-child { border-top: 0; }
.log-row .t { color: var(--muted); font-size: 11px; }
