:root {
  --bg: #faf8f6;
  --surface: #ffffff;
  --surface-subtle: #f3efeb;
  --border: #e7e1da;
  --text: #171614;
  --text-muted: #6c655d;
  --accent: #e60023;
  --accent-hover: #c4001d;
  --accent-soft: rgba(230, 0, 35, 0.1);
  --success: #15803d;
  --warn-bg: #fef3c7;
  --warn-text: #92400e;
  --error-bg: #fef2f2;
  --error-border: #fecaca;
  --error-text: #b91c1c;
  --shadow-sm: 0 1px 2px rgba(23, 22, 20, 0.05);
  --shadow-md: 0 8px 24px rgba(23, 22, 20, 0.07);
  --shadow-lg: 0 20px 50px rgba(23, 22, 20, 0.16);
  --radius-sm: 10px;
  --radius-md: 16px;
  --radius-lg: 22px;
}

[data-theme="dark"] {
  --bg: #111113;
  --surface: #19191d;
  --surface-subtle: #232329;
  --border: #2c2c34;
  --text: #f4f2ef;
  --text-muted: #9f9a93;
  --accent: #ff2e4c;
  --accent-hover: #e61735;
  --accent-soft: rgba(255, 46, 76, 0.16);
  --success: #4ade80;
  --warn-bg: rgba(245, 158, 11, 0.15);
  --warn-text: #fcd34d;
  --error-bg: rgba(239, 68, 68, 0.12);
  --error-border: rgba(239, 68, 68, 0.35);
  --error-text: #fca5a5;
  --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.3);
  --shadow-md: 0 10px 28px rgba(0, 0, 0, 0.35);
  --shadow-lg: 0 24px 60px rgba(0, 0, 0, 0.6);
}

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

html,
body {
  margin: 0;
  padding: 0;
  font-family: "Plus Jakarta Sans", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

.hidden {
  display: none !important;
}

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

code {
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.9em;
  background: var(--surface-subtle);
  padding: 0.12em 0.42em;
  border-radius: 6px;
}

.container {
  width: 100%;
  max-width: 1320px;
  margin: 0 auto;
  padding: 0 20px;
}

/* Header */
.topbar {
  position: sticky;
  top: 0;
  z-index: 40;
  background: color-mix(in srgb, var(--bg) 88%, transparent);
  backdrop-filter: blur(12px);
  border-bottom: 1px solid var(--border);
}

.topbar-inner {
  display: flex;
  align-items: center;
  justify-content: space-between;
  height: 64px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-logo {
  width: 38px;
  height: 38px;
  border-radius: 12px;
  background: var(--accent);
  color: #fff;
  display: grid;
  place-items: center;
  box-shadow: 0 4px 12px rgba(230, 0, 35, 0.28);
}

.brand-name {
  font-weight: 800;
  font-size: 1.08rem;
  letter-spacing: -0.02em;
  line-height: 1.1;
}

.brand-sub {
  font-size: 0.76rem;
  color: var(--text-muted);
  font-weight: 500;
}

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

.pill-badge {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  font-size: 0.78rem;
  font-weight: 600;
  padding: 6px 12px;
  border-radius: 999px;
  background: var(--surface);
  border: 1px solid var(--border);
  color: var(--text-muted);
}

.pill-badge .dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--success);
}

.icon-btn {
  width: 38px;
  height: 38px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  display: grid;
  place-items: center;
  cursor: pointer;
  transition: background 0.15s, border-color 0.15s;
}

.icon-btn:hover {
  background: var(--surface-subtle);
}

/* Main */
.main-content {
  padding-top: 28px;
  padding-bottom: 64px;
}

/* Hero Card */
.hero-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 32px;
  box-shadow: var(--shadow-md);
}

.hero-head {
  max-width: 720px;
  margin-bottom: 22px;
}

.hero-head h1 {
  margin: 0 0 8px;
  font-size: clamp(1.45rem, 2.5vw, 2.05rem);
  font-weight: 800;
  letter-spacing: -0.03em;
  line-height: 1.2;
}

.hero-head p {
  margin: 0;
  color: var(--text-muted);
  font-size: 0.96rem;
}

.scan-form {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.input-row {
  display: flex;
  gap: 10px;
  flex-wrap: wrap;
}

.url-input-wrap {
  flex: 1 1 340px;
  position: relative;
  display: flex;
  align-items: center;
}

.url-icon {
  position: absolute;
  left: 15px;
  color: var(--text-muted);
  pointer-events: none;
}

.url-input-wrap input {
  width: 100%;
  height: 50px;
  padding: 0 78px 0 44px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.95rem;
  transition: border-color 0.15s, box-shadow 0.15s;
}

.url-input-wrap input:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 4px var(--accent-soft);
}

