:root {
  --bg: #11171f;
  --bg-grad-a: #1e2d39;
  --bg-grad-b: #352517;
  --surface: rgba(255, 255, 255, 0.08);
  --surface-2: rgba(255, 255, 255, 0.04);
  --line: rgba(255, 255, 255, 0.18);
  --text: #eef4fa;
  --muted: #9bb0c2;
  --accent: #f07a3b;
  --accent-2: #2db693;
  --danger: #e85f5f;
  --ok: #4fcf86;
  --shadow: 0 10px 28px rgba(5, 9, 14, 0.35);
}

:root[data-theme='light'] {
  --bg: #f5f1ea;
  --bg-grad-a: #f4e7d7;
  --bg-grad-b: #dfebf7;
  --surface: rgba(255, 255, 255, 0.86);
  --surface-2: rgba(255, 255, 255, 0.58);
  --line: rgba(17, 29, 38, 0.14);
  --text: #18222c;
  --muted: #5d7081;
  --accent: #c65f2a;
  --accent-2: #1a8f71;
  --danger: #b54040;
  --ok: #1f8757;
  --shadow: 0 10px 24px rgba(25, 43, 58, 0.12);
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  font-family: 'Space Grotesk', 'Segoe UI', sans-serif;
  color: var(--text);
  background:
    radial-gradient(circle at 0% 0%, var(--bg-grad-a) 0%, transparent 36%),
    radial-gradient(circle at 100% 100%, var(--bg-grad-b) 0%, transparent 38%),
    var(--bg);
  min-height: 100vh;
}

a {
  color: inherit;
}

.app-shell {
  max-width: 1360px;
  margin: 0 auto;
  padding: 22px 18px 96px;
  display: grid;
  gap: 14px;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 18px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.kicker {
  margin: 0;
  font-size: 11px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  color: #f7bd9e;
}

h1 {
  margin: 5px 0 6px;
  font-size: clamp(24px, 3.5vw, 40px);
  line-height: 1.05;
}

h2, h3 {
  margin: 0;
}

.muted {
  color: var(--muted);
  margin: 0;
  font-size: 13px;
}

.icon-btn,
.ghost,
.primary,
.nav-tabs button,
.chip,
.bottom-nav button,
.link-btn {
  border: 1px solid var(--line);
  border-radius: 11px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  transition: transform 0.16s ease, background 0.16s ease, border-color 0.16s ease;
}

.icon-btn:hover,
.ghost:hover,
.primary:hover,
.nav-tabs button:hover,
.chip:hover,
.bottom-nav button:hover,
.link-btn:hover {
  transform: translateY(-1px);
}

.icon-btn {
  width: 42px;
  height: 42px;
  font-size: 18px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

.icon-gear {
  width: 20px;
  height: 20px;
}

.link-btn {
  text-decoration: none;
  padding: 8px 12px;
}

.primary {
  background: linear-gradient(160deg, var(--accent), #ff9a50);
  border-color: transparent;
  color: #171f26;
  font-weight: 700;
  padding: 9px 14px;
}

.ghost {
  padding: 9px 14px;
}

.nav-tabs {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
}

.nav-tabs button {
  padding: 10px;
  font-weight: 600;
  text-transform: lowercase;
}

.nav-tabs button.active,
.chip.active,
.bottom-nav button.active {
  border-color: rgba(240, 122, 59, 0.8);
  background: rgba(240, 122, 59, 0.18);
}

.panel {
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.panel.error {
  border-color: rgba(232, 95, 95, 0.6);
  color: #ffd6d6;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 12px;
}

.panel-head.compact {
  margin-bottom: 6px;
}

.note {
  margin: 0 0 12px;
  color: var(--muted);
  font-size: 13px;
}

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.market-stats {
  grid-template-columns: repeat(7, minmax(0, 1fr));
}

.stats-grid > div {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 9px 10px;
  background: rgba(0, 0, 0, 0.12);
  display: grid;
  gap: 3px;
}

.stats-grid span {
  color: var(--muted);
  font-size: 12px;
}

.stats-grid strong {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 16px;
}

.pos {
  color: var(--ok);
}

.neg {
  color: var(--danger);
}

.mono {
  font-family: 'IBM Plex Mono', monospace;
}

.market-head {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  margin-bottom: 10px;
}

.market-head h3 {
  margin-bottom: 4px;
}

.chips {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
}

.chip {
  padding: 8px 12px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 12px;
}

.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
  min-width: 960px;
}

th,
td {
  border-bottom: 1px solid var(--line);
  padding: 8px;
  text-align: left;
  vertical-align: top;
  font-size: 13px;
}

th {
  color: var(--muted);
  font-size: 12px;
  font-weight: 600;
}

.tweets-wrap {
  overflow-x: hidden;
}

.tweets-table {
  min-width: 0;
  table-layout: fixed;
}

.tweets-table .tweet-time {
  width: 178px;
  white-space: nowrap;
}

.tweets-table .tweet-type {
  width: 64px;
  white-space: nowrap;
}

.tweets-table .tweet-text,
.tweets-table .tweet-text a {
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.market-col {
  min-width: 260px;
}

.edge {
  display: inline-block;
  border-radius: 999px;
  padding: 3px 8px;
  font-family: 'IBM Plex Mono', monospace;
  font-size: 11px;
  border: 1px solid transparent;
}

.pos-edge {
  background: rgba(79, 207, 134, var(--a));
  border-color: rgba(79, 207, 134, calc(var(--a) + 0.05));
  color: #0f2a1d;
}

.neg-edge {
  background: rgba(232, 95, 95, var(--a));
  border-color: rgba(232, 95, 95, calc(var(--a) + 0.05));
  color: #311313;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(8, 11, 15, 0.55);
  display: grid;
  justify-items: end;
  z-index: 30;
}

.drawer {
  width: min(420px, 94vw);
  height: 100%;
  background: var(--bg);
  border-left: 1px solid var(--line);
  padding: 18px;
  display: grid;
  align-content: start;
  gap: 12px;
}

.drawer-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
}

.field {
  display: grid;
  gap: 6px;
}

.field span {
  font-size: 13px;
  color: var(--muted);
}

.field input,
.field select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
}

.field textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  resize: vertical;
}

.totals {
  margin-bottom: 16px;
}

.wallet-panel {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
  background: rgba(0, 0, 0, 0.08);
}

.wallet-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
}

