:root {
  --bg: #0b0d10;
  --panel: #14171f;
  --panel-2: #1a1f29;
  --line: rgba(255, 255, 255, 0.08);
  --line-strong: rgba(255, 255, 255, 0.16);
  --text: #f5f7fa;
  --muted: #98a2b3;
  --dim: #6b7480;
  --accent: #4c8dff;
  --accent-soft: rgba(76, 141, 255, 0.14);
  --ok: #3dd68c;
  --warn: #f5a524;
  --danger: #f2555a;
  --radius: 18px;
}

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

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, "PingFang SC", "Microsoft YaHei", sans-serif;
  -webkit-font-smoothing: antialiased;
  overflow: hidden;
}

body.scrollable { overflow: auto; }

a { color: inherit; text-decoration: none; }
button { font-family: inherit; cursor: pointer; border: none; background: none; color: inherit; }
input, textarea, select { font-family: inherit; }
input[type="checkbox"] { accent-color: var(--accent); cursor: pointer; }

.wrap {
  height: 100%;
  display: flex;
  flex-direction: column;
  padding: 28px 44px 32px;
  gap: 20px;
}

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  flex: none;
}

.brand { display: flex; align-items: center; gap: 14px; }

.brand-logo { height: 46px; width: auto; display: block; }
.brand-divider { width: 1px; height: 30px; background: rgba(255, 255, 255, 0.2); }
.login-logo { height: 62px; width: auto; display: block; margin: 0 auto 26px; }

