:root {
  --bg: #0a0b0c;
  --bg-soft: #0c0d0e;
  --fg: #e8eae6;
  --muted: #8a8f8c;
  --line: #2a2d2c;
  --red: #c8322b;
  --red-dim: #7d221d;
  --sans: "PingFang SC", "Hiragino Sans GB", "Noto Sans SC", "Microsoft YaHei", system-ui, sans-serif;
  --mono: ui-monospace, "SFMono-Regular", Menlo, Consolas, monospace;
}

* { box-sizing: border-box; }

html { background: var(--bg); }

body {
  margin: 0;
  min-height: 100%;
  background: var(--bg);
  color: var(--fg);
  font-family: var(--sans);
  font-size: 16px;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
  padding-bottom: env(safe-area-inset-bottom);
}

button, input { font: inherit; color: inherit; }
button { background: none; border: 0; padding: 0; cursor: pointer; }
p, h1 { margin: 0; }
[hidden] { display: none !important; }

::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #2a2d2c; border-radius: 3px; }

.mono {
  font-family: var(--mono);
  font-size: 10px;
  letter-spacing: 0.14em;
  text-transform: uppercase;
}

.rec-dot {
  display: inline-block;
  width: 7px; height: 7px;
  border-radius: 50%;
  background: var(--red);
  animation: pulse 2.4s steps(2, end) infinite;
}
@keyframes pulse { 50% { opacity: 0.25; } }

.scan {
  position: fixed;
  inset: 0;
  z-index: 0;
  pointer-events: none;
  background: repeating-linear-gradient(0deg, rgba(0, 0, 0, 0.18) 0 1px, transparent 1px 3px);
  opacity: 0.45;
}

/* ---------- 顶部 ---------- */

.top {
  position: sticky;
  top: 0;
  z-index: 30;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 16px 20px;
  background: rgba(10, 11, 12, 0.9);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(6px);
}
.brand-name { font-size: 18px; letter-spacing: 0.28em; }
.brand-sub { color: var(--muted); margin-top: 2px; font-size: 9px; }
.top-status { display: flex; align-items: center; gap: 8px; color: var(--muted); }
.top-status.is-recording { color: var(--red); }
.top-status.is-recording .rec-dot { animation-duration: 0.9s; }

/* ---------- 布局 ---------- */

.wrap {
  position: relative;
  z-index: 1;
  width: min(780px, 100%);
  margin: 0 auto;
  padding: 26px 20px calc(150px + env(safe-area-inset-bottom));
}

.privacy {
  font-size: 11px;
  line-height: 1.9;
  color: var(--muted);
  border-left: 1px solid var(--line);
  padding-left: 12px;
  margin-bottom: 28px;
}

.title {
  font-size: clamp(24px, 6vw, 32px);
  font-weight: 400;
  letter-spacing: 0.16em;
  line-height: 1.4;
}
.lead {
  margin-top: 10px;
  font-size: 13px;
  line-height: 1.9;
  color: var(--muted);
  max-width: 38em;
}

.name-field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin: 28px 0 22px;
}
.name-field span { color: var(--muted); }
.name-field input {
  width: 100%;
  height: 44px;
  padding: 0 2px;
  background: transparent;
  border: 0;
  border-bottom: 1px solid var(--line);
  color: var(--fg);
  font-size: 15px;
  outline: none;
  border-radius: 0;
}
.name-field input:focus { border-color: var(--fg); }
.name-field input::placeholder { color: #454a48; }

/* ---------- 角色 ---------- */

.role-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(168px, 1fr));
  gap: 10px;
}

.role-card {
  display: flex;
  flex-direction: column;
  align-items: flex-start;
  gap: 5px;
  min-height: 118px;
  padding: 14px;
  text-align: left;
  background: var(--bg-soft);
  border: 1px solid var(--line);
  border-radius: 2px;
  transition: border-color 160ms, background 160ms, transform 160ms;
}
.role-card:hover,
.role-card:focus-visible {
  border-color: var(--fg);
  background: #111213;
  outline: none;
  transform: translateY(-1px);
}
.role-top {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 8px;
  width: 100%;
}
.role-card .role-name { font-size: 16px; letter-spacing: 0.06em; }
.role-tag {
  font-family: var(--mono);
  font-size: 8px;
  letter-spacing: 0.14em;
  color: var(--red);
  border: 1px solid rgba(200, 50, 43, 0.45);
  padding: 1px 5px;
}
.role-tag.optional { color: var(--muted); border-color: var(--line); }
.role-meta { font-size: 11px; color: var(--muted); }
.role-progress {
  margin-top: auto;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.08em;
  color: var(--muted);
}
.role-card.is-complete .role-progress { color: var(--fg); }

