:root {
  --fallback-page: #f7f7f8;
  --fallback-surface: #ffffff;
  --fallback-surface-soft: #f7f7f8;
  --fallback-text: #17191c;
  --fallback-muted: #8a8e94;
  --fallback-link: #087bfa;
  --page-bg: var(--tg-theme-secondary-bg-color, var(--fallback-page));
  --surface: var(--tg-theme-bg-color, var(--fallback-surface));
  --surface-soft: var(--tg-theme-secondary-bg-color, var(--fallback-surface-soft));
  --text: var(--tg-theme-text-color, var(--fallback-text));
  --muted: var(--tg-theme-hint-color, var(--fallback-muted));
  --primary: var(--tg-theme-button-color, var(--fallback-link));
  --primary-text: var(--tg-theme-button-text-color, #ffffff);
  --link: var(--tg-theme-link-color, var(--fallback-link));
  --danger: #f22535;
  --success: #0ba471;
  --warning: #b76d00;
  --border: rgba(127, 127, 127, 0.2);
  --border-strong: rgba(127, 127, 127, 0.38);
  --shadow: 0 10px 32px rgba(22, 29, 37, 0.12);
  --shadow-soft: 0 2px 8px rgba(22, 29, 37, 0.07);
  --radius: 14px;
  --radius-small: 9px;
  color-scheme: light dark;
  font-family:
    Inter, "PingFang SC", "Microsoft YaHei", system-ui, -apple-system,
    BlinkMacSystemFont, "Segoe UI", sans-serif;
  font-synthesis: none;
  text-rendering: optimizeLegibility;
}

:root[data-theme="dark"] {
  --fallback-page: #111418;
  --fallback-surface: #1a1e23;
  --fallback-surface-soft: #20252b;
  --fallback-text: #f4f6f8;
  --fallback-muted: #a5aab2;
  --border: rgba(255, 255, 255, 0.12);
  --border-strong: rgba(255, 255, 255, 0.25);
  --shadow: 0 14px 38px rgba(0, 0, 0, 0.36);
  --shadow-soft: 0 2px 8px rgba(0, 0, 0, 0.22);
}

* {
  box-sizing: border-box;
}

html {
  min-width: 280px;
  min-height: 100%;
  background: var(--page-bg);
}

body {
  min-width: 280px;
  min-height: 100vh;
  min-height: 100dvh;
  margin: 0;
  overflow-x: hidden;
  background: var(--page-bg);
  color: var(--text);
  -webkit-tap-highlight-color: transparent;
}

body.modal-open {
  overflow: hidden;
}

button,
input,
textarea,
select {
  font: inherit;
}

button {
  color: inherit;
}

button:not(:disabled) {
  cursor: pointer;
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.56;
}

[hidden] {
  display: none !important;
}

.app-shell {
  width: min(100%, 1240px);
  margin: 0 auto;
  padding:
    max(28px, env(safe-area-inset-top), var(--tg-safe-area-inset-top, 0px))
    max(32px, env(safe-area-inset-right), var(--tg-safe-area-inset-right, 0px))
    max(36px, env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px))
    max(32px, env(safe-area-inset-left), var(--tg-safe-area-inset-left, 0px));
}

.page-header {
  margin-bottom: 30px;
}

.page-header .user-usage-title,
.dub-view__header .user-usage-title,
.user-usage-title {
  margin: 0 0 8px;
  color: var(--link);
  font-size: 0.98rem;
  font-weight: 650;
  letter-spacing: -0.02em;
}

.page-header h1 {
  margin: 0;
  font-size: clamp(2rem, 4vw, 2.65rem);
  line-height: 1.18;
  letter-spacing: -0.045em;
}

.page-header p {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 1.02rem;
}

.dev-banner,
.message-panel {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  margin: -8px 0 24px;
  padding: 13px 16px;
  border: 1px solid rgba(232, 151, 22, 0.36);
  border-radius: var(--radius-small);
  background: rgba(232, 151, 22, 0.1);
  color: var(--text);
  font-size: 0.9rem;
}

.dev-banner__dot {
  flex: 0 0 auto;
  width: 9px;
  height: 9px;
  margin-top: 5px;
  border-radius: 50%;
  background: #e89716;
  box-shadow: 0 0 0 4px rgba(232, 151, 22, 0.15);
}

.message-panel {
  margin: 0 0 24px;
  border-color: var(--border);
  background: var(--surface);
}

.message-panel--danger {
  border-color: rgba(242, 37, 53, 0.35);
  background: rgba(242, 37, 53, 0.08);
}

.message-panel > .icon {
  flex: 0 0 auto;
  width: 24px;
  height: 24px;
  color: var(--danger);
}

.message-panel h2 {
  margin: 0;
  font-size: 1rem;
}

.message-panel p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.9rem;
}

.text-button {
  margin: 8px 0 0;
  padding: 0;
  border: 0;
  background: none;
  color: var(--link);
  font-weight: 650;
}

