:root {
  --purple: #7c3aed;
  --purple-dark: #6d28d9;
  --pink: #ec4899;
  --green: #22c55e;
  --green-dark: #16a34a;
  --yellow: #facc15;
  --blue: #3b82f6;
  --bg1: #a78bfa;
  --bg2: #f0abfc;
  --ink: #2d1b4e;
  --card: #ffffff;
}

* { box-sizing: border-box; -webkit-tap-highlight-color: transparent; }

html, body {
  margin: 0;
  min-height: 100%;
  font-family: -apple-system, "SF Pro Rounded", "Apple SD Gothic Neo", system-ui, sans-serif;
  color: var(--ink);
  background: linear-gradient(160deg, var(--bg1), var(--bg2));
  background-attachment: fixed;
}

.app {
  max-width: 520px;
  margin: 0 auto;
  padding: max(24px, env(safe-area-inset-top)) 20px 40px;
  display: flex;
  flex-direction: column;
  gap: 20px;
}

.header {
  text-align: center;
  margin-top: 8px;
}
.logo { font-size: 64px; line-height: 1; }
.header h1 {
  margin: 4px 0 0;
  font-size: 34px;
  font-weight: 900;
  color: #fff;
  text-shadow: 0 3px 0 rgba(0,0,0,0.12);
  letter-spacing: 1px;
}
.subtitle {
  margin: 6px 0 0;
  font-size: 15px;
  font-weight: 700;
  color: #ffe4f2;
  opacity: 0.85;
  text-shadow: 0 1px 2px rgba(0,0,0,0.08);
}

.card {
  background: var(--card);
  border-radius: 28px;
  padding: 24px;
  box-shadow: 0 12px 30px rgba(80, 30, 120, 0.22);
  display: flex;
  flex-direction: column;
  gap: 18px;
  animation: pop 0.25s ease;
}
@keyframes pop {
  from { transform: scale(0.96); opacity: 0; }
  to   { transform: scale(1);    opacity: 1; }
}

input#url {
  width: 100%;
  font-size: 20px;
  padding: 18px 20px;
  border: 3px solid #e9d5ff;
  border-radius: 20px;
  outline: none;
  background: #faf5ff;
}
input#url:focus { border-color: var(--purple); }

.big-btn {
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  width: 100%;
  font-size: 26px;
  font-weight: 900;
  padding: 22px;
  border: none;
  border-radius: 24px;
  color: #fff;
  cursor: pointer;
  text-decoration: none;
  box-shadow: 0 6px 0 rgba(0,0,0,0.15);
  transition: transform 0.08s ease, box-shadow 0.08s ease;
  user-select: none;
}
.big-btn:active { transform: translateY(4px); box-shadow: 0 2px 0 rgba(0,0,0,0.15); }

.find  { background: var(--purple); }
.save  { background: var(--green); }
.again { background: var(--blue); }

.state {
  text-align: center;
  color: #fff;
  font-size: 22px;
  font-weight: 800;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.spinner {
  width: 64px; height: 64px;
  border: 8px solid rgba(255,255,255,0.4);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.9s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

#thumb {
  width: 100%;
  border-radius: 18px;
  aspect-ratio: 16 / 9;
  object-fit: cover;
  background: #eee;
}
.title {
  margin: 0;
  font-size: 19px;
  font-weight: 800;
  text-align: center;
  line-height: 1.35;
  max-height: 3.2em;
  overflow: hidden;
}
.hint {
  margin: 0;
  text-align: center;
  font-size: 20px;
  font-weight: 800;
  color: #7c3aed;
}

.quality-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 14px;
}
.q-btn {
  border: none;
  border-radius: 22px;
  padding: 20px 10px;
  font-weight: 900;
  color: #fff;
  cursor: pointer;
  box-shadow: 0 5px 0 rgba(0,0,0,0.15);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  transition: transform 0.08s ease, box-shadow 0.08s ease;
}
.q-btn:active { transform: translateY(4px); box-shadow: 0 1px 0 rgba(0,0,0,0.15); }
.q-btn .q-emoji { font-size: 34px; }
.q-btn .q-name  { font-size: 20px; }
.q-btn .q-res   { font-size: 14px; opacity: 0.9; font-weight: 700; }
.q-1080 { background: var(--pink); }
.q-720  { background: var(--purple); }
.q-480  { background: var(--blue); }
.q-360  { background: var(--green-dark); }

.big-emoji { font-size: 72px; margin: 0; text-align: center; }

.bar {
  width: 100%;
  height: 28px;
  background: #ede9fe;
  border-radius: 999px;
  overflow: hidden;
}
#bar-fill {
  height: 100%;
  width: 0%;
  background: linear-gradient(90deg, var(--purple), var(--pink));
  border-radius: 999px;
  transition: width 0.3s ease;
}
.pct {
  margin: 0;
  text-align: center;
  font-size: 30px;
  font-weight: 900;
  color: var(--purple);
}

.error {
  text-align: center;
  background: #fff;
  color: #dc2626;
  font-weight: 800;
  font-size: 18px;
  padding: 16px 20px;
  border-radius: 18px;
  box-shadow: 0 8px 20px rgba(80,30,120,0.18);
}

.hidden { display: none !important; }
