:root {
  --bg: #0f0f0f;
  --bg2: #1e1e1e;
  --text: #e0e0e0;
  --hint: #888;
  --border: #2a2a2a;
  --accent: #ff4444;
}

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

body {
  background: var(--bg);
  color: var(--text);
  font-family: system-ui, -apple-system, sans-serif;
  direction: rtl;
  min-height: 100vh;
}

#app {
  max-width: 480px;
  margin: 0 auto;
  padding: 0 16px 32px;
}

/* View routing */
.view { display: none; }
.view.active { display: block; }

/* ───── Hero search screen ───── */
#search-hero {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 56px 0 32px;
  text-align: center;
  transition: padding 0.35s ease, opacity 0.25s ease;
}

#search-hero.collapsed {
  padding: 16px 0 12px;
}

#hero-header {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 10px;
  transition: transform 0.35s ease, opacity 0.25s ease;
}

#search-hero.collapsed #hero-header {
  transform: scale(0.82) translateY(-4px);
  opacity: 0.7;
}

#hero-logo {
  font-size: 2.4rem;
  line-height: 1;
  filter: drop-shadow(0 0 8px rgba(255,68,68,0.4));
}

#search-hero.collapsed #hero-logo {
  font-size: 1.6rem;
}

#hero-title {
  font-size: 1.4rem;
  font-weight: 700;
  letter-spacing: -0.02em;
  background: linear-gradient(135deg, var(--text) 40%, var(--accent));
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  background-clip: text;
}

#search-hero.collapsed #hero-title {
  font-size: 1rem;
}

#hero-hint {
  font-size: 0.82rem;
  color: var(--hint);
  max-width: 260px;
  line-height: 1.5;
  margin-bottom: 24px;
  transition: max-height 0.3s ease, opacity 0.25s ease, margin 0.3s ease;
}

#search-hero.collapsed #hero-hint {
  max-height: 0;
  opacity: 0;
  margin-bottom: 10px;
  overflow: hidden;
  pointer-events: none;
}

/* Search box */
#search-box-wrap {
  display: flex;
  align-items: center;
  width: 100%;
  max-width: 400px;
  background: var(--bg2);
  border-radius: 16px;
  border: 2px solid var(--border);
  padding: 4px 6px 4px 10px;
  gap: 4px;
  transition: border-color 0.2s, box-shadow 0.3s, transform 0.2s;
}

#search-box-wrap.focused {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(255, 68, 68, 0.12), 0 4px 24px rgba(255, 68, 68, 0.08);
  transform: scale(1.01);
}

#search-input {
  flex: 1;
  background: transparent;
  color: var(--text);
  border: none;
  outline: none;
  padding: 12px 8px;
  font-size: 1rem;
  font-family: inherit;
  min-height: 48px;
}

#search-input::placeholder {
  color: var(--hint);
}

#clear-btn {
  display: none;
  align-items: center;
  justify-content: center;
  background: var(--border);
  border: none;
  color: var(--hint);
  font-size: 0.75rem;
  cursor: pointer;
  padding: 0;
  width: 24px;
  height: 24px;
  border-radius: 50%;
  flex-shrink: 0;
  transition: background 0.15s, color 0.15s;
}

#clear-btn:hover { background: var(--accent); color: #fff; }

#search-btn {
  background: var(--accent);
  color: #fff;
  border: none;
  border-radius: 12px;
  padding: 10px 14px;
  font-size: 1rem;
  cursor: pointer;
  min-height: 44px;
  flex-shrink: 0;
  transition: background 0.15s, transform 0.15s;
}

#search-btn:hover  { background: #e03030; }
#search-btn:active { transform: scale(0.92); }

/* Status text */
#search-status {
  text-align: center;
  color: var(--hint);
  font-size: 0.9rem;
  padding: 24px 0;
}

/* Results list */
#results { margin-top: 4px; }

/* Result card — slide-in animation */
@keyframes card-in {
  from { opacity: 0; transform: translateY(10px); }
  to   { opacity: 1; transform: translateY(0); }
}

.result-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  border-radius: 12px;
  border: 1px solid var(--border);
  border-right: 3px solid transparent;
  cursor: pointer;
  margin-bottom: 8px;
  animation: card-in 0.3s ease both;
  transition: background 0.15s, border-right-color 0.2s, transform 0.1s;
}

.result-card:hover {
  background: #181818;
  border-right-color: var(--accent);
}

.result-card:active {
  background: var(--bg2);
  transform: scale(0.97);
}

.thumb {
  width: 120px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  border-radius: 6px;
  flex-shrink: 0;
  background: var(--bg2);
}

.meta {
  flex: 1;
  min-width: 0;
  display: flex;
  flex-direction: column;
  justify-content: center;
  gap: 6px;
}

