:root {
  --bg: #f6f2ea;
  --bg-soft: #efe8dc;
  --paper: #fffdf9;
  --ink: #211c17;
  --ink-2: #5f574c;
  --muted: #6f665a;
  --line: #e6ded0;
  --line-strong: #d8ccb8;
  --accent: #a8422f;
  --accent-2: #c96f4f;
  --accent-soft: #f4e4dd;
  --gold: #a8874d;
  --shadow: 0 10px 30px rgba(60, 44, 25, 0.07);
  --shadow-sm: 0 2px 10px rgba(60, 44, 25, 0.05);
  --radius: 16px;
  --radius-sm: 10px;
  --serif: "Songti SC", "STSong", "Noto Serif SC", "Source Han Serif SC", "SimSun", serif;
  --sans: -apple-system, BlinkMacSystemFont, "PingFang SC", "Hiragino Sans GB", "Microsoft YaHei", sans-serif;
}

[data-theme="dark"] {
  --bg: #17140f;
  --bg-soft: #201b15;
  --paper: #211c16;
  --ink: #f1e9dc;
  --ink-2: #c7bcaa;
  --muted: #93887a;
  --line: #352c22;
  --line-strong: #4a3d2f;
  --accent: #d0705a;
  --accent-2: #e09a7f;
  --accent-soft: #3a241e;
  --gold: #c2a26a;
  --shadow: 0 10px 30px rgba(0, 0, 0, 0.3);
  --shadow-sm: 0 2px 10px rgba(0, 0, 0, 0.25);
}

* { box-sizing: border-box; }

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

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

a { color: inherit; text-decoration: none; }
button, input, textarea, select { font: inherit; color: inherit; }
img { max-width: 100%; display: block; }

.container {
  width: min(940px, 100% - 32px);
  margin: 0 auto;
}

