:root {
  --bg: #0c1016;
  --panel: #121820;
  --panel-2: #1a2230;
  --border: rgba(107, 159, 212, 0.22);
  --text: #e8eaed;
  --muted: #8a939e;
  --accent: #3d6a9e;
  --accent-2: #6b9fd4;
  --danger: #e05a5a;
  --font: Inter, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  --img-min: 180px;
}

* { box-sizing: border-box; }
html, body {
  margin: 0;
  min-height: 100%;
  background: radial-gradient(1200px 600px at 15% -10%, #1a2d4a 0%, var(--bg) 55%);
  color: var(--text);
  font-family: var(--font);
}

.hidden { display: none !important; }

.gate {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
}
.gate-card {
  width: min(440px, 100%);
  background: rgba(18, 24, 32, 0.92);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 28px 24px;
  text-align: center;
  box-shadow: 0 16px 48px rgba(0,0,0,0.35);
}
.gate-card h1 { margin: 12px 0 8px; font-size: 1.6rem; }
.gate-card p { margin: 0 0 18px; color: var(--muted); line-height: 1.45; }
.gate-actions { display: flex; gap: 8px; justify-content: center; flex-wrap: wrap; }

.brand-mark {
  width: 52px; height: 52px; border-radius: 12px;
  display: grid; place-items: center; margin: 0 auto;
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0c1016; font-weight: 800; font-size: 1.05rem;
}
.brand-mark.sm { width: 40px; height: 40px; margin: 0; font-size: 0.9rem; }

.btn {
  appearance: none; border: 1px solid var(--border);
  background: var(--panel-2); color: var(--text);
  border-radius: 9px; padding: 9px 14px; font-weight: 600;
  text-decoration: none; cursor: pointer;
}
.btn.primary {
  background: linear-gradient(135deg, var(--accent), var(--accent-2));
  color: #0c1016; border-color: transparent;
}
.btn.danger {
  background: rgba(224, 90, 90, 0.12);
  border-color: rgba(224, 90, 90, 0.45);
  color: #f0a8a8;
}
.btn.danger:hover { background: rgba(224, 90, 90, 0.22); }
.btn.ghost:hover { border-color: var(--accent-2); }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.icon-btn {
  display: inline-grid; place-items: center;
  padding: 10px 12px; flex-shrink: 0;
}

.topbar {
  display: flex; align-items: center; justify-content: space-between; gap: 16px;
  padding: 14px 20px; border-bottom: 1px solid var(--border);
  background: rgba(12, 16, 22, 0.88); backdrop-filter: blur(8px);
  position: sticky; top: 0; z-index: 5;
}
.brand { display: flex; align-items: center; gap: 12px; }
.brand h1 { margin: 0; font-size: 1.15rem; }
.brand p { margin: 2px 0 0; color: var(--muted); font-size: 0.85rem; }
.top-actions { display: flex; gap: 8px; flex-wrap: wrap; }

.shell {
  max-width: 980px;
  margin: 0 auto;
  padding: 20px 16px 48px;
  transition: max-width 0.2s ease;
}
.shell.is-images { max-width: 1280px; }
.shell.is-images.size-l { max-width: 1440px; }
.shell.is-images.size-xl { max-width: 1600px; }

.search-box {
  position: relative;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: rgba(18, 24, 32, 0.85);
  padding: 14px;
  margin-bottom: 18px;
}
.tabs { display: flex; gap: 6px; margin-bottom: 10px; flex-wrap: wrap; }
.tab {
  appearance: none; border: 1px solid transparent;
  background: transparent; color: var(--muted);
  border-radius: 999px; padding: 7px 14px; font-weight: 650; cursor: pointer;
}
.tab.is-active {
  color: var(--text);
  background: rgba(107, 159, 212, 0.16);
  border-color: var(--border);
}
.search-row { display: flex; gap: 8px; }
.search-row input {
  flex: 1; min-width: 0;
  border-radius: 10px; border: 1px solid var(--border);
  background: #0c1016; color: var(--text);
  padding: 12px 14px; font-size: 1rem;
}
.search-row input:focus { outline: 1px solid var(--accent-2); }

.image-tools {
  display: flex; flex-wrap: wrap; gap: 10px 14px;
  align-items: center; margin-top: 10px;
  padding-top: 10px; border-top: 1px solid rgba(255,255,255,0.05);
}
.size-label {
  display: inline-flex; align-items: center; gap: 8px;
  color: var(--muted); font-size: 0.88rem; font-weight: 600;
}
.size-label select {
  appearance: none;
  background: #0c1016; color: var(--text);
  border: 1px solid var(--border); border-radius: 8px;
  padding: 7px 10px; font-size: 0.9rem; cursor: pointer;
}
.reverse-row {
  display: flex; gap: 8px; flex: 1; min-width: min(100%, 280px);
}
.reverse-row input {
  flex: 1; min-width: 0;
  border-radius: 8px; border: 1px solid var(--border);
  background: #0c1016; color: var(--text);
  padding: 8px 10px; font-size: 0.9rem;
}

.suggest {
  list-style: none; margin: 8px 0 0; padding: 0;
  border: 1px solid var(--border); border-radius: 10px; overflow: hidden;
  background: #10161f;
}
.suggest li {
  padding: 10px 12px; cursor: pointer; color: var(--muted);
  border-bottom: 1px solid rgba(255,255,255,0.04);
}
.suggest li:last-child { border-bottom: 0; }
.suggest li:hover, .suggest li.is-active { background: rgba(107,159,212,0.12); color: var(--text); }

.meta { color: var(--muted); font-size: 0.9rem; margin: 0 0 12px; }
.answers {
  margin: 0 0 14px; padding: 12px 14px; border-radius: 12px;
  border: 1px solid var(--border); background: rgba(26, 34, 48, 0.55);
}
.answers p { margin: 0; line-height: 1.45; }

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

.result {
  display: grid;
  grid-template-columns: 120px 1fr;
  gap: 16px;
  padding: 14px;
  border-radius: 14px;
  border: 1px solid var(--border);
  background: rgba(18, 24, 32, 0.88);
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  transition: border-color 0.15s, transform 0.15s;
}
.result:hover {
  border-color: rgba(107, 159, 212, 0.45);
  transform: translateY(-1px);
}
.result-thumb {
  width: 120px;
  height: 90px;
  border-radius: 12px;
  overflow: hidden;
  background: #0a0e14;
  border: 1px solid rgba(255,255,255,0.06);
  display: grid;
  place-items: center;
  flex-shrink: 0;
}
.result-thumb img {
  width: 100%;
  height: 100%;
  object-fit: cover;
  display: block;
  background: #0a0e14;
}
.result-thumb.is-empty {
  background:
    linear-gradient(135deg, rgba(107,159,212,0.08), transparent 60%),
    #0a0e14;
}
.result-body { min-width: 0; display: flex; flex-direction: column; gap: 4px; }
.result-url {
  color: var(--accent-2); font-size: 0.82rem;
  text-decoration: none; white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.result-title {
  color: var(--text); font-size: 1.18rem; font-weight: 750; text-decoration: none;
  line-height: 1.25; letter-spacing: -0.01em;
}
.result-title:hover { color: var(--accent-2); }
.result-snippet {
  color: #b7c2d0; line-height: 1.5; font-size: 0.98rem;
  display: -webkit-box; -webkit-line-clamp: 3; -webkit-box-orient: vertical; overflow: hidden;
}
.result-meta {
  margin-top: 6px; display: flex; flex-wrap: wrap; gap: 8px; align-items: center;
  color: var(--muted); font-size: 0.78rem;
}
.chip {
  display: inline-flex; align-items: center;
  padding: 2px 8px; border-radius: 999px;
  background: rgba(107, 159, 212, 0.12);
  border: 1px solid rgba(107, 159, 212, 0.2);
  color: #c5d8ef;
}

.shopping-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(210px, 1fr));
  gap: 14px;
}
.shop-card {
  border: 1px solid var(--border);
  border-radius: 14px;
  overflow: hidden;
  background: rgba(18, 24, 32, 0.88);
  text-decoration: none; color: inherit;
  display: flex; flex-direction: column;
  box-shadow: 0 8px 24px rgba(0,0,0,0.18);
  transition: border-color 0.15s, transform 0.15s;
}
.shop-card:hover {
  border-color: rgba(107, 159, 212, 0.45);
  transform: translateY(-1px);
}
.shop-card .thumb {
  width: 100%; aspect-ratio: 1; background: #0a0e14;
  display: grid; place-items: center; overflow: hidden;
}
.shop-card .thumb img {
  width: 100%; height: 100%; object-fit: cover; display: block;
}
.shop-card .body { padding: 10px 12px 12px; display: flex; flex-direction: column; gap: 4px; }
.shop-card .title {
  font-size: 0.95rem; font-weight: 700; line-height: 1.3;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden;
}
.shop-card .price { color: #9ad0ff; font-weight: 750; font-size: 1.12rem; margin-top: 2px; }
.shop-card .price.is-fallback { color: var(--muted); font-weight: 600; font-size: 0.92rem; }
.shop-card .engine { color: var(--muted); font-size: 0.75rem; }

.image-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(var(--img-min), 1fr));
  gap: 12px;
  align-items: start;
}
.image-grid[data-size="s"] { --img-min: 120px; }
.image-grid[data-size="m"] { --img-min: 180px; }
.image-grid[data-size="l"] { --img-min: 260px; }
.image-grid[data-size="xl"] { --img-min: 340px; }

