:root {
  --bg: #0b0f19;
  --surface: #121826;
  --surface-2: #1a2234;
  --border: #243044;
  --text: #e8eef7;
  --text-muted: #8b9bb4;
  --primary: #6366f1;
  --primary-hover: #818cf8;
  --success: #22c55e;
  --danger: #ef4444;
  --radius: 14px;
  --radius-sm: 10px;
  --shadow: 0 8px 30px rgba(0,0,0,.35);
  --font: 'Inter', system-ui, -apple-system, sans-serif;
}

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

html { font-size: 16px; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.app {
  max-width: 880px;
  margin: 0 auto;
  padding: 24px 20px 60px;
}

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

.logo {
  display: flex;
  align-items: center;
  gap: 10px;
}

.logo-mark {
  width: 36px;
  height: 36px;
  border-radius: 10px;
  background: linear-gradient(135deg, #6366f1, #8b5cf6);
  display: grid;
  place-items: center;
  color: white;
}

.logo-text {
  font-weight: 700;
  font-size: 1.2rem;
  letter-spacing: -0.02em;
}

.status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.85rem;
  color: var(--text-muted);
  background: var(--surface);
  padding: 6px 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
}

.status-dot {
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: #64748b;
}

.status.online .status-dot { background: var(--success); box-shadow: 0 0 8px var(--success); }
.status.offline .status-dot { background: var(--danger); }

/* Hero */
.hero {
  text-align: center;
  margin-bottom: 36px;
}

.hero h1 {
  font-size: clamp(1.8rem, 4vw, 2.4rem);
  font-weight: 700;
  letter-spacing: -0.03em;
  margin-bottom: 10px;
  background: linear-gradient(135deg, #fff 30%, #a5b4fc);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

.hero p {
  color: var(--text-muted);
  font-size: 1.05rem;
  max-width: 480px;
  margin: 0 auto;
}

/* Upload */
.upload-box {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow: hidden;
  margin-bottom: 32px;
  box-shadow: var(--shadow);
}

.upload-zone {
  padding: 48px 24px;
  text-align: center;
  cursor: pointer;
  transition: background .2s, border-color .2s;
  border: 2px dashed transparent;
}

.upload-zone:hover,
.upload-zone.dragover {
  background: var(--surface-2);
  border-color: var(--primary);
}

.upload-icon {
  color: var(--primary);
  margin-bottom: 16px;
  opacity: .9;
}

.upload-zone h2 {
  font-size: 1.25rem;
  font-weight: 600;
  margin-bottom: 6px;
}

.upload-zone p {
  color: var(--text-muted);
  margin-bottom: 20px;
}

.link-btn {
  background: none;
  border: none;
  color: var(--primary);
  font: inherit;
  font-weight: 500;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.hints {
  display: flex;
  flex-wrap: wrap;
  justify-content: center;
  gap: 8px;
  font-size: 0.8rem;
  color: var(--text-muted);
}

.hints span {
  background: var(--surface-2);
  padding: 4px 10px;
  border-radius: 6px;
  border: 1px solid var(--border);
}

.hints .sep {
  background: none;
  border: none;
  padding: 0;
  color: var(--border);
}

/* Loading */
.loading {
  padding: 56px 24px;
  text-align: center;
}

.spinner {
  width: 42px;
  height: 42px;
  border: 3px solid var(--border);
  border-top-color: var(--primary);
  border-radius: 50%;
  margin: 0 auto 20px;
  animation: spin .8s linear infinite;
}

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

.loading h3 {
  font-size: 1.1rem;
  margin-bottom: 6px;
}

.loading p {
  color: var(--text-muted);
  font-size: 0.9rem;
}

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

.results-top {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 20px;
}

.results-top h2 {
  font-size: 1.3rem;
  font-weight: 600;
}

.results-meta {
  color: var(--text-muted);
  font-size: 0.9rem;
  margin-top: 2px;
}

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

.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font: inherit;
  font-size: 0.9rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid transparent;
  transition: all .15s;
}

.btn-ghost {
  background: var(--surface);
  border-color: var(--border);
  color: var(--text);
}

.btn-ghost:hover {
  background: var(--surface-2);
  border-color: #334155;
}

.btn-text {
  background: none;
  border: none;
  color: var(--text-muted);
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
}

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

/* Tabs */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 20px;
}

.tab {
  background: transparent;
  border: 1px solid var(--border);
  color: var(--text-muted);
  padding: 6px 14px;
  border-radius: 999px;
  font: inherit;
  font-size: 0.85rem;
  cursor: pointer;
  transition: all .15s;
}

.tab:hover { color: var(--text); border-color: #334155; }
.tab.active {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
  gap: 16px;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  overflow: hidden;
  transition: border-color .2s, transform .2s;
}

.card:hover {
  border-color: #334155;
  transform: translateY(-2px);
}

.card-preview {
  aspect-ratio: 16/10;
  background: var(--surface-2);
  display: grid;
  place-items: center;
  overflow: hidden;
  cursor: pointer;
}

.card-preview img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.card-body {
  padding: 14px;
}

.card-title-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 8px;
}

.card-title {
  font-weight: 600;
  font-size: 0.95rem;
}

.card-badge {
  font-size: 0.7rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  background: var(--surface-2);
  color: var(--primary-hover);
  padding: 2px 8px;
  border-radius: 4px;
}

.card-info {
  display: flex;
  gap: 12px;
  font-size: 0.8rem;
  color: var(--text-muted);
  margin-bottom: 12px;
}

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

.card-actions button {
  flex: 1;
  padding: 8px;
  border-radius: 7px;
  font: inherit;
  font-size: 0.85rem;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text);
  transition: all .15s;
}

.card-actions button:hover {
  background: var(--primary);
  border-color: var(--primary);
  color: white;
}

.card-actions .copied {
  background: var(--success) !important;
  border-color: var(--success) !important;
  color: white !important;
}

/* History */
.history {
  margin-top: 8px;
}

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

.history-head h3 {
  font-size: 1rem;
  font-weight: 600;
}

.history-list {
  display: flex;
  gap: 12px;
  overflow-x: auto;
  padding-bottom: 8px;
}

.history-item {
  flex: 0 0 auto;
  width: 120px;
  cursor: pointer;
  text-align: center;
}

.history-item img {
  width: 120px;
  height: 80px;
  object-fit: cover;
  border-radius: 8px;
  border: 1px solid var(--border);
  margin-bottom: 6px;
  transition: border-color .15s;
}

.history-item:hover img { border-color: var(--primary); }

.history-item span {
  font-size: 0.75rem;
  color: var(--text-muted);
  display: block;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* Footer */
.footer {
  text-align: center;
  margin-top: 48px;
  color: var(--text-muted);
  font-size: 0.8rem;
}

/* Toasts */
.toasts {
  position: fixed;
  bottom: 24px;
  right: 24px;
  z-index: 1000;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.toast {
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text);
  padding: 12px 18px;
  border-radius: 10px;
  font-size: 0.9rem;
  box-shadow: var(--shadow);
  transform: translateY(20px);
  opacity: 0;
  transition: all .3s ease;
  max-width: 320px;
}

.toast.show {
  transform: translateY(0);
  opacity: 1;
}

.toast.success { border-left: 3px solid var(--success); }
.toast.error { border-left: 3px solid var(--danger); }

/* Modal */
.modal {
  position: fixed;
  inset: 0;
  z-index: 900;
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal[hidden] { display: none; }

.modal-backdrop {
  position: absolute;
  inset: 0;
  background: rgba(0,0,0,.75);
  backdrop-filter: blur(4px);
}

.modal-body {
  position: relative;
  max-width: 90vw;
  max-height: 90vh;
  background: var(--surface);
  border-radius: var(--radius);
  overflow: hidden;
  border: 1px solid var(--border);
}

.modal-body img {
  display: block;
  max-width: 90vw;
  max-height: 80vh;
  object-fit: contain;
}

.modal-close {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  background: rgba(0,0,0,.6);
  border: none;
  color: white;
  font-size: 1.4rem;
  cursor: pointer;
  line-height: 1;
  z-index: 2;
}

.modal-meta {
  padding: 12px 16px;
  display: flex;
  justify-content: space-between;
  font-size: 0.9rem;
  color: var(--text-muted);
}

/* Responsive */
@media (max-width: 600px) {
  .app { padding: 16px 14px 40px; }
  .header { margin-bottom: 28px; }
  .hero { margin-bottom: 28px; }
  .upload-zone { padding: 36px 16px; }
  .grid { grid-template-columns: 1fr; }
  .results-top { flex-direction: column; }
  .toasts { left: 16px; right: 16px; bottom: 16px; }
}