.voices-grid,
.loading-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(min(285px, 100%), 1fr));
  gap: 24px;
}

.loading-grid {
  margin-top: 24px;
}

.add-card,
.voice-card,
.skeleton-card {
  min-height: 224px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.add-card {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  width: 100%;
  padding: 28px 20px;
  text-align: center;
  transition:
    border-color 160ms ease,
    box-shadow 160ms ease,
    transform 160ms ease;
}

.add-card:not(:disabled):hover {
  border-color: color-mix(in srgb, var(--primary) 48%, transparent);
  box-shadow: var(--shadow);
  transform: translateY(-2px);
}

.add-card__icon {
  display: grid;
  width: 58px;
  height: 58px;
  margin-bottom: 20px;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
}

.add-card__icon .icon {
  width: 29px;
  height: 29px;
}

.add-card__title {
  font-size: 1rem;
  font-weight: 750;
}

.add-card__description {
  margin-top: 9px;
  color: var(--muted);
  font-size: 0.83rem;
  line-height: 1.5;
}

.voice-card {
  position: relative;
  display: flex;
  flex-direction: column;
  min-width: 0;
  padding: 22px;
}

.voice-card__top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
}

.voice-card__icon {
  display: grid;
  width: 54px;
  height: 54px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 12px;
  background: var(--surface-soft);
  color: color-mix(in srgb, var(--text) 72%, transparent);
}

.voice-card__icon .icon {
  width: 28px;
  height: 28px;
}

.voice-card__menu-button {
  display: grid;
  width: 34px;
  height: 34px;
  margin: -5px -7px 0 0;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.voice-card__menu-button:hover,
.voice-card__menu-button[aria-expanded="true"] {
  background: var(--surface-soft);
}

.voice-card__menu-button .icon {
  width: 21px;
  height: 21px;
}

.voice-card__menu {
  position: absolute;
  z-index: 10;
  top: 52px;
  right: 20px;
  min-width: 132px;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface);
  box-shadow: var(--shadow);
}

.voice-menu-item {
  display: flex;
  align-items: center;
  width: 100%;
  gap: 10px;
  padding: 10px;
  border: 0;
  border-radius: 7px;
  background: transparent;
  text-align: left;
  white-space: nowrap;
}

.voice-menu-item:hover {
  background: var(--surface-soft);
}

.voice-menu-item .icon {
  width: 17px;
  height: 17px;
}

.voice-menu-item--danger {
  color: var(--danger);
}

.voice-card__content {
  min-width: 0;
  margin-top: 18px;
}