.wallet-ok,
.wallet-bad {
  font-size: 11px;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 3px 8px;
}

.wallet-ok {
  color: var(--ok);
}

.wallet-bad {
  color: var(--danger);
}

.wallet-stats {
  margin-bottom: 10px;
}

.mode-switch {
  margin-left: auto;
}

.market-switch {
  margin-bottom: 10px;
}

.history-stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.history-wrap {
  overflow-x: hidden;
}

.history-table {
  min-width: 0;
  table-layout: auto;
}

.history-table th,
.history-table td {
  padding: 7px 6px;
  font-size: 12px;
  white-space: normal;
  overflow-wrap: anywhere;
  word-break: break-word;
}

.history-sub {
  color: var(--muted);
  font-size: 11px;
}

.history-table .h-time {
  width: 185px;
}

.history-table .h-expand {
  width: 46px;
  text-align: center;
}

.history-table .h-slug {
  width: 220px;
}

.history-table .h-wallet {
  width: 130px;
}

.history-table .h-outcome {
  width: 86px;
}

.history-table .h-state {
  width: 100px;
}

.history-table .h-sizes,
.history-table .h-prices,
.history-table .h-pnl {
  width: 120px;
  text-align: right;
}

.expand-btn {
  width: 28px;
  height: 28px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
  color: var(--text);
  cursor: pointer;
  font-size: 14px;
  line-height: 1;
}

.history-detail-row td {
  background: rgba(255, 255, 255, 0.03);
}

.history-detail-box {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
}

.history-detail-stats {
  grid-template-columns: repeat(5, minmax(0, 1fr));
}

.edge-chart-wrap {
  margin-top: 8px;
}

.edge-chart {
  width: 100%;
  height: 240px;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: rgba(0, 0, 0, 0.1);
}

.edge-axis {
  stroke: rgba(255, 255, 255, 0.35);
  stroke-width: 1.2;
}

.edge-grid {
  stroke: rgba(255, 255, 255, 0.12);
  stroke-width: 1;
}

.edge-zero {
  stroke: rgba(240, 122, 59, 0.65);
  stroke-width: 1.2;
  stroke-dasharray: 3 4;
}

.edge-line {
  fill: none;
  stroke-width: 2.2;
}

