/* Rateo — styles. Dark by default (ticker aesthetic), light theme via
   [data-theme="light"] on <html>. Mobile-first. */

:root {
  --bg: #0b1020;
  --bg-soft: #111731;
  --card: #151c3a;
  --card-2: #1a2246;
  --border: #242e5c;
  --text: #e8ecf8;
  --muted: #8b93b8;
  --accent: #13e0a0;
  --accent-2: #35b6ff;
  --up: #13e0a0;
  --down: #ff5c7a;
  --warn: #ffb84d;
  --brand-mark: #0b1020;
  --radius: 14px;
  --mono: "SF Mono", "Cascadia Code", ui-monospace, Menlo, Consolas, monospace;
}

html[data-theme="light"] {
  --bg: #f2f5fb;
  --bg-soft: #e7ecf6;
  --card: #ffffff;
  --card-2: #f4f7fd;
  --border: #d8e0ef;
  --text: #131a33;
  --muted: #5a6488;
  --accent: #0aa678;
  --accent-2: #0d7fd6;
  --up: #0aa678;
  --down: #e23b57;
  --warn: #b57d0e;
  --brand-mark: #ffffff;
}

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

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--text);
  font: 16px/1.5 system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  min-height: 100dvh;
  display: flex;
  flex-direction: column;
  transition: background .25s, color .25s;
}

a { color: var(--accent-2); text-decoration: none; }
a:hover { text-decoration: underline; }

/* ---------------- Top bar ---------------- */
.topbar {
  position: sticky; top: 0; z-index: 20;
  background: color-mix(in srgb, var(--bg) 82%, transparent);
  backdrop-filter: blur(10px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 960px; margin: 0 auto; padding: 12px 16px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
}
.brand { display: flex; align-items: center; gap: 10px; color: var(--text); }
.brand:hover { text-decoration: none; }
.brand-mark { width: 30px; height: 30px; }
.brand-name { font-weight: 800; font-size: 1.25rem; letter-spacing: .02em; }
.topbar-right { display: flex; align-items: center; gap: 12px; }

.live-badge {
  display: inline-flex; align-items: center; gap: 7px;
  font-size: .75rem; font-weight: 700; letter-spacing: .12em;
  color: var(--muted); text-transform: uppercase;
}
.live-dot {
  width: 8px; height: 8px; border-radius: 50%;
  background: var(--muted); transition: background .3s;
}
.live-badge.live .live-dot { background: var(--accent); box-shadow: 0 0 0 0 rgba(19,224,160,.5); animation: pulse 2s infinite; }
.live-badge.err .live-dot { background: var(--down); }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(19,224,160,.45); }
  70% { box-shadow: 0 0 0 8px rgba(19,224,160,0); }
  100% { box-shadow: 0 0 0 0 rgba(19,224,160,0); }
}

.icon-btn {
  background: var(--card-2); border: 1px solid var(--border); color: var(--text);
  width: 38px; height: 38px; border-radius: 10px; cursor: pointer;
  display: inline-flex; align-items: center; justify-content: center;
  transition: transform .15s, background .2s;
}
.icon-btn:hover { background: var(--card); transform: translateY(-1px); }

/* ---------------- Layout ---------------- */
main {
  flex: 1; width: 100%; max-width: 960px; margin: 0 auto;
  padding: 20px 16px 40px;
  display: flex; flex-direction: column; gap: 20px;
}

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

/* ---------------- Converter ---------------- */
.converter-row {
  display: grid; grid-template-columns: 1fr;
  gap: 12px;
}
.field { display: flex; flex-direction: column; gap: 6px; position: relative; }
.field label { font-size: .72rem; font-weight: 700; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); }
.field input {
  width: 100%; padding: 12px 14px; font-size: 1.05rem;
  background: var(--card-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px;
  outline: none; transition: border-color .2s, box-shadow .2s;
}
.field input:focus { border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 20%, transparent); }