.voice-card__name {
  overflow: hidden;
  margin: 0;
  font-size: 1.13rem;
  line-height: 1.35;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.voice-card__meta {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 6px;
  margin: 3px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.voice-card__meta time {
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.status-badge {
  display: inline-flex;
  align-items: center;
  margin-top: 7px;
  padding: 3px 8px;
  border-radius: 999px;
  background: rgba(232, 151, 22, 0.12);
  color: var(--warning);
  font-size: 0.74rem;
  font-weight: 650;
}

.voice-card__actions {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 11px;
  margin-top: auto;
  padding-top: 16px;
}

.card-button,
.primary-button,
.secondary-button,
.danger-button,
.small-button {
  display: inline-flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border-radius: 6px;
  font-weight: 680;
  transition:
    filter 140ms ease,
    background 140ms ease,
    border-color 140ms ease;
}

.card-button {
  border: 1px solid var(--primary);
  background: transparent;
  color: var(--primary);
}

.card-button--primary,
.primary-button {
  border: 1px solid var(--primary);
  background: var(--primary);
  color: var(--primary-text);
  box-shadow: 0 3px 7px color-mix(in srgb, var(--primary) 24%, transparent);
}

.card-button:hover,
.primary-button:hover,
.choose-file-bar:hover {
  filter: brightness(0.96);
}

.card-button .icon {
  width: 17px;
  height: 17px;
}

.skeleton-card {
  position: relative;
  overflow: hidden;
  background:
    linear-gradient(var(--surface-soft), var(--surface-soft)) 22px 22px / 54px 54px no-repeat,
    linear-gradient(var(--surface-soft), var(--surface-soft)) 22px 98px / 48% 17px no-repeat,
    linear-gradient(var(--surface-soft), var(--surface-soft)) 22px 126px / 65% 12px no-repeat,
    var(--surface);
}

.skeleton-card::after {
  position: absolute;
  inset: 0;
  background: linear-gradient(100deg, transparent 25%, rgba(255, 255, 255, 0.24) 50%, transparent 75%);
  content: "";
  transform: translateX(-100%);
  animation: shimmer 1.3s infinite;
}

.active-jobs {
  display: grid;
  gap: 10px;
  margin: 0 0 22px;
}

.job-card {
  display: flex;
  min-height: 46px;
  align-items: center;
  gap: 11px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius-small);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.job-card .spinner {
  width: 21px;
  height: 21px;
  border-width: 3px;
}

.job-card__copy {
  display: flex;
  min-width: 0;
  flex: 1;
  flex-wrap: wrap;
  align-items: baseline;
  gap: 5px;
  font-size: 0.9rem;
}

.job-card__copy strong {
  font-variant-numeric: tabular-nums;
}

.job-card__detail {
  color: var(--muted);
  font-size: 0.8rem;
}

.job-card--failed {
  border-color: rgba(242, 37, 53, 0.35);
  background: rgba(242, 37, 53, 0.07);
}

.job-card--failed .job-card__copy {
  color: var(--danger);
}

.job-card__dismiss {
  display: grid;
  width: 30px;
  height: 30px;
  flex: 0 0 auto;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.job-card__dismiss:hover {
  background: rgba(127, 127, 127, 0.12);
}

.job-card__dismiss .icon {
  width: 17px;
  height: 17px;
}

.modal-layer {
  position: fixed;
  z-index: 100;
  inset: 0;
  display: grid;
  overflow: auto;
  padding:
    max(16px, env(safe-area-inset-top), var(--tg-content-safe-area-inset-top, 0px))
    max(16px, env(safe-area-inset-right), var(--tg-content-safe-area-inset-right, 0px))
    max(16px, env(safe-area-inset-bottom), var(--tg-content-safe-area-inset-bottom, 0px))
    max(16px, env(safe-area-inset-left), var(--tg-content-safe-area-inset-left, 0px));
  place-items: center;
  background: rgba(0, 0, 0, 0.43);
  backdrop-filter: blur(5px);
  overscroll-behavior: contain;
}

.modal {
  position: relative;
  width: 100%;
  max-height: calc(100vh - 32px);
  max-height: calc(100dvh - 32px);
  overflow: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow);
}

.modal--large {
  width: min(100%, 880px);
  padding: 24px;
}

.modal--compact {
  width: min(100%, 430px);
  padding: 22px;
}

.modal__header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 18px;
}

.modal__header h2 {
  margin: 0;
  font-size: 1.17rem;
}

.icon-button {
  display: grid;
  width: 36px;
  height: 36px;
  padding: 0;
  place-items: center;
  border: 0;
  border-radius: 50%;
  background: transparent;
}

.icon-button:hover {
  background: var(--surface-soft);
}

.icon-button .icon {
  width: 23px;
  height: 23px;
}

.modal__close {
  flex: 0 0 auto;
  margin: -8px -8px 0 0;
}

.clone-view {
  min-width: 0;
}

.choose-file-bar {
  display: flex;
  width: 100%;
  min-height: 44px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid var(--primary);
  border-radius: 9px;
  background: var(--primary);
  color: var(--primary-text);
  font-weight: 680;
  box-shadow: 0 3px 7px color-mix(in srgb, var(--primary) 22%, transparent);
}

.choose-file-bar .icon {
  width: 20px;
  height: 20px;
}

.drop-zone {
  display: flex;
  min-height: 255px;
  align-items: center;
  justify-content: center;
  flex-direction: column;
  gap: 9px;
  margin-top: 14px;
  padding: 28px;
  border: 2px dashed var(--border);
  border-radius: var(--radius);
  outline: none;
  text-align: center;
  transition:
    border-color 150ms ease,
    background 150ms ease;
}

.drop-zone:hover,
.drop-zone:focus-visible,
.drop-zone.is-dragging {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 5%, transparent);
}

.drop-zone__icon {
  display: grid;
  width: 72px;
  height: 72px;
  margin-bottom: 14px;
  place-items: center;
  border-radius: 50%;
  background: color-mix(in srgb, var(--primary) 12%, transparent);
  color: var(--primary);
}

.drop-zone__icon .icon {
  width: 37px;
  height: 37px;
}

.drop-zone strong {
  font-size: 0.96rem;
}

.drop-zone > span:last-child {
  color: var(--muted);
  font-size: 0.82rem;
  line-height: 1.5;
}

.file-loading {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 11px;
  min-height: 255px;
  margin-top: 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--muted);
}

.tips-panel {
  margin-top: 14px;
  padding: 16px;
  border-radius: 10px;
  background: var(--surface-soft);
}

.tips-panel h3 {
  margin: 0;
  font-size: 0.88rem;
  font-weight: 500;
}

.tips-panel ul {
  display: grid;
  gap: 8px;
  margin: 10px 0 0;
  padding: 0 0 0 18px;
  font-size: 0.83rem;
  line-height: 1.45;
}

.tips-panel li::marker {
  color: var(--primary);
}

.audio-summary {
  display: flex;
  min-height: 45px;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  padding: 0 16px;
  border-radius: 10px 10px 0 0;
  background: var(--surface-soft);
  font-size: 0.85rem;
}

