:root {
  --bg: #0a0e17;
  --surface: #111827;
  --border: #1f2937;
  --text: #e5e7eb;
  --muted: #9ca3af;
  --accent: #11c4d4;
  --accent2: #6366f1;
  --success: #22c55e;
  --danger: #ef4444;
  --warning: #f59e0b;
  --radius: 12px;
  --font: "Segoe UI", system-ui, sans-serif;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
}

.bg-grid {
  position: fixed;
  inset: 0;
  background-image:
    linear-gradient(rgba(17, 196, 212, 0.03) 1px, transparent 1px),
    linear-gradient(90deg, rgba(17, 196, 212, 0.03) 1px, transparent 1px);
  background-size: 40px 40px;
  pointer-events: none;
  z-index: 0;
}

.header {
  position: relative;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 1rem 2rem;
  border-bottom: 1px solid var(--border);
  backdrop-filter: blur(8px);
}

.logo {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-weight: 700;
  font-size: 1.1rem;
}

.logo-icon { color: var(--accent); font-size: 1.4rem; }

.header nav a {
  color: var(--muted);
  text-decoration: none;
  font-size: 0.9rem;
}

.header nav a:hover { color: var(--accent); }

.container {
  position: relative;
  z-index: 1;
  max-width: 1100px;
  margin: 0 auto;
  padding: 2rem;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 1.5rem;
}

.hero { margin-bottom: 1.5rem; }

.badge {
  display: inline-block;
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--accent);
  background: rgba(17, 196, 212, 0.1);
  padding: 0.25rem 0.6rem;
  border-radius: 999px;
  margin-bottom: 0.75rem;
}

.hero h1 { font-size: 1.75rem; margin-bottom: 0.5rem; }

.subtitle { color: var(--muted); margin-bottom: 1.25rem; }

.status {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.75rem 1rem;
  border-radius: 8px;
  margin-bottom: 1rem;
  font-size: 0.9rem;
}

.status .dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: var(--muted);
}

.status.idle { background: rgba(156, 163, 175, 0.1); }
.status.connected { background: rgba(34, 197, 94, 0.1); }
.status.connected .dot { background: var(--success); }
.status.authorized { background: rgba(17, 196, 212, 0.1); }
.status.authorized .dot { background: var(--accent); }
.status.error { background: rgba(239, 68, 68, 0.1); }
.status.error .dot { background: var(--danger); }

.wallet-info {
  display: grid;
  gap: 0.5rem;
  margin-bottom: 1rem;
  padding: 1rem;
  background: rgba(0, 0, 0, 0.2);
  border-radius: 8px;
}

.wallet-info.hidden { display: none; }

.info-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  font-size: 0.85rem;
}

.info-row span { color: var(--muted); }

.info-row code {
  font-family: ui-monospace, monospace;
  font-size: 0.8rem;
  word-break: break-all;
  text-align: right;
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  margin-bottom: 1.25rem;
}

.btn {
  border: none;
  border-radius: 8px;
  padding: 0.65rem 1.2rem;
  font-size: 0.9rem;
  cursor: pointer;
  transition: opacity 0.15s, transform 0.1s;
}

.btn:disabled { opacity: 0.4; cursor: not-allowed; }
.btn:not(:disabled):hover { transform: translateY(-1px); }

.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent2));
  color: #fff;
  font-weight: 600;
}

.btn.secondary {
  background: rgba(99, 102, 241, 0.2);
  color: #c7d2fe;
  border: 1px solid rgba(99, 102, 241, 0.4);
}

.btn.ghost {
  background: transparent;
  color: var(--muted);
  border: 1px solid var(--border);
}

.btn.danger { color: var(--danger); border-color: rgba(239, 68, 68, 0.3); }
.btn.small { padding: 0.4rem 0.8rem; font-size: 0.8rem; }

.log-panel {
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.log-header {
  padding: 0.5rem 1rem;
  background: rgba(0, 0, 0, 0.3);
  font-size: 0.8rem;
  color: var(--muted);
}

#logOutput {
  padding: 1rem;
  font-family: ui-monospace, monospace;
  font-size: 0.78rem;
  max-height: 220px;
  overflow-y: auto;
  white-space: pre-wrap;
  color: #a5f3fc;
}

.features {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(260px, 1fr));
  gap: 1rem;
}

.feature h3 { font-size: 0.95rem; margin-bottom: 0.75rem; }
.feature ul, .feature ol { padding-left: 1.2rem; color: var(--muted); font-size: 0.85rem; }
.feature li { margin-bottom: 0.35rem; }
.feature p { font-size: 0.85rem; color: var(--muted); margin-bottom: 0.5rem; }

.deeplink {
  display: block;
  font-size: 0.72rem;
  word-break: break-all;
  padding: 0.5rem;
  background: rgba(0, 0, 0, 0.3);
  border-radius: 6px;
  margin-bottom: 0.5rem;
}

.footer {
  position: relative;
  z-index: 1;
  text-align: center;
  padding: 2rem;
  color: var(--muted);
  font-size: 0.8rem;
}

.balance-box {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: 1rem 1.25rem;
  background: rgba(0, 0, 0, 0.25);
  border: 1px solid var(--border);
  border-radius: 10px;
  margin-bottom: 1.25rem;
}

.balance-main { display: flex; align-items: baseline; gap: 0.5rem; flex-wrap: wrap; }
.balance-label { color: var(--muted); font-size: 0.85rem; width: 100%; }
.balance-value { font-size: 1.75rem; font-weight: 700; color: var(--accent); }
.balance-symbol { color: var(--muted); font-size: 0.95rem; }