.ghost-inline-btn {
  position: absolute;
  right: 8px;
  height: 34px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: color 0.15s, background 0.15s;
}

.ghost-inline-btn:hover {
  color: var(--text);
  background: var(--surface-subtle);
}

/* Buttons */
.btn-primary,
.btn-secondary,
.btn-ghost-sm {
  font-family: inherit;
  font-weight: 700;
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  text-decoration: none;
  transition: transform 0.12s, background 0.15s, opacity 0.15s, border-color 0.15s;
}

.btn-primary {
  height: 50px;
  padding: 0 22px;
  border: none;
  border-radius: 14px;
  background: var(--accent);
  color: #fff;
  font-size: 0.94rem;
  box-shadow: 0 4px 14px rgba(230, 0, 35, 0.25);
}

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

.btn-primary:disabled {
  opacity: 0.55;
  cursor: not-allowed;
  transform: none;
}

.btn-primary.btn-sm {
  height: 38px;
  padding: 0 15px;
  border-radius: 10px;
  font-size: 0.84rem;
}

.btn-primary.btn-download {
  height: 40px;
  padding: 0 18px;
  border-radius: 11px;
  font-size: 0.88rem;
}

.btn-secondary {
  height: 50px;
  padding: 0 20px;
  border-radius: 14px;
  border: 1.5px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.92rem;
}

.btn-secondary:hover {
  background: var(--surface-subtle);
}

.btn-ghost-sm {
  height: 36px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-size: 0.82rem;
  font-weight: 600;
}

.btn-ghost-sm:hover {
  background: var(--surface-subtle);
}

/* Options row */
.options-row {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 16px;
  font-size: 0.86rem;
  color: var(--text-muted);
}

.option-item {
  display: inline-flex;
  align-items: center;
  gap: 8px;
  font-weight: 500;
}

.option-item select,
.compact-select {
  height: 36px;
  padding: 0 10px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
}

.checkbox-inline {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  cursor: pointer;
  user-select: none;
  font-weight: 500;
}

.checkbox-inline input[type="checkbox"] {
  width: 16px;
  height: 16px;
  accent-color: var(--accent);
  cursor: pointer;
}

.link-btn {
  margin-left: auto;
  border: none;
  background: none;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.84rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: underline;
  text-underline-offset: 3px;
}

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

.advanced-panel {
  padding: 14px 16px;
  border-radius: 12px;
  background: var(--surface-subtle);
  border: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.advanced-label {
  font-size: 0.84rem;
  font-weight: 600;
}

.advanced-panel input {
  height: 40px;
  padding: 0 12px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text);
  font-family: inherit;
  font-size: 0.86rem;
}

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

/* Progress bar */
.scan-progress {
  margin-top: 20px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
}

.scan-progress-top {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  margin-bottom: 10px;
  font-size: 0.88rem;
}

.scan-status-text {
  font-weight: 600;
}

.scan-count-badge {
  font-weight: 700;
  color: var(--accent);
  background: var(--accent-soft);
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 0.8rem;
}

.progress-track {
  width: 100%;
  height: 8px;
  border-radius: 999px;
  background: var(--surface-subtle);
  overflow: hidden;
}

.progress-track.lg {
  height: 11px;
}

.progress-bar {
  height: 100%;
  background: var(--accent);
  border-radius: 999px;
  transition: width 0.25s ease;
}

.progress-bar.indeterminate {
  width: 38%;
  animation: indeterminateMove 1.3s ease-in-out infinite;
}

@keyframes indeterminateMove {
  0% {
    transform: translateX(-110%);
  }
  100% {
    transform: translateX(320%);
  }
}

/* Error Alert */
.error-alert {
  margin-top: 16px;
  padding: 13px 16px;
  border-radius: 12px;
  background: var(--error-bg);
  border: 1px solid var(--error-border);
  color: var(--error-text);
  display: flex;
  align-items: flex-start;
  gap: 10px;
  font-size: 0.88rem;
  font-weight: 500;
}

.error-alert svg {
  flex-shrink: 0;
  margin-top: 2px;
}

/* Board Summary */
.board-summary {
  margin-top: 24px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 20px;
  display: flex;
  align-items: center;
  gap: 20px;
  box-shadow: var(--shadow-sm);
}

.board-cover-wrap {
  width: 84px;
  height: 84px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface-subtle);
  flex-shrink: 0;
}

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

.board-meta {
  flex: 1;
  min-width: 0;
}

.board-title-row {
  display: flex;
  align-items: center;
  gap: 12px;
  flex-wrap: wrap;
}

.board-title-row h2 {
  margin: 0;
  font-size: 1.25rem;
  font-weight: 800;
  letter-spacing: -0.02em;
}

.external-link {
  font-size: 0.8rem;
  font-weight: 600;
  color: var(--text-muted);
  text-decoration: none;
}