.crop-summary {
  overflow: hidden;
  color: var(--link);
  font-size: 0.78rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.waveform-shell {
  position: relative;
  min-height: 100px;
  overflow: hidden;
  background: #0c5482;
}

#waveform {
  width: 100%;
  min-height: 100px;
}

#waveform ::part(region) {
  border-right: 3px solid #13d4e8;
  border-left: 3px solid #13d4e8;
  background: rgba(23, 212, 232, 0.12) !important;
}

#waveform ::part(region-handle-left),
#waveform ::part(region-handle-right) {
  width: 9px !important;
  border-color: #13d4e8 !important;
}

.crop-range {
  display: grid;
  grid-template-columns: 1fr auto 1fr;
  align-items: center;
  gap: 8px;
  margin-top: 5px;
  color: var(--muted);
  font-size: 0.75rem;
  font-variant-numeric: tabular-nums;
}

.crop-range strong {
  color: var(--text);
  font-size: 0.78rem;
}

.crop-range span:last-child {
  text-align: right;
}

.editor-controls {
  display: flex;
  min-height: 68px;
  align-items: center;
  justify-content: center;
  flex-wrap: wrap;
  gap: 12px;
  padding-top: 14px;
}

.small-button {
  min-height: 34px;
  padding: 5px 14px;
  border: 1px solid var(--text);
  background: transparent;
  color: var(--text);
  font-size: 0.82rem;
}

.small-button--primary {
  border-color: var(--primary);
  background: var(--primary);
  color: var(--primary-text);
}

.small-button .icon {
  width: 16px;
  height: 16px;
}

.clone-submit-area {
  margin-top: 30px;
}

.primary-button {
  width: 100%;
  min-height: 42px;
  padding: 8px 18px;
}

.primary-button--fit {
  width: auto;
  min-width: 92px;
}

.secondary-button,
.danger-button {
  min-width: 92px;
  min-height: 40px;
  padding: 7px 16px;
}

.secondary-button {
  border: 1px solid var(--border-strong);
  background: transparent;
}

.danger-button {
  border: 1px solid var(--danger);
  background: var(--danger);
  color: #fff;
}

.upload-status {
  overflow: hidden;
  min-height: 42px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface);
}

.upload-status__label {
  display: flex;
  min-height: 40px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  padding: 7px 12px;
  font-size: 0.85rem;
}

.progress-track {
  height: 4px;
  overflow: hidden;
  background: color-mix(in srgb, var(--primary) 15%, transparent);
}

.progress-track > span {
  display: block;
  width: 0;
  height: 100%;
  background: var(--primary);
  transition: width 140ms linear;
}

.progress-track.is-indeterminate > span {
  width: 42%;
  animation: indeterminate 1.2s ease-in-out infinite;
}

.inline-alert,
.field-error {
  color: var(--danger);
  font-size: 0.83rem;
}

.inline-alert {
  margin: -4px 0 14px;
  padding: 10px 12px;
  border: 1px solid rgba(242, 37, 53, 0.3);
  border-radius: 7px;
  background: rgba(242, 37, 53, 0.07);
}

.field-label {
  display: block;
  margin-bottom: 8px;
  font-size: 0.86rem;
  font-weight: 650;
}

.text-input {
  width: 100%;
  height: 43px;
  padding: 0 12px;
  border: 1px solid var(--border-strong);
  border-radius: 7px;
  outline: none;
  background: var(--surface);
  color: var(--text);
}

.text-input:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}

.field-error {
  margin: 8px 0 0;
}

.confirm-copy {
  margin: 0;
  color: var(--muted);
  line-height: 1.65;
}

.confirm-copy strong {
  color: var(--text);
}

.modal__actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 24px;
}

.dub-view {
  width: min(100%, 1000px);
  margin: 0 auto;
}

.dub-view__header {
  display: flex;
  align-items: center;
  gap: 14px;
  margin-bottom: 24px;
}

.dub-view__header h1 {
  margin: 0;
  font-size: clamp(1.7rem, 4vw, 2.25rem);
  line-height: 1.2;
}

.dub-view__header p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.92rem;
}