.image-card {
  border: 1px solid var(--border);
  border-radius: 12px;
  overflow: hidden;
  background: rgba(18, 24, 32, 0.72);
  color: inherit;
  display: flex; flex-direction: column;
  cursor: zoom-in;
  transition: border-color 0.18s, box-shadow 0.18s, transform 0.18s;
}
.image-card:hover {
  border-color: rgba(107, 159, 212, 0.45);
}
.image-card.is-expanded {
  grid-column: span 2;
  grid-row: span 2;
  cursor: pointer;
  z-index: 2;
  border-color: rgba(107, 159, 212, 0.65);
  box-shadow: 0 16px 40px rgba(0,0,0,0.45);
}
.image-card img {
  width: 100%; aspect-ratio: 1; object-fit: cover; background: #0a0e14;
  display: block;
  transition: aspect-ratio 0.2s ease;
}
.image-card.is-expanded img {
  aspect-ratio: auto;
  max-height: min(70vh, 720px);
  object-fit: contain;
  background: #05070a;
}
.image-card .cap {
  padding: 8px 10px; font-size: 0.8rem; color: var(--muted);
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.image-card.is-expanded .cap {
  white-space: normal;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
}
.image-card .open-hint {
  display: none;
  padding: 0 10px 10px;
  font-size: 0.75rem;
  color: var(--accent-2);
}
.image-card.is-expanded .open-hint { display: block; }

.pager {
  display: flex; align-items: center; justify-content: center; gap: 12px;
  margin-top: 22px; color: var(--muted);
}
.empty, .error {
  text-align: center; color: var(--muted); padding: 36px 12px;
}
.error { color: #f0a0a0; }

@media (max-width: 640px) {
  .search-row { flex-wrap: wrap; }
  .brand-mark.sm { display: none; }
  .result { grid-template-columns: 88px 1fr; gap: 10px; }
  .result-thumb { width: 88px; height: 66px; }
  .image-card.is-expanded {
    grid-column: span 1;
    grid-row: span 1;
  }
  .image-grid[data-size="xl"],
  .image-grid[data-size="l"] { --img-min: 160px; }
}
