/* ===== Reset & Variables ===== */
*,
*::before,
*::after {
  margin: 0;
  padding: 0;
  box-sizing: border-box;
}

:root {
  --coral: #ff6b6b;
  --coral-dark: #ee5a24;
  --purple: #6c5ce7;
  --purple-dark: #5a4bd1;
  --teal: #00b894;
  --yellow: #fdcb6e;
  --sky: #74b9ff;
  --text: #2d3436;
  --text-light: #636e72;
  --text-muted: #b2bec3;
  --bg: #f0f3f8;
  --card: #ffffff;
  --card-shadow: 0 4px 24px rgba(0, 0, 0, 0.06);
  --radius: 16px;
  --radius-sm: 10px;
  --transition: 0.25s ease;
  --max-width: 640px;
}

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

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

/* ===== Layout ===== */
#app {
  max-width: var(--max-width);
  margin: 0 auto;
  padding: 0 16px 32px;
}

/* ===== Hero ===== */
.hero {
  text-align: center;
  padding: 40px 0 24px;
}

.hero-title {
  font-size: 2rem;
  font-weight: 800;
  background: linear-gradient(135deg, var(--coral) 0%, var(--purple) 100%);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
  letter-spacing: -0.5px;
}

.hero-subtitle {
  color: var(--text-light);
  font-size: 0.95rem;
  margin-top: 8px;
}

/* ===== Tabs ===== */
.tabs {
  display: flex;
  gap: 0;
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  margin-bottom: 20px;
}

.tab {
  flex: 1;
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  padding: 14px 16px;
  border: none;
  background: transparent;
  font-size: 1rem;
  font-weight: 600;
  color: var(--text-light);
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
}

.tab::after {
  content: "";
  position: absolute;
  bottom: 0;
  left: 20%;
  right: 20%;
  height: 3px;
  border-radius: 3px 3px 0 0;
  background: transparent;
  transition: background var(--transition);
}

.tab:hover {
  color: var(--text);
  background: rgba(0, 0, 0, 0.02);
}

.tab.active {
  color: var(--purple);
}

.tab.active::after {
  background: linear-gradient(90deg, var(--coral), var(--purple));
}

.tab-icon {
  font-size: 1.2rem;
}

/* ===== Panels ===== */
.panel {
  display: none;
}

.panel.active {
  display: block;
}

/* ===== Cards ===== */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  padding: 24px;
  margin-bottom: 20px;
}

/* ===== Forms ===== */
.form-group {
  margin-bottom: 16px;
}

.form-group label {
  display: block;
  font-weight: 600;
  font-size: 0.9rem;
  margin-bottom: 6px;
  color: var(--text);
}

.label-hint {
  font-weight: 400;
  font-size: 0.78rem;
  color: var(--text-muted);
  margin-left: 8px;
}

.char-count {
  display: block;
  text-align: right;
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 4px;
}

textarea,
select {
  width: 100%;
  padding: 12px 14px;
  border: 2px solid #e8ecf1;
  border-radius: var(--radius-sm);
  font-size: 0.95rem;
  font-family: inherit;
  color: var(--text);
  background: #fafbfc;
  transition: border-color var(--transition), box-shadow var(--transition);
  resize: vertical;
}

textarea:focus,
select:focus {
  outline: none;
  border-color: var(--purple);
  box-shadow: 0 0 0 3px rgba(108, 92, 231, 0.12);
}

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

.form-row {
  display: flex;
  gap: 12px;
}

.form-group-sm {
  flex: 1;
}

.form-group-sm select {
  cursor: pointer;
}

.form-row-toggles {
  margin-bottom: 20px;
  gap: 20px;
}

/* ===== Toggle Switch ===== */
.toggle {
  display: flex;
  align-items: center;
  gap: 10px;
  cursor: pointer;
  user-select: none;
}

.toggle input {
  display: none;
}

.toggle-slider {
  width: 44px;
  height: 24px;
  background: #dfe6e9;
  border-radius: 12px;
  position: relative;
  transition: background var(--transition);
  flex-shrink: 0;
}

