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

:root {
  --bg: #ffffff;
  --bg-secondary: #f5f5f5;
  --text: #111111;
  --text-muted: #888888;
  --border: #e0e0e0;
  --primary: #111111;
  --primary-hover: #333333;
  --error: #e53935;
  --success: #43a047;
  --radius: 6px;
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'PingFang SC', 'Hiragino Sans GB', 'Microsoft YaHei', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.6;
  font-size: 14px;
}

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

/* Header */
.header {
  border-bottom: 1px solid var(--border);
  padding: 14px 0;
}

.logo {
  font-size: 16px;
  font-weight: 600;
}

.main {
  padding-top: 40px;
  padding-bottom: 80px;
}

/* Input */
.input-section {
  margin-bottom: 32px;
}

.tab-row {
  display: flex;
  gap: 0;
  margin-bottom: 16px;
  border-bottom: 1px solid var(--border);
}

.tab-btn {
  padding: 8px 16px;
  background: none;
  border: none;
  border-bottom: 2px solid transparent;
  font-size: 14px;
  font-family: inherit;
  color: var(--text-muted);
  cursor: pointer;
  transition: color 0.15s, border-color 0.15s;
}

.tab-btn:hover { color: var(--text); }
.tab-btn.active { color: var(--text); border-bottom-color: var(--text); }

.mode-panel { display: none; }
.mode-panel.active { display: block; }

.html-input {
  width: 100%;
  min-height: 120px;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  font-family: 'SF Mono', Monaco, Consolas, monospace;
  outline: none;
  transition: border-color 0.15s;
  background: var(--bg);
  color: var(--text);
  resize: vertical;
  margin-bottom: 8px;
}

.html-input:focus { border-color: var(--text); }
.html-input::placeholder { color: var(--text-muted); font-size: 13px; }

.input-row {
  display: flex;
  gap: 8px;
  margin-bottom: 8px;
}

.url-input {
  flex: 1;
  padding: 10px 14px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
  background: var(--bg);
  color: var(--text);
}

.url-input:focus {
  border-color: var(--text);
}

.url-input::placeholder {
  color: var(--text-muted);
}

.btn-primary {
  padding: 10px 20px;
  background: var(--primary);
  color: white;
  border: none;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  cursor: pointer;
  font-family: inherit;
  transition: background 0.15s;
  white-space: nowrap;
}

.btn-primary:hover { background: var(--primary-hover); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-secondary {
  padding: 7px 14px;
  background: var(--bg);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  transition: border-color 0.15s;
}

.btn-secondary:hover { border-color: var(--text-muted); }
.btn-secondary:disabled { opacity: 0.4; cursor: not-allowed; }

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font-size: 13px;
  cursor: pointer;
  font-family: inherit;
  padding: 4px 0;
}

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

/* Loading */
.loading-section {
  text-align: center;
  padding: 48px 0;
}

.spinner {
  width: 28px;
  height: 28px;
  border: 2px solid var(--border);
  border-top-color: var(--text);
  border-radius: 50%;
  margin: 0 auto 12px;
  animation: spin 0.7s linear infinite;
}

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

.loading-text {
  color: var(--text-muted);
  font-size: 13px;
}

/* Error */
.error-section {
  text-align: center;
  padding: 48px 0;
}

.error-message {
  color: var(--error);
  font-size: 14px;
  margin-bottom: 12px;
}

/* Results */
.result-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 20px;
}

.result-header h2 {
  font-size: 16px;
  font-weight: 600;
}

.result-meta {
  display: flex;
  align-items: center;
  gap: 16px;
  font-size: 13px;
  color: var(--text-muted);
}

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
  gap: 12px;
}

/* Image Card */
.image-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  background: var(--bg);
}

.image-preview {
  position: relative;
  aspect-ratio: 1;
  background: var(--bg-secondary);
  cursor: pointer;
  overflow: hidden;
}

.image-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
}

.image-loading {
  position: absolute;
  inset: 0;
  display: flex;
  align-items: center;
  justify-content: center;
}

.image-loading .spinner {
  width: 22px;
  height: 22px;
  border-width: 2px;
  margin: 0;
}

.image-error {
  position: absolute;
  inset: 0;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 6px;
  color: var(--text-muted);
  font-size: 12px;
}

.image-info {
  padding: 10px 12px;
}

.image-prompt {
  font-size: 13px;
  margin-bottom: 2px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.image-dimensions {
  font-size: 11px;
  color: var(--text-muted);
}

.image-actions {
  display: flex;
  gap: 8px;
  padding: 0 12px 12px;
}

.image-actions .btn-secondary {
  flex: 1;
  text-align: center;
}

/* Modal */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.9);
  z-index: 1000;
  align-items: center;
  justify-content: center;
  padding: 24px;
}

.modal-overlay.active {
  display: flex;
}

.modal-content {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  align-items: center;
}

.modal-image {
  max-width: 100%;
  max-height: 78vh;
  object-fit: contain;
}

.modal-loading {
  color: rgba(255, 255, 255, 0.6);
  font-size: 13px;
  padding: 40px;
}

.modal-close {
  position: absolute;
  top: -36px;
  right: 0;
  background: none;
  border: none;
  color: white;
  font-size: 28px;
  cursor: pointer;
  line-height: 1;
  opacity: 0.7;
}

.modal-close:hover { opacity: 1; }

.modal-info {
  color: rgba(255, 255, 255, 0.7);
  font-size: 12px;
  margin-top: 10px;
  text-align: center;
  max-width: 600px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.modal-download {
  margin-top: 10px;
  padding: 8px 18px;
  font-size: 13px;
}

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: var(--text);
  color: white;
  padding: 9px 18px;
  border-radius: var(--radius);
  font-size: 13px;
  opacity: 0;
  transition: opacity 0.2s;
  pointer-events: none;
  z-index: 2000;
}

.toast.show { opacity: 1; }
.toast.error { background: var(--error); }
.toast.success { background: var(--success); }

/* Responsive */
@media (max-width: 640px) {
  .input-row { flex-direction: column; }
  .image-grid { grid-template-columns: repeat(2, 1fr); gap: 8px; }
  .result-header { flex-direction: column; gap: 8px; align-items: flex-start; }
}