/* ---------------- Currency picker (fuzzy search combobox) ---------------- */
.picker { position: relative; width: 100%; }
.picker-btn {
  width: 100%; display: flex; align-items: center; gap: 8px;
  padding: 12px 14px; background: var(--card-2); color: var(--text);
  border: 1px solid var(--border); border-radius: 10px; cursor: pointer;
  text-align: left; transition: border-color .2s, box-shadow .2s;
  font: inherit;
}
.picker-btn:hover, .picker.open .picker-btn {
  border-color: var(--accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 14%, transparent);
}
.picker-sym { font-size: 1rem; width: 22px; text-align: center; color: var(--accent); flex: none; }
.picker-code { font-weight: 800; font-size: 1.02rem; font-family: var(--mono); }
.picker-name { flex: 1; font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.picker-caret { color: var(--muted); flex: none; }

.picker-pop {
  position: absolute; top: calc(100% + 6px); left: 0; right: 0; z-index: 40;
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  box-shadow: 0 16px 40px rgba(0,0,0,.35); overflow: hidden;
}
.picker-pop[hidden] { display: none; }
.picker-search {
  width: 100%; padding: 11px 14px; border: none; border-bottom: 1px solid var(--border);
  background: var(--card-2); color: var(--text); font-size: .95rem; outline: none;
}
.picker-list { max-height: 300px; overflow-y: auto; padding: 6px; list-style: none; margin: 0; overscroll-behavior: contain; }
.li-group { font-size: .66rem; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; color: var(--muted); padding: 8px 10px 4px; }
.li-opt { display: flex; align-items: center; gap: 10px; padding: 9px 10px; border-radius: 8px; cursor: pointer; }
.li-opt:hover, .li-opt.active { background: color-mix(in srgb, var(--accent) 14%, var(--card-2)); }
.li-code { font-weight: 800; font-family: var(--mono); min-width: 52px; }
.li-name { flex: 1; font-size: .85rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.li-badge { font-size: .6rem; letter-spacing: .06em; text-transform: uppercase; color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 40%, transparent); border-radius: 6px; padding: 1px 5px; flex: none; }
.li-empty { padding: 14px; text-align: center; color: var(--muted); font-size: .85rem; list-style: none; }

.swap-btn {
  justify-self: center; width: 44px; height: 44px; border-radius: 50%;
  background: var(--card-2); border: 1px solid var(--border); color: var(--accent);
  cursor: pointer; display: flex; align-items: center; justify-content: center;
  transition: transform .2s, background .2s;
}
.swap-btn:hover { background: var(--card); transform: rotate(180deg); }

.result { margin-top: 18px; padding-top: 16px; border-top: 1px dashed var(--border); }
.result-main { display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
#result-value {
  font-family: var(--mono); font-size: clamp(1.9rem, 8vw, 3rem);
  font-weight: 700; letter-spacing: -.02em; line-height: 1.1;
}
.result-code { font-size: 1.2rem; color: var(--muted); font-weight: 600; }
.result-meta { margin-top: 6px; font-size: .9rem; color: var(--muted); display: flex; gap: 8px; flex-wrap: wrap; }
.dot-sep { opacity: .5; }

.chips { margin-top: 16px; display: flex; flex-wrap: wrap; gap: 8px; }
.chip {
  font-size: .82rem; font-weight: 600; padding: 6px 12px;
  background: var(--card-2); border: 1px solid var(--border); border-radius: 999px;
  color: var(--text); cursor: pointer; transition: background .15s, border-color .15s;
}
.chip:hover { border-color: var(--accent); background: var(--card); }
.chip b { color: var(--accent); }

/* ---------------- History chart ---------------- */
.chart { margin-top: 16px; }
.chart-head { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
.chart-title { font-family: var(--mono); font-weight: 700; font-size: .95rem; }
.chart-change { font-family: var(--mono); font-size: .8rem; font-weight: 700; }
.chart-change.up { color: var(--up); }
.chart-change.down { color: var(--down); }
.chart-periods { margin-left: auto; display: flex; gap: 4px; }
.chart-periods button {
  background: var(--card-2); border: 1px solid var(--border); color: var(--muted);
  font-size: .72rem; font-weight: 700; padding: 4px 10px; border-radius: 8px; cursor: pointer;
  font: inherit;
}
.chart-periods button:hover { color: var(--text); }
.chart-periods button.active { color: var(--text); border-color: var(--accent); }
.chart-body { position: relative; height: 200px; }
#chart { width: 100%; height: 100%; display: block; }
.chart-msg {
  position: absolute; inset: 0; display: flex; align-items: center; justify-content: center;
  color: var(--muted); font-size: .85rem;
}
.chart-msg[hidden] { display: none; }
.chart-tip {
  position: absolute; pointer-events: none; z-index: 5;
  background: var(--card); border: 1px solid var(--border); border-radius: 8px;
  padding: 5px 9px; font-family: var(--mono); font-size: .76rem; color: var(--text);
  box-shadow: 0 6px 20px rgba(0,0,0,.28); white-space: nowrap;
  transform: translate(-50%, -115%);
}
.chart-tip small { display: block; color: var(--muted); font-weight: 400; }
.chart-tip[hidden] { display: none; }

/* ---------------- Affiliate CTA ---------------- */
.cta {
  margin-top: 16px; display: flex; align-items: center; gap: 14px; flex-wrap: wrap;
  background: linear-gradient(135deg, color-mix(in srgb, var(--accent) 12%, var(--card)), var(--card));
  border: 1px solid color-mix(in srgb, var(--accent) 35%, var(--border));
  border-radius: 12px; padding: 14px 16px;
}
.cta[hidden] { display: none; }
.cta-text { flex: 1; min-width: 200px; display: flex; flex-direction: column; gap: 2px; }
.cta-text strong { font-size: .92rem; }
.cta-text span { font-size: .8rem; color: var(--muted); }
.cta-btn {
  background: var(--accent); color: var(--brand-mark); font-weight: 800; font-size: .85rem;
  padding: 10px 16px; border-radius: 10px; text-decoration: none; white-space: nowrap;
}
.cta-btn:hover { text-decoration: none; filter: brightness(1.06); }

/* ---------------- Market board ---------------- */
.board { display: flex; flex-direction: column; gap: 8px; }
.board-head { display: flex; align-items: baseline; justify-content: space-between; gap: 10px; margin-top: 12px; }
.board-head h2 { font-size: 1.05rem; font-weight: 800; letter-spacing: .02em; }
.head-live { font-size: .68rem; color: var(--accent); border: 1px solid color-mix(in srgb, var(--accent) 45%, transparent); border-radius: 999px; padding: 2px 8px; vertical-align: middle; margin-left: 4px; letter-spacing: .08em; }
.head-daily { font-size: .68rem; color: var(--warn); border: 1px solid color-mix(in srgb, var(--warn) 45%, transparent); border-radius: 999px; padding: 2px 8px; vertical-align: middle; margin-left: 4px; letter-spacing: .08em; }
.board-note { font-size: .78rem; color: var(--muted); }

.grid {
  display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
  gap: 10px;
}
.tile {
  background: var(--card); border: 1px solid var(--border); border-radius: 12px;
  padding: 12px 14px; display: flex; flex-direction: column; gap: 6px;
  transition: border-color .15s, transform .15s;
}
.tile:hover { border-color: var(--accent-2); transform: translateY(-1px); }
.tile-head { display: flex; align-items: center; justify-content: space-between; gap: 6px; }
.tile-code { font-weight: 800; font-size: .95rem; font-family: var(--mono); }
.tile-badge { font-size: .6rem; letter-spacing: .08em; text-transform: uppercase; color: var(--muted); border: 1px solid var(--border); border-radius: 6px; padding: 1px 5px; }
.tile-name { font-size: .78rem; color: var(--muted); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.tile-price { font-family: var(--mono); font-size: 1.02rem; font-weight: 600; }
.tile-change { font-family: var(--mono); font-size: .8rem; font-weight: 700; }
.tile-change.up { color: var(--up); }
.tile-change.down { color: var(--down); }
.tile-spark { width: 100%; height: 34px; display: block; }
.tile-rate { font-family: var(--mono); font-size: .95rem; font-weight: 600; }
.tile-note { font-size: .68rem; color: var(--muted); letter-spacing: .05em; text-transform: uppercase; }
.tile-empty {
  grid-column: 1 / -1; align-items: center; justify-content: center;
  text-align: center; font-size: .8rem; color: var(--muted); min-height: 60px;
}

/* ---------------- Notice & footer ---------------- */
.notice p { font-size: .82rem; color: var(--muted); }
.footer { border-top: 1px solid var(--border); }
.footer-inner {
  max-width: 960px; margin: 0 auto; padding: 16px;
  display: flex; flex-wrap: wrap; gap: 8px 16px; justify-content: space-between;
  font-size: .8rem; color: var(--muted);
}
.footer-links a { color: var(--muted); }
.footer-links a:hover { color: var(--text); }

/* ---------------- Error banner ---------------- */
.error-banner {
  position: fixed; left: 16px; right: 16px; bottom: 16px; z-index: 50;
  max-width: 480px; margin: 0 auto;
  background: color-mix(in srgb, var(--down) 14%, var(--card));
  border: 1px solid var(--down); border-radius: 12px;
  padding: 12px 14px; display: flex; align-items: center; gap: 10px;
  font-size: .9rem;
}
.error-banner[hidden] { display: none; }
.error-banner button { margin-left: auto; color: var(--down); border-color: var(--down); }

/* ---------------- Desktop ---------------- */
@media (min-width: 720px) {
  .converter-row { grid-template-columns: 1.2fr 1fr auto 1fr; align-items: end; }
  .swap-btn { margin-bottom: 2px; }
  main { padding: 28px 24px 60px; gap: 24px; }
}