.dub-back-button {
  display: grid;
  width: 43px;
  height: 43px;
  flex: 0 0 auto;
  padding: 0;
  place-items: center;
  border: 1px solid var(--border);
  border-radius: 50%;
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.dub-back-button:hover {
  background: var(--surface-soft);
}

.dub-back-button .icon {
  width: 22px;
  height: 22px;
}

.dub-panel {
  padding: clamp(18px, 4vw, 30px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
  box-shadow: var(--shadow-soft);
}

.dub-voice-bar {
  display: flex;
  min-width: 0;
  align-items: center;
  gap: 13px;
  margin-bottom: 18px;
}

.dub-voice-bar > strong {
  overflow: hidden;
  min-width: 0;
  flex: 1;
  font-size: 1.05rem;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.dub-voice-change {
  min-width: 96px;
  margin-left: auto;
}

.dub-composer {
  position: relative;
}

.dub-textarea {
  display: block;
  width: 100%;
  min-height: 250px;
  resize: vertical;
  padding: 14px 14px 42px;
  border: 1px solid var(--border-strong);
  border-radius: 8px;
  outline: none;
  background: var(--surface);
  color: var(--text);
  line-height: 1.65;
}

.dub-textarea::placeholder {
  color: var(--muted);
}

.dub-textarea:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 15%, transparent);
}

.dub-counter {
  position: absolute;
  right: 13px;
  bottom: 11px;
  display: flex;
  align-items: center;
  gap: 9px;
  padding-left: 8px;
  background: var(--surface);
  color: var(--muted);
  font-size: 0.82rem;
  font-variant-numeric: tabular-nums;
}

.dub-counter strong {
  color: inherit;
  font-weight: 500;
}

.dub-clear {
  margin: 0;
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 500;
}

.dub-annotated {
  margin: 10px 0 0;
  padding: 10px 12px;
  border: 1px dashed color-mix(in srgb, var(--primary) 35%, var(--border));
  border-radius: 8px;
  background: color-mix(in srgb, var(--primary) 6%, var(--surface));
  color: var(--text);
  font-size: 0.9rem;
  line-height: 1.7;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.dub-annotation {
  color: var(--primary);
  font-weight: 650;
}

.dub-tools {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 10px;
  margin-top: 14px;
}

.tool-button {
  min-height: 34px;
  padding: 5px 13px;
  border: 1px solid var(--border);
  border-radius: 6px;
  background: var(--surface-soft);
  font-size: 0.82rem;
  font-weight: 650;
}

.tool-button:hover {
  border-color: var(--border-strong);
  filter: brightness(0.98);
}

.tool-button--link {
  padding-inline: 2px;
  border-color: transparent;
  background: transparent;
  color: var(--link);
}

.dub-error {
  margin: 14px 0 0;
}

.dub-generate {
  min-height: 48px;
  margin-top: 20px;
  font-size: 1rem;
}

.dub-session-hint {
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.8rem;
  line-height: 1.5;
}

.tts-status {
  display: flex;
  min-height: 74px;
  align-items: center;
  justify-content: center;
  gap: 13px;
  margin-top: 14px;
  padding: 13px 18px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
}

.tts-status[data-status="failed"] {
  border-color: rgba(242, 37, 53, 0.35);
  background: rgba(242, 37, 53, 0.07);
  color: var(--danger);
}

.tts-status[data-status="failed"] .spinner {
  display: none;
}

.tts-status strong {
  display: block;
}

.tts-status p {
  margin: 4px 0 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.tts-result {
  margin-top: 18px;
  padding: 18px;
  border: 1px solid color-mix(in srgb, var(--success) 36%, var(--border));
  border-radius: 10px;
  background: color-mix(in srgb, var(--success) 6%, var(--surface));
}

.tts-result__heading {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 15px;
}

.tts-result__heading h2 {
  margin: 0;
  font-size: 1rem;
}

.tts-result__heading p {
  margin: 5px 0 0;
  color: var(--muted);
  font-size: 0.82rem;
}

.success-mark {
  display: grid;
  width: 28px;
  height: 28px;
  flex: 0 0 auto;
  place-items: center;
  border-radius: 50%;
  background: var(--success);
  color: #fff;
  font-weight: 800;
}

.tts-result audio {
  display: block;
  width: 100%;
}

.tts-result__actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 14px;
  color: var(--muted);
  font-size: 0.84rem;
}

.tts-download {
  min-width: 132px;
  min-height: 42px;
  justify-content: center;
  gap: 8px;
  margin-left: auto;
  padding-inline: 18px;
  font-size: 0.88rem;
  font-weight: 700;
  box-shadow: 0 4px 10px color-mix(in srgb, var(--primary) 28%, transparent);
}

.tts-download .icon {
  width: 18px;
  height: 18px;
}

.tts-speed-trigger {
  min-width: 108px;
  min-height: 42px;
}

.speed-modal {
  width: min(100%, 920px);
  padding: 24px;
}

.speed-waveform-panel {
  padding: 14px 12px 8px;
  border: 1px solid var(--border);
  border-radius: 9px;
  background: var(--surface-soft);
}

.speed-waveform {
  position: relative;
  min-height: 112px;
}

.speed-waveform:empty::before {
  position: absolute;
  inset: 0;
  display: grid;
  place-items: center;
  color: var(--muted);
  content: "波形加载中…";
  font-size: 0.84rem;
}

.speed-time-row {
  display: flex;
  justify-content: space-between;
  margin-top: 4px;
  color: var(--muted);
  font-size: 0.78rem;
  font-variant-numeric: tabular-nums;
}

.speed-control {
  display: grid;
  grid-template-columns: 34px minmax(120px, 1fr) 34px 72px;
  align-items: center;
  gap: 12px;
  margin-top: 18px;
  padding: 16px 18px;
  border-radius: 9px;
  background: var(--surface-soft);
}

.speed-control__animal {
  display: grid;
  min-width: 30px;
  place-items: center;
  filter: grayscale(0.25);
  font-size: 1.28rem;
  line-height: 1;
}

.speed-range {
  width: 100%;
  height: 30px;
  margin: 0;
  accent-color: var(--primary);
  cursor: pointer;
}

.speed-value {
  color: var(--text);
  font-size: 0.94rem;
  font-weight: 750;
  font-variant-numeric: tabular-nums;
  text-align: right;
}

.speed-error {
  margin-top: 12px;
}

.speed-actions {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 20px;
}

.speed-actions__spacer {
  flex: 1 1 auto;
}

.speed-action {
  min-width: 112px;
  min-height: 42px;
  gap: 8px;
}

.speed-action .icon {
  width: 18px;
  height: 18px;
}

.modal-hint {
  margin: -7px 0 15px;
  color: var(--muted);
  font-size: 0.84rem;
  line-height: 1.55;
}

.optimize-modal {
  width: min(100%, 620px);
}

.optimize-preview {
  max-height: min(46vh, 360px);
  overflow: auto;
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--surface-soft);
  font-size: 0.92rem;
  line-height: 1.65;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.dub-tips-list {
  display: grid;
  gap: 12px;
  margin: 0;
  padding-left: 22px;
  color: var(--muted);
  font-size: 0.88rem;
  line-height: 1.6;
}

.dub-tips-list li::marker {
  color: var(--primary);
}

.modal-layer--fullscreen {
  align-items: center;
}

.modal--pronunciation {
  display: flex;
  width: min(92vw, 920px);
  height: min(74vh, 620px);
  height: min(74dvh, 620px);
  min-height: min(400px, calc(100vh - 32px));
  min-height: min(400px, calc(100dvh - 32px));
  flex-direction: column;
  padding: clamp(18px, 3vw, 28px);
}

.pronunciation-header {
  align-items: flex-start;
}

.pronunciation-header p {
  margin: 6px 0 0;
  color: var(--muted);
  font-size: 0.83rem;
}

.pronunciation-text {
  flex: 1;
  min-height: 190px;
  overflow: auto;
  padding: clamp(15px, 3vw, 24px);
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--surface-soft);
  font-size: clamp(1.05rem, 2.8vw, 1.32rem);
  line-height: 2.4;
  overflow-wrap: anywhere;
  white-space: pre-wrap;
}

.pronunciation-char {
  position: relative;
  display: inline-flex;
  width: 1.72em;
  height: 1.72em;
  min-width: 1.72em;
  align-items: center;
  justify-content: center;
  margin: 0.12em 0.03em;
  border: 1px solid transparent;
  border-radius: 6px;
  outline: none;
  cursor: pointer;
  line-height: 1;
  text-align: center;
  vertical-align: middle;
  transition:
    border-color 120ms ease,
    box-shadow 120ms ease,
    color 120ms ease,
    background 120ms ease;
}

.pronunciation-char:hover,
.pronunciation-char:focus-visible {
  background: color-mix(in srgb, var(--primary) 16%, transparent);
  border-color: color-mix(in srgb, var(--primary) 30%, transparent);
  box-shadow: 0 2px 7px color-mix(in srgb, var(--primary) 14%, transparent);
  color: var(--primary);
}

.pronunciation-char:focus-visible {
  outline: 2px solid color-mix(in srgb, var(--primary) 65%, transparent);
  outline-offset: 2px;
}

.pronunciation-char.has-reading {
  background: color-mix(in srgb, var(--primary) 10%, transparent);
}

.pronunciation-char sup {
  position: absolute;
  top: -0.72em;
  left: 50%;
  max-width: 5em;
  overflow: hidden;
  color: var(--primary);
  font-size: 0.48em;
  font-weight: 700;
  line-height: 1;
  text-overflow: ellipsis;
  transform: translateX(-50%);
  white-space: nowrap;
}

.pronunciation-empty {
  margin: 14px 0 0;
  color: var(--muted);
  text-align: center;
}

.pronunciation-footer {
  display: flex;
  align-items: center;
  justify-content: flex-end;
  gap: 18px;
  margin-top: 18px;
  color: var(--muted);
  font-size: 0.84rem;
}

.modal-layer--nested {
  z-index: 130;
}

.modal--reading {
  width: min(100%, 650px);
  padding: 24px;
}

.reading-tabs {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 3px;
  margin-bottom: 20px;
  padding: 3px;
  border-radius: 8px;
  background: var(--surface-soft);
}

.reading-tab {
  min-height: 42px;
  border: 0;
  border-radius: 6px;
  background: transparent;
  color: var(--muted);
}

.reading-tab.is-active {
  background: var(--surface);
  box-shadow: var(--shadow-soft);
  color: var(--text);
  font-weight: 650;
}

.reading-panel {
  min-height: 176px;
}

.reading-loading {
  display: flex;
  min-height: 100px;
  align-items: center;
  justify-content: center;
  gap: 10px;
  color: var(--muted);
  font-size: 0.86rem;
}

.reading-loading .spinner {
  width: 19px;
  height: 19px;
}

.pinyin-options {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(110px, 1fr));
  gap: 10px;
}

