:root {
  --bg: #0a0e1a;
  --bg-soft: #12182a;
  --card: #1a2238;
  --text: #e7ecff;
  --muted: #9aa8d6;
  --primary: #5b8cff;
  --success: #20c997;
  --danger: #ff6b6b;
  --border: #2a3556;
}

* {
  box-sizing: border-box;
  -webkit-tap-highlight-color: transparent;
}

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "PingFang SC", "Segoe UI", Roboto, Arial, sans-serif;
  min-height: 100%;
}

body {
  display: flex;
  flex-direction: column;
  max-width: 640px;
  margin: 0 auto;
  padding-bottom: calc(84px + env(safe-area-inset-bottom));
}

.theme-light {
  --bg: #f5f7ff;
  --bg-soft: #eef2ff;
  --card: #ffffff;
  --text: #131a2c;
  --muted: #556080;
  --primary: #4c6fff;
  --success: #0ca678;
  --danger: #e03131;
  --border: #d7ddf1;
}

.hidden { display: none !important; }

.app-header {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  justify-content: space-between;
  align-items: center;
  background: rgba(10, 14, 26, 0.92);
  backdrop-filter: blur(8px);
  border-bottom: 1px solid var(--border);
  padding: calc(12px + env(safe-area-inset-top)) 14px 12px;
}

.theme-light .app-header { background: rgba(245, 247, 255, 0.92); }

.header-left { display: flex; align-items: center; gap: 8px; }
.app-logo { font-size: 1.2rem; }
.app-title { font-weight: 700; font-size: 1.06rem; }
.header-right { display: flex; align-items: center; gap: 8px; }

.status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  display: inline-block;
  background: var(--danger);
}
.status-dot.online { background: var(--success); }

.icon-btn {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  min-width: 36px;
  height: 36px;
  font-size: 16px;
}

.lang-menu {
  position: fixed;
  right: 12px;
  top: 64px;
  z-index: 60;
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 12px;
  box-shadow: 0 10px 25px rgba(0, 0, 0, 0.2);
  overflow: hidden;
}

.lang-menu button {
  width: 100%;
  text-align: left;
  background: transparent;
  color: var(--text);
  border: 0;
  border-bottom: 1px solid var(--border);
  padding: 10px 14px;
}

.lang-menu button:last-child { border-bottom: 0; }

.app-main {
  padding: 14px;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.tab-section { display: none; }
.tab-section.active { display: block; }

.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.section-header h2 {
  margin: 0;
  font-size: 1.08rem;
}

.last-updated {
  color: var(--muted);
  font-size: 0.8rem;
}

.search-bar input,
.calc-input,
.calc-select,
.settings-select {
  width: 100%;
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 12px;
  padding: 10px 12px;
  font-size: 15px;
}

.currency-filter {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 8px;
  margin: 10px 0 14px;
}

.filter-btn,
.primary-btn,
.toggle-btn,
.danger-btn,
.swap-btn,
.formula-tab {
  border: 1px solid var(--border);
  background: var(--card);
  color: var(--text);
  border-radius: 10px;
  padding: 10px;
  font-size: 0.92rem;
}

.filter-btn.active,
.nav-btn.active,
.formula-tab.active,
.primary-btn {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
}

.coin-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.coin-item {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
}

.coin-top { display: flex; align-items: center; gap: 10px; }
.coin-rank {
  min-width: 28px;
  height: 28px;
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.78rem;
  background: var(--bg-soft);
}
.coin-name strong { display: block; }
.coin-name span { color: var(--muted); font-size: 0.84rem; }
.coin-price { text-align: right; font-weight: 700; }
.coin-change { font-size: 0.84rem; }
.coin-change.up { color: var(--success); }
.coin-change.down { color: var(--danger); }

.coin-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
}

.coin-btn {
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text);
  border-radius: 8px;
  padding: 6px 10px;
}

.calc-card,
.math-card,
.settings-list {
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 12px;
  margin-bottom: 12px;
}

.calc-label { display: block; margin-bottom: 6px; color: var(--muted); }
.calc-input-row {
  display: grid;
  grid-template-columns: 1fr 120px;
  gap: 8px;
  margin-bottom: 8px;
}

.swap-btn-wrap { text-align: center; margin: 2px 0 8px; }
.swap-btn { min-width: 42px; }
.result-input { font-weight: 700; }
.primary-btn { width: 100%; margin-top: 8px; }

.formula-tabs {
  display: flex;
  gap: 6px;
  flex-wrap: wrap;
  margin-bottom: 10px;
}

.formula-display {
  background: var(--bg-soft);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px;
  min-height: 54px;
  margin-bottom: 10px;
}

.formula-input-group {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.formula-input-group input {
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  border-radius: 10px;
  padding: 8px;
}

.formula-result {
  margin-top: 10px;
  color: var(--primary);
  font-weight: 700;
}

.settings-item {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
}

.settings-about {
  text-align: center;
  color: var(--muted);
  padding-top: 10px;
}

.about-logo { font-size: 1.6rem; }

.bottom-nav {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: 0;
  width: 100%;
  max-width: 640px;
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: rgba(12, 18, 36, 0.96);
  backdrop-filter: blur(8px);
  border-top: 1px solid var(--border);
  padding: 8px 8px calc(8px + env(safe-area-inset-bottom));
  z-index: 40;
}

.theme-light .bottom-nav { background: rgba(245, 247, 255, 0.96); }

.nav-btn {
  border: 0;
  background: transparent;
  color: var(--muted);
  border-radius: 10px;
  padding: 8px 4px;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
}

.nav-btn.active { color: #fff; }
.theme-light .nav-btn.active { color: #fff; }
.nav-icon { font-size: 1rem; }
.nav-label { font-size: 0.75rem; }

.skeleton-loader { display: grid; gap: 10px; }
.skeleton-item {
  height: 74px;
  border-radius: 12px;
  background: linear-gradient(90deg, var(--bg-soft), var(--card), var(--bg-soft));
  background-size: 200% 100%;
  animation: pulse 1.4s linear infinite;
}
@keyframes pulse {
  from { background-position: 200% 0; }
  to { background-position: -200% 0; }
}

.toast {
  position: fixed;
  left: 50%;
  transform: translateX(-50%);
  bottom: calc(80px + env(safe-area-inset-bottom));
  background: var(--card);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 10px 14px;
  z-index: 80;
}

.modal {
  position: fixed;
  inset: 0;
  z-index: 90;
}

.modal-overlay {
  position: absolute;
  inset: 0;
  background: rgba(0, 0, 0, 0.42);
}

.modal-content {
  position: absolute;
  left: 50%;
  top: 50%;
  transform: translate(-50%, -50%);
  width: min(92vw, 480px);
  background: var(--card);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 14px;
}

.modal-close {
  border: 0;
  background: transparent;
  color: var(--text);
  font-size: 18px;
  position: absolute;
  top: 8px;
  right: 8px;
}

@media (max-width: 420px) {
  .calc-input-row { grid-template-columns: 1fr 100px; }
}
