:root {
  --bg: #0a0e1a;
  --bg2: #0f1524;
  --surface: #151c2e;
  --surface2: #1c2540;
  --border: #26304d;
  --gold: #f5c542;
  --gold-dim: #b8912f;
  --text: #e8ecf5;
  --muted: #7c88a8;
  --green: #34d399;
  --red: #f87171;
}

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

body {
  font-family: 'Vazirmatn', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}

.app { position: relative; min-height: 100vh; overflow-x: hidden; }

.bg-glow {
  position: fixed; inset: 0; z-index: 0; pointer-events: none;
  background:
    radial-gradient(700px circle at 85% -5%, rgba(245,197,66,0.10), transparent 60%),
    radial-gradient(600px circle at 10% 100%, rgba(52,211,153,0.06), transparent 55%),
    linear-gradient(180deg, var(--bg) 0%, var(--bg2) 100%);
}

/* ---- Header ---- */
.header {
  position: sticky; top: 0; z-index: 20;
  background: rgba(10,14,26,0.82);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--border);
  padding: 12px 16px 10px;
}
.header-inner {
  display: flex; justify-content: space-between; align-items: center;
  gap: 12px; max-width: 1400px; margin: 0 auto; flex-wrap: wrap;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand-emoji { font-size: 34px; filter: drop-shadow(0 0 10px rgba(245,197,66,0.4)); }
.brand-title {
  font-weight: 900; font-size: 24px; letter-spacing: -0.5px;
  background: linear-gradient(90deg, var(--gold), #ffe9a3);
  -webkit-background-clip: text; background-clip: text; -webkit-text-fill-color: transparent;
}
.brand-sub { font-size: 12px; color: var(--muted); font-weight: 300; margin-top: 1px; }

.header-ctrls { display: flex; align-items: center; gap: 10px; }

.status-pill {
  display: flex; align-items: center; gap: 7px;
  padding: 6px 12px; border-radius: 999px; font-size: 13px; font-weight: 600;
  border: 1px solid var(--border);
}
.status-pill .dot { width: 8px; height: 8px; border-radius: 50%; }
.st-ok .dot { background: var(--green); box-shadow: 0 0 8px var(--green); animation: pulse 1.6s infinite; }
.st-ok { color: var(--green); }
.st-ref .dot { background: var(--gold); animation: pulse 0.8s infinite; }
.st-ref { color: var(--gold); }
.st-off .dot { background: var(--red); }
.st-off { color: var(--red); }
.st-load .dot { background: var(--muted); animation: pulse 1s infinite; }
.st-load { color: var(--muted); }
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: 0.3; } }

.countdown {
  display: flex; flex-direction: column; align-items: center;
  min-width: 40px; padding: 3px 8px; border-radius: 10px;
  background: var(--surface); border: 1px solid var(--border);
}
.cd-num { font-weight: 800; font-size: 18px; color: var(--gold); line-height: 1; }
.cd-lbl { font-size: 9px; color: var(--muted); }

.gear {
  background: var(--surface); border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; font-size: 18px; cursor: pointer;
  transition: transform 0.3s, background 0.2s;
}
.gear:hover { transform: rotate(60deg); background: var(--surface2); }