.secure-warn {
  margin-top: 18px;
  padding: 12px 14px;
  border: 1px solid var(--red-dim);
  background: rgba(200, 50, 43, 0.06);
  color: var(--muted);
  font-size: 12px;
  line-height: 1.8;
}
.secure-warn b { color: var(--fg); font-weight: 500; }

.tips {
  margin-top: 34px;
  padding-top: 16px;
  border-top: 1px solid var(--line);
  color: var(--muted);
  font-size: 11px;
  line-height: 2;
}

/* ---------- 麦克风 ---------- */

.record-nav {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}
.back {
  color: var(--muted);
  font-size: 12px;
  letter-spacing: 0.08em;
  padding: 4px 0;
}
.back:hover { color: var(--fg); }

.mic-panel {
  margin-top: 22px;
  padding: 16px;
  border: 1px solid var(--line);
  background: var(--bg-soft);
}
.mic-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
}
.mic-state { color: var(--muted); font-size: 9px; }
.mic-tip { margin-top: 5px; font-size: 11px; line-height: 1.7; color: var(--muted); }
.mic-actions { display: flex; align-items: center; gap: 12px; flex: none; }

.meter {
  display: flex;
  gap: 3px;
  height: 18px;
  margin-top: 14px;
}
.meter span {
  flex: 1;
  background: var(--line);
  border-radius: 1px;
  transition: background 60ms linear;
}
.meter span.on { background: var(--fg); }
.meter span.hot { background: var(--red); }
.meter.idle span { background: var(--line); }

/* ---------- 台词卡 ---------- */

.line-list { margin-top: 22px; }

.line-card {
  padding: 18px;
  margin-bottom: 12px;
  border: 1px solid var(--line);
  border-radius: 2px;
  background: var(--bg-soft);
  transition: border-color 180ms, background 180ms;
}
.line-card.recording {
  border-color: var(--red);
  background: #120d0d;
}
.line-head { display: flex; align-items: center; gap: 10px; }
.line-id { color: var(--fg); font-size: 10px; }
.line-label { color: var(--muted); font-size: 11px; }
.take-count { margin-left: auto; color: var(--muted); font-size: 9px; }

.line-text {
  margin: 12px 0 16px;
  font-size: 15px;
  line-height: 2;
  letter-spacing: 0.02em;
  white-space: pre-line;
}

.line-foot { display: flex; align-items: center; gap: 14px; flex-wrap: wrap; }
.line-status { font-family: var(--mono); font-size: 9px; letter-spacing: 0.08em; color: var(--muted); }
.line-card.recording .line-status { color: var(--red); }

.rec-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  min-height: 40px;
  padding: 8px 16px;
  border: 1px solid rgba(200, 50, 43, 0.55);
  border-radius: 2px;
  color: var(--fg);
  font-size: 12px;
  letter-spacing: 0.08em;
  transition: background 160ms, border-color 160ms;
}
.rec-btn:hover { background: rgba(200, 50, 43, 0.1); }
.rec-btn:disabled { opacity: 0.3; cursor: not-allowed; }
.rec-btn .dot {
  width: 6px; height: 6px;
  border-radius: 50%;
  background: var(--red);
}
.line-card.recording .rec-btn {
  background: var(--red);
  border-color: var(--red);
  color: #fff;
}
.line-card.recording .rec-btn .dot {
  background: #fff;
  animation: pulse 0.9s steps(2, end) infinite;
}