.external-link:hover {
  color: var(--accent);
}

.board-owner {
  font-size: 0.86rem;
  color: var(--text-muted);
  margin-top: 2px;
}

.board-desc {
  margin: 6px 0 0;
  font-size: 0.86rem;
  color: var(--text-muted);
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.board-stats {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 10px;
}

.stat-chip {
  font-size: 0.78rem;
  padding: 4px 10px;
  border-radius: 999px;
  background: var(--surface-subtle);
  color: var(--text-muted);
}

.stat-chip strong {
  color: var(--text);
}

.stat-chip.stat-warn {
  background: var(--warn-bg);
  color: var(--warn-text);
  font-weight: 600;
}

/* Toolbar */
.gallery-section {
  margin-top: 20px;
}

.toolbar {
  position: sticky;
  top: 72px;
  z-index: 30;
  background: color-mix(in srgb, var(--surface) 94%, transparent);
  backdrop-filter: blur(12px);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 12px 14px;
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  box-shadow: var(--shadow-sm);
  margin-bottom: 20px;
}

.toolbar-left,
.toolbar-right {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
}

.search-box {
  position: relative;
  display: flex;
  align-items: center;
}

.search-box svg {
  position: absolute;
  left: 11px;
  color: var(--text-muted);
  pointer-events: none;
}

.search-box input {
  height: 36px;
  width: 195px;
  padding: 0 10px 0 32px;
  border-radius: 9px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  font-family: inherit;
  font-size: 0.84rem;
}

.search-box input:focus {
  outline: none;
  border-color: var(--accent);
}

.filter-pills {
  display: flex;
  flex-wrap: wrap;
  gap: 5px;
}

.filter-pill {
  height: 34px;
  padding: 0 12px;
  border-radius: 999px;
  border: 1px solid var(--border);
  background: transparent;
  color: var(--text-muted);
  font-family: inherit;
  font-size: 0.8rem;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.15s;
}

.filter-pill:hover {
  color: var(--text);
  background: var(--surface-subtle);
}

.filter-pill.active {
  background: var(--text);
  color: var(--bg);
  border-color: var(--text);
}

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

.compact-check {
  font-size: 0.82rem;
  color: var(--text-muted);
  padding: 0 4px;
}

/* Masonry Gallery */
.masonry-grid {
  column-count: 5;
  column-gap: 16px;
}

@media (max-width: 1200px) {
  .masonry-grid {
    column-count: 4;
  }
}

@media (max-width: 900px) {
  .masonry-grid {
    column-count: 3;
  }
}

@media (max-width: 600px) {
  .masonry-grid {
    column-count: 2;
    column-gap: 12px;
  }
  .hero-card {
    padding: 20px;
  }
  .board-summary {
    flex-direction: column;
    align-items: flex-start;
  }
}

.pin-card {
  break-inside: avoid;
  margin-bottom: 16px;
  border-radius: 14px;
  overflow: hidden;
  background: var(--surface);
  border: 2px solid transparent;
  box-shadow: var(--shadow-sm);
  cursor: pointer;
  position: relative;
  transition: transform 0.15s, border-color 0.15s, opacity 0.15s, box-shadow 0.15s;
}

.pin-card:hover {
  transform: translateY(-2px);
  box-shadow: var(--shadow-md);
}

.pin-card.selected {
  border-color: var(--accent);
}

.pin-card:not(.selected) {
  opacity: 0.62;
}

.pin-card:not(.selected):hover {
  opacity: 0.92;
}

.pin-img-box {
  position: relative;
  width: 100%;
  background: var(--surface-subtle);
  overflow: hidden;
}

.pin-img-box img {
  width: 100%;
  height: auto;
  display: block;
  min-height: 90px;
}

.pin-check {
  position: absolute;
  top: 10px;
  left: 10px;
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: rgba(17, 17, 19, 0.58);
  border: 2px solid rgba(255, 255, 255, 0.9);
  color: #fff;
  display: grid;
  place-items: center;
  backdrop-filter: blur(4px);
  transition: background 0.15s, transform 0.15s;
}

.pin-card.selected .pin-check {
  background: var(--accent);
  border-color: #fff;
}

.pin-zoom-btn {
  position: absolute;
  top: 10px;
  right: 10px;
  width: 30px;
  height: 30px;
  border-radius: 50%;
  border: none;
  background: rgba(17, 17, 19, 0.62);
  color: #fff;
  display: grid;
  place-items: center;
  cursor: pointer;
  opacity: 0;
  backdrop-filter: blur(4px);
  transition: opacity 0.15s, background 0.15s;
}

.pin-card:hover .pin-zoom-btn,
.pin-zoom-btn:focus-visible {
  opacity: 1;
}

.pin-zoom-btn:hover {
  background: rgba(17, 17, 19, 0.88);
}

.pin-badges {
  position: absolute;
  bottom: 8px;
  left: 8px;
  right: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  pointer-events: none;
  gap: 6px;
}

.res-badge {
  font-size: 0.7rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(17, 17, 19, 0.72);
  color: #fff;
  backdrop-filter: blur(4px);
}

.video-badge {
  font-size: 0.68rem;
  font-weight: 700;
  padding: 3px 7px;
  border-radius: 6px;
  background: rgba(230, 0, 35, 0.86);
  color: #fff;
}

.pin-caption {
  padding: 9px 11px;
  font-size: 0.78rem;
  font-weight: 500;
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.empty-state {
  text-align: center;
  padding: 48px 20px;
  border-radius: var(--radius-md);
  border: 1px dashed var(--border);
  color: var(--text-muted);
}

/* Tips Grid */
.tips-grid {
  margin-top: 26px;
  display: grid;
  grid-template-columns: repeat(3, minmax(0, 1fr));
  gap: 16px;
}

@media (max-width: 820px) {
  .tips-grid {
    grid-template-columns: 1fr;
  }
}

.tip-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  padding: 22px;
}

.tip-icon {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 34px;
  height: 34px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--accent);
  font-weight: 800;
  font-size: 0.82rem;
  margin-bottom: 12px;
}

