:root {
  color-scheme: dark;
  --bg: #080b0a;
  --surface: #0d1110;
  --surface-2: #111714;
  --surface-3: #151d19;
  --line: #28342f;
  --line-soft: #1b2420;
  --text: #f2f6f3;
  --muted: #8a9690;
  --muted-2: #5f6964;
  --lime: #c7f85d;
  --green: #43e19d;
  --red: #ff6c73;
  --blue: #66a8ff;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--bg); }
body {
  margin: 0;
  min-width: 320px;
  min-height: 100vh;
  color: var(--text);
  background: radial-gradient(circle at 76% -10%, rgba(199, 248, 93, .07), transparent 30%), var(--bg);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
  -webkit-font-smoothing: antialiased;
}

.topbar {
  position: sticky;
  top: 0;
  z-index: 20;
  min-height: 70px;
  display: flex;
  align-items: center;
  gap: 30px;
  padding: 10px clamp(18px, 2.4vw, 42px);
  border-bottom: 1px solid var(--line-soft);
  background: rgba(8, 11, 10, .9);
  backdrop-filter: blur(18px);
}

.brand { display: inline-flex; align-items: center; gap: 11px; color: var(--text); text-decoration: none; }
.brand-copy { display: flex; flex-direction: column; gap: 3px; line-height: 1; }
.brand-copy strong { font-size: 14px; letter-spacing: .035em; white-space: nowrap; }
.brand-copy small { color: var(--muted); font-size: 7px; letter-spacing: .035em; white-space: nowrap; }
.brand-mark { width: 25px; height: 25px; display: flex; align-items: flex-end; gap: 3px; }
.brand-mark i { width: 6px; display: block; background: var(--lime); transform: skew(-13deg); }
.brand-mark i:nth-child(1) { height: 12px; opacity: .5; }
.brand-mark i:nth-child(2) { height: 21px; }
.brand-mark i:nth-child(3) { height: 16px; opacity: .76; }
.page-title { padding-left: 28px; border-left: 1px solid var(--line); display: flex; flex-direction: column; gap: 2px; }
.page-title span, .section-kicker { color: var(--lime); font: 700 8px/1.2 ui-monospace, SFMono-Regular, Menlo, monospace; letter-spacing: .16em; }
.page-title strong { font-size: 13px; font-weight: 620; }
.header-status { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.header-status > span:last-child { display: flex; flex-direction: column; gap: 2px; }
.header-status strong { font-size: 11px; }
.header-status small { color: var(--muted); font-size: 9px; }
.engine-pulse { width: 8px; height: 8px; border-radius: 50%; background: var(--green); box-shadow: 0 0 0 4px rgba(67, 225, 157, .1); animation: pulse 1.8s ease-in-out infinite; }

main { width: min(1880px, 100%); margin: 0 auto; padding: 20px clamp(12px, 1.5vw, 28px) 34px; }
.overview {
  display: flex;
  align-items: end;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 16px;
  padding: 0 2px;
}
.overview h1 { margin: 6px 0 0; font-size: clamp(20px, 2vw, 30px); letter-spacing: -.035em; }
.overview-copy { max-width: 760px; }
.overview-copy p { max-width: 720px; margin: 7px 0 0; color: var(--muted); font-size: 10px; line-height: 1.55; }
.overview-metrics { display: flex; align-items: stretch; border: 1px solid var(--line); border-radius: 9px; overflow: hidden; background: var(--surface); }
.overview-metrics > span { min-width: 108px; padding: 9px 14px; display: flex; flex-direction: column; gap: 4px; border-left: 1px solid var(--line-soft); }
.overview-metrics > span:first-child { border-left: 0; }
.overview-metrics small { color: var(--muted-2); font: 700 7px/1 ui-monospace, monospace; letter-spacing: .13em; }
.overview-metrics strong { font-size: 13px; font-variant-numeric: tabular-nums; }

.trade-grid { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 12px; align-items: stretch; }
.trade-box {
  min-width: 0;
  height: 410px;
  display: flex;
  flex-direction: column;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: 0 14px 36px rgba(0, 0, 0, .14);
}
.trade-titlebar {
  min-height: 42px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  padding: 0 13px;
  border-bottom: 1px solid var(--line);
  background: #101612;
}
.title-status { min-width: 0; display: flex; align-items: center; gap: 8px; }
.title-status i { width: 6px; height: 6px; flex: 0 0 auto; border-radius: 50%; background: var(--muted-2); }
.trade-title { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; font-weight: 650; letter-spacing: .012em; }
.box-number { color: var(--muted-2); font: 700 8px/1 ui-monospace, monospace; }
.trade-content { min-height: 0; flex: 1; display: flex; flex-direction: column; }

.state-waiting .trade-content { align-items: center; justify-content: center; background: radial-gradient(circle, rgba(199,248,93,.035), transparent 58%); }
.waiting-state { display: flex; flex-direction: column; align-items: center; text-align: center; }
.scanner { position: relative; width: 52px; height: 52px; margin-bottom: 14px; border: 1px solid var(--line); border-radius: 50%; }
.scanner::before, .scanner::after { content: ""; position: absolute; inset: 8px; border: 1px solid var(--line-soft); border-radius: 50%; }
.scanner::after { inset: 50% auto auto 50%; width: 19px; height: 1px; border: 0; border-radius: 0; background: linear-gradient(90deg, var(--lime), transparent); transform-origin: left center; animation: scan 2s linear infinite; }
.waiting-state strong { font-size: 11px; }
.waiting-state span { margin-top: 5px; color: var(--muted); font-size: 9px; }

.state-deploying .trade-titlebar { border-bottom-color: rgba(199, 248, 93, .35); }
.state-deploying .title-status i { background: var(--lime); box-shadow: 0 0 0 4px rgba(199, 248, 93, .08); }
.cli-shell { min-height: 0; flex: 1; display: flex; flex-direction: column; background: #090c0b; }
.cli-head { height: 30px; flex: 0 0 auto; display: flex; align-items: center; gap: 5px; padding: 0 11px; border-bottom: 1px solid #1d2521; }
.cli-head i { width: 6px; height: 6px; border-radius: 50%; background: #ff6c73; }
.cli-head i:nth-child(2) { background: #f3c45d; }
.cli-head i:nth-child(3) { background: #43e19d; }
.cli-head span { margin-left: auto; color: #48524d; font: 7px ui-monospace, monospace; }
.cli-output { min-height: 0; flex: 1; overflow: hidden; padding: 11px 12px; color: #b7c1bc; font: 8.5px/1.5 ui-monospace, SFMono-Regular, Menlo, monospace; }
.cli-line { margin-bottom: 5px; opacity: 0; transform: translateY(4px); animation: lineIn .2s ease forwards; }
.cli-line.command { color: var(--lime); }
.cli-line.message { color: #edf2ef; line-height: 1.55; }
.cli-line.setting { display: flex; justify-content: space-between; gap: 12px; padding-left: 8px; border-left: 1px solid #27322d; }
.cli-line.setting span { color: #68736d; }
.cli-line.setting strong { color: #d4dcd8; text-align: right; font-weight: 500; }
.cli-line.success { color: var(--green); }
.cli-line.loading { color: #f2f6f3; }
.cli-foot { min-height: 30px; flex: 0 0 auto; display: flex; align-items: center; gap: 8px; padding: 0 11px; border-top: 1px solid #1d2521; color: #66716b; font: 7px ui-monospace, monospace; }
.cli-spinner { width: 10px; height: 10px; border: 1px solid #2e3934; border-top-color: var(--lime); border-radius: 50%; animation: spin .8s linear infinite; }

.state-live .trade-titlebar { border-bottom-color: rgba(67, 225, 157, .4); }
.state-live .title-status i { background: var(--green); box-shadow: 0 0 0 4px rgba(67, 225, 157, .08); animation: pulse 1.6s ease-in-out infinite; }
.live-shell { min-height: 0; flex: 1; display: grid; grid-template-rows: auto minmax(0, 1.08fr) minmax(0, .92fr); }
.live-summary { min-height: 51px; display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 8px 11px; border-bottom: 1px solid var(--line-soft); }
.strategy-label { min-width: 0; display: flex; flex-direction: column; gap: 3px; }
.strategy-label strong { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 10px; }
.strategy-label span { color: var(--muted); font: 7px ui-monospace, monospace; }
.balance-label { flex: 0 0 auto; display: flex; flex-direction: column; align-items: flex-end; gap: 2px; }
.balance-label strong { font-size: 11px; font-variant-numeric: tabular-nums; }
.balance-label span { color: var(--muted); font: 7px ui-monospace, monospace; }
.chart-panel { min-height: 0; position: relative; padding: 7px 8px 3px; border-bottom: 1px solid var(--line-soft); background: linear-gradient(180deg, rgba(17,23,20,.7), rgba(13,17,16,.7)); }
.chart-head { position: absolute; z-index: 2; top: 8px; left: 10px; right: 10px; display: flex; justify-content: space-between; pointer-events: none; }
.chart-head span { color: var(--muted-2); font: 7px ui-monospace, monospace; letter-spacing: .1em; }
.chart-head strong { font: 8px ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.mini-chart { width: 100%; height: 100%; display: block; }
.feed-panel { min-height: 0; display: flex; flex-direction: column; }
.feed-head, .trade-row { display: grid; grid-template-columns: 1.35fr .72fr .72fr; align-items: center; column-gap: 8px; }
.feed-head { min-height: 23px; padding: 0 10px; color: var(--muted-2); font: 7px ui-monospace, monospace; letter-spacing: .1em; }
.trade-list { min-height: 0; flex: 1; overflow: hidden; }
.trade-row { min-height: 27px; padding: 0 10px; border-top: 1px solid #18201c; animation: rowIn .25s ease; }
.trade-row strong { font-size: 8px; }
.trade-row span { text-align: right; font: 7.5px ui-monospace, monospace; font-variant-numeric: tabular-nums; }
.trade-row .positive { color: var(--green); }
.trade-row .negative { color: var(--red); }
.feed-empty { height: 100%; display: grid; place-items: center; color: var(--muted-2); font: 8px ui-monospace, monospace; }

.state-finished .trade-titlebar { border-bottom-color: currentColor; }
.state-finished.result-positive .trade-titlebar, .state-finished.result-positive .trade-title { color: var(--green); }
.state-finished.result-negative .trade-titlebar, .state-finished.result-negative .trade-title { color: var(--red); }
.state-finished .title-status i { background: currentColor; }
.state-finished .live-shell { position: relative; opacity: .42; }
.finished-overlay { position: absolute; z-index: 5; inset: 0; display: grid; place-items: center; padding: 22px; background: rgba(8, 11, 10, .78); backdrop-filter: blur(2px); }
.finish-card { width: min(260px, 100%); padding: 16px; border: 1px solid var(--line); border-radius: 8px; background: #0d1210; text-align: center; }
.finish-card > span { color: var(--muted); font: 7px ui-monospace, monospace; letter-spacing: .13em; }
.finish-card strong { display: block; margin-top: 7px; font-size: 21px; font-variant-numeric: tabular-nums; }
.finish-card p { margin: 5px 0 0; font: 10px ui-monospace, monospace; }
.finish-card small { display: block; margin-top: 12px; color: var(--muted-2); font-size: 8px; }
.finish-card.positive strong, .finish-card.positive p { color: var(--green); }
.finish-card.negative strong, .finish-card.negative p { color: var(--red); }

.positive { color: var(--green); }
.negative { color: var(--red); }

@keyframes scan { to { transform: rotate(360deg); } }
@keyframes spin { to { transform: rotate(360deg); } }
@keyframes pulse { 50% { opacity: .52; box-shadow: 0 0 0 7px transparent; } }
@keyframes lineIn { to { opacity: 1; transform: translateY(0); } }
@keyframes rowIn { from { opacity: 0; transform: translateY(-5px); } }

@media (max-width: 1380px) {
  .trade-grid { grid-template-columns: repeat(3, minmax(0, 1fr)); }
}
@media (max-width: 980px) {
  .trade-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .overview { align-items: flex-start; flex-direction: column; }
  .overview-metrics { width: 100%; }
  .overview-metrics > span { min-width: 0; flex: 1; }
}
@media (max-width: 640px) {
  .topbar { gap: 14px; }
  .page-title { display: none; }
  .header-status small { display: none; }
  .trade-grid { grid-template-columns: 1fr; }
  .overview-metrics { display: grid; grid-template-columns: 1fr 1fr; }
  .overview-metrics > span:nth-child(3) { border-left: 0; border-top: 1px solid var(--line-soft); }
  .overview-metrics > span:nth-child(4) { border-top: 1px solid var(--line-soft); }
}

@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after { animation-duration: .01ms !important; animation-iteration-count: 1 !important; scroll-behavior: auto !important; }
}