.takes { margin-top: 14px; border-top: 1px solid var(--line); }
.takes:empty { display: none; }
.take {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
  padding: 9px 0;
  border-bottom: 1px solid rgba(42, 45, 44, 0.55);
  font-size: 10px;
}
.take:last-child { border-bottom: 0; }
.take-name {
  flex: 1;
  min-width: 150px;
  font-family: var(--mono);
  font-size: 9px;
  letter-spacing: 0.03em;
  color: var(--muted);
  word-break: break-all;
}
.take-dur { font-family: var(--mono); font-size: 9px; color: var(--muted); }
.take button, .take a {
  font-size: 10px;
  color: var(--muted);
  text-decoration: none;
  padding: 3px 4px;
}
.take button:hover, .take a:hover { color: var(--fg); }
.take .del { color: #6d3a37; }
.take .del:hover { color: var(--red); }
.take.playing .play { color: var(--red); }

/* ---------- 按钮 ---------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 42px;
  padding: 10px 18px;
  border: 1px solid var(--fg);
  border-radius: 2px;
  color: var(--fg);
  font-size: 12px;
  letter-spacing: 0.08em;
  transition: background 160ms, color 160ms, border-color 160ms;
  white-space: nowrap;
}
.btn:hover { background: var(--fg); color: var(--bg); }
.btn:disabled { opacity: 0.4; cursor: wait; }
.btn.small { min-height: 36px; padding: 7px 14px; font-size: 11px; }
.btn.ghost { border-color: var(--line); }
.btn.ghost:hover { border-color: var(--fg); background: rgba(232, 234, 230, 0.05); color: var(--fg); }
.btn-text {
  color: var(--muted);
  font-size: 11px;
  letter-spacing: 0.06em;
  padding: 4px 0;
}
.btn-text:hover { color: var(--fg); }

/* ---------- 底部进度 ---------- */

.sticky {
  position: fixed;
  left: 0; right: 0; bottom: 0;
  z-index: 35;
  display: flex;
  align-items: center;
  gap: 20px;
  padding: 12px max(20px, calc((100vw - 780px) / 2 + 20px)) calc(12px + env(safe-area-inset-bottom));
  background: rgba(10, 11, 12, 0.94);
  border-top: 1px solid var(--line);
  backdrop-filter: blur(8px);
}
.progress { flex: 1; min-width: 120px; }
.progress-text { color: var(--muted); font-size: 9px; }
.progress-track { height: 2px; margin-top: 7px; background: var(--line); overflow: hidden; }
.progress-track span { display: block; height: 100%; width: 0; background: var(--fg); transition: width 220ms ease; }
.sticky-actions { display: flex; gap: 8px; flex: none; }

/* ---------- 倒计时 / 提示 ---------- */

.countdown {
  position: fixed;
  inset: 0;
  z-index: 50;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 10px;
  background: rgba(4, 5, 5, 0.93);
  backdrop-filter: blur(3px);
  cursor: pointer;
}
.countdown .mono { color: var(--muted); }
.countdown-num {
  font-size: clamp(72px, 22vw, 120px);
  font-weight: 200;
  line-height: 1;
  letter-spacing: 0.04em;
}
.countdown-cancel { font-size: 11px; color: var(--line); }

.toast {
  position: fixed;
  left: 50%;
  bottom: calc(96px + env(safe-area-inset-bottom));
  z-index: 60;
  transform: translate(-50%, 6px);
  max-width: 86vw;
  padding: 9px 16px;
  background: rgba(8, 9, 10, 0.96);
  border: 1px solid var(--line);
  color: var(--fg);
  font-size: 12px;
  line-height: 1.7;
  text-align: center;
  opacity: 0;
  transition: opacity 180ms, transform 180ms;
  pointer-events: none;
}
.toast.on { opacity: 1; transform: translate(-50%, 0); }
.toast.red { border-color: rgba(200, 50, 43, 0.5); color: #e6b3b0; }

@media (max-width: 560px) {
  .wrap { padding: 20px 16px calc(170px + env(safe-area-inset-bottom)); }
  .top { padding: 13px 16px; }
  .brand-name { font-size: 16px; }
  .role-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 8px; }
  .role-card { min-height: 112px; padding: 12px; }
  .role-card .role-name { font-size: 15px; }
  .line-card { padding: 15px; }
  .line-text { font-size: 14.5px; line-height: 1.95; }
  .mic-head { flex-direction: column; gap: 10px; }
  .mic-actions { width: 100%; }
  .mic-actions .btn { flex: 1; }
  .sticky { flex-wrap: wrap; gap: 10px; padding: 10px 16px calc(10px + env(safe-area-inset-bottom)); }
  .progress { width: 100%; flex: 1 0 100%; }
  .sticky-actions { width: 100%; }
  .sticky-actions .btn { flex: 1; }
  .toast { bottom: calc(140px + env(safe-area-inset-bottom)); }
}

@media (prefers-reduced-motion: reduce) {
  * { animation-duration: 0.001ms !important; animation-iteration-count: 1 !important; transition-duration: 0.001ms !important; }
}
