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

:root {
  --bg-primary: #0d0d14;
  --bg-secondary: #13131c;
  --bg-card: #191922;
  --bg-hover: #22222e;
  --border: #2a2a38;
  --text-primary: #dedee8;
  --text-secondary: #88889c;
  --text-muted: #555568;
  --accent: #6080c0;
  --accent-subtle: rgba(96, 128, 192, 0.15);
  --accent-hover: #7090d0;
  --success: #50b090;
  --error: #d06060;
  --radius: 10px;
  --radius-sm: 6px;
  --shadow: 0 2px 20px rgba(0, 0, 0, 0.5);
  --font-sans: 'Poppins', -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', 'Fira Code', 'Cascadia Code', 'Consolas', monospace;
}

body {
  font-family: var(--font-sans);
  background: var(--bg-primary);
  color: var(--text-primary);
  min-height: 100vh;
  line-height: 1.7;
  font-weight: 500;
  font-size: 15px;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 20px;
}

header {
  text-align: center;
  padding: 48px 0 32px;
}

.logo {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 10px;
  margin-bottom: 8px;
}

.logo-mark {
  font-size: 24px;
  font-weight: 500;
  font-family: 'Caveat', cursive;
  color: var(--text-primary);
  letter-spacing: -1px;
  padding: 2px 10px 4px;
  border: 1.5px solid var(--accent);
  border-radius: 6px;
  line-height: 1;
}

.logo-mark .logo-dot {
  color: var(--accent);
  font-weight: 500;
}

.logo h1 {
  font-size: 26px;
  font-weight: 500;
  letter-spacing: -0.3px;
  color: var(--text-primary);
}

.tagline {
  color: var(--text-muted);
  font-size: 14px;
  font-weight: 400;
  max-width: 420px;
  margin: 0 auto;
}

.api-section {
  margin-bottom: 24px;
}

.input-group {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 14px 18px;
}

.input-group label {
  display: block;
  font-size: 11px;
  font-weight: 500;
  color: var(--text-muted);
  margin-bottom: 8px;
  text-transform: uppercase;
  letter-spacing: 0.8px;
}

.key-row {
  display: flex;
  gap: 8px;
}

.key-row input {
  flex: 1;
  padding: 9px 12px;
  background: var(--bg-secondary);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-primary);
  font-size: 13px;
  font-family: var(--font-mono);
  outline: none;
  transition: border-color 0.2s;
}

.key-row input:focus {
  border-color: var(--accent);
}

.key-row input::placeholder {
  color: var(--text-muted);
  font-family: var(--font-sans);
  font-size: 13px;
}

.hint {
  margin-top: 6px;
  font-size: 12px;
  color: var(--text-muted);
}

.hint a {
  color: var(--accent);
  text-decoration: none;
}

.hint a:hover {
  text-decoration: underline;
}

.btn-secondary {
  padding: 9px 16px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  color: var(--text-secondary);
  font-size: 12px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s;
  white-space: nowrap;
}

.btn-secondary:hover {
  background: var(--border);
  color: var(--text-primary);
}

.btn-primary {
  padding: 12px 36px;
  background: var(--accent);
  border: none;
  border-radius: var(--radius);
  color: #fff;
  font-size: 14px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s;
  min-width: 200px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  letter-spacing: 0.2px;
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

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

.btn-icon {
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  transition: all 0.2s;
}

.btn-icon:hover {
  background: var(--bg-hover);
  color: var(--text-primary);
}

.btn-small {
  padding: 5px 12px;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  border-radius: 5px;
  color: var(--text-muted);
  font-size: 11px;
  font-weight: 500;
  font-family: var(--font-sans);
  cursor: pointer;
  transition: all 0.2s;
  letter-spacing: 0.2px;
}

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

.main-area {
  display: grid;
  gap: 20px;
}

.upload-panel {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.upload-zone {
  position: relative;
  min-height: 200px;
  display: flex;
  align-items: center;
  justify-content: center;
  cursor: pointer;
  transition: all 0.2s;
}

.upload-zone.dragover {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.upload-content {
  text-align: center;
  padding: 36px 20px;
}

.upload-icon {
  color: var(--text-muted);
  margin-bottom: 12px;
  transition: color 0.2s;
  opacity: 0.6;
}

.upload-zone:hover .upload-icon {
  opacity: 1;
  color: var(--accent);
}

.upload-text {
  font-size: 15px;
  color: var(--text-secondary);
  margin-bottom: 4px;
}

.upload-text .link {
  color: var(--accent);
  text-decoration: underline;
  text-underline-offset: 2px;
  text-decoration-color: rgba(96, 128, 192, 0.3);
}

.upload-hint {
  font-size: 12px;
  color: var(--text-muted);
}

.upload-preview {
  position: relative;
  width: 100%;
  height: 300px;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  background: var(--bg-secondary);
}

.upload-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.upload-preview .btn-icon {
  position: absolute;
  top: 10px;
  right: 10px;
  background: rgba(0, 0, 0, 0.5);
  border-color: transparent;
}

.upload-preview .btn-icon:hover {
  background: rgba(180, 60, 60, 0.7);
  color: #fff;
}

.action-bar {
  text-align: center;
  padding: 20px 0;
}

.btn-loader {
  display: inline-flex;
  gap: 4px;
  align-items: center;
}

.dot {
  width: 5px;
  height: 5px;
  border-radius: 50%;
  background: #fff;
  animation: bounce 1.4s infinite ease-in-out both;
}

.dot:nth-child(1) { animation-delay: -0.32s; }
.dot:nth-child(2) { animation-delay: -0.16s; }
.dot:nth-child(3) { animation-delay: 0s; }

@keyframes bounce {
  0%, 80%, 100% { transform: scale(0.6); opacity: 0.4; }
  40% { transform: scale(1); opacity: 1; }
}

.result-panel {
  display: grid;
  gap: 20px;
}

.preview-box,
.code-box {
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
}

.preview-header,
.code-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 14px;
  background: var(--bg-secondary);
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 500;
  color: var(--text-muted);
  letter-spacing: 0.3px;
}

.preview-frame {
  height: 400px;
  overflow: hidden;
}

.preview-frame iframe {
  width: 100%;
  height: 100%;
  border: none;
  background: #fff;
}

.code-actions {
  display: flex;
  gap: 6px;
}

.code-body {
  max-height: 400px;
  overflow: auto;
}

.code-body pre {
  padding: 14px 16px;
  font-family: var(--font-mono);
  font-size: 12.5px;
  line-height: 1.5;
  color: #d0d0da;
  white-space: pre-wrap;
  word-break: break-all;
}

.code-body::-webkit-scrollbar {
  width: 6px;
  height: 6px;
}

.code-body::-webkit-scrollbar-track {
  background: transparent;
}

.code-body::-webkit-scrollbar-thumb {
  background: var(--border);
  border-radius: 3px;
}

.error-section {
  padding: 0 0 16px;
}

.error-box {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 14px;
  background: rgba(180, 60, 60, 0.08);
  border: 1px solid rgba(180, 60, 60, 0.2);
  border-radius: var(--radius-sm);
  color: var(--error);
  font-size: 13px;
}

.error-icon {
  font-size: 15px;
  flex-shrink: 0;
  opacity: 0.8;
}

.history-section {
  margin-top: 32px;
  padding: 24px 0;
  border-top: 1px solid var(--border);
}

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

.history-header h2 {
  font-size: 15px;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: -0.2px;
}

.history-list {
  display: grid;
  gap: 8px;
}

.history-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--bg-card);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  cursor: pointer;
  transition: all 0.15s;
}