.transfer-form {
  display: grid;
  gap: 0.85rem;
  margin-bottom: 0.75rem;
}

.transfer-form label {
  display: grid;
  gap: 0.35rem;
  font-size: 0.85rem;
  color: var(--muted);
}

.transfer-form input {
  background: #0a1020;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 0.65rem 0.75rem;
  color: var(--text);
  font: inherit;
}

.transfer-actions { display: flex; gap: 0.75rem; flex-wrap: wrap; }

.hint {
  font-size: 0.8rem;
  color: var(--muted);
}

.provider-hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-bottom: 1rem;
  padding: 0.65rem 0.85rem;
  background: rgba(17, 196, 212, 0.06);
  border: 1px solid rgba(17, 196, 212, 0.15);
  border-radius: 8px;
}

.imtoken-card {
  margin-bottom: 1.25rem;
  padding: 1.25rem;
  border-radius: 12px;
  border: 1px solid rgba(56, 189, 248, 0.35);
  background: linear-gradient(135deg, rgba(56, 189, 248, 0.1), rgba(99, 102, 241, 0.06));
}

.imtoken-card.imtoken-ready {
  border-color: rgba(56, 189, 248, 0.65);
  box-shadow: 0 0 24px rgba(56, 189, 248, 0.15);
}

.imtoken-header {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.imtoken-icon { font-size: 1.75rem; line-height: 1; }

.imtoken-header strong { display: block; margin-bottom: 0.25rem; }

.imtoken-header p {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
}

.btn.imtoken-btn {
  width: 100%;
  background: linear-gradient(135deg, #22d3ee, #6366f1);
  color: #fff;
  border: none;
}

.imtoken-hint {
  margin-top: 0.75rem;
  font-size: 0.8rem;
  color: var(--muted);
}

.network-tabs {
  display: flex;
  gap: 0.5rem;
  margin-bottom: 1rem;
}

.network-tab {
  flex: 1;
  padding: 0.55rem 0.75rem;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: rgba(0, 0, 0, 0.25);
  color: var(--muted);
  cursor: pointer;
  font: inherit;
}

.network-tab.active {
  color: var(--text);
  border-color: rgba(56, 189, 248, 0.6);
  background: rgba(56, 189, 248, 0.12);
}

.network-tab.tron-active {
  border-color: rgba(255, 0, 122, 0.55);
  background: rgba(255, 0, 122, 0.1);
}

.metamask-card {
  margin-bottom: 1.25rem;
  padding: 1.25rem;
  border-radius: 12px;
  border: 1px solid rgba(245, 133, 66, 0.35);
  background: linear-gradient(135deg, rgba(245, 133, 66, 0.08), rgba(227, 118, 20, 0.04));
}

.metamask-card.metamask-ready {
  border-color: rgba(245, 133, 66, 0.6);
  box-shadow: 0 0 24px rgba(245, 133, 66, 0.12);
}

.metamask-header {
  display: flex;
  gap: 0.75rem;
  align-items: flex-start;
  margin-bottom: 1rem;
}

.metamask-icon { font-size: 1.75rem; line-height: 1; }

.metamask-header strong { display: block; margin-bottom: 0.25rem; }

.metamask-header p {
  font-size: 0.82rem;
  color: var(--muted);
  margin: 0;
}

.btn.metamask-btn {
  width: 100%;
  background: linear-gradient(135deg, #f6851b, #e2761b);
  color: #fff;
  font-weight: 600;
  border: none;
}

.btn.metamask-btn:hover:not(:disabled) {
  filter: brightness(1.08);
}

.btn.metamask-btn:disabled {
  opacity: 0.6;
  background: #555;
}

.metamask-hint {
  font-size: 0.8rem;
  color: var(--muted);
  margin-top: 0.65rem;
  margin-bottom: 0;
}

.delegate-block {
  margin-top: 1rem;
  padding: 0.85rem;
  border-radius: 8px;
  border: 1px dashed rgba(245, 133, 66, 0.4);
  background: rgba(0, 0, 0, 0.2);
}

.delegate-check {
  display: flex;
  gap: 0.5rem;
  align-items: flex-start;
  font-size: 0.85rem;
  margin-bottom: 0.75rem;
  cursor: pointer;
}

.delegate-key-label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
}

.delegate-key-label input {
  width: 100%;
  margin-top: 0.35rem;
  padding: 0.5rem 0.65rem;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: monospace;
  font-size: 0.8rem;
}

.delegate-note {
  font-size: 0.75rem;
  color: var(--muted);
  margin: 0.5rem 0 0;
  line-height: 1.45;
}

.backend-session {
  margin-bottom: 1.25rem;
  padding: 1rem 1.25rem;
  background: rgba(34, 197, 94, 0.06);
  border: 1px solid rgba(34, 197, 94, 0.25);
  border-radius: 10px;
}

.backend-session h3 {
  font-size: 0.95rem;
  margin-bottom: 0.75rem;
  color: #4ade80;
}

.backend-session code {
  font-size: 0.72rem;
  word-break: break-all;
}

.hero h2 { font-size: 1.25rem; margin-bottom: 0.35rem; }

@media (max-width: 600px) {
  .container { padding: 1rem; }
  .actions { flex-direction: column; }
  .btn { width: 100%; }
}
