:root {
  --bg: #0b0f17;
  --bg2: #121826;
  --panel: #151c2c;
  --panel-border: rgba(120, 160, 255, 0.12);
  --text: #e8eefc;
  --muted: #8b97b3;
  --accent: #5b8cff;
  --accent2: #2ee6a6;
  --warn: #ffb020;
  --bad: #ff5d7a;
  --good: #2ee6a6;
  --radius: 14px;
  --shadow: 0 10px 40px rgba(0, 0, 0, 0.35);
  --font: "Segoe UI", "PingFang HK", "Noto Sans TC", system-ui, sans-serif;
  --tabbar-h: 64px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 600px at 10% -10%, #1a2744 0%, transparent 55%),
              radial-gradient(900px 500px at 100% 0%, #132a28 0%, transparent 50%),
              var(--bg);
  color: var(--text);
  font-family: var(--font);
}
.hidden { display: none !important; }
.muted { color: var(--muted); }
.error { color: var(--bad); font-size: 0.9rem; }

/* Login */
.login-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.login-card {
  width: min(380px, 100%);
  background: linear-gradient(180deg, #1a2336, var(--panel));
  border: 1px solid var(--panel-border);
  border-radius: 20px;
  padding: 28px 24px 24px;
  box-shadow: var(--shadow);
  display: flex;
  flex-direction: column;
  gap: 12px;
}
.brand-mark {
  width: 44px; height: 44px;
  border-radius: 12px;
  display: grid; place-items: center;
  font-weight: 800;
  background: linear-gradient(135deg, var(--accent), #8b5cff);
  box-shadow: 0 0 24px rgba(91, 140, 255, 0.45);
}
.login-card h1 { margin: 0; font-size: 1.5rem; }
.field { display: flex; flex-direction: column; gap: 6px; font-size: 0.85rem; color: var(--muted); }
.field input {
  background: var(--bg2);
  border: 1px solid var(--panel-border);
  border-radius: 10px;
  padding: 12px 14px;
  color: var(--text);
  font-size: 1rem;
}
.field input:focus { outline: 2px solid rgba(91, 140, 255, 0.45); border-color: var(--accent); }

.btn {
  border: none;
  border-radius: 10px;
  padding: 11px 16px;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.15s ease;
}
.btn:hover { transform: translateY(-1px); }
.btn.primary {
  background: linear-gradient(135deg, var(--accent), #7a5cff);
  color: white;
}
.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--panel-border);
}
.btn.ghost:hover { color: var(--text); }

/* Desk */
.desk { min-height: 100vh; display: flex; flex-direction: column; }
.topbar {
  position: sticky; top: 0; z-index: 20;
  display: flex; align-items: center; gap: 16px; flex-wrap: wrap;
  padding: 12px 18px;
  background: rgba(11, 15, 23, 0.82);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--panel-border);
}
.topbar-left { display: flex; align-items: center; gap: 10px; }
.logo {
  font-weight: 800;
  letter-spacing: 0.02em;
  background: linear-gradient(90deg, #fff, #9db7ff);
  -webkit-background-clip: text;
  background-clip: text;
  color: transparent;
}
.pulse {
  color: var(--accent2);
  animation: pulseGlow 1.6s ease-in-out infinite;
  font-size: 0.85rem;
}
.pulse.stale { color: var(--warn); animation: none; }
.pulse.down { color: var(--bad); animation: none; }
.pulse.soft-pulse {
  animation: softPulse 0.7s ease;
}
@keyframes softPulse {
  0% { transform: scale(1); filter: brightness(1); }
  40% { transform: scale(1.35); filter: brightness(1.6); }
  100% { transform: scale(1); filter: brightness(1); }
}
@keyframes pulseGlow {
  0%, 100% { opacity: 1; text-shadow: 0 0 8px rgba(46, 230, 166, 0.7); }
  50% { opacity: 0.45; text-shadow: 0 0 2px rgba(46, 230, 166, 0.2); }
}

.topbar-metrics {
  display: flex; gap: 14px; flex: 1; justify-content: center; flex-wrap: wrap;
}
.metric {
  background: rgba(255,255,255,0.03);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 6px 12px;
  min-width: 100px;
}
.metric-label { display: block; font-size: 0.7rem; color: var(--muted); text-transform: uppercase; letter-spacing: 0.06em; }
.metric-value { font-weight: 700; font-variant-numeric: tabular-nums; }
.num { transition: opacity 0.25s ease; }
.num.flash { opacity: 0.35; }

.topbar-right { margin-left: auto; }

.main {
  width: min(1200px, 100%);
  margin: 0 auto;
  padding: 16px 14px 28px;
  display: flex; flex-direction: column; gap: 16px;
  flex: 1;
}
.panel {
  background: linear-gradient(180deg, rgba(28, 38, 58, 0.9), var(--panel));
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 14px;
  box-shadow: var(--shadow);
}
.panel-head {
  display: flex; align-items: center; justify-content: space-between;
  margin-bottom: 12px;
}
.panel-head h2 { margin: 0; font-size: 1rem; font-weight: 700; }
.chip {
  font-size: 0.75rem;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(91, 140, 255, 0.15);
  color: #b7cbff;
}
.equity-delta.up { background: rgba(46,230,166,0.18); color: var(--good); }
.equity-delta.down { background: rgba(255,93,122,0.18); color: var(--bad); }
.curve-legend { margin: 0 0 8px; font-size: 0.72rem; }
.equity-chart {
  width: 100%;
  height: 180px;
  border-radius: 12px;
  background: rgba(0,0,0,0.22);
  border: 1px solid var(--panel-border);
  overflow: hidden;
}
.equity-chart svg { width: 100%; height: 100%; display: block; }
.equity-empty {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  font-size: 0.85rem;
}

.sleeve-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
  gap: 10px;
}
.sleeve-card {
  background: rgba(0,0,0,0.22);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 12px;
  animation: fadeUp 0.35s ease both;
}
.sleeve-card.off { opacity: 0.55; }
.sleeve-card .row { display: flex; justify-content: space-between; gap: 8px; align-items: baseline; }
.sleeve-card .name { font-weight: 700; }
.badge {
  font-size: 0.68rem;
  padding: 2px 7px;
  border-radius: 999px;
  font-weight: 700;
}
.badge.on { background: rgba(46,230,166,0.15); color: var(--good); }
.badge.off { background: rgba(255,93,122,0.12); color: var(--bad); }
.badge.research { background: rgba(255,176,32,0.15); color: var(--warn); }
.kpi {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  margin-top: 10px;
}
.kpi div {
  background: rgba(255,255,255,0.03);
  border-radius: 8px;
  padding: 6px;
  text-align: center;
}
.kpi .k { display: block; font-size: 0.65rem; color: var(--muted); }
.kpi .v { font-weight: 700; font-variant-numeric: tabular-nums; font-size: 0.95rem; }
.gates { margin-top: 8px; font-size: 0.72rem; color: var(--muted); line-height: 1.35; }

.split {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 16px;
}

.card-list, .feed {
  display: flex; flex-direction: column; gap: 8px;
  max-height: 560px; overflow: auto;
  padding-right: 2px;
}
.item {
  background: rgba(0,0,0,0.2);
  border: 1px solid var(--panel-border);
  border-radius: 12px;
  padding: 10px 12px;
  animation: fadeUp 0.3s ease both;
}
.item .title {
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 4px;
  word-break: break-word;
}
.item .meta {
  display: flex; flex-wrap: wrap; gap: 6px 10px;
  font-size: 0.75rem; color: var(--muted);
}
.tag {
  display: inline-flex; align-items: center;
  padding: 2px 7px; border-radius: 6px;
  background: rgba(91,140,255,0.18); color: #c5d6ff;
  font-size: 0.7rem; font-weight: 700;
}
.tag.ok { background: rgba(46,230,166,0.15); color: var(--good); }
.tag.fail { background: rgba(255,93,122,0.15); color: var(--bad); }
.agg { color: #ffd37a; font-weight: 700; }
.pnl-pos { color: var(--good); }
.pnl-neg { color: var(--bad); }

/* Tweet-like activity cards */
.tweet {
  display: flex;
  gap: 12px;
  background: rgba(0,0,0,0.22);
  border: 1px solid var(--panel-border);
  border-radius: 14px;
  padding: 12px 14px;
  animation: fadeUp 0.3s ease both;
  transition: background 0.4s ease, box-shadow 0.4s ease;
}
.tweet.fresh {
  background: rgba(91, 140, 255, 0.12);
  box-shadow: 0 0 0 1px rgba(91, 140, 255, 0.35);
}
.tweet-avatar {
  flex-shrink: 0;
  width: 42px; height: 42px;
  border-radius: 50%;
  display: grid; place-items: center;
  font-weight: 800;
  font-size: 0.72rem;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, #3d5cff, #8b5cff);
  color: #fff;
}
.tweet-body { flex: 1; min-width: 0; }
.tweet-action {
  font-weight: 700;
  font-size: 0.95rem;
  margin-bottom: 2px;
}
.tweet-slug {
  color: var(--muted);
  font-size: 0.82rem;
  margin-bottom: 6px;
  word-break: break-word;
}
.tweet-meta {
  display: flex; flex-wrap: wrap; gap: 6px 10px;
  align-items: center;
  font-size: 0.75rem;
  color: var(--muted);
}
.pill {
  display: inline-flex;
  padding: 2px 8px;
  border-radius: 999px;
  font-weight: 700;
  font-size: 0.68rem;
}
.pill.ok { background: rgba(46,230,166,0.15); color: var(--good); }
.pill.fail { background: rgba(255,93,122,0.15); color: var(--bad); }

.foot {
  display: flex; justify-content: space-between; gap: 10px; flex-wrap: wrap;
  padding: 10px 18px 18px;
  font-size: 0.75rem;
}

/* Mobile / desktop visibility */
.mobile-only { display: none; }
.desk-only { display: block; }
.split.desk-only { display: grid; }

.tab-bar {
  position: fixed;
  bottom: 0; left: 0; right: 0;
  z-index: 40;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  height: calc(var(--tabbar-h) + env(safe-area-inset-bottom, 0px));
  padding-bottom: env(safe-area-inset-bottom, 0px);
  background: rgba(11, 15, 23, 0.94);
  backdrop-filter: blur(14px);
  border-top: 1px solid var(--panel-border);
}
.tab-btn {
  background: transparent;
  border: none;
  color: var(--muted);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 2px;
  font-size: 0.72rem;
  font-weight: 600;
  cursor: pointer;
  padding: 8px 4px;
}
.tab-btn .tab-ico { font-size: 1.05rem; line-height: 1; }
.tab-btn.active { color: var(--accent2); }
.tab-pane { display: none; padding-bottom: 8px; }
.tab-pane.active { display: block; }
.sticky-head {
  position: sticky;
  top: 0;
  z-index: 5;
  background: rgba(11, 15, 23, 0.9);
  backdrop-filter: blur(8px);
  padding: 8px 0;
  margin-bottom: 8px;
}

@media (max-width: 860px) {
  .mobile-only { display: block; }
  .tab-bar.mobile-only { display: grid; }
  .desk-only { display: none !important; }
  .split { grid-template-columns: 1fr; }
  .topbar-metrics { justify-content: flex-start; width: 100%; order: 3; }
  .topbar-right { margin-left: 0; }
  .main {
    padding: 12px 12px calc(var(--tabbar-h) + 28px);
    gap: 0;
  }
  .mobile-panes {
    min-height: 50vh;
  }
  /* Remove max-height traps — each tab scrolls the viewport */
  .card-list, .feed {
    max-height: none;
    overflow: visible;
  }
  .equity-chart { height: 220px; }
  .foot { padding-bottom: calc(var(--tabbar-h) + 12px); }
}

@keyframes fadeUp {
  from { opacity: 0; transform: translateY(6px); }
  to { opacity: 1; transform: none; }
}

::-webkit-scrollbar { width: 8px; height: 8px; }
::-webkit-scrollbar-thumb { background: rgba(120,140,180,0.35); border-radius: 8px; }
