
:root {
  --bg: #f5f5f7;
  --card: #ffffff;
  --border: #e8e8ed;
  --text: #1d1d1f;
  --text-dim: #6e6e73;
  --accent: #0071e3;
  --primary: #6c5ce7;
  --success: #34c759;
  --danger: #ff3b30;
  --btn-bg: #f5f5f7;
  --radius: 12px;
  --ring-size: 120px;
}

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

body {
  font-family: -apple-system, BlinkMacSystemFont, "PingFang SC", "Microsoft YaHei", sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  -webkit-font-smoothing: antialiased;
}

header {
  display: flex; align-items: center; gap: 16px;
  padding: 8px 16px;
  position: sticky; top: 0; z-index: 100;
  background: rgba(255,255,255,.85);
  backdrop-filter: blur(12px); -webkit-backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
  flex-wrap: wrap;
}
header nav a:hover { opacity: .7; }
.brand-subtitle { font-size:11px; color:var(--text-dim); margin-left:8px; padding-left:8px; border-left:1.5px solid var(--border); font-weight:400; white-space:nowrap; }

main {
  max-width: 680px;
  margin: 0 auto;
  padding: 24px 16px 40px;
}

.card {
  background: var(--card);
  border-radius: var(--radius);
  padding: 24px;
  margin-bottom: 16px;
  border: 1px solid var(--border);
  transition: box-shadow 0.15s;
}
.card:hover { box-shadow: 0 2px 8px rgba(0,0,0,0.04); }

.card h2 {
  font-size: 16px;
  font-weight: 600;
  margin-bottom: 8px;
  display: flex;
  align-items: center;
  gap: 8px;
}

.badge {
  font-size: 10px;
  background: var(--accent);
  color: #fff;
  padding: 2px 8px;
  border-radius: 10px;
  font-weight: 500;
}

.hint {
  color: var(--text-dim);
  font-size: 13px;
  margin-bottom: 12px;
}

/* Script textarea */
#script-text {
  width: 100%;
  padding: 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  font-size: 15px;
  line-height: 1.8;
  resize: vertical;
  font-family: inherit;
}
#script-text:focus { outline: none; border-color: var(--accent); }

.script-presets {
  margin-top: 10px;
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  font-size: 12px;
  color: var(--text-dim);
}
.script-presets button {
  font-size: 11px;
  padding: 4px 12px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: all 0.15s;
  font-family: inherit;
}
.script-presets button:hover {
  border-color: var(--accent);
  color: var(--accent);
}

/* Record area */
.record-area {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.timer-ring {
  position: relative;
  width: var(--ring-size);
  height: var(--ring-size);
}
.timer-ring svg { transform: rotate(-90deg); }
.timer-ring .ring-bg {
  fill: none;
  stroke: var(--border);
  stroke-width: 6;
}
.timer-ring .ring-progress {
  fill: none;
  stroke: var(--accent);
  stroke-width: 6;
  stroke-linecap: round;
  stroke-dasharray: 339.292;
  stroke-dashoffset: 339.292;
  transition: stroke-dashoffset 0.3s;
}
.timer-ring .ring-progress.recording {
  stroke: var(--danger);
}
#timer-display {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 22px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  color: var(--text);
}

.record-controls {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
  justify-content: center;
}

/* Buttons */
button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  border-radius: 8px;
  padding: 10px 24px;
  font-size: 14px;
  font-weight: 500;
  transition: all 0.15s;
}
button:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-record {
  background: var(--danger);
  color: #fff;
  font-size: 15px;
  padding: 12px 32px;
  border-radius: 24px;
}
.btn-record:hover:not(:disabled) { opacity: 0.9; }
.btn-record.recording { animation: pulse-record 1.5s infinite; }

@keyframes pulse-record {
  0%, 100% { box-shadow: 0 0 0 0 rgba(255,59,48,0.4); }
  50% { box-shadow: 0 0 0 12px rgba(255,59,48,0); }
}

.btn-stop {
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 24px;
}
.btn-stop:hover:not(:disabled) { background: var(--border); }

.btn-play {
  background: var(--btn-bg);
  color: var(--accent);
  border: 1px solid var(--border);
  border-radius: 24px;
}
.btn-play:hover:not(:disabled) { background: var(--border); }

.btn-clone {
  background: var(--accent);
  color: #fff;
  width: 100%;
  padding: 14px;
  font-size: 16px;
  font-weight: 600;
  margin-top: 8px;
  border-radius: 12px;
}
.btn-clone:hover:not(:disabled) { opacity: 0.88; transform: translateY(-1px); }

.btn-test {
  background: var(--success);
  color: #fff;
  border-radius: 16px;
}
.btn-copy {
  background: var(--btn-bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 16px;
}
.btn-reset {
  background: transparent;
  color: var(--text-dim);
  border: 1px solid var(--border);
  border-radius: 16px;
}

/* Clone form */
.clone-form { display: flex; flex-direction: column; gap: 12px; }
.form-row { display: flex; flex-direction: column; gap: 4px; }
.form-row label { font-size: 13px; color: var(--text-dim); }
.form-row input {
  padding: 10px 14px;
  border-radius: 8px;
  border: 1px solid var(--border);
  background: var(--btn-bg);
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
}
.form-row input:focus { outline: none; border-color: var(--accent); }

/* Progress */
.progress-bar {
  margin-top: 12px;
  height: 4px;
  background: var(--border);
  border-radius: 2px;
  overflow: hidden;
  position: relative;
}
.progress-bar-fill {
  height: 100%;
  background: var(--accent);
  border-radius: 2px;
  animation: progress-indeterminate 1.5s infinite;
  width: 40%;
}
@keyframes progress-indeterminate {
  0% { transform: translateX(-100%); }
  100% { transform: translateX(350%); }
}
.progress-text {
  display: block;
  text-align: center;
  font-size: 12px;
  color: var(--text-dim);
  margin-top: 6px;
}

/* Result */
#result-info {
  background: rgba(52,199,89,0.08);
  border: 1px solid rgba(52,199,89,0.2);
  padding: 12px 16px;
  border-radius: 8px;
  margin-bottom: 12px;
}
#result-info .voice-id {
  font-family: "SF Mono", "Fira Code", monospace;
  font-size: 13px;
  color: var(--success);
  word-break: break-all;
}

.result-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* History */
#history-list { display: flex; flex-direction: column; gap: 6px; }
.history-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--btn-bg);
  border-radius: 8px;
  font-size: 13px;
}
.history-item .h-name { font-weight: 500; }
.history-item .h-id { font-family: monospace; font-size: 11px; color: var(--text-dim); }
.history-item button { font-size: 11px; padding: 4px 12px; }

/* Footer */
footer {
  text-align: center;
  padding: 20px;
  color: var(--text-dim);
  font-size: 12px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  padding: 12px 24px;
  border-radius: 8px;
  font-size: 14px;
  z-index: 100;
  animation: toast-in 0.3s ease, toast-out 0.3s ease 2.5s forwards;
}
.toast.success { background: var(--success); color: #fff; }
.toast.error { background: var(--danger); color: #fff; }
.toast.info { background: var(--accent); color: #fff; }

@keyframes toast-in { from { opacity:0; transform:translateX(-50%) translateY(10px); } to { opacity:1; transform:translateX(-50%) translateY(0); } }
@keyframes toast-out { from { opacity:1; } to { opacity:0; } }

@media (max-width: 480px) {
  .card { padding: 16px; }
  .record-controls { flex-direction: column; align-items: center; }
}