.toggle-slider::after {
  content: "";
  position: absolute;
  width: 20px;
  height: 20px;
  background: white;
  border-radius: 50%;
  top: 2px;
  left: 2px;
  transition: transform var(--transition);
  box-shadow: 0 1px 4px rgba(0, 0, 0, 0.15);
}

.toggle input:checked + .toggle-slider {
  background: var(--teal);
}

.toggle input:checked + .toggle-slider::after {
  transform: translateX(20px);
}

.toggle-label {
  font-size: 0.88rem;
  color: var(--text-light);
}

/* ===== Buttons ===== */
.btn {
  width: 100%;
  padding: 14px 24px;
  border: none;
  border-radius: var(--radius-sm);
  font-size: 1rem;
  font-weight: 700;
  color: white;
  cursor: pointer;
  transition: all var(--transition);
  position: relative;
  overflow: hidden;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-image {
  background: linear-gradient(135deg, var(--coral), #ff9a56);
}

.btn-image:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(255, 107, 107, 0.35);
}

.btn-music {
  background: linear-gradient(135deg, var(--purple), #a29bfe);
}

.btn-music:hover:not(:disabled) {
  transform: translateY(-1px);
  box-shadow: 0 6px 20px rgba(108, 92, 231, 0.35);
}

.btn:active:not(:disabled) {
  transform: translateY(0);
}

.btn-loading {
  display: inline-flex;
  align-items: center;
  gap: 8px;
}

.btn-loading::before {
  content: "";
  width: 16px;
  height: 16px;
  border: 2px solid rgba(255, 255, 255, 0.3);
  border-top-color: white;
  border-radius: 50%;
  animation: spin 0.6s linear infinite;
}

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

/* ===== Quota Hints ===== */
.form-row-footer {
  justify-content: flex-end;
  margin-bottom: 4px;
  margin-top: -8px;
}

.quota-hint {
  font-size: 0.78rem;
  color: var(--text-muted);
}

.quota-hint-exhausted {
  color: var(--coral);
  font-weight: 600;
}
}

/* ===== Results ===== */
.results {
  margin-bottom: 20px;
}

.result-card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--card-shadow);
  overflow: hidden;
  margin-bottom: 16px;
  animation: fadeUp 0.4s ease;
}

