:root {
  --bg: #0b0f16;
  --bg-elev: #0f1521;
  --panel: rgba(255,255,255,0.04);
  --border: rgba(255,255,255,0.09);
  --text: #e7edf5;
  --muted: #9aa7b8;
  --accent: #69e2ff;
  --green: #1ddb7f;
  --red: #ff5a78;
  --yellow: #f8d56b;
  --shadow: 0 8px 30px rgba(0,0,0,0.35);
  --sticky-top: 0px;
  /* Global table cell padding */
  --cell-pad-y: 8px;
  --cell-pad-x: 8px;
  /* Ensure form controls render in dark mode */
  color-scheme: dark;
}

[data-theme="light"] {
  --bg: #f5f7fb;
  --bg-elev: #ffffff;
  --panel: rgba(0,0,0,0.02);
  --border: rgba(0,0,0,0.08);
  --text: #0b0f16;
  --muted: #5b6675;
  --accent: #4a72ff;
  --green: #0aa66a;
  --red: #d23b5a;
  --yellow: #e39d00;
  --shadow: 0 6px 24px rgba(0,0,0,0.12);
  color-scheme: light;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: Inter, system-ui, -apple-system, Segoe UI, Roboto, Helvetica, Arial, "Apple Color Emoji", "Segoe UI Emoji";
  color: var(--text);
}

/* Header */
.app-header {
  position: relative;
  z-index: 10;
  -webkit-backdrop-filter: saturate(120%) blur(10px);
  backdrop-filter: saturate(120%) blur(10px);
  background: linear-gradient(180deg, rgba(8,12,19,0.85), rgba(8,12,19,0.65) 60%, rgba(8,12,19,0));
}

/* Prevent focus zoom on mobile across all form fields */
input, select, textarea { font-size: 16px; }
[data-theme="light"] .app-header {
  background: linear-gradient(180deg, rgba(255,255,255,0.85), rgba(255,255,255,0.65) 60%, rgba(255,255,255,0));
}
.nav {
  position: sticky;
  top: 0;
  z-index: 20;
  display: grid;
  grid-template-columns: 1fr 2fr 1fr;
  gap: 16px;
  align-items: center;
  padding: 14px 20px;
  border-bottom: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(8,12,19,0.72), rgba(8,12,19,0.55));
  -webkit-backdrop-filter: saturate(120%) blur(10px);
  backdrop-filter: saturate(120%) blur(10px);
}

[data-theme="light"] .nav {
  background: linear-gradient(180deg, rgba(255,255,255,0.85), rgba(255,255,255,0.65));
  -webkit-backdrop-filter: saturate(120%) blur(10px);
  backdrop-filter: saturate(120%) blur(10px);
}
.brand { display: inline-flex; align-items: center; gap: 10px; text-decoration: none; color: var(--text); font-weight: 700; }
.brand img { filter: drop-shadow(0 4px 10px rgba(105,226,255,0.25)); }
.brand span { letter-spacing: 0.2px; }

.search-wrap {
  display: flex; align-items: center; gap: 10px;
  border: 1px solid var(--border);
  background: var(--panel);
  padding: 10px 12px;
  border-radius: 12px;
  box-shadow: var(--shadow);
  max-width: 640px; width: 100%; margin: 0 auto;
}
.search-wrap svg { width: 18px; height: 18px; stroke: var(--muted); fill: none; stroke-width: 2; }
.search-wrap input {
  appearance: none; outline: none;
  background: transparent; border: 0; color: var(--text);
  width: 100%; font-size: 16px; /* >=16px prevents iOS zoom on focus */
}
.controls { display: flex; gap: 10px; justify-self: end; }
.controls .ghost {
  appearance: none; border: 1px solid var(--border); background: var(--panel);
  color: var(--text); padding: 10px 14px; border-radius: 10px; cursor: pointer;
}
.controls .ghost:hover { border-color: rgba(255,255,255,0.2); }
.controls .ghost:active { transform: translateY(1px); }
.select { display: inline-block; }
.select select {
  -webkit-appearance: none;
  -moz-appearance: none;
  appearance: none;
  background-color: var(--bg-elev);
  color: var(--text);
  border: 1px solid var(--border);
  padding: 10px 34px 10px 12px;
  border-radius: 10px;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%239aa7b8' stroke-width='2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  background-size: 12px;
}
.select select:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}
/* Attempt to style dropdown options where supported */
.select select option {
  background-color: var(--bg-elev);
  color: var(--text);
}