.toggle-row {
  display: flex; gap: 10px; align-items: center; flex-wrap: wrap;
  max-width: 1400px; margin: 10px auto 0;
}
.seg { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 10px; padding: 3px; gap: 2px; }
.seg-btn {
  background: transparent; border: none; color: var(--muted); cursor: pointer;
  padding: 6px 14px; border-radius: 8px; font-size: 13px; font-weight: 600;
  font-family: inherit; transition: all 0.15s;
}
.seg-btn.active { background: var(--gold); color: #1a1300; }
.seg-btn:hover:not(.active) { color: var(--text); }

.chip {
  background: var(--surface); border: 1px solid var(--border); color: var(--muted);
  padding: 7px 14px; border-radius: 10px; font-size: 13px; font-weight: 600;
  cursor: pointer; font-family: inherit; transition: all 0.15s;
}
.chip.on { border-color: var(--gold-dim); color: var(--gold); }

.search-wrap { flex: 1; min-width: 160px; }
.search {
  width: 100%; background: var(--surface); border: 1px solid var(--border);
  color: var(--text); padding: 8px 14px; border-radius: 10px; font-size: 14px;
  font-family: inherit; outline: none; transition: border-color 0.15s;
}
.search:focus { border-color: var(--gold-dim); }
.search::placeholder { color: var(--muted); }

/* ---- Main ---- */
.main { position: relative; z-index: 1; max-width: 1400px; margin: 0 auto; padding: 16px; }

.rate-banner {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap;
  background: linear-gradient(90deg, rgba(245,197,66,0.10), transparent);
  border: 1px solid var(--gold-dim); border-radius: 12px;
  padding: 10px 16px; margin-bottom: 20px; font-size: 14px; color: var(--muted);
}
.rate-banner strong { color: var(--gold); font-weight: 800; }
.edit-rate {
  margin-inline-start: auto; background: var(--surface2); border: 1px solid var(--border);
  color: var(--gold); padding: 4px 12px; border-radius: 8px; font-size: 12px;
  cursor: pointer; font-family: inherit;
}

.section { margin-bottom: 28px; animation: fadeUp 0.4s ease both; }
@keyframes fadeUp { from { opacity: 0; transform: translateY(12px); } to { opacity: 1; transform: none; } }

.section-title {
  display: flex; align-items: center; gap: 8px;
  font-size: 17px; font-weight: 800; margin-bottom: 12px; color: var(--text);
}
.sec-icon { font-size: 20px; }
.sec-count {
  font-size: 12px; font-weight: 600; color: var(--muted);
  background: var(--surface); border: 1px solid var(--border);
  padding: 1px 8px; border-radius: 999px;
}

.grid {
  display: grid; gap: 12px;
  grid-template-columns: repeat(4, 1fr);
}
@media (max-width: 1024px) { .grid { grid-template-columns: repeat(3, 1fr); } }
@media (max-width: 720px) { .grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 440px) { .grid { grid-template-columns: 1fr; } }

/* ---- Card ---- */
.card {
  position: relative;
  background: linear-gradient(160deg, var(--surface), var(--bg2));
  border: 1px solid var(--border); border-radius: 16px;
  padding: 14px; transition: border-color 0.2s, transform 0.2s, box-shadow 0.2s;
  overflow: hidden;
}
.card:hover { border-color: var(--gold-dim); transform: translateY(-2px); box-shadow: 0 8px 24px rgba(0,0,0,0.4); }
.card.flash-up { animation: flashUp 0.7s ease; }
.card.flash-down { animation: flashDown 0.7s ease; }
@keyframes flashUp { 0% { background: linear-gradient(160deg, rgba(52,211,153,0.25), var(--bg2)); } 100% {} }
@keyframes flashDown { 0% { background: linear-gradient(160deg, rgba(248,113,113,0.25), var(--bg2)); } 100% {} }

.badge-est {
  position: absolute; top: 10px; inset-inline-start: 10px;
  font-size: 9px; font-weight: 700; color: var(--gold);
  background: rgba(245,197,66,0.12); border: 1px solid var(--gold-dim);
  padding: 1px 6px; border-radius: 6px;
}
.badge-live {
  position: absolute; top: 10px; inset-inline-start: 10px;
  font-size: 9px; font-weight: 700; color: var(--green);
  background: rgba(52,211,153,0.12); border: 1px solid rgba(52,211,153,0.5);
  padding: 1px 6px; border-radius: 6px;
}
.fav-btn {
  position: absolute; top: 8px; inset-inline-end: 8px;
  background: none; border: none; cursor: pointer; font-size: 16px;
  color: var(--muted); transition: transform 0.2s;
}
.fav-btn.faved { color: var(--gold); }
.fav-btn:hover { transform: scale(1.3); }

.card-head { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; margin-top: 6px; }
.card-icon {
  font-size: 22px; width: 40px; height: 40px; display: flex;
  align-items: center; justify-content: center;
  background: var(--surface2); border-radius: 12px; border: 1px solid var(--border);
  font-weight: 800; color: var(--gold);
}
.card-name-wrap { min-width: 0; }
.card-name { font-weight: 700; font-size: 14px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.card-ticker { font-size: 11px; color: var(--muted); font-family: 'Vazirmatn', monospace; }

.card-price {
  font-size: 22px; font-weight: 800; letter-spacing: -0.5px;
  color: var(--text); direction: ltr; text-align: end; line-height: 1.1;
}
.card-sub { font-size: 13px; color: var(--muted); direction: ltr; text-align: end; margin-top: 2px; }

.card-foot {
  display: flex; align-items: center; justify-content: space-between;
  margin-top: 10px; padding-top: 10px; border-top: 1px solid var(--border);
}
.change { font-size: 13px; font-weight: 700; direction: ltr; }
.spark { opacity: 0.9; }
.spark-empty { width: 80px; height: 26px; }

/* ---- Loader ---- */
.loader { text-align: center; padding: 80px 20px; }
.coin-spin { font-size: 60px; animation: spin 1.4s ease-in-out infinite; }
@keyframes spin { 0%,100% { transform: rotateY(0); } 50% { transform: rotateY(180deg); } }
.loader-txt { margin-top: 20px; color: var(--muted); font-size: 16px; }

.no-res { text-align: center; padding: 60px; color: var(--muted); font-size: 18px; }

/* ---- Footer ---- */
.footer {
  position: relative; z-index: 1; text-align: center;
  padding: 30px 16px 40px; color: var(--muted); font-size: 12px;
  border-top: 1px solid var(--border); margin-top: 20px;
  display: flex; flex-direction: column; gap: 8px;
}
.footer-disc { color: var(--gold-dim); }
.remix {
  color: var(--gold); text-decoration: none; font-weight: 700;
  border: 1px solid var(--gold-dim); padding: 5px 14px; border-radius: 999px;
  display: inline-block; transition: background 0.2s;
}
.remix:hover { background: rgba(245,197,66,0.12); }

/* ---- Modal ---- */
.modal-overlay {
  position: fixed; inset: 0; z-index: 50;
  background: rgba(5,8,16,0.75); backdrop-filter: blur(6px);
  display: flex; align-items: center; justify-content: center; padding: 20px;
  animation: fadeIn 0.2s;
}
@keyframes fadeIn { from { opacity: 0; } to { opacity: 1; } }
.modal {
  background: var(--surface); border: 1px solid var(--border); border-radius: 18px;
  padding: 22px; width: 100%; max-width: 400px;
  animation: modalUp 0.25s ease;
}
@keyframes modalUp { from { transform: translateY(20px) scale(0.97); opacity: 0; } to { transform: none; opacity: 1; } }
.modal-head { display: flex; justify-content: space-between; align-items: center; margin-bottom: 18px; }
.modal-head h3 { font-size: 18px; font-weight: 800; }
.close { background: none; border: none; color: var(--muted); font-size: 20px; cursor: pointer; }
.close:hover { color: var(--text); }
.field { display: flex; flex-direction: column; gap: 8px; margin-bottom: 18px; font-size: 13px; color: var(--muted); font-weight: 600; }
.input {
  background: var(--bg2); border: 1px solid var(--border); color: var(--text);
  padding: 10px 14px; border-radius: 10px; font-size: 16px; font-family: inherit;
  outline: none; direction: ltr; text-align: end;
}
.input:focus { border-color: var(--gold-dim); }
.last-up { font-size: 12px; color: var(--muted); margin-bottom: 12px; }
.modal-note { font-size: 12px; color: var(--gold-dim); line-height: 1.7; background: rgba(245,197,66,0.06); padding: 10px; border-radius: 10px; }