@keyframes fadeUp {
  from {
    opacity: 0;
    transform: translateY(16px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

.result-prompt {
  padding: 14px 18px;
  font-size: 0.85rem;
  color: var(--text-light);
  border-bottom: 1px solid #f0f0f0;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.image-grid {
  display: grid;
  grid-template-columns: 1fr;
  gap: 0;
}

.image-grid.grid-2 {
  grid-template-columns: 1fr 1fr;
}

.image-grid img {
  width: 100%;
  display: block;
  cursor: pointer;
  transition: opacity var(--transition);
}

.image-grid img:hover {
  opacity: 0.92;
}

.result-meta {
  padding: 12px 18px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  border-top: 1px solid #f0f0f0;
}

.result-time {
  font-size: 0.78rem;
  color: var(--text-muted);
}

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

.btn-sm {
  padding: 6px 14px;
  border: none;
  border-radius: 8px;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all var(--transition);
}

.btn-download {
  background: #f0f3f8;
  color: var(--text-light);
}

.btn-download:hover {
  background: #e8ecf1;
  color: var(--text);
}

/* ===== Audio Player ===== */
.audio-card {
  padding: 18px;
}

.audio-player {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

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

.play-btn {
  width: 48px;
  height: 48px;
  border-radius: 50%;
  border: none;
  background: linear-gradient(135deg, var(--purple), #a29bfe);
  color: white;
  font-size: 1.2rem;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: all var(--transition);
  flex-shrink: 0;
}

.play-btn:hover {
  transform: scale(1.08);
  box-shadow: 0 4px 16px rgba(108, 92, 231, 0.4);
}

.progress-bar {
  flex: 1;
  height: 6px;
  background: #e8ecf1;
  border-radius: 3px;
  overflow: hidden;
  cursor: pointer;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--purple), var(--coral));
  border-radius: 3px;
  width: 0%;
  transition: width 0.1s linear;
}

.audio-time {
  font-size: 0.78rem;
  color: var(--text-muted);
  font-variant-numeric: tabular-nums;
  min-width: 40px;
}

.audio-info {
  display: flex;
  gap: 12px;
  flex-wrap: wrap;
}

.audio-tag {
  font-size: 0.75rem;
  padding: 3px 10px;
  background: #f0f3f8;
  border-radius: 20px;
  color: var(--text-light);
}

/* ===== History ===== */
.history-section {
  margin-top: 12px;
}

.history-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 12px;
}

.history-header h2 {
  font-size: 1.1rem;
  font-weight: 700;
}

.btn-link {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  cursor: pointer;
  padding: 4px 8px;
}

.btn-link:hover {
  color: var(--coral);
}

.history-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.history-empty {
  text-align: center;
  color: var(--text-muted);
  font-size: 0.88rem;
  padding: 20px 0;
}

.history-item {
  background: var(--card);
  border-radius: var(--radius-sm);
  padding: 12px 16px;
  display: flex;
  align-items: center;
  gap: 12px;
  box-shadow: 0 2px 8px rgba(0, 0, 0, 0.04);
  cursor: pointer;
  transition: all var(--transition);
}

.history-item:hover {
  box-shadow: 0 4px 16px rgba(0, 0, 0, 0.08);
}

.history-icon {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 1rem;
  flex-shrink: 0;
}

.history-icon.type-image {
  background: linear-gradient(135deg, #ffeaa7, #fdcb6e);
}

.history-icon.type-music {
  background: linear-gradient(135deg, #a29bfe, #6c5ce7);
  color: white;
}

.history-body {
  flex: 1;
  min-width: 0;
}

.history-text {
  font-size: 0.85rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.history-date {
  font-size: 0.75rem;
  color: var(--text-muted);
  margin-top: 2px;
}

/* ===== Footer ===== */
.app-footer {
  text-align: center;
  padding: 24px 0 16px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* ===== Toast ===== */
.toast-container {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 9999;
  display: flex;
  flex-direction: column;
  gap: 8px;
  pointer-events: none;
}

.toast {
  background: var(--text);
  color: white;
  padding: 12px 20px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.15);
  animation: toastIn 0.3s ease, toastOut 0.3s ease 2.7s forwards;
  pointer-events: auto;
  max-width: 90vw;
  text-align: center;
}

.toast.error {
  background: var(--coral-dark);
}

.toast.success {
  background: var(--teal);
}

@keyframes toastIn {
  from {
    opacity: 0;
    transform: translateY(-10px);
  }
  to {
    opacity: 1;
    transform: translateY(0);
  }
}

@keyframes toastOut {
  from {
    opacity: 1;
  }
  to {
    opacity: 0;
    transform: translateY(-10px);
  }
}

/* ===== Lightbox ===== */
.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 9998;
  cursor: zoom-out;
  animation: fadeIn 0.2s ease;
}

.lightbox img {
  max-width: 95vw;
  max-height: 95vh;
  border-radius: 8px;
  box-shadow: 0 8px 40px rgba(0, 0, 0, 0.3);
}

@keyframes fadeIn {
  from { opacity: 0; }
  to { opacity: 1; }
}

/* ===== Responsive ===== */
@media (min-width: 480px) {
  .hero-title {
    font-size: 2.4rem;
  }
}

@media (max-width: 400px) {
  .form-row-toggles {
    flex-direction: column;
    gap: 12px;
  }

  .tabs {
    border-radius: var(--radius-sm);
  }

  .hero-title {
    font-size: 1.6rem;
  }
}

/* ===== Hidden ===== */
.hidden {
  display: none !important;
}