.history-item:hover {
  background: var(--bg-hover);
  border-color: var(--accent);
}

.history-item.active {
  border-color: var(--accent);
  background: var(--accent-subtle);
}

.history-thumb {
  width: 40px;
  height: 40px;
  border-radius: 4px;
  object-fit: cover;
  background: var(--bg-secondary);
  flex-shrink: 0;
}

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

.history-info .history-date {
  font-size: 12px;
  color: var(--text-muted);
  display: block;
  margin-bottom: 2px;
}

.history-info .history-preview {
  font-size: 12px;
  color: var(--text-secondary);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
  display: block;
  font-family: var(--font-mono);
  opacity: 0.7;
}

.history-item .btn-icon {
  opacity: 0;
  transition: opacity 0.15s;
  flex-shrink: 0;
}

.history-item:hover .btn-icon {
  opacity: 1;
}

.history-item .btn-icon:hover {
  color: var(--error);
  border-color: rgba(180, 60, 60, 0.3);
}

.history-empty {
  text-align: center;
  padding: 24px;
  color: var(--text-muted);
  font-size: 13px;
}

.examples-section {
  margin-top: 40px;
  padding: 32px 0;
  border-top: 1px solid var(--border);
}

.examples-section h2 {
  text-align: center;
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 28px;
  color: var(--text-secondary);
  letter-spacing: -0.2px;
}

.steps {
  display: flex;
  align-items: flex-start;
  justify-content: center;
  gap: 8px;
  flex-wrap: wrap;
}

.step {
  text-align: center;
  flex: 1;
  min-width: 130px;
  max-width: 170px;
}

.step-num {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-hover);
  border: 1px solid var(--border);
  color: var(--text-muted);
  font-size: 13px;
  font-weight: 500;
  display: flex;
  align-items: center;
  justify-content: center;
  margin: 0 auto 8px;
}

.step h3 {
  font-size: 14px;
  font-weight: 500;
  margin-bottom: 4px;
  color: var(--text-primary);
}

.step p {
  font-size: 12px;
  color: var(--text-muted);
  line-height: 1.5;
}

.step-arrow {
  color: var(--text-muted);
  font-size: 16px;
  padding-top: 8px;
  opacity: 0.5;
}

footer {
  text-align: center;
  padding: 28px 0 16px;
  border-top: 1px solid var(--border);
  margin-top: 16px;
}

footer p {
  font-size: 12px;
  color: var(--text-muted);
}

footer a {
  color: var(--text-secondary);
  text-decoration: none;
}

footer a:hover {
  color: var(--accent);
}

.toast {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(80px);
  padding: 10px 22px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  font-family: var(--font-sans);
  opacity: 0;
  transition: all 0.3s ease;
  z-index: 1000;
  pointer-events: none;
  backdrop-filter: blur(8px);
}

.toast.show {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
}

.toast.success {
  background: rgba(60, 160, 120, 0.15);
  border: 1px solid rgba(60, 160, 120, 0.3);
  color: var(--success);
}

.toast.error {
  background: rgba(180, 60, 60, 0.15);
  border: 1px solid rgba(180, 60, 60, 0.3);
  color: var(--error);
}

@media (min-width: 720px) {
  .result-panel {
    grid-template-columns: 1fr 1fr;
  }

  .main-area {
    gap: 0;
  }
}

@media (max-width: 640px) {
  .container {
    padding: 16px 12px;
  }

  header {
    padding: 28px 0 20px;
  }

  .logo h1 {
    font-size: 20px;
  }

  .key-row {
    flex-direction: column;
  }

  .steps {
    flex-direction: column;
    align-items: center;
  }

  .step {
    max-width: 240px;
  }

  .step-arrow {
    transform: rotate(90deg);
    padding: 2px 0;
  }

  .upload-preview {
    height: 200px;
  }

  .preview-frame {
    height: 280px;
  }

  .code-body {
    max-height: 280px;
  }
}
