:root {
  --bg: #0e1014;
  --bg-2: #161a21;
  --bg-3: #1d232c;
  --border: #262d38;
  --text: #e6e8eb;
  --muted: #8a93a3;
  --accent: #4ea1ff;
  --accent-2: #1f2937;
  --buy: #2ecc71;
  --sell: #ff5d6c;
  --warn: #ffbf47;
  --list-w: 420px;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "Hiragino Sans", "Noto Sans JP", sans-serif;
  font-size: 14px;
  height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  height: 100vh;
  overflow: hidden;
}

a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.title { display: flex; align-items: center; gap: 10px; }
.title h1 { font-size: 16px; margin: 0; font-weight: 600; }
.title .emoji { font-size: 20px; }
.meta {
  color: var(--muted);
  font-size: 12px;
  display: flex;
  align-items: center;
  gap: 0;
}
.meta .sep { margin: 0 6px; }

.reload-btn {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 6px;
  font-size: 13px;
  cursor: pointer;
  line-height: 1;
  font-family: inherit;
}
.reload-btn:hover { border-color: var(--accent); }
.reload-btn.spinning { animation: spin 0.8s linear infinite; }
@keyframes spin {
  from { transform: rotate(0deg); }
  to { transform: rotate(360deg); }
}

.auto-toggle {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  margin-left: 8px;
  cursor: pointer;
  user-select: none;
}
.auto-toggle input { margin: 0; }

.controls {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  padding: 10px 16px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
}
.control-group { display: flex; align-items: center; gap: 6px; }
.control-group.grow { flex: 1; min-width: 200px; }
.control-group label { color: var(--muted); font-size: 12px; }

.tab {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 4px 12px;
  cursor: pointer;
  font-size: 13px;
}
.tab + .tab { border-left: none; }
.tab:first-child { border-radius: 6px 0 0 6px; }
.tab:last-child { border-radius: 0 6px 6px 0; }
.tab.active {
  background: var(--accent);
  color: #000;
  border-color: var(--accent);
}
.tab.special { color: var(--warn); }
.tab.special.active { color: #000; background: var(--warn); border-color: var(--warn); }

.watch-add {
  display: flex;
  gap: 6px;
  padding: 8px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
}
.watch-add input {
  flex: 1;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 12px;
  font-family: monospace;
}

.toolbar-actions {
  display: flex;
  align-items: center;
  gap: 6px;
}
.list-toolbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  font-size: 12px;
  color: var(--muted);
}
.action-btn.danger { color: var(--sell); border-color: rgba(255, 93, 108, 0.4); }
.action-btn.danger:hover { background: rgba(255, 93, 108, 0.12); border-color: var(--sell); }

select, input[type=number], input[type=search] {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 8px;
  font-size: 13px;
}
input[type=search] { width: 100%; }
input[type=number] { width: 60px; }

.layout {
  flex: 1;
  display: grid;
  grid-template-columns: var(--list-w) 6px 1fr;
  overflow: hidden;
  min-height: 0;
}

.list-pane {
  overflow-y: auto;
  background: var(--bg);
}

.resizer {
  background: var(--border);
  cursor: col-resize;
  user-select: none;
  transition: background 0.12s;
  position: relative;
}
.resizer::after {
  /* タップ/クリック判定を少し広げる視覚的なグリップ */
  content: "";
  position: absolute;
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
  width: 2px;
  height: 36px;
  background: var(--muted);
  border-radius: 2px;
  opacity: 0.4;
}
.resizer:hover,
.resizer.dragging { background: var(--accent); }
.resizer:hover::after,
.resizer.dragging::after { opacity: 0.9; background: #000; }
.token-list { list-style: none; margin: 0; padding: 0; }
.token-list li {
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  cursor: pointer;
  display: grid;
  grid-template-columns: 20px 32px 1fr auto;
  gap: 10px;
  align-items: center;
}
.token-list li:hover { background: var(--bg-2); }
.fav-star {
  background: none;
  border: none;
  color: var(--muted);
  font-size: 14px;
  cursor: pointer;
  padding: 0;
  line-height: 1;
}
.fav-star.on { color: var(--warn); }
.fav-star:hover { color: var(--warn); }
.watch-del {
  background: var(--bg-3);
  border: 1px solid var(--border);
  color: var(--muted);
  border-radius: 4px;
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
  padding: 2px 7px;
}
.watch-del:hover { color: var(--sell); border-color: var(--sell); }
.token-list .muted-tag { color: var(--muted); font-style: italic; }
.buyers .wallet .rating,
#events-list .wallet .rating { font-size: 10px; letter-spacing: -1px; }
.token-list li.selected { background: var(--accent-2); }
.token-list .icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  background: var(--bg-3);
  object-fit: cover;
}
.token-list .info { min-width: 0; }
.token-list .symbol-row {
  display: flex; align-items: baseline; gap: 8px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.token-list .sym { font-weight: 600; font-size: 14px; }
.token-list .name { color: var(--muted); font-size: 11px; overflow: hidden; text-overflow: ellipsis; }
.token-list .stats {
  display: flex; gap: 10px; margin-top: 3px;
  color: var(--muted); font-size: 12px;
}
.token-list .stats .buy { color: var(--buy); }
.token-list .stats .warn { color: var(--warn); }
.token-list .dex-stats {
  display: flex; gap: 8px; margin-top: 2px;
  color: var(--muted); font-size: 11px;
  flex-wrap: wrap;
  font-variant-numeric: tabular-nums;
}
.token-list .dex-stats span { white-space: nowrap; }
.token-list .right {
  text-align: right;
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
}
.token-list .right .big {
  display: block;
  color: var(--text);
  font-size: 14px;
  font-weight: 600;
}

.empty-msg { color: var(--muted); padding: 20px; text-align: center; }

.chart-pane { display: flex; flex-direction: column; overflow: hidden; }
.chart-empty {
  margin: auto;
  color: var(--muted);
  font-size: 13px;
}
.chart-detail { display: flex; flex-direction: column; height: 100%; overflow: hidden; }

.chart-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 10px 16px;
  border-bottom: 1px solid var(--border);
  background: var(--bg-2);
  flex-wrap: wrap;
}
.back-btn {
  display: none;
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 18px;
  line-height: 1;
  cursor: pointer;
  margin-right: 4px;
}
.back-btn:hover { background: var(--accent-2); }