.pinyin-option {
  position: relative;
  display: flex;
  min-height: 49px;
  align-items: center;
  gap: 8px;
  padding: 9px 11px;
  border: 1px solid var(--border);
  border-radius: 7px;
  background: var(--surface);
}

.pinyin-option:has(input:checked) {
  border-color: var(--primary);
  background: color-mix(in srgb, var(--primary) 7%, var(--surface));
}

.pinyin-option input {
  accent-color: var(--primary);
}

.pinyin-option__value {
  font-weight: 650;
}

.pinyin-option__recommended {
  margin-left: auto;
  color: var(--primary);
  font-size: 0.7rem;
}

.hanzi-reading-input {
  height: 50px;
  font-size: 1.45rem;
  font-weight: 700;
}

.reading-example {
  min-height: 24px;
  margin: 10px 0 0;
  color: var(--muted);
  font-size: 0.84rem;
}

.apply-all-option {
  display: inline-flex;
  align-items: center;
  gap: 9px;
  margin-top: 8px;
  font-size: 0.88rem;
}

.apply-all-option input {
  width: 19px;
  height: 19px;
  accent-color: var(--primary);
}

.reading-actions {
  align-items: center;
}

.reading-actions__spacer {
  flex: 1;
}

.toast-region {
  position: fixed;
  z-index: 200;
  right: max(18px, env(safe-area-inset-right));
  bottom: max(20px, env(safe-area-inset-bottom));
  left: max(18px, env(safe-area-inset-left));
  display: grid;
  justify-items: center;
  gap: 8px;
  pointer-events: none;
}

