:root {
  --bg: #f3f4f8;
  --surface: #ffffff;
  --text: #111827;
  --muted: #6b7280;
  --line: #e5e7eb;
  --up: #e53935;
  --down: #1b8a46;
  --accent: #2563eb;
  --shadow: 0 10px 30px rgba(17, 24, 39, 0.08);
  color-scheme: light;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #0b1220;
    --surface: #151c2c;
    --text: #f3f4f6;
    --muted: #9ca3af;
    --line: #243044;
    --accent: #60a5fa;
    --shadow: 0 10px 30px rgba(0, 0, 0, 0.28);
    color-scheme: dark;
  }
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", sans-serif;
}

body {
  min-height: 100dvh;
}

.page {
  height: 100dvh;
  max-width: 480px;
  margin: 0 auto;
  display: flex;
  flex-direction: column;
  padding: env(safe-area-inset-top) 0 env(safe-area-inset-bottom);
  background: var(--bg);
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px 8px;
}

.titles h1 {
  margin: 0;
  font-size: 22px;
  letter-spacing: 0.02em;
}

.titles p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 13px;
}

.actions, .search {
  display: flex;
  align-items: center;
  gap: 4px;
}

.icon-btn, .chip, .text-btn {
  border: 0;
  background: transparent;
  color: inherit;
  font: inherit;
}

.icon-btn {
  width: 40px;
  height: 40px;
  border-radius: 20px;
  display: grid;
  place-items: center;
}

.icon-btn:active, .chip:active, .text-btn:active {
  transform: scale(0.97);
}

.controls {
  padding: 0 16px 8px;
}

.search {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 14px;
  padding: 0 6px 0 12px;
}

.search input {
  flex: 1;
  height: 44px;
  border: 0;
  outline: none;
  background: transparent;
  color: inherit;
  font-size: 16px;
}

.chips {
  display: flex;
  gap: 8px;
  margin-top: 10px;
}

.chip {
  padding: 8px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--line);
  color: var(--muted);
}

.chip.is-active {
  color: var(--text);
  border-color: var(--text);
  font-weight: 600;
}

.banner {
  margin: 0 16px 8px;
  color: #b91c1c;
  font-size: 13px;
}

button {
  -webkit-tap-highlight-color: transparent;
}

.list {
  flex: 1;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
  overscroll-behavior: contain;
  padding: 0 8px 16px;
}

.list.is-loading {
  opacity: 0.7;
}

.list-inner {
  position: relative;
}

.row {
  position: absolute;
  left: 0;
  right: 0;
  display: flex;
  align-items: center;
  justify-content: space-between;
  min-height: 64px;
  padding: 0 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--line);
}

.row strong {
  display: block;
  font-size: 16px;
}

.row small, .pct small {
  color: var(--muted);
  font-size: 12px;
}

.pct {
  text-align: right;
  font-variant-numeric: tabular-nums;
}

.pct b {
  display: block;
  font-size: 16px;
}

.is-up { color: var(--up); }
.is-down { color: var(--down); }

.status {
  height: 100%;
  display: grid;
  place-items: center;
  color: var(--muted);
  padding: 48px 24px;
  text-align: center;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 3px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

@keyframes spin {
  to { transform: rotate(360deg); }
}

.mask {
  position: fixed;
  inset: 0;
  background: rgba(15, 23, 42, 0.45);
  display: grid;
  justify-items: center;
  align-items: end;
}

.sheet {
  width: min(480px, 100%);
  background: var(--surface);
  border-radius: 20px 20px 0 0;
  padding: 20px 20px calc(20px + env(safe-area-inset-bottom));
  box-shadow: var(--shadow);
}

.sheet h2 {
  margin: 0 0 16px;
  font-size: 18px;
}

.sheet label {
  display: block;
  color: var(--muted);
  font-size: 13px;
}

.sheet input {
  width: 100%;
  margin-top: 6px;
  height: 44px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 12px;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
}

.hint {
  color: var(--muted);
  font-size: 12px;
  line-height: 1.5;
}

.sheet-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  margin-top: 8px;
}

.text-btn {
  padding: 10px 14px;
  color: var(--muted);
}

.text-btn.primary {
  color: var(--accent);
  font-weight: 700;
}

[hidden] { display: none !important; }

.gate {
  min-height: 100dvh;
  display: grid;
  place-items: center;
  padding: 24px 16px calc(24px + env(safe-area-inset-bottom));
}

.gate-card {
  width: min(420px, 100%);
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 20px;
  padding: 28px 22px 22px;
  box-shadow: var(--shadow);
}

.gate-card h1 {
  margin: 0;
  font-size: 24px;
}

.gate-card p {
  margin: 8px 0 18px;
  color: var(--muted);
  font-size: 14px;
}

.gate-card input {
  width: 100%;
  height: 48px;
  border: 1px solid var(--line);
  border-radius: 12px;
  padding: 0 14px;
  font-size: 16px;
  background: var(--bg);
  color: var(--text);
  outline: none;
}

.gate-card input:focus {
  border-color: var(--accent);
}

.gate-error {
  margin: 10px 0 0 !important;
  color: #b91c1c !important;
  font-size: 13px !important;
}

.gate-card button {
  width: 100%;
  margin-top: 16px;
  height: 48px;
  border: 0;
  border-radius: 12px;
  background: var(--text);
  color: var(--bg);
  font-size: 16px;
  font-weight: 700;
}

.gate-card button:disabled {
  opacity: 0.6;
}