.chart-title { display: flex; align-items: center; gap: 10px; min-width: 0; }
.chart-title img {
  width: 32px; height: 32px; border-radius: 50%;
  background: var(--bg-3);
}
.chart-title .symbol { font-size: 16px; font-weight: 700; margin-right: 6px; }
.chart-title .name { color: var(--muted); font-size: 12px; }
.chart-title .line-2 {
  color: var(--muted);
  font-size: 11px;
  font-variant-numeric: tabular-nums;
  margin-top: 2px;
}

.chart-source { display: flex; align-items: center; gap: 6px; }
.src-btn {
  background: var(--bg-3); color: var(--text);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 4px 10px; font-size: 12px; cursor: pointer;
}
.src-btn.active { background: var(--accent); color: #000; border-color: var(--accent); }
.open-ext { font-size: 12px; margin-left: 8px; }

.action-bar {
  display: flex;
  gap: 6px;
  padding: 6px 12px;
  background: var(--bg-2);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
.action-btn {
  background: var(--bg-3);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 4px 10px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.1s, border-color 0.1s;
}
.action-btn:hover {
  background: var(--accent-2);
  border-color: var(--accent);
}
.action-btn:active { transform: translateY(1px); }
.action-btn.icon-only { padding: 4px 8px; }
.action-btn:disabled { opacity: 0.4; cursor: not-allowed; }
a.action-btn {
  text-decoration: none;
  display: inline-flex;
  align-items: center;
  line-height: 1.4;
}
a.action-btn:hover { text-decoration: none; }

.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: rgba(0, 0, 0, 0.92);
  color: var(--text);
  border: 1px solid var(--accent);
  padding: 8px 16px;
  border-radius: 4px;
  font-size: 13px;
  z-index: 1000;
  pointer-events: none;
  opacity: 0;
  transition: opacity 0.2s;
}
.toast.show { opacity: 1; }
.toast.error { border-color: var(--sell); }

.iframe-wrap {
  flex: 1;
  min-height: 320px;
  background: #000;
  overflow: hidden;
}
.iframe-wrap iframe {
  width: 100%;
  height: 100%;
  border: 0;
  display: block;
}

.token-info-view { font-size: 12px; padding-top: 4px; }
.token-info-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(120px, 1fr));
  gap: 6px 10px;
  margin-bottom: 10px;
}
.ti-cell {
  background: var(--bg-3);
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 6px 8px;
}
.ti-label {
  color: var(--muted);
  font-size: 10px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.ti-value {
  color: var(--text);
  font-size: 13px;
  font-weight: 600;
  font-variant-numeric: tabular-nums;
  margin-top: 1px;
}
.ti-value .buy { color: var(--buy); }
.ti-value .sell { color: var(--sell); }
.ti-value .pos { color: var(--buy); }
.ti-value .neg { color: var(--sell); }

.token-info-score {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.ti-badge {
  padding: 2px 8px;
  font-size: 11px;
  border-radius: 99px;
  border: 1px solid var(--border);
  background: var(--bg-3);
}
.ti-badge.good { color: var(--buy); border-color: rgba(46, 204, 113, 0.5); }
.ti-badge.warn { color: var(--warn); border-color: rgba(255, 191, 71, 0.5); }
.ti-badge.bad  { color: var(--sell); border-color: rgba(255, 93, 108, 0.5); }
.ti-empty { color: var(--muted); font-size: 11px; }

.buyers {
  border-top: 1px solid var(--border);
  background: var(--bg-2);
  padding: 8px 16px 12px;
  max-height: 30vh;
  overflow-y: auto;
}
.buyers h3 { margin: 4px 0 6px; font-size: 13px; color: var(--muted); font-weight: 500; }
.buyers ul { list-style: none; margin: 0; padding: 0; }

.buyers-tabs {
  display: flex;
  gap: 4px;
  margin-bottom: 6px;
  border-bottom: 1px solid var(--border);
}
.buyers-tab {
  background: transparent;
  color: var(--muted);
  border: none;
  border-bottom: 2px solid transparent;
  padding: 6px 12px;
  font-size: 12px;
  cursor: pointer;
  font-family: inherit;
}
.buyers-tab:hover { color: var(--text); }
.buyers-tab.active {
  color: var(--text);
  border-bottom-color: var(--accent);
}

.buyers-header,
.buyers li {
  display: grid;
  grid-template-columns:
    minmax(90px, auto)   /* ウォレット */
    minmax(60px, 1fr)    /* ラベル */
    44px                  /* 取引数 */
    minmax(70px, auto)   /* 合計 */
    minmax(95px, auto);  /* 最終 */
  gap: 10px;
  align-items: baseline;
}
.buyers-header {
  padding: 4px 0;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-2);
}
.buyers-header .num { text-align: right; }

.buyers li {
  padding: 4px 0;
  font-size: 12px;
  border-bottom: 1px dashed var(--border);
  font-variant-numeric: tabular-nums;
}
.buyers .wallet { font-family: monospace; color: var(--text); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.buyers .label-cell { color: var(--warn); overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.buyers .label-cell.empty { color: var(--border); }
.buyers .trades { text-align: right; color: var(--text); }
.buyers .amount { color: var(--buy); text-align: right; white-space: nowrap; }
.buyers .ts { color: var(--muted); text-align: right; white-space: nowrap; }
.buyers .ts .abs { color: var(--text); }
.buyers .ts .ago { color: var(--muted); margin-left: 6px; font-size: 11px; }

/* 履歴 (events) ビュー */
.events-header,
#events-list li {
  display: grid;
  grid-template-columns:
    minmax(95px, auto)   /* 時刻 */
    44px                  /* 方向 */
    minmax(90px, auto)   /* ウォレット */
    minmax(60px, 1fr)    /* ラベル */
    minmax(80px, auto);  /* 金額 */
  gap: 10px;
  align-items: baseline;
}
.events-header {
  padding: 4px 0;
  font-size: 10px;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--bg-2);
}
.events-header .num { text-align: right; }
#events-list li {
  padding: 4px 0;
  font-size: 12px;
  border-bottom: 1px dashed var(--border);
  font-variant-numeric: tabular-nums;
}
#events-list .dir {
  font-weight: 600;
  font-size: 11px;
  text-align: center;
}
#events-list .dir.buy { color: var(--buy); }
#events-list .dir.sell { color: var(--sell); }
#events-list .amount.buy { color: var(--buy); text-align: right; white-space: nowrap; }
#events-list .amount.sell { color: var(--sell); text-align: right; white-space: nowrap; }

