:root {
  --bg: #0b0d12;
  --card: #151922;
  --line: #232936;
  --text: #e8ecf4;
  --muted: #8b95a7;
  --accent: #6ea8fe;
  --danger: #ff6b6b;
  --ok: #4ade80;
  --radius: 14px;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font: 15px/1.5 -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", "Noto Sans SC", sans-serif;
}

body { padding: env(safe-area-inset-top) 12px calc(env(safe-area-inset-bottom) + 24px); }

main { max-width: 720px; margin: 0 auto; }

h1 { font-size: 22px; margin: 0 0 4px; }
h2 { font-size: 16px; margin: 24px 0 10px; }

.muted { color: var(--muted); }
.tiny { font-size: 12px; }
.error { color: var(--danger); font-size: 13px; }

/* ── 顶栏 ── */
#topbar {
  max-width: 720px;
  margin: 0 auto;
  padding: 14px 2px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}
.who { display: flex; align-items: baseline; gap: 10px; min-width: 0; }
.who b { font-size: 16px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.credits { color: var(--accent); font-size: 13px; white-space: nowrap; }

/* ── 卡片 / 表单 ── */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 16px;
  margin-bottom: 14px;
}

label { display: block; margin-bottom: 12px; font-size: 13px; color: var(--muted); }
input, textarea, select {
  display: block;
  width: 100%;
  margin-top: 6px;
  padding: 12px;
  font: inherit;
  font-size: 16px; /* 防止 iOS 聚焦缩放 */
  color: var(--text);
  background: #0f131b;
  border: 1px solid var(--line);
  border-radius: 10px;
  outline: none;
}
input:focus, textarea:focus, select:focus { border-color: var(--accent); }
textarea { resize: vertical; }

button {
  width: 100%;
  padding: 13px;
  font: inherit;
  font-weight: 600;
  color: #06101f;
  background: var(--accent);
  border: 0;
  border-radius: 10px;
  cursor: pointer;
}
button:disabled { opacity: .5; }
button.ghost {
  width: auto;
  padding: 8px 12px;
  color: var(--muted);
  background: transparent;
  border: 1px solid var(--line);
  font-weight: 500;
}
button.ghost.tiny { font-size: 12px; padding: 6px 10px; }

.row { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.cost { opacity: .8; font-weight: 500; font-size: 13px; }

summary { cursor: pointer; color: var(--muted); font-size: 13px; margin-bottom: 10px; }

.redeem form { display: flex; gap: 8px; margin-top: 10px; }
.redeem input { margin-top: 0; }
.redeem button { width: auto; padding: 12px 18px; white-space: nowrap; }

.login { margin-top: 8vh; }
.login h1 { margin-bottom: 2px; }
.login p.muted { margin: 0 0 20px; }

/* ── 状态 ── */
.status { display: flex; align-items: center; gap: 12px; }
.status-text { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.status-text b { font-size: 14px; }

.spinner {
  width: 20px; height: 20px; flex: none;
  border: 2px solid var(--line);
  border-top-color: var(--accent);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── 历史 ── */
.grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(104px, 1fr)); gap: 8px; }
.thumb {
  position: relative;
  aspect-ratio: 2 / 3;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 10px;
  overflow: hidden;
  cursor: pointer;
}
.thumb img { width: 100%; height: 100%; object-fit: cover; display: block; }
.thumb .badge {
  position: absolute; left: 6px; bottom: 6px;
  padding: 2px 6px;
  font-size: 10px;
  color: var(--text);
  background: rgba(0,0,0,.6);
  border-radius: 6px;
  backdrop-filter: blur(4px);
}
.thumb .dl {
  position: absolute; right: 6px; top: 6px;
  width: 26px; height: 26px;
  display: grid; place-items: center;
  font-size: 13px;
  color: var(--text);
  background: rgba(0,0,0,.55);
  border-radius: 8px;
  text-decoration: none;
}

/* ── toast / 大图 ── */
.toast {
  position: fixed;
  left: 50%;
  bottom: calc(env(safe-area-inset-bottom) + 20px);
  transform: translateX(-50%);
  max-width: 90vw;
  padding: 11px 16px;
  font-size: 14px;
  color: var(--text);
  background: #1e2432;
  border: 1px solid var(--line);
  border-radius: 12px;
  box-shadow: 0 6px 24px rgba(0,0,0,.4);
  z-index: 20;
}
.toast.bad { border-color: var(--danger); }
.toast.ok { border-color: var(--ok); }

.viewer {
  position: fixed;
  inset: 0;
  z-index: 30;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  padding: 16px;
  background: rgba(0,0,0,.94);
}
.viewer img { max-width: 100%; max-height: 80vh; object-fit: contain; border-radius: 8px; }
.viewer button { width: auto; padding: 10px 22px; }
/* ── 顶栏动作区 ── */
.who-actions { display: flex; gap: 8px; align-items: center; }
.who-actions a { text-decoration: none; }

/* ── 管理后台 ── */
.tabs { display: flex; gap: 8px; margin: 4px 0 14px; }
.tabs button {
  flex: 1;
  padding: 10px 6px;
  font-size: 13px;
  color: var(--muted);
  background: var(--card);
  border: 1px solid var(--line);
}
.tabs button.active { color: #06101f; background: var(--accent); border-color: var(--accent); }

.stat-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 10px; }
.stat {
  display: flex;
  flex-direction: column;
  gap: 4px;
  padding: 12px 14px;
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: 12px;
}
.stat b { font-size: 20px; font-variant-numeric: tabular-nums; }

table { width: 100%; border-collapse: collapse; font-size: 13px; }
th, td { padding: 9px 6px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 500; font-size: 12px; }
td button { width: auto; }

.tag {
  padding: 1px 5px;
  font-size: 10px;
  color: var(--accent);
  border: 1px solid var(--accent);
  border-radius: 5px;
}

.banner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 12px;
  padding: 11px 14px;
  font-size: 13px;
  background: rgba(255, 107, 107, .1);
  border: 1px solid var(--danger);
  border-radius: 12px;
}
.banner button { flex: none; }

.alert { padding: 10px 12px; margin-bottom: 8px; background: var(--card); border-left: 3px solid var(--danger); border-radius: 8px; }
.alert.warn { border-left-color: #f0b429; }
.alert.acked { opacity: .5; }
.alert p { margin: 3px 0 0; }

#codes-text { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 13px; letter-spacing: .5px; }
