:root {
  --bg: #0f1218;
  --panel: #161a22;
  --panel-2: #1c212b;
  --line: #262c38;
  --text: #d8dce4;
  --muted: #8a93a3;
  --accent: #5865f2;
  --accent-2: #4752c4;
  --up: #26a69a;
  --down: #ef5350;
  --warn: #f0b90b;
  --radius: 10px;
  color-scheme: dark;
}

* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  background: var(--bg);
  color: var(--text);
  font: 14px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  -webkit-font-smoothing: antialiased;
}
[hidden] { display: none !important; }
a { color: inherit; }
h1, h2 { margin: 0 0 12px; font-weight: 700; }
h2 { font-size: 16px; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.up { color: var(--up); }
.down { color: var(--down); }

/* ---------- ヘッダー ---------- */
.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 10px 20px; border-bottom: 1px solid var(--line); background: var(--panel);
  position: sticky; top: 0; z-index: 10;
}
.brand { font-weight: 800; letter-spacing: .02em; font-size: 16px; }
.brand-mark { color: var(--up); }
.user { display: flex; align-items: center; gap: 10px; min-width: 0; }
.user-text { display: flex; flex-direction: column; line-height: 1.2; min-width: 0; }
.user-name { font-weight: 600; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 160px; }
.user-level { font-size: 11px; color: var(--muted); }
.avatar { width: 28px; height: 28px; border-radius: 50%; background: var(--panel-2); flex: none; object-fit: cover; }
.avatar-sm { width: 22px; height: 22px; }

/* ---------- ボタン・入力 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--line); background: var(--panel-2); color: var(--text);
  border-radius: 8px; padding: 8px 14px; font: inherit; font-weight: 600; cursor: pointer;
  text-decoration: none; white-space: nowrap;
}
.btn:hover { border-color: #3a4252; }
.btn:disabled { opacity: .5; cursor: default; }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-2); }
.btn-danger { background: transparent; border-color: #5a2a2a; color: #ff8a80; }
.btn-ghost { background: transparent; }
.btn-discord { background: var(--accent); border-color: var(--accent); color: #fff; padding: 12px 22px; font-size: 15px; }
.input {
  background: var(--bg); color: var(--text); border: 1px solid var(--line); border-radius: 8px;
  padding: 8px 10px; font: inherit; min-width: 0;
}
.input:focus { outline: 2px solid var(--accent); outline-offset: -1px; }
.input-select { padding-right: 28px; }

/* ---------- ログイン・お知らせ ---------- */
.notice {
  width: calc(100% - 32px); max-width: 460px; margin: 12vh auto; padding: 32px 24px; text-align: center;
  background: var(--panel); border: 1px solid var(--line); border-radius: 14px;
}
.notice p { margin: 0 0 14px; }
.notice .btn { margin-top: 8px; }