/* === モバイル: 一覧と詳細を「画面切替」で見せる (左右 2 ペイン不可) === */
@media (max-width: 800px) {
  .topbar { padding: 8px 10px; }
  .title h1 { font-size: 14px; }
  .controls { padding: 8px 10px; gap: 8px; }
  .control-group.grow { width: 100%; order: 99; }
  input[type=number] { width: 50px; }

  .layout {
    grid-template-columns: 1fr;
    position: relative;
  }
  .resizer { display: none; }

  /* 詳細ペインはフルスクリーンに被せる形 */
  .chart-pane {
    position: fixed;
    inset: 0;
    z-index: 100;
    background: var(--bg);
    transform: translateX(100%);
    transition: transform 0.2s ease;
    visibility: hidden;
  }
  body.show-detail .chart-pane {
    transform: translateX(0);
    visibility: visible;
  }
  body.show-detail { overflow: hidden; }

  .back-btn { display: inline-block; }
  .chart-header { padding: 8px 10px; }
  .chart-source { gap: 4px; flex-wrap: wrap; }
  .src-btn { padding: 4px 8px; font-size: 11px; }
  .open-ext { font-size: 11px; margin-left: 4px; }
  .chart-title .symbol { font-size: 14px; }
  .iframe-wrap { min-height: 320px; }
  .buyers { max-height: 40vh; }

  .token-info-grid {
    grid-template-columns: 1fr 1fr;
  }
}