.toast {
  max-width: min(92vw, 480px);
  padding: 11px 16px;
  border: 1px solid rgba(255, 255, 255, 0.14);
  border-radius: 9px;
  background: rgba(24, 27, 31, 0.94);
  box-shadow: var(--shadow);
  color: #fff;
  font-size: 0.87rem;
  line-height: 1.45;
  animation: toast-in 180ms ease-out;
}

.toast--danger {
  background: rgba(166, 20, 31, 0.96);
}

.spinner {
  display: inline-block;
  width: 22px;
  height: 22px;
  flex: 0 0 auto;
  border: 3px solid rgba(127, 127, 127, 0.28);
  border-top-color: currentColor;
  border-radius: 50%;
  animation: spin 0.8s linear infinite;
}

.icon {
  display: block;
  width: 1em;
  height: 1em;
  overflow: visible;
  fill: none;
  stroke: currentColor;
  stroke-linecap: round;
  stroke-linejoin: round;
  stroke-width: 1.8;
}

.icon .icon-fill {
  fill: currentColor;
  stroke: none;
}

.svg-sprite {
  position: absolute;
  width: 0;
  height: 0;
  overflow: hidden;
}

.visually-hidden {
  position: absolute !important;
  width: 1px !important;
  height: 1px !important;
  overflow: hidden !important;
  clip: rect(0 0 0 0) !important;
  clip-path: inset(50%) !important;
  white-space: nowrap !important;
}

button:focus-visible,
[role="button"]:focus-visible,
input:focus-visible,
textarea:focus-visible,
select:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--primary) 30%, transparent);
  outline-offset: 2px;
}

@keyframes spin {
  to {
    transform: rotate(360deg);
  }
}

@keyframes shimmer {
  to {
    transform: translateX(100%);
  }
}

@keyframes indeterminate {
  0% {
    transform: translateX(-110%);
  }
  50% {
    transform: translateX(90%);
  }
  100% {
    transform: translateX(240%);
  }
}

@keyframes toast-in {
  from {
    opacity: 0;
    transform: translateY(8px);
  }
}