.tip-card h3 {
  margin: 0 0 6px;
  font-size: 1rem;
  font-weight: 700;
}

.tip-card p {
  margin: 0;
  font-size: 0.86rem;
  color: var(--text-muted);
}

/* Modals */
.modal-backdrop {
  position: fixed;
  inset: 0;
  z-index: 100;
  background: rgba(10, 10, 12, 0.65);
  backdrop-filter: blur(6px);
  display: grid;
  place-items: center;
  padding: 20px;
}

.modal-card {
  width: 100%;
  max-width: 500px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.modal-header {
  padding: 20px 24px 14px;
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}

.modal-header h3 {
  margin: 0;
  font-size: 1.12rem;
  font-weight: 800;
}

.modal-subtitle {
  margin: 3px 0 0;
  font-size: 0.82rem;
  color: var(--text-muted);
  word-break: break-all;
}

.modal-body {
  padding: 6px 24px 20px;
}

.zip-progress-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 10px;
  margin-top: 10px;
  font-size: 0.84rem;
}

.zip-current-file {
  color: var(--text-muted);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.zip-percent {
  font-weight: 800;
  color: var(--accent);
}

.zip-metrics {
  margin-top: 16px;
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 10px;
}

.metric-box {
  background: var(--surface-subtle);
  border-radius: 12px;
  padding: 12px;
  display: flex;
  flex-direction: column;
  gap: 3px;
}

.metric-label {
  font-size: 0.74rem;
  color: var(--text-muted);
  font-weight: 600;
}

.metric-box strong {
  font-size: 0.98rem;
}

.failed-details {
  margin-top: 14px;
  font-size: 0.8rem;
  color: var(--error-text);
}

.failed-details summary {
  cursor: pointer;
  font-weight: 600;
}

.failed-details ul {
  margin: 8px 0 0;
  padding-left: 18px;
  max-height: 120px;
  overflow-y: auto;
}

.modal-footer {
  padding: 14px 24px 20px;
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}

/* Lightbox */
.lightbox-card {
  position: relative;
  width: 100%;
  max-width: 920px;
  max-height: 90vh;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
  display: flex;
  flex-direction: column;
  box-shadow: var(--shadow-lg);
}

.lightbox-close {
  position: absolute;
  top: 14px;
  right: 14px;
  z-index: 5;
  width: 36px;
  height: 36px;
  border-radius: 50%;
  border: none;
  background: rgba(17, 17, 19, 0.75);
  color: #fff;
  font-size: 1rem;
  cursor: pointer;
}

.lightbox-media {
  background: #0d0d0f;
  flex: 1;
  min-height: 260px;
  max-height: calc(90vh - 82px);
  display: grid;
  place-items: center;
  overflow: auto;
}

.lightbox-media img {
  max-width: 100%;
  max-height: calc(90vh - 86px);
  object-fit: contain;
  display: block;
}

.lightbox-bar {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 14px;
  flex-wrap: wrap;
}

.lightbox-info {
  display: flex;
  flex-direction: column;
  min-width: 0;
  max-width: 520px;
}

.lightbox-info strong {
  font-size: 0.92rem;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.lightbox-info span {
  font-size: 0.8rem;
}

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

/* Toast */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 120;
  background: var(--text);
  color: var(--bg);
  padding: 11px 18px;
  border-radius: 999px;
  font-size: 0.86rem;
  font-weight: 600;
  box-shadow: var(--shadow-lg);
}