.logo {
  width: 40px; height: 40px;
  border-radius: 12px;
  background: linear-gradient(135deg, #4c8dff, #2e6be6);
  display: grid; place-items: center;
  font-weight: 700; font-size: 19px; color: #fff;
  letter-spacing: 0;
}

.brand h1 { font-size: 19px; font-weight: 500; letter-spacing: 0.5px; }
.brand .sub { font-size: 13px; color: var(--dim); margin-top: 2px; }

.topbar-right { display: flex; align-items: center; gap: 14px; font-size: 14px; color: var(--muted); }

.btn {
  display: inline-flex; align-items: center; gap: 8px;
  height: 42px; padding: 0 20px;
  border-radius: 12px;
  background: var(--panel-2);
  border: 1px solid var(--line);
  color: var(--text);
  font-size: 15px;
  transition: background 0.15s, border-color 0.15s, transform 0.1s;
  white-space: nowrap;
}
.btn:hover { background: #232a36; border-color: var(--line-strong); }
.btn:active { transform: translateY(1px); }
.btn.primary { background: var(--accent); color: #fff; border-color: transparent; font-weight: 600; }
.btn.primary:hover { background: #6ba1ff; }
.btn.ghost { background: transparent; }
.btn.small { height: 34px; padding: 0 14px; font-size: 13px; border-radius: 10px; }
.btn.danger { color: var(--danger); }
.btn:disabled { opacity: 0.45; cursor: not-allowed; }

.hint { font-size: 13px; color: var(--dim); }
.kbd {
  display: inline-block;
  min-width: 22px; padding: 2px 7px;
  border-radius: 6px;
  border: 1px solid var(--line-strong);
  background: rgba(255, 255, 255, 0.04);
  font-size: 12px; color: var(--muted);
  text-align: center;
  font-family: ui-monospace, Menlo, Consolas, monospace;
}

/* ---------- 首页宫格 ---------- */
.grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
  grid-auto-rows: 200px;
  gap: 18px;
  align-content: start;
}

.card {
  position: relative;
  display: flex; flex-direction: column; justify-content: space-between;
  padding: 28px;
  border-radius: var(--radius);
  background: var(--panel);
  border: 1px solid var(--line);
  transition: border-color 0.18s, background 0.18s, transform 0.18s;
  overflow: hidden;
}
.card:hover { border-color: rgba(76, 141, 255, 0.45); background: var(--panel-2); transform: translateY(-2px); }
.card .icon {
  width: 52px; height: 52px; border-radius: 14px;
  display: grid; place-items: center;
  background: var(--accent-soft);
  color: var(--accent);
  font-size: 22px; font-weight: 600;
}
.card h2 { font-size: 24px; font-weight: 500; margin-top: 18px; }
.card p { font-size: 14px; color: var(--muted); margin-top: 8px; line-height: 1.6; }
.card .arrow { position: absolute; right: 26px; top: 28px; color: var(--dim); font-size: 20px; }

/* ---------- 话题库 ---------- */
.topic-grid {
  flex: 1;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 18px;
  min-height: 0;
}

.topic {
  position: relative;
  display: flex; flex-direction: column; justify-content: flex-start;
  padding: 64px 32px 72px;
  border-radius: 20px;
  background: var(--panel);
  border: 1px solid var(--line);
  min-height: 0;
  overflow: hidden;
  transition: border-color 0.2s, box-shadow 0.2s;
}
.topic:hover { border-color: var(--line-strong); }
.topic.picked { border-color: var(--accent); box-shadow: 0 0 0 1px var(--accent), 0 0 40px -12px rgba(76, 141, 255, 0.55); }

.topic-meta { position: absolute; top: 26px; left: 32px; display: flex; align-items: center; gap: 10px; }
.tag {
  font-size: 12px; padding: 4px 10px; border-radius: 999px;
  background: rgba(255, 255, 255, 0.06); color: var(--muted);
}
.tag.accent { background: var(--accent-soft); color: var(--accent); }

.topic-body {
  display: flex; align-items: center;
  min-height: 0;
  overflow: auto;
}
.topic-text {
  font-size: clamp(28px, 2.6vw, 52px);
  line-height: 1.45;
  font-weight: 500;
  letter-spacing: 0.3px;
}

.topic-extra { margin-top: 26px; }
.topic-extra .row { margin-top: 16px; }
.topic-extra .row:first-child { margin-top: 0; }
.topic-extra .label {
  display: block;
  font-size: 13px;
  color: var(--muted);
  letter-spacing: 0.08em;
  margin-bottom: 6px;
}
.topic-extra .val {
  display: block;
  /* 主话题字号的一半：clamp(28,2.6vw,52) / 2 */
  font-size: clamp(14px, 1.3vw, 26px);
  line-height: 1.55;
  color: #cdd5e0;
}

.topic-actions { position: absolute; bottom: 22px; left: 32px; display: flex; gap: 8px; }

.fav {
  width: 38px; height: 38px; border-radius: 10px;
  display: grid; place-items: center;
  border: 1px solid var(--line);
  color: #6b7480; font-size: 19px; line-height: 1;
  transition: all 0.15s;
}
.fav:hover { color: var(--accent); border-color: var(--accent); }
.fav.on { color: var(--accent); background: var(--accent-soft); border-color: rgba(76, 141, 255, 0.4); }

.footer-bar { flex: none; display: flex; align-items: center; justify-content: space-between; gap: 16px; }
.footer-bar .keys { display: flex; align-items: center; gap: 18px; font-size: 13px; color: var(--dim); }
.footer-bar .keys span { display: inline-flex; align-items: center; gap: 6px; }

/* 隐藏 UI（采集用） */
body.bare .topbar,
body.bare .footer-bar,
body.bare .topic-actions,
body.bare .topic-extra,
body.bare .topic-meta { display: none; }

body.bare .wrap { padding: 24px; }
body.bare .topic {
  border-color: transparent; background: transparent;
  justify-content: flex-start; padding: 11vh 28px 0;
}
body.bare .topic-body { justify-content: center; text-align: center; }
body.bare .topic-text { font-size: clamp(34px, 3.4vw, 62px); line-height: 1.35; }
body.bare .topic.picked { box-shadow: none; border-color: transparent; }

.bare-hint {
  position: fixed; left: 50%; bottom: 14px; transform: translateX(-50%);
  font-size: 12px; color: rgba(255, 255, 255, 0.28);
  opacity: 0; transition: opacity 0.4s;
  pointer-events: none;
}
body.bare .bare-hint { opacity: 1; }

/* ---------- 转盘 ---------- */
.wheel-stage {
  flex: 1;
  display: grid;
  place-items: center;
  min-height: 0;
  position: relative;
}
#wheel { height: 100%; aspect-ratio: 1; max-width: 100%; }
.wheel-result {
  position: absolute; inset: auto 0 8% 0;
  text-align: center;
  font-size: clamp(30px, 3.2vw, 56px);
  font-weight: 600; color: var(--accent);
  opacity: 0; transform: translateY(10px);
  transition: opacity 0.35s, transform 0.35s;
  pointer-events: none;
}
.wheel-result.show { opacity: 1; transform: translateY(0); }

/* ---------- 登录 ---------- */
.login-page { display: grid; place-items: center; height: 100%; }
.login-card {
  width: 380px; padding: 40px 36px;
  border-radius: 22px;
  background: var(--panel);
  border: 1px solid var(--line);
}
.login-card .logo { margin-bottom: 22px; }
.login-card h1 { font-size: 22px; font-weight: 500; text-align: center; }
.login-card .sub { font-size: 14px; color: var(--muted); margin-top: 6px; text-align: center; }
.field { margin-top: 20px; }
.field label { display: block; font-size: 13px; color: var(--muted); margin-bottom: 8px; }
.field input {
  width: 100%; height: 46px; padding: 0 14px;
  border-radius: 11px;
  background: #0e1116;
  border: 1px solid var(--line);
  color: var(--text); font-size: 15px;
  outline: none; transition: border-color 0.15s;
}
.field input:focus { border-color: var(--accent); }
.login-card .btn { width: 100%; justify-content: center; margin-top: 26px; height: 48px; }
.login-err { color: var(--danger); font-size: 13px; margin-top: 14px; min-height: 18px; }

/* ---------- 后台 ---------- */
.admin-layout { display: flex; gap: 0; height: 100%; }
.sidebar {
  width: 190px; flex: none;
  border-right: 1px solid var(--line);
  padding: 24px 14px;
  display: flex; flex-direction: column; gap: 4px;
}
.sidebar .item {
  padding: 11px 14px; border-radius: 10px;
  font-size: 14px; color: var(--muted);
  text-align: left; width: 100%;
  transition: background 0.15s, color 0.15s;
}
.sidebar .item:hover { background: rgba(255, 255, 255, 0.04); color: var(--text); }
.sidebar .item.active { background: var(--accent-soft); color: var(--accent); }
.sidebar .spacer { flex: 1; }

.admin-main { flex: 1; padding: 26px 30px; overflow: auto; min-width: 0; }
.admin-head { display: flex; align-items: center; justify-content: space-between; gap: 16px; margin-bottom: 20px; }
.admin-head h2 { font-size: 20px; font-weight: 500; }

.stats-row { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat { padding: 20px; border-radius: 14px; background: var(--panel); border: 1px solid var(--line); }
.stat .n { font-size: 30px; font-weight: 600; }
.stat .l { font-size: 13px; color: var(--muted); margin-top: 4px; }

table { width: 100%; border-collapse: collapse; font-size: 14px; }
th, td { text-align: left; padding: 12px 10px; border-bottom: 1px solid var(--line); vertical-align: middle; }
th { font-size: 12px; font-weight: 500; color: var(--dim); text-transform: none; position: sticky; top: 0; background: var(--bg); }
tr:hover td { background: rgba(255, 255, 255, 0.02); }
td .muted { color: var(--dim); font-size: 12px; }

.pill { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: 12px; }
.pill.ok { background: rgba(61, 214, 140, 0.14); color: var(--ok); }
.pill.off { background: rgba(152, 162, 179, 0.14); color: var(--muted); }
.pill.warn { background: rgba(245, 165, 36, 0.14); color: var(--warn); }

.input, .textarea, .select {
  width: 100%; padding: 10px 12px;
  border-radius: 10px;
  background: #0e1116;
  border: 1px solid var(--line);
  color: var(--text); font-size: 14px; outline: none;
}
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.textarea { min-height: 120px; resize: vertical; font-family: ui-monospace, Menlo, Consolas, monospace; font-size: 13px; line-height: 1.6; }
.form-row { display: flex; gap: 10px; align-items: center; margin-bottom: 14px; flex-wrap: wrap; }
.form-row > * { flex: none; }
.form-row .grow { flex: 1; min-width: 180px; }

.modal-mask {
  position: fixed; inset: 0; background: rgba(0, 0, 0, 0.6);
  display: none; place-items: center; z-index: 50;
}
.modal-mask.show { display: grid; }
.modal {
  width: min(680px, 92vw); max-height: 86vh; overflow: auto;
  background: var(--panel); border: 1px solid var(--line-strong);
  border-radius: 18px; padding: 26px;
}
.modal h3 { font-size: 18px; font-weight: 500; margin-bottom: 18px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 22px; }

/* ---------- toast ---------- */
#toast-wrap { position: fixed; left: 50%; bottom: 40px; transform: translateX(-50%); display: flex; flex-direction: column; gap: 8px; z-index: 99; }
.toast {
  padding: 11px 20px; border-radius: 11px;
  background: #232a36; border: 1px solid var(--line-strong);
  font-size: 14px; color: var(--text);
  animation: toastIn 0.22s ease;
  white-space: nowrap;
}
.toast.err { border-color: rgba(242, 85, 90, 0.5); color: #ffb4b6; }
.toast.ok { border-color: rgba(61, 214, 140, 0.4); color: #a8f0cd; }
@keyframes toastIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: none; } }

.empty { padding: 60px 20px; text-align: center; color: var(--dim); font-size: 14px; }

@media (max-width: 1200px) {
  .topic-grid { grid-template-columns: 1fr; }
  .wrap { padding: 18px; }
}