.title {
  font-weight: 600;
  font-size: 0.92rem;
  line-height: 1.4;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.sub {
  font-size: 0.8rem;
  color: var(--hint);
}

/* ───── Picker screen ───── */
.picker-thumb {
  width: 100%;
  aspect-ratio: 16 / 9;
  border-radius: 12px;
  object-fit: cover;
  margin-top: 12px;
  background: var(--bg2);
}

.picker-title {
  font-weight: 700;
  font-size: 1rem;
  line-height: 1.4;
  margin: 12px 0 4px;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
  overflow: hidden;
}

.picker-sub {
  font-size: 0.85rem;
  color: var(--hint);
  margin-bottom: 8px;
}

.picker-desc {
  font-size: 0.82rem;
  color: var(--hint);
  line-height: 1.5;
  margin-bottom: 16px;
  white-space: pre-line;
}

.desc-toggle {
  display: block;
  background: none;
  border: none;
  color: #aaa;
  font-size: 0.8rem;
  font-family: inherit;
  cursor: pointer;
  padding: 4px 0 0;
  text-align: right;
  width: 100%;
}

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

/* Quality buttons — staggered pop-in */
.quality-list {
  display: flex;
  flex-direction: column;
  gap: 10px;
  margin-top: 4px;
}

@keyframes btn-pop {
  0%   { opacity: 0; transform: scale(0.92) translateY(8px); }
  70%  { transform: scale(1.02) translateY(0); }
  100% { opacity: 1; transform: scale(1) translateY(0); }
}

.quality-btn {
  display: flex;
  justify-content: space-between;
  align-items: center;
  width: 100%;
  background: var(--bg2);
  color: var(--text);
  border: 1.5px solid var(--border);
  border-radius: 14px;
  padding: 16px 18px;
  font-size: 1rem;
  font-family: inherit;
  cursor: pointer;
  position: relative;
  overflow: hidden;
  animation: btn-pop 0.4s cubic-bezier(0.34, 1.56, 0.64, 1) both;
  transition: background 0.15s, border-color 0.2s, transform 0.12s, box-shadow 0.2s;
}

/* ripple pseudo-element */
.quality-btn::after {
  content: "";
  position: absolute;
  inset: 0;
  background: radial-gradient(circle at var(--rx, 50%) var(--ry, 50%), rgba(255,68,68,0.18) 0%, transparent 70%);
  opacity: 0;
  transition: opacity 0.4s ease;
  pointer-events: none;
}

.quality-btn:hover {
  background: #242424;
  border-color: var(--accent);
  box-shadow: 0 0 0 1px rgba(255,68,68,0.15), 0 4px 16px rgba(255,68,68,0.08);
}

.quality-btn:hover::after { opacity: 1; }

.quality-btn:active {
  transform: scale(0.96);
  box-shadow: none;
}

.qlabel {
  font-weight: 700;
  font-size: 1rem;
}

.qsize {
  color: var(--hint);
  font-size: 0.85rem;
  background: var(--bg);
  border-radius: 6px;
  padding: 3px 8px;
  border: 1px solid var(--border);
}

.picker-loading {
  text-align: center;
  color: var(--hint);
  padding: 48px 0;
}

.picker-error {
  text-align: center;
  color: var(--accent);
  padding: 32px 0;
  font-size: 0.9rem;
}

/* ───── Empty / error states ───── */
.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--hint);
}

.empty-icon {
  font-size: 40px;
  margin-bottom: 12px;
}

.error-card {
  text-align: center;
  padding: 32px 16px;
}

.error-msg {
  color: var(--accent);
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.retry-btn {
  background: var(--bg2);
  color: var(--text);
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 24px;
  font-family: inherit;
  cursor: pointer;
  font-size: 0.9rem;
  transition: background 0.15s, border-color 0.2s;
}

.retry-btn:hover {
  background: var(--border);
  border-color: var(--accent);
}

/* ───── Skeleton loaders ───── */
.skeleton {
  background: linear-gradient(
    90deg,
    var(--bg2) 0%,
    var(--border) 40%,
    color-mix(in srgb, var(--accent) 12%, var(--border)) 50%,
    var(--border) 60%,
    var(--bg2) 100%
  );
  background-size: 200% 100%;
  animation: shimmer 1.4s ease-in-out infinite;
  border-radius: 8px;
}

@keyframes shimmer {
  0%   { background-position: 200% 0; }
  100% { background-position: -200% 0; }
}

.skeleton-card {
  display: flex;
  gap: 12px;
  padding: 12px;
  margin-bottom: 8px;
  border-radius: 12px;
  border: 1px solid var(--border);
}

.skeleton-thumb  { width: 120px; height: 68px; border-radius: 6px; flex-shrink: 0; }
.skeleton-line   { height: 14px; border-radius: 4px; margin-bottom: 6px; }
.skeleton-line.wide   { width: 80%; }
.skeleton-line.narrow { width: 50%; }
.skeleton-picker-thumb { width: 100%; aspect-ratio: 16/9; border-radius: 12px; margin-top: 12px; }
.skeleton-btn    { height: 54px; border-radius: 14px; margin-bottom: 10px; }

/* ───── Status overlay ───── */
#status-overlay {
  position: fixed;
  inset: 0;
  background: var(--bg);
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 16px;
  text-align: center;
  padding: 32px;
  z-index: 100;
}

#status-overlay.hidden { display: none; }

.status-icon {
  font-size: 48px;
  animation: pulse 1s ease-in-out infinite alternate;
}

@keyframes pulse {
  from { opacity: 0.6; }
  to   { opacity: 1.0; }
}

.status-msg {
  font-size: 16px;
  line-height: 1.6;
  color: var(--text);
  white-space: pre-line;
}