/* ---------- 顶栏 ---------- */
.topbar {
  position: sticky;
  top: 0;
  z-index: 50;
  background: color-mix(in srgb, var(--bg) 86%, transparent);
  backdrop-filter: blur(14px);
  border-bottom: 1px solid var(--line);
}
.topbar-inner {
  width: min(940px, 100% - 32px);
  margin: 0 auto;
  height: 62px;
  display: flex;
  align-items: center;
  gap: 18px;
}
.brand { display: flex; align-items: center; gap: 10px; flex-shrink: 0; }
.brand-mark {
  width: 32px; height: 32px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  font-family: var(--serif);
  font-size: 19px;
  border-radius: 9px;
  letter-spacing: 0;
  box-shadow: inset 0 0 0 1px rgba(255,255,255,.18);
}
.brand-name {
  font-family: var(--serif);
  font-size: 21px;
  letter-spacing: 0.12em;
  line-height: 1;
  display: flex;
  align-items: baseline;
  gap: 8px;
}
.brand-name em {
  font-family: var(--sans);
  font-style: normal;
  font-size: 11px;
  letter-spacing: 0.2em;
  color: var(--muted);
}
.nav { display: flex; gap: 4px; margin-left: 10px; }
.nav a {
  padding: 7px 12px;
  border-radius: 999px;
  font-size: 14px;
  color: var(--ink-2);
  white-space: nowrap;
}
.nav a:hover { background: var(--bg-soft); color: var(--ink); }
.nav a.active { color: var(--accent); background: var(--accent-soft); }
.userbox { margin-left: auto; position: relative; }
.user-btn {
  display: flex; align-items: center; gap: 8px;
  background: transparent; border: 1px solid var(--line);
  border-radius: 999px; padding: 4px 12px 4px 4px; cursor: pointer;
}
.user-btn:hover { border-color: var(--line-strong); }
.user-name { font-size: 13px; color: var(--ink-2); max-width: 90px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.user-menu {
  position: absolute; right: 0; top: calc(100% + 8px);
  background: var(--paper); border: 1px solid var(--line);
  border-radius: 12px; box-shadow: var(--shadow);
  min-width: 150px; padding: 6px; z-index: 60;
}
.user-menu a, .user-menu button {
  display: block; width: 100%; text-align: left;
  background: none; border: 0; cursor: pointer;
  padding: 9px 12px; border-radius: 8px; font-size: 14px;
}
.user-menu a:hover, .user-menu button:hover { background: var(--bg-soft); }
.avatar { border-radius: 50%; object-fit: cover; flex: none; }
.avatar-text {
  display: inline-grid; place-items: center;
  background: var(--accent-soft); color: var(--accent);
  font-family: var(--serif); border-radius: 50%; flex: none;
}

/* ---------- 通用 ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 11px 22px;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  background: var(--paper);
  color: var(--ink);
  font-size: 15px;
  cursor: pointer;
  transition: transform .12s ease, background .15s ease, border-color .15s ease;
  white-space: nowrap;
}
.btn:hover { border-color: var(--accent-2); }
.btn:active { transform: scale(0.98); }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: #92392a; border-color: #92392a; }
.btn-ghost { background: transparent; }
.btn-sm { padding: 7px 15px; font-size: 13px; }
.btn-block { width: 100%; }
.btn-danger { color: var(--accent); border-color: var(--accent); }

.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}
.section { padding: 34px 0 10px; }
.section-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; margin-bottom: 18px; flex-wrap: wrap;
}
.section-title {
  font-family: var(--serif);
  font-size: 22px;
  letter-spacing: .08em;
  margin: 0;
  display: flex; align-items: center; gap: 10px;
  white-space: nowrap;
}
.section-title::before {
  content: ""; width: 4px; height: 20px; background: var(--accent); border-radius: 2px;
}
.muted { color: var(--muted); }
.small { font-size: 13px; }
.center { text-align: center; }
.row { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.spacer { flex: 1; }
.hidden { display: none !important; }

.tabs { display: inline-flex; background: var(--bg-soft); border-radius: 999px; padding: 4px; gap: 2px; }
.tabs button {
  border: 0; background: transparent; cursor: pointer;
  padding: 7px 16px; border-radius: 999px; font-size: 14px; color: var(--ink-2);
}
.tabs button.active { background: var(--paper); color: var(--ink); box-shadow: var(--shadow-sm); }

/* ---------- 首页 ---------- */
.hero { padding: 58px 0 18px; text-align: center; }
.hero h1 {
  font-family: var(--serif);
  font-size: clamp(38px, 9vw, 64px);
  letter-spacing: .22em;
  margin: 0 0 6px;
  font-weight: 600;
  text-indent: .22em;
}
.hero .sub {
  font-family: var(--serif);
  color: var(--muted);
  letter-spacing: .34em;
  font-size: 14px;
  text-indent: .34em;
}
.hero-rule {
  width: 66px; height: 1px; background: var(--line-strong);
  margin: 24px auto 0; position: relative;
}
.hero-rule::before {
  content: "❖"; position: absolute; left: 50%; top: -13px;
  transform: translateX(-50%); background: var(--bg);
  color: var(--gold); font-size: 11px; padding: 0 6px;
}

.piece-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(250px, 1fr)); gap: 14px; }
.piece-card { padding: 20px; display: block; transition: transform .15s ease, box-shadow .15s ease; }
.piece-card:hover { transform: translateY(-2px); box-shadow: var(--shadow); }
.piece-card .pc-title { font-family: var(--serif); font-size: 19px; letter-spacing: .04em; margin: 0 0 4px; }
.piece-card .pc-author { font-size: 13px; color: var(--muted); }
.piece-card .pc-meta { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.tag {
  display: inline-flex; align-items: center; gap: 4px;
  font-size: 11px; color: var(--ink-2);
  background: var(--bg-soft); border-radius: 999px; padding: 3px 9px;
}
.tag.accent { color: var(--accent); background: var(--accent-soft); }

.work-list { display: grid; grid-template-columns: repeat(auto-fill, minmax(280px, 1fr)); gap: 14px; }
.work-card { padding: 16px; }
.work-top { display: flex; gap: 12px; align-items: center; }
.work-cover {
  width: 52px; height: 52px; border-radius: 12px; flex: none;
  display: grid; place-items: center;
  font-family: var(--serif); font-size: 22px; color: #fff;
  background: linear-gradient(135deg, var(--accent), #7d2f22);
}
.work-card:nth-child(3n+2) .work-cover { background: linear-gradient(135deg, #8a6a3f, #5f4726); }
.work-card:nth-child(3n) .work-cover { background: linear-gradient(135deg, #4f6470, #35454e); }
.work-title { font-family: var(--serif); font-size: 16px; margin: 0; line-height: 1.4; }
.work-by { font-size: 12px; color: var(--muted); margin-top: 3px; display: flex; align-items: center; gap: 5px; }
.work-actions { display: flex; align-items: center; gap: 8px; margin-top: 14px; }
.icon-btn {
  border: 1px solid var(--line); background: transparent; cursor: pointer;
  border-radius: 999px; padding: 6px 12px; font-size: 13px; color: var(--ink-2);
  display: inline-flex; align-items: center; gap: 4px;
}
.icon-btn:hover { border-color: var(--line-strong); color: var(--ink); }
.icon-btn.liked { color: var(--accent); border-color: var(--accent); background: var(--accent-soft); }

/* 自定义播放器 */
.player {
  display: flex; align-items: center; gap: 11px;
  margin-top: 12px; padding: 9px 12px;
  background: var(--bg-soft); border-radius: 12px;
}
.play-toggle {
  width: 38px; height: 38px; border-radius: 50%; border: 0; flex: none;
  background: var(--accent); color: #fff; cursor: pointer;
  display: grid; place-items: center; font-size: 13px;
}
.play-toggle:disabled { opacity: .45; cursor: wait; }
.player-body { flex: 1; min-width: 0; }
.seek {
  -webkit-appearance: none; appearance: none;
  width: 100%; height: 4px; border-radius: 4px; background: var(--line-strong);
  outline: none; cursor: pointer;
}
.seek::-webkit-slider-thumb {
  -webkit-appearance: none; width: 13px; height: 13px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--paper); box-shadow: 0 1px 4px rgba(0,0,0,.2);
}
.time-row { display: flex; justify-content: space-between; font-size: 11px; color: var(--muted); margin-top: 3px; font-variant-numeric: tabular-nums; }

/* ---------- 篇目页 ---------- */
.piece-head { padding: 44px 0 8px; text-align: center; }
.piece-head h1 { font-family: var(--serif); font-size: clamp(28px, 7vw, 42px); letter-spacing: .1em; margin: 0 0 8px; }
.piece-head .author { color: var(--muted); font-size: 14px; letter-spacing: .1em; }
.piece-body { padding: 30px 0 10px; max-width: 640px; margin: 0 auto; }
.piece-body p {
  font-family: var(--serif);
  font-size: 19px; line-height: 2.15;
  margin: 0 0 1.35em;
  letter-spacing: .01em;
  text-align: justify;
}
.piece-body p.indent { text-indent: 2em; }
.piece-actions { display: flex; gap: 10px; justify-content: center; flex-wrap: wrap; margin: 26px 0 8px; }

/* ---------- 表单 ---------- */
.field { margin-bottom: 15px; }
.field label { display: block; font-size: 13px; color: var(--ink-2); margin-bottom: 6px; letter-spacing: .04em; }
.input, .textarea, .select {
  width: 100%; padding: 11px 13px;
  background: var(--paper); color: var(--ink);
  border: 1px solid var(--line-strong); border-radius: var(--radius-sm);
  outline: none; font-size: 15px;
  transition: border-color .15s ease, box-shadow .15s ease;
}
.input:focus, .textarea:focus, .select:focus {
  border-color: var(--accent-2);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--accent) 13%, transparent);
}
.textarea { min-height: 180px; resize: vertical; line-height: 1.9; font-family: var(--serif); }
.range { width: 100%; accent-color: var(--accent); }

/* ---------- 录音台 ---------- */
.record-layout { padding: 22px 0 60px; }
.record-text {
  background: var(--paper); border: 1px solid var(--line);
  border-radius: var(--radius); padding: 26px 26px 12px;
  max-height: 52vh; overflow-y: auto;
  scroll-behavior: smooth;
  font-family: var(--serif);
  font-size: 19px; line-height: 2.1;
}
.record-text p { margin: 0 0 1.15em; opacity: .38; transition: opacity .3s ease; }
.record-text p.current { opacity: 1; }
.record-text p.current::before { content: "▍"; color: var(--accent); margin-left: -.78em; }
.record-text p.done { opacity: .72; }
.text-tools { display: flex; align-items: center; gap: 8px; margin-bottom: 10px; flex-wrap: wrap; }
.text-tools .range { max-width: 130px; }

.recorder { padding: 22px; margin-top: 16px; }
.rec-row { display: flex; align-items: center; justify-content: center; gap: 22px; }
.rec-btn {
  width: 78px; height: 78px; border-radius: 50%;
  border: 0; cursor: pointer;
  background: var(--accent); color: #fff;
  font-size: 15px; letter-spacing: .08em;
  display: grid; place-items: center;
  box-shadow: 0 8px 24px color-mix(in srgb, var(--accent) 40%, transparent);
  transition: transform .12s ease;
}
.rec-btn:active { transform: scale(.96); }
.rec-btn.recording { background: #7d2f22; animation: pulse 1.6s infinite; }
@keyframes pulse {
  0% { box-shadow: 0 0 0 0 rgba(168,66,47,.45); }
  70% { box-shadow: 0 0 0 18px rgba(168,66,47,0); }
  100% { box-shadow: 0 0 0 0 rgba(168,66,47,0); }
}
.rec-time { font-variant-numeric: tabular-nums; font-size: 26px; letter-spacing: .04em; min-width: 78px; text-align: center; }
.wave { width: 100%; height: 64px; display: block; margin-top: 14px; opacity: .85; }
.rec-status { text-align: center; font-size: 13px; color: var(--muted); margin-top: 10px; min-height: 20px; }
.bgm-box { margin-top: 18px; padding-top: 18px; border-top: 1px dashed var(--line); }
.bgm-row { display: grid; grid-template-columns: 1fr auto; gap: 10px; align-items: center; }
.bgm-hint { font-size: 12px; color: var(--muted); margin-top: 8px; line-height: 1.6; }
.mode-toggle { display: flex; gap: 8px; margin-top: 10px; flex-wrap: wrap; }
.chip {
  border: 1px solid var(--line-strong); background: transparent; cursor: pointer;
  border-radius: 999px; padding: 6px 13px; font-size: 13px; color: var(--ink-2);
}
.chip.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }

.preview-box { margin-top: 16px; }
.preview-box audio { width: 100%; }
.result-box { margin-top: 16px; padding: 16px; background: var(--bg-soft); border-radius: 12px; }
.result-box audio { width: 100%; margin: 8px 0; }
.banner {
  padding: 13px 16px; border-radius: 12px; font-size: 14px; line-height: 1.65;
  background: var(--accent-soft); color: var(--ink); border: 1px solid color-mix(in srgb, var(--accent) 25%, transparent);
  margin: 14px 0;
}
.banner.warn { background: #fbf1d8; border-color: #ead9a8; }
[data-theme="dark"] .banner.warn { background: #362c16; border-color: #57461f; }

/* ---------- 接龙 ---------- */
.progress { height: 8px; border-radius: 999px; background: var(--bg-soft); overflow: hidden; }
.progress > i { display: block; height: 100%; background: linear-gradient(90deg, var(--accent), var(--accent-2)); border-radius: 999px; transition: width .4s ease; }
.seg-list { display: grid; gap: 10px; margin-top: 18px; }
.seg-item {
  display: flex; gap: 14px; align-items: flex-start;
  padding: 15px 16px; border: 1px solid var(--line); border-radius: 12px; background: var(--paper);
}
.seg-no {
  width: 30px; height: 30px; flex: none; border-radius: 50%;
  display: grid; place-items: center; font-size: 13px;
  background: var(--bg-soft); color: var(--ink-2);
}
.seg-item.recorded .seg-no { background: var(--accent); color: #fff; }
.seg-item.claimed .seg-no { background: var(--accent-soft); color: var(--accent); }
.seg-main { flex: 1; min-width: 0; }
.seg-text {
  font-family: var(--serif); font-size: 15px; line-height: 1.75;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.seg-meta { font-size: 12px; color: var(--muted); margin-top: 5px; display: flex; align-items: center; gap: 6px; }
.seg-side { flex: none; }

/* ---------- 登录 ---------- */
.login-wrap { min-height: 72vh; display: grid; place-items: center; padding: 30px 0; }
.login-card { max-width: 420px; width: 100%; padding: 34px 28px; text-align: center; }
.login-card h1 { font-family: var(--serif); letter-spacing: .14em; margin: 0 0 8px; font-size: 28px; }
.login-card p { color: var(--muted); font-size: 14px; line-height: 1.9; }
.login-card .btn { margin-top: 18px; }

/* ---------- 管理 ---------- */
.admin-tabs { display: flex; gap: 6px; flex-wrap: wrap; margin: 20px 0; }
.admin-tabs button {
  border: 1px solid var(--line); background: var(--paper); cursor: pointer;
  border-radius: 999px; padding: 8px 16px; font-size: 14px; color: var(--ink-2);
}
.admin-tabs button.active { border-color: var(--accent); color: var(--accent); background: var(--accent-soft); }
.table { width: 100%; border-collapse: collapse; font-size: 13px; }
.table th, .table td { text-align: left; padding: 10px 8px; border-bottom: 1px solid var(--line); vertical-align: middle; }
.table th { color: var(--muted); font-weight: 500; font-size: 12px; letter-spacing: .05em; }
.table tr:hover td { background: var(--bg-soft); }
.mono { font-family: ui-monospace, SFMono-Regular, Menlo, monospace; font-size: 12px; }
.admin-panel { padding: 20px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ---------- 空态 / 加载 ---------- */
.empty { text-align: center; color: var(--muted); padding: 42px 10px; font-size: 14px; }
.empty::before { content: "○"; display: block; font-size: 26px; margin-bottom: 8px; opacity: .4; }
.skeleton { border-radius: 12px; background: linear-gradient(90deg, var(--bg-soft), var(--paper), var(--bg-soft)); background-size: 200% 100%; animation: shimmer 1.4s infinite; height: 92px; }
@keyframes shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

/* ---------- toast ---------- */
.toast {
  position: fixed; left: 50%; bottom: 32px; transform: translate(-50%, 20px);
  background: var(--ink); color: var(--bg);
  padding: 11px 20px; border-radius: 999px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: all .25s ease; z-index: 999;
  max-width: calc(100% - 40px);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast[data-type="error"] { background: #8d2d20; color: #fff; }

/* ---------- 页脚 ---------- */
.foot { padding: 44px 0 40px; text-align: center; color: var(--muted); font-size: 12px; letter-spacing: .12em; }

/* ---------- 响应式 ---------- */
@media (max-width: 640px) {
  .container, .topbar-inner { width: calc(100% - 24px); }
  .topbar-inner { gap: 6px; }
  .brand-name { font-size: 18px; letter-spacing: .05em; }
  .brand-name em { display: none; }
  .brand-mark { width: 29px; height: 29px; font-size: 17px; }
  .nav { margin-left: 2px; gap: 0; }
  .nav a { padding: 6px 7px; font-size: 12px; }
  .user-name { display: none; }
  .user-btn { padding: 3px; border-color: transparent; }
  .user-btn:hover { border-color: var(--line); }
  .section-title { font-size: 20px; }
  #stats { flex-basis: 100%; }
  .hero { padding: 40px 0 12px; }
  .piece-body p { font-size: 18px; line-height: 2.05; }
  .recorder { padding: 16px; }
  .record-text { padding: 20px 20px 8px; font-size: 18px; }
  .form-grid { grid-template-columns: 1fr; }
  .work-list, .piece-grid { grid-template-columns: 1fr; }
  .table { font-size: 12px; }
  .table .hide-m { display: none; }
}
