:root {
  --bg: #0b0f14;
  --surface: #131a23;
  --surface-2: #1a2330;
  --border: #243142;
  --text: #e8edf3;
  --muted: #8d9aab;
  --accent: #4c8dff;
  --buy: #22c55e;
  --buy-soft: rgba(34, 197, 94, .14);
  --sell: #f05252;
  --sell-soft: rgba(240, 82, 82, .14);
  --hold: #9aa5b4;
  --hold-soft: rgba(154, 165, 180, .14);
  --warn: #f5a524;
  --warn-soft: rgba(245, 165, 36, .14);
  --radius: 16px;
  --safe-top: env(safe-area-inset-top, 0px);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  color-scheme: dark;
}

@media (prefers-color-scheme: light) {
  :root {
    --bg: #f4f6f9;
    --surface: #ffffff;
    --surface-2: #eef1f5;
    --border: #dde3ea;
    --text: #111827;
    --muted: #5f6b7a;
    --accent: #2563eb;
    --buy: #15803d;
    --buy-soft: rgba(21, 128, 61, .10);
    --sell: #c81e1e;
    --sell-soft: rgba(200, 30, 30, .09);
    --hold: #5f6b7a;
    --hold-soft: rgba(95, 107, 122, .10);
    --warn: #b45309;
    --warn-soft: rgba(180, 83, 9, .10);
    color-scheme: light;
  }
}

* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 -apple-system, BlinkMacSystemFont, "SF Pro Text", "Segoe UI", Roboto, sans-serif;
  -webkit-font-smoothing: antialiased;
  -webkit-tap-highlight-color: transparent;
}
button, input { font: inherit; color: inherit; }
a { color: var(--accent); }

#app {
  max-width: 640px;
  margin: 0 auto;
  padding: calc(var(--safe-top) + 12px) 16px calc(var(--safe-bottom) + 96px);
}

/* header */
.top { display: flex; align-items: flex-start; justify-content: space-between; gap: 12px; margin: 4px 0 16px; }
.top h1 { font-size: 28px; line-height: 1.15; margin: 0; letter-spacing: -.02em; }
.top .sub { color: var(--muted); font-size: 13px; margin-top: 4px; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; white-space: nowrap;
  padding: 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 600;
  background: var(--surface-2); color: var(--muted); border: 1px solid var(--border);
}
.banner {
  border-radius: 12px; padding: 10px 12px; font-size: 14px; margin-bottom: 12px;
  background: var(--warn-soft); color: var(--warn); border: 1px solid transparent;
}

/* cards */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}
.card-head { display: flex; justify-content: space-between; align-items: baseline; gap: 8px; }
.pair { font-size: 22px; font-weight: 700; letter-spacing: -.01em; }
.pair-name { color: var(--muted); font-size: 13px; }
.when { color: var(--muted); font-size: 12px; text-align: right; }

.rating {
  display: flex; align-items: center; gap: 10px; margin: 14px 0 6px;
}
.badge {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 8px 14px; border-radius: 12px; font-weight: 800; font-size: 18px; letter-spacing: .02em;
}
.badge svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.6; stroke-linecap: round; stroke-linejoin: round; }
.badge.small { padding: 3px 8px; font-size: 12px; border-radius: 8px; font-weight: 700; }
.badge.small svg { width: 12px; height: 12px; }
.r-buy { background: var(--buy-soft); color: var(--buy); }
.r-sell { background: var(--sell-soft); color: var(--sell); }
.r-hold { background: var(--hold-soft); color: var(--hold); }
.r-review { background: var(--warn-soft); color: var(--warn); }
.r-error { background: var(--sell-soft); color: var(--sell); }
.rating .en { color: var(--muted); font-size: 13px; }

.price { font-size: 14px; color: var(--muted); }
.price b { color: var(--text); font-variant-numeric: tabular-nums; font-size: 16px; }

.levels {
  display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; margin: 12px 0;
}
.level { background: var(--surface-2); border-radius: 12px; padding: 8px 10px; min-width: 0; }
.level small { display: block; color: var(--muted); font-size: 11px; text-transform: uppercase; letter-spacing: .04em; }
.level b { display: block; font-variant-numeric: tabular-nums; font-size: 15px; overflow: hidden; text-overflow: ellipsis; }

.summary { font-size: 15px; margin: 8px 0 0; color: var(--text); }
.clamp { display: -webkit-box; -webkit-line-clamp: 4; -webkit-box-orient: vertical; overflow: hidden; }
.note { color: var(--muted); font-size: 12px; margin-top: 8px; }
.empty { color: var(--muted); font-size: 14px; margin: 12px 0 4px; }

.actions { display: flex; gap: 10px; margin-top: 14px; }
.btn {
  flex: 1; display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  min-height: 46px; padding: 0 14px; border-radius: 12px; border: 1px solid var(--border);
  background: var(--surface-2); font-weight: 600; font-size: 15px; text-decoration: none; color: var(--text);
  cursor: pointer;
}
.btn.primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn.danger { color: var(--sell); }
.btn:disabled { opacity: .5; }
.btn:active { transform: scale(.98); }

/* running state */
.running {
  margin-top: 14px; padding: 12px; border-radius: 12px;
  background: var(--surface-2); font-size: 14px;
}
.running .row { display: flex; align-items: center; gap: 10px; }
.running .label { font-weight: 600; }
.running .meta { color: var(--muted); font-size: 12px; margin-top: 4px; }
.spinner {
  width: 18px; height: 18px; flex: none; border-radius: 50%;
  border: 2.5px solid var(--border); border-top-color: var(--accent);
  animation: spin .9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }
