:root {
  --bg: #0b1020;
  --bg-elevated: #121a2f;
  --bg-soft: #18233c;
  --panel: #0f1629;
  --line: rgba(226, 232, 240, 0.08);
  --line-strong: rgba(226, 232, 240, 0.14);
  --text: #eef2ff;
  --text-muted: #93a0b8;
  --text-faint: #6b7893;
  --buy: #1ecf8e;
  --buy-soft: rgba(30, 207, 142, 0.12);
  --buy-ink: #042816;
  --sell: #ff5d5d;
  --sell-soft: rgba(255, 93, 93, 0.12);
  --sell-ink: #3a0b0b;
  --accent: #7dd3fc;
  --accent-soft: rgba(125, 211, 252, 0.12);
  --warn: #f5c451;
  --radius: 16px;
  --radius-sm: 10px;
  --shadow: 0 18px 50px rgba(0, 0, 0, 0.35);
  --safe-bottom: env(safe-area-inset-bottom, 0px);
  --safe-top: env(safe-area-inset-top, 0px);
  --font: "Manrope", ui-sans-serif, system-ui, sans-serif;
  --mono: "IBM Plex Mono", ui-monospace, SFMono-Regular, Menlo, monospace;
  color-scheme: dark;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  min-height: 100%;
  background:
    radial-gradient(900px 420px at 8% -10%, rgba(125, 211, 252, 0.08), transparent 55%),
    radial-gradient(700px 380px at 100% 0%, rgba(30, 207, 142, 0.06), transparent 50%),
    linear-gradient(180deg, #0d1426 0%, var(--bg) 42%, #080d18 100%);
  color: var(--text);
  font-family: var(--font);
  -webkit-font-smoothing: antialiased;
  text-rendering: optimizeLegibility;
}

body {
  min-height: 100dvh;
}

button,
input {
  font: inherit;
}

.mono {
  font-family: var(--mono);
  font-variant-numeric: tabular-nums;
}

.app {
  width: min(1180px, 100%);
  margin: 0 auto;
  min-height: 100dvh;
  padding: calc(16px + var(--safe-top)) 16px calc(88px + var(--safe-bottom));
  display: flex;
  flex-direction: column;
  gap: 16px;
  contain: layout style;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.brand-lockup {
  display: flex;
  align-items: center;
  gap: 12px;
}

.mark {
  width: 36px;
  height: 36px;
  border-radius: 11px;
  background:
    linear-gradient(145deg, rgba(125, 211, 252, 0.95), rgba(30, 207, 142, 0.75));
  position: relative;
}

.mark::after {
  content: "";
  position: absolute;
  inset: 9px;
  border-radius: 4px;
  border: 2px solid rgba(8, 13, 24, 0.7);
  border-right-color: transparent;
  border-bottom-color: transparent;
  transform: rotate(45deg);
}

.brand {
  margin: 0;
  font-size: 1.35rem;
  font-weight: 800;
  letter-spacing: -0.04em;
  line-height: 1;
}

.brand-sub {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 500;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 8px;
}

.status-pill {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  padding: 8px 12px;
  border-radius: 999px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03);
  color: var(--text-muted);
  font-size: 0.78rem;
  font-weight: 600;
}

.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--buy);
  box-shadow: 0 0 0 4px var(--buy-soft);
  animation: pulse 2.2s ease-in-out infinite;
}

@keyframes pulse {
  0%,
  100% {
    opacity: 1;
  }
  50% {
    opacity: 0.55;
  }
}

