/* 浅色（默认；data-theme="light" 强制浅色） */
:root,
:root[data-theme="light"] {
  --bg: #f4f5f7;
  --card: #ffffff;
  --card2: #f7f8fa;
  --line: #e3e6ec;
  --text: #1a1d24;
  --muted: #6b7180;
  --up: #e02e24;   /* 涨=红（中国习惯） */
  --down: #1aa251; /* 跌=绿 */
  --accent: #e0920f;
  --grid: rgba(0, 0, 0, .06);
}

/* 强制深色（手动选「深色」） */
:root[data-theme="dark"] {
  --bg: #0f1117;
  --card: #181b24;
  --card2: #1f2330;
  --line: #2a2f3e;
  --text: #e8eaf0;
  --muted: #8b90a0;
  --up: #ef4444;
  --down: #22c55e;
  --accent: #f0a830;
  --grid: rgba(255, 255, 255, .06);
}

/* 跟随系统：系统为深色且未手动指定浅/深时 */
@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]):not([data-theme="dark"]) {
    --bg: #0f1117;
    --card: #181b24;
    --card2: #1f2330;
    --line: #2a2f3e;
    --text: #e8eaf0;
    --muted: #8b90a0;
    --up: #ef4444;
    --down: #22c55e;
    --accent: #f0a830;
    --grid: rgba(255, 255, 255, .06);
  }
}

* { 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, "PingFang SC", "Segoe UI", Roboto, sans-serif;
}

.app {
  max-width: 560px;
  margin: 0 auto;
  padding: max(env(safe-area-inset-top), 14px) 16px calc(env(safe-area-inset-bottom) + 24px);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 0 2px;
}
.title { display: flex; align-items: center; gap: 8px; }
.title h1 { font-size: 20px; margin: 0; font-weight: 700; letter-spacing: .5px; }
.flag { font-size: 22px; }
.actions { display: flex; align-items: center; gap: 8px; }
.theme-btn {
  display: flex; align-items: center; gap: 6px;
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  height: 40px;
  padding: 0 12px;
  border-radius: 12px;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.theme-btn .ticon { font-size: 16px; line-height: 1; }
.refresh {
  background: var(--card);
  border: 1px solid var(--line);
  color: var(--text);
  width: 40px; height: 40px;
  border-radius: 12px;
  font-size: 20px;
  cursor: pointer;
  transition: transform .3s;
}
.refresh:active { transform: rotate(180deg); }
.refresh.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

.updated { color: var(--muted); font-size: 13px; margin: 6px 0 14px; }

.cards { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
@media (max-width: 420px) { .cards { grid-template-columns: 1fr; } }

.card {
  background: linear-gradient(160deg, var(--card2), var(--card));
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
}
.card-head { display: flex; align-items: center; justify-content: space-between; }
.pair { font-size: 13px; color: var(--muted); font-weight: 600; }
.flag2 { font-size: 14px; }
.change { font-size: 13px; font-weight: 700; padding: 2px 8px; border-radius: 8px; }
.change.up { color: var(--up); background: rgba(239,68,68,.12); }
.change.down { color: var(--down); background: rgba(34,197,94,.12); }
.change.flat { color: var(--muted); }
.rate { font-size: 34px; font-weight: 800; margin: 10px 0 2px; letter-spacing: .5px; }
.sub { font-size: 12px; color: var(--muted); }

.panel {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 18px;
  padding: 16px;
  margin-top: 14px;
}
.panel h2 { font-size: 15px; margin: 0 0 12px; font-weight: 700; }
.panel-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 4px; }
.panel-head h2 { margin: 0; }

.range { display: flex; gap: 6px; }
.range button {
  background: var(--card2);
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 6px 12px;
  border-radius: 10px;
  font-size: 13px;
  cursor: pointer;
}
.range button.active { color: #fff; background: var(--accent); border-color: var(--accent); }

.calc-row {
  display: flex; align-items: center; gap: 10px;
  background: var(--card2);
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  margin-bottom: 10px;
}
.calc-row input {
  flex: 1; background: transparent; border: none; color: var(--text);
  font-size: 22px; font-weight: 700; padding: 14px 0; outline: none; width: 100%;
  -moz-appearance: textfield;
}
.calc-row input::-webkit-outer-spin-button,
.calc-row input::-webkit-inner-spin-button { -webkit-appearance: none; margin: 0; }
.calc-row .ccy { color: var(--muted); font-weight: 700; font-size: 14px; white-space: nowrap; }
.calc-row.out input { font-size: 19px; }
.calc-out { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.calc-out .calc-row { margin-bottom: 0; }
@media (max-width: 420px) { .calc-out { grid-template-columns: 1fr; } }
.calc-hint { color: var(--muted); font-size: 12px; margin: 8px 0 0; }

.legend { display: flex; gap: 16px; font-size: 12px; margin: 6px 0 4px; }
.lg-usd { color: #f0a830; }
.lg-cny { color: #4aa3ff; }
.chart-wrap { position: relative; height: 240px; }

.foot { margin-top: 20px; text-align: center; }
.foot p { font-size: 12px; color: var(--muted); margin: 4px 0; }
.foot .muted { opacity: .7; }