.edge-3 { stroke: #f07a3b; }
.edge-7 { stroke: #2db693; }
.edge-14 { stroke: #66a7ff; }
.edge-all { stroke: #f4d35e; }

.edge-label {
  fill: var(--muted);
  font-size: 11px;
  font-family: 'IBM Plex Mono', monospace;
}

.edge-legend {
  margin-top: 8px;
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
  color: var(--muted);
  font-size: 12px;
}

.edge-legend .dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  margin-right: 5px;
}

.edge-legend .dot.d3 { background: #f07a3b; }
.edge-legend .dot.d7 { background: #2db693; }
.edge-legend .dot.d14 { background: #66a7ff; }
.edge-legend .dot.dall { background: #f4d35e; }

.history-filters {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.history-filters .field {
  margin: 0;
}

.history-actions {
  display: flex;
  align-items: end;
  justify-content: flex-end;
}

.drawer-actions {
  margin-top: 4px;
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.bottom-nav {
  position: fixed;
  left: 0;
  right: 0;
  bottom: 0;
  padding: 10px 14px;
  display: none;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  background: color-mix(in srgb, var(--bg) 84%, transparent);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--line);
}

.bottom-nav button {
  padding: 10px;
  text-transform: lowercase;
  font-weight: 600;
}

.news-stats {
  grid-template-columns: repeat(4, minmax(0, 1fr));
}

.news-rate-bar {
  width: 100%;
  height: 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  overflow: hidden;
  background: rgba(255, 255, 255, 0.08);
  margin: 6px 0 12px;
}

.news-rate-fill {
  height: 100%;
  background: linear-gradient(90deg, #2db693, #f07a3b, #e85f5f);
}

.news-list {
  display: grid;
  gap: 8px;
}

.news-item {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 10px;
  background: rgba(0, 0, 0, 0.12);
  display: grid;
  gap: 6px;
}

.news-meta {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px;
  color: var(--muted);
  font-size: 12px;
}

.news-source {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 2px 8px;
}

.news-title {
  color: var(--text);
  text-decoration: none;
  font-weight: 600;
}

.news-title:hover {
  text-decoration: underline;
}

.news-sentiment {
  border-radius: 999px;
  padding: 2px 8px;
  border: 1px solid var(--line);
  font-weight: 600;
}

.news-sentiment.pos {
  color: var(--ok);
}

.news-sentiment.neg {
  color: var(--danger);
}

.hour-stats {
  grid-template-columns: repeat(3, minmax(0, 1fr));
}

.hour-table {
  min-width: 640px;
}

.hour-heatmap {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 8px;
  margin-bottom: 12px;
}

.hour-heat-cell {
  border: 1px solid var(--line);
  border-radius: 10px;
  padding: 8px 9px;
  min-height: 56px;
  display: grid;
  gap: 4px;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.05);
}

.hour-heat-hour {
  font-size: 12px;
}

.hour-heat-val {
  font-size: 15px;
}

.hour-bar-wrap {
  width: 100%;
  height: 10px;
  border: 1px solid var(--line);
  border-radius: 999px;
  background: rgba(255, 255, 255, 0.08);
  overflow: hidden;
}

.hour-bar {
  height: 100%;
  background: linear-gradient(90deg, var(--accent), var(--accent-2));
  border-radius: 999px;
}

@media (max-width: 1120px) {
  .stats-grid {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .market-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .news-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .history-filters {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .hour-heatmap {
    grid-template-columns: repeat(4, minmax(0, 1fr));
  }

  .history-table .h-slug {
    width: 170px;
  }

  .history-detail-stats {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  .history-table .h-wallet {
    width: 100px;
  }

  .history-table .h-outcome {
    width: 74px;
  }

  .history-table .h-time {
    width: 160px;
  }

  .history-table .h-sizes,
  .history-table .h-prices,
  .history-table .h-pnl {
    width: 105px;
  }
}

@media (max-width: 780px) {
  .app-shell {
    padding: 14px 12px 88px;
  }

  .topbar {
    padding: 14px;
  }

  .nav-tabs {
    display: none;
  }

  .bottom-nav {
    display: grid;
  }

  .stats-grid,
  .market-stats {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .news-stats {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }

  .history-stats {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }

  .history-filters {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }

  .hour-heatmap {
    grid-template-columns: repeat(3, minmax(0, 1fr));
  }

  table {
    min-width: 860px;
  }

  .history-table {
    min-width: 0;
  }

  .history-table th,
  .history-table td {
    font-size: 11px;
    padding: 5px 4px;
  }

  .history-table .h-time {
    width: 120px;
  }

  .history-table .h-slug {
    width: 120px;
  }

  .history-detail-stats {
    grid-template-columns: repeat(1, minmax(0, 1fr));
  }

  .history-table .h-wallet {
    width: 82px;
  }

  .history-table .h-outcome {
    width: 62px;
  }

  .history-table .h-state,
  .history-table .h-sizes,
  .history-table .h-prices,
  .history-table .h-pnl {
    width: 82px;
  }

  .tweets-table {
    min-width: 0;
  }

  .tweets-table .tweet-time {
    width: 138px;
    font-size: 12px;
  }
}