/* Layout */
.container { max-width: 1200px; margin: 0 auto; padding: 24px 20px 64px; }
.panel {
  background: linear-gradient(180deg, rgba(255,255,255,0.04), rgba(255,255,255,0.02));
  border: 1px solid var(--border);
  border-radius: 16px;
  box-shadow: var(--shadow);
}
.panel-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px; border-bottom: 1px solid var(--border); }
.status { display: inline-flex; align-items: center; gap: 10px; color: var(--muted); }
.status .dot { width: 8px; height: 8px; border-radius: 6px; background: var(--yellow); box-shadow: 0 0 12px var(--yellow); }
.actions .hint { color: var(--muted); font-size: 12px; }

/* Actions */
.actions .ghost {
  appearance: none; border: 1px solid var(--border); background: var(--panel);
  color: var(--text); padding: 8px 12px; border-radius: 10px; cursor: pointer;
}
.actions .ghost:hover { border-color: rgba(255,255,255,0.2); }
.actions .ghost:active { transform: translateY(1px); }
.actions .ghost:disabled { opacity: 0.5; cursor: not-allowed; }

.movers-panel { margin-bottom: 20px; }
.movers-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; padding: 12px 16px 16px; }
.mover-card { background: var(--panel); border: 1px solid var(--border); border-radius: 12px; padding: 8px; }
.mover-card .card-head { display: flex; align-items: center; justify-content: space-between; padding: 6px 8px 10px; border-bottom: 1px solid var(--border); }
.mover-card h3 { margin: 0; font-size: 14px; }
.mover-list { list-style: none; margin: 0; padding: 0; }
.mover-item { display: grid; grid-template-columns: auto 1fr auto; gap: 10px; align-items: center; padding: 10px 8px; border-bottom: 1px solid rgba(255,255,255,0.06); }
.mover-item:last-child { border-bottom: 0; }
.badge { width: 22px; height: 22px; border-radius: 50%; }
.label { display: flex; flex-direction: column; }
.label .name { font-weight: 600; }
.label .sym { color: var(--muted); font-size: 12px; }

.table-wrap { position: relative; overflow-x: auto; overflow-y: visible; -webkit-overflow-scrolling: touch; }
/* Avoid inline style/CSP issues: no dynamic offsets via CSS vars */
table { width: 100%; border-collapse: collapse; table-layout: auto; }
thead th {
  position: sticky;
  top: var(--sticky-top, 0px);
  background: var(--bg);
  -webkit-backdrop-filter: blur(6px);
  backdrop-filter: blur(6px);
  border-bottom: 1px solid var(--border);
  font-weight: 600;
  padding: var(--cell-pad-y) var(--cell-pad-x);
  text-align: right;
  color: #c9d4e0;
  z-index: 5;
}
thead th.sticky { text-align: left; }
thead th.first { width: auto; min-width: 56px; text-align: center; }
thead th[data-sort] { cursor: pointer; }
thead th[data-sort].sorted-asc,
thead th[data-sort].sorted-desc { color: var(--text); font-weight: 700; }
thead th[data-sort].sorted-asc::after,
thead th[data-sort].sorted-desc::after { content: ''; display: inline-block; width: 0; height: 0; margin-left: 6px; border-left: 5px solid transparent; border-right: 5px solid transparent; }
thead th[data-sort].sorted-asc::after { border-bottom: 7px solid var(--accent); }
thead th[data-sort].sorted-desc::after { border-top: 7px solid var(--accent); }
tbody td { padding: var(--cell-pad-y) var(--cell-pad-x); border-bottom: 1px solid rgba(255,255,255,0.06); text-align: right; }
tbody tr:hover { background: rgba(255,255,255,0.03); }
tbody td.coin { text-align: left; }
 