.metrics {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.metric {
  background: rgba(15, 22, 41, 0.88);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 14px 14px 12px;
  backdrop-filter: blur(8px);
}

.metric-label {
  margin: 0;
  color: var(--text-faint);
  font-size: 0.72rem;
  font-weight: 600;
  letter-spacing: 0.06em;
  text-transform: uppercase;
}

.metric-value {
  margin: 8px 0 0;
  font-size: 1.2rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.metric-value.up {
  color: var(--buy);
}

.metric-value.down {
  color: var(--sell);
}

.workspace {
  display: flex;
  flex-direction: column;
  gap: 14px;
  flex: 1;
}

.rail {
  position: fixed;
  left: 50%;
  bottom: calc(12px + var(--safe-bottom));
  transform: translateX(-50%);
  width: min(420px, calc(100% - 24px));
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 6px;
  padding: 6px;
  border-radius: 18px;
  border: 1px solid var(--line-strong);
  background: rgba(12, 18, 34, 0.92);
  backdrop-filter: blur(16px);
  z-index: 15;
}

.nav-item {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: 12px;
  padding: 12px 8px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  font-size: 0.78rem;
  font-weight: 700;
  cursor: pointer;
  transition: background 160ms ease, color 160ms ease;
}

.nav-item.active {
  background: rgba(238, 242, 255, 0.08);
  color: var(--text);
}

.nav-icon {
  font-size: 0.95rem;
  line-height: 1;
  opacity: 0.85;
}

.main {
  min-width: 0;
}

.panel {
  display: none;
}

.panel.active {
  display: block;
  animation: enter 240ms ease;
}

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

.grid-2 {
  display: grid;
  gap: 14px;
}

.stack {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.card {
  background: rgba(15, 22, 41, 0.92);
  border: 1px solid var(--line);
  border-radius: calc(var(--radius) + 2px);
  padding: 16px;
}

.card-head {
  display: flex;
  align-items: baseline;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.card-head h2 {
  margin: 0;
  font-size: 0.95rem;
  font-weight: 700;
  letter-spacing: -0.01em;
}

.hint {
  margin: 0;
  color: var(--text-faint);
  font-size: 0.78rem;
  font-weight: 500;
}

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

.coin-chip {
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
  color: var(--text);
  border-radius: 12px;
  padding: 12px 10px;
  text-align: left;
  cursor: pointer;
  transition: border-color 140ms ease, background 140ms ease, transform 140ms ease;
  content-visibility: auto;
}

.coin-chip:hover {
  border-color: var(--line-strong);
}

.coin-chip.active {
  border-color: rgba(125, 211, 252, 0.45);
  background: var(--accent-soft);
}

.coin-chip strong {
  display: block;
  font-size: 0.92rem;
  font-weight: 750;
}

.coin-chip span {
  display: block;
  margin-top: 3px;
  color: var(--text-muted);
  font-size: 0.72rem;
}

.quote {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: flex-end;
  margin-top: 16px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
}

.quote-name {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 750;
  letter-spacing: -0.02em;
}

.quote-pair {
  margin: 4px 0 0;
  color: var(--text-muted);
  font-size: 0.82rem;
}

.quote-right {
  text-align: right;
}

.quote-last {
  margin: 0;
  font-size: 1.55rem;
  font-weight: 600;
  letter-spacing: -0.03em;
}

.quote-chg {
  margin: 6px 0 0;
  font-size: 0.84rem;
  font-weight: 700;
}

.quote-chg.up,
.timer-pnl.up,
.result-pnl.up,
.ai-action.up,
.row-item .up {
  color: var(--buy);
}

.quote-chg.down,
.timer-pnl.down,
.result-pnl.down,
.ai-action.down,
.row-item .down {
  color: var(--sell);
}

.field {
  margin-bottom: 16px;
}

.field-row {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 8px;
}

.field-label {
  color: var(--text-muted);
  font-size: 0.8rem;
  font-weight: 600;
}

.field-hint {
  color: var(--text-faint);
  font-size: 0.78rem;
}

.seg {
  display: grid;
  grid-template-columns: repeat(5, minmax(0, 1fr));
  gap: 6px;
  padding: 4px;
  border-radius: 12px;
  background: rgba(255, 255, 255, 0.03);
  border: 1px solid var(--line);
}

.duration-chip {
  border: 0;
  background: transparent;
  color: var(--text-muted);
  border-radius: 9px;
  padding: 10px 4px;
  font-weight: 700;
  font-size: 0.82rem;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease;
}

.duration-chip.active {
  background: rgba(238, 242, 255, 0.1);
  color: var(--text);
}

.input-shell {
  display: flex;
  align-items: center;
  gap: 8px;
  border: 1px solid var(--line-strong);
  background: rgba(8, 13, 24, 0.55);
  border-radius: 12px;
  padding: 12px 14px;
  transition: border-color 140ms ease;
}

.input-shell:focus-within {
  border-color: rgba(125, 211, 252, 0.45);
}

.input-prefix {
  color: var(--text-faint);
  font-family: var(--mono);
  font-weight: 600;
  font-size: 1.1rem;
}

.input-shell input {
  flex: 1;
  width: 100%;
  border: 0;
  outline: none;
  background: transparent;
  color: var(--text);
  font-family: var(--mono);
  font-size: 1.35rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}

.quick-row {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-top: 10px;
}

.quick {
  border: 1px solid var(--line);
  background: transparent;
  color: var(--text-muted);
  border-radius: 999px;
  padding: 7px 11px;
  font-size: 0.75rem;
  font-weight: 650;
  cursor: pointer;
  transition: background 140ms ease, color 140ms ease, border-color 140ms ease;
}

.quick:hover {
  color: var(--text);
  border-color: var(--line-strong);
}

.estimate {
  margin: 0 0 14px;
  min-height: 2.4em;
  color: var(--text-muted);
  font-size: 0.86rem;
  line-height: 1.45;
}

.action-row {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
}

.btn {
  border: 0;
  border-radius: 12px;
  padding: 12px 14px;
  font-weight: 700;
  cursor: pointer;
  transition: transform 120ms ease, opacity 120ms ease, filter 120ms ease;
}

.btn:active {
  transform: scale(0.985);
}

.btn:disabled {
  opacity: 0.45;
  cursor: not-allowed;
}

.btn-ghost {
  background: rgba(255, 255, 255, 0.03);
  color: var(--text);
  border: 1px solid var(--line);
}

.btn-primary {
  background: var(--text);
  color: #0b1020;
}

.btn-buy,
.btn-sell {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 4px;
  padding: 14px;
  text-align: left;
}

.btn-buy {
  background: var(--buy);
  color: var(--buy-ink);
}

.btn-sell {
  background: var(--sell);
  color: var(--sell-ink);
}

.btn-title {
  font-size: 1rem;
  font-weight: 800;
}

.btn-sub {
  font-size: 0.72rem;
  font-weight: 600;
  opacity: 0.8;
}

.fineprint {
  margin: 14px 0 0;
  color: var(--text-faint);
  font-size: 0.74rem;
  line-height: 1.45;
}

.active-trades {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.timer-card {
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 12px;
  background: rgba(8, 13, 24, 0.35);
}

.timer-top {
  display: flex;
  justify-content: space-between;
  gap: 10px;
  align-items: baseline;
}

.timer-title {
  margin: 0;
  font-size: 0.9rem;
  font-weight: 700;
}

.timer-clock {
  margin: 0;
  font-family: var(--mono);
  font-size: 1.15rem;
  font-weight: 600;
}

.timer-meta {
  margin: 6px 0 8px;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.timer-pnl {
  margin: 0 0 10px;
  font-family: var(--mono);
  font-size: 0.95rem;
  font-weight: 600;
}

.timer-bar {
  height: 3px;
  border-radius: 99px;
  background: rgba(255, 255, 255, 0.06);
  overflow: hidden;
  margin-bottom: 10px;
}

.timer-bar > span {
  display: block;
  height: 100%;
  width: 100%;
  transform-origin: left center;
  background: linear-gradient(90deg, var(--accent), var(--buy));
  will-change: transform;
}

.timer-actions {
  display: flex;
  justify-content: flex-end;
}

.timer-actions .btn {
  padding: 7px 10px;
  font-size: 0.75rem;
}

.table {
  display: flex;
  flex-direction: column;
}

.row-item {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px 12px;
  padding: 14px 2px;
  border-bottom: 1px solid var(--line);
}

.row-item:last-child {
  border-bottom: 0;
}

.row-title {
  margin: 0;
  font-weight: 700;
  font-size: 0.92rem;
}

.row-sub {
  margin: 3px 0 0;
  color: var(--text-muted);
  font-size: 0.78rem;
}

.row-value {
  margin: 0;
  text-align: right;
  font-family: var(--mono);
  font-weight: 600;
  font-size: 0.9rem;
}

.row-side {
  margin: 0 0 4px;
  text-align: right;
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.04em;
}

.row-side.buy {
  color: var(--buy);
}

.row-side.sell {
  color: var(--sell);
}

.empty {
  margin: 0;
  color: var(--text-muted);
  padding: 18px 4px 8px;
  line-height: 1.5;
  font-size: 0.9rem;
}

.overlay {
  position: fixed;
  inset: 0;
  background: rgba(4, 8, 16, 0.62);
  backdrop-filter: blur(6px);
  z-index: 30;
}

.drawer {
  position: fixed;
  left: 50%;
  bottom: 0;
  transform: translateX(-50%) translateY(110%);
  width: min(440px, 100%);
  z-index: 40;
  transition: transform 280ms cubic-bezier(0.22, 1, 0.36, 1);
}

.drawer.open {
  transform: translateX(-50%) translateY(0);
}

.drawer-inner {
  margin: 0;
  border-radius: 22px 22px 0 0;
  border: 1px solid var(--line-strong);
  border-bottom: 0;
  background: #121a2f;
  padding: 22px 20px calc(20px + var(--safe-bottom));
  box-shadow: var(--shadow);
}

.drawer-kicker {
  margin: 0;
  color: var(--text-faint);
  font-size: 0.72rem;
  font-weight: 700;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.drawer-title {
  margin: 8px 0 14px;
  font-size: 1.45rem;
  font-weight: 800;
  letter-spacing: -0.03em;
}

.facts {
  margin: 0 0 18px;
  display: grid;
  gap: 0;
}

.facts div {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  padding: 12px 0;
  border-bottom: 1px solid var(--line);
}

.facts dt {
  color: var(--text-muted);
  font-size: 0.86rem;
}

.facts dd {
  margin: 0;
  font-weight: 700;
  font-size: 0.9rem;
}

.drawer-actions {
  display: grid;
  gap: 8px;
}

.drawer-actions .btn {
  width: 100%;
  justify-content: center;
  align-items: center;
  text-align: center;
}

.drawer-actions .btn-buy,
.drawer-actions .btn-sell {
  align-items: center;
}

.result-pnl {
  margin: 0 0 12px;
  font-size: 2rem;
  font-weight: 650;
  letter-spacing: -0.03em;
}

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(84px + var(--safe-bottom));
  transform: translateX(-50%) translateY(12px);
  width: min(420px, calc(100% - 24px));
  background: var(--text);
  color: #0b1020;
  border-radius: 12px;
  padding: 12px 14px;
  font-size: 0.88rem;
  font-weight: 700;
  z-index: 50;
  opacity: 0;
  pointer-events: none;
  transition: opacity 160ms ease, transform 160ms ease;
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.error {
  background: var(--sell);
  color: var(--sell-ink);
}

.ai-blurb {
  margin: 0 0 16px;
  color: var(--text-muted);
  font-size: 0.88rem;
  line-height: 1.45;
}

.ai-blurb + .field,
.field + .field {
  margin-top: 12px;
}

.select {
  width: 100%;
  appearance: none;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.03)
    url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath fill='%2394a3b8' d='M1 1l5 5 5-5'/%3E%3C/svg%3E")
    right 14px center / 12px no-repeat;
  color: var(--text);
  border-radius: 12px;
  padding: 12px 36px 12px 14px;
  font: inherit;
  font-weight: 600;
}

.select:focus {
  outline: none;
  border-color: rgba(125, 211, 252, 0.45);
}

.toggle-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
  margin: 16px 0 4px;
  cursor: pointer;
}

.toggle-row input {
  margin-top: 4px;
  width: 18px;
  height: 18px;
  accent-color: #7dd3fc;
}

.toggle-row strong {
  display: block;
  font-size: 0.92rem;
}

.toggle-row small {
  display: block;
  margin-top: 2px;
  color: var(--text-faint);
  font-size: 0.78rem;
}

.ai-limits {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 10px;
  margin-top: 14px;
}

.ai-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 16px;
}

.ai-actions .btn {
  flex: 1 1 140px;
}

.ai-last {
  margin-bottom: 14px;
  padding: 12px 14px;
  border-radius: 12px;
  border: 1px solid var(--line);
  background: rgba(255, 255, 255, 0.02);
}

.ai-last .muted {
  margin: 0;
  color: var(--text-faint);
  font-size: 0.85rem;
}

.ai-last .ai-action {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 750;
  letter-spacing: -0.01em;
}

.ai-last .ai-reason {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.84rem;
  line-height: 1.4;
}

.ai-log .row-item {
  align-items: flex-start;
}

.fineprint a {
  color: #7dd3fc;
  text-decoration: none;
}

.fineprint a:hover {
  text-decoration: underline;
}

@media (min-width: 720px) {
  .app {
    padding: 24px 24px 28px;
    gap: 18px;
  }

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

  .metric-value {
    font-size: 1.35rem;
  }

  .workspace {
    display: grid;
    grid-template-columns: 200px minmax(0, 1fr);
    gap: 18px;
    align-items: start;
  }

  .rail {
    position: sticky;
    top: 24px;
    left: auto;
    bottom: auto;
    transform: none;
    width: auto;
    display: flex;
    flex-direction: column;
    gap: 6px;
    padding: 8px;
    border-radius: 16px;
    background: rgba(15, 22, 41, 0.92);
  }

  .nav-item {
    flex-direction: row;
    justify-content: flex-start;
    gap: 10px;
    padding: 12px 12px;
    font-size: 0.88rem;
  }

  .grid-2 {
    grid-template-columns: 1.05fr 0.95fr;
    align-items: start;
  }

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

  .drawer {
    top: 50%;
    bottom: auto;
    width: min(420px, calc(100% - 32px));
    transform: translate(-50%, -46%) scale(0.98);
    opacity: 0;
    pointer-events: none;
    transition: transform 220ms ease, opacity 220ms ease;
  }

  .drawer.open {
    transform: translate(-50%, -50%) scale(1);
    opacity: 1;
    pointer-events: auto;
  }

  .drawer-inner {
    border-radius: 18px;
    border-bottom: 1px solid var(--line-strong);
    padding: 22px;
  }

  .toast {
    bottom: 28px;
  }
}

@media (min-width: 1100px) {
  .app {
    padding-top: 28px;
  }

  .brand {
    font-size: 1.5rem;
  }

  .quote-last {
    font-size: 1.75rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    animation: none !important;
    transition: none !important;
  }
}