.bar { height: 4px; background: var(--border); border-radius: 4px; margin-top: 10px; overflow: hidden; }
.bar i { display: block; height: 100%; width: 0; background: var(--accent); border-radius: 4px; transition: width .6s; }

/* lists */
.filters { display: flex; gap: 8px; overflow-x: auto; margin-bottom: 12px; padding-bottom: 2px; }
.filters button {
  border: 1px solid var(--border); background: var(--surface); color: var(--muted);
  border-radius: 999px; padding: 7px 14px; font-size: 14px; font-weight: 600; white-space: nowrap;
}
.filters button.on { background: var(--text); color: var(--bg); border-color: var(--text); }
.list { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden; }
.item {
  display: flex; align-items: center; gap: 12px; padding: 12px 14px; text-decoration: none; color: inherit;
  border-bottom: 1px solid var(--border);
}
.item:last-child { border-bottom: 0; }
.item .grow { flex: 1; min-width: 0; }
.item .t1 { font-weight: 700; }
.item .t2 { color: var(--muted); font-size: 13px; }
.item .px { font-variant-numeric: tabular-nums; font-size: 14px; color: var(--muted); text-align: right; }
.chev { width: 16px; height: 16px; stroke: var(--muted); fill: none; stroke-width: 2; flex: none; }

/* detail */
.back { display: inline-flex; align-items: center; gap: 4px; color: var(--accent); text-decoration: none; font-weight: 600; margin: 4px 0 12px; }
.back svg { width: 18px; height: 18px; stroke: currentColor; fill: none; stroke-width: 2.4; }
.kv { display: grid; grid-template-columns: auto 1fr; gap: 6px 12px; font-size: 14px; margin-top: 12px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; text-align: right; font-variant-numeric: tabular-nums; }
details.section { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); margin-bottom: 10px; }
details.section summary {
  list-style: none; cursor: pointer; padding: 14px 16px; font-weight: 700;
  display: flex; justify-content: space-between; align-items: center;
}
details.section summary::-webkit-details-marker { display: none; }
details.section summary::after { content: "+"; color: var(--muted); font-size: 20px; font-weight: 400; }
details.section[open] summary::after { content: "–"; }
.md { padding: 0 16px 14px; font-size: 15px; overflow-wrap: anywhere; }
.md h1, .md h2, .md h3, .md h4 { font-size: 16px; margin: 16px 0 6px; }
.md p { margin: 8px 0; }
.md ul, .md ol { padding-left: 20px; }
.md table { display: block; overflow-x: auto; border-collapse: collapse; font-size: 13px; margin: 8px 0; }
.md th, .md td { border: 1px solid var(--border); padding: 5px 8px; text-align: left; white-space: nowrap; }
.md code { background: var(--surface-2); padding: 1px 4px; border-radius: 4px; font-size: 13px; }
.md blockquote { margin: 8px 0; padding-left: 12px; border-left: 3px solid var(--border); color: var(--muted); }
.disclaimer { color: var(--muted); font-size: 12px; text-align: center; margin: 18px 8px; }

/* settings */
.group-title { color: var(--muted); font-size: 13px; text-transform: uppercase; letter-spacing: .05em; margin: 18px 4px 8px; }
.row-line { display: flex; justify-content: space-between; gap: 12px; padding: 12px 14px; border-bottom: 1px solid var(--border); font-size: 15px; }
.row-line:last-child { border-bottom: 0; }
.row-line span:last-child { color: var(--muted); text-align: right; overflow-wrap: anywhere; }
.stack { display: grid; gap: 10px; margin-top: 12px; }
.help { color: var(--muted); font-size: 13px; margin: 8px 4px; }
.help code { background: var(--surface-2); padding: 1px 5px; border-radius: 4px; }

/* login */
.login { min-height: 80vh; display: grid; place-items: center; }
.login .card { width: 100%; max-width: 380px; text-align: center; padding: 28px 20px; }
.login img { width: 72px; height: 72px; border-radius: 18px; }
.login h1 { font-size: 24px; margin: 12px 0 4px; }
.login p { color: var(--muted); margin: 0 0 18px; font-size: 14px; }
.login input {
  width: 100%; min-height: 50px; padding: 0 14px; border-radius: 12px; font-size: 17px;
  border: 1px solid var(--border); background: var(--surface-2); margin-bottom: 12px;
}
.login .err { color: var(--sell); font-size: 14px; min-height: 20px; margin-bottom: 8px; }

/* tab bar */
.tabbar {
  position: fixed; left: 0; right: 0; bottom: 0; z-index: 10;
  display: flex; justify-content: center;
  padding: 6px 8px calc(var(--safe-bottom) + 6px);
  background: color-mix(in srgb, var(--surface) 88%, transparent);
  -webkit-backdrop-filter: blur(16px); backdrop-filter: blur(16px);
  border-top: 1px solid var(--border);
}
.tabbar[hidden] { display: none; }
.tabbar a {
  flex: 1; max-width: 160px; display: flex; flex-direction: column; align-items: center; gap: 2px;
  padding: 4px 0; color: var(--muted); text-decoration: none; font-size: 11px; font-weight: 600;
}
.tabbar svg { width: 24px; height: 24px; stroke: currentColor; fill: none; stroke-width: 1.9; stroke-linecap: round; stroke-linejoin: round; }
.tabbar a.on { color: var(--accent); }

.toast {
  position: fixed; left: 50%; bottom: calc(var(--safe-bottom) + 84px); transform: translateX(-50%);
  background: var(--text); color: var(--bg); padding: 10px 16px; border-radius: 12px;
  font-size: 14px; font-weight: 600; z-index: 20; max-width: calc(100vw - 32px);
}