/* ---------- レイアウト ---------- */
.app { padding: 16px 20px 40px; max-width: 1400px; margin: 0 auto; }
.tabs { display: flex; gap: 6px; overflow-x: auto; padding-bottom: 12px; scrollbar-width: none; }
.tab {
  border: 1px solid var(--line); background: var(--panel); color: var(--muted);
  border-radius: 999px; padding: 6px 14px; font: inherit; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.tab .count { margin-left: 6px; font-size: 11px; opacity: .8; }
.tab[aria-selected="true"] { background: var(--text); color: var(--bg); border-color: var(--text); }

.watch-view { display: grid; grid-template-columns: minmax(0, 1fr) minmax(0, 1.05fr); gap: 16px; align-items: start; }
.list-pane, .detail-pane, .card {
  background: var(--panel); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px;
}
.detail-pane { position: sticky; top: 64px; }

/* ---------- 追加フォーム ---------- */
.add-form { display: flex; gap: 8px; margin-bottom: 12px; }
.add-form #add-ticker { flex: 1; }

/* ---------- 一覧 ---------- */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { font-size: 11px; font-weight: 600; color: var(--muted); text-align: left; padding: 6px 8px; border-bottom: 1px solid var(--line); white-space: nowrap; }
td { padding: 9px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.watch-table tbody tr { cursor: pointer; }
.watch-table tbody tr:hover { background: var(--panel-2); }
.watch-table tbody tr[aria-selected="true"] { background: #232a38; }
.group-row td { cursor: default; background: var(--bg); color: var(--muted); font-size: 12px; font-weight: 700; padding: 6px 8px; }
.col-star { width: 32px; }
.star {
  border: 0; background: none; cursor: pointer; font-size: 16px; line-height: 1; padding: 2px;
  color: #4a5160; filter: grayscale(1);
}
.star[aria-pressed="true"] { color: var(--warn); filter: none; }
.name { font-weight: 700; }
.dex { font-size: 10px; color: var(--muted); border: 1px solid var(--line); border-radius: 4px; padding: 0 4px; margin-left: 6px; vertical-align: 1px; }
.nick { display: block; font-size: 11px; color: var(--muted); }
.people { display: flex; align-items: center; }
.people .avatar { width: 22px; height: 22px; border: 2px solid var(--panel); margin-left: -6px; }
.people .avatar:first-child { margin-left: 0; }
.people .more { font-size: 11px; color: var(--muted); margin-left: 4px; }
.empty { text-align: center; color: var(--muted); padding: 24px 0; }

/* ---------- 詳細 ---------- */
.detail-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 8px 12px; flex-wrap: wrap; }
.detail-head > div { min-width: 0; }
.d-title { font-size: 20px; margin: 0; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(110px, 1fr)); gap: 8px; margin: 12px 0; }
.stat { background: var(--panel-2); border-radius: 8px; padding: 8px 10px; }
.stat-label { font-size: 11px; color: var(--muted); }
.stat-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.toolbar { display: flex; justify-content: space-between; align-items: center; gap: 8px; margin-bottom: 8px; flex-wrap: wrap; }
.seg { display: inline-flex; border: 1px solid var(--line); border-radius: 8px; overflow: hidden; }
.seg button { border: 0; background: transparent; color: var(--muted); font: inherit; font-weight: 700; padding: 6px 14px; cursor: pointer; white-space: nowrap; }
.seg button + button { border-left: 1px solid var(--line); }
.seg button[aria-pressed="true"] { background: var(--accent); color: #fff; }
.chart { height: 420px; border-radius: 8px; overflow: hidden; background: #131722; }
.detail-actions { display: flex; flex-wrap: wrap; gap: 8px; margin-top: 12px; }
#d-meta { margin-top: 10px; }

/* ---------- ウォレット ---------- */
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; font-size: 12px; }
.wallet-form { display: grid; gap: 8px; margin-bottom: 12px; }
.wallet-form-row { display: grid; grid-template-columns: 2fr 1fr; gap: 8px; align-items: center; }
.wallet-form .check { margin: 0; }
.addr-line { display: flex; align-items: center; gap: 6px; margin-top: 2px; min-width: 0; }
.addr-line code { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; min-width: 0; }
.chart-sm { height: 260px; }
.sub { font-size: 13px; color: var(--muted); margin: 18px 0 6px; }
.pos-table td { font-size: 13px; padding: 7px 8px; white-space: nowrap; }
.pos-table th { padding: 5px 8px; }
.pos-table .empty-row td { color: var(--muted); text-align: center; }
.side { font-size: 11px; font-weight: 700; border-radius: 4px; padding: 0 5px; margin-right: 6px; white-space: nowrap; }
.side.long { background: rgba(38, 166, 154, .18); color: var(--up); }
.side.short { background: rgba(239, 83, 80, .18); color: var(--down); }
.sub-num { display: block; font-size: 11px; color: var(--muted); }

/* ---------- 設定 ---------- */
.settings-view { display: grid; grid-template-columns: minmax(0, 420px) minmax(0, 1fr); gap: 16px; align-items: start; }
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; font-size: 12px; color: var(--muted); }
.field .input { color: var(--text); font-size: 14px; }
.field-row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.check { display: flex; align-items: center; gap: 8px; margin-bottom: 12px; }
.audit-table td { font-size: 12px; }
.audit-table td:first-child { white-space: nowrap; color: var(--muted); }

/* ---------- トースト ---------- */
.toast {
  position: fixed; left: 50%; bottom: 24px; transform: translateX(-50%); z-index: 50;
  background: var(--panel-2); border: 1px solid var(--line); border-radius: 10px; padding: 10px 16px;
  box-shadow: 0 8px 24px rgba(0, 0, 0, .4); max-width: calc(100vw - 32px);
}
.toast.error { border-color: #7a2e2e; color: #ffb4ab; }

/* ---------- 狭い画面 ---------- */
@media (max-width: 1000px) {
  .watch-view, .settings-view { grid-template-columns: minmax(0, 1fr); }
  .detail-pane { position: static; }
}
@media (max-width: 640px) {
  .topbar { padding: 10px 16px; }
  .app { padding: 12px 16px 32px; }
  .user-text { display: none; }
  .col-wide { display: none; }
  .add-form { flex-wrap: wrap; }
  .add-form #add-ticker { flex-basis: 100%; }
  .add-form .input-select { flex: 1; }
  .chart { height: 320px; }
  .people .avatar:nth-child(n+4) { display: none; }
  .field-row { grid-template-columns: 1fr; }
  .wallet-form-row { grid-template-columns: 1fr; }
  .chart-sm { height: 220px; }
  .seg button { padding: 6px 10px; }
  .pos-table td, .pos-table th { padding-left: 5px; padding-right: 5px; }
}