@media (max-width: 700px) {
  .app-shell {
    padding:
      max(22px, env(safe-area-inset-top), var(--tg-safe-area-inset-top, 0px))
      max(14px, env(safe-area-inset-right), var(--tg-safe-area-inset-right, 0px))
      max(28px, env(safe-area-inset-bottom), var(--tg-safe-area-inset-bottom, 0px))
      max(14px, env(safe-area-inset-left), var(--tg-safe-area-inset-left, 0px));
  }

  .page-header {
    margin-bottom: 22px;
  }

  .page-header h1 {
    font-size: 1.9rem;
  }

  .voices-grid,
  .loading-grid {
    gap: 14px;
  }

  .add-card,
  .voice-card,
  .skeleton-card {
    min-height: 205px;
  }

  .voice-card {
    padding: 18px;
  }

  .modal-layer {
    align-items: end;
    padding:
      max(8px, env(safe-area-inset-top), var(--tg-content-safe-area-inset-top, 0px))
      max(8px, env(safe-area-inset-right), var(--tg-content-safe-area-inset-right, 0px))
      max(8px, env(safe-area-inset-bottom), var(--tg-content-safe-area-inset-bottom, 0px))
      max(8px, env(safe-area-inset-left), var(--tg-content-safe-area-inset-left, 0px));
  }

  .modal {
    max-height: calc(100vh - 16px);
    max-height: calc(100dvh - 16px);
    border-radius: 15px;
  }

  .modal--large,
  .modal--compact {
    padding: 18px;
  }

  .drop-zone,
  .file-loading {
    min-height: 210px;
  }

  .drop-zone {
    padding: 22px 14px;
  }

  .drop-zone__icon {
    width: 62px;
    height: 62px;
    margin-bottom: 8px;
  }

  .audio-summary {
    padding: 0 12px;
  }

  .editor-controls {
    gap: 8px;
  }

  .tips-panel {
    padding: 14px;
  }

  .clone-submit-area {
    margin-top: 20px;
  }

  .dub-view__header {
    margin-bottom: 18px;
  }

  .dub-panel {
    padding: 16px;
  }

  .dub-textarea {
    min-height: 235px;
  }

  .tts-result__actions {
    align-items: stretch;
    flex-wrap: wrap;
  }

  .tts-download {
    width: 100%;
    margin-left: 0;
  }

  .tts-speed-trigger {
    width: 100%;
  }

  .speed-modal-layer {
    align-items: center;
    padding:
      max(14px, env(safe-area-inset-top), var(--tg-content-safe-area-inset-top, 0px))
      max(14px, env(safe-area-inset-right), var(--tg-content-safe-area-inset-right, 0px))
      max(14px, env(safe-area-inset-bottom), var(--tg-content-safe-area-inset-bottom, 0px))
      max(14px, env(safe-area-inset-left), var(--tg-content-safe-area-inset-left, 0px));
  }

  .speed-modal {
    width: min(100%, 390px);
    max-height: calc(100vh - 28px);
    max-height: calc(100dvh - 28px);
    padding: 20px;
  }

  .speed-waveform-panel {
    padding-inline: 8px;
  }

  .speed-waveform {
    min-height: 108px;
  }

  .speed-control {
    grid-template-columns: 28px minmax(0, 1fr) 28px 62px;
    gap: 8px;
    padding: 15px 12px;
  }

  .speed-control__animal {
    min-width: 24px;
    font-size: 1.1rem;
  }

  .speed-actions {
    display: grid;
    grid-template-columns: 1fr;
  }

  .speed-actions__spacer {
    display: none;
  }

  .speed-action {
    width: 100%;
  }

  .modal-layer--fullscreen {
    padding:
      max(10px, env(safe-area-inset-top), var(--tg-content-safe-area-inset-top, 0px))
      max(10px, env(safe-area-inset-right), var(--tg-content-safe-area-inset-right, 0px))
      max(10px, env(safe-area-inset-bottom), var(--tg-content-safe-area-inset-bottom, 0px))
      max(10px, env(safe-area-inset-left), var(--tg-content-safe-area-inset-left, 0px));
  }

  .modal--pronunciation {
    width: 100%;
    height: min(86vh, 620px);
    height: min(86dvh, 620px);
    min-height: min(400px, calc(100vh - 20px));
    min-height: min(400px, calc(100dvh - 20px));
    max-height: calc(100vh - 20px);
    max-height: calc(100dvh - 20px);
    padding: 18px;
    border-radius: 12px;
  }

  .pronunciation-text {
    min-height: 170px;
    padding: 15px;
  }

  .modal--reading {
    padding: 18px;
  }

  .reading-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .reading-actions__spacer {
    display: none;
  }

  #remove-reading {
    grid-column: 1 / -1;
  }
}

@media (max-width: 390px) {
  .voice-card__actions {
    grid-template-columns: 1fr;
  }

  .audio-summary {
    align-items: flex-start;
    justify-content: center;
    flex-direction: column;
    gap: 2px;
    padding-block: 8px;
  }

  .modal__actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .modal__actions > button {
    width: 100%;
  }

  .dub-voice-bar {
    align-items: flex-start;
    flex-wrap: wrap;
  }

  .dub-voice-change {
    width: 100%;
    margin-left: 0;
  }

  .reading-tabs {
    font-size: 0.83rem;
  }
}

@media (prefers-reduced-motion: reduce) {
  *,
  *::before,
  *::after {
    scroll-behavior: auto !important;
    animation-duration: 0.01ms !important;
    animation-iteration-count: 1 !important;
    transition-duration: 0.01ms !important;
  }
}