tbody td:first-child { min-width: 56px; text-align: center; white-space: nowrap; overflow: visible; text-overflow: clip; }
.coin-cell { display: flex; align-items: center; gap: 10px; }
.coin-cell img { width: 22px; height: 22px; border-radius: 50%; }
.coin-cell .sym { color: var(--muted); font-size: 12px; letter-spacing: 0.5px; }
.chg { font-weight: 600; }
.pos { color: var(--green); }
.neg { color: var(--red); }
.spark svg { width: 120px; height: 40px; }

.skeleton { position: absolute; inset: 0; pointer-events: none; background: linear-gradient(90deg, transparent, rgba(255,255,255,0.04), transparent); background-size: 240px 100%; animation: shimmer 1.2s infinite; border-radius: 0 0 16px 16px; }
@keyframes shimmer { 0% { background-position: -240px 0; } 100% { background-position: 100% 0; } }
.skeleton.hidden { display: none; }

/* Generic utility for toggling visibility without inline styles */
.hidden { display: none !important; }
[hidden] { display: none !important; }

/* Infinite scroll sentinel + loader states */
#io-sentinel { height: 1px; }
.io-loader { display: none; align-items: center; justify-content: center; padding: 12px 0 16px; }
.io-loader.active { display: flex; }

.error { position: absolute; top: 10px; right: 10px; padding: 10px 12px; background: rgba(255,90,120,0.12); border: 1px solid rgba(255,90,120,0.35); color: #ffdce5; border-radius: 10px; box-shadow: var(--shadow); }

.footer { color: var(--muted); text-align: center; padding: 36px 0; border-top: 1px solid var(--border); }
.footer a { color: var(--accent); text-decoration: none; }
.footer a:hover { text-decoration: underline; }

/* Infinite scroll loader spinner */
.io-loader::after {
  content: "";
  width: 18px;
  height: 18px;
  border: 2px solid var(--border);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Modal overlay with iframe */
.overlay { position: fixed; inset: 0; display: grid; place-items: center; z-index: 1000; }
.overlay.hidden { display: none !important; }
.overlay-backdrop {
  position: absolute; inset: 0;
  /* Subtle dim + blur for background, distinct from frosted panel */
  background: rgba(0,0,0,0.28);
  -webkit-backdrop-filter: blur(6px) saturate(110%);
  backdrop-filter: blur(6px) saturate(110%);
}
[data-theme="light"] .overlay-backdrop { background: rgba(0,0,0,0.12); }
.overlay-content {
  position: relative; width: min(960px, 96vw); height: auto;
  /* Frosted glass panel distinct from backdrop */
  background: linear-gradient(180deg, rgba(255,255,255,0.12), rgba(255,255,255,0.06));
  -webkit-backdrop-filter: blur(12px) saturate(140%);
  backdrop-filter: blur(12px) saturate(140%);
  border: 1px solid var(--border);
  border-radius: 16px; box-shadow: var(--shadow);
  overflow: visible; display: flex; flex-direction: column;
}
[data-theme="light"] .overlay-content {
  background: linear-gradient(180deg, rgba(255,255,255,0.75), rgba(255,255,255,0.55));
}
.overlay-content .close-btn { position: absolute; top: calc(env(safe-area-inset-top, 0) + 10px); right: calc(env(safe-area-inset-right, 0) + 10px); z-index: 2; }
.close-btn {
  --btn-size: 40px;
  width: var(--btn-size);
  height: var(--btn-size);
  display: inline-grid;
  place-items: center;
  padding: 0;
  border-radius: 12px;
  color: var(--text);
  border: 1px solid var(--border);
  background: linear-gradient(180deg, rgba(255,255,255,0.14), rgba(255,255,255,0.06));
  -webkit-backdrop-filter: blur(10px) saturate(140%);
  backdrop-filter: blur(10px) saturate(140%);
  transition: transform .15s ease, border-color .15s ease, background-color .15s ease, box-shadow .15s ease;
}
[data-theme="light"] .close-btn { background: linear-gradient(180deg, rgba(255,255,255,0.85), rgba(255,255,255,0.65)); }
.close-btn svg { width: 20px; height: 20px; stroke: currentColor; stroke-width: 2; fill: none; }
.close-btn:hover { transform: translateY(-1px); box-shadow: 0 6px 20px rgba(0,0,0,0.18); }
.close-btn:active { transform: translateY(0); box-shadow: none; }
.close-btn:focus { outline: none; }
.close-btn:focus-visible { box-shadow: 0 0 0 3px rgba(105,226,255,0.35); }
@media (max-width: 480px) {
  .close-btn { --btn-size: 36px; border-radius: 10px; }
  .close-btn svg { width: 18px; height: 18px; }
}
.overlay-content iframe { width: 100%; border: 0; background: transparent; border-top-left-radius: 16px; border-top-right-radius: 16px; }

/* Details iframe page styles */
.details { background: transparent; }
.details-page, .details-page body { height: auto !important; min-height: 0 !important; }
.details .meta-grid { border-bottom: 0; }
 
.sheet { height: 100%; display: grid; grid-template-rows: auto auto 1fr; background: transparent; }
.details .sheet { height: auto; grid-template-rows: auto auto auto; }
.sheet-head { display:flex; align-items:center; gap:12px; padding:12px 14px; border-bottom:1px solid var(--border); background: linear-gradient(180deg, rgba(255,255,255,0.06), rgba(255,255,255,0)); -webkit-backdrop-filter: blur(6px) saturate(120%); backdrop-filter: blur(6px) saturate(120%); }
.sheet-head img { width: 28px; height: 28px; border-radius: 50%; }
.sheet-head .title { display:flex; align-items:baseline; gap:8px; }
.sheet-head .title .name { font-weight:700; }
.sheet-head .title .sym { color: var(--muted); font-size: 12px; }
.sheet-head .price { font-weight: 700; }
.spacer { flex: 1; }


.meta-grid { display:grid; grid-template-columns: 1fr 1fr; gap:12px; padding:12px 14px; border-bottom:1px solid var(--border); }
.card { background: var(--panel); border:1px solid var(--border); border-radius: 12px; padding: 10px 12px; -webkit-backdrop-filter: blur(6px) saturate(120%); backdrop-filter: blur(6px) saturate(120%); }
.card h3 { margin: 0 0 8px; font-size: 14px; }
.kv { display:grid; grid-template-columns: auto 1fr; gap:8px 12px; font-size: 14px; }
.kv dt { color: var(--muted); }
.kv dd { margin:0; text-align:right; }

.urls { display:flex; flex-wrap:wrap; gap:8px; }
.urls a { color: var(--accent); text-decoration: none; font-size: 13px; }
.urls a:hover { text-decoration: underline; }
@media (max-width: 640px) { .meta-grid { grid-template-columns: 1fr; } }

/* Responsive */
@media (max-width: 980px) {
  .nav { grid-template-columns: 1fr; }
  .controls { justify-self: stretch; }
thead th.spark, td.spark { display: none; }
.has-spark thead th.spark,
.has-spark td.spark { display: table-cell; }
  /* Also hide Market Cap and Volume on tablets */
  thead th.col-market-cap, td.col-market-cap,
  thead th.col-volume, td.col-volume,
  thead th.col-7d, td.col-7d { display: none; }
  .movers-grid { grid-template-columns: 1fr; }
}

@media (max-width: 768px) {
  .container { padding: 18px 12px 56px; }
  :root { --cell-pad-y: 6px; --cell-pad-x: 6px; }
  thead th, tbody td { padding: var(--cell-pad-y) var(--cell-pad-x); }
  .coin-cell { gap: 8px; }
  .coin-cell img { width: 20px; height: 20px; }
  /* Show only the symbol on mobile; hide full names */
  .coin-cell .name { display: none; }
  .label .name { display: none; }
  /* Hide on mobile: 1h, Market Cap, Volume, 7d, Spark */
  thead th.col-1h, td.col-1h,
  thead th.col-market-cap, td.col-market-cap,
  thead th.col-volume, td.col-volume,
  thead th.col-7d, td.col-7d,
  thead th.spark, td.spark { display: none; }
  /* First column (#) padding + width tweaks for phones */
  thead th.first, tbody td:first-child { padding-left: 6px; padding-right: 6px; min-width: 52px; }
}